plugin:vote
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:vote [2010-10-03 15:40] – [vote plugin] HåkanS | plugin:vote [2023-12-21 15:42] (current) – new download url Aleksandr | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== vote plugin | + | ====== vote Plugin |
---- plugin ---- | ---- plugin ---- | ||
- | description: | + | description: |
author | author | ||
email : norihiro.tobo@gmail.com | email : norihiro.tobo@gmail.com | ||
Line 13: | Line 13: | ||
tags : poll, !experimental | tags : poll, !experimental | ||
- | downloadurl: | + | downloadurl: |
+ | bugtracker : | ||
+ | sourcerepo : | ||
+ | donationurl: | ||
+ | |||
+ | screenshot_img: | ||
---- | ---- | ||
- | |||
- | ==Sample Image== | ||
- | |||
- | {{http:// | ||
===== Syntax ===== | ===== Syntax ===== | ||
- | Use this [[plugins|plugin]] to add a vote to a wiki page. The syntax looks like this: | + | Use this plugin to add a vote to a wiki page. The syntax looks like this: |
<vote [title] [usercheck option]> | <vote [title] [usercheck option]> | ||
Line 35: | Line 36: | ||
===== Example ===== | ===== Example ===== | ||
- | == No usercheck == | + | ==== No usercheck ==== |
No limit to vote. | No limit to vote. | ||
- | <code text> | ||
- | <vote title> | ||
- | question | ||
- | * option A | ||
- | * option B | ||
- | * option C | ||
- | </ | ||
- | </ | ||
- | == Usercheck with IP Address == | + | <vote title> |
+ | question | ||
+ | * option A | ||
+ | * option B | ||
+ | * option C | ||
+ | </ | ||
+ | |||
+ | ==== Usercheck with IP Address ==== | ||
User can vote only once. | User can vote only once. | ||
- | <code text> | ||
- | <vote title check=ip> | ||
- | question | ||
- | * option A | ||
- | * option B | ||
- | * option C | ||
- | </ | ||
- | </ | ||
- | == Usercheck with DokuWiki username == | + | <vote title check=ip> |
+ | question | ||
+ | * option A | ||
+ | * option B | ||
+ | * option C | ||
+ | </ | ||
+ | |||
+ | ==== Usercheck with DokuWiki username ==== | ||
User can vote only once. | User can vote only once. | ||
- | <code text> | ||
- | <vote title check=user> | ||
- | question | ||
- | * option A | ||
- | * option B | ||
- | * option C | ||
- | </ | ||
- | </ | ||
- | ----- | + | <vote title check=user> |
+ | question | ||
+ | * option A | ||
+ | * option B | ||
+ | * option C | ||
+ | </ | ||
===== Discussion ===== | ===== Discussion ===== | ||
Line 116: | Line 116: | ||
Somebody with the skills should make a prettier fix. | Somebody with the skills should make a prettier fix. | ||
+ | ----- | ||
+ | \\ | ||
+ | Here comes a suggestion how to remove the ' | ||
+ | * the user is not logged in (is ' | ||
+ | * the user is logged in, but has already voted | ||
+ | Needs to edit **lib/ | ||
+ | <file php syntax.php> | ||
+ | <?php | ||
+ | /** | ||
+ | * Vote Plugin: allows to create simple votes | ||
+ | * | ||
+ | * @license GPL 2 (http:// | ||
+ | * @author Esther Brunner < | ||
+ | * @author Gina Häußge, | ||
+ | * @author Norihiro Tobo | ||
+ | */ | ||
+ | |||
+ | if(!defined(' | ||
+ | if(!defined(' | ||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | |||
+ | class syntax_plugin_vote extends DokuWiki_Syntax_Plugin { | ||
+ | |||
+ | |||
+ | function getInfo(){ | ||
+ | return confToHash(dirname(__FILE__).'/ | ||
+ | } | ||
+ | function getType(){ return ' | ||
+ | function getPType(){ return ' | ||
+ | function getSort(){ return 168; } | ||
+ | function connectTo( $mode ) { | ||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | function handle( $match, $state, $pos, & | ||
+ | |||
+ | $data = $match; | ||
+ | // | ||
+ | |||
+ | // Extract Title and Param | ||
+ | preg_match( '/< | ||
+ | $title = htmlspecialchars( $regx_result[1] ); | ||
+ | if( ! isset( $title ) ) { return NULL; } | ||
+ | |||
+ | preg_match( '/< | ||
+ | $param = htmlspecialchars( $regx_result[1] ); | ||
+ | |||
+ | preg_match( '/< | ||
+ | $question = htmlspecialchars( $regx_result[1] ); | ||
+ | |||
+ | // | ||
+ | |||
+ | |||
+ | // Extract options | ||
+ | $data = strip_tags( $data ); | ||
+ | preg_match_all( '/ | ||
+ | foreach( $regex_result[1] as $option ) { | ||
+ | $options[] = htmlspecialchars( trim( $option ) ); | ||
+ | } | ||
+ | |||
+ | $this-> | ||
+ | |||
+ | return array( $title, $param, $question, $options ); | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | function render( $mode, & | ||
+ | |||
+ | |||
+ | $ouotput = ""; | ||
+ | if ( $mode != ' | ||
+ | |||
+ | // Parse data | ||
+ | list( $title, $param, $question, $options ) = $data; | ||
+ | $renderer-> | ||
+ | $vote_log = $this-> | ||
+ | |||
+ | //Print header parts | ||
+ | $output .= '< | ||
+ | $output .= " | ||
+ | if ( $question ) { | ||
+ | $output .= '< | ||
+ | } | ||
+ | | ||
+ | |||
+ | $vote_allowed = $this-> | ||
+ | //Update vote log | ||
+ | if ( $_REQUEST[' | ||
+ | |||
+ | $vote = $_REQUEST[' | ||
+ | |||
+ | | ||
+ | |||
+ | if ( $vote == $option ) { | ||
+ | $vote_log[ ' | ||
+ | $vote_log[ ' | ||
+ | $vote_log[ ' | ||
+ | global $USERINFO; | ||
+ | $vote_log[ ' | ||
+ | $vote_allowed = false; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | // display vote form | ||
+ | $output .= $this-> | ||
+ | $output .= '</ | ||
+ | $output .= " | ||
+ | |||
+ | $renderer-> | ||
+ | return true; | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | function _user_check( $vote_log, $param ) { | ||
+ | |||
+ | if( preg_match( '/ | ||
+ | $check = $regex_result[1]; | ||
+ | } else { | ||
+ | return TRUE; | ||
+ | } | ||
+ | |||
+ | switch( $check ) { | ||
+ | |||
+ | case " | ||
+ | $ip = clientIP( true ); | ||
+ | if ( isset( $vote_log[' | ||
+ | return FALSE; | ||
+ | } | ||
+ | break; | ||
+ | |||
+ | case " | ||
+ | global $USERINFO; | ||
+ | $user = $USERINFO[' | ||
+ | if ( ( isset( $vote_log[' | ||
+ | return FALSE; | ||
+ | } | ||
+ | break; | ||
+ | } | ||
+ | |||
+ | return TRUE; | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | function _create_vote_log_file( $title, $options ) { | ||
+ | |||
+ | $vote_log_file = metaFN( md5( $title ), ' | ||
+ | |||
+ | if( file_exists( $vote_log_file ) ){ return TRUE; } | ||
+ | |||
+ | foreach( $options as $option ) { | ||
+ | $vote_skelton[ ' | ||
+ | } | ||
+ | $vote_skelton[ ' | ||
+ | |||
+ | $fh = fopen( $vote_log_file, | ||
+ | fwrite( $fh, serialize( $vote_skelton ) ); | ||
+ | fclose( $fh ); | ||
+ | |||
+ | return TRUE; | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | function _debug_out( $title, $data ) { | ||
+ | |||
+ | $file = metaFN( $title, ' | ||
+ | $fh = fopen( $file, ' | ||
+ | fwrite( $fh, $data ); | ||
+ | fclose( $fh ); | ||
+ | |||
+ | return TRUE; | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | function _read_vote_log( $title ) { | ||
+ | |||
+ | $vote_log = NULL; | ||
+ | |||
+ | $vote_log_file = metaFN( md5( $title ), ' | ||
+ | $vote_log | ||
+ | |||
+ | return $vote_log; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | function _write_vote_log( $title, $vote_log ) { | ||
+ | |||
+ | $vote_log_file = metaFN( md5( $title ), ' | ||
+ | |||
+ | $fh = fopen( $vote_log_file, | ||
+ | fwrite( $fh, serialize( $vote_log ) ); | ||
+ | fclose( $fh); | ||
+ | |||
+ | return TRUE; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | function _print_vote_form( $vote_log, $vote_allowed ){ | ||
+ | |||
+ | global $lang; | ||
+ | global $ID; | ||
+ | |||
+ | $total = $vote_log[' | ||
+ | if ( $total < 0 ) { return ''; | ||
+ | |||
+ | $option_count = count( $vote_log[' | ||
+ | $options = array_keys( (array)( $vote_log[ ' | ||
+ | $votes | ||
+ | |||
+ | $ret = '< | ||
+ | '" | ||
+ | '< | ||
+ | '< | ||
+ | $ret .= " | ||
+ | |||
+ | $ret .= '< | ||
+ | $ret .= " | ||
+ | |||
+ | |||
+ | for ( $i = 0; $i < $option_count; | ||
+ | |||
+ | $absolute = $votes[ $i ]; | ||
+ | if( $total == 0 ) { | ||
+ | $percent = 0; | ||
+ | } else { | ||
+ | $percent | ||
+ | } | ||
+ | |||
+ | $ret .= " | ||
+ | $ret .= '< | ||
+ | $ret .= '< | ||
+ | |||
+ | if ( $percent ) { | ||
+ | $ret .= '< | ||
+ | } | ||
+ | //Result | ||
+ | $ret .= '</ | ||
+ | '< | ||
+ | '< | ||
+ | //Form | ||
+ | $ret .= '< | ||
+ | '< | ||
+ | ' | ||
+ | $ret .= '</ | ||
+ | $ret .= " | ||
+ | |||
+ | } | ||
+ | |||
+ | $ret .= "</ | ||
+ | if($vote_allowed) { | ||
+ | $ret .= '< | ||
+ | ' | ||
+ | } | ||
+ | else { | ||
+ | $ret .= "< | ||
+ | } | ||
+ | $ret .= "</ | ||
+ | |||
+ | |||
+ | return $ret; | ||
+ | } | ||
+ | |||
+ | } // Class Definition | ||
+ | |||
+ | //Setup VIM: ex: et ts=4 enc=utf-8 : | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | ------ | ||
+ | \\ | ||
+ | There' |
plugin/vote.1286113259.txt.gz · Last modified: 2010-10-03 15:40 by HåkanS