From 8e5673e3d289e4d28b4fc9f20721bda9f1c858c7 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 4 Oct 2014 23:31:03 -0400 Subject: Improve settings page and move some config parameters to the database --- app/Controller/Base.php | 9 +- app/Controller/Board.php | 8 +- app/Controller/Config.php | 124 +++++++++++++++------ app/Controller/User.php | 2 +- app/Controller/Webhook.php | 4 +- app/Locales/de_DE/translations.php | 20 +++- app/Locales/es_ES/translations.php | 20 +++- app/Locales/fi_FI/translations.php | 20 +++- app/Locales/fr_FR/translations.php | 20 +++- app/Locales/it_IT/translations.php | 20 +++- app/Locales/pl_PL/translations.php | 20 +++- app/Locales/pt_BR/translations.php | 20 +++- app/Locales/ru_RU/translations.php | 20 +++- app/Locales/sv_SE/translations.php | 20 +++- app/Locales/zh_CN/translations.php | 20 +++- app/Model/Config.php | 70 +++++++----- app/Model/Notification.php | 2 +- app/Model/Project.php | 2 +- app/Model/Webhook.php | 6 +- app/Schema/Mysql.php | 33 +++++- app/Schema/Postgres.php | 33 +++++- app/Schema/Sqlite.php | 33 +++++- app/Templates/board_index.php | 8 +- app/Templates/board_show.php | 4 +- app/Templates/config_about.php | 41 +++++++ app/Templates/config_api.php | 18 +++ app/Templates/config_application.php | 23 ++++ app/Templates/config_board.php | 29 +++++ app/Templates/config_index.php | 71 ------------ app/Templates/config_layout.php | 13 +++ app/Templates/config_sidebar.php | 22 ++++ app/Templates/config_webhook.php | 38 +++++++ app/Templates/layout.php | 4 +- app/Templates/notification_comment_creation.php | 2 +- app/Templates/notification_comment_update.php | 2 +- app/Templates/notification_file_creation.php | 2 +- app/Templates/notification_footer.php | 4 +- app/Templates/notification_subtask_creation.php | 2 +- app/Templates/notification_subtask_update.php | 2 +- .../notification_task_assignee_change.php | 2 +- app/Templates/notification_task_close.php | 2 +- app/Templates/notification_task_creation.php | 2 +- app/Templates/notification_task_due.php | 2 +- app/Templates/notification_task_move_column.php | 2 +- app/Templates/notification_task_move_position.php | 2 +- app/Templates/notification_task_open.php | 2 +- app/Templates/notification_task_update.php | 2 +- app/Templates/project_share.php | 2 +- app/Templates/project_show.php | 2 +- app/Templates/user_external.php | 4 +- app/Templates/user_show.php | 2 +- app/constants.php | 9 -- app/helpers.php | 29 ++++- 53 files changed, 677 insertions(+), 198 deletions(-) create mode 100644 app/Templates/config_about.php create mode 100644 app/Templates/config_api.php create mode 100644 app/Templates/config_application.php create mode 100644 app/Templates/config_board.php delete mode 100644 app/Templates/config_index.php create mode 100644 app/Templates/config_layout.php create mode 100644 app/Templates/config_sidebar.php create mode 100644 app/Templates/config_webhook.php (limited to 'app') diff --git a/app/Controller/Base.php b/app/Controller/Base.php index e07aabf7..9c1416fc 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -5,7 +5,6 @@ namespace Controller; use Core\Tool; use Core\Registry; use Core\Security; -use Core\Translator; use Model\LastLogin; /** @@ -123,12 +122,8 @@ abstract class Base $this->response->hsts(); } - // Load translations - $language = $this->config->get('language', 'en_US'); - if ($language !== 'en_US') Translator::load($language); - - // Set timezone - date_default_timezone_set($this->config->get('timezone', 'UTC')); + $this->config->setupTranslations(); + $this->config->setupTimezone(); // Authentication if (! $this->authentication->isAuthenticated($controller, $action)) { diff --git a/app/Controller/Board.php b/app/Controller/Board.php index b56adca0..0e1dd3e1 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -177,8 +177,8 @@ class Board extends Base 'categories' => $this->category->getList($project['id'], false), 'title' => $project['name'], 'no_layout' => true, - 'auto_refresh' => true, 'not_editable' => true, + 'board_public_refresh_interval' => $this->config->get('board_public_refresh_interval'), ))); } @@ -238,6 +238,8 @@ class Board extends Base 'menu' => 'boards', 'title' => $projects[$project['id']], 'board_selector' => $board_selector, + 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), + 'board_highlight_period' => $this->config->get('board_highlight_period'), ))); } @@ -407,6 +409,8 @@ class Board extends Base 'current_project_id' => $project_id, 'board' => $this->board->get($project_id), 'categories' => $this->category->getList($project_id, false), + 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), + 'board_highlight_period' => $this->config->get('board_highlight_period'), )), 201 ); @@ -443,6 +447,8 @@ class Board extends Base 'current_project_id' => $project_id, 'board' => $this->board->get($project_id), 'categories' => $this->category->getList($project_id, false), + 'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'), + 'board_highlight_period' => $this->config->get('board_highlight_period'), )) ); } diff --git a/app/Controller/Config.php b/app/Controller/Config.php index 4c3018c1..869d4331 100644 --- a/app/Controller/Config.php +++ b/app/Controller/Config.php @@ -11,58 +11,117 @@ namespace Controller; class Config extends Base { /** - * Display the settings page + * Common layout for config views * - * @access public + * @access private + * @param string $template Template name + * @param array $params Template parameters + * @return string */ - public function index() + private function layout($template, array $params) { - $this->response->html($this->template->layout('config_index', array( - 'db_size' => $this->config->getDatabaseSize(), - 'languages' => $this->config->getLanguages(), - 'values' => $this->config->getAll(), - 'errors' => array(), - 'menu' => 'config', - 'title' => t('Settings'), - 'timezones' => $this->config->getTimezones(), - 'default_columns' => implode(', ', $this->board->getDefaultColumns()), - ))); + $params['values'] = $this->config->getAll(); + $params['errors'] = array(); + $params['menu'] = 'config'; + $params['config_content_for_layout'] = $this->template->load($template, $params); + + return $this->template->layout('config_layout', $params); } /** - * Validate and save settings + * Common method between pages * - * @access public + * @access private + * @param string $redirect Action to redirect after saving the form */ - public function save() + private function common($redirect) { - $values = $this->request->getValues(); - list($valid, $errors) = $this->config->validateModification($values); + if ($this->request->isPost()) { - if ($valid) { + $values = $this->request->getValues(); if ($this->config->save($values)) { $this->config->reload(); $this->session->flash(t('Settings saved successfully.')); - } else { + } + else { $this->session->flashError(t('Unable to save your settings.')); } - $this->response->redirect('?controller=config'); + $this->response->redirect('?controller=config&action='.$redirect); } + } - $this->response->html($this->template->layout('config_index', array( + /** + * Display the about page + * + * @access public + */ + public function index() + { + $this->response->html($this->layout('config_about', array( 'db_size' => $this->config->getDatabaseSize(), + 'title' => t('About'), + ))); + } + + /** + * Display the application settings page + * + * @access public + */ + public function application() + { + $this->common('application'); + + $this->response->html($this->layout('config_application', array( + 'title' => t('Application settings'), 'languages' => $this->config->getLanguages(), - 'values' => $values, - 'errors' => $errors, - 'menu' => 'config', - 'title' => t('Settings'), 'timezones' => $this->config->getTimezones(), + ))); + } + + /** + * Display the board settings page + * + * @access public + */ + public function board() + { + $this->common('board'); + + $this->response->html($this->layout('config_board', array( + 'title' => t('Board settings'), 'default_columns' => implode(', ', $this->board->getDefaultColumns()), ))); } + /** + * Display the webhook settings page + * + * @access public + */ + public function webhook() + { + $this->common('webhook'); + + $this->response->html($this->layout('config_webhook', array( + 'title' => t('Webhook settings'), + ))); + } + + /** + * Display the api settings page + * + * @access public + */ + public function api() + { + $this->response->html($this->layout('config_api', array( + 'title' => t('API'), + ))); + } + /** * Download the Sqlite database * @@ -89,15 +148,18 @@ class Config extends Base } /** - * Regenerate all application tokens + * Regenerate webhook token * * @access public */ - public function tokens() + public function token() { + $type = $this->request->getStringParam('type'); + $this->checkCSRFParam(); - $this->config->regenerateTokens(); - $this->session->flash(t('All tokens have been regenerated.')); - $this->response->redirect('?controller=config'); + $this->config->regenerateToken($type.'_token'); + + $this->session->flash(t('Token regenerated.')); + $this->response->redirect('?controller=config&action='.$type); } } diff --git a/app/Controller/User.php b/app/Controller/User.php index cc7464e6..bbed9f6f 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -73,7 +73,7 @@ class User extends Base } /** - * Common layout for project views + * Common layout for user views * * @access private * @param string $template Template name diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php index c72dc983..71acab08 100644 --- a/app/Controller/Webhook.php +++ b/app/Controller/Webhook.php @@ -17,7 +17,7 @@ class Webhook extends Base */ public function task() { - if ($this->config->get('webhooks_token') !== $this->request->getStringParam('token')) { + if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { $this->response->text('Not Authorized', 401); } @@ -49,7 +49,7 @@ class Webhook extends Base */ public function github() { - if ($this->config->get('webhooks_token') !== $this->request->getStringParam('token')) { + if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { $this->response->text('Not Authorized', 401); } diff --git a/app/Locales/de_DE/translations.php b/app/Locales/de_DE/translations.php index ec570691..93721f65 100644 --- a/app/Locales/de_DE/translations.php +++ b/app/Locales/de_DE/translations.php @@ -83,7 +83,7 @@ return array( 'Settings' => 'Einstellungen', 'Application settings' => 'Anwendungskonfiguration', 'Language' => 'Sprache', - 'Webhooks token:' => 'Webhooks Token:', + // 'Webhook token:' => '', 'API token:' => 'API Token:', 'More information' => 'Mehr Informationen', 'Database size:' => 'Datenbankgröße:', @@ -516,4 +516,22 @@ return array( // 'Reference' => '', // 'Reference: %s' => '', // 'Label' => '', + // 'Database' => '', + // 'About' => '', + // 'Database driver:' => '', + // 'Board settings' => '', + // 'URL and token' => '', + // 'Webhook settings' => '', + // 'URL for task creation:' => '', + // 'Reset token' => '', + // 'API endpoint:' => '', + // 'Refresh interval for private board' => '', + // 'Refresh interval for public board' => '', + // 'Task highlight period' => '', + // 'Period (in second) to consider a task was modified recently (0 to disable, 2 days by default)' => '', + // 'Frequency in second (60 seconds by default)' => '', + // 'Frequency in second (0 to disable this feature, 10 seconds by default)' => '', + // 'Application URL' => '', + // 'Example: http://example.kanboard.net/ (used by email notifications)' => '', + // 'Token regenerated.' => '', ); diff --git a/app/Locales/es_ES/translations.php b/app/Locales/es_ES/translations.php index 05646a74..8b92b9a5 100644 --- a/app/Locales/es_ES/translations.php +++ b/app/Locales/es_ES/translations.php @@ -83,7 +83,7 @@ return array( 'Settings' => 'Preferencias', 'Application settings' => 'Parámetros de la aplicación', 'Language' => 'Idioma', - 'Webhooks token:' => 'Ficha de seguridad (token) para los webhooks :', + 'Webhook token:' => 'Ficha de seguridad (token) para los webhooks :', 'API token:' => 'Ficha de seguridad (token) para API:', 'More information' => 'Más informaciones', 'Database size:' => 'Tamaño de la base de datos:', @@ -516,4 +516,22 @@ return array( // 'Reference' => '', // 'Reference: %s' => '', // 'Label' => '', + // 'Database' => '', + // 'About' => '', + // 'Database driver:' => '', + // 'Board settings' => '', + // 'URL and token' => '', + // 'Webhook settings' => '', + // 'URL for task creation:' => '', + // 'Reset token' => '', + // 'API endpoint:' => '', + // 'Refresh interval for private board' => '', + // 'Refresh interval for public board' => '', + // 'Task highlight period' => '', + // 'Period (in second) to consider a task was modified recently (0 to disable, 2 days by default)' => '', + // 'Frequency in second (60 seconds by default)' => '', + // 'Frequency in second (0 to disable this feature, 10 seconds by default)' => '', + // 'Application URL' => '', + // 'Example: http://example.kanboard.net/ (used by email notifications)' => '', + // 'Token regenerated.' => '', ); diff --git a/app/Locales/fi_FI/translations.php b/app/Locales/fi_FI/translations.php index 3bb2185e..923ba970 100644 --- a/app/Locales/fi_FI/translations.php +++ b/app/Locales/fi_FI/translations.php @@ -83,7 +83,7 @@ return array( 'Settings' => 'Asetukset', 'Application settings' => 'Ohjelman asetukset', 'Language' => 'Kieli', - 'Webhooks token:' => 'Webhooks avain:', + 'Webhook token:' => 'Webhooks avain:', // 'API token:' => '', 'More information' => 'Lisätietoja', 'Database size:' => 'Tietokannan koko:', @@ -516,4 +516,22 @@ return array( // 'Reference' => '', // 'Reference: %s' => '', // 'Label' => '', + // 'Database' => '', + // 'About' => '', + // 'Database driver:' => '', + // 'Board settings' => '', + // 'URL and token' => '', + // 'Webhook settings' => '', + // 'URL for task creation:' => '', + // 'Reset token' => '', + // 'API endpoint:' => '', + // 'Refresh interval for private board' => '', + // 'Refresh interval for public board' => '', + // 'Task highlight period' => '', + // 'Period (in second) to consider a task was modified recently (0 to disable, 2 days by default)' => '', + // 'Frequency in second (60 seconds by default)' => '', + // 'Frequency in second (0 to disable this feature, 10 seconds by default)' => '', + // 'Application URL' => '', + // 'Example: http://example.kanboard.net/ (used by email notifications)' => '', + // 'Token regenerated.' => '', ); diff --git a/app/Locales/fr_FR/translations.php b/app/Locales/fr_FR/translations.php index c1723875..19c15f86 100644 --- a/app/Locales/fr_FR/translations.php +++ b/app/Locales/fr_FR/translations.php @@ -83,7 +83,7 @@ return array( 'Settings' => 'Préférences', 'Application settings' => 'Paramètres de l\'application', 'Language' => 'Langue', - 'Webhooks token:' => 'Jeton de securité pour les webhooks :', + 'Webhook token:' => 'Jeton de securité pour les webhooks :', 'API token:' => 'Jeton de securité pour l\'API :', 'More information' => 'Plus d\'informations', 'Database size:' => 'Taille de la base de données :', @@ -516,4 +516,22 @@ return array( 'Reference' => 'Référence', 'Reference: %s' => 'Référence : %s', 'Label' => 'Libellé', + 'Database' => 'Base de données', + 'About' => 'A propos', + 'Database driver:' => 'Type de base de données :', + 'Board settings' => 'Paramètres du tableau', + 'URL and token' => 'URL et jeton de sécurité', + 'Webhook settings' => 'Paramètres pour les webhooks', + 'URL for task creation:' => 'URL pour la création de tâche :', + 'Reset token' => 'Regénérer le jeton de sécurité', + 'API endpoint:' => 'URL de l\'API :', + 'Refresh interval for private board' => 'Intervalle pour rafraîchir un tableau privé', + 'Refresh interval for public board' => 'Intervalle pour rafraîchir un tableau public', + 'Task highlight period' => 'Durée pour mettre une tâche en évidence', + 'Period (in second) to consider a task was modified recently (0 to disable, 2 days by default)' => 'Durée en seconde pour considérer une tâche comme récemment modifiée (0 pour désactiver, 2 jours par défaut)', + 'Frequency in second (60 seconds by default)' => 'Fréquence en seconde (60 secondes par défaut)', + 'Frequency in second (0 to disable this feature, 10 seconds by default)' => 'Fréquence en seconde (0 pour désactiver, 10 secondes par défaut)', + 'Application URL' => 'URL de l\'application', + 'Example: http://example.kanboard.net/ (used by email notifications)' => 'Exemple : http://exemple.kanboard.net/ (utilisé pour les notifications)', + 'Token regenerated.' => 'Jeton de sécurité regénéré.', ); diff --git a/app/Locales/it_IT/translations.php b/app/Locales/it_IT/translations.php index 6acac109..e5b5eb57 100644 --- a/app/Locales/it_IT/translations.php +++ b/app/Locales/it_IT/translations.php @@ -83,7 +83,7 @@ return array( 'Settings' => 'Impostazioni', 'Application settings' => 'Impostazioni dell\'applicazione', 'Language' => 'Lingua', - 'Webhooks token:' => 'Identificatore (token) per i webhooks :', + 'Webhook token:' => 'Identificatore (token) per i webhooks :', // 'API token:' => '', 'More information' => 'Più informazioni', 'Database size:' => 'Dimensioni della base dati:', @@ -516,4 +516,22 @@ return array( // 'Reference' => '', // 'Reference: %s' => '', // 'Label' => '', + // 'Database' => '', + // 'About' => '', + // 'Database driver:' => '', + // 'Board settings' => '', + // 'URL and token' => '', + // 'Webhook settings' => '', + // 'URL for task creation:' => '', + // 'Reset token' => '', + // 'API endpoint:' => '', + // 'Refresh interval for private board' => '', + // 'Refresh interval for public board' => '', + // 'Task highlight period' => '', + // 'Period (in second) to consider a task was modified recently (0 to disable, 2 days by default)' => '', + // 'Frequency in second (60 seconds by default)' => '', + // 'Frequency in second (0 to disable this feature, 10 seconds by default)' => '', + // 'Application URL' => '', + // 'Example: http://example.kanboard.net/ (used by email notifications)' => '', + // 'Token regenerated.' => '', ); diff --git a/app/Locales/pl_PL/translations.php b/app/Locales/pl_PL/translations.php index 3e33ce8b..cdf200b9 100644 --- a/app/Locales/pl_PL/translations.php +++ b/app/Locales/pl_PL/translations.php @@ -83,7 +83,7 @@ return array( 'Settings' => 'Ustawienia', 'Application settings' => 'Ustawienia aplikacji', 'Language' => 'Język', - 'Webhooks token:' => 'Token :', + 'Webhook token:' => 'Token :', // 'API token:' => '', 'More information' => 'Więcej informacji', 'Database size:' => 'Rozmiar bazy danych :', @@ -516,4 +516,22 @@ return array( // 'Reference' => '', // 'Reference: %s' => '', // 'Label' => '', + // 'Database' => '', + // 'About' => '', + // 'Database driver:' => '', + // 'Board settings' => '', + // 'URL and token' => '', + // 'Webhook settings' => '', + // 'URL for task creation:' => '', + // 'Reset token' => '', + // 'API endpoint:' => '', + // 'Refresh interval for private board' => '', + // 'Refresh interval for public board' => '', + // 'Task highlight period' => '', + // 'Period (in second) to consider a task was modified recently (0 to disable, 2 days by default)' => '', + // 'Frequency in second (60 seconds by default)' => '', + // 'Frequency in second (0 to disable this feature, 10 seconds by default)' => '', + // 'Application URL' => '', + // 'Example: http://example.kanboard.net/ (used by email notifications)' => '', + // 'Token regenerated.' => '', ); diff --git a/app/Locales/pt_BR/translations.php b/app/Locales/pt_BR/translations.php index 68946936..1524355d 100644 --- a/app/Locales/pt_BR/translations.php +++ b/app/Locales/pt_BR/translations.php @@ -83,7 +83,7 @@ return array( 'Settings' => 'Preferências', 'Application settings' => 'Preferências da aplicação', 'Language' => 'Idioma', - 'Webhooks token:' => 'Token de webhooks:', + 'Webhook token:' => 'Token de webhooks:', 'API token:' => 'API Token:', 'More information' => 'Mais informação', 'Database size:' => 'Tamanho do banco de dados:', @@ -516,4 +516,22 @@ return array( // 'Reference' => '', // 'Reference: %s' => '', // 'Label' => '', + // 'Database' => '', + // 'About' => '', + // 'Database driver:' => '', + // 'Board settings' => '', + // 'URL and token' => '', + // 'Webhook settings' => '', + // 'URL for task creation:' => '', + // 'Reset token' => '', + // 'API endpoint:' => '', + // 'Refresh interval for private board' => '', + // 'Refresh interval for public board' => '', + // 'Task highlight period' => '', + // 'Period (in second) to consider a task was modified recently (0 to disable, 2 days by default)' => '', + // 'Frequency in second (60 seconds by default)' => '', + // 'Frequency in second (0 to disable this feature, 10 seconds by default)' => '', + // 'Application URL' => '', + // 'Example: http://example.kanboard.net/ (used by email notifications)' => '', + // 'Token regenerated.' => '', ); diff --git a/app/Locales/ru_RU/translations.php b/app/Locales/ru_RU/translations.php index a949dbd0..e5e3e8bc 100644 --- a/app/Locales/ru_RU/translations.php +++ b/app/Locales/ru_RU/translations.php @@ -83,7 +83,7 @@ return array( 'Settings' => 'Настройки', 'Application settings' => 'Настройки приложения', 'Language' => 'Язык', - 'Webhooks token:' => 'Webhooks токен :', + 'Webhook token:' => 'Webhooks токен :', 'API token:' => 'API токен :', 'More information' => 'Подробнее', 'Database size:' => 'Размер базы данных :', @@ -516,4 +516,22 @@ return array( // 'Reference' => '', // 'Reference: %s' => '', // 'Label' => '', + // 'Database' => '', + // 'About' => '', + // 'Database driver:' => '', + // 'Board settings' => '', + // 'URL and token' => '', + // 'Webhook settings' => '', + // 'URL for task creation:' => '', + // 'Reset token' => '', + // 'API endpoint:' => '', + // 'Refresh interval for private board' => '', + // 'Refresh interval for public board' => '', + // 'Task highlight period' => '', + // 'Period (in second) to consider a task was modified recently (0 to disable, 2 days by default)' => '', + // 'Frequency in second (60 seconds by default)' => '', + // 'Frequency in second (0 to disable this feature, 10 seconds by default)' => '', + // 'Application URL' => '', + // 'Example: http://example.kanboard.net/ (used by email notifications)' => '', + // 'Token regenerated.' => '', ); diff --git a/app/Locales/sv_SE/translations.php b/app/Locales/sv_SE/translations.php index 68c0597f..4c8aef81 100644 --- a/app/Locales/sv_SE/translations.php +++ b/app/Locales/sv_SE/translations.php @@ -83,7 +83,7 @@ return array( 'Settings' => 'Inställningar', 'Application settings' => 'Applikationsinställningar', 'Language' => 'Språk', - 'Webhooks token:' => 'Token för webhooks:', + 'Webhook token:' => 'Token för webhooks:', 'API token:' => 'API token:', 'More information' => 'Mer information', 'Database size:' => 'Databasstorlek:', @@ -516,4 +516,22 @@ return array( // 'Reference' => '', // 'Reference: %s' => '', // 'Label' => '', + // 'Database' => '', + // 'About' => '', + // 'Database driver:' => '', + // 'Board settings' => '', + // 'URL and token' => '', + // 'Webhook settings' => '', + // 'URL for task creation:' => '', + // 'Reset token' => '', + // 'API endpoint:' => '', + // 'Refresh interval for private board' => '', + // 'Refresh interval for public board' => '', + // 'Task highlight period' => '', + // 'Period (in second) to consider a task was modified recently (0 to disable, 2 days by default)' => '', + // 'Frequency in second (60 seconds by default)' => '', + // 'Frequency in second (0 to disable this feature, 10 seconds by default)' => '', + // 'Application URL' => '', + // 'Example: http://example.kanboard.net/ (used by email notifications)' => '', + // 'Token regenerated.' => '', ); diff --git a/app/Locales/zh_CN/translations.php b/app/Locales/zh_CN/translations.php index ef33881e..3285e9a6 100644 --- a/app/Locales/zh_CN/translations.php +++ b/app/Locales/zh_CN/translations.php @@ -83,7 +83,7 @@ return array( 'Settings' => '设置', 'Application settings' => '应用设置', 'Language' => '语言', - 'Webhooks token:' => '页面钩子令牌:', + 'Webhook token:' => '页面钩子令牌:', // 'API token:' => '', 'More information' => '更多信息', 'Database size:' => '数据库大小:', @@ -516,4 +516,22 @@ return array( // 'Reference' => '', // 'Reference: %s' => '', // 'Label' => '', + // 'Database' => '', + // 'About' => '', + // 'Database driver:' => '', + // 'Board settings' => '', + // 'URL and token' => '', + // 'Webhook settings' => '', + // 'URL for task creation:' => '', + // 'Reset token' => '', + // 'API endpoint:' => '', + // 'Refresh interval for private board' => '', + // 'Refresh interval for public board' => '', + // 'Task highlight period' => '', + // 'Period (in second) to consider a task was modified recently (0 to disable, 2 days by default)' => '', + // 'Frequency in second (60 seconds by default)' => '', + // 'Frequency in second (0 to disable this feature, 10 seconds by default)' => '', + // 'Application URL' => '', + // 'Example: http://example.kanboard.net/ (used by email notifications)' => '', + // 'Token regenerated.' => '', ); diff --git a/app/Model/Config.php b/app/Model/Config.php index f411e3e2..da261de6 100644 --- a/app/Model/Config.php +++ b/app/Model/Config.php @@ -6,6 +6,7 @@ use SimpleValidator\Validator; use SimpleValidator\Validators; use Core\Translator; use Core\Security; +use Core\Session; /** * Config model @@ -20,7 +21,7 @@ class Config extends Base * * @var string */ - const TABLE = 'config'; + const TABLE = 'settings'; /** * Get available timezones @@ -68,6 +69,11 @@ class Config extends Base */ public function get($name, $default_value = '') { + if (! Session::isOpen()) { + $value = $this->db->table(self::TABLE)->eq('option', $name)->findOneColumn('value'); + return $value ?: $default_value; + } + if (! isset($_SESSION['config'][$name])) { $_SESSION['config'] = $this->getAll(); } @@ -87,7 +93,7 @@ class Config extends Base */ public function getAll() { - return $this->db->table(self::TABLE)->findOne(); + return $this->db->table(self::TABLE)->listing('option', 'value'); } /** @@ -99,8 +105,16 @@ class Config extends Base */ public function save(array $values) { - $_SESSION['config'] = $values; - return $this->db->table(self::TABLE)->update($values); + foreach ($values as $option => $value) { + + $result = $this->db->table(self::TABLE)->eq('option', $option)->update(array('value' => $value)); + + if (! $result) { + return false; + } + } + + return true; } /** @@ -111,27 +125,31 @@ class Config extends Base public function reload() { $_SESSION['config'] = $this->getAll(); - Translator::load($this->get('language', 'en_US')); + $this->setupTranslations(); } /** - * Validate settings modification + * Load translations * * @access public - * @param array $values Form values - * @return array $valid, $errors [0] = Success or not, [1] = List of errors */ - public function validateModification(array $values) + public function setupTranslations() { - $v = new Validator($values, array( - new Validators\Required('language', t('The language is required')), - new Validators\Required('timezone', t('The timezone is required')), - )); + $language = $this->get('application_language', 'en_US'); - return array( - $v->execute(), - $v->getErrors() - ); + if ($language !== 'en_US') { + Translator::load($language); + } + } + + /** + * Set timezone + * + * @access public + */ + public function setupTimezone() + { + date_default_timezone_set($this->get('application_timezone', 'UTC')); } /** @@ -168,21 +186,15 @@ class Config extends Base } /** - * Regenerate all tokens (projects and webhooks) + * Regenerate a token * * @access public + * @param string $option Parameter name */ - public function regenerateTokens() + public function regenerateToken($option) { - $this->db->table(self::TABLE)->update(array( - 'webhooks_token' => Security::generateToken(), - 'api_token' => Security::generateToken(), - )); - - $projects = $this->db->table(Project::TABLE)->findAllByColumn('id'); - - foreach ($projects as $project_id) { - $this->db->table(Project::TABLE)->eq('id', $project_id)->update(array('token' => Security::generateToken())); - } + return $this->db->table(self::TABLE) + ->eq('option', $option) + ->update(array('value' => Security::generateToken())); } } diff --git a/app/Model/Notification.php b/app/Model/Notification.php index a7dd7fc0..3c14caf0 100644 --- a/app/Model/Notification.php +++ b/app/Model/Notification.php @@ -182,7 +182,7 @@ class Notification extends Base public function getMailContent($template, array $data) { $tpl = new Template; - return $tpl->load($template, $data); + return $tpl->load($template, $data + array('application_url' => $this->config->get('application_url'))); } /** diff --git a/app/Model/Project.php b/app/Model/Project.php index c3e8cc55..d2b769ed 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -287,7 +287,7 @@ class Project extends Base } $project_id = $this->db->getConnection()->getLastId(); - $column_names = explode(',', $this->config->get('default_columns', implode(',', $this->board->getDefaultColumns()))); + $column_names = explode(',', $this->config->get('board_columns', implode(',', $this->board->getDefaultColumns()))); $columns = array(); foreach ($column_names as $column_name) { diff --git a/app/Model/Webhook.php b/app/Model/Webhook.php index e03bdcb4..241806ba 100644 --- a/app/Model/Webhook.php +++ b/app/Model/Webhook.php @@ -64,9 +64,9 @@ class Webhook extends Base */ public function attachEvents() { - $this->url_task_creation = $this->config->get('webhooks_url_task_creation'); - $this->url_task_modification = $this->config->get('webhooks_url_task_modification'); - $this->token = $this->config->get('webhooks_token'); + $this->url_task_creation = $this->config->get('webhook_url_task_creation'); + $this->url_task_modification = $this->config->get('webhook_url_task_modification'); + $this->token = $this->config->get('webhook_token'); if ($this->url_task_creation) { $this->attachCreateEvents(); diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index 577fac80..e6a33ee5 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -2,9 +2,40 @@ namespace Schema; +use PDO; use Core\Security; -const VERSION = 28; +const VERSION = 29; + +function version_29($pdo) +{ + $pdo->exec(" + CREATE TABLE settings ( + option VARCHAR(100) PRIMARY KEY, + value VARCHAR(255) DEFAULT '' + ) + "); + + // Migrate old config parameters + $rq = $pdo->prepare('SELECT * FROM config'); + $rq->execute(); + $parameters = $rq->fetch(PDO::FETCH_ASSOC); + + $rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)'); + $rq->execute(array('board_highlight_period', defined('RECENT_TASK_PERIOD') ? RECENT_TASK_PERIOD : 48*60*60)); + $rq->execute(array('board_public_refresh_interval', defined('BOARD_PUBLIC_CHECK_INTERVAL') ? BOARD_PUBLIC_CHECK_INTERVAL : 60)); + $rq->execute(array('board_private_refresh_interval', defined('BOARD_CHECK_INTERVAL') ? BOARD_CHECK_INTERVAL : 10)); + $rq->execute(array('board_columns', $parameters['default_columns'])); + $rq->execute(array('webhook_url_task_creation', $parameters['webhooks_url_task_creation'])); + $rq->execute(array('webhook_url_task_modification', $parameters['webhooks_url_task_modification'])); + $rq->execute(array('webhook_token', $parameters['webhooks_token'])); + $rq->execute(array('api_token', $parameters['api_token'])); + $rq->execute(array('application_language', $parameters['language'])); + $rq->execute(array('application_timezone', $parameters['timezone'])); + $rq->execute(array('application_url', defined('KANBOARD_URL') ? KANBOARD_URL : '')); + + $pdo->exec('DROP TABLE config'); +} function version_28($pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index 33859513..0eeb2a72 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -2,9 +2,40 @@ namespace Schema; +use PDO; use Core\Security; -const VERSION = 9; +const VERSION = 10; + +function version_10($pdo) +{ + $pdo->exec(" + CREATE TABLE settings ( + option VARCHAR(100) PRIMARY KEY, + value VARCHAR(255) DEFAULT '' + ) + "); + + // Migrate old config parameters + $rq = $pdo->prepare('SELECT * FROM config'); + $rq->execute(); + $parameters = $rq->fetch(PDO::FETCH_ASSOC); + + $rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)'); + $rq->execute(array('board_highlight_period', defined('RECENT_TASK_PERIOD') ? RECENT_TASK_PERIOD : 48*60*60)); + $rq->execute(array('board_public_refresh_interval', defined('BOARD_PUBLIC_CHECK_INTERVAL') ? BOARD_PUBLIC_CHECK_INTERVAL : 60)); + $rq->execute(array('board_private_refresh_interval', defined('BOARD_CHECK_INTERVAL') ? BOARD_CHECK_INTERVAL : 10)); + $rq->execute(array('board_columns', $parameters['default_columns'])); + $rq->execute(array('webhook_url_task_creation', $parameters['webhooks_url_task_creation'])); + $rq->execute(array('webhook_url_task_modification', $parameters['webhooks_url_task_modification'])); + $rq->execute(array('webhook_token', $parameters['webhooks_token'])); + $rq->execute(array('api_token', $parameters['api_token'])); + $rq->execute(array('application_language', $parameters['language'])); + $rq->execute(array('application_timezone', $parameters['timezone'])); + $rq->execute(array('application_url', defined('KANBOARD_URL') ? KANBOARD_URL : '')); + + $pdo->exec('DROP TABLE config'); +} function version_9($pdo) { diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index d9b3787d..5986d327 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -3,8 +3,39 @@ namespace Schema; use Core\Security; +use PDO; -const VERSION = 28; +const VERSION = 29; + +function version_29($pdo) +{ + $pdo->exec(" + CREATE TABLE settings ( + option TEXT PRIMARY KEY, + value TEXT DEFAULT '' + ) + "); + + // Migrate old config parameters + $rq = $pdo->prepare('SELECT * FROM config'); + $rq->execute(); + $parameters = $rq->fetch(PDO::FETCH_ASSOC); + + $rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)'); + $rq->execute(array('board_highlight_period', defined('RECENT_TASK_PERIOD') ? RECENT_TASK_PERIOD : 48*60*60)); + $rq->execute(array('board_public_refresh_interval', defined('BOARD_PUBLIC_CHECK_INTERVAL') ? BOARD_PUBLIC_CHECK_INTERVAL : 60)); + $rq->execute(array('board_private_refresh_interval', defined('BOARD_CHECK_INTERVAL') ? BOARD_CHECK_INTERVAL : 10)); + $rq->execute(array('board_columns', $parameters['default_columns'])); + $rq->execute(array('webhook_url_task_creation', $parameters['webhooks_url_task_creation'])); + $rq->execute(array('webhook_url_task_modification', $parameters['webhooks_url_task_modification'])); + $rq->execute(array('webhook_token', $parameters['webhooks_token'])); + $rq->execute(array('api_token', $parameters['api_token'])); + $rq->execute(array('application_language', $parameters['language'])); + $rq->execute(array('application_timezone', $parameters['timezone'])); + $rq->execute(array('application_url', defined('KANBOARD_URL') ? KANBOARD_URL : '')); + + $pdo->exec('DROP TABLE config'); +} function version_28($pdo) { diff --git a/app/Templates/board_index.php b/app/Templates/board_index.php index da40468d..bff7dcc9 100644 --- a/app/Templates/board_index.php +++ b/app/Templates/board_index.php @@ -26,7 +26,13 @@

- $current_project_id, 'board' => $board, 'categories' => $categories)) ?> + $current_project_id, + 'board' => $board, + 'categories' => $categories, + 'board_private_refresh_interval' => $board_private_refresh_interval, + 'board_highlight_period' => $board_highlight_period, + )) ?> diff --git a/app/Templates/board_show.php b/app/Templates/board_show.php index e91ab4cf..e8c3c1ba 100644 --- a/app/Templates/board_show.php +++ b/app/Templates/board_show.php @@ -1,4 +1,4 @@ -> +
> @@ -32,7 +32,7 @@ data-task-limit="" > -
+

+
+
+ +
+ + +
+ +
\ No newline at end of file diff --git a/app/Templates/config_api.php b/app/Templates/config_api.php new file mode 100644 index 00000000..037ea08d --- /dev/null +++ b/app/Templates/config_api.php @@ -0,0 +1,18 @@ + +
+ +
\ No newline at end of file diff --git a/app/Templates/config_application.php b/app/Templates/config_application.php new file mode 100644 index 00000000..251a45dc --- /dev/null +++ b/app/Templates/config_application.php @@ -0,0 +1,23 @@ + +
+
+ + + + +
+

+ + +
+ + +
+ +
+ +
+ +
\ No newline at end of file diff --git a/app/Templates/config_board.php b/app/Templates/config_board.php new file mode 100644 index 00000000..f260d084 --- /dev/null +++ b/app/Templates/config_board.php @@ -0,0 +1,29 @@ + +
+
+ + + + +
+

+ + +
+

+ + +
+

+ + +
+

+ +
+ +
+ +
\ No newline at end of file diff --git a/app/Templates/config_index.php b/app/Templates/config_index.php deleted file mode 100644 index 2d9ce116..00000000 --- a/app/Templates/config_index.php +++ /dev/null @@ -1,71 +0,0 @@ -
- - -
-
- - - - -
- - -
- - -
- - -
- - -
-

- -
- -
- -
- - -
- -
-
diff --git a/app/Templates/config_layout.php b/app/Templates/config_layout.php new file mode 100644 index 00000000..3aacb9b7 --- /dev/null +++ b/app/Templates/config_layout.php @@ -0,0 +1,13 @@ +
+ +
+ + + +
+ +
+
+
\ No newline at end of file diff --git a/app/Templates/config_sidebar.php b/app/Templates/config_sidebar.php new file mode 100644 index 00000000..d96159b8 --- /dev/null +++ b/app/Templates/config_sidebar.php @@ -0,0 +1,22 @@ +
+

+
+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+
\ No newline at end of file diff --git a/app/Templates/config_webhook.php b/app/Templates/config_webhook.php new file mode 100644 index 00000000..052a2a99 --- /dev/null +++ b/app/Templates/config_webhook.php @@ -0,0 +1,38 @@ + +
+
+ + + + +
+ + +
+ +
+ +
+ +
+ + +
+ +
\ No newline at end of file diff --git a/app/Templates/layout.php b/app/Templates/layout.php index e0158dfb..434c5aca 100644 --- a/app/Templates/layout.php +++ b/app/Templates/layout.php @@ -6,8 +6,8 @@ - - + + diff --git a/app/Templates/notification_comment_creation.php b/app/Templates/notification_comment_creation.php index fac6ea25..5b334d76 100644 --- a/app/Templates/notification_comment_creation.php +++ b/app/Templates/notification_comment_creation.php @@ -4,4 +4,4 @@ - $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_comment_update.php b/app/Templates/notification_comment_update.php index 92c06ffb..04aafb85 100644 --- a/app/Templates/notification_comment_update.php +++ b/app/Templates/notification_comment_update.php @@ -4,4 +4,4 @@ - $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_file_creation.php b/app/Templates/notification_file_creation.php index 50f4a2d5..d8636820 100644 --- a/app/Templates/notification_file_creation.php +++ b/app/Templates/notification_file_creation.php @@ -2,4 +2,4 @@

- $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_footer.php b/app/Templates/notification_footer.php index f0c9c0d4..533621f4 100644 --- a/app/Templates/notification_footer.php +++ b/app/Templates/notification_footer.php @@ -1,6 +1,6 @@
Kanboard - - - . + + - . diff --git a/app/Templates/notification_subtask_creation.php b/app/Templates/notification_subtask_creation.php index c382355c..2ddfc649 100644 --- a/app/Templates/notification_subtask_creation.php +++ b/app/Templates/notification_subtask_creation.php @@ -14,4 +14,4 @@ - $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_subtask_update.php b/app/Templates/notification_subtask_update.php index ad6dfdc9..999edbf9 100644 --- a/app/Templates/notification_subtask_update.php +++ b/app/Templates/notification_subtask_update.php @@ -18,4 +18,4 @@ - $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_task_assignee_change.php b/app/Templates/notification_task_assignee_change.php index 65194f1e..d23f769e 100644 --- a/app/Templates/notification_task_assignee_change.php +++ b/app/Templates/notification_task_assignee_change.php @@ -17,4 +17,4 @@ - $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_task_close.php b/app/Templates/notification_task_close.php index d9b2dce6..d56e71bb 100644 --- a/app/Templates/notification_task_close.php +++ b/app/Templates/notification_task_close.php @@ -2,4 +2,4 @@

- $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_task_creation.php b/app/Templates/notification_task_creation.php index 43b3b291..1b555096 100644 --- a/app/Templates/notification_task_creation.php +++ b/app/Templates/notification_task_creation.php @@ -40,4 +40,4 @@ - $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_task_due.php b/app/Templates/notification_task_due.php index 25ecc9f1..ae02f64e 100644 --- a/app/Templates/notification_task_due.php +++ b/app/Templates/notification_task_due.php @@ -12,4 +12,4 @@ - $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_task_move_column.php b/app/Templates/notification_task_move_column.php index 026db776..c3f94df7 100644 --- a/app/Templates/notification_task_move_column.php +++ b/app/Templates/notification_task_move_column.php @@ -8,4 +8,4 @@
  • - $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_task_move_position.php b/app/Templates/notification_task_move_position.php index 026db776..c3f94df7 100644 --- a/app/Templates/notification_task_move_position.php +++ b/app/Templates/notification_task_move_position.php @@ -8,4 +8,4 @@
  • - $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_task_open.php b/app/Templates/notification_task_open.php index 7bf674cc..5d9f7d5b 100644 --- a/app/Templates/notification_task_open.php +++ b/app/Templates/notification_task_open.php @@ -2,4 +2,4 @@

    - $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/notification_task_update.php b/app/Templates/notification_task_update.php index 9fd61b57..b3c07911 100644 --- a/app/Templates/notification_task_update.php +++ b/app/Templates/notification_task_update.php @@ -40,4 +40,4 @@ - $task)) ?> \ No newline at end of file + $task, 'application_url' => $application_url)) ?> \ No newline at end of file diff --git a/app/Templates/project_share.php b/app/Templates/project_share.php index 6cfd85f6..f06d7671 100644 --- a/app/Templates/project_share.php +++ b/app/Templates/project_share.php @@ -4,7 +4,7 @@ -
    +
    • diff --git a/app/Templates/project_show.php b/app/Templates/project_show.php index 98ffb581..96b9e404 100644 --- a/app/Templates/project_show.php +++ b/app/Templates/project_show.php @@ -1,7 +1,7 @@ -
        +
        • diff --git a/app/Templates/user_external.php b/app/Templates/user_external.php index a67d886e..676b2c73 100644 --- a/app/Templates/user_external.php +++ b/app/Templates/user_external.php @@ -5,7 +5,7 @@

          -

          +

          @@ -21,7 +21,7 @@

          -

          +

          diff --git a/app/Templates/user_show.php b/app/Templates/user_show.php index 5d42d3cf..1c843751 100644 --- a/app/Templates/user_show.php +++ b/app/Templates/user_show.php @@ -1,7 +1,7 @@

          -
            +
            • diff --git a/app/constants.php b/app/constants.php index 777e6f0e..93075892 100644 --- a/app/constants.php +++ b/app/constants.php @@ -1,14 +1,5 @@ '.$label.''; +} + +/** + * URL + * + * a('link', 'task', 'show', array('task_id' => $task_id)) + * + * @param string $controller Controller name + * @param string $action Action name + * @param array $params Url parameters + * @param boolean $csrf Add a CSRF token + * @return string + */ +function u($controller, $action, array $params = array(), $csrf = false) +{ + $html = '?controller='.$controller.'&action='.$action; + + if ($csrf) { + $params['csrf_token'] = Security::getCSRFToken(); + } foreach ($params as $key => $value) { $html .= '&'.$key.'='.$value; } - return '" class="'.$class.'"/>'.$label.''; -} + return $html; +} \ No newline at end of file -- cgit v1.2.3