diff options
Diffstat (limited to 'app/Helper')
-rw-r--r-- | app/Helper/AppHelper.php (renamed from app/Helper/App.php) | 13 | ||||
-rw-r--r-- | app/Helper/AssetHelper.php (renamed from app/Helper/Asset.php) | 9 | ||||
-rw-r--r-- | app/Helper/BoardHelper.php (renamed from app/Helper/Board.php) | 4 | ||||
-rw-r--r-- | app/Helper/DateHelper.php (renamed from app/Helper/Dt.php) | 49 | ||||
-rw-r--r-- | app/Helper/File.php | 56 | ||||
-rw-r--r-- | app/Helper/FileHelper.php | 109 | ||||
-rw-r--r-- | app/Helper/FormHelper.php (renamed from app/Helper/Form.php) | 31 | ||||
-rw-r--r-- | app/Helper/HookHelper.php (renamed from app/Helper/Hook.php) | 6 | ||||
-rw-r--r-- | app/Helper/LayoutHelper.php | 188 | ||||
-rw-r--r-- | app/Helper/ModelHelper.php | 94 | ||||
-rw-r--r-- | app/Helper/Subtask.php | 46 | ||||
-rw-r--r-- | app/Helper/SubtaskHelper.php | 95 | ||||
-rw-r--r-- | app/Helper/Task.php | 68 | ||||
-rw-r--r-- | app/Helper/TaskHelper.php | 186 | ||||
-rw-r--r-- | app/Helper/TextHelper.php (renamed from app/Helper/Text.php) | 38 | ||||
-rw-r--r-- | app/Helper/UrlHelper.php (renamed from app/Helper/Url.php) | 23 | ||||
-rw-r--r-- | app/Helper/UserHelper.php (renamed from app/Helper/User.php) | 6 |
17 files changed, 807 insertions, 214 deletions
diff --git a/app/Helper/App.php b/app/Helper/AppHelper.php index 0593795f..e6f6412d 100644 --- a/app/Helper/App.php +++ b/app/Helper/AppHelper.php @@ -5,23 +5,24 @@ namespace Kanboard\Helper; use Kanboard\Core\Base; /** - * Application helpers + * Application Helper * * @package helper * @author Frederic Guillot */ -class App extends Base +class AppHelper extends Base { /** * Get config variable * * @access public * @param string $param + * @param mixed $default_value * @return mixed */ - public function config($param) + public function config($param, $default_value = '') { - return $this->config->get($param); + return $this->config->get($param, $default_value); } /** @@ -115,11 +116,11 @@ class App extends Base $failure_message = $this->flash->getMessage('failure'); if (! empty($success_message)) { - return '<div class="alert alert-success alert-fade-out">'.$this->helper->e($success_message).'</div>'; + return '<div class="alert alert-success alert-fade-out">'.$this->helper->text->e($success_message).'</div>'; } if (! empty($failure_message)) { - return '<div class="alert alert-error">'.$this->helper->e($failure_message).'</div>'; + return '<div class="alert alert-error">'.$this->helper->text->e($failure_message).'</div>'; } return ''; diff --git a/app/Helper/Asset.php b/app/Helper/AssetHelper.php index c4178e8c..b3dc711f 100644 --- a/app/Helper/Asset.php +++ b/app/Helper/AssetHelper.php @@ -2,18 +2,21 @@ namespace Kanboard\Helper; +use Kanboard\Core\Base; + /** - * Assets helpers + * Asset Helper * * @package helper * @author Frederic Guillot */ -class Asset extends \Kanboard\Core\Base +class AssetHelper extends Base { /** * Add a Javascript asset * - * @param string $filename Filename + * @param string $filename Filename + * @param bool $async * @return string */ public function js($filename, $async = false) diff --git a/app/Helper/Board.php b/app/Helper/BoardHelper.php index 430d1858..a86a6c18 100644 --- a/app/Helper/Board.php +++ b/app/Helper/BoardHelper.php @@ -2,13 +2,15 @@ namespace Kanboard\Helper; +use Kanboard\Core\Base; + /** * Board Helper * * @package helper * @author Frederic Guillot */ -class Board extends \Kanboard\Core\Base +class BoardHelper extends Base { /** * Return true if tasks are collapsed diff --git a/app/Helper/Dt.php b/app/Helper/DateHelper.php index 78002b1b..3844ce64 100644 --- a/app/Helper/Dt.php +++ b/app/Helper/DateHelper.php @@ -3,6 +3,7 @@ namespace Kanboard\Helper; use DateTime; +use Kanboard\Core\Base; /** * DateTime helpers @@ -10,9 +11,53 @@ use DateTime; * @package helper * @author Frederic Guillot */ -class Dt extends \Kanboard\Core\Base +class DateHelper extends Base { /** + * Get formatted time + * + * @access public + * @param integer $value + * @return string + */ + public function time($value) + { + return date($this->config->get('application_time_format', 'H:i'), $value); + } + + /** + * Get formatted date + * + * @access public + * @param integer $value + * @return string + */ + public function date($value) + { + if (empty($value)) { + return ''; + } + + if (! ctype_digit($value)) { + $value = strtotime($value); + } + + return date($this->config->get('application_date_format', 'm/d/Y'), $value); + } + + /** + * Get formatted datetime + * + * @access public + * @param integer $value + * @return string + */ + public function datetime($value) + { + return date($this->config->get('application_datetime_format', 'm/d/Y H:i'), $value); + } + + /** * Get duration in seconds into human format * * @access public @@ -107,6 +152,6 @@ class Dt extends \Kanboard\Core\Base */ public function getWeekDay($day) { - return dt('%A', strtotime('next Monday +'.($day - 1).' days')); + return date('l', strtotime('next Monday +'.($day - 1).' days')); } } diff --git a/app/Helper/File.php b/app/Helper/File.php deleted file mode 100644 index d2cdfc6a..00000000 --- a/app/Helper/File.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php - -namespace Kanboard\Helper; - -/** - * File helpers - * - * @package helper - * @author Frederic Guillot - */ -class File extends \Kanboard\Core\Base -{ - /** - * Get file icon - * - * @access public - * @param string $filename Filename - * @return string Font-Awesome-Icon-Name - */ - public function icon($filename) - { - $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); - - switch ($extension) { - case 'jpeg': - case 'jpg': - case 'png': - case 'gif': - return 'fa-file-image-o'; - case 'xls': - case 'xlsx': - return 'fa-file-excel-o'; - case 'doc': - case 'docx': - return 'fa-file-word-o'; - case 'ppt': - case 'pptx': - return 'fa-file-powerpoint-o'; - case 'zip': - case 'rar': - return 'fa-file-archive-o'; - case 'mp3': - return 'fa-audio-o'; - case 'avi': - return 'fa-video-o'; - case 'php': - case 'html': - case 'css': - return 'fa-code-o'; - case 'pdf': - return 'fa-file-pdf-o'; - } - - return 'fa-file-o'; - } -} diff --git a/app/Helper/FileHelper.php b/app/Helper/FileHelper.php new file mode 100644 index 00000000..cabf371c --- /dev/null +++ b/app/Helper/FileHelper.php @@ -0,0 +1,109 @@ +<?php + +namespace Kanboard\Helper; + +use Kanboard\Core\Base; + +/** + * File helpers + * + * @package helper + * @author Frederic Guillot + */ +class FileHelper extends Base +{ + /** + * Get file icon + * + * @access public + * @param string $filename Filename + * @return string Font-Awesome-Icon-Name + */ + public function icon($filename) + { + $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + + switch ($extension) { + case 'jpeg': + case 'jpg': + case 'png': + case 'gif': + return 'fa-file-image-o'; + case 'xls': + case 'xlsx': + return 'fa-file-excel-o'; + case 'doc': + case 'docx': + return 'fa-file-word-o'; + case 'ppt': + case 'pptx': + return 'fa-file-powerpoint-o'; + case 'zip': + case 'rar': + case 'tar': + case 'bz2': + case 'xz': + case 'gz': + return 'fa-file-archive-o'; + case 'mp3': + return 'fa-file-audio-o'; + case 'avi': + case 'mov': + return 'fa-file-video-o'; + case 'php': + case 'html': + case 'css': + return 'fa-file-code-o'; + case 'pdf': + return 'fa-file-pdf-o'; + } + + return 'fa-file-o'; + } + + /** + * Return the image mimetype based on the file extension + * + * @access public + * @param $filename + * @return string + */ + public function getImageMimeType($filename) + { + $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + + switch ($extension) { + case 'jpeg': + case 'jpg': + return 'image/jpeg'; + case 'png': + return 'image/png'; + case 'gif': + return 'image/gif'; + default: + return 'image/jpeg'; + } + } + + /** + * Get the preview type + * + * @access public + * @param string $filename + * @return string + */ + public function getPreviewType($filename) + { + $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + + switch ($extension) { + case 'md': + case 'markdown': + return 'markdown'; + case 'txt': + return 'text'; + } + + return null; + } +} diff --git a/app/Helper/Form.php b/app/Helper/FormHelper.php index bfd75ee3..c2ea1d72 100644 --- a/app/Helper/Form.php +++ b/app/Helper/FormHelper.php @@ -10,7 +10,7 @@ use Kanboard\Core\Base; * @package helper * @author Frederic Guillot */ -class Form extends Base +class FormHelper extends Base { /** * Hidden CSRF token field @@ -40,11 +40,12 @@ class Form extends Base * Display a select field * * @access public - * @param string $name Field name - * @param array $options Options - * @param array $values Form values - * @param array $errors Form errors - * @param string $class CSS class + * @param string $name Field name + * @param array $options Options + * @param array $values Form values + * @param array $errors Form errors + * @param array $attributes + * @param string $class CSS class * @return string */ public function select($name, array $options, array $values = array(), array $errors = array(), array $attributes = array(), $class = '') @@ -52,7 +53,7 @@ class Form extends Base $html = '<select name="'.$name.'" id="form-'.$name.'" class="'.$class.'" '.implode(' ', $attributes).'>'; foreach ($options as $id => $value) { - $html .= '<option value="'.$this->helper->e($id).'"'; + $html .= '<option value="'.$this->helper->text->e($id).'"'; if (isset($values->$name) && $id == $values->$name) { $html .= ' selected="selected"'; @@ -61,7 +62,7 @@ class Form extends Base $html .= ' selected="selected"'; } - $html .= '>'.$this->helper->e($value).'</option>'; + $html .= '>'.$this->helper->text->e($value).'</option>'; } $html .= '</select>'; @@ -103,7 +104,7 @@ class Form extends Base */ public function radio($name, $label, $value, $selected = false, $class = '') { - return '<label><input type="radio" name="'.$name.'" class="'.$class.'" value="'.$this->helper->e($value).'" '.($selected ? 'checked="checked"' : '').'> '.$this->helper->e($label).'</label>'; + return '<label><input type="radio" name="'.$name.'" class="'.$class.'" value="'.$this->helper->text->e($value).'" '.($selected ? 'checked="checked"' : '').'> '.$this->helper->text->e($label).'</label>'; } /** @@ -139,7 +140,7 @@ class Form extends Base */ public function checkbox($name, $label, $value, $checked = false, $class = '') { - return '<label><input type="checkbox" name="'.$name.'" class="'.$class.'" value="'.$this->helper->e($value).'" '.($checked ? 'checked="checked"' : '').'> '.$this->helper->e($label).'</label>'; + return '<label><input type="checkbox" name="'.$name.'" class="'.$class.'" value="'.$this->helper->text->e($value).'" '.($checked ? 'checked="checked"' : '').'> '.$this->helper->text->e($label).'</label>'; } /** @@ -153,7 +154,7 @@ class Form extends Base */ public function label($label, $name, array $attributes = array()) { - return '<label for="form-'.$name.'" '.implode(' ', $attributes).'>'.$this->helper->e($label).'</label>'; + return '<label for="form-'.$name.'" '.implode(' ', $attributes).'>'.$this->helper->text->e($label).'</label>'; } /** @@ -173,7 +174,7 @@ class Form extends Base $html = '<textarea name="'.$name.'" id="form-'.$name.'" class="'.$class.'" '; $html .= implode(' ', $attributes).'>'; - $html .= isset($values->$name) ? $this->helper->e($values->$name) : isset($values[$name]) ? $values[$name] : ''; + $html .= isset($values->$name) ? $this->helper->text->e($values->$name) : isset($values[$name]) ? $values[$name] : ''; $html .= '</textarea>'; $html .= $this->errorList($errors, $name); @@ -334,7 +335,7 @@ class Form extends Base $html .= '<ul class="form-errors">'; foreach ($errors[$name] as $error) { - $html .= '<li>'.$this->helper->e($error).'</li>'; + $html .= '<li>'.$this->helper->text->e($error).'</li>'; } $html .= '</ul>'; @@ -354,9 +355,9 @@ class Form extends Base private function formValue($values, $name) { if (isset($values->$name)) { - return 'value="'.$this->helper->e($values->$name).'"'; + return 'value="'.$this->helper->text->e($values->$name).'"'; } - return isset($values[$name]) ? 'value="'.$this->helper->e($values[$name]).'"' : ''; + return isset($values[$name]) ? 'value="'.$this->helper->text->e($values[$name]).'"' : ''; } } diff --git a/app/Helper/Hook.php b/app/Helper/HookHelper.php index 7b691949..2d13ebcc 100644 --- a/app/Helper/Hook.php +++ b/app/Helper/HookHelper.php @@ -2,13 +2,15 @@ namespace Kanboard\Helper; +use Kanboard\Core\Base; + /** * Template Hook helpers * * @package helper * @author Frederic Guillot */ -class Hook extends \Kanboard\Core\Base +class HookHelper extends Base { /** * Add assets JS or CSS @@ -54,7 +56,7 @@ class Hook extends \Kanboard\Core\Base * @access public * @param string $hook * @param string $template - * @return \Helper\Hook + * @return \Kanboard\Helper\Hook */ public function attach($hook, $template) { diff --git a/app/Helper/LayoutHelper.php b/app/Helper/LayoutHelper.php new file mode 100644 index 00000000..9384da1b --- /dev/null +++ b/app/Helper/LayoutHelper.php @@ -0,0 +1,188 @@ +<?php + +namespace Kanboard\Helper; + +use Kanboard\Core\Base; + +/** + * Layout Helper + * + * @package helper + * @author Frederic Guillot + */ +class LayoutHelper extends Base +{ + /** + * Render a template without the layout if Ajax request + * + * @access public + * @param string $template Template name + * @param array $params Template parameters + * @return string + */ + public function app($template, array $params = array()) + { + if ($this->request->isAjax()) { + return $this->template->render($template, $params); + } + + if (! isset($params['no_layout']) && ! isset($params['board_selector'])) { + $params['board_selector'] = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + } + + return $this->pageLayout($template, $params); + } + + /** + * Common layout for user views + * + * @access public + * @param string $template Template name + * @param array $params Template parameters + * @return string + */ + public function user($template, array $params) + { + if (isset($params['user'])) { + $params['title'] = '#'.$params['user']['id'].' '.($params['user']['name'] ?: $params['user']['username']); + } + + return $this->subLayout('user/layout', 'user/sidebar', $template, $params); + } + + /** + * Common layout for task views + * + * @access public + * @param string $template Template name + * @param array $params Template parameters + * @return string + */ + public function task($template, array $params) + { + $params['title'] = $params['task']['project_name']; + return $this->subLayout('task/layout', 'task/sidebar', $template, $params); + } + + /** + * Common layout for project views + * + * @access public + * @param string $template + * @param array $params + * @param string $sidebar + * @return string + */ + public function project($template, array $params, $sidebar = 'project/sidebar') + { + if (empty($params['title'])) { + $params['title'] = $params['project']['name']; + } elseif ($params['project']['name'] !== $params['title']) { + $params['title'] = $params['project']['name'].' > '.$params['title']; + } + + return $this->subLayout('project/layout', $sidebar, $template, $params); + } + + /** + * Common layout for project user views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function projectUser($template, array $params) + { + $params['filter'] = array('user_id' => $params['user_id']); + return $this->subLayout('project_user/layout', 'project_user/sidebar', $template, $params); + } + + /** + * Common layout for config views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function config($template, array $params) + { + if (! isset($params['values'])) { + $params['values'] = $this->config->getAll(); + } + + if (! isset($params['errors'])) { + $params['errors'] = array(); + } + + return $this->subLayout('config/layout', 'config/sidebar', $template, $params); + } + + /** + * Common layout for dashboard views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function dashboard($template, array $params) + { + return $this->subLayout('app/layout', 'app/sidebar', $template, $params); + } + + /** + * Common layout for analytic views + * + * @access public + * @param string $template + * @param array $params + * @return string + */ + public function analytic($template, array $params) + { + return $this->subLayout('analytic/layout', 'analytic/sidebar', $template, $params); + } + + /** + * Render page layout + * + * @access public + * @param string $template Template name + * @param array $params Key/value dictionary + * @param string $layout Layout name + * @return string + */ + public function pageLayout($template, array $params = array(), $layout = 'layout') + { + return $this->template->render( + $layout, + $params + array('content_for_layout' => $this->template->render($template, $params)) + ); + } + + /** + * Common method to generate a sub-layout + * + * @access public + * @param string $sublayout + * @param string $sidebar + * @param string $template + * @param array $params + * @return string + */ + public function subLayout($sublayout, $sidebar, $template, array $params = array()) + { + $content = $this->template->render($template, $params); + + if ($this->request->isAjax()) { + return $content; + } + + $params['content_for_sublayout'] = $content; + $params['sidebar_template'] = $sidebar; + + return $this->app($sublayout, $params); + } +} diff --git a/app/Helper/ModelHelper.php b/app/Helper/ModelHelper.php new file mode 100644 index 00000000..d49637c8 --- /dev/null +++ b/app/Helper/ModelHelper.php @@ -0,0 +1,94 @@ +<?php + +namespace Kanboard\Helper; + +use Kanboard\Core\Base; + +/** + * Model Helper + * + * @package helper + * @author Frederic Guillot + */ +class ModelHelper extends Base +{ + /** + * Remove keys from an array + * + * @access public + * @param array $values Input array + * @param string[] $keys List of keys to remove + */ + public function removeFields(array &$values, array $keys) + { + foreach ($keys as $key) { + if (array_key_exists($key, $values)) { + unset($values[$key]); + } + } + } + + /** + * Remove keys from an array if empty + * + * @access public + * @param array $values Input array + * @param string[] $keys List of keys to remove + */ + public function removeEmptyFields(array &$values, array $keys) + { + foreach ($keys as $key) { + if (array_key_exists($key, $values) && empty($values[$key])) { + unset($values[$key]); + } + } + } + + /** + * Force fields to be at 0 if empty + * + * @access public + * @param array $values Input array + * @param string[] $keys List of keys + */ + public function resetFields(array &$values, array $keys) + { + foreach ($keys as $key) { + if (isset($values[$key]) && empty($values[$key])) { + $values[$key] = 0; + } + } + } + + /** + * Force some fields to be integer + * + * @access public + * @param array $values Input array + * @param string[] $keys List of keys + */ + public function convertIntegerFields(array &$values, array $keys) + { + foreach ($keys as $key) { + if (isset($values[$key])) { + $values[$key] = (int) $values[$key]; + } + } + } + + /** + * Force some fields to be null if empty + * + * @access public + * @param array $values Input array + * @param string[] $keys List of keys + */ + public function convertNullFields(array &$values, array $keys) + { + foreach ($keys as $key) { + if (array_key_exists($key, $values) && empty($values[$key])) { + $values[$key] = null; + } + } + } +} diff --git a/app/Helper/Subtask.php b/app/Helper/Subtask.php deleted file mode 100644 index 90bd733e..00000000 --- a/app/Helper/Subtask.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -namespace Kanboard\Helper; - -/** - * Subtask helpers - * - * @package helper - * @author Frederic Guillot - */ -class Subtask extends \Kanboard\Core\Base -{ - /** - * Get the link to toggle subtask status - * - * @access public - * @param array $subtask - * @param string $redirect - * @param integer $project_id - * @return string - */ - public function toggleStatus(array $subtask, $redirect, $project_id = 0) - { - if ($project_id > 0 && ! $this->helper->user->hasProjectAccess('subtask', 'edit', $project_id)) { - return trim($this->template->render('subtask/icons', array('subtask' => $subtask))) . $this->helper->e($subtask['title']); - } - - if ($subtask['status'] == 0 && isset($this->sessionStorage->hasSubtaskInProgress) && $this->sessionStorage->hasSubtaskInProgress) { - return $this->helper->url->link( - trim($this->template->render('subtask/icons', array('subtask' => $subtask))) . $this->helper->e($subtask['title']), - 'subtask', - 'subtaskRestriction', - array('task_id' => $subtask['task_id'], 'subtask_id' => $subtask['id'], 'redirect' => $redirect), - false, - 'popover task-board-popover' - ); - } - - return $this->helper->url->link( - trim($this->template->render('subtask/icons', array('subtask' => $subtask))) . $this->helper->e($subtask['title']), - 'subtask', - 'toggleStatus', - array('task_id' => $subtask['task_id'], 'subtask_id' => $subtask['id'], 'redirect' => $redirect) - ); - } -} diff --git a/app/Helper/SubtaskHelper.php b/app/Helper/SubtaskHelper.php new file mode 100644 index 00000000..afa3c14e --- /dev/null +++ b/app/Helper/SubtaskHelper.php @@ -0,0 +1,95 @@ +<?php + +namespace Kanboard\Helper; + +use Kanboard\Core\Base; + +/** + * Subtask helpers + * + * @package helper + * @author Frederic Guillot + */ +class SubtaskHelper extends Base +{ + public function getTitle(array $subtask) + { + if ($subtask['status'] == 0) { + $html = '<i class="fa fa-square-o fa-fw"></i>'; + } elseif ($subtask['status'] == 1) { + $html = '<i class="fa fa-gears fa-fw"></i>'; + } else { + $html = '<i class="fa fa-check-square-o fa-fw"></i>'; + } + + return $html.$this->helper->text->e($subtask['title']); + } + + /** + * Get the link to toggle subtask status + * + * @access public + * @param array $subtask + * @param integer $project_id + * @param boolean $refresh_table + * @return string + */ + public function toggleStatus(array $subtask, $project_id, $refresh_table = false) + { + if (! $this->helper->user->hasProjectAccess('subtask', 'edit', $project_id)) { + return $this->getTitle($subtask); + } + + $params = array('task_id' => $subtask['task_id'], 'subtask_id' => $subtask['id'], 'refresh-table' => (int) $refresh_table); + + if ($subtask['status'] == 0 && isset($this->sessionStorage->hasSubtaskInProgress) && $this->sessionStorage->hasSubtaskInProgress) { + return $this->helper->url->link($this->getTitle($subtask), 'SubtaskRestriction', 'popover', $params, false, 'popover'); + } + + $class = 'subtask-toggle-status '.($refresh_table ? 'subtask-refresh-table' : ''); + return $this->helper->url->link($this->getTitle($subtask), 'SubtaskStatus', 'change', $params, false, $class); + } + + public function selectTitle(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="1"', 'required', 'maxlength="255"'), $attributes); + + $html = $this->helper->form->label(t('Title'), 'title'); + $html .= $this->helper->form->text('title', $values, $errors, $attributes); + + return $html; + } + + public function selectAssignee(array $users, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="2"'), $attributes); + + $html = $this->helper->form->label(t('Assignee'), 'user_id'); + $html .= $this->helper->form->select('user_id', $users, $values, $errors, $attributes); + $html .= ' <a href="#" class="assign-me" data-target-id="form-user_id" data-current-id="'.$this->userSession->getId().'" title="'.t('Assign to me').'">'.t('Me').'</a>'; + + return $html; + } + + public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="3"'), $attributes); + + $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); + $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } + + public function selectTimeSpent(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="4"'), $attributes); + + $html = $this->helper->form->label(t('Time spent'), 'time_spent'); + $html .= $this->helper->form->numeric('time_spent', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } +} diff --git a/app/Helper/Task.php b/app/Helper/Task.php deleted file mode 100644 index 500b8a89..00000000 --- a/app/Helper/Task.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -namespace Kanboard\Helper; - -use Kanboard\Core\Base; - -/** - * Task helpers - * - * @package helper - * @author Frederic Guillot - */ -class Task extends Base -{ - public function getColors() - { - return $this->color->getList(); - } - - public function recurrenceTriggers() - { - return $this->task->getRecurrenceTriggerList(); - } - - public function recurrenceTimeframes() - { - return $this->task->getRecurrenceTimeframeList(); - } - - public function recurrenceBasedates() - { - return $this->task->getRecurrenceBasedateList(); - } - - public function canRemove(array $task) - { - return $this->taskPermission->canRemoveTask($task); - } - - public function selectPriority(array $project, array $values) - { - $html = ''; - - if ($project['priority_end'] > $project['priority_start']) { - $range = range($project['priority_start'], $project['priority_end']); - $options = array_combine($range, $range); - $values += array('priority' => $project['priority_default']); - - $html .= $this->helper->form->label(t('Priority'), 'priority'); - $html .= $this->helper->form->select('priority', $options, $values, array(), array('tabindex="7"')); - } - - return $html; - } - - public function formatPriority(array $project, array $task) - { - $html = ''; - - if ($project['priority_end'] > $project['priority_start']) { - $html .= '<span class="task-board-priority" title="'.t('Task priority').'">'; - $html .= $task['priority'] >= 0 ? 'P'.$task['priority'] : '-P'.abs($task['priority']); - $html .= '</span>'; - } - - return $html; - } -} diff --git a/app/Helper/TaskHelper.php b/app/Helper/TaskHelper.php new file mode 100644 index 00000000..4857d0ee --- /dev/null +++ b/app/Helper/TaskHelper.php @@ -0,0 +1,186 @@ +<?php + +namespace Kanboard\Helper; + +use Kanboard\Core\Base; + +/** + * Task helpers + * + * @package helper + * @author Frederic Guillot + */ +class TaskHelper extends Base +{ + /** + * Local cache for project columns + * + * @access private + * @var array + */ + private $columns = array(); + + public function getColors() + { + return $this->color->getList(); + } + + public function recurrenceTriggers() + { + return $this->task->getRecurrenceTriggerList(); + } + + public function recurrenceTimeframes() + { + return $this->task->getRecurrenceTimeframeList(); + } + + public function recurrenceBasedates() + { + return $this->task->getRecurrenceBasedateList(); + } + + public function canRemove(array $task) + { + return $this->taskPermission->canRemoveTask($task); + } + + public function selectAssignee(array $users, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="3"'), $attributes); + + $html = $this->helper->form->label(t('Assignee'), 'owner_id'); + $html .= $this->helper->form->select('owner_id', $users, $values, $errors, $attributes); + $html .= ' <a href="#" class="assign-me" data-target-id="form-owner_id" data-current-id="'.$this->userSession->getId().'" title="'.t('Assign to me').'">'.t('Me').'</a>'; + + return $html; + } + + public function selectCategory(array $categories, array $values, array $errors = array(), array $attributes = array(), $allow_one_item = false) + { + $attributes = array_merge(array('tabindex="4"'), $attributes); + $html = ''; + + if (! (! $allow_one_item && count($categories) === 1 && key($categories) == 0)) { + $html .= $this->helper->form->label(t('Category'), 'category_id'); + $html .= $this->helper->form->select('category_id', $categories, $values, $errors, $attributes); + } + + return $html; + } + + public function selectSwimlane(array $swimlanes, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="5"'), $attributes); + $html = ''; + + if (! (count($swimlanes) === 1 && key($swimlanes) == 0)) { + $html .= $this->helper->form->label(t('Swimlane'), 'swimlane_id'); + $html .= $this->helper->form->select('swimlane_id', $swimlanes, $values, $errors, $attributes); + } + + return $html; + } + + public function selectColumn(array $columns, array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="6"'), $attributes); + + $html = $this->helper->form->label(t('Column'), 'column_id'); + $html .= $this->helper->form->select('column_id', $columns, $values, $errors, $attributes); + + return $html; + } + + public function selectPriority(array $project, array $values) + { + $html = ''; + + if ($project['priority_end'] > $project['priority_start']) { + $range = range($project['priority_start'], $project['priority_end']); + $options = array_combine($range, $range); + $values += array('priority' => $project['priority_default']); + + $html .= $this->helper->form->label(t('Priority'), 'priority'); + $html .= $this->helper->form->select('priority', $options, $values, array(), array('tabindex="7"')); + } + + return $html; + } + + public function selectScore(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="8"'), $attributes); + + $html = $this->helper->form->label(t('Complexity'), 'score'); + $html .= $this->helper->form->number('score', $values, $errors, $attributes); + + return $html; + } + + public function selectTimeEstimated(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="9"'), $attributes); + + $html = $this->helper->form->label(t('Original estimate'), 'time_estimated'); + $html .= $this->helper->form->numeric('time_estimated', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } + + public function selectTimeSpent(array $values, array $errors = array(), array $attributes = array()) + { + $attributes = array_merge(array('tabindex="10"'), $attributes); + + $html = $this->helper->form->label(t('Time spent'), 'time_spent'); + $html .= $this->helper->form->numeric('time_spent', $values, $errors, $attributes); + $html .= ' '.t('hours'); + + return $html; + } + + public function selectStartDate(array $values, array $errors = array(), array $attributes = array()) + { + $placeholder = date($this->config->get('application_date_format', 'm/d/Y H:i')); + $attributes = array_merge(array('tabindex="11"', 'placeholder="'.$placeholder.'"'), $attributes); + + $html = $this->helper->form->label(t('Start Date'), 'date_started'); + $html .= $this->helper->form->text('date_started', $values, $errors, $attributes, 'form-datetime'); + + return $html; + } + + public function selectDueDate(array $values, array $errors = array(), array $attributes = array()) + { + $placeholder = date($this->config->get('application_date_format', 'm/d/Y')); + $attributes = array_merge(array('tabindex="12"', 'placeholder="'.$placeholder.'"'), $attributes); + + $html = $this->helper->form->label(t('Due Date'), 'date_due'); + $html .= $this->helper->form->text('date_due', $values, $errors, $attributes, 'form-date'); + + return $html; + } + + public function formatPriority(array $project, array $task) + { + $html = ''; + + if ($project['priority_end'] > $project['priority_start']) { + $html .= '<span class="task-board-priority" title="'.t('Task priority').'">'; + $html .= $task['priority'] >= 0 ? 'P'.$task['priority'] : '-P'.abs($task['priority']); + $html .= '</span>'; + } + + return $html; + } + + public function getProgress($task) + { + if (! isset($this->columns[$task['project_id']])) { + $this->columns[$task['project_id']] = $this->column->getList($task['project_id']); + } + + return $this->task->getProgress($task, $this->columns[$task['project_id']]); + } +} diff --git a/app/Helper/Text.php b/app/Helper/TextHelper.php index 59bfd997..e5aefdcf 100644 --- a/app/Helper/Text.php +++ b/app/Helper/TextHelper.php @@ -11,9 +11,20 @@ use Kanboard\Core\Base; * @package helper * @author Frederic Guillot */ -class Text extends Base +class TextHelper extends Base { /** + * HTML escaping + * + * @param string $value Value to escape + * @return string + */ + public function e($value) + { + return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false); + } + + /** * Markdown transformation * * @param string $text Markdown content @@ -43,6 +54,29 @@ class Text extends Base } /** + * Get the number of bytes from PHP size + * + * @param integer $val PHP size (example: 2M) + * @return integer + */ + public function phpToBytes($val) + { + $val = trim($val); + $last = strtolower($val[strlen($val)-1]); + + switch ($last) { + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + + return $val; + } + + /** * Return true if needle is contained in the haystack * * @param string $haystack Haystack @@ -65,7 +99,7 @@ class Text extends Base public function in($id, array $listing, $default_value = '?') { if (isset($listing[$id])) { - return $this->helper->e($listing[$id]); + return $this->helper->text->e($listing[$id]); } return $default_value; diff --git a/app/Helper/Url.php b/app/Helper/UrlHelper.php index 720297cf..cad9fdef 100644 --- a/app/Helper/Url.php +++ b/app/Helper/UrlHelper.php @@ -5,12 +5,12 @@ namespace Kanboard\Helper; use Kanboard\Core\Base; /** - * Url helpers + * Url Helper * * @package helper * @author Frederic Guillot */ -class Url extends Base +class UrlHelper extends Base { private $base = ''; private $directory = ''; @@ -32,19 +32,20 @@ class Url extends Base * HTML Link tag * * @access public - * @param string $label Link label - * @param string $controller Controller name - * @param string $action Action name - * @param array $params Url parameters - * @param boolean $csrf Add a CSRF token - * @param string $class CSS class attribute - * @param boolean $new_tab Open the link in a new tab - * @param string $anchor Link Anchor + * @param string $label Link label + * @param string $controller Controller name + * @param string $action Action name + * @param array $params Url parameters + * @param boolean $csrf Add a CSRF token + * @param string $class CSS class attribute + * @param string $title + * @param boolean $new_tab Open the link in a new tab + * @param string $anchor Link Anchor * @return string */ public function link($label, $controller, $action, array $params = array(), $csrf = false, $class = '', $title = '', $new_tab = false, $anchor = '') { - return '<a href="'.$this->href($controller, $action, $params, $csrf, $anchor).'" class="'.$class.'" title="'.$title.'" '.($new_tab ? 'target="_blank"' : '').'>'.$label.'</a>'; + return '<a href="'.$this->href($controller, $action, $params, $csrf, $anchor).'" class="'.$class.'" title=\''.$title.'\' '.($new_tab ? 'target="_blank"' : '').'>'.$label.'</a>'; } /** diff --git a/app/Helper/User.php b/app/Helper/UserHelper.php index 29844dfb..cbdb4af8 100644 --- a/app/Helper/User.php +++ b/app/Helper/UserHelper.php @@ -2,13 +2,15 @@ namespace Kanboard\Helper; +use Kanboard\Core\Base; + /** * User helpers * * @package helper * @author Frederic Guillot */ -class User extends \Kanboard\Core\Base +class UserHelper extends Base { /** * Return true if the logged user as unread notifications @@ -168,7 +170,7 @@ class User extends \Kanboard\Core\Base public function avatar($email, $alt = '') { if (! empty($email) && $this->config->get('integration_gravatar') == 1) { - return '<img class="avatar" src="https://www.gravatar.com/avatar/'.md5(strtolower($email)).'?s=25" alt="'.$this->helper->e($alt).'" title="'.$this->helper->e($alt).'">'; + return '<img class="avatar" src="https://www.gravatar.com/avatar/'.md5(strtolower($email)).'?s=25" alt="'.$this->helper->text->e($alt).'" title="'.$this->helper->text->e($alt).'">'; } return ''; |