DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:userpoll

Userpoll Plugin

Compatible with DokuWiki

2012-01-25, angua

plugin Lets you add polls to a wiki page

Last updated on
2013-05-09
Provides
Syntax

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to doodle2, doodle3, doodle4, multipoll, poll

Tagged with poll

Description

Use this plugin to add a poll to a wiki page. The syntax looks like this:

<userpoll [id]>
  [question]

  * [option]
  * [option]
  * ...
</userpoll>

That means, you can simply put <userpoll> tags around regular bulleted lists to get a radio button poll.

[id] the ID of the poll; must be unique1); appears as title required
[question] the question you'd like to ask optional
[option] a possible answer to the above question required

The main difference with Esther's plugin is that this plugin is user based. That is while Esther's poll allows one vote per client IP address. This one allows one vote per logged in user. It also remembers what every voter voted, to let them change their mind if they wish.

It is compatible with the poll plugin except that if there are one poll and one userpoll on a same page, voting for userpoll will make you vote for the poll one. The contrary is not true as userpoll checks for what you're voting for, which allows you do have several userpolls in a same page.

Download & Installation

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

Languages

UPDATE: 2013-05-09 added German language support.

Only English, French and Spanish supported so far. Russian is located below.

/ru/lang.php
<?php
 
$lang['btn_vote']       = 'Голос';
$lang['btn_changemind'] = 'Поменять';
$lang['login_required'] = 'Нужно зарегистрироваться';
 
//Setup VIM: ex: et ts=4 enc=utf-8 :

Revision History

  • 2013-05-09:
    • latest version, stable
  • 2007-02-09:
    • first version, experimental

Discussion

Maybe you should have the title and the id different.

And maybe change the “*” that indicates a question to something else so you can do ordinary styles inside the poll.

Example:

<userpoll [ ID | Title ]>
  **We want this ?**
  <question> ====== [yes] ======</question>
  <question>[no]</question>
  <question>[Maybe]</question>
</userpoll>
Solved this idea with the following lines of code in lib/plugins/userpoll/syntax.php
If you use the syntax <userpoll [PAGEID|Title]> the ID of the current document is used as the userpoll ID or use e.g. <userpoll [123|Title]>
function render($mode, &$renderer, $data) {

  if ($mode == 'xhtml'){
    global $ID;

    $options = $data[1];
    $title   = $renderer->_xmlEntities($data[0]);

    // prevent caching to ensure the poll results are fresh
    $renderer->info['cache'] = false;

    //starting modifications for syntax <userpoll [ID|Title]>
    $title=preg_replace( "/^\[/","",$title );
    $title=preg_replace( "/\]$/","",$title );
    if( preg_match( "/\|/", $title ) ) {
            $tmp_array = explode("|", $title);
            if( $tmp_array[0] == "PAGEID" ) {
                    $pollid = $ID;
            }
            else {
                    $pollid = $tmp_array[0];
            }
            $title = $tmp_array[1];
            if( strlen($title) > 0 ) {
                    $title = '[' . $tmp_array[1] . ']';
            }
    }
    else {
            $pollid = $title;
    }
    //$title = $title . "id=" . $pollid;  //debug

    // get poll file contents
    //$pollid = md5('@userpoll@'.$title);
    $pollid = md5('@userpoll@'.$pollid);
    //end of modifications for syntax <userpoll [ID|Title]>

    $pfile = metaFN($pollid, '.userpoll');
    $poll  = unserialize(@file_get_contents($pfile));


Oli

I've excluded the chance for the users to modify their vote.. It's a very easy hack… You have simply to edit syntax.php and comment the code from line 174 to line 183.

/*if ($pollid) {
      // user had already voted, allow him/her to changer his/her mind
      $ret .= '<tr><td colspan="4">'
        . '<form id="userpoll__form" method="post" action="'.script().'" accept-charset="'.$lang['encoding'].'">'
        . '<div class="no"><input type="hidden" name="do" value="show" />'
        . '<input type="hidden" name="pollid" value="' . $pollid . '" />'
        . '<input type="hidden" name="id" value="'.$ID.'" />'
        . '<input type="hidden" name="vote" value="@FORGET@">'
        . '<input class="button" type="submit" value="' . $this->getLang('btn_changemind') . '"></form></div></td></tr>';
    }
*/

Possible Bug?

Not sure where to report bugs in this plugin. We just downloaded it and tried it in our installation (on 1/24/08). Some people were able to vote, while others were not. That is, they cast their vote, but in the results screen, they didn't see their vote reflected. I can obtain more information on this end if there's someone on that end who's interested. Thanks!

Quick update on this: I figured out what the problem was. One of the choices in the poll did not work, either because of an ampersand (&) or an apostrophe ('). I created a new poll and took those symbols out, and everything worked. Just FYI for anyone who uses this plugin.


— 04/01/2012 An error message,

Security Token did not match. Possible CSRF attack.

Something like this don't know why???

— 09/05/2013

Problem solved due to changes in the newest version. Redownload the plugin here!

1)
If it is not, metadata of the polls with the same id gets mixed up, i.e. users who have voted for a previous poll with that id can't vote again.
plugin/userpoll.txt · Last modified: 2023-12-17 21:25 by Aleksandr

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki