Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 02, 2012
romain - Added softness in email validation (authorized the + sign before th…
…e @)

- Added softness in choices syntax
- Added "don't do anything if looking at a revision"
- Added a close button. Admins do not need to edit the page anymore to
close the vote
46cc5dd
romain Added doodle_not_found translations 466a196
romain - Resolve problems with the close button
- Don't do anything if the vote is already closed
044e22f
2  VERSION
View
@@ -1 +1 @@
-3.1
+3.2
9 doodle_template.php
View
@@ -65,7 +65,13 @@
</td>
</tr>
<?php } ?>
-
+<?php if(!empty($template['closeform'])) { ?>
+ <tr>
+ <td colspan="<?php echo $c+1 ?>">
+ <input type="submit" name="close__vote" value="<?php echo $template['closeform'] ?>" class="button">
+ </td>
+ </tr>
+<?php } ?>
</tbody>
</table>
@@ -75,4 +81,3 @@
-
4 lang/de/lang.php
View
@@ -14,6 +14,8 @@
$lang['not_allowed_to_change'] = 'Du darfst diese Stimme nicht ver&auml;ndern!';
$lang['vote_saved'] = 'Deine Stimme wurde gez&auml;hlt.';
$lang['vote_deleted'] = 'Stimme gel&ouml;scht.';
-
+$lang['vote_closed'] = 'Dieser Stimme wurde geschlossen.';
+$lang['no_doodle'] = 'Keine doodle auf dieser Seite gefunden';
+$lang['doodle_not_found'] = 'Der gesuchte doodle ist nicht gefunden.';
?>
4 lang/en/lang.php
View
@@ -14,6 +14,8 @@
$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.';
-
+$lang['vote_closed'] = 'This vote has been closed.';
+$lang['no_doodle'] = 'No doodle found on this page.';
+$lang['doodle_not_found'] = 'The searched doodle has not been found.';
?>
4 lang/fr/lang.php
View
@@ -14,6 +14,8 @@
$lang['not_allowed_to_change'] = 'Vous n\'&ecirc;tes pas autoris&eacute; &agrave; changer ce vote !';
$lang['vote_saved'] = 'Votre vote a &eacute;t&eacute; sauvegard&eacute;.';
$lang['vote_deleted'] = 'Votre vote a &eacute;t&eacute; supprim&eacute;.';
-
+$lang['vote_closed'] = 'Ce doodle a &eacute;t&eacute; ferm&eacute;.';
+$lang['no_doodle'] = 'Aucun doodle &agrave; supprimer sur cette page.';
+$lang['doodle_not_found'] = 'Le doodle recherch&eacute; n\'a pas &eacute;t&eacute; trouv&eacute;.';
?>
166 syntax.php
View
@@ -7,6 +7,7 @@
* @author Robert Rackl <wiki@doogie.de>
* @author Jonathan Tsai <tryweb@ichiayi.com>
* @author Esther Brunner <wikidesign@gmail.com>
+ * @author Romain Coltel <aorimn@gmail.com>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
@@ -124,7 +125,7 @@ function handle($match, $state, $pos, &$handler) {
} 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)) {
+ if (preg_match('/^[_a-z0-9-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,5})$/', $value)) {
$params['adminMail'] = $value;
}
} else
@@ -133,7 +134,7 @@ function handle($match, $state, $pos, &$handler) {
} else
if ((strcmp($name, "CLOSEON") == 0) &&
(($timestamp = strtotime($value)) !== false) &&
- (time() > $timestamp) )
+ (time() >= $timestamp) )
{
$params['closed'] = 1;
} else
@@ -153,11 +154,11 @@ function handle($match, $state, $pos, &$handler) {
/**
* 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();
- preg_match_all('/^ \* (.*?)$/m', $choiceStr, $matches, PREG_PATTERN_ORDER);
+ preg_match_all('/^ {2,}\* ?(.*?)$/m', $choiceStr, $matches, PREG_PATTERN_ORDER);
foreach ($matches[1] as $choice) {
$choice = hsc(trim($choice));
if (!empty($choice)) {
@@ -190,6 +191,7 @@ function render($mode, &$renderer, $data) {
//debout("render: $mode");
global $conf;
global $ACT; // action from $_REQUEST['do']
+ global $REV; // to not allow any action if it's an old page
$this->params = $data['params'];
$this->choices = $data['choices'];
@@ -205,9 +207,9 @@ function render($mode, &$renderer, $data) {
}
//FIXME: count($choices) may be different from number of choices in $doodle data!
- // ----- FORM ACTIONS (only allowed when showing the page, not when editing) -----
- $formId = 'doodle__form__'.cleanID($this->params['title']);
- if ($ACT == 'show' && $_REQUEST['formId'] == $formId ) {
+ // ----- FORM ACTIONS (only allowed when showing the most recent page, not when editing) -----
+ $formId = 'doodle__form__'.cleanID($this->params['title']);
+ if ($ACT == 'show' && $_REQUEST['formId'] == $formId && $REV === '') {
// ---- cast new vote
if (!empty($_REQUEST['cast__vote'])) {
$this->castVote();
@@ -224,6 +226,10 @@ function render($mode, &$renderer, $data) {
if (!empty($_REQUEST['delete__entry']) ) {
$this->deleteEntry($_REQUEST['delete__entry']);
}
+ // ---- close the doodle
+ if (!empty($_REQUEST['close__vote'])) {
+ $this->closeVote();
+ }
}
/******** Format of the $doodle array ***********
@@ -266,7 +272,7 @@ function render($mode, &$renderer, $data) {
$this->template['count'][$col] = 0;
foreach ($this->doodle as $fullname => $userData) {
if (!empty($userData['username'])) {
- $this->template['doodleData']["$fullname"]['username'] = '&nbsp('.$userData['username'].')';
+ $this->template['doodleData']["$fullname"]['username'] = '&nbsp;('.$userData['username'].')';
}
if (in_array($col, $userData['choices'])) {
$timeLoc = strftime($conf['dformat'], $userData['time']); // localized time of vote
@@ -282,10 +288,9 @@ function render($mode, &$renderer, $data) {
// ---- add edit link to editable entries
foreach($this->doodle as $fullname => $userData) {
- if ($ACT == 'show' &&
+ if ($ACT == 'show' && $REV === '' &&
$this->isAllowedToEditEntry($fullname))
{
- // the javascript source of these functions is in script.js
$this->template['doodleData']["$fullname"]['editLinks'] =
'<input type="submit" class="doodle__edit" value="'.$fullname.'" name="edit__entry" />'."\n".
'<input type="submit" class="doodle__delete" value="'.$fullname.'" name="delete__entry" />'."\n";
@@ -294,6 +299,9 @@ function render($mode, &$renderer, $data) {
// ---- calculates if user is allowed to vote
$this->template['inputTR'] = $this->getInputTR();
+
+ // ---- create the "close doodle" form
+ $this->template['closeform'] = $this->getCloseForm();
// ----- I am using PHP as a templating engine here.
//debout("Template", $this->template);
@@ -439,25 +447,14 @@ function deleteEntry($entryName) {
*/
function isAllowedToEditEntry($entryFullname) {
global $INFO;
-
- if ($this->params['closed']) return false;
+
+ if ($this->params['closed']) return false;
if (!($this->isLoggedIn() || $this->params['auth'] === self::AUTH_IP))
return false;
- //check adminGroups
- if (!empty($this->params['adminGroups'])) {
- $adminGroups = explode('|', $this->params['adminGroups']); // array of adminGroups
- $usersGroups = $INFO['userinfo']['grps']; // array of groups that the user is in
- if (count(array_intersect($adminGroups, $usersGroups)) > 0)
- return true;
- }
-
- //check adminUsers
- if (!empty($this->params['adminUsers'])) {
- $adminUsers = explode('|', $this->params['adminUsers']); // array of adminUsers
- if(in_array(strtoupper($_SERVER['REMOTE_USER']), $adminUsers))
- return true;
- }
+ //check if the user is an admin of this doodle
+ if($this->isDoodleAdmin())
+ return true;
//check own entry
switch($this->params['auth'])
@@ -564,6 +561,123 @@ function getInputTR() {
return $TR;
}
+
+ /**
+ * Create the form to display for the admin to close the doodle
+ * Check whether this form has to be displayed or not
+ * @return the form for the close button
+ */
+ function getCloseForm() {
+ //if the doodle is already close or the user is not an admin of the doodle
+ if($this->params['closed'] || !$this->isDoodleAdmin())
+ return '';
+
+ return 'Close';
+ }
+
+
+ /**
+ * Close the vote if it's not yet and the user is an admin
+ */
+ function closeVote() {
+ global $ID;
+
+ //if the doodle is already closed or the user is not an admin of the doodle
+ if($this->params['closed'] || !$this->isDoodleAdmin())
+ return;
+
+ //close for the current session
+ $this->params['closed'] = true;
+
+ //close for life (update the file)
+ $file_content = rawWiki($ID);
+ $ok = false;
+
+ //check for title/id in case of multiple doodle on the page
+ $cpt = 0;
+ if(preg_match_all('/<doodle.*title="(.*)".*>/Us', $file_content, $out, PREG_PATTERN_ORDER))
+ {
+ foreach($out[1] as $title)
+ {
+ //once we found the title, add a "closeon" attribute to the vote
+ if($this->params['title'] === hsc(trim($title)))
+ {
+ //escape all backslashes
+ $title = preg_replace('#\\\#', '\\\\\\', $title);
+
+ //check if someone didn't already close the vote
+ if(preg_match('/closeon=/', $out[0][$cpt]) > 0)
+ return;
+
+ //add the closeon attribute with the date of right now
+ $new_file_content = preg_replace(
+ '/(title=\\Q"'.$title.'\\E".*)>/Us',
+ '$1 closeon="'.date(DATE_RSS).'">',
+ $file_content
+ );
+
+ $closed = $this->getLang('vote_closed');
+
+ //remove the cache for this page for the handle() function to be call
+ $cache = new cache_instructions($ID, wikiFN($ID));
+ $cache->removeCache();
+
+ //and save the page containing this new attribute
+ lock($ID);
+ saveWikiText($ID, $new_file_content, $closed." (\"$title\")", true);
+ unlock($ID);
+
+ //reindex the page
+ idx_addPage($ID);
+
+ //tell the user we have found and closed the vote
+ $this->template['msg'] = $closed;
+ $ok = true;
+ break;
+ }
+
+ $cpt++;
+ }
+
+ if(!$ok)
+ msg($this->getLang('doodle_not_found'), -1);
+ }
+ else
+ {
+ msg($this->getLang('no_doodle'), -1);
+ }
+ }
+
+
+ /**
+ * Check whether the user is a doodle admin or not
+ * return TRUE if the user is admin of the doodle, FALSE otherwise
+ */
+ function isDoodleAdmin()
+ {
+ global $INFO;
+
+ //the user has to be logged in to pretend to be admin
+ if(!$this->isLoggedIn())
+ return false;
+
+ //check adminGroups
+ if (!empty($this->params['adminGroups'])) {
+ $adminGroups = explode('|', $this->params['adminGroups']); // array of adminGroups
+ $usersGroups = $INFO['userinfo']['grps']; // array of groups that the user is in
+ if (count(array_intersect($adminGroups, $usersGroups)) > 0)
+ return true;
+ }
+
+ //check adminUsers
+ if (!empty($this->params['adminUsers'])) {
+ $adminUsers = explode('|', $this->params['adminUsers']); // array of adminUsers
+ if(in_array(strtoupper($_SERVER['REMOTE_USER']), $adminUsers))
+ return true;
+ }
+
+ return false;
+ }
/**
* Loads the serialized doodle data from the file in the metadata directory.

No commit comments for this range

Something went wrong with that request. Please try again.