summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-05-22 12:28:28 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-05-22 12:28:28 -0400
commit2230dd4e6b148346c0ec596b9e3e12996a762ed8 (patch)
treeef99ccde4f8b18592a3fb06a6ec45162c501fe38
parenta750b8ab2a0cb715da6fd9025a7ec8375db68a4d (diff)
Code refactoring (add autoloader and change files organization)
-rw-r--r--app/.htaccess (renamed from actions/.htaccess)0
-rw-r--r--app/Action/Base.php (renamed from actions/base.php)4
-rw-r--r--app/Action/TaskAssignColorCategory.php (renamed from actions/task_assign_color_category.php)4
-rw-r--r--app/Action/TaskAssignColorUser.php (renamed from actions/task_assign_color_user.php)4
-rw-r--r--app/Action/TaskAssignCurrentUser.php (renamed from actions/task_assign_current_user.php)5
-rw-r--r--app/Action/TaskAssignSpecificUser.php (renamed from actions/task_assign_specific_user.php)4
-rw-r--r--app/Action/TaskClose.php (renamed from actions/task_close.php)4
-rw-r--r--app/Action/TaskDuplicateAnotherProject.php (renamed from actions/task_duplicate_another_project.php)4
-rw-r--r--app/Controller/Action.php (renamed from controllers/action.php)2
-rw-r--r--app/Controller/App.php (renamed from controllers/app.php)4
-rw-r--r--app/Controller/Base.php (renamed from controllers/base.php)157
-rw-r--r--app/Controller/Board.php (renamed from controllers/board.php)11
-rw-r--r--app/Controller/Category.php (renamed from controllers/category.php)2
-rw-r--r--app/Controller/Comment.php (renamed from controllers/comment.php)2
-rw-r--r--app/Controller/Config.php (renamed from controllers/config.php)2
-rw-r--r--app/Controller/Project.php (renamed from controllers/project.php)4
-rw-r--r--app/Controller/Task.php (renamed from controllers/task.php)6
-rw-r--r--app/Controller/User.php (renamed from controllers/user.php)2
-rw-r--r--app/Core/Event.php (renamed from core/event.php)14
-rw-r--r--app/Core/Listener.php17
-rw-r--r--app/Core/Loader.php37
-rw-r--r--app/Core/Registry.php (renamed from core/registry.php)0
-rw-r--r--app/Core/Request.php (renamed from core/request.php)0
-rw-r--r--app/Core/Response.php (renamed from core/response.php)0
-rw-r--r--app/Core/Router.php (renamed from core/router.php)65
-rw-r--r--app/Core/Session.php (renamed from core/session.php)0
-rw-r--r--app/Core/Template.php72
-rw-r--r--app/Core/Translator.php155
-rw-r--r--app/Event/TaskModification.php (renamed from events/task_modification.php)4
-rw-r--r--app/Locales/es_ES/translations.php (renamed from locales/es_ES/translations.php)1
-rw-r--r--app/Locales/fr_FR/translations.php (renamed from locales/fr_FR/translations.php)1
-rw-r--r--app/Locales/pl_PL/translations.php (renamed from locales/pl_PL/translations.php)1
-rw-r--r--app/Locales/pt_BR/translations.php (renamed from locales/pt_BR/translations.php)1
-rw-r--r--app/Model/Acl.php (renamed from models/acl.php)2
-rw-r--r--app/Model/Action.php (renamed from models/action.php)16
-rw-r--r--app/Model/Base.php (renamed from models/base.php)31
-rw-r--r--app/Model/Board.php (renamed from models/board.php)7
-rw-r--r--app/Model/Category.php (renamed from models/category.php)2
-rw-r--r--app/Model/Comment.php (renamed from models/comment.php)6
-rw-r--r--app/Model/Config.php (renamed from models/config.php)6
-rw-r--r--app/Model/Google.php (renamed from models/google.php)15
-rw-r--r--app/Model/LastLogin.php (renamed from models/last_login.php)2
-rw-r--r--app/Model/Ldap.php (renamed from models/ldap.php)2
-rw-r--r--app/Model/Project.php (renamed from models/project.php)6
-rw-r--r--app/Model/RememberMe.php (renamed from models/remember_me.php)2
-rw-r--r--app/Model/Task.php (renamed from models/task.php)2
-rw-r--r--app/Model/User.php (renamed from models/user.php)6
-rw-r--r--app/Schema/Mysql.php (renamed from schemas/mysql.php)2
-rw-r--r--app/Schema/Sqlite.php (renamed from schemas/sqlite.php)2
-rw-r--r--app/Templates/action_index.php (renamed from templates/action_index.php)0
-rw-r--r--app/Templates/action_params.php (renamed from templates/action_params.php)0
-rw-r--r--app/Templates/action_remove.php (renamed from templates/action_remove.php)0
-rw-r--r--app/Templates/app_notfound.php (renamed from templates/app_notfound.php)0
-rw-r--r--app/Templates/board_assign.php (renamed from templates/board_assign.php)0
-rw-r--r--app/Templates/board_edit.php (renamed from templates/board_edit.php)0
-rw-r--r--app/Templates/board_index.php (renamed from templates/board_index.php)0
-rw-r--r--app/Templates/board_public.php (renamed from templates/board_public.php)0
-rw-r--r--app/Templates/board_remove.php (renamed from templates/board_remove.php)0
-rw-r--r--app/Templates/board_show.php (renamed from templates/board_show.php)0
-rw-r--r--app/Templates/category_edit.php (renamed from templates/category_edit.php)0
-rw-r--r--app/Templates/category_index.php (renamed from templates/category_index.php)0
-rw-r--r--app/Templates/category_remove.php (renamed from templates/category_remove.php)0
-rw-r--r--app/Templates/comment_forbidden.php (renamed from templates/comment_forbidden.php)0
-rw-r--r--app/Templates/comment_remove.php (renamed from templates/comment_remove.php)0
-rw-r--r--app/Templates/comment_show.php (renamed from templates/comment_show.php)0
-rw-r--r--app/Templates/config_index.php (renamed from templates/config_index.php)0
-rw-r--r--app/Templates/layout.php (renamed from templates/layout.php)0
-rw-r--r--app/Templates/project_edit.php (renamed from templates/project_edit.php)0
-rw-r--r--app/Templates/project_forbidden.php (renamed from templates/project_forbidden.php)0
-rw-r--r--app/Templates/project_index.php (renamed from templates/project_index.php)0
-rw-r--r--app/Templates/project_new.php (renamed from templates/project_new.php)0
-rw-r--r--app/Templates/project_remove.php (renamed from templates/project_remove.php)0
-rw-r--r--app/Templates/project_search.php (renamed from templates/project_search.php)0
-rw-r--r--app/Templates/project_tasks.php (renamed from templates/project_tasks.php)0
-rw-r--r--app/Templates/project_users.php (renamed from templates/project_users.php)0
-rw-r--r--app/Templates/task_close.php (renamed from templates/task_close.php)0
-rw-r--r--app/Templates/task_edit.php (renamed from templates/task_edit.php)0
-rw-r--r--app/Templates/task_layout.php (renamed from templates/task_layout.php)0
-rw-r--r--app/Templates/task_new.php (renamed from templates/task_new.php)0
-rw-r--r--app/Templates/task_open.php (renamed from templates/task_open.php)0
-rw-r--r--app/Templates/task_remove.php (renamed from templates/task_remove.php)0
-rw-r--r--app/Templates/task_show.php (renamed from templates/task_show.php)0
-rw-r--r--app/Templates/task_sidebar.php (renamed from templates/task_sidebar.php)0
-rw-r--r--app/Templates/user_edit.php (renamed from templates/user_edit.php)0
-rw-r--r--app/Templates/user_forbidden.php (renamed from templates/user_forbidden.php)0
-rw-r--r--app/Templates/user_index.php (renamed from templates/user_index.php)0
-rw-r--r--app/Templates/user_login.php (renamed from templates/user_login.php)0
-rw-r--r--app/Templates/user_new.php (renamed from templates/user_new.php)0
-rw-r--r--app/Templates/user_remove.php (renamed from templates/user_remove.php)0
-rw-r--r--app/check_setup.php (renamed from check_setup.php)2
-rw-r--r--app/common.php98
-rw-r--r--app/helpers.php (renamed from core/helper.php)0
-rw-r--r--app/translator.php36
-rw-r--r--assets/js/board.js1
-rw-r--r--common.php156
-rw-r--r--config.default.php5
-rw-r--r--core/template.php40
-rw-r--r--core/translator.php130
-rw-r--r--docs/.htaccess (renamed from controllers/.htaccess)0
-rw-r--r--index.php9
-rw-r--r--schemas/.htaccess1
-rw-r--r--scripts/.htaccess (renamed from core/.htaccess)0
-rw-r--r--templates/.htaccess1
-rw-r--r--tests/.htaccess (renamed from models/.htaccess)0
-rw-r--r--tests/Base.php39
105 files changed, 612 insertions, 604 deletions
diff --git a/actions/.htaccess b/app/.htaccess
index 14249c50..14249c50 100644
--- a/actions/.htaccess
+++ b/app/.htaccess
diff --git a/actions/base.php b/app/Action/Base.php
index 13e4b6ee..14b0a3c0 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
index 6fba5223..4304d084 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
index d5784270..9ff140b3 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
index a3d9559e..1c038966 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
index aabe5420..8c379bcc 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
index 22d61f29..32887d3c 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
index 6e1ee84b..7ef0f6ab 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
index 5c5d5726..b32a8906 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
index 68872a48..64f9461f 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
index 49376dce..bb9add4f 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
- *
- * @accesss protected
- * @var \Model\Acl
- */
- 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
+ * Registry instance
*
- * @accesss protected
- * @var \Model\Category
+ * @access private
+ * @var Core\Registry
*/
- protected $category;
+ private $registry;
/**
- * Event instance
+ * Constructor
*
- * @accesss protected
- * @var \Model\Event
+ * @access public
+ * @param \Core\Registry $registry Registry instance
*/
- protected $event;
+ public function __construct(Registry $registry)
+ {
+ $this->registry = $registry;
+ }
/**
- * Constructor
+ * Load automatically models
*
* @access public
- * @param \Core\Registry $registry
+ * @param string $name Model name
*/
- public function __construct(\Core\Registry $registry)
+ public function __get($name)
{
- $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');
+ $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()
@@ -227,6 +136,16 @@ abstract class Base
}
/**
+ * 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
*
* @access protected
@@ -254,16 +173,6 @@ abstract class Base
}
/**
- * 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)
*
* @access protected
diff --git a/controllers/board.php b/app/Controller/Board.php
index f7128210..c727a422 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
index 23de2735..f96c1d4a 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
index 93dbb5ad..c9f226f7 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
index 527c8a4c..b4a5b8d3 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
index 1b9fd110..5cb244a2 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
index bdedb9dd..2291ad43 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
index edd7ae45..e3fd8253 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
index 0941acac..2c029b49 100644
--- a/core/event.php
+++ b/app/Core/Event.php
@@ -3,20 +3,6 @@
namespace Core;
/**
- * Event listener interface
- *
- * @package core
- * @author Frederic Guillot
- */
-interface Listener {
-
- /**
- * @return boolean
- */
- public function execute(array $data);
-}
-
-/**
* Event dispatcher class
*
* @package core
diff --git a/app/Core/Listener.php b/app/Core/Listener.php
new file mode 100644
index 00000000..b8bdd680
--- /dev/null
+++ b/app/Core/Listener.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace Core;
+
+/**
+ * Event listener interface
+ *
+ * @package core
+ * @author Frederic Guillot
+ */
+interface Listener {
+
+ /**
+ * @return boolean
+ */
+ public function execute(array $data);
+}
diff --git a/app/Core/Loader.php b/app/Core/Loader.php
new file mode 100644
index 00000000..7c437654
--- /dev/null
+++ b/app/Core/Loader.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Core;
+
+/**
+ * Loader class
+ *
+ * @package core
+ * @author Frederic Guillot
+ */
+class Loader
+{
+ /**
+ * Load the missing class
+ *
+ * @access public
+ * @param string $class Class name
+ */
+ public function load($class)
+ {
+ $filename = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
+
+ if (file_exists($filename)) {
+ require $filename;
+ }
+ }
+
+ /**
+ * Register the autoloader
+ *
+ * @access public
+ */
+ public function execute()
+ {
+ spl_autoload_register(array($this, 'load'));
+ }
+}
diff --git a/core/registry.php b/app/Core/Registry.php
index f11d427c..f11d427c 100644
--- a/core/registry.php
+++ b/app/Core/Registry.php
diff --git a/core/request.php b/app/Core/Request.php
index df8ea41a..df8ea41a 100644
--- a/core/request.php
+++ b/app/Core/Request.php
diff --git a/core/response.php b/app/Core/Response.php
index a5f0e4dc..a5f0e4dc 100644
--- a/core/response.php
+++ b/app/Core/Response.php
diff --git a/core/router.php b/app/Core/Router.php
index 56a95e52..3a5df715 100644
--- a/core/router.php
+++ b/app/Core/Router.php
@@ -2,17 +2,46 @@
namespace Core;
-require __DIR__.'/request.php';
-require __DIR__.'/response.php';
-require __DIR__.'/session.php';
-require __DIR__.'/template.php';
-
+/**
+ * Router class
+ *
+ * @package core
+ * @author Frederic Guillot
+ */
class Router
{
+ /**
+ * Controller name
+ *
+ * @access private
+ * @var string
+ */
private $controller = '';
+
+ /**
+ * Action name
+ *
+ * @access private
+ * @var string
+ */
private $action = '';
+
+ /**
+ * Registry instance
+ *
+ * @access private
+ * @var Core\Registry
+ */
private $registry;
+ /**
+ * Constructor
+ *
+ * @access public
+ * @param Core\Registry $registry Registry instance
+ * @param string $controller Controller name
+ * @param string $action Action name
+ */
public function __construct(Registry $registry, $controller = '', $action = '')
{
$this->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
index 0c3ec2d9..0c3ec2d9 100644
--- a/core/session.php
+++ b/app/Core/Session.php
diff --git a/app/Core/Template.php b/app/Core/Template.php
new file mode 100644
index 00000000..8740a685
--- /dev/null
+++ b/app/Core/Template.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace Core;
+
+/**
+ * Template class
+ *
+ * @package core
+ * @author Frederic Guillot
+ */
+class Template
+{
+ /**
+ * Template path
+ *
+ * @var string
+ */
+ const PATH = 'app/Templates/';
+
+ /**
+ * Load a template
+ *
+ * Example:
+ *
+ * $template->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 00000000..be0be66a
--- /dev/null
+++ b/app/Core/Translator.php
@@ -0,0 +1,155 @@
+<?php
+
+namespace Core;
+
+/**
+ * Translator class
+ *
+ * @package core
+ * @author Frederic Guillot
+ */
+class Translator
+{
+ /**
+ * Locales path
+ *
+ * @var string
+ */
+ const PATH = 'app/Locales/';
+
+ /**
+ * Locales
+ *
+ * @static
+ * @access private
+ * @var array
+ */
+ private static $locales = array();
+
+ /**
+ * Get a translation
+ *
+ * $translator->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
index 97ee73fd..b1d412c7 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
index ac97d46c..ce797972 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
index 46faf502..c93a83ae 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
index 94726c20..81ecaf01 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
index fc91b0b2..7c9a6c17 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
index 0d1cd06e..ad2118f4 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
index c8cbf3b1..d1b97ebc 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
index f2a3194e..fef2ddbb 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
index 3229c44e..59a98923 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
index 2a1891a5..9be37f9d 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
index 453c2afc..b5102070 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
index d18b8ec5..994f0bc8 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
index 4f83a41e..f5beb8f8 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';
-
-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;
+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;
/**
* Google model
diff --git a/models/last_login.php b/app/Model/LastLogin.php
index a991ee30..56739b48 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
index 69fe9bec..3359318c 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
index cbbbfda2..85294830 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
index be6b4e53..1494b14a 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
index 0c62a9f4..bd67d272 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
index bb54fc2e..bce717a7 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
index eb869465..6764ad5d 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
index b444faa5..0bb4de8d 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
index b515ccaa..b515ccaa 100644
--- a/templates/action_index.php
+++ b/app/Templates/action_index.php
diff --git a/templates/action_params.php b/app/Templates/action_params.php
index 15a1d420..15a1d420 100644
--- a/templates/action_params.php
+++ b/app/Templates/action_params.php
diff --git a/templates/action_remove.php b/app/Templates/action_remove.php
index b90136e8..b90136e8 100644
--- a/templates/action_remove.php
+++ b/app/Templates/action_remove.php
diff --git a/templates/app_notfound.php b/app/Templates/app_notfound.php
index 734d16a4..734d16a4 100644
--- a/templates/app_notfound.php
+++ b/app/Templates/app_notfound.php
diff --git a/templates/board_assign.php b/app/Templates/board_assign.php
index 74448a5c..74448a5c 100644
--- a/templates/board_assign.php
+++ b/app/Templates/board_assign.php
diff --git a/templates/board_edit.php b/app/Templates/board_edit.php
index 575536a8..575536a8 100644
--- a/templates/board_edit.php
+++ b/app/Templates/board_edit.php
diff --git a/templates/board_index.php b/app/Templates/board_index.php
index 989c2e06..989c2e06 100644
--- a/templates/board_index.php
+++ b/app/Templates/board_index.php
diff --git a/templates/board_public.php b/app/Templates/board_public.php
index 0808079e..0808079e 100644
--- a/templates/board_public.php
+++ b/app/Templates/board_public.php
diff --git a/templates/board_remove.php b/app/Templates/board_remove.php
index b406eb38..b406eb38 100644
--- a/templates/board_remove.php
+++ b/app/Templates/board_remove.php
diff --git a/templates/board_show.php b/app/Templates/board_show.php
index 719e3bdd..719e3bdd 100644
--- a/templates/board_show.php
+++ b/app/Templates/board_show.php
diff --git a/templates/category_edit.php b/app/Templates/category_edit.php
index 99ba0c7c..99ba0c7c 100644
--- a/templates/category_edit.php
+++ b/app/Templates/category_edit.php
diff --git a/templates/category_index.php b/app/Templates/category_index.php
index db986143..db986143 100644
--- a/templates/category_index.php
+++ b/app/Templates/category_index.php
diff --git a/templates/category_remove.php b/app/Templates/category_remove.php
index cc2eb678..cc2eb678 100644
--- a/templates/category_remove.php
+++ b/app/Templates/category_remove.php
diff --git a/templates/comment_forbidden.php b/app/Templates/comment_forbidden.php
index eeea8404..eeea8404 100644
--- a/templates/comment_forbidden.php
+++ b/app/Templates/comment_forbidden.php
diff --git a/templates/comment_remove.php b/app/Templates/comment_remove.php
index ad1b8e4a..ad1b8e4a 100644
--- a/templates/comment_remove.php
+++ b/app/Templates/comment_remove.php
diff --git a/templates/comment_show.php b/app/Templates/comment_show.php
index 24bf9070..24bf9070 100644
--- a/templates/comment_show.php
+++ b/app/Templates/comment_show.php
diff --git a/templates/config_index.php b/app/Templates/config_index.php
index 6c610d2b..6c610d2b 100644
--- a/templates/config_index.php
+++ b/app/Templates/config_index.php
diff --git a/templates/layout.php b/app/Templates/layout.php
index 0bb8446d..0bb8446d 100644
--- a/templates/layout.php
+++ b/app/Templates/layout.php
diff --git a/templates/project_edit.php b/app/Templates/project_edit.php
index 557986bf..557986bf 100644
--- a/templates/project_edit.php
+++ b/app/Templates/project_edit.php
diff --git a/templates/project_forbidden.php b/app/Templates/project_forbidden.php
index 1cba7b58..1cba7b58 100644
--- a/templates/project_forbidden.php
+++ b/app/Templates/project_forbidden.php
diff --git a/templates/project_index.php b/app/Templates/project_index.php
index df153fe7..df153fe7 100644
--- a/templates/project_index.php
+++ b/app/Templates/project_index.php
diff --git a/templates/project_new.php b/app/Templates/project_new.php
index 2026d461..2026d461 100644
--- a/templates/project_new.php
+++ b/app/Templates/project_new.php
diff --git a/templates/project_remove.php b/app/Templates/project_remove.php
index e9f213b5..e9f213b5 100644
--- a/templates/project_remove.php
+++ b/app/Templates/project_remove.php
diff --git a/templates/project_search.php b/app/Templates/project_search.php
index 3594fd09..3594fd09 100644
--- a/templates/project_search.php
+++ b/app/Templates/project_search.php
diff --git a/templates/project_tasks.php b/app/Templates/project_tasks.php
index 9f4263b8..9f4263b8 100644
--- a/templates/project_tasks.php
+++ b/app/Templates/project_tasks.php
diff --git a/templates/project_users.php b/app/Templates/project_users.php
index 0448004f..0448004f 100644
--- a/templates/project_users.php
+++ b/app/Templates/project_users.php
diff --git a/templates/task_close.php b/app/Templates/task_close.php
index 3531b37d..3531b37d 100644
--- a/templates/task_close.php
+++ b/app/Templates/task_close.php
diff --git a/templates/task_edit.php b/app/Templates/task_edit.php
index 8c8bc107..8c8bc107 100644
--- a/templates/task_edit.php
+++ b/app/Templates/task_edit.php
diff --git a/templates/task_layout.php b/app/Templates/task_layout.php
index 9a6bbd00..9a6bbd00 100644
--- a/templates/task_layout.php
+++ b/app/Templates/task_layout.php
diff --git a/templates/task_new.php b/app/Templates/task_new.php
index d233efd2..d233efd2 100644
--- a/templates/task_new.php
+++ b/app/Templates/task_new.php
diff --git a/templates/task_open.php b/app/Templates/task_open.php
index 54cc11f0..54cc11f0 100644
--- a/templates/task_open.php
+++ b/app/Templates/task_open.php
diff --git a/templates/task_remove.php b/app/Templates/task_remove.php
index 1aa9503b..1aa9503b 100644
--- a/templates/task_remove.php
+++ b/app/Templates/task_remove.php
diff --git a/templates/task_show.php b/app/Templates/task_show.php
index a5b79359..a5b79359 100644
--- a/templates/task_show.php
+++ b/app/Templates/task_show.php
diff --git a/templates/task_sidebar.php b/app/Templates/task_sidebar.php
index 314d5214..314d5214 100644
--- a/templates/task_sidebar.php
+++ b/app/Templates/task_sidebar.php
diff --git a/templates/user_edit.php b/app/Templates/user_edit.php
index c857fe1c..c857fe1c 100644
--- a/templates/user_edit.php
+++ b/app/Templates/user_edit.php
diff --git a/templates/user_forbidden.php b/app/Templates/user_forbidden.php
index 853159ba..853159ba 100644
--- a/templates/user_forbidden.php
+++ b/app/Templates/user_forbidden.php
diff --git a/templates/user_index.php b/app/Templates/user_index.php
index f6302a6b..f6302a6b 100644
--- a/templates/user_index.php
+++ b/app/Templates/user_index.php
diff --git a/templates/user_login.php b/app/Templates/user_login.php
index 878170e3..878170e3 100644
--- a/templates/user_login.php
+++ b/app/Templates/user_login.php
diff --git a/templates/user_new.php b/app/Templates/user_new.php
index 6ad976f2..6ad976f2 100644
--- a/templates/user_new.php
+++ b/app/Templates/user_new.php
diff --git a/templates/user_remove.php b/app/Templates/user_remove.php
index a4db2e4a..a4db2e4a 100644
--- a/templates/user_remove.php
+++ b/app/Templates/user_remove.php
diff --git a/check_setup.php b/app/check_setup.php
index 1484d459..9ed16967 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 00000000..5a26860f
--- /dev/null
+++ b/app/common.php
@@ -0,0 +1,98 @@
+<?php
+
+require __DIR__.'/Core/Loader.php';
+require __DIR__.'/helpers.php';
+require __DIR__.'/translator.php';
+
+use Core\Event;
+use Core\Loader;
+use Core\Registry;
+
+// Include custom config file
+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', '');
+
+$loader = new Loader;
+$loader->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
index 8351328a..8351328a 100644
--- a/core/helper.php
+++ b/app/helpers.php
diff --git a/app/translator.php b/app/translator.php
new file mode 100644
index 00000000..338821d3
--- /dev/null
+++ b/app/translator.php
@@ -0,0 +1,36 @@
+<?php
+
+use Core\Translator;
+
+// Get a translation
+function t()
+{
+ $t = new Translator;
+ return call_user_func_array(array($t, 'translate'), func_get_args());
+}
+
+// Get a locale currency
+function c($value)
+{
+ $t = new Translator;
+ return $t->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 af54d0c8..357849e6 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 70b18a51..00000000
--- a/common.php
+++ /dev/null
@@ -1,156 +0,0 @@
-<?php
-
-require __DIR__.'/core/registry.php';
-require __DIR__.'/core/helper.php';
-require __DIR__.'/core/translator.php';
-
-$registry = new Core\Registry;
-
-$registry->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 99acb883..6810ce9d 100644
--- a/config.default.php
+++ b/config.default.php
@@ -1,7 +1,10 @@
<?php
// Auto-refresh frequency in seconds for the public board view (60 seconds by default)
-define('AUTO_REFRESH_DURATION', 60);
+define('BOARD_PUBLIC_CHECK_INTERVAL', 60);
+
+// Board refresh frequency in seconds (the value 0 disable this feature, 10 seconds by default)
+define('BOARD_CHECK_INTERVAL', 10);
// Database driver: sqlite or mysql (sqlite by default)
define('DB_DRIVER', 'sqlite');
diff --git a/core/template.php b/core/template.php
deleted file mode 100644
index ad31ffb7..00000000
--- a/core/template.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-namespace Core;
-
-class Template
-{
- const PATH = 'templates/';
-
- // Template\load('template_name', ['bla' => '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 8adb1bfd..00000000
--- a/core/translator.php
+++ /dev/null
@@ -1,130 +0,0 @@
-<?php
-
-namespace Translator {
-
- const PATH = 'locales/';
-
- function translate($identifier)
- {
- $args = \func_get_args();
-
- \array_shift($args);
- \array_unshift($args, get($identifier, $identifier));
-
- foreach ($args as &$arg) {
- $arg = htmlspecialchars($arg, ENT_QUOTES, 'UTF-8', false);
- }
-
- return \call_user_func_array(
- 'sprintf',
- $args
- );
- }
-
- function number($number)
- {
- return number_format(
- $number,
- get('number.decimals', 2),
- get('number.decimals_separator', '.'),
- get('number.thousands_separator', ',')
- );
- }
-
- function currency($amount)
- {
- $position = get('currency.position', 'before');
- $symbol = get('currency.symbol', '$');
- $str = '';
-
- if ($position === 'before') {
- $str .= $symbol;
- }
-
- $str .= number($amount);
-
- if ($position === 'after') {
- $str .= ' '.$symbol;
- }
-
- return $str;
- }
-
- function datetime($format, $timestamp)
- {
- if (! $timestamp) {
- return '';
- }
-
- return strftime(get($format, $format), (int) $timestamp);
- }
-
- function get($identifier, $default = '')
- {
- $locales = container();
-
- if (isset($locales[$identifier])) {
- return $locales[$identifier];
- }
- else {
- return $default;
- }
- }
-
- function load($language)
- {
- setlocale(LC_TIME, $language.'.UTF-8', $language);
-
- $path = PATH.$language;
- $locales = array();
-
- if (is_dir($path)) {
-
- $dir = new \DirectoryIterator($path);
-
- foreach ($dir as $fileinfo) {
-
- if (strpos($fileinfo->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
index 14249c50..14249c50 100644
--- a/controllers/.htaccess
+++ b/docs/.htaccess
diff --git a/index.php b/index.php
index bd691c10..cee8017d 100644
--- a/index.php
+++ b/index.php
@@ -1,8 +1,9 @@
<?php
-require __DIR__.'/check_setup.php';
-require __DIR__.'/common.php';
-require __DIR__.'/core/router.php';
+require __DIR__.'/app/check_setup.php';
+require __DIR__.'/app/common.php';
-$router = new Core\Router($registry);
+use Core\Router;
+
+$router = new Router($registry);
$router->execute();
diff --git a/schemas/.htaccess b/schemas/.htaccess
deleted file mode 100644
index 14249c50..00000000
--- 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
index 14249c50..14249c50 100644
--- a/core/.htaccess
+++ b/scripts/.htaccess
diff --git a/templates/.htaccess b/templates/.htaccess
deleted file mode 100644
index 14249c50..00000000
--- 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
index 14249c50..14249c50 100644
--- a/models/.htaccess
+++ b/tests/.htaccess
diff --git a/tests/Base.php b/tests/Base.php
index 400643ac..9c8cfc4a 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 {