Commit: 8a77e300a74953e4332346031ce38af9837eb63e
Author: Hannes Magnusson <[email protected]> Mon, 16 Dec 2013
10:01:30 -0800
Parents: 5226c7ce6acdc64a4f0f7a16a33d531be08702d3
Branches: master
Link:
http://git.php.net/?p=web/wiki.git;a=commitdiff;h=8a77e300a74953e4332346031ce38af9837eb63e
Log:
Update plugin
Changed paths:
M dokuwiki/lib/plugins/doodle/doodle_template.php
M dokuwiki/lib/plugins/doodle/lang/de/lang.php
M dokuwiki/lib/plugins/doodle/lang/en/lang.php
M dokuwiki/lib/plugins/doodle/script.js
M dokuwiki/lib/plugins/doodle/style.css
M dokuwiki/lib/plugins/doodle/syntax.php
diff --git a/dokuwiki/lib/plugins/doodle/doodle_template.php
b/dokuwiki/lib/plugins/doodle/doodle_template.php
index 4aa6369..a3e55b4 100755
--- a/dokuwiki/lib/plugins/doodle/doodle_template.php
+++ b/dokuwiki/lib/plugins/doodle/doodle_template.php
@@ -6,6 +6,8 @@
* doodle_tempalte.php is simply included and evaled from syntax.php
* The variable $template will be inherited from syntax.php and can be
used here.
*/
+ global $ID;
+
$template = $this->template;
$c = count($template['choices']);
?>
@@ -13,6 +15,7 @@
<!-- Doodle Plugin -->
<form action="<?php echo wl() ?>" method="post" name="doodle__form" id="<?php
echo $template['formId'] ?>" accept-charset="utf-8" >
+<input type="hidden" name="sectok" value="<?php echo getSecurityToken() ?>" />
<input type="hidden" name="do" value="show" >
<input type="hidden" name="id" value="<?php echo $ID ?>" >
<input type="hidden" name="formId" value="<?php echo $template['formId'] ?>" >
@@ -28,9 +31,9 @@
</tr>
<tr class="row1">
<th class="col0"><?php echo $lang['fullname'] ?></th>
- <?php foreach ($template['choices'] as $choice) { ?>
+<?php foreach ($template['choices'] as $choice) { ?>
<td class="centeralign"><?php echo $choice ?></td>
- <?php } ?>
+<?php } ?>
</tr>
<?php foreach ($template['doodleData'] as $fullname => $userData) { ?>
@@ -47,9 +50,9 @@
<!-- Results / sum per column -->
<tr>
<th class="rightalign"><b><?php echo $template['result'] ?></b></th>
- <?php for ($col = 0; $col < $c; $col++) { ?>
+<?php for ($col = 0; $col < $c; $col++) { ?>
<th class="centeralign"><b><?php echo $template['count'][$col]
?></b></th>
- <?php } ?>
+<?php } ?>
</tr>
<?php
@@ -65,7 +68,6 @@
</tr>
<?php } ?>
-
</tbody>
</table>
@@ -74,4 +76,3 @@
-
diff --git a/dokuwiki/lib/plugins/doodle/lang/de/lang.php
b/dokuwiki/lib/plugins/doodle/lang/de/lang.php
index 9ff881d..423125b 100644
--- a/dokuwiki/lib/plugins/doodle/lang/de/lang.php
+++ b/dokuwiki/lib/plugins/doodle/lang/de/lang.php
@@ -1,18 +1,23 @@
<?php
+// headers and buttons
$lang['btn_vote'] = 'Abstimmen';
$lang['btn_change'] = 'Stimme Ändern';
$lang['count'] = 'Summe:';
$lang['final_result'] = 'Ergebnis:';
$lang['edit'] = 'ändern';
+// info messages
+$lang['poll_closed'] = 'Abstimmung beendet';
+$lang['vote_saved'] = 'Stimme wurde gezählt.';
+$lang['vote_deleted'] = 'Stimme wurde gelöscht.';
+
// error messages
-$lang['must_be_logged_in'] = 'Du must eingeloggt sein um abstimmen zu
dürfen!';
-$lang['ip_has_already_voted'] = 'Diese IP (<code>%s</code>) hat bereits
abgestimmt!';
+$lang['dont_have_name'] = 'Du hast vergessen deinen Namen anzugeben!';
+$lang['must_be_logged_in'] = 'Du must eingeloggt sein um abzustimmen!';
+$lang['ip_has_already_voted'] = 'Die IP (<code>%s</code>) hat bereits
abgestimmt!';
+$lang['select_one_option'] = 'Bitte wähle eine Option.';
$lang['you_voted_already'] = 'Du hast bereits abgestimmt!';
-$lang['not_allowed_to_change'] = 'Du darfst diese Stimme nicht
verändern!';
-$lang['vote_saved'] = 'Deine Stimme wurde gezählt.';
-$lang['vote_deleted'] = 'Stimme gelöscht.';
-
+$lang['not_allowed_to_change'] = 'Du darfst diese Stimme nicht ändern!';
?>
diff --git a/dokuwiki/lib/plugins/doodle/lang/en/lang.php
b/dokuwiki/lib/plugins/doodle/lang/en/lang.php
index 6cafcd4..39f2388 100644
--- a/dokuwiki/lib/plugins/doodle/lang/en/lang.php
+++ b/dokuwiki/lib/plugins/doodle/lang/en/lang.php
@@ -1,18 +1,24 @@
<?php
+// headers and buttons
$lang['btn_vote'] = 'Vote';
$lang['btn_change'] = 'Change Vote';
$lang['count'] = 'Count:';
$lang['final_result'] = 'Final result:';
$lang['edit'] = 'edit';
+// info messages
+$lang['poll_closed'] = 'This poll has been closed.';
+$lang['vote_saved'] = 'Vote has been saved.';
+$lang['vote_deleted'] = 'Vote has been deleted.';
+
// error messages
+$lang['dont_have_name'] = 'You forgot to provide your name!';
$lang['must_be_logged_in'] = 'You must be logged in to vote!';
$lang['ip_has_already_voted'] = 'The IP (<code>%s</code>) has already voted!';
+$lang['select_one_option'] = 'Please select one option.';
$lang['you_voted_already'] = 'You voted already!';
$lang['not_allowed_to_change'] = 'You are not allowed to change this vote!';
-$lang['vote_saved'] = 'Vote has been saved.';
-$lang['vote_deleted'] = 'Vote has been deleted.';
?>
diff --git a/dokuwiki/lib/plugins/doodle/script.js
b/dokuwiki/lib/plugins/doodle/script.js
index a967fcf..56a2024 100644
--- a/dokuwiki/lib/plugins/doodle/script.js
+++ b/dokuwiki/lib/plugins/doodle/script.js
@@ -1,7 +1,5 @@
/**
- * JavsScript methods
- * for the dokuwiki
- * doodle plugin
+ * JavsScript methods for the dokuwiki doodle plugin
*
* @author Robert Rackl <[email protected]>
* @date January 2011
@@ -13,10 +11,10 @@
* @param fullname name of the entry that should be edited
*/
function editEntry(formId, fullname) {
- var doodleForm = document.getElementById(formId);
- doodleForm.formId = formId;
- doodleForm.edit__entry.value = fullname;
- doodleForm.submit();
+ var doodleForm = document.getElementById(formId);
+ doodleForm.formId = formId;
+ doodleForm.edit__entry.value = fullname;
+ doodleForm.submit();
}
/**
@@ -25,8 +23,8 @@ function editEntry(formId, fullname) {
* @param fullname name of the entry that should be edited
*/
function deleteEntry(formId, fullname) {
- var doodleForm = document.getElementById(formId);
- doodleForm.formId = formId;
- doodleForm.delete__entry.value = fullname;
- doodleForm.submit();
-}
+ var doodleForm = document.getElementById(formId);
+ doodleForm.formId = formId;
+ doodleForm.delete__entry.value = fullname;
+ doodleForm.submit();
+}
\ No newline at end of file
diff --git a/dokuwiki/lib/plugins/doodle/style.css
b/dokuwiki/lib/plugins/doodle/style.css
index 7aee3f7..0db25ee 100644
--- a/dokuwiki/lib/plugins/doodle/style.css
+++ b/dokuwiki/lib/plugins/doodle/style.css
@@ -7,3 +7,23 @@ div.dokuwiki table.inline td.notokay {
background-color: #fcc;
text-align: center;
}
+
+.doodle__edit {
+ background:url(../../../lib/images/pencil.png) top right no-repeat;
+ width: 20px;
+ height: 20px;
+ padding: 0 0 0 10px;
+ cursor: pointer;
+ border: 0;
+ color: rgba(0, 0, 0, 0);
+}
+
+.doodle__delete {
+ background:url(../../../lib/images/del.png) top right no-repeat;
+ width: 20px;
+ height: 20px;
+ padding: 0 0 0 10px;
+ cursor: pointer;
+ border: 0;
+ color: rgba(0, 0, 0, 0);
+}
diff --git a/dokuwiki/lib/plugins/doodle/syntax.php
b/dokuwiki/lib/plugins/doodle/syntax.php
index 8dce672..eb75dba 100755
--- a/dokuwiki/lib/plugins/doodle/syntax.php
+++ b/dokuwiki/lib/plugins/doodle/syntax.php
@@ -7,6 +7,7 @@
* @author Robert Rackl <[email protected]>
* @author Jonathan Tsai <[email protected]>
* @author Esther Brunner <[email protected]>
+ * @author Romain Coltel <[email protected]>
*/
if(!defined('DOKU_INC'))
define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
@@ -20,31 +21,33 @@ require_once(DOKU_PLUGIN.'syntax.php');
* <pre>
* <doodle
* title="What do you like best?"
- * auth="none|ip|login"
+ * auth="none|ip|user"
* adminUsers="user1|user2"
* adminGroups="group1|group2"
- * voteType="single|multi"
- * closed="true|false"
- * >
+ * voteType="default|multi"
+ * closed="true|false" >
* * Option 1
* * Option 2 **some wikimarkup** \\ is __allowed__!
* * Option 3
- * </doodle>
+ * </doodle>
* </pre>
*
- * Required: a title and at least one option.
+ * Only required parameteres are a title and at least one option.
*
* <h3>Parameters</h3>
* auth="none" - everyone can vote with any username, (IPs will be recorded
but not checked)
* auth="ip" - everyone can vote with any username, votes will be tracked by
IP to prevent duplicate voting
* auth="user" - users must login with a valid dokuwiki user. This has the
advantage, that users can
* edit their vote ("change their mind") later on.
- * adminUser/adminGroups - Logged in adminUsers or members of the adminGroups
can always edit and delete any entry.
*
- * If type="single", then each user can choose only one option (round
checkboxes will be shown).
- * If type="multi", then each user can choose multiple options (square
checkboxes will be shown).
+ * <h3>adminUsers and adminGroups</h3>
+ * "|"-separated list of adminUsers or adminGroups, whose members can always
edit and delete <b>any</b> entry.
*
- * If the doodle is closed, then no one can vote anymore. The result will
still be shown on the page.
+ * <h3>Vote Type</h3>
+ * default - user can vote for exactly one option (round checkboxes will be
shown)
+ * multi - can choose any number of options, including none (square
checkboxes will be shown).
+ *
+ * If closed=="true", then no one can vote anymore. The result will still be
shown on the page.
*
* The doodle's data is saved in '<dokuwiki>/data/meta/title_of_vote.doodle'.
The filename is the (masked) title.
* This has the advantage that you can move your doodle to another page,
without loosing the data.
@@ -58,7 +61,7 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
/**
* return info about this plugin
*/
- function getInfo(){
+ function getInfo() {
return array(
'author' => 'Robert Rackl',
'email' => '[email protected]',
@@ -76,7 +79,7 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
/**
* Connect pattern to lexer
*/
- function connectTo($mode){
+ function connectTo($mode) {
$this->Lexer->addSpecialPattern('<doodle\b.*?>.+?</doodle>', $mode,
'plugin_doodle');
}
@@ -90,11 +93,13 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
//----- default parameter settings
$params = array(
- 'title' => 'Default title',
- 'auth' => self::AUTH_NONE,
- 'adminGroup' => '',
- 'voteTyp' => 'single',
- 'closed' => FALSE
+ 'title' => 'Default title',
+ 'auth' => self::AUTH_NONE,
+ 'adminUsers' => '',
+ 'adminGroups' => '',
+ 'adminMail' => null,
+ 'voteType' => 'default',
+ 'closed' => FALSE
);
//----- parse parameteres into name="value" pairs
@@ -120,15 +125,29 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
} else
if (strcmp($name, "ADMINGROUPS") == 0) {
$params['adminGroups'] = $value;
+ } else
+ if (strcmp($name, "ADMINMAIL") == 0) {
+ // check for valid email adress
+ if
(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,5})$/',
$value)) {
+ $params['adminMail'] = $value;
+ }
} else
if (strcmp($name, "VOTETYPE") == 0) {
- $params['allowMultiVote'] = strcasecmp($value, "multi") == 0;
- } else
- if (strcmp($name, "AUTOGROUP") == 0) {
- $params['autoGroup'] = $value;
+ if (preg_match('/default|multi/', $value)) {
+ $params['voteType'] = $value;
+ }
+ } else
+ if ((strcmp($name, "CLOSEON") == 0) &&
+ (($timestamp = strtotime($value)) !== false) &&
+ (time() > $timestamp) )
+ {
+ $params['closed'] = 1;
} else
if (strcmp($name, "CLOSED") == 0) {
$params['closed'] = strcasecmp($value, "TRUE") == 0;
+ } else
+ if (strcmp($name, "SORT") == 0) {
+ $params['sort'] = $value; // make it possible to sort by time
}
}
@@ -143,7 +162,7 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
/**
* parse list of choices
* explode, trim and encode html entities,
- * emtpy choices will be skipped.
+ * empty choices will be skipped.
*/
function parseChoices($choiceStr) {
$choices = array();
@@ -183,8 +202,11 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
global $conf;
global $INFO; // needed for users real name
global $ACT; // action from $_REQUEST['do']
+ global $REV; // to not allow any action if it's an old page
global $ID; // name of current page
+ //debout('data in render', $data);
+
$this->params = $data['params'];
$this->choices = $data['choices'];
$this->doodle = array();
@@ -197,16 +219,12 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
if (count($this->choices) > 0) {
$this->doodle = $this->readDoodleDataFromFile();
}
- //FIXME: count($choices) may be different from number of choices in
$doodle data!
- $can_vote = false;
- if (count(array_intersect(array('admin', 'phpcvs', 'voting'),
$INFO['userinfo']['grps'])) > 0) {
- $can_vote = true;
- }
+ //FIXME: count($choices) may be different from number of choices in
$doodle data!
- // ----- FORM ACTIONS (only allowed when showing the page, not when
editing) -----
+ // ----- FORM ACTIONS (only allowed when showing the most recent
version of the page, not when editing) -----
$formId = 'doodle__form__'.cleanID($this->params['title']);
- if ($ACT == 'show' && $_REQUEST['formId'] == $formId && $can_vote) {
+ if ($ACT == 'show' && $_REQUEST['formId'] == $formId && $REV == false)
{
// ---- cast new vote
if (!empty($_REQUEST['cast__vote'])) {
$this->castVote();
@@ -229,7 +247,7 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
* The $doodle array maps fullnames (with html special characters
masked) to an array of userData for this vote.
* Each sub array contains:
* 'username' loggin name if use was logged in
- * 'choices' is an array of column indexes where user has voted !!!
+ * 'choices' is an (variable length!) array of column indexes where
user has voted
* 'ip' ip of voting machine
* 'time' unix timestamp when vote was casted
@@ -260,28 +278,31 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
$this->template['result'] = $this->params['closed'] ?
$this->getLang('final_result') : $this->getLang('count');
$this->template['doodleData'] = array(); // this will be filled with
some HTML snippets
$this->template['formId'] = $formId;
+ if ($this->params['closed']) {
+ $this->template['msg'] = $this->getLang('poll_closed');
+ }
for($col = 0; $col < count($this->choices); $col++) {
$this->template['count'][$col] = 0;
foreach ($this->doodle as $fullname => $userData) {
if (!empty($userData['username'])) {
- $this->template['doodleData']["$fullname"]['username'] =
' ('.$userData['username'].')';
+ $this->template['doodleData']["$fullname"]['username'] =
' ('.$userData['username'].')';
}
if (in_array($col, $userData['choices'])) {
$timeLoc = strftime($conf['dformat'], $userData['time']);
// localized time of vote
$this->template['doodleData']["$fullname"]['choice'][$col]
=
- '<td class="okay"><img
src="'.DOKU_BASE.'lib/images/success.png" title="'.$timeLoc.'"></td>';
+ '<td class="centeralign"
style="background-color:#AFA"><img src="'.DOKU_BASE.'lib/images/success.png"
title="'.$timeLoc.'"></td>';
$this->template['count']["$col"]++;
} else {
$this->template['doodleData']["$fullname"]['choice'][$col]
=
- '<td class="notokay"> </td>';
+ '<td class="centeralign"
style="background-color:#FCC"> </td>';
}
}
}
// ---- add edit link to editable entries
foreach($this->doodle as $fullname => $userData) {
- if ($ACT == 'show' &&
+ if ($ACT == 'show' && $REV == false &&
$this->isAllowedToEditEntry($fullname))
{
// the javascript source of these functions is in script.js
@@ -296,9 +317,9 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
}
// ---- calculates if user is allowed to vote
- $this->template['inputTR'] = ($can_vote?$this->getInputTR():'');
+ $this->template['inputTR'] = $this->getInputTR();
- // ----- I am using PHP as a templating enginge here.
+ // ----- I am using PHP as a templating engine here.
//debout("Template", $this->template);
ob_start();
include 'doodle_template.php'; // the array $template can be used
inside doodle_template.php!
@@ -316,13 +337,20 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
function castVote() {
$fullname = hsc(trim($_REQUEST['fullname']));
$selected_indexes = $_REQUEST['selected_indexes']; // may not be set
when all checkboxes are deseleted.
- if (empty($selected_indexes)) {
- $selected_indexes = array();
- }
-
+
if (empty($fullname)) {
+ $this->template['msg'] = $this->getLang('dont_have_name');
return;
}
+ if (empty($selected_indexes)) {
+ if ($this->params['voteType'] == 'multi') {
+ $selected_indexes = array(); //allow empty vote only if
voteType is "multi"
+ } else {
+ $this->template['msg'] = $this->getLang('select_one_option');
+ return;
+ }
+ }
+
//---- check if user is allowed to vote, according to 'auth' parameter
//if AUTH_USER, then user must be logged in
@@ -364,16 +392,24 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
$this->doodle["$fullname"]['ip'] = $_SERVER['REMOTE_ADDR'];
$this->writeDoodleDataToFile();
$this->template['msg'] = $this->getLang('vote_saved');
+
+ //send mail if $params['adminMail'] is filled
+ if (!empty($this->params['adminMail'])) {
+ $subj = "[DoodlePlugin] Vote casted by $fullname
(".$this->doodle["$fullname"]['username'].')';
+ $body = 'User has casted a
vote'."\n\n".print_r($this->doodle["$fullname"], true);
+ mail_send($this->params['adminMail'], $subj, $body,
$conf['mailfrom']);
+ }
}
- /** ACTION: start editing an entry */
+ /**
+ * ACTION: start editing an entry
+ * expects fullname of voter in request param edit__entry
+ */
function startEditEntry() {
$fullname = hsc(trim($_REQUEST['edit__entry']));
- if (empty($fullname) ||
- !isset($this->doodle["$fullname"]) ||
- !$this->isAllowedToEditEntry($fullname) ) return;
+ if (!$this->isAllowedToEditEntry($fullname)) return;
- $this->template['editEntry']['fullname'] = $fullname;
+ $this->template['editEntry']['fullname'] = $fullname;
$this->template['editEntry']['selected_indexes'] =
$this->doodle["$fullname"]['choices'];
// $fullname will be shown in the input row
}
@@ -381,9 +417,7 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
/** ACTION: delete an entry completely */
function deleteEntry() {
$fullname = hsc(trim($_REQUEST['delete__entry']));
- if (empty($fullname) ||
- !isset($this->doodle["$fullname"]) ||
- !$this->isAllowedToEditEntry($fullname) ) return;
+ if (!$this->isAllowedToEditEntry($fullname)) return;
unset($this->doodle["$fullname"]);
$this->writeDoodleDataToFile();
@@ -393,13 +427,16 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
// ---------- HELPER METHODS -----------
/**
- * check if the currently logged in user is allowed to edit a given entry
- * @return true if user is loggedin and in the list of admins or
$entryFullname is his own entry
+ * check if the currently logged in user is allowed to edit a given entry.
+ * @return true if entryFullname is the entry of the current user, or
+ * the currently logged in user is in the list of admins
*/
function isAllowedToEditEntry($entryFullname) {
global $INFO;
global $auth;
-
+
+ if (empty($entryFullname)) return false;
+ if (!isset($this->doodle["$entryFullname"])) return false;
if ($this->params['closed']) return false;
if (!$this->isLoggedIn()) return false;
@@ -411,9 +448,9 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
}
//check adminUsers
- if (!empty($this->params['adminUsers']) &&
- stripos($this->params['adminUsers'], $_SERVER['REMOTE_USER']) !==
false) {
- return true;
+ if (!empty($this->params['adminUsers'])) {
+ $adminUsers = explode('|', $this->params['adminUsers']);
+ return in_array($_SERVER['REMOTE_USER'], $adminUsers);
}
//check own entry
@@ -424,14 +461,14 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
* return true if the user is currently logged in
*/
function isLoggedIn() {
- global $conf;
- global $auth;
- return $conf['useacl'] && $auth && $_SERVER['REMOTE_USER'];
+ // see http://www.dokuwiki.org/devel:environment
+ global $INFO;
+ return isset($INFO['userinfo']);
}
/**
* calculate the input table row:
- *
+ * @return complete <TR> tags for input row and information message
* May return empty string, if user is not allowed to vote
*
* If user is logged in he is always allowed edit his own entry. ("change
his mind")
@@ -466,7 +503,8 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
$TR .= '<td class="rightalign">';
if ($fullname) {
if ($editMode) $TR .= $this->getLang('edit').': ';
- $TR .= hsc($fullname).'<input type="hidden" name="fullname"
value="'.$fullname.'">';
+ $TR .= $fullname.' ('.$_SERVER['REMOTE_USER'].')';
+ $TR .= '<input type="hidden" name="fullname"
value="'.$fullname.'">';
} else {
$TR .= '<input type="text" name="fullname" value="">';
}
@@ -477,20 +515,26 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
if ($editMode && in_array($col,
$this->template['editEntry']['selected_indexes']) ) {
$selected = 'checked="checked"';
}
- if ($this->params['allowMultiVote']) {
- $TR .= '<td class="centeralign"><input type="checkbox"
name="selected_indexes[]" value="'."$col\" $selected></td>";
+ $TR .= '<td class="centeralign">';
+
+ if ($this->params['voteType'] == 'multi') {
+ $inputType = "checkbox";
} else {
- $TR .= '<td class="centeralign"><input type="radio"
name="selected_indexes[]" value="'."$col\" $selected></td>";
+ $inputType = "radio";
}
+ $TR .= '<input type="'.$inputType.'" name="selected_indexes[]"
value="'.$col.'"';
+ $TR .= $selected.">";
+ $TR .= '</TD>';
}
$TR .= '</tr>';
$TR .= '<tr>';
$TR .= ' <td colspan="'.($c+1).'" class="centeralign">';
+
if ($editMode) {
- $TR .= ' <input type="submit" value="
'.$this->getLang('btn_change').' " name="change__vote" class="button">';
+ $TR .= ' <input type="submit" id="voteButton" value="
'.$this->getLang('btn_change').' " name="change__vote" class="button">';
} else {
- $TR .= ' <input type="submit" value="
'.$this->getLang('btn_vote').' " name="cast__vote" class="button">';
+ $TR .= ' <input type="submit" id="voteButton" value="
'.$this->getLang('btn_vote').' " name="cast__vote" class="button">';
}
$TR .= ' </td>';
$TR .= '</tr>';
@@ -514,9 +558,16 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
//sanitize: $doodle[$fullnmae]['choices'] must be at least an array
// This may happen if user deselected all choices
foreach($doodle as $fullname => $userData) {
- if (!is_array($doodle["$fullname"]['choices'])) {
- $doodle["$fullname"]['choices'] = array();
- }
+ if (!is_array($doodle["$fullname"]['choices'])) {
+ $doodle["$fullname"]['choices'] = array();
+ }
+ }
+
+ if (strcmp($this->params['sort'], 'time') == 0) {
+ debout("sorting by time");
+ uasort($doodle, 'cmpEntryByTime');
+ } else {
+ uksort($doodle, "strnatcasecmp"); // case insensitive "natural"
sort
}
//debout("read from $dfile", $doodle);
return $doodle;
@@ -528,7 +579,7 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
function writeDoodleDataToFile() {
if (!is_array($this->doodle)) return;
$dfile = $this->getDoodleFileName();
- ksort($this->doodle, SORT_LOCALE_STRING); // sort by localized
fullnames
+ uksort($this->doodle, "strnatcasecmp"); // case insensitive "natural"
sort
io_saveFile($dfile, serialize($this->doodle));
//debout("written to $dfile", $doodle);
return $dfile;
@@ -548,10 +599,17 @@ class syntax_plugin_doodle extends DokuWiki_Syntax_Plugin
return $dfile;
}
+
} // end of class
// ----- static functions
+/** compare two doodle entries by the time of vote */
+function cmpEntryByTime($a, $b) {
+ return strcmp($a['time'], $b['time']);
+}
+
+
function debout() {
if (func_num_args() == 1) {
msg('<pre>'.hsc(print_r(func_get_arg(0), true)).'</pre>');--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php