From fffba1655aa792a66da186cb8ea328682c456177 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 7 Sep 2022 23:37:07 +0200 Subject: [PATCH 01/14] refactor perm check --- helper.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/helper.php b/helper.php index 9621f1f..52165c3 100644 --- a/helper.php +++ b/helper.php @@ -419,9 +419,11 @@ function _vcategories($cat) { * Returns access classification for VTODO */ function _vclass($id) { - global $USERINFO; // checks access rights for anonymous user - if (auth_aclcheck($id, '', $USERINFO['grps'])) return 'PUBLIC'; - else return 'PRIVATE'; + if (auth_quickaclcheck($id) >= AUTH_READ) { + return 'PUBLIC'; + } else { + return 'PRIVATE'; + } } /** From 54067a023e152f08413ecbda7b37146c1c079263 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 7 Sep 2022 23:38:25 +0200 Subject: [PATCH 02/14] replace deprecated trigger_event --- helper.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/helper.php b/helper.php index 52165c3..59a0649 100644 --- a/helper.php +++ b/helper.php @@ -1,4 +1,7 @@ @@ -311,7 +314,7 @@ function _notify($task) { if ((!$conf['subscribers']) && (!$conf['notify'])) return; //subscribers enabled? $data = array('id' => $ID, 'addresslist' => '', 'self' => false); - trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, 'subscription_addresslist'); + Event::createAndTrigger('COMMON_NOTIFY_ADDRESSLIST', $data, 'subscription_addresslist'); $bcc = $data['addresslist']; if ((empty($bcc)) && (!$conf['notify'])) return; $to = $conf['notify']; From 907153eeac9dfd6f4620f4d3ddeff81484301ecb Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 7 Sep 2022 23:38:55 +0200 Subject: [PATCH 03/14] add missing perm info --- helper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/helper.php b/helper.php index 59a0649..c487950 100644 --- a/helper.php +++ b/helper.php @@ -133,6 +133,7 @@ function getTasks($ns, $num = NULL, $filter = '', $user = NULL) { elseif (($date + 86400 < time()) && ($filter == 'due')) continue; elseif (($date + 86400 > time()) && ($filter == 'overdue')) continue; } + $perm = auth_quickaclcheck($id); $result[$task['key']] = array( 'id' => $id, From 168a1d1c271bdba2e9e24bba7303e554d704466d Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 7 Sep 2022 23:39:36 +0200 Subject: [PATCH 04/14] helper reformatting --- helper.php | 263 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 156 insertions(+), 107 deletions(-) diff --git a/helper.php b/helper.php index c487950..dec5e27 100644 --- a/helper.php +++ b/helper.php @@ -8,54 +8,56 @@ */ class helper_plugin_task extends DokuWiki_Plugin { - + function getMethods() { - $result = array(); - $result[] = array( + $result = []; + $result[] = [ 'name' => 'th', 'desc' => 'returns the header of the task column for pagelist', - 'return' => array('header' => 'string'), - ); - $result[] = array( + 'return' => ['header' => 'string'], + ]; + $result[] = [ 'name' => 'td', 'desc' => 'returns the status of the task', - 'params' => array('id' => 'string'), - 'return' => array('label' => 'string'), - ); - $result[] = array( + 'params' => ['id' => 'string'], + 'return' => ['label' => 'string'], + ]; + $result[] = [ 'name' => 'getTasks', 'desc' => 'get task pages, sorted by priority', - 'params' => array( + 'params' => [ 'namespace' => 'string', 'number (optional)' => 'integer', - 'filter (optional)' => 'string'), - 'return' => array('pages' => 'array'), - ); - $result[] = array( + 'filter (optional)' => 'string'], + 'return' => ['pages' => 'array'], + ]; + $result[] = [ 'name' => 'readTask', 'desc' => 'get a single task metafile', - 'params' => array('id' => 'string'), - 'return' => array('task on success, else false' => 'array, (boolean)'), - ); - $result[] = array( + 'params' => ['id' => 'string'], + 'return' => ['task on success, else false' => 'array, (boolean)'], + ]; + $result[] = [ 'name' => 'writeTask', 'desc' => 'save task metdata in a file', - 'params' => array( + 'params' => [ 'id' => 'string', - 'task' => 'array'), - 'return' => array('success' => 'boolean'), - ); - $result[] = array( + 'task' => 'array'], + 'return' => ['success' => 'boolean'], + ]; + $result[] = [ 'name' => 'statusLabel', 'desc' => 'returns the status label for a given integer', - 'params' => array('status' => 'integer'), - 'return' => array('label' => 'string'), - ); + 'params' => ['status' => 'integer'], + 'return' => ['label' => 'string'], + ]; return $result; } - + /** * Returns the column header for the Pagelist Plugin + * + * @return string header text, escaped by Pagelist */ function th() { return $this->getLang('status'); @@ -63,6 +65,12 @@ function th() { /** * Returns the status of the task + * + * Used by pagelist plugin for filling the cells of the table + * and in listing by the tagfilter + * + * @param string $id page id of row + * @return string html with escaped values */ function td($id) { $task = $this->readTask($id); @@ -72,23 +80,23 @@ function td($id) { /** * Returns an array of task pages, sorted by priority */ - function getTasks($ns, $num = NULL, $filter = '', $user = NULL) { + function getTasks($ns, $num = null, $filter = '', $user = null) { global $conf; - if (!$filter) $filter = strtolower($_REQUEST['filter']); - - require_once(DOKU_INC.'inc/search.php'); + if (!$filter) { + $filter = strtolower($_REQUEST['filter']); + } $dir = $conf['datadir'].($ns ? '/'.str_replace(':', '/', $ns): ''); // returns the list of pages in the given namespace and it's subspaces - $items = array(); - $opts = array(); + $items = []; + $opts = []; $ns = utf8_encodeFN(str_replace(':', '/', $ns)); search($items, $conf['datadir'], 'search_allpages', $opts, $ns); // add pages with comments to result - $result = array(); + $result = []; foreach ($items as $item) { $id = $item['id']; @@ -117,25 +125,25 @@ function getTasks($ns, $num = NULL, $filter = '', $user = NULL) { if ($task['status'] != 4) continue; } else { // No pure status filter, skip done and closed tasks - if (($task['status'] < 0) || ($task['status'] > 2)) continue; + if ($task['status'] < 0 || $task['status'] > 2) continue; } } // skip other's tasks if filter is 'my' - if (($filter == 'my') && (!$responsible)) continue; + if ($filter == 'my' && !$responsible) continue; // skip assigned and not new tasks if filter is 'new' - if (($filter == 'new') && ($task['user']['name'] || ($task['status'] != 0))) continue; + if ($filter == 'new' && ($task['user']['name'] || $task['status'] != 0)) continue; - // filter is 'due' or 'overdue' - if (in_array($filter, array('due', 'overdue'))) { + // filter is 'due' or 'overdue' + if (in_array($filter, ['due', 'overdue'])) { if (!$date || ($date > time()) || ($task['status'] > 2)) continue; elseif (($date + 86400 < time()) && ($filter == 'due')) continue; elseif (($date + 86400 > time()) && ($filter == 'overdue')) continue; - } + } $perm = auth_quickaclcheck($id); - $result[$task['key']] = array( + $result[$task['key']] = [ 'id' => $id, 'date' => $date, 'user' => $task['user']['name'], @@ -144,13 +152,15 @@ function getTasks($ns, $num = NULL, $filter = '', $user = NULL) { 'perm' => $perm, 'file' => $task['file'], 'exists' => true, - ); + ]; } // finally sort by time of last comment krsort($result); - if (is_numeric($num)) $result = array_slice($result, 0, $num); + if (is_numeric($num)) { + $result = array_slice($result, 0, $num); + } return $result; } @@ -163,15 +173,19 @@ function readTask($id) { if (!@file_exists($file)) { $data = p_get_metadata($id, 'task'); if (is_array($data)) { - $data['date'] = array('due' => $data['date']); - $data['user'] = array('name' => $data['user']); - $meta = array('task' => NULL); - if ($this->writeTask($id, $data)) p_set_metadata($id, $meta); + $data['date'] = ['due' => $data['date']]; + $data['user'] = ['name' => $data['user']]; + $meta = ['task' => null]; + if ($this->writeTask($id, $data)) { + p_set_metadata($id, $meta); + } } } else { $data = unserialize(io_readFile($file, false)); } - if (!is_array($data) || empty($data)) return false; + if (!is_array($data) || empty($data)) { + return false; + } $data['file'] = $file; $data['exists'] = true; return $data; @@ -181,22 +195,28 @@ function readTask($id) { * Saves the .task metafile */ function writeTask($id, $data) { - if (!is_array($data)) return false; - $file = ($data['file'] ? $data['file'] : metaFN($id, '.task')); + if (!is_array($data)) { + return false; + } + $file = ($data['file'] ?: metaFN($id, '.task')); // remove file and exists keys unset($data['file']); unset($data['exists']); // set creation or modification time - if (!is_array($data['date'])) $data['date'] = array('due' => $data['date']); + if (!is_array($data['date'])) { + $data['date'] = ['due' => $data['date']]; + } if (!@file_exists($file) || !$data['date']['created']) { $data['date']['created'] = time(); } else { $data['date']['modified'] = time(); } - if (!is_array($data['user'])) $data['user'] = array('name' => $data['user']); + if (!is_array($data['user'])) { + $data['user'] = ['name' => $data['user']]; + } if (!isset($data['status'])) { // make sure we don't overwrite status $current = unserialize(io_readFile($file, false)); @@ -259,11 +279,17 @@ function priorityLabel($priority) { * Is the given task assigned to the current user? */ function _isResponsible($user) { - global $INFO; + global $INFO, $INPUT; - if (!$user) return false; + if (!$user) { + return false; + } - if (isset($user['id']) && $user['id'] == $_SERVER['REMOTE_USER'] || isset($user['name']) && $user['name'] == $INFO['userinfo']['name'] || $user == $INFO['userinfo']['name']) { + if ( + isset($user['id']) && $user['id'] == $INPUT->server->str('REMOTE_USER') + || isset($user['name']) && $user['name'] == $INFO['userinfo']['name'] + || $user == $INFO['userinfo']['name'] + ) { return true; } @@ -274,7 +300,9 @@ function _isResponsible($user) { * Interpret date with strtotime() */ function _interpretDate($str) { - if (!$str) return NULL; + if (!$str) { + return null; + } // only year given -> time till end of year if (preg_match("/^\d{4}$/", $str)) { @@ -297,7 +325,9 @@ function _interpretDate($str) { // convert to UNIX time $date = strtotime($str); - if ($date === -1) $date = NULL; + if ($date === -1) { + $date = null; + } return $date; } @@ -313,11 +343,16 @@ function _notify($task) { global $conf; global $ID; - if ((!$conf['subscribers']) && (!$conf['notify'])) return; //subscribers enabled? - $data = array('id' => $ID, 'addresslist' => '', 'self' => false); + //subscribers enabled? + if (!$conf['subscribers'] && !$conf['notify']) { + return; + } + $data = ['id' => $ID, 'addresslist' => '', 'self' => false]; Event::createAndTrigger('COMMON_NOTIFY_ADDRESSLIST', $data, 'subscription_addresslist'); $bcc = $data['addresslist']; - if ((empty($bcc)) && (!$conf['notify'])) return; + if (empty($bcc) && !$conf['notify']) { + return; + } $to = $conf['notify']; $text = io_readFile($this->localFN('subscribermail')); @@ -336,8 +371,11 @@ function _notify($task) { $text = str_replace('@DOKUWIKIURL@', DOKU_URL, $text); $subject = '['.$conf['title'].'] '; - if ($task['status'] == 0) $subject .= $this->getLang('mail_newtask'); - else $subject .= $this->getLang('mail_changedtask'); + if ($task['status'] == 0) { + $subject .= $this->getLang('mail_newtask'); + } else { + $subject .= $this->getLang('mail_changedtask'); + } mail_send($to, $subject, $text, $conf['mailfrom'], '', $bcc); } @@ -354,23 +392,32 @@ function _vtodo($id, $task) { 'UID:'.$id.'@'.$_SERVER['SERVER_NAME'].CRLF. 'URL:'.wl($id, '', true, '&').CRLF. 'SUMMARY:'.$this->_vsc($meta['title']).CRLF; - if ($meta['description']['abstract']) - $ret .= 'DESCRIPTION:'.$this->_vsc($meta['description']['abstract']).CRLF; - if ($meta['subject']) - $ret .= 'CATEGORIES:'.$this->_vcategories($meta['subject']).CRLF; - if ($task['date']['created']) - $ret .= 'CREATED:'.$this->_vdate($task['date']['created']).CRLF; - if ($task['date']['modified']) - $ret .= 'LAST-MODIFIED:'.$this->_vdate($task['date']['modified']).CRLF; - if ($task['date']['due']) - $ret .= 'DUE:'.$this->_vdate($task['date']['due']).CRLF; - if ($task['date']['completed']) - $ret .= 'COMPLETED:'.$this->_vdate($task['date']['completed']).CRLF; - if ($task['user']) $ret .= 'ORGANIZER;CN="'.$this->_vsc($task['user']['name']).'":'. - 'MAILTO:'.$task['user']['mail'].CRLF; + if ($meta['description']['abstract']) { + $ret .= 'DESCRIPTION:' . $this->_vsc($meta['description']['abstract']) . CRLF; + } + if ($meta['subject']) { + $ret .= 'CATEGORIES:' . $this->_vcategories($meta['subject']) . CRLF; + } + if ($task['date']['created']) { + $ret .= 'CREATED:' . $this->_vdate($task['date']['created']) . CRLF; + } + if ($task['date']['modified']) { + $ret .= 'LAST-MODIFIED:' . $this->_vdate($task['date']['modified']) . CRLF; + } + if ($task['date']['due']) { + $ret .= 'DUE:' . $this->_vdate($task['date']['due']) . CRLF; + } + if ($task['date']['completed']) { + $ret .= 'COMPLETED:' . $this->_vdate($task['date']['completed']) . CRLF; + } + if ($task['user']) { + $ret .= 'ORGANIZER;CN="' . $this->_vsc($task['user']['name']) . '":' . + 'MAILTO:' . $task['user']['mail'] . CRLF; + } $ret .= 'STATUS:'.$this->_vstatus($task['status']).CRLF; - if (is_numeric($task['priority'])) - $ret .= 'PRIORITY:'.(7 - ($task['priority'] * 2)).CRLF; + if (is_numeric($task['priority'])) { + $ret .= 'PRIORITY:' . (7 - ($task['priority'] * 2)) . CRLF; + } $ret .= 'CLASS:'.$this->_vclass($id).CRLF. 'END:VTODO'.CRLF; return $ret; @@ -380,8 +427,8 @@ function _vtodo($id, $task) { * Encodes vCard / iCal special characters */ function _vsc($string) { - $search = array("\\", ",", ";", "\n", "\r"); - $replace = array("\\\\", "\\,", "\\;", "\\n", "\\n"); + $search = ["\\", ",", ";", "\n", "\r"]; + $replace = ["\\\\", "\\,", "\\;", "\\n", "\\n"]; return str_replace($search, $replace, $string); } @@ -389,8 +436,11 @@ function _vsc($string) { * Generates YYYYMMDD"T"hhmmss"Z" UTC time date format (ISO 8601 / RFC 3339) */ function _vdate($date, $extended = false) { - if ($extended) return strftime('%Y-%m-%dT%H:%M:%SZ', $date); - else return strftime('%Y%m%dT%H%M%SZ', $date); + if ($extended) { + return strftime('%Y-%m-%dT%H:%M:%SZ', $date); + } else { + return strftime('%Y%m%dT%H%M%SZ', $date); + } } /** @@ -400,10 +450,10 @@ function _vstatus($status) { switch ($status) { case -1: return 'CANCELLED'; - case 1: + case 1: case 2: return 'IN-PROCESS'; - case 3: + case 3: case 4: return 'COMPLETED'; default: @@ -415,7 +465,9 @@ function _vstatus($status) { * Returns VTODO categories */ function _vcategories($cat) { - if (!is_array($cat)) $cat = explode(' ', $cat); + if (!is_array($cat)) { + $cat = explode(' ', $cat); + } return join(',', $this->_vsc($cat)); } @@ -433,16 +485,16 @@ function _vclass($id) { /** * Show the form to create a new task. * The function just forwards the call to the old or new function. - * + * * @param string $ns The DokuWiki namespace in which the new task * page shall be created * @param bool $selectUser If false then create a simple input line for the user field. * If true then create a drop down list. - * @param bool $selectUserGroup If not NULL and if $selectUser==true then the drop down list + * @param bool $selectUserGroup If not null and if $selectUser==true then the drop down list * for the user field will only show users who are members of * the user group given in $selectUserGroup. */ - function _newTaskForm($ns, $selectUser=false, $selectUserGroup=NULL) { + function _newTaskForm($ns, $selectUser=false, $selectUserGroup=null) { if (class_exists('dokuwiki\Form\Form')) { return $this->_newTaskFormNew($ns, $selectUser, $selectUserGroup); } else { @@ -453,13 +505,13 @@ function _newTaskForm($ns, $selectUser=false, $selectUserGroup=NULL) { /** * Show the form to create a new task. * This is the new version using class dokuwiki\Form\Form. - * + * * @see _newTaskForm */ - protected function _newTaskFormNew($ns, $selectUser=false, $selectUserGroup=NULL) { + protected function _newTaskFormNew($ns, $selectUser=false, $selectUserGroup=null) { global $ID, $lang, $INFO, $auth; - $form = new dokuwiki\Form\Form(array('id' => 'task__newtask_form')); + $form = new dokuwiki\Form\Form(['id' => 'task__newtask_form']); $pos = 1; // Open fieldset @@ -471,7 +523,7 @@ protected function _newTaskFormNew($ns, $selectUser=false, $selectUserGroup=NULL $form->setHiddenField ('ns', $ns); // Set input filed for task title - $input = $form->addTextInput('title', NULL, $pos++); + $input = $form->addTextInput('title', null, $pos++); $input->attr('id', 'task__newtask_title'); $input->attr('size', '40'); @@ -479,19 +531,19 @@ protected function _newTaskFormNew($ns, $selectUser=false, $selectUserGroup=NULL $form->addHTML('', $pos++); @@ -499,21 +551,19 @@ protected function _newTaskFormNew($ns, $selectUser=false, $selectUserGroup=NULL // Field for due date if ($this->getConf('datefield')) { $form->addHTML('', $pos++); } // Select priority from drop down list $form->addHTML('', $pos++); @@ -521,7 +571,7 @@ protected function _newTaskFormNew($ns, $selectUser=false, $selectUserGroup=NULL $form->addHTML('
'.$this->getLang('user').':', $pos++); if(!$selectUser) { // Old way input field - $input = $form->addTextInput('user', NULL, $pos++); + $input = $form->addTextInput('user', null, $pos++); $input->attr('value', hsc($INFO['userinfo']['name'])); } else { // Select user from drop down list - $filter = array(); + $filter = []; $filter['grps'] = $selectUserGroup; - $options = array(); + $options = []; if ($auth) { foreach ($auth->retrieveUsers(0, 0, $filter) as $curr_user) { $options [] = $curr_user['name']; } } - $input = $form->addDropdown('user', $options, NULL, $pos++); + $input = $form->addDropdown('user', $options, null, $pos++); $input->val($INFO['userinfo']['name']); } $form->addHTML('
'.$this->getLang('date').':', $pos++); - $input = $form->addTextInput('date', NULL, $pos++); + $input = $form->addTextInput('date', null, $pos++); $input->attr('value', date('Y-m-d')); $form->addHTML('
'.$this->getLang('priority').':'); - $filter = array(); - $filter['grps'] = $selectUserGroup; - $options = array(); + $options = []; $options [''] = $this->getLang('low'); $options ['!'] = $this->getLang('medium'); $options ['!!'] = $this->getLang('high'); $options ['!!!'] = $this->getLang('critical'); - $input = $form->addDropdown('priority', $options, NULL, $pos++); + $input = $form->addDropdown('priority', $options, null, $pos++); $input->attr('size', '1'); $input->val($this->getLang('low')); $form->addHTML('
', $pos++); // Add button - $form->addButton(NULL, $lang['btn_create'], $pos++); + $form->addButton(null, $lang['btn_create'], $pos++); // Close fieldset $form->addFieldsetClose($pos++); @@ -537,10 +587,10 @@ protected function _newTaskFormNew($ns, $selectUser=false, $selectUserGroup=NULL /** * Show the form to create a new task. * This is the old version, creating all HTML code on its own. - * + * * @see _newTaskForm */ - protected function _newTaskFormOld($ns, $selectUser=false, $selectUserGroup=NULL) { + protected function _newTaskFormOld($ns, $selectUser=false, $selectUserGroup=null) { global $ID, $lang, $INFO, $auth; $ret = '
'; @@ -562,7 +612,7 @@ protected function _newTaskFormOld($ns, $selectUser=false, $selectUserGroup=NULL $ret .= ''.$this->getLang('user').':'; $ret .= ''; @@ -264,7 +287,7 @@ function _statusMenuOld($options, $status) { /** * Returns the download link for the iCal file */ - function _icsDownload() { + protected function _icsDownload() { global $ID; global $INFO; @@ -283,20 +306,19 @@ function _icsDownload() { /** * Returns the organizer in hCalendar format as hCard */ - function _hCalUser($user) { + protected function _hCalUser($user) { return '' . hsc($user) . ''; } /** * Returns the date in hCalendar format */ - function _hCalDate($date) { + protected function _hCalDate($date) { global $conf; // strip time from preferred date format - $onlydate = preg_replace('#%[HIMprRST]|:#', '', ($conf['dformat'])); + $onlydate = preg_replace('#%[HIMprRST]|:#', '', $conf['dformat']); - return '' . strftime($onlydate, $date) . ''; + return '' . strftime($onlydate, $date) . ''; } } -// vim:ts=4:sw=4:et:enc=utf-8: diff --git a/syntax/taskform.php b/syntax/taskform.php index 6dabd2d..e078779 100644 --- a/syntax/taskform.php +++ b/syntax/taskform.php @@ -7,7 +7,10 @@ */ class syntax_plugin_task_taskform extends DokuWiki_Syntax_Plugin { - protected $helper = NULL; + /** + * @var helper_plugin_task + */ + protected $helper = null; /** * Constructor. Loads helper plugin. @@ -16,15 +19,15 @@ public function __construct() { $this->helper = plugin_load('helper', 'task'); } - function getType() { return 'substition'; } - function getPType() { return 'block'; } - function getSort() { return 306; } + public function getType() { return 'substition'; } + public function getPType() { return 'block'; } + public function getSort() { return 306; } - function connectTo($mode) { + public function connectTo($mode) { $this->Lexer->addSpecialPattern('\{\{task>form>.+?\}\}', $mode, 'plugin_task_taskform'); } - function handle($match, $state, $pos, Doku_Handler $handler) { + public function handle($match, $state, $pos, Doku_Handler $handler) { global $ID; // strip {{task>form> from start and }} from end @@ -32,30 +35,35 @@ function handle($match, $state, $pos, Doku_Handler $handler) { list($ns, $flags) = array_pad(explode('&', $match, 2), 2,''); $flags = explode('&', $flags); - if (($ns == '*') || ($ns == ':')) $ns = ''; - elseif ($ns == '.') $ns = getNS($ID); - else $ns = cleanID($ns); + if ($ns == '*' || $ns == ':') { + $ns = ''; + } elseif ($ns == '.') { + $ns = getNS($ID); + } else { + $ns = cleanID($ns); + } - $selectUserGroup = NULL; + $selectUserGroup = null; foreach ($flags as $flag) { if (substr($flag, 0, 16) == 'selectUserGroup=') { $selectUserGroup = substr($flag, 16); $selectUserGroup = trim($selectUserGroup, '"'); } } - return array($ns, $flags, $selectUserGroup); + return [$ns, $flags, $selectUserGroup]; } - function render($mode, Doku_Renderer $renderer, $data) { - if ($mode != 'xhtml') { - false; + public function render($format, Doku_Renderer $renderer, $data) { + if ($format != 'xhtml') { + return false; } list($ns, $flags, $selectUserGroup) = $data; $selectUser = in_array('selectUser', $flags); - if ($this->helper) $renderer->doc .= $this->helper->newTaskForm($ns, $selectUser, $selectUserGroup); + if ($this->helper) { + $renderer->doc .= $this->helper->newTaskForm($ns, $selectUser, $selectUserGroup); + } return true; } } -// vim:et:ts=4:sw=4:enc=utf-8: diff --git a/syntax/tasks.php b/syntax/tasks.php index e0b4265..74452c7 100644 --- a/syntax/tasks.php +++ b/syntax/tasks.php @@ -7,7 +7,8 @@ */ class syntax_plugin_task_tasks extends DokuWiki_Syntax_Plugin { - protected $helper = NULL; + /** @var helper_plugin_task */ + protected $helper = null; /** * Constructor. Loads helper plugin. @@ -16,15 +17,22 @@ public function __construct() { $this->helper = plugin_load('helper', 'task'); } - function getType() { return 'substition'; } - function getPType() { return 'block'; } - function getSort() { return 306; } + public function getType() { return 'substition'; } + public function getPType() { return 'block'; } + public function getSort() { return 306; } - function connectTo($mode) { + public function connectTo($mode) { $this->Lexer->addSpecialPattern('\{\{tasks>.+?\}\}', $mode, 'plugin_task_tasks'); } - function handle($match, $state, $pos, Doku_Handler $handler) { + /** + * @param string $match The text matched by the patterns + * @param int $state The lexer state for the match + * @param int $pos The character position of the matched text + * @param Doku_Handler $handler The Doku_Handler object + * @return array Return an array with all data you want to use in render, false don't add an instruction + */ + public function handle($match, $state, $pos, Doku_Handler $handler) { global $ID; $match = substr($match, 8, -2); // strip {{topic> from start and }} from end @@ -33,32 +41,49 @@ function handle($match, $state, $pos, Doku_Handler $handler) { list($match, $refine) = array_pad(explode(' ', $match, 2),2,''); list($ns, $filter) = array_pad(explode('?', $match, 2),2,''); - if (($ns == '*') || ($ns == ':')) $ns = ''; - elseif ($ns == '.') $ns = getNS($ID); - else $ns = cleanID($ns); + if ($ns == '*' || $ns == ':') { + $ns = ''; + } elseif ($ns == '.') { + $ns = getNS($ID); + } else { + $ns = cleanID($ns); + } - return array($ns, $filter, $flags, $refine); + return [$ns, $filter, $flags, $refine]; } - function render($mode, Doku_Renderer $renderer, $data) { + /** + * @param string $format output format being rendered + * @param Doku_Renderer $renderer the current renderer object + * @param array $data data created by handler() + * @return bool rendered correctly? (however, returned value is not used at the moment) + */ + public function render($format, Doku_Renderer $renderer, $data) { global $conf; list($ns, $filter, $flags, $refine) = $data; - if (!$filter || ($filter == 'select')) { + if (!$filter || $filter == 'select') { $select = true; $filter = trim($_REQUEST['filter']); } $filter = strtolower($filter); $filters = $this->_viewFilters(); - if (!in_array($filter, $filters)) $filter = 'open'; - if(isset($_REQUEST['view_user'])) $user = $_REQUEST['view_user']; + if (!in_array($filter, $filters)) { + $filter = 'open'; + } + if(isset($_REQUEST['view_user'])) { + $user = $_REQUEST['view_user']; + } - if ($this->helper) $pages = $this->helper->getTasks($ns, NULL, $filter, $user); + if ($this->helper) { + $pages = $this->helper->getTasks($ns, null, $filter, $user); + } // use tag refinements? if ($refine) { - if (plugin_isdisabled('tag') || (!$tag = plugin_load('helper', 'tag'))) { + /** @var helper_plugin_tag $tag */ + if (!$tag = $this->loadHelper('tag', false)) { msg('The Tag Plugin must be installed to use tag refinements.', -1); } else { $pages = $tag->tagRefine($pages, $refine); @@ -66,12 +91,18 @@ function render($mode, Doku_Renderer $renderer, $data) { } if(!$pages) { - if($mode != 'xhtml') return true; + if($format != 'xhtml') { + return true; + } $renderer->nocache(); - if($select) $renderer->doc .= $this->_viewMenu($filter); + if($select) { + $renderer->doc .= $this->_viewMenu($filter); + } if(auth_quickaclcheck($ns.':*') >= AUTH_CREATE) { if(!in_array('noform', $flags)) { - if ($this->helper) $renderer->doc .= $this->helper->newTaskForm($ns); + if ($this->helper) { + $renderer->doc .= $this->helper->newTaskForm($ns); + } } } return true; // nothing to display @@ -83,12 +114,14 @@ function render($mode, Doku_Renderer $renderer, $data) { if ($c > $perpage) { $numOfPages = ceil($c / $perpage); $first = $_REQUEST['first']; - if (!is_numeric($first)) $first = 0; + if (!is_numeric($first)) { + $first = 0; + } $currentPage = round($first / $perpage) + 1; $pages = array_slice($pages, $first, $perpage); } - if ($mode == 'xhtml') { + if ($format == 'xhtml') { // prevent caching to ensure content is always fresh $renderer->nocache(); @@ -97,19 +130,23 @@ function render($mode, Doku_Renderer $renderer, $data) { $perm_create = (auth_quickaclcheck($ns.':*') >= AUTH_CREATE); if($perm_create && ($this->getConf('tasks_formposition') == 'top')) { if(!in_array('noform', $flags)) { - if ($this->helper) $renderer->doc .= $this->helper->newTaskForm($ns); + if ($this->helper) { + $renderer->doc .= $this->helper->newTaskForm($ns); + } } } // let Pagelist Plugin do the work for us - if (plugin_isdisabled('pagelist') - || (!$pagelist = plugin_load('helper', 'pagelist'))) { + /** @var helper_plugin_pagelist $pagelist */ + if (!$pagelist = $this->loadHelper('pagelist', false)) { msg('The Pagelist Plugin must be installed for task lists.', -1); return false; } // show view filter popup if not - if ($select) $renderer->doc .= $this->_viewMenu($filter); + if ($select) { + $renderer->doc .= $this->_viewMenu($filter); + } // prepare pagelist columns $pagelist->header['page'] = $this->getLang('task'); @@ -141,7 +178,8 @@ function render($mode, Doku_Renderer $renderer, $data) { return true; // for metadata renderer - } elseif ($mode == 'metadata') { + } elseif ($format == 'metadata') { + /** @var Doku_Renderer_metadata $renderer */ foreach ($pages as $page) { $renderer->meta['relation']['references'][$page['id']] = true; } @@ -157,7 +195,7 @@ function render($mode, Doku_Renderer $renderer, $data) { * Show a popup to select the task view filter. * Just forwards call to the old or new function. */ - function _viewMenu($filter) { + protected function _viewMenu($filter) { if (class_exists('dokuwiki\Form\Form')) { return $this->_viewMenuNew($filter); } else { @@ -171,12 +209,12 @@ function _viewMenu($filter) { * * @see _viewMenu */ - function _viewMenuNew($filter) { - global $ID, $lang; + protected function _viewMenuNew($filter) { + global $ID; $options = $this->_viewFilters(); - $form = new dokuwiki\Form\Form(array('id' => 'task__changeview_form')); + $form = new dokuwiki\Form\Form(['id' => 'task__changeview_form']); $pos = 1; $form->addHTML('', $pos++); if(isset($_SERVER['REMOTE_USER'])) { $form->addHTML('
'; - $ret .= ''.DOKU_LF; + $ret .= ''; return $ret; } /** * Returns the download link for the iCal file + * + * @return string html of link */ - protected function _icsDownload() { + protected function htmlIcsDownloadLink() { global $ID; global $INFO; @@ -296,29 +322,31 @@ protected function _icsDownload() { $link = DOKU_BASE.'lib/plugins/task/ics.php?id='.$ID; $src = DOKU_BASE.'lib/plugins/task/images/ics.gif'; - $out = '' + return '' . ''.$title.'' . ' '; - - return $out; } /** * Returns the organizer in hCalendar format as hCard + * + * @return string html */ - protected function _hCalUser($user) { + protected function htmlhCalUser($user) { return '' . hsc($user) . ''; } /** * Returns the date in hCalendar format + * + * @return string html */ - protected function _hCalDate($date) { + protected function htmlhCalDate($date) { global $conf; // strip time from preferred date format - $onlydate = preg_replace('#%[HIMprRST]|:#', '', $conf['dformat']); + $onlydateformat = preg_replace('#%[HIMprRST]|:#', '', $conf['dformat']); - return '' . strftime($onlydate, $date) . ''; + return '' . strftime($onlydateformat, $date) . ''; } } From c1bef39f6d3f5a952bd3189cf75d497960dde429 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Thu, 20 Oct 2022 14:23:09 +0200 Subject: [PATCH 13/14] use $INPUT, reformatting, phpdocs --- action.php | 44 +++++++++++--------- helper.php | 46 ++++++++++----------- syntax/task.php | 26 ++++++------ syntax/tasks.php | 103 +++++++++++++++++++++++++---------------------- 4 files changed, 115 insertions(+), 104 deletions(-) diff --git a/action.php b/action.php index 023c436..61441e9 100644 --- a/action.php +++ b/action.php @@ -40,11 +40,10 @@ public function handleTaskActions($event, $param) { * Creates a new task page */ protected function newTask() { - global $ID; - global $INFO; + global $ID, $INFO, $INPUT; - $ns = cleanID($_REQUEST['ns']); - $title = str_replace(':', '', $_REQUEST['title']); + $ns = cleanID($INPUT->post->str('ns')); + $title = str_replace(':', '', $INPUT->post->str('title')); $back = $ID; $ID = ($ns ? $ns.':' : '').cleanID($title); $INFO = pageinfo(); @@ -63,12 +62,12 @@ protected function newTask() { if (!@file_exists($INFO['filepath'])) { global $TEXT; - $user = $_REQUEST['user']; - $date = $_REQUEST['date']; - $priority = $_REQUEST['priority']; + $user = $INPUT->post->str('user'); + $date = $INPUT->post->str('date'); + $priority = $INPUT->post->str('priority'); // create wiki page - $data = array( + $data = [ 'id' => $ID, 'ns' => $ns, 'title' => $title, @@ -76,7 +75,7 @@ protected function newTask() { 'priority' => $priority, 'user' => $user, 'date' => $date, - ); + ]; $TEXT = $this->_pageTemplate($data); return 'preview'; @@ -90,6 +89,17 @@ protected function newTask() { /** * Adapted version of pageTemplate() function + * + * @param array $data with: + * 'id' => string page id, + * 'ns' => string namespace, + * 'user' => string user id, + * 'date' => string date Y-m-d, + * 'back' => string page id of page to go back to, + * 'title' => string page title, + * 'priority' => string zero to three exclamation marks(!) + * + * @return string raw wiki text */ function _pageTemplate($data) { global $INFO; @@ -128,20 +138,18 @@ function _pageTemplate($data) { } // do the replace - $tpl = str_replace(array_keys($replace), array_values($replace), $tpl); - return $tpl; + return str_replace(array_keys($replace), array_values($replace), $tpl); } /** * Changes the status of a task */ protected function changeTask() { - global $ID; - global $INFO; + global $ID, $INFO, $INPUT; - $status = $_REQUEST['status']; + $status = $INPUT->post->int('status'); //TODO check if other default then 0? $status = trim($status); - if (!is_numeric($status) || $status < -1 || $status > 4) { + if (!is_numeric($status) || $status < -1 || $status > 4) { //FIXME is_numeric not needed if ($this->getConf('show_error_msg')) { $message = $this->getLang('msg_rcvd_invalid_status'); $message = str_replace('%status%', $status, $message); @@ -195,7 +203,7 @@ protected function changeTask() { // assign task to a user if (!$task['user']['name']) { // FIXME error message? - if (!$_SERVER['REMOTE_USER']) { + if (!$INPUT->server->has('REMOTE_USER')) { // no logged in user if ($this->getConf('show_info_msg')) { msg($this->getLang('msg_not_logged_in')); @@ -212,7 +220,7 @@ protected function changeTask() { } $task['user'] = [ - 'id' => $_SERVER['REMOTE_USER'], + 'id' => $INPUT->server->str('REMOTE_USER'), 'name' => $INFO['userinfo']['name'], 'mail' => $INFO['userinfo']['mail'], ]; @@ -222,7 +230,7 @@ protected function changeTask() { $oldstatus = $task['status']; $task['status'] = $status; $helper->writeTask($ID, $task); - $_REQUEST['purge'] = true; + $INPUT->set('purge', true); if ($this->getConf('show_success_msg')) { $message = $this->getLang('msg_status_changed'); diff --git a/helper.php b/helper.php index 7e12877..f9ced9c 100644 --- a/helper.php +++ b/helper.php @@ -97,14 +97,12 @@ public function td($id) { * ] */ public function getTasks($ns, $num = null, $filter = '', $user = null) { - global $conf; + global $conf, $INPUT; if (!$filter) { - $filter = strtolower($_REQUEST['filter']); + $filter = strtolower($INPUT->str('filter')); } - $dir = $conf['datadir'].($ns ? '/'.str_replace(':', '/', $ns): ''); - // returns the list of pages in the given namespace and it's subspaces $items = []; $opts = []; @@ -153,9 +151,9 @@ public function getTasks($ns, $num = null, $filter = '', $user = null) { // filter is 'due' or 'overdue' if (in_array($filter, ['due', 'overdue'])) { - if (!$date || ($date > time()) || ($task['status'] > 2)) continue; - elseif (($date + 86400 < time()) && ($filter == 'due')) continue; - elseif (($date + 86400 > time()) && ($filter == 'overdue')) continue; + if (!$date || $date > time() || $task['status'] > 2) continue; + elseif ($date + 86400 < time() && $filter == 'due') continue; + elseif ($date + 86400 > time() && $filter == 'overdue') continue; } $perm = auth_quickaclcheck($id); @@ -434,7 +432,7 @@ protected function notify($task) { $text = str_replace('@PAGE@', $ID, $text); $text = str_replace('@TITLE@', $conf['title'], $text); if(!empty($task['date']['due'])) { - $dformat = preg_replace('#%[HIMprRST]|:#', '', ($conf['dformat'])); + $dformat = preg_replace('#%[HIMprRST]|:#', '', $conf['dformat']); $text = str_replace('@DATE@', strftime($dformat, $task['date']['due']), $text); } else { $text = str_replace('@DATE@', '', $text); @@ -452,7 +450,7 @@ protected function notify($task) { $subject .= $this->getLang('mail_changedtask'); } - mail_send($to, $subject, $text, $conf['mailfrom'], '', $bcc); + mail_send($to, $subject, $text, $conf['mailfrom'], '', $bcc); //FIXME replace } /** @@ -607,10 +605,9 @@ protected function newTaskFormNew($ns, $selectUser=false, $selectUserGroup=null) global $ID, $lang, $INFO, $auth; $form = new dokuwiki\Form\Form(['id' => 'task__newtask_form']); - $pos = 1; // Open fieldset - $form->addFieldsetOpen($this->getLang('newtask'), $pos++); + $form->addFieldsetOpen($this->getLang('newtask')); // Set hidden fields $form->setHiddenField ('id', $ID); @@ -618,15 +615,15 @@ protected function newTaskFormNew($ns, $selectUser=false, $selectUserGroup=null) $form->setHiddenField ('ns', $ns); // Set input filed for task title - $input = $form->addTextInput('title', null, $pos++); + $input = $form->addTextInput('title', null); $input->attr('id', 'task__newtask_title'); $input->attr('size', '40'); // Set input field for user (either text field or drop down box) - $form->addHTML('
'.$this->getLang('user').':', $pos++); + $form->addHTML('', $pos++); + $form->addHTML(''); // Field for due date if ($this->getConf('datefield')) { - $form->addHTML('', $pos++); + $form->addHTML(''); } // Select priority from drop down list @@ -658,18 +655,18 @@ protected function newTaskFormNew($ns, $selectUser=false, $selectUserGroup=null) $options ['!'] = $this->getLang('medium'); $options ['!!'] = $this->getLang('high'); $options ['!!!'] = $this->getLang('critical'); - $input = $form->addDropdown('priority', $options, null, $pos++); + $input = $form->addDropdown('priority', $options, null); $input->attr('size', '1'); $input->val($this->getLang('low')); - $form->addHTML('', $pos++); + $form->addHTML(''); - $form->addHTML('
'.$this->getLang('user').':'); if(!$selectUser) { // Old way input field - $input = $form->addTextInput('user', null, $pos++); + $input = $form->addTextInput('user', null); $input->attr('value', hsc($INFO['userinfo']['name'])); } else { // Select user from drop down list @@ -638,17 +635,17 @@ protected function newTaskFormNew($ns, $selectUser=false, $selectUserGroup=null) $options [] = $curr_user['name']; } } - $input = $form->addDropdown('user', $options, null, $pos++); + $input = $form->addDropdown('user', $options, null); $input->val($INFO['userinfo']['name']); } - $form->addHTML('
'.$this->getLang('date').':', $pos++); - $input = $form->addTextInput('date', null, $pos++); + $form->addHTML('
'.$this->getLang('date').':'); + $input = $form->addTextInput('date', null); $input->attr('value', date('Y-m-d')); - $form->addHTML('
', $pos++); + $form->addHTML('
'); // Add button - $form->addButton(null, $lang['btn_create'], $pos++); + $form->addButton(null, $lang['btn_create']); // Close fieldset - $form->addFieldsetClose($pos++); + $form->addFieldsetClose(); // Generate the HTML-Representation of the form $ret = '
'; @@ -684,6 +681,7 @@ protected function newTaskFormNew($ns, $selectUser=false, $selectUserGroup=null) * This is the old version, creating all HTML code on its own. * * @see newTaskForm + * @deprecated 2017-03-30 */ protected function newTaskFormOld($ns, $selectUser=false, $selectUserGroup=null) { global $ID, $lang, $INFO, $auth; diff --git a/syntax/task.php b/syntax/task.php index 4405e7f..74eb512 100644 --- a/syntax/task.php +++ b/syntax/task.php @@ -70,7 +70,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { * @return boolean rendered correctly? */ public function render($format, Doku_Renderer $renderer, $data) { - global $ID; + global $ID, $INPUT; list($user, $date, $priority) = $data; @@ -87,10 +87,10 @@ public function render($format, Doku_Renderer $renderer, $data) { $task = $this->helper->readTask($ID); } - $status = $this->getStatus($user, $sn); + $status = $this->getStatus($user, $statusNumber); $due = ''; - if ($date && $sn < 3) { + if ($date && $statusNumber < 3) { if ($date + 86400 < time()) { $due = 'overdue'; } @@ -129,7 +129,7 @@ public function render($format, Doku_Renderer $renderer, $data) { } // show status update form only to logged in users - if(isset($_SERVER['REMOTE_USER'])) { + if($INPUT->server->has('REMOTE_USER')) { $this->renderTableRow('status', $status, $renderer); } @@ -247,9 +247,8 @@ protected function statusMenuNew($options, $status) { global $ID; $form = new dokuwiki\Form\Form(array('id' => 'task__changetask_form')); - $pos = 1; - $form->addHTML('
', $pos++); + $form->addHTML('
'); // Set hidden fields $form->setHiddenField ('id', $ID); @@ -262,15 +261,15 @@ protected function statusMenuNew($options, $status) { if ($status == $option) { $selected = $option.' '; } - $dropDownOptions [$option.' '] = $this->helper->statusLabel($option); + $dropDownOptions[$option.' '] = $this->helper->statusLabel($option); } - $input = $form->addDropdown('status', $dropDownOptions, null, $pos++); + $input = $form->addDropdown('status', $dropDownOptions, null); $input->val($selected); // Add button - $form->addButton(null, $this->getLang('btn_change'), $pos++); + $form->addButton(null, $this->getLang('btn_change')); - $form->addHTML('
', $pos++); + $form->addHTML('
'); return $form->toHTML(); } @@ -314,11 +313,10 @@ protected function statusMenuOld($options, $status) { * @return string html of link */ protected function htmlIcsDownloadLink() { - global $ID; - global $INFO; + global $ID, $INFO, $INPUT; - $uid = hsc($ID.'@'.$_SERVER['SERVER_NAME']); - $title = hsc($INFO['meta']['title']); + $uid = hsc($ID.'@'.$INPUT->server->str('SERVER_NAME')); + $title = hsc($INFO['meta']['title'] ?? ''); $link = DOKU_BASE.'lib/plugins/task/ics.php?id='.$ID; $src = DOKU_BASE.'lib/plugins/task/images/ics.gif'; diff --git a/syntax/tasks.php b/syntax/tasks.php index 74452c7..4124e09 100644 --- a/syntax/tasks.php +++ b/syntax/tasks.php @@ -59,23 +59,26 @@ public function handle($match, $state, $pos, Doku_Handler $handler) { * @return bool rendered correctly? (however, returned value is not used at the moment) */ public function render($format, Doku_Renderer $renderer, $data) { - global $conf; + global $conf, $INPUT; list($ns, $filter, $flags, $refine) = $data; + $select = false; if (!$filter || $filter == 'select') { $select = true; - $filter = trim($_REQUEST['filter']); + $filter = trim($INPUT->str('filter')); } $filter = strtolower($filter); - $filters = $this->_viewFilters(); + $filters = $this->viewFilters(); if (!in_array($filter, $filters)) { $filter = 'open'; } - if(isset($_REQUEST['view_user'])) { - $user = $_REQUEST['view_user']; + $user = ''; //FIXME getTasks() does not use $user... + if($INPUT->has('view_user')) { + $user = $INPUT->str('view_user'); } + $pages = []; if ($this->helper) { $pages = $this->helper->getTasks($ns, null, $filter, $user); } @@ -96,7 +99,7 @@ public function render($format, Doku_Renderer $renderer, $data) { } $renderer->nocache(); if($select) { - $renderer->doc .= $this->_viewMenu($filter); + $renderer->doc .= $this->viewMenu($filter); } if(auth_quickaclcheck($ns.':*') >= AUTH_CREATE) { if(!in_array('noform', $flags)) { @@ -111,13 +114,11 @@ public function render($format, Doku_Renderer $renderer, $data) { // prepare pagination $c = count($pages); $perpage = ($conf['recent'] != 0) ? $conf['recent'] : 20; // prevent division by zero + $numOfPages = $currentPage = 1; if ($c > $perpage) { $numOfPages = ceil($c / $perpage); - $first = $_REQUEST['first']; - if (!is_numeric($first)) { - $first = 0; - } - $currentPage = round($first / $perpage) + 1; + $first = $INPUT->int('first'); + $currentPage = round($first / $perpage) + 1; //TODO check 14/20=0.7==>1, 1+1=2? $pages = array_slice($pages, $first, $perpage); } @@ -127,8 +128,8 @@ public function render($format, Doku_Renderer $renderer, $data) { $renderer->nocache(); // show form to create a new task? - $perm_create = (auth_quickaclcheck($ns.':*') >= AUTH_CREATE); - if($perm_create && ($this->getConf('tasks_formposition') == 'top')) { + $hasCreatePermission = auth_quickaclcheck($ns.':*') >= AUTH_CREATE; + if($hasCreatePermission && $this->getConf('tasks_formposition') == 'top') { if(!in_array('noform', $flags)) { if ($this->helper) { $renderer->doc .= $this->helper->newTaskForm($ns); @@ -145,7 +146,7 @@ public function render($format, Doku_Renderer $renderer, $data) { // show view filter popup if not if ($select) { - $renderer->doc .= $this->_viewMenu($filter); + $renderer->doc .= $this->viewMenu($filter); } // prepare pagelist columns @@ -166,10 +167,10 @@ public function render($format, Doku_Renderer $renderer, $data) { $pagelist->addPage($page); } $renderer->doc .= $pagelist->finishList(); - $renderer->doc .= $this->_paginationLinks($numOfPages, $currentPage, $filter); + $renderer->doc .= $this->paginationLinks($numOfPages, $currentPage, $filter); // show form to create a new task? - if($perm_create && ($this->getConf('tasks_formposition') == 'bottom')) { + if($hasCreatePermission && ($this->getConf('tasks_formposition') == 'bottom')) { if(!in_array('noform', $flags)) { if ($this->helper) $renderer->doc .= $this->helper->newTaskForm($ns); } @@ -195,11 +196,11 @@ public function render($format, Doku_Renderer $renderer, $data) { * Show a popup to select the task view filter. * Just forwards call to the old or new function. */ - protected function _viewMenu($filter) { + protected function viewMenu($filter) { if (class_exists('dokuwiki\Form\Form')) { - return $this->_viewMenuNew($filter); + return $this->viewMenuNew($filter); } else { - return $this->_viewMenuOld($filter); + return $this->viewMenuOld($filter); } } @@ -207,12 +208,12 @@ protected function _viewMenu($filter) { * Show a popup to select the task view filter. * This is the new version using class dokuwiki\Form\Form. * - * @see _viewMenu + * @see viewMenu */ - protected function _viewMenuNew($filter) { - global $ID; + protected function viewMenuNew($filter) { + global $ID, $INPUT; - $options = $this->_viewFilters(); + $options = $this->viewFilters(); $form = new dokuwiki\Form\Form(['id' => 'task__changeview_form']); $pos = 1; @@ -238,11 +239,11 @@ protected function _viewMenuNew($filter) { $form->addHTML('', $pos++); - if(isset($_SERVER['REMOTE_USER'])) { + if($INPUT->server->has('REMOTE_USER')) { $form->addHTML('', $pos++); @@ -262,12 +263,12 @@ protected function _viewMenuNew($filter) { * Show a popup to select the task view filter. * Old function generating all HTML on its own. * - * @see _viewMenu + * @see viewMenu */ - protected function _viewMenuOld($filter) { - global $ID, $lang; + protected function viewMenuOld($filter) { + global $ID, $lang, $INPUT; - $options = $this->_viewFilters(); + $options = $this->viewFilters(); $ret = '
'; $ret .= '
'; @@ -288,10 +289,10 @@ protected function _viewMenuOld($filter) { $ret .= ''; $ret .= ''; - if(isset($_SERVER['REMOTE_USER'])) { + if($INPUT->server->has('REMOTE_USER')) { $ret .= ''; } @@ -304,11 +305,12 @@ protected function _viewMenuOld($filter) { /** * Returns an array of available view filters for the task list */ - protected function _viewFilters() { - if (!$_SERVER['REMOTE_USER']) { - $filters = ['all', 'open', 'done']; - } else { + protected function viewFilters() { + global $INPUT; + if ($INPUT->server->has('REMOTE_USER')) { $filters = ['all', 'open', 'new', 'done', 'my', 'rejected', 'started', 'accepted', 'verified']; + } else { + $filters = ['all', 'open', 'done']; } if ($this->getConf('datefield')) { $filters[] = 'due'; @@ -318,10 +320,15 @@ protected function _viewFilters() { } /** - * Returns pagination links if more than one page - */ - protected function _paginationLinks($num, $cur, $filter) { - global $ID, $conf; + * Returns html of pagination links if more than one page + * + * @param int $num number of pagination pages + * @param int $cur current pagination page no + * @param string $filter current active filter + * @return string html of pagination links + */ + protected function paginationLinks($num, $cur, $filter) { + global $ID, $conf, $INPUT; if (!is_numeric($num) || $num < 2) { return ''; @@ -333,17 +340,17 @@ protected function _paginationLinks($num, $cur, $filter) { if ($i == $cur) { $ret[] = ''.$i.''; } else { - $opt = []; - $opt['first'] = $perpage * ($i - 1); - $opt['filter'] = $filter; - if(isset($_REQUEST['view_user'])) { + $param = []; + $param['first'] = $perpage * ($i - 1); + $param['filter'] = $filter; + if($INPUT->has('view_user')) { $user = []; - $user['id'] = $_REQUEST['view_user']; + $user['id'] = $INPUT->str('view_user'); if($this->helper->isResponsible($user)) { - $opt['view_user'] = $_REQUEST['view_user']; + $param['view_user'] = $INPUT->str('view_user'); } } - $ret[] = ''.$i.''; + $ret[] = ''.$i.''; } } return '
'. From 1e72c2ec9d0a0dcf949000c0ba50ac8d28940d61 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Thu, 20 Oct 2022 14:23:39 +0200 Subject: [PATCH 14/14] use new helper functions of pagelist plugin, deprecated old --- syntax/tasks.php | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/syntax/tasks.php b/syntax/tasks.php index 4124e09..4be461b 100644 --- a/syntax/tasks.php +++ b/syntax/tasks.php @@ -150,13 +150,31 @@ public function render($format, Doku_Renderer $renderer, $data) { } // prepare pagelist columns - $pagelist->header['page'] = $this->getLang('task'); - $pagelist->header['date'] = str_replace(' ', ' ', $this->getLang('date')); - $pagelist->header['user'] = str_replace(' ', ' ', $this->getLang('user')); - $pagelist->column['date'] = $this->getConf('datefield'); - $pagelist->column['user'] = true; - $pagelist->setFlags($flags); - $pagelist->addColumn('task', 'status'); + /* @deprecated 2022-10-17 */ + if(method_exists($pagelist, 'setHeader')) { + //since 2022-10-17 some new methods are introduced + $pagelist->setHeader([ + 'page' => $this->getLang('task'), + 'date' => str_replace(' ', ' ', $this->getLang('date')), + 'user' => str_replace(' ', ' ', $this->getLang('user')) + ]); + $pagelist->modifyColumn('date', $this->getConf('datefield')); + $pagelist->modifyColumn('user', true); + $pagelist->addColumn('task', 'status'); + $pagelist->setFlags(['header']); //allow override via user provided flags + $pagelist->setFlags($flags); + } else { + //before 2022-10-17 + $pagelist->header['page'] = $this->getLang('task'); + $pagelist->header['date'] = str_replace(' ', ' ', $this->getLang('date')); + $pagelist->header['user'] = str_replace(' ', ' ', $this->getLang('user')); + $pagelist->column['date'] = $this->getConf('datefield'); + $pagelist->column['user'] = true; + $pagelist->setFlags(['header']); //allow override via user provided flags + $pagelist->setFlags($flags); + $pagelist->addColumn('task', 'status'); + } + // output list $pagelist->startList();