From 2230dd4e6b148346c0ec596b9e3e12996a762ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Thu, 22 May 2014 12:28:28 -0400 Subject: [PATCH] Code refactoring (add autoloader and change files organization) --- {actions => app}/.htaccess | 0 actions/base.php => app/Action/Base.php | 4 +- .../Action/TaskAssignColorCategory.php | 4 +- .../Action/TaskAssignColorUser.php | 4 +- .../Action/TaskAssignCurrentUser.php | 5 +- .../Action/TaskAssignSpecificUser.php | 4 +- .../Action/TaskClose.php | 4 +- .../Action/TaskDuplicateAnotherProject.php | 4 +- .../action.php => app/Controller/Action.php | 2 - controllers/app.php => app/Controller/App.php | 4 +- .../base.php => app/Controller/Base.php | 163 ++++-------------- .../board.php => app/Controller/Board.php | 11 +- .../Controller/Category.php | 2 - .../comment.php => app/Controller/Comment.php | 2 - .../config.php => app/Controller/Config.php | 2 - .../project.php => app/Controller/Project.php | 4 +- .../task.php => app/Controller/Task.php | 6 +- .../user.php => app/Controller/User.php | 2 - core/event.php => app/Core/Event.php | 14 -- app/Core/Listener.php | 17 ++ app/Core/Loader.php | 37 ++++ core/registry.php => app/Core/Registry.php | 0 core/request.php => app/Core/Request.php | 0 core/response.php => app/Core/Response.php | 0 core/router.php => app/Core/Router.php | 65 +++++-- core/session.php => app/Core/Session.php | 0 app/Core/Template.php | 72 ++++++++ app/Core/Translator.php | 155 +++++++++++++++++ .../Event/TaskModification.php | 4 +- .../Locales}/es_ES/translations.php | 1 + .../Locales}/fr_FR/translations.php | 1 + .../Locales}/pl_PL/translations.php | 1 + .../Locales}/pt_BR/translations.php | 1 + models/acl.php => app/Model/Acl.php | 2 - models/action.php => app/Model/Action.php | 16 +- models/base.php => app/Model/Base.php | 31 ++-- models/board.php => app/Model/Board.php | 7 +- models/category.php => app/Model/Category.php | 2 - models/comment.php => app/Model/Comment.php | 6 +- models/config.php => app/Model/Config.php | 6 +- models/google.php => app/Model/Google.php | 13 +- .../last_login.php => app/Model/LastLogin.php | 2 - models/ldap.php => app/Model/Ldap.php | 2 - models/project.php => app/Model/Project.php | 6 - .../Model/RememberMe.php | 2 - models/task.php => app/Model/Task.php | 2 - models/user.php => app/Model/User.php | 6 +- schemas/mysql.php => app/Schema/Mysql.php | 2 + schemas/sqlite.php => app/Schema/Sqlite.php | 2 + {templates => app/Templates}/action_index.php | 0 .../Templates}/action_params.php | 0 .../Templates}/action_remove.php | 0 {templates => app/Templates}/app_notfound.php | 0 {templates => app/Templates}/board_assign.php | 0 {templates => app/Templates}/board_edit.php | 0 {templates => app/Templates}/board_index.php | 0 {templates => app/Templates}/board_public.php | 0 {templates => app/Templates}/board_remove.php | 0 {templates => app/Templates}/board_show.php | 0 .../Templates}/category_edit.php | 0 .../Templates}/category_index.php | 0 .../Templates}/category_remove.php | 0 .../Templates}/comment_forbidden.php | 0 .../Templates}/comment_remove.php | 0 {templates => app/Templates}/comment_show.php | 0 {templates => app/Templates}/config_index.php | 0 {templates => app/Templates}/layout.php | 0 {templates => app/Templates}/project_edit.php | 0 .../Templates}/project_forbidden.php | 0 .../Templates}/project_index.php | 0 {templates => app/Templates}/project_new.php | 0 .../Templates}/project_remove.php | 0 .../Templates}/project_search.php | 0 .../Templates}/project_tasks.php | 0 .../Templates}/project_users.php | 0 {templates => app/Templates}/task_close.php | 0 {templates => app/Templates}/task_edit.php | 0 {templates => app/Templates}/task_layout.php | 0 {templates => app/Templates}/task_new.php | 0 {templates => app/Templates}/task_open.php | 0 {templates => app/Templates}/task_remove.php | 0 {templates => app/Templates}/task_show.php | 0 {templates => app/Templates}/task_sidebar.php | 0 {templates => app/Templates}/user_edit.php | 0 .../Templates}/user_forbidden.php | 0 {templates => app/Templates}/user_index.php | 0 {templates => app/Templates}/user_login.php | 0 {templates => app/Templates}/user_new.php | 0 {templates => app/Templates}/user_remove.php | 0 check_setup.php => app/check_setup.php | 2 +- app/common.php | 98 +++++++++++ core/helper.php => app/helpers.php | 0 app/translator.php | 36 ++++ assets/js/board.js | 1 + common.php | 156 ----------------- config.default.php | 5 +- core/template.php | 40 ----- core/translator.php | 130 -------------- {controllers => docs}/.htaccess | 0 index.php | 9 +- schemas/.htaccess | 1 - {core => scripts}/.htaccess | 0 templates/.htaccess | 1 - {models => tests}/.htaccess | 0 tests/Base.php | 39 +++-- 105 files changed, 614 insertions(+), 606 deletions(-) rename {actions => app}/.htaccess (100%) rename actions/base.php => app/Action/Base.php (98%) rename actions/task_assign_color_category.php => app/Action/TaskAssignColorCategory.php (94%) rename actions/task_assign_color_user.php => app/Action/TaskAssignColorUser.php (94%) rename actions/task_assign_current_user.php => app/Action/TaskAssignCurrentUser.php (94%) rename actions/task_assign_specific_user.php => app/Action/TaskAssignSpecificUser.php (94%) rename actions/task_close.php => app/Action/TaskClose.php (93%) rename actions/task_duplicate_another_project.php => app/Action/TaskDuplicateAnotherProject.php (94%) rename controllers/action.php => app/Controller/Action.php (99%) rename controllers/app.php => app/Controller/App.php (80%) rename controllers/base.php => app/Controller/Base.php (71%) rename controllers/board.php => app/Controller/Board.php (97%) rename controllers/category.php => app/Controller/Category.php (99%) rename controllers/comment.php => app/Controller/Comment.php (99%) rename controllers/config.php => app/Controller/Config.php (98%) rename controllers/project.php => app/Controller/Project.php (99%) rename controllers/task.php => app/Controller/Task.php (98%) rename controllers/user.php => app/Controller/User.php (99%) rename core/event.php => app/Core/Event.php (93%) create mode 100644 app/Core/Listener.php create mode 100644 app/Core/Loader.php rename core/registry.php => app/Core/Registry.php (100%) rename core/request.php => app/Core/Request.php (100%) rename core/response.php => app/Core/Response.php (100%) rename core/router.php => app/Core/Router.php (50%) rename core/session.php => app/Core/Session.php (100%) create mode 100644 app/Core/Template.php create mode 100644 app/Core/Translator.php rename events/task_modification.php => app/Event/TaskModification.php (95%) rename {locales => app/Locales}/es_ES/translations.php (99%) rename {locales => app/Locales}/fr_FR/translations.php (99%) rename {locales => app/Locales}/pl_PL/translations.php (99%) rename {locales => app/Locales}/pt_BR/translations.php (99%) rename models/acl.php => app/Model/Acl.php (99%) rename models/action.php => app/Model/Action.php (91%) rename models/base.php => app/Model/Base.php (55%) rename models/board.php => app/Model/Board.php (98%) rename models/category.php => app/Model/Category.php (99%) rename models/comment.php => app/Model/Comment.php (97%) rename models/config.php => app/Model/Config.php (97%) rename models/google.php => app/Model/Google.php (92%) rename models/last_login.php => app/Model/LastLogin.php (98%) rename models/ldap.php => app/Model/Ldap.php (98%) rename models/project.php => app/Model/Project.php (98%) rename models/remember_me.php => app/Model/RememberMe.php (99%) rename models/task.php => app/Model/Task.php (99%) rename models/user.php => app/Model/User.php (99%) rename schemas/mysql.php => app/Schema/Mysql.php (99%) rename schemas/sqlite.php => app/Schema/Sqlite.php (99%) rename {templates => app/Templates}/action_index.php (100%) rename {templates => app/Templates}/action_params.php (100%) rename {templates => app/Templates}/action_remove.php (100%) rename {templates => app/Templates}/app_notfound.php (100%) rename {templates => app/Templates}/board_assign.php (100%) rename {templates => app/Templates}/board_edit.php (100%) rename {templates => app/Templates}/board_index.php (100%) rename {templates => app/Templates}/board_public.php (100%) rename {templates => app/Templates}/board_remove.php (100%) rename {templates => app/Templates}/board_show.php (100%) rename {templates => app/Templates}/category_edit.php (100%) rename {templates => app/Templates}/category_index.php (100%) rename {templates => app/Templates}/category_remove.php (100%) rename {templates => app/Templates}/comment_forbidden.php (100%) rename {templates => app/Templates}/comment_remove.php (100%) rename {templates => app/Templates}/comment_show.php (100%) rename {templates => app/Templates}/config_index.php (100%) rename {templates => app/Templates}/layout.php (100%) rename {templates => app/Templates}/project_edit.php (100%) rename {templates => app/Templates}/project_forbidden.php (100%) rename {templates => app/Templates}/project_index.php (100%) rename {templates => app/Templates}/project_new.php (100%) rename {templates => app/Templates}/project_remove.php (100%) rename {templates => app/Templates}/project_search.php (100%) rename {templates => app/Templates}/project_tasks.php (100%) rename {templates => app/Templates}/project_users.php (100%) rename {templates => app/Templates}/task_close.php (100%) rename {templates => app/Templates}/task_edit.php (100%) rename {templates => app/Templates}/task_layout.php (100%) rename {templates => app/Templates}/task_new.php (100%) rename {templates => app/Templates}/task_open.php (100%) rename {templates => app/Templates}/task_remove.php (100%) rename {templates => app/Templates}/task_show.php (100%) rename {templates => app/Templates}/task_sidebar.php (100%) rename {templates => app/Templates}/user_edit.php (100%) rename {templates => app/Templates}/user_forbidden.php (100%) rename {templates => app/Templates}/user_index.php (100%) rename {templates => app/Templates}/user_login.php (100%) rename {templates => app/Templates}/user_new.php (100%) rename {templates => app/Templates}/user_remove.php (100%) rename check_setup.php => app/check_setup.php (96%) create mode 100644 app/common.php rename core/helper.php => app/helpers.php (100%) create mode 100644 app/translator.php delete mode 100644 common.php delete mode 100644 core/template.php delete mode 100644 core/translator.php rename {controllers => docs}/.htaccess (100%) delete mode 100644 schemas/.htaccess rename {core => scripts}/.htaccess (100%) delete mode 100644 templates/.htaccess rename {models => tests}/.htaccess (100%) diff --git a/actions/.htaccess b/app/.htaccess similarity index 100% rename from actions/.htaccess rename to app/.htaccess diff --git a/actions/base.php b/app/Action/Base.php similarity index 98% rename from actions/base.php rename to app/Action/Base.php index 13e4b6eed..14b0a3c00 100644 --- a/actions/base.php +++ b/app/Action/Base.php @@ -2,13 +2,15 @@ namespace Action; +use Core\Listener; + /** * Base class for automatic actions * * @package action * @author Frederic Guillot */ -abstract class Base implements \Core\Listener +abstract class Base implements Listener { /** * Project id diff --git a/actions/task_assign_color_category.php b/app/Action/TaskAssignColorCategory.php similarity index 94% rename from actions/task_assign_color_category.php rename to app/Action/TaskAssignColorCategory.php index 6fba52235..4304d0847 100644 --- a/actions/task_assign_color_category.php +++ b/app/Action/TaskAssignColorCategory.php @@ -2,7 +2,7 @@ namespace Action; -require_once __DIR__.'/base.php'; +use Model\Task; /** * Assign a color to a specific category @@ -27,7 +27,7 @@ class TaskAssignColorCategory extends Base * @param integer $project_id Project id * @param \Model\Task $task Task model instance */ - public function __construct($project_id, \Model\Task $task) + public function __construct($project_id, Task $task) { parent::__construct($project_id); $this->task = $task; diff --git a/actions/task_assign_color_user.php b/app/Action/TaskAssignColorUser.php similarity index 94% rename from actions/task_assign_color_user.php rename to app/Action/TaskAssignColorUser.php index d57842701..9ff140b30 100644 --- a/actions/task_assign_color_user.php +++ b/app/Action/TaskAssignColorUser.php @@ -2,7 +2,7 @@ namespace Action; -require_once __DIR__.'/base.php'; +use Model\Task; /** * Assign a color to a specific user @@ -27,7 +27,7 @@ class TaskAssignColorUser extends Base * @param integer $project_id Project id * @param \Model\Task $task Task model instance */ - public function __construct($project_id, \Model\Task $task) + public function __construct($project_id, Task $task) { parent::__construct($project_id); $this->task = $task; diff --git a/actions/task_assign_current_user.php b/app/Action/TaskAssignCurrentUser.php similarity index 94% rename from actions/task_assign_current_user.php rename to app/Action/TaskAssignCurrentUser.php index a3d9559ea..1c0389661 100644 --- a/actions/task_assign_current_user.php +++ b/app/Action/TaskAssignCurrentUser.php @@ -2,7 +2,8 @@ namespace Action; -require_once __DIR__.'/base.php'; +use Model\Task; +use Model\Acl; /** * Assign a task to the logged user @@ -36,7 +37,7 @@ class TaskAssignCurrentUser extends Base * @param \Model\Task $task Task model instance * @param \Model\Acl $acl Acl model instance */ - public function __construct($project_id, \Model\Task $task, \Model\Acl $acl) + public function __construct($project_id, Task $task, Acl $acl) { parent::__construct($project_id); $this->task = $task; diff --git a/actions/task_assign_specific_user.php b/app/Action/TaskAssignSpecificUser.php similarity index 94% rename from actions/task_assign_specific_user.php rename to app/Action/TaskAssignSpecificUser.php index aabe5420a..8c379bcc1 100644 --- a/actions/task_assign_specific_user.php +++ b/app/Action/TaskAssignSpecificUser.php @@ -2,7 +2,7 @@ namespace Action; -require_once __DIR__.'/base.php'; +use Model\Task; /** * Assign a task to a specific user @@ -27,7 +27,7 @@ class TaskAssignSpecificUser extends Base * @param integer $project_id Project id * @param \Model\Task $task Task model instance */ - public function __construct($project_id, \Model\Task $task) + public function __construct($project_id, Task $task) { parent::__construct($project_id); $this->task = $task; diff --git a/actions/task_close.php b/app/Action/TaskClose.php similarity index 93% rename from actions/task_close.php rename to app/Action/TaskClose.php index 22d61f298..32887d3c8 100644 --- a/actions/task_close.php +++ b/app/Action/TaskClose.php @@ -2,7 +2,7 @@ namespace Action; -require_once __DIR__.'/base.php'; +use Model\Task; /** * Close automatically a task @@ -27,7 +27,7 @@ class TaskClose extends Base * @param integer $project_id Project id * @param \Model\Task $task Task model instance */ - public function __construct($project_id, \Model\Task $task) + public function __construct($project_id, Task $task) { parent::__construct($project_id); $this->task = $task; diff --git a/actions/task_duplicate_another_project.php b/app/Action/TaskDuplicateAnotherProject.php similarity index 94% rename from actions/task_duplicate_another_project.php rename to app/Action/TaskDuplicateAnotherProject.php index 6e1ee84b3..7ef0f6abb 100644 --- a/actions/task_duplicate_another_project.php +++ b/app/Action/TaskDuplicateAnotherProject.php @@ -2,7 +2,7 @@ namespace Action; -require_once __DIR__.'/base.php'; +use Model\Task; /** * Duplicate a task to another project @@ -27,7 +27,7 @@ class TaskDuplicateAnotherProject extends Base * @param integer $project_id Project id * @param \Model\Task $task Task model instance */ - public function __construct($project_id, \Model\Task $task) + public function __construct($project_id, Task $task) { parent::__construct($project_id); $this->task = $task; diff --git a/controllers/action.php b/app/Controller/Action.php similarity index 99% rename from controllers/action.php rename to app/Controller/Action.php index 5c5d57260..b32a89067 100644 --- a/controllers/action.php +++ b/app/Controller/Action.php @@ -2,8 +2,6 @@ namespace Controller; -require_once __DIR__.'/base.php'; - /** * Automatic actions management * diff --git a/controllers/app.php b/app/Controller/App.php similarity index 80% rename from controllers/app.php rename to app/Controller/App.php index 68872a48d..64f9461f3 100644 --- a/controllers/app.php +++ b/app/Controller/App.php @@ -2,7 +2,7 @@ namespace Controller; -require_once __DIR__.'/base.php'; +use Model\Project; /** * Application controller @@ -19,7 +19,7 @@ class App extends Base */ public function index() { - if ($this->project->countByStatus(\Model\Project::ACTIVE)) { + if ($this->project->countByStatus(Project::ACTIVE)) { $this->response->redirect('?controller=board'); } else { diff --git a/controllers/base.php b/app/Controller/Base.php similarity index 71% rename from controllers/base.php rename to app/Controller/Base.php index 49376dce1..bb9add4f0 100644 --- a/controllers/base.php +++ b/app/Controller/Base.php @@ -2,6 +2,10 @@ namespace Controller; +use Core\Registry; +use Core\Translator; +use Model\LastLogin; + /** * Base controller * @@ -43,130 +47,35 @@ abstract class Base public $session; /** - * Acl model + * Registry instance * - * @accesss protected - * @var \Model\Acl + * @access private + * @var Core\Registry */ - protected $acl; - - /** - * Action model - * - * @accesss protected - * @var \Model\Action - */ - protected $action; - - /** - * Board model - * - * @accesss protected - * @var \Model\Board - */ - protected $board; - - /** - * Config model - * - * @accesss protected - * @var \Model\Config - */ - protected $config; - - /** - * Project model - * - * @accesss protected - * @var \Model\Project - */ - protected $project; - - /** - * Task model - * - * @accesss protected - * @var \Model\Task - */ - protected $task; - - /** - * User model - * - * @accesss protected - * @var \Model\User - */ - protected $user; - - /** - * Comment model - * - * @accesss protected - * @var \Model\Comment - */ - protected $comment; - - /** - * RememberMe model - * - * @accesss protected - * @var \Model\RememberMe - */ - protected $rememberMe; - - /** - * LastLogin model - * - * @accesss protected - * @var \Model\LastLogin - */ - protected $lastLogin; - - /** - * Google model - * - * @accesss protected - * @var \Model\Google - */ - protected $google; - - /** - * Category model - * - * @accesss protected - * @var \Model\Category - */ - protected $category; - - /** - * Event instance - * - * @accesss protected - * @var \Model\Event - */ - protected $event; + private $registry; /** * Constructor * * @access public - * @param \Core\Registry $registry + * @param \Core\Registry $registry Registry instance */ - public function __construct(\Core\Registry $registry) + public function __construct(Registry $registry) { - $this->acl = $registry->acl; - $this->action = $registry->action; - $this->board = $registry->board; - $this->config = $registry->config; - $this->project = $registry->project; - $this->task = $registry->task; - $this->user = $registry->user; - $this->comment = $registry->comment; - $this->rememberMe = $registry->rememberMe; - $this->lastLogin = $registry->lastLogin; - $this->google = $registry->google; - $this->category = $registry->category; - $this->event = $registry->shared('event'); + $this->registry = $registry; + } + + /** + * Load automatically models + * + * @access public + * @param string $name Model name + */ + public function __get($name) + { + $class = '\Model\\'.ucfirst($name); + $this->registry->$name = new $class($this->registry->shared('db'), $this->registry->shared('event')); + return $this->registry->shared($name); } /** @@ -188,7 +97,7 @@ abstract class Base // Load translations $language = $this->config->get('language', 'en_US'); - if ($language !== 'en_US') \Translator\load($language); + if ($language !== 'en_US') Translator::load($language); // Set timezone date_default_timezone_set($this->config->get('timezone', 'UTC')); @@ -205,7 +114,7 @@ abstract class Base else { $this->lastLogin->create( - \Model\LastLogin::AUTH_REMEMBER_ME, + LastLogin::AUTH_REMEMBER_ME, $this->acl->getUserId(), $this->user->getIpAddress(), $this->user->getUserAgent() @@ -226,6 +135,16 @@ abstract class Base $this->project->attachEvents(); } + /** + * Application not found page (404 error) + * + * @access public + */ + public function notfound() + { + $this->response->html($this->template->layout('app_notfound', array('title' => t('Page not found')))); + } + /** * Check if the current user have access to the given project * @@ -253,16 +172,6 @@ abstract class Base $this->response->redirect('?controller=project&action=create'); } - /** - * Application not found page (404 error) - * - * @access public - */ - public function notfound() - { - $this->response->html($this->template->layout('app_notfound', array('title' => t('Page not found')))); - } - /** * Display the template show task (common between different actions) * diff --git a/controllers/board.php b/app/Controller/Board.php similarity index 97% rename from controllers/board.php rename to app/Controller/Board.php index f7128210d..c727a422d 100644 --- a/controllers/board.php +++ b/app/Controller/Board.php @@ -2,7 +2,8 @@ namespace Controller; -require_once __DIR__.'/base.php'; +use Model\Project; +use Model\User; /** * Board controller @@ -51,7 +52,7 @@ class Board extends Base { $task = $this->task->getById($this->request->getIntegerParam('task_id')); $project = $this->project->getById($task['project_id']); - $projects = $this->project->getListByStatus(\Model\Project::ACTIVE); + $projects = $this->project->getListByStatus(Project::ACTIVE); if ($this->acl->isRegularUser()) { $projects = $this->project->filterListByAccess($projects, $this->acl->getUserId()); @@ -142,7 +143,7 @@ class Board extends Base */ public function index() { - $projects = $this->project->getListByStatus(\Model\Project::ACTIVE); + $projects = $this->project->getListByStatus(Project::ACTIVE); if ($this->acl->isRegularUser()) { $projects = $this->project->filterListByAccess($projects, $this->acl->getUserId()); @@ -176,10 +177,10 @@ class Board extends Base public function show() { $project_id = $this->request->getIntegerParam('project_id'); - $user_id = $this->request->getIntegerParam('user_id', \Model\User::EVERYBODY_ID); + $user_id = $this->request->getIntegerParam('user_id', User::EVERYBODY_ID); $this->checkProjectPermissions($project_id); - $projects = $this->project->getListByStatus(\Model\Project::ACTIVE); + $projects = $this->project->getListByStatus(Project::ACTIVE); if ($this->acl->isRegularUser()) { $projects = $this->project->filterListByAccess($projects, $this->acl->getUserId()); diff --git a/controllers/category.php b/app/Controller/Category.php similarity index 99% rename from controllers/category.php rename to app/Controller/Category.php index 23de27357..f96c1d4a4 100644 --- a/controllers/category.php +++ b/app/Controller/Category.php @@ -2,8 +2,6 @@ namespace Controller; -require_once __DIR__.'/base.php'; - /** * Categories management * diff --git a/controllers/comment.php b/app/Controller/Comment.php similarity index 99% rename from controllers/comment.php rename to app/Controller/Comment.php index 93dbb5ad4..c9f226f75 100644 --- a/controllers/comment.php +++ b/app/Controller/Comment.php @@ -2,8 +2,6 @@ namespace Controller; -require_once __DIR__.'/base.php'; - /** * Comment controller * diff --git a/controllers/config.php b/app/Controller/Config.php similarity index 98% rename from controllers/config.php rename to app/Controller/Config.php index 527c8a4c2..b4a5b8d33 100644 --- a/controllers/config.php +++ b/app/Controller/Config.php @@ -2,8 +2,6 @@ namespace Controller; -require_once __DIR__.'/base.php'; - /** * Config controller * diff --git a/controllers/project.php b/app/Controller/Project.php similarity index 99% rename from controllers/project.php rename to app/Controller/Project.php index 1b9fd1106..5cb244a25 100644 --- a/controllers/project.php +++ b/app/Controller/Project.php @@ -2,7 +2,7 @@ namespace Controller; -require_once __DIR__.'/base.php'; +use Model\Task; /** * Project controller @@ -96,7 +96,7 @@ class Project extends Base $filters = array( array('column' => 'project_id', 'operator' => 'eq', 'value' => $project_id), - array('column' => 'is_active', 'operator' => 'eq', 'value' => \Model\Task::STATUS_CLOSED), + array('column' => 'is_active', 'operator' => 'eq', 'value' => Task::STATUS_CLOSED), ); $tasks = $this->task->find($filters); diff --git a/controllers/task.php b/app/Controller/Task.php similarity index 98% rename from controllers/task.php rename to app/Controller/Task.php index bdedb9dd1..2291ad439 100644 --- a/controllers/task.php +++ b/app/Controller/Task.php @@ -2,7 +2,7 @@ namespace Controller; -require_once __DIR__.'/base.php'; +use Model\Project; /** * Task controller @@ -162,7 +162,7 @@ class Task extends Base $this->response->html($this->template->layout('task_new', array( 'errors' => $errors, 'values' => $values, - 'projects_list' => $this->project->getListByStatus(\Model\Project::ACTIVE), + 'projects_list' => $this->project->getListByStatus(Project::ACTIVE), 'columns_list' => $this->board->getColumnsList($values['project_id']), 'users_list' => $this->project->getUsersList($values['project_id']), 'colors_list' => $this->task->getColors(), @@ -384,7 +384,7 @@ class Task extends Base $this->response->html($this->template->layout('task_new', array( 'errors' => array(), 'values' => $task, - 'projects_list' => $this->project->getListByStatus(\Model\Project::ACTIVE), + 'projects_list' => $this->project->getListByStatus(Project::ACTIVE), 'columns_list' => $this->board->getColumnsList($task['project_id']), 'users_list' => $this->project->getUsersList($task['project_id']), 'colors_list' => $this->task->getColors(), diff --git a/controllers/user.php b/app/Controller/User.php similarity index 99% rename from controllers/user.php rename to app/Controller/User.php index edd7ae45c..e3fd82531 100644 --- a/controllers/user.php +++ b/app/Controller/User.php @@ -2,8 +2,6 @@ namespace Controller; -require_once __DIR__.'/base.php'; - /** * User controller * diff --git a/core/event.php b/app/Core/Event.php similarity index 93% rename from core/event.php rename to app/Core/Event.php index 0941acac4..2c029b492 100644 --- a/core/event.php +++ b/app/Core/Event.php @@ -2,20 +2,6 @@ namespace Core; -/** - * Event listener interface - * - * @package core - * @author Frederic Guillot - */ -interface Listener { - - /** - * @return boolean - */ - public function execute(array $data); -} - /** * Event dispatcher class * diff --git a/app/Core/Listener.php b/app/Core/Listener.php new file mode 100644 index 000000000..b8bdd6800 --- /dev/null +++ b/app/Core/Listener.php @@ -0,0 +1,17 @@ +registry = $registry; @@ -21,7 +50,11 @@ class Router } /** - * @param string $default_value + * Check controller and action parameter + * + * @access public + * @param string $value Controller or action name + * @param string $default_value Default value if validation fail */ public function sanitize($value, $default_value) { @@ -29,8 +62,12 @@ class Router } /** - * @param string $filename - * @param string $class + * Load a controller and execute the action + * + * @access public + * @param string $filename Controller filename + * @param string $class Class name + * @param string $method Method name */ public function load($filename, $class, $method) { @@ -38,7 +75,9 @@ class Router require $filename; - if (! method_exists($class, $method)) return false; + if (! method_exists($class, $method)) { + return false; + } $instance = new $class($this->registry); $instance->request = new Request; @@ -54,12 +93,18 @@ class Router return false; } + /** + * Find a route + * + * @access public + */ public function execute() { $this->controller = $this->sanitize($this->controller, 'app'); $this->action = $this->sanitize($this->action, 'index'); + $filename = __DIR__.'/../Controller/'.ucfirst($this->controller).'.php'; - if (! $this->load('controllers/'.$this->controller.'.php', '\Controller\\'.$this->controller, $this->action)) { + if (! $this->load($filename, '\Controller\\'.$this->controller, $this->action)) { die('Page not found!'); } } diff --git a/core/session.php b/app/Core/Session.php similarity index 100% rename from core/session.php rename to app/Core/Session.php diff --git a/app/Core/Template.php b/app/Core/Template.php new file mode 100644 index 000000000..8740a6855 --- /dev/null +++ b/app/Core/Template.php @@ -0,0 +1,72 @@ +load('template_name', ['bla' => 'value']); + * + * @access public + * @return string + */ + public function load() + { + if (func_num_args() < 1 || func_num_args() > 2) { + die('Invalid template arguments'); + } + + if (! file_exists(self::PATH.func_get_arg(0).'.php')) { + die('Unable to load the template: "'.func_get_arg(0).'"'); + } + + if (func_num_args() === 2) { + + if (! is_array(func_get_arg(1))) { + die('Template variables must be an array'); + } + + extract(func_get_arg(1)); + } + + ob_start(); + + include self::PATH.func_get_arg(0).'.php'; + + return ob_get_clean(); + } + + /** + * Render a page layout + * + * @access public + * @param string $template_name Template name + * @param array $template_args Key/value map + * @param string $layout_name Layout name + * @return string + */ + public function layout($template_name, array $template_args = array(), $layout_name = 'layout') + { + return $this->load( + $layout_name, + $template_args + array('content_for_layout' => $this->load($template_name, $template_args)) + ); + } +} diff --git a/app/Core/Translator.php b/app/Core/Translator.php new file mode 100644 index 000000000..be0be66ad --- /dev/null +++ b/app/Core/Translator.php @@ -0,0 +1,155 @@ +translate('I have %d kids', 5); + * + * @access public + * @return string + */ + public function translate($identifier) + { + $args = func_get_args(); + + array_shift($args); + array_unshift($args, $this->get($identifier, $identifier)); + + foreach ($args as &$arg) { + $arg = htmlspecialchars($arg, ENT_QUOTES, 'UTF-8', false); + } + + return call_user_func_array( + 'sprintf', + $args + ); + } + + /** + * Get a formatted number + * + * $translator->number(1234.56); + * + * @access public + * @param float $number Number to format + * @return string + */ + public function number($number) + { + return number_format( + $number, + $this->get('number.decimals', 2), + $this->get('number.decimals_separator', '.'), + $this->get('number.thousands_separator', ',') + ); + } + + /** + * Get a formatted currency number + * + * $translator->currency(1234.56); + * + * @access public + * @param float $amount Number to format + * @return string + */ + public function currency($amount) + { + $position = $this->get('currency.position', 'before'); + $symbol = $this->get('currency.symbol', '$'); + $str = ''; + + if ($position === 'before') { + $str .= $symbol; + } + + $str .= $this->number($amount); + + if ($position === 'after') { + $str .= ' '.$symbol; + } + + return $str; + } + + /** + * Get a formatted datetime + * + * $translator->datetime('%Y-%m-%d', time()); + * + * @access public + * @param string $format Format defined by the strftime function + * @param integer $timestamp Unix timestamp + * @return string + */ + public function datetime($format, $timestamp) + { + if (! $timestamp) { + return ''; + } + + return strftime($this->get($format, $format), (int) $timestamp); + } + + /** + * Get an identifier from the translations or return the default + * + * @access public + * @param string $idendifier Locale identifier + * @param string $default Default value + * @return string + */ + public function get($identifier, $default = '') + { + if (isset(self::$locales[$identifier])) { + return self::$locales[$identifier]; + } + else { + return $default; + } + } + + /** + * Load translations + * + * @static + * @access public + * @param string $language Locale code: fr_FR + */ + public static function load($language) + { + setlocale(LC_TIME, $language.'.UTF-8', $language); + + $filename = self::PATH.$language.DIRECTORY_SEPARATOR.'translations.php'; + + if (file_exists($filename)) { + self::$locales = require $filename; + } + } +} diff --git a/events/task_modification.php b/app/Event/TaskModification.php similarity index 95% rename from events/task_modification.php rename to app/Event/TaskModification.php index 97ee73fd6..b1d412c74 100644 --- a/events/task_modification.php +++ b/app/Event/TaskModification.php @@ -2,8 +2,8 @@ namespace Event; -use \Core\Listener; -use \Model\Project; +use Core\Listener; +use Model\Project; /** * Task modification listener diff --git a/locales/es_ES/translations.php b/app/Locales/es_ES/translations.php similarity index 99% rename from locales/es_ES/translations.php rename to app/Locales/es_ES/translations.php index ac97d46ca..ce7979721 100644 --- a/locales/es_ES/translations.php +++ b/app/Locales/es_ES/translations.php @@ -330,4 +330,5 @@ return array( // 'Filter by category' => '', // 'All categories' => '', // 'No category' => '', + // 'The name is required' => '', ); diff --git a/locales/fr_FR/translations.php b/app/Locales/fr_FR/translations.php similarity index 99% rename from locales/fr_FR/translations.php rename to app/Locales/fr_FR/translations.php index 46faf5029..c93a83aeb 100644 --- a/locales/fr_FR/translations.php +++ b/app/Locales/fr_FR/translations.php @@ -330,4 +330,5 @@ return array( 'Filter by category' => 'Filtrer par catégorie', 'All categories' => 'Toutes les catégories', 'No category' => 'Aucune catégorie', + 'The name is required' => 'Le nom est requis', ); diff --git a/locales/pl_PL/translations.php b/app/Locales/pl_PL/translations.php similarity index 99% rename from locales/pl_PL/translations.php rename to app/Locales/pl_PL/translations.php index 94726c201..81ecaf011 100644 --- a/locales/pl_PL/translations.php +++ b/app/Locales/pl_PL/translations.php @@ -335,4 +335,5 @@ return array( // 'Filter by category' => '', // 'All categories' => '', // 'No category' => '', + // 'The name is required' => '', ); diff --git a/locales/pt_BR/translations.php b/app/Locales/pt_BR/translations.php similarity index 99% rename from locales/pt_BR/translations.php rename to app/Locales/pt_BR/translations.php index fc91b0b27..7c9a6c170 100644 --- a/locales/pt_BR/translations.php +++ b/app/Locales/pt_BR/translations.php @@ -331,4 +331,5 @@ return array( // 'Filter by category' => '', // 'All categories' => '', // 'No category' => '', + // 'The name is required' => '', ); diff --git a/models/acl.php b/app/Model/Acl.php similarity index 99% rename from models/acl.php rename to app/Model/Acl.php index 0d1cd06e3..ad2118f42 100644 --- a/models/acl.php +++ b/app/Model/Acl.php @@ -2,8 +2,6 @@ namespace Model; -require_once __DIR__.'/base.php'; - /** * Acl model * diff --git a/models/action.php b/app/Model/Action.php similarity index 91% rename from models/action.php rename to app/Model/Action.php index c8cbf3b14..d1b97ebc1 100644 --- a/models/action.php +++ b/app/Model/Action.php @@ -2,11 +2,9 @@ namespace Model; -require_once __DIR__.'/base.php'; -require_once __DIR__.'/task.php'; - -use \SimpleValidator\Validator; -use \SimpleValidator\Validators; +use LogicException; +use SimpleValidator\Validator; +use SimpleValidator\Validators; /** * Action model @@ -222,31 +220,25 @@ class Action extends Base { switch ($name) { case 'TaskClose': - require_once __DIR__.'/../actions/task_close.php'; $className = '\Action\TaskClose'; return new $className($project_id, new Task($this->db, $this->event)); case 'TaskAssignCurrentUser': - require_once __DIR__.'/../actions/task_assign_current_user.php'; $className = '\Action\TaskAssignCurrentUser'; return new $className($project_id, new Task($this->db, $this->event), new Acl($this->db, $this->event)); case 'TaskAssignSpecificUser': - require_once __DIR__.'/../actions/task_assign_specific_user.php'; $className = '\Action\TaskAssignSpecificUser'; return new $className($project_id, new Task($this->db, $this->event)); case 'TaskDuplicateAnotherProject': - require_once __DIR__.'/../actions/task_duplicate_another_project.php'; $className = '\Action\TaskDuplicateAnotherProject'; return new $className($project_id, new Task($this->db, $this->event)); case 'TaskAssignColorUser': - require_once __DIR__.'/../actions/task_assign_color_user.php'; $className = '\Action\TaskAssignColorUser'; return new $className($project_id, new Task($this->db, $this->event)); case 'TaskAssignColorCategory': - require_once __DIR__.'/../actions/task_assign_color_category.php'; $className = '\Action\TaskAssignColorCategory'; return new $className($project_id, new Task($this->db, $this->event)); default: - throw new \LogicException('Action not found: '.$name); + throw new LogicException('Action not found: '.$name); } } diff --git a/models/base.php b/app/Model/Base.php similarity index 55% rename from models/base.php rename to app/Model/Base.php index f2a3194e2..fef2ddbb9 100644 --- a/models/base.php +++ b/app/Model/Base.php @@ -2,18 +2,21 @@ namespace Model; -require __DIR__.'/../vendor/SimpleValidator/Validator.php'; -require __DIR__.'/../vendor/SimpleValidator/Base.php'; -require __DIR__.'/../vendor/SimpleValidator/Validators/Required.php'; -require __DIR__.'/../vendor/SimpleValidator/Validators/Unique.php'; -require __DIR__.'/../vendor/SimpleValidator/Validators/MaxLength.php'; -require __DIR__.'/../vendor/SimpleValidator/Validators/MinLength.php'; -require __DIR__.'/../vendor/SimpleValidator/Validators/Integer.php'; -require __DIR__.'/../vendor/SimpleValidator/Validators/Equals.php'; -require __DIR__.'/../vendor/SimpleValidator/Validators/AlphaNumeric.php'; -require __DIR__.'/../vendor/SimpleValidator/Validators/GreaterThan.php'; -require __DIR__.'/../vendor/SimpleValidator/Validators/Date.php'; -require __DIR__.'/../vendor/SimpleValidator/Validators/Email.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validator.php'; +require __DIR__.'/../../vendor/SimpleValidator/Base.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validators/Required.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validators/Unique.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validators/MaxLength.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validators/MinLength.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validators/Integer.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validators/Equals.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validators/AlphaNumeric.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validators/GreaterThan.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validators/Date.php'; +require __DIR__.'/../../vendor/SimpleValidator/Validators/Email.php'; + +use Core\Event; +use PicoDb\Database; /** * Base model class @@ -43,10 +46,10 @@ abstract class Base * Constructor * * @access public - * @param PicoDb\Database $db Database instance + * @param \PicoDb\Database $db Database instance * @param \Core\Event $event Event dispatcher instance */ - public function __construct(\PicoDb\Database $db, \Core\Event $event) + public function __construct(Database $db, Event $event) { $this->db = $db; $this->event = $event; diff --git a/models/board.php b/app/Model/Board.php similarity index 98% rename from models/board.php rename to app/Model/Board.php index 3229c44ed..59a98923a 100644 --- a/models/board.php +++ b/app/Model/Board.php @@ -2,11 +2,8 @@ namespace Model; -require_once __DIR__.'/base.php'; -require_once __DIR__.'/task.php'; - -use \SimpleValidator\Validator; -use \SimpleValidator\Validators; +use SimpleValidator\Validator; +use SimpleValidator\Validators; /** * Board model diff --git a/models/category.php b/app/Model/Category.php similarity index 99% rename from models/category.php rename to app/Model/Category.php index 2a1891a57..9be37f9d5 100644 --- a/models/category.php +++ b/app/Model/Category.php @@ -2,8 +2,6 @@ namespace Model; -require_once __DIR__.'/base.php'; - use SimpleValidator\Validator; use SimpleValidator\Validators; diff --git a/models/comment.php b/app/Model/Comment.php similarity index 97% rename from models/comment.php rename to app/Model/Comment.php index 453c2afcf..b51020700 100644 --- a/models/comment.php +++ b/app/Model/Comment.php @@ -2,10 +2,8 @@ namespace Model; -require_once __DIR__.'/base.php'; - -use \SimpleValidator\Validator; -use \SimpleValidator\Validators; +use SimpleValidator\Validator; +use SimpleValidator\Validators; /** * Comment model diff --git a/models/config.php b/app/Model/Config.php similarity index 97% rename from models/config.php rename to app/Model/Config.php index d18b8ec5d..994f0bc8e 100644 --- a/models/config.php +++ b/app/Model/Config.php @@ -2,10 +2,8 @@ namespace Model; -require_once __DIR__.'/base.php'; - -use \SimpleValidator\Validator; -use \SimpleValidator\Validators; +use SimpleValidator\Validator; +use SimpleValidator\Validators; /** * Config model diff --git a/models/google.php b/app/Model/Google.php similarity index 92% rename from models/google.php rename to app/Model/Google.php index 4f83a41e4..f5beb8f85 100644 --- a/models/google.php +++ b/app/Model/Google.php @@ -2,14 +2,13 @@ namespace Model; -require_once __DIR__.'/base.php'; -require __DIR__.'/../vendor/OAuth/bootstrap.php'; +require __DIR__.'/../../vendor/OAuth/bootstrap.php'; -use \OAuth\Common\Storage\Session; -use \OAuth\Common\Consumer\Credentials; -use \OAuth\Common\Http\Uri\UriFactory; -use \OAuth\ServiceFactory; -use \OAuth\Common\Http\Exception\TokenResponseException; +use OAuth\Common\Storage\Session; +use OAuth\Common\Consumer\Credentials; +use OAuth\Common\Http\Uri\UriFactory; +use OAuth\ServiceFactory; +use OAuth\Common\Http\Exception\TokenResponseException; /** * Google model diff --git a/models/last_login.php b/app/Model/LastLogin.php similarity index 98% rename from models/last_login.php rename to app/Model/LastLogin.php index a991ee307..56739b480 100644 --- a/models/last_login.php +++ b/app/Model/LastLogin.php @@ -2,8 +2,6 @@ namespace Model; -require_once __DIR__.'/base.php'; - /** * LastLogin model * diff --git a/models/ldap.php b/app/Model/Ldap.php similarity index 98% rename from models/ldap.php rename to app/Model/Ldap.php index 69fe9becc..3359318c3 100644 --- a/models/ldap.php +++ b/app/Model/Ldap.php @@ -2,8 +2,6 @@ namespace Model; -require_once __DIR__.'/base.php'; - /** * LDAP model * diff --git a/models/project.php b/app/Model/Project.php similarity index 98% rename from models/project.php rename to app/Model/Project.php index cbbbfda2a..852948309 100644 --- a/models/project.php +++ b/app/Model/Project.php @@ -2,12 +2,6 @@ namespace Model; -require_once __DIR__.'/base.php'; -require_once __DIR__.'/acl.php'; -require_once __DIR__.'/board.php'; -require_once __DIR__.'/task.php'; -require_once __DIR__.'/../events/task_modification.php'; - use SimpleValidator\Validator; use SimpleValidator\Validators; use Event\TaskModification; diff --git a/models/remember_me.php b/app/Model/RememberMe.php similarity index 99% rename from models/remember_me.php rename to app/Model/RememberMe.php index be6b4e53b..1494b14a0 100644 --- a/models/remember_me.php +++ b/app/Model/RememberMe.php @@ -2,8 +2,6 @@ namespace Model; -require_once __DIR__.'/base.php'; - /** * RememberMe model * diff --git a/models/task.php b/app/Model/Task.php similarity index 99% rename from models/task.php rename to app/Model/Task.php index 0c62a9f44..bd67d272c 100644 --- a/models/task.php +++ b/app/Model/Task.php @@ -2,8 +2,6 @@ namespace Model; -require_once __DIR__.'/base.php'; - use SimpleValidator\Validator; use SimpleValidator\Validators; use DateTime; diff --git a/models/user.php b/app/Model/User.php similarity index 99% rename from models/user.php rename to app/Model/User.php index bb54fc2e9..bce717a71 100644 --- a/models/user.php +++ b/app/Model/User.php @@ -2,10 +2,8 @@ namespace Model; -require_once __DIR__.'/base.php'; - -use \SimpleValidator\Validator; -use \SimpleValidator\Validators; +use SimpleValidator\Validator; +use SimpleValidator\Validators; /** * User model diff --git a/schemas/mysql.php b/app/Schema/Mysql.php similarity index 99% rename from schemas/mysql.php rename to app/Schema/Mysql.php index eb8694651..6764ad5d8 100644 --- a/schemas/mysql.php +++ b/app/Schema/Mysql.php @@ -2,6 +2,8 @@ namespace Schema; +const VERSION = 16; + function version_16($pdo) { $pdo->exec(" diff --git a/schemas/sqlite.php b/app/Schema/Sqlite.php similarity index 99% rename from schemas/sqlite.php rename to app/Schema/Sqlite.php index b444faa5a..0bb4de8df 100644 --- a/schemas/sqlite.php +++ b/app/Schema/Sqlite.php @@ -2,6 +2,8 @@ namespace Schema; +const VERSION = 16; + function version_16($pdo) { $pdo->exec(" diff --git a/templates/action_index.php b/app/Templates/action_index.php similarity index 100% rename from templates/action_index.php rename to app/Templates/action_index.php diff --git a/templates/action_params.php b/app/Templates/action_params.php similarity index 100% rename from templates/action_params.php rename to app/Templates/action_params.php diff --git a/templates/action_remove.php b/app/Templates/action_remove.php similarity index 100% rename from templates/action_remove.php rename to app/Templates/action_remove.php diff --git a/templates/app_notfound.php b/app/Templates/app_notfound.php similarity index 100% rename from templates/app_notfound.php rename to app/Templates/app_notfound.php diff --git a/templates/board_assign.php b/app/Templates/board_assign.php similarity index 100% rename from templates/board_assign.php rename to app/Templates/board_assign.php diff --git a/templates/board_edit.php b/app/Templates/board_edit.php similarity index 100% rename from templates/board_edit.php rename to app/Templates/board_edit.php diff --git a/templates/board_index.php b/app/Templates/board_index.php similarity index 100% rename from templates/board_index.php rename to app/Templates/board_index.php diff --git a/templates/board_public.php b/app/Templates/board_public.php similarity index 100% rename from templates/board_public.php rename to app/Templates/board_public.php diff --git a/templates/board_remove.php b/app/Templates/board_remove.php similarity index 100% rename from templates/board_remove.php rename to app/Templates/board_remove.php diff --git a/templates/board_show.php b/app/Templates/board_show.php similarity index 100% rename from templates/board_show.php rename to app/Templates/board_show.php diff --git a/templates/category_edit.php b/app/Templates/category_edit.php similarity index 100% rename from templates/category_edit.php rename to app/Templates/category_edit.php diff --git a/templates/category_index.php b/app/Templates/category_index.php similarity index 100% rename from templates/category_index.php rename to app/Templates/category_index.php diff --git a/templates/category_remove.php b/app/Templates/category_remove.php similarity index 100% rename from templates/category_remove.php rename to app/Templates/category_remove.php diff --git a/templates/comment_forbidden.php b/app/Templates/comment_forbidden.php similarity index 100% rename from templates/comment_forbidden.php rename to app/Templates/comment_forbidden.php diff --git a/templates/comment_remove.php b/app/Templates/comment_remove.php similarity index 100% rename from templates/comment_remove.php rename to app/Templates/comment_remove.php diff --git a/templates/comment_show.php b/app/Templates/comment_show.php similarity index 100% rename from templates/comment_show.php rename to app/Templates/comment_show.php diff --git a/templates/config_index.php b/app/Templates/config_index.php similarity index 100% rename from templates/config_index.php rename to app/Templates/config_index.php diff --git a/templates/layout.php b/app/Templates/layout.php similarity index 100% rename from templates/layout.php rename to app/Templates/layout.php diff --git a/templates/project_edit.php b/app/Templates/project_edit.php similarity index 100% rename from templates/project_edit.php rename to app/Templates/project_edit.php diff --git a/templates/project_forbidden.php b/app/Templates/project_forbidden.php similarity index 100% rename from templates/project_forbidden.php rename to app/Templates/project_forbidden.php diff --git a/templates/project_index.php b/app/Templates/project_index.php similarity index 100% rename from templates/project_index.php rename to app/Templates/project_index.php diff --git a/templates/project_new.php b/app/Templates/project_new.php similarity index 100% rename from templates/project_new.php rename to app/Templates/project_new.php diff --git a/templates/project_remove.php b/app/Templates/project_remove.php similarity index 100% rename from templates/project_remove.php rename to app/Templates/project_remove.php diff --git a/templates/project_search.php b/app/Templates/project_search.php similarity index 100% rename from templates/project_search.php rename to app/Templates/project_search.php diff --git a/templates/project_tasks.php b/app/Templates/project_tasks.php similarity index 100% rename from templates/project_tasks.php rename to app/Templates/project_tasks.php diff --git a/templates/project_users.php b/app/Templates/project_users.php similarity index 100% rename from templates/project_users.php rename to app/Templates/project_users.php diff --git a/templates/task_close.php b/app/Templates/task_close.php similarity index 100% rename from templates/task_close.php rename to app/Templates/task_close.php diff --git a/templates/task_edit.php b/app/Templates/task_edit.php similarity index 100% rename from templates/task_edit.php rename to app/Templates/task_edit.php diff --git a/templates/task_layout.php b/app/Templates/task_layout.php similarity index 100% rename from templates/task_layout.php rename to app/Templates/task_layout.php diff --git a/templates/task_new.php b/app/Templates/task_new.php similarity index 100% rename from templates/task_new.php rename to app/Templates/task_new.php diff --git a/templates/task_open.php b/app/Templates/task_open.php similarity index 100% rename from templates/task_open.php rename to app/Templates/task_open.php diff --git a/templates/task_remove.php b/app/Templates/task_remove.php similarity index 100% rename from templates/task_remove.php rename to app/Templates/task_remove.php diff --git a/templates/task_show.php b/app/Templates/task_show.php similarity index 100% rename from templates/task_show.php rename to app/Templates/task_show.php diff --git a/templates/task_sidebar.php b/app/Templates/task_sidebar.php similarity index 100% rename from templates/task_sidebar.php rename to app/Templates/task_sidebar.php diff --git a/templates/user_edit.php b/app/Templates/user_edit.php similarity index 100% rename from templates/user_edit.php rename to app/Templates/user_edit.php diff --git a/templates/user_forbidden.php b/app/Templates/user_forbidden.php similarity index 100% rename from templates/user_forbidden.php rename to app/Templates/user_forbidden.php diff --git a/templates/user_index.php b/app/Templates/user_index.php similarity index 100% rename from templates/user_index.php rename to app/Templates/user_index.php diff --git a/templates/user_login.php b/app/Templates/user_login.php similarity index 100% rename from templates/user_login.php rename to app/Templates/user_login.php diff --git a/templates/user_new.php b/app/Templates/user_new.php similarity index 100% rename from templates/user_new.php rename to app/Templates/user_new.php diff --git a/templates/user_remove.php b/app/Templates/user_remove.php similarity index 100% rename from templates/user_remove.php rename to app/Templates/user_remove.php diff --git a/check_setup.php b/app/check_setup.php similarity index 96% rename from check_setup.php rename to app/check_setup.php index 1484d459d..9ed16967a 100644 --- a/check_setup.php +++ b/app/check_setup.php @@ -36,5 +36,5 @@ if (! is_writable('data')) { // Include password_compat for PHP < 5.5 if (version_compare(PHP_VERSION, '5.5.0', '<')) { - require __DIR__.'/vendor/password.php'; + require __DIR__.'/../vendor/password.php'; } diff --git a/app/common.php b/app/common.php new file mode 100644 index 000000000..5a26860fa --- /dev/null +++ b/app/common.php @@ -0,0 +1,98 @@ +execute(); + +$registry = new Registry; + +$registry->db = function() use ($registry) { + require __DIR__.'/../vendor/PicoDb/Database.php'; + + if (DB_DRIVER === 'sqlite') { + + require __DIR__.'/Schema/Sqlite.php'; + + $db = new \PicoDb\Database(array( + 'driver' => 'sqlite', + 'filename' => DB_FILENAME + )); + } + elseif (DB_DRIVER === 'mysql') { + + require __DIR__.'/Schema/Mysql.php'; + + $db = new \PicoDb\Database(array( + 'driver' => 'mysql', + 'hostname' => DB_HOSTNAME, + 'username' => DB_USERNAME, + 'password' => DB_PASSWORD, + 'database' => DB_NAME, + 'charset' => 'utf8', + )); + } + else { + die('Database driver not supported'); + } + + if ($db->schema()->check(Schema\VERSION)) { + return $db; + } + else { + die('Unable to migrate database schema!'); + } +}; + +$registry->event = function() use ($registry) { + return new Event; +}; diff --git a/core/helper.php b/app/helpers.php similarity index 100% rename from core/helper.php rename to app/helpers.php diff --git a/app/translator.php b/app/translator.php new file mode 100644 index 000000000..338821d3d --- /dev/null +++ b/app/translator.php @@ -0,0 +1,36 @@ +currency($value); +} + +// Get a formatted number +function n($value) +{ + $t = new Translator; + return $t->number($value); +} + +// Get a locale date +function dt($format, $timestamp) +{ + $t = new Translator; + return $t->datetime($format, $timestamp); +} + +// Plurals, return $t2 if $value > 1 +function p($value, $t1, $t2) { + return $value > 1 ? $t2 : $t1; +} diff --git a/assets/js/board.js b/assets/js/board.js index af54d0c8a..357849e63 100644 --- a/assets/js/board.js +++ b/assets/js/board.js @@ -45,6 +45,7 @@ // Stop events function board_unload_events() { + $("[data-task-id]").off(); clearInterval(checkInterval); } diff --git a/common.php b/common.php deleted file mode 100644 index 70b18a51b..000000000 --- a/common.php +++ /dev/null @@ -1,156 +0,0 @@ -db_version = 16; - -$registry->db = function() use ($registry) { - require __DIR__.'/vendor/PicoDb/Database.php'; - - if (DB_DRIVER === 'sqlite') { - - require __DIR__.'/schemas/sqlite.php'; - - $db = new \PicoDb\Database(array( - 'driver' => 'sqlite', - 'filename' => DB_FILENAME - )); - } - elseif (DB_DRIVER === 'mysql') { - - require __DIR__.'/schemas/mysql.php'; - - $db = new \PicoDb\Database(array( - 'driver' => 'mysql', - 'hostname' => DB_HOSTNAME, - 'username' => DB_USERNAME, - 'password' => DB_PASSWORD, - 'database' => DB_NAME, - 'charset' => 'utf8', - )); - } - else { - die('Database driver not supported'); - } - - if ($db->schema()->check($registry->db_version)) { - return $db; - } - else { - die('Unable to migrate database schema!'); - } -}; - -$registry->event = function() use ($registry) { - require __DIR__.'/core/event.php'; - return new \Core\Event; -}; - -$registry->action = function() use ($registry) { - require_once __DIR__.'/models/action.php'; - return new \Model\Action($registry->shared('db'), $registry->shared('event')); -}; - -$registry->config = function() use ($registry) { - require_once __DIR__.'/models/config.php'; - return new \Model\Config($registry->shared('db'), $registry->shared('event')); -}; - -$registry->acl = function() use ($registry) { - require_once __DIR__.'/models/acl.php'; - return new \Model\Acl($registry->shared('db'), $registry->shared('event')); -}; - -$registry->user = function() use ($registry) { - require_once __DIR__.'/models/user.php'; - return new \Model\User($registry->shared('db'), $registry->shared('event')); -}; - -$registry->comment = function() use ($registry) { - require_once __DIR__.'/models/comment.php'; - return new \Model\Comment($registry->shared('db'), $registry->shared('event')); -}; - -$registry->task = function() use ($registry) { - require_once __DIR__.'/models/task.php'; - return new \Model\Task($registry->shared('db'), $registry->shared('event')); -}; - -$registry->board = function() use ($registry) { - require_once __DIR__.'/models/board.php'; - return new \Model\Board($registry->shared('db'), $registry->shared('event')); -}; - -$registry->project = function() use ($registry) { - require_once __DIR__.'/models/project.php'; - return new \Model\Project($registry->shared('db'), $registry->shared('event')); -}; - -$registry->action = function() use ($registry) { - require_once __DIR__.'/models/action.php'; - return new \Model\Action($registry->shared('db'), $registry->shared('event')); -}; - -$registry->rememberMe = function() use ($registry) { - require_once __DIR__.'/models/remember_me.php'; - return new \Model\RememberMe($registry->shared('db'), $registry->shared('event')); -}; - -$registry->lastLogin = function() use ($registry) { - require_once __DIR__.'/models/last_login.php'; - return new \Model\LastLogin($registry->shared('db'), $registry->shared('event')); -}; - -$registry->google = function() use ($registry) { - require_once __DIR__.'/models/google.php'; - return new \Model\Google($registry->shared('db'), $registry->shared('event')); -}; - -$registry->category = function() use ($registry) { - require_once __DIR__.'/models/category.php'; - return new \Model\Category($registry->shared('db'), $registry->shared('event')); -}; - -if (file_exists('config.php')) require 'config.php'; - -// Board refresh frequency in seconds for the public board view -defined('BOARD_PUBLIC_CHECK_INTERVAL') or define('BOARD_PUBLIC_CHECK_INTERVAL', 60); - -// Board refresh frequency in seconds (the value 0 disable this feature) -defined('BOARD_CHECK_INTERVAL') or define('BOARD_CHECK_INTERVAL', 10); - -// Custom session save path -defined('SESSION_SAVE_PATH') or define('SESSION_SAVE_PATH', ''); - -// Application version -defined('APP_VERSION') or define('APP_VERSION', 'master'); - -// Base directory -define('BASE_URL_DIRECTORY', dirname($_SERVER['PHP_SELF'])); - -// Database driver: sqlite or mysql -defined('DB_DRIVER') or define('DB_DRIVER', 'sqlite'); - -// Sqlite configuration -defined('DB_FILENAME') or define('DB_FILENAME', 'data/db.sqlite'); - -// Mysql configuration -defined('DB_USERNAME') or define('DB_USERNAME', 'root'); -defined('DB_PASSWORD') or define('DB_PASSWORD', ''); -defined('DB_HOSTNAME') or define('DB_HOSTNAME', 'localhost'); -defined('DB_NAME') or define('DB_NAME', 'kanboard'); - -// LDAP configuration -defined('LDAP_AUTH') or define('LDAP_AUTH', false); -defined('LDAP_SERVER') or define('LDAP_SERVER', ''); -defined('LDAP_PORT') or define('LDAP_PORT', 389); -defined('LDAP_USER_DN') or define('LDAP_USER_DN', '%s'); - -// Google authentication -defined('GOOGLE_AUTH') or define('GOOGLE_AUTH', false); -defined('GOOGLE_CLIENT_ID') or define('GOOGLE_CLIENT_ID', ''); -defined('GOOGLE_CLIENT_SECRET') or define('GOOGLE_CLIENT_SECRET', ''); diff --git a/config.default.php b/config.default.php index 99acb8832..6810ce9d3 100644 --- a/config.default.php +++ b/config.default.php @@ -1,7 +1,10 @@ 'value']); - public function load() - { - if (func_num_args() < 1 || func_num_args() > 2) { - die('Invalid template arguments'); - } - - if (! file_exists(self::PATH.func_get_arg(0).'.php')) { - die('Unable to load the template: "'.func_get_arg(0).'"'); - } - - if (func_num_args() === 2) { - - if (! is_array(func_get_arg(1))) { - die('Template variables must be an array'); - } - - extract(func_get_arg(1)); - } - - ob_start(); - - include self::PATH.func_get_arg(0).'.php'; - - return ob_get_clean(); - } - - public function layout($template_name, array $template_args = array(), $layout_name = 'layout') - { - return $this->load($layout_name, $template_args + array('content_for_layout' => $this->load($template_name, $template_args))); - } -} diff --git a/core/translator.php b/core/translator.php deleted file mode 100644 index 8adb1bfd0..000000000 --- a/core/translator.php +++ /dev/null @@ -1,130 +0,0 @@ -getFilename(), '.php') !== false) { - $locales = array_merge($locales, include $fileinfo->getPathname()); - } - } - } - - container($locales); - } - - function container($locales = null) - { - static $values = array(); - - if ($locales !== null) { - $values = $locales; - } - - return $values; - } -} - - -namespace { - - function t() { - return call_user_func_array('\Translator\translate', func_get_args()); - } - - function c() { - return call_user_func_array('\Translator\currency', func_get_args()); - } - - function n() { - return call_user_func_array('\Translator\number', func_get_args()); - } - - function dt() { - return call_user_func_array('\Translator\datetime', func_get_args()); - } - - function p($value, $t1, $t2) { - return $value > 1 ? $t2 : $t1; - } -} diff --git a/controllers/.htaccess b/docs/.htaccess similarity index 100% rename from controllers/.htaccess rename to docs/.htaccess diff --git a/index.php b/index.php index bd691c108..cee8017d8 100644 --- a/index.php +++ b/index.php @@ -1,8 +1,9 @@ execute(); diff --git a/schemas/.htaccess b/schemas/.htaccess deleted file mode 100644 index 14249c50b..000000000 --- a/schemas/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all \ No newline at end of file diff --git a/core/.htaccess b/scripts/.htaccess similarity index 100% rename from core/.htaccess rename to scripts/.htaccess diff --git a/templates/.htaccess b/templates/.htaccess deleted file mode 100644 index 14249c50b..000000000 --- a/templates/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all \ No newline at end of file diff --git a/models/.htaccess b/tests/.htaccess similarity index 100% rename from models/.htaccess rename to tests/.htaccess diff --git a/tests/Base.php b/tests/Base.php index 400643ac7..9c8cfc4a4 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -5,21 +5,28 @@ if (version_compare(PHP_VERSION, '5.5.0', '<')) { } require_once __DIR__.'/../vendor/PicoDb/Database.php'; -require_once __DIR__.'/../core/event.php'; -require_once __DIR__.'/../core/translator.php'; -require_once __DIR__.'/../schemas/sqlite.php'; -require_once __DIR__.'/../models/task.php'; -require_once __DIR__.'/../models/acl.php'; -require_once __DIR__.'/../models/comment.php'; -require_once __DIR__.'/../models/project.php'; -require_once __DIR__.'/../models/user.php'; -require_once __DIR__.'/../models/board.php'; -require_once __DIR__.'/../models/action.php'; -require_once __DIR__.'/../actions/task_close.php'; -require_once __DIR__.'/../actions/task_assign_specific_user.php'; -require_once __DIR__.'/../actions/task_assign_color_user.php'; -require_once __DIR__.'/../actions/task_assign_current_user.php'; -require_once __DIR__.'/../actions/task_duplicate_another_project.php'; +require_once __DIR__.'/../app/Schema/Sqlite.php'; + +require_once __DIR__.'/../app/Core/Listener.php'; +require_once __DIR__.'/../app/Core/Event.php'; +require_once __DIR__.'/../app/Core/Translator.php'; +require_once __DIR__.'/../app/translator.php'; + +require_once __DIR__.'/../app/Model/Base.php'; +require_once __DIR__.'/../app/Model/Task.php'; +require_once __DIR__.'/../app/Model/Acl.php'; +require_once __DIR__.'/../app/Model/Comment.php'; +require_once __DIR__.'/../app/Model/Project.php'; +require_once __DIR__.'/../app/Model/User.php'; +require_once __DIR__.'/../app/Model/Board.php'; +require_once __DIR__.'/../app/Model/Action.php'; + +require_once __DIR__.'/../app/Action/Base.php'; +require_once __DIR__.'/../app/Action/TaskClose.php'; +require_once __DIR__.'/../app/Action/TaskAssignSpecificUser.php'; +require_once __DIR__.'/../app/Action/TaskAssignColorUser.php'; +require_once __DIR__.'/../app/Action/TaskAssignCurrentUser.php'; +require_once __DIR__.'/../app/Action/TaskDuplicateAnotherProject.php'; abstract class Base extends PHPUnit_Framework_TestCase { @@ -36,7 +43,7 @@ abstract class Base extends PHPUnit_Framework_TestCase 'filename' => ':memory:' )); - if ($db->schema()->check(16)) { + if ($db->schema()->check(\Schema\VERSION)) { return $db; } else {