diff --git a/app/Controller/Analytic.php b/app/Controller/Analytic.php index 6c49089b9..115f75f0f 100644 --- a/app/Controller/Analytic.php +++ b/app/Controller/Analytic.php @@ -21,7 +21,7 @@ class Analytic extends Base private function layout($template, array $params) { $params['board_selector'] = $this->projectPermission->getAllowedProjects($this->acl->getUserId()); - $params['analytic_content_for_layout'] = $this->template->load($template, $params); + $params['analytic_content_for_layout'] = $this->template->render($template, $params); return $this->template->layout('analytic/layout', $params); } diff --git a/app/Controller/App.php b/app/Controller/App.php index eb1d83af1..56e811792 100644 --- a/app/Controller/App.php +++ b/app/Controller/App.php @@ -3,7 +3,6 @@ namespace Controller; use Model\SubTask as SubTaskModel; -use Helper; /** * Application controller @@ -192,7 +191,7 @@ class App extends Base $this->response->html('
'.t('Nothing to preview...').'
'); } else { - $this->response->html(Helper\markdown($payload['text'])); + $this->response->html($this->template->markdown($payload['text'])); } } diff --git a/app/Controller/Base.php b/app/Controller/Base.php index 19eb7f128..18f21ee81 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -17,6 +17,8 @@ use Symfony\Component\EventDispatcher\Event; * @package controller * @author Frederic Guillot * + * @property \Core\Session $session + * @property \Core\Template $template * @property \Model\Acl $acl * @property \Model\Authentication $authentication * @property \Model\Action $action @@ -69,22 +71,6 @@ abstract class Base */ protected $response; - /** - * Template instance - * - * @accesss protected - * @var \Core\Template - */ - protected $template; - - /** - * Session instance - * - * @accesss public - * @var \Core\Session - */ - protected $session; - /** * Container instance * @@ -104,8 +90,6 @@ abstract class Base $this->container = $container; $this->request = new Request; $this->response = new Response; - $this->session = new Session; - $this->template = new Template; } /** @@ -265,7 +249,7 @@ abstract class Base $params['hide_remove_menu'] = true; } - $content = $this->template->load($template, $params); + $content = $this->template->render($template, $params); $params['task_content_for_layout'] = $content; $params['title'] = $params['task']['project_name'].' > '.$params['task']['title']; $params['board_selector'] = $this->projectPermission->getAllowedProjects($this->acl->getUserId()); @@ -283,7 +267,7 @@ abstract class Base */ protected function projectLayout($template, array $params) { - $content = $this->template->load($template, $params); + $content = $this->template->render($template, $params); $params['project_content_for_layout'] = $content; $params['title'] = $params['project']['name'] === $params['title'] ? $params['title'] : $params['project']['name'].' > '.$params['title']; $params['board_selector'] = $this->projectPermission->getAllowedProjects($this->acl->getUserId()); diff --git a/app/Controller/Board.php b/app/Controller/Board.php index 072acf26e..2c10e105b 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -39,7 +39,7 @@ class Board extends Base $task = $this->getTask(); $project = $this->project->getById($task['project_id']); - $this->response->html($this->template->load('board/assignee', array( + $this->response->html($this->template->render('board/assignee', array( 'values' => $task, 'users_list' => $this->projectPermission->getMemberList($project['id']), 'project' => $project, @@ -78,7 +78,7 @@ class Board extends Base $task = $this->getTask(); $project = $this->project->getById($task['project_id']); - $this->response->html($this->template->load('board/category', array( + $this->response->html($this->template->render('board/category', array( 'values' => $task, 'categories_list' => $this->category->getList($project['id']), 'project' => $project, @@ -360,7 +360,7 @@ class Board extends Base } $this->response->html( - $this->template->load('board/show', array( + $this->template->render('board/show', array( 'project' => $this->project->getById($project_id), 'swimlanes' => $this->board->getBoard($project_id), 'categories' => $this->category->getList($project_id, false), @@ -394,7 +394,7 @@ class Board extends Base } $this->response->html( - $this->template->load('board/show', array( + $this->template->render('board/show', array( 'project' => $this->project->getById($project_id), 'swimlanes' => $this->board->getBoard($project_id), 'categories' => $this->category->getList($project_id, false), @@ -412,7 +412,7 @@ class Board extends Base public function subtasks() { $task = $this->getTask(); - $this->response->html($this->template->load('board/subtasks', array( + $this->response->html($this->template->render('board/subtasks', array( 'subtasks' => $this->subTask->getAll($task['id']) ))); } @@ -427,7 +427,7 @@ class Board extends Base $task = $this->getTask(); $this->subTask->toggleStatus($this->request->getIntegerParam('subtask_id')); - $this->response->html($this->template->load('board/subtasks', array( + $this->response->html($this->template->render('board/subtasks', array( 'subtasks' => $this->subTask->getAll($task['id']) ))); } @@ -441,7 +441,7 @@ class Board extends Base { $task = $this->getTask(); - $this->response->html($this->template->load('board/files', array( + $this->response->html($this->template->render('board/files', array( 'files' => $this->file->getAll($task['id']) ))); } @@ -455,7 +455,7 @@ class Board extends Base { $task = $this->getTask(); - $this->response->html($this->template->load('board/comments', array( + $this->response->html($this->template->render('board/comments', array( 'comments' => $this->comment->getAll($task['id']) ))); } @@ -469,7 +469,7 @@ class Board extends Base { $task = $this->getTask(); - $this->response->html($this->template->load('board/description', array( + $this->response->html($this->template->render('board/description', array( 'task' => $task ))); } diff --git a/app/Controller/Config.php b/app/Controller/Config.php index 199259d79..4093b7a1a 100644 --- a/app/Controller/Config.php +++ b/app/Controller/Config.php @@ -23,7 +23,7 @@ class Config extends Base $params['board_selector'] = $this->projectPermission->getAllowedProjects($this->acl->getUserId()); $params['values'] = $this->config->getAll(); $params['errors'] = array(); - $params['config_content_for_layout'] = $this->template->load($template, $params); + $params['config_content_for_layout'] = $this->template->render($template, $params); return $this->template->layout('config/layout', $params); } diff --git a/app/Controller/File.php b/app/Controller/File.php index ae44cac06..1585a7017 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -75,7 +75,7 @@ class File extends Base $file = $this->file->getById($this->request->getIntegerParam('file_id')); if ($file['task_id'] == $task['id']) { - $this->response->html($this->template->load('file/open', array( + $this->response->html($this->template->render('file/open', array( 'file' => $file ))); } diff --git a/app/Controller/Project.php b/app/Controller/Project.php index 5395a5a46..9037a91a3 100644 --- a/app/Controller/Project.php +++ b/app/Controller/Project.php @@ -447,7 +447,7 @@ class Project extends Base $this->forbidden(true); } - $this->response->xml($this->template->load('project/feed', array( + $this->response->xml($this->template->render('project/feed', array( 'events' => $this->projectActivity->getProject($project['id']), 'project' => $project, ))); diff --git a/app/Controller/Task.php b/app/Controller/Task.php index 33b4b039b..284cbec06 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -89,7 +89,7 @@ class Task extends Base public function create(array $values = array(), array $errors = array()) { $project = $this->getProject(); - $method = $this->request->isAjax() ? 'load' : 'layout'; + $method = $this->request->isAjax() ? 'render' : 'layout'; if (empty($values)) { @@ -179,7 +179,7 @@ class Task extends Base ); if ($ajax) { - $this->response->html($this->template->load('task/edit', $params)); + $this->response->html($this->template->render('task/edit', $params)); } else { $this->response->html($this->taskLayout('task/edit', $params)); @@ -410,7 +410,7 @@ class Task extends Base ); if ($ajax) { - $this->response->html($this->template->load('task/edit_description', $params)); + $this->response->html($this->template->render('task/edit_description', $params)); } else { $this->response->html($this->taskLayout('task/edit_description', $params)); diff --git a/app/Controller/User.php b/app/Controller/User.php index 93b5ca186..619bbc902 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -76,7 +76,7 @@ class User extends Base */ private function layout($template, array $params) { - $content = $this->template->load($template, $params); + $content = $this->template->render($template, $params); $params['user_content_for_layout'] = $content; $params['board_selector'] = $this->projectPermission->getAllowedProjects($this->acl->getUserId()); diff --git a/app/Core/Helper.php b/app/Core/Helper.php new file mode 100644 index 000000000..860346927 --- /dev/null +++ b/app/Core/Helper.php @@ -0,0 +1,629 @@ +container = $container; + } + + /** + * Load automatically models + * + * @access public + * @param string $name Model name + * @return mixed + */ + public function __get($name) + { + return $this->container[$name]; + } + + /** + * Return the user full name + * + * @param array $user User properties + * @return string + */ + public function getFullname(array $user = array()) + { + return $this->user->getFullname(empty($user) ? $_SESSION['user'] : $user); + } + + /** + * HTML escaping + * + * @param string $value Value to escape + * @return string + */ + public function e($value) + { + return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false); + } + + /** + * Add a Javascript asset + * + * @param string $filename Filename + * @return string + */ + public function js($filename) + { + return ''; + } + + /** + * Add a stylesheet asset + * + * @param string $filename Filename + * @return string + */ + public function css($filename) + { + return ''; + } + + /** + * Display the form error class + * + * @param array $errors Error list + * @param string $name Field name + * @return string + */ + public function errorClass(array $errors, $name) + { + return ! isset($errors[$name]) ? '' : ' form-error'; + } + + /** + * Display a list of form errors + * + * @param array $errors List of errors + * @param string $name Field name + * @return string + */ + public function errorList(array $errors, $name) + { + $html = ''; + + if (isset($errors[$name])) { + + $html .= '