From 684e662a58b02bde225e44d3677987b6fc3adf0b Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 18 May 2016 21:48:24 +0200 Subject: Replace $GLOBALS configuration with the configuration manager in the whole code base --- application/PageBuilder.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'application/PageBuilder.php') diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 82580787..cf13c714 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -29,21 +29,22 @@ class PageBuilder private function initialize() { $this->tpl = new RainTPL(); + $conf = ConfigManager::getInstance(); try { $version = ApplicationUtils::checkUpdate( shaarli_version, - $GLOBALS['config']['UPDATECHECK_FILENAME'], - $GLOBALS['config']['UPDATECHECK_INTERVAL'], - $GLOBALS['config']['ENABLE_UPDATECHECK'], + $conf->get('config.UPDATECHECK_FILENAME'), + $conf->get('config.UPDATECHECK_INTERVAL'), + $conf->get('config.ENABLE_UPDATECHECK'), isLoggedIn(), - $GLOBALS['config']['UPDATECHECK_BRANCH'] + $conf->get('config.UPDATECHECK_BRANCH') ); $this->tpl->assign('newVersion', escape($version)); $this->tpl->assign('versionError', ''); } catch (Exception $exc) { - logm($GLOBALS['config']['LOG_FILE'], $_SERVER['REMOTE_ADDR'], $exc->getMessage()); + logm($conf->get('config.LOG_FILE'), $_SERVER['REMOTE_ADDR'], $exc->getMessage()); $this->tpl->assign('newVersion', ''); $this->tpl->assign('versionError', escape($exc->getMessage())); } @@ -62,16 +63,19 @@ class PageBuilder $this->tpl->assign('scripturl', index_url($_SERVER)); $this->tpl->assign('pagetitle', 'Shaarli'); $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? - if (!empty($GLOBALS['title'])) { - $this->tpl->assign('pagetitle', $GLOBALS['title']); + if ($conf->exists('title')) { + $this->tpl->assign('pagetitle', $conf->get('title')); } - if (!empty($GLOBALS['titleLink'])) { - $this->tpl->assign('titleLink', $GLOBALS['titleLink']); + if ($conf->exists('titleLink')) { + $this->tpl->assign('titleLink', $conf->get('titleLink')); } - if (!empty($GLOBALS['pagetitle'])) { - $this->tpl->assign('pagetitle', $GLOBALS['pagetitle']); + if ($conf->exists('pagetitle')) { + $this->tpl->assign('pagetitle', $conf->get('pagetitle')); } - $this->tpl->assign('shaarlititle', empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title']); + $this->tpl->assign('shaarlititle', $conf->get('title', 'Shaarli')); + $this->tpl->assign('openshaarli', $conf->get('config.OPEN_SHAARLI', false)); + $this->tpl->assign('showatom', $conf->get('config.SHOW_ATOM', false)); + // FIXME! Globals if (!empty($GLOBALS['plugin_errors'])) { $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); } -- cgit v1.2.3 From b74b96bfbd0b778ac50fd17f5e107c51435b1678 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 29 May 2016 12:32:14 +0200 Subject: Adds ConfigJson which handle the configuration in JSON format. Also use the Updater to make the transition --- application/PageBuilder.php | 1 + 1 file changed, 1 insertion(+) (limited to 'application/PageBuilder.php') diff --git a/application/PageBuilder.php b/application/PageBuilder.php index cf13c714..1d3ba9e8 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -75,6 +75,7 @@ class PageBuilder $this->tpl->assign('shaarlititle', $conf->get('title', 'Shaarli')); $this->tpl->assign('openshaarli', $conf->get('config.OPEN_SHAARLI', false)); $this->tpl->assign('showatom', $conf->get('config.SHOW_ATOM', false)); + $this->tpl->assign('hide_timestamps', $conf->get('config.HIDE_TIMESTAMPS', false)); // FIXME! Globals if (!empty($GLOBALS['plugin_errors'])) { $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); -- cgit v1.2.3 From da10377b3c263d96a46cf9101c202554343d2cd0 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 29 May 2016 16:10:32 +0200 Subject: Rename configuration keys and fix GLOBALS in templates --- application/PageBuilder.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'application/PageBuilder.php') diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 1d3ba9e8..04454865 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -34,17 +34,17 @@ class PageBuilder try { $version = ApplicationUtils::checkUpdate( shaarli_version, - $conf->get('config.UPDATECHECK_FILENAME'), - $conf->get('config.UPDATECHECK_INTERVAL'), - $conf->get('config.ENABLE_UPDATECHECK'), + $conf->get('path.update_check'), + $conf->get('general.check_updates_interval'), + $conf->get('general.check_updates'), isLoggedIn(), - $conf->get('config.UPDATECHECK_BRANCH') + $conf->get('general.check_updates_branch') ); $this->tpl->assign('newVersion', escape($version)); $this->tpl->assign('versionError', ''); } catch (Exception $exc) { - logm($conf->get('config.LOG_FILE'), $_SERVER['REMOTE_ADDR'], $exc->getMessage()); + logm($conf->get('path.log'), $_SERVER['REMOTE_ADDR'], $exc->getMessage()); $this->tpl->assign('newVersion', ''); $this->tpl->assign('versionError', escape($exc->getMessage())); } @@ -63,20 +63,19 @@ class PageBuilder $this->tpl->assign('scripturl', index_url($_SERVER)); $this->tpl->assign('pagetitle', 'Shaarli'); $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? - if ($conf->exists('title')) { - $this->tpl->assign('pagetitle', $conf->get('title')); + if ($conf->exists('general.title')) { + $this->tpl->assign('pagetitle', $conf->get('general.title')); } - if ($conf->exists('titleLink')) { - $this->tpl->assign('titleLink', $conf->get('titleLink')); + if ($conf->exists('general.header_link')) { + $this->tpl->assign('titleLink', $conf->get('general.header_link')); } if ($conf->exists('pagetitle')) { $this->tpl->assign('pagetitle', $conf->get('pagetitle')); } $this->tpl->assign('shaarlititle', $conf->get('title', 'Shaarli')); - $this->tpl->assign('openshaarli', $conf->get('config.OPEN_SHAARLI', false)); - $this->tpl->assign('showatom', $conf->get('config.SHOW_ATOM', false)); - $this->tpl->assign('hide_timestamps', $conf->get('config.HIDE_TIMESTAMPS', false)); - // FIXME! Globals + $this->tpl->assign('openshaarli', $conf->get('extras.open_shaarli', false)); + $this->tpl->assign('showatom', $conf->get('extras.show_atom', false)); + $this->tpl->assign('hide_timestamps', $conf->get('extras.hide_timestamps', false)); if (!empty($GLOBALS['plugin_errors'])) { $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); } -- cgit v1.2.3 From 278d9ee2836df7d805845077f26f8cecd16f0f4f Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 9 Jun 2016 20:04:02 +0200 Subject: ConfigManager no longer uses singleton pattern --- application/PageBuilder.php | 48 +++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'application/PageBuilder.php') diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 04454865..843cc0dc 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -14,13 +14,21 @@ class PageBuilder */ private $tpl; + /** + * @var ConfigManager $conf Configuration Manager instance. + */ + protected $conf; + /** * PageBuilder constructor. * $tpl is initialized at false for lazy loading. + * + * @param ConfigManager $conf Configuration Manager instance (reference). */ - function __construct() + function __construct(&$conf) { $this->tpl = false; + $this->conf = $conf; } /** @@ -29,22 +37,21 @@ class PageBuilder private function initialize() { $this->tpl = new RainTPL(); - $conf = ConfigManager::getInstance(); try { $version = ApplicationUtils::checkUpdate( shaarli_version, - $conf->get('path.update_check'), - $conf->get('general.check_updates_interval'), - $conf->get('general.check_updates'), + $this->conf->get('path.update_check'), + $this->conf->get('general.check_updates_interval'), + $this->conf->get('general.check_updates'), isLoggedIn(), - $conf->get('general.check_updates_branch') + $this->conf->get('general.check_updates_branch') ); $this->tpl->assign('newVersion', escape($version)); $this->tpl->assign('versionError', ''); } catch (Exception $exc) { - logm($conf->get('path.log'), $_SERVER['REMOTE_ADDR'], $exc->getMessage()); + logm($this->conf->get('path.log'), $_SERVER['REMOTE_ADDR'], $exc->getMessage()); $this->tpl->assign('newVersion', ''); $this->tpl->assign('versionError', escape($exc->getMessage())); } @@ -63,19 +70,19 @@ class PageBuilder $this->tpl->assign('scripturl', index_url($_SERVER)); $this->tpl->assign('pagetitle', 'Shaarli'); $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? - if ($conf->exists('general.title')) { - $this->tpl->assign('pagetitle', $conf->get('general.title')); + if ($this->conf->exists('general.title')) { + $this->tpl->assign('pagetitle', $this->conf->get('general.title')); } - if ($conf->exists('general.header_link')) { - $this->tpl->assign('titleLink', $conf->get('general.header_link')); + if ($this->conf->exists('general.header_link')) { + $this->tpl->assign('titleLink', $this->conf->get('general.header_link')); } - if ($conf->exists('pagetitle')) { - $this->tpl->assign('pagetitle', $conf->get('pagetitle')); + if ($this->conf->exists('pagetitle')) { + $this->tpl->assign('pagetitle', $this->conf->get('pagetitle')); } - $this->tpl->assign('shaarlititle', $conf->get('title', 'Shaarli')); - $this->tpl->assign('openshaarli', $conf->get('extras.open_shaarli', false)); - $this->tpl->assign('showatom', $conf->get('extras.show_atom', false)); - $this->tpl->assign('hide_timestamps', $conf->get('extras.hide_timestamps', false)); + $this->tpl->assign('shaarlititle', $this->conf->get('title', 'Shaarli')); + $this->tpl->assign('openshaarli', $this->conf->get('extras.open_shaarli', false)); + $this->tpl->assign('showatom', $this->conf->get('extras.show_atom', false)); + $this->tpl->assign('hide_timestamps', $this->conf->get('extras.hide_timestamps', false)); if (!empty($GLOBALS['plugin_errors'])) { $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); } @@ -89,7 +96,6 @@ class PageBuilder */ public function assign($placeholder, $value) { - // Lazy initialization if ($this->tpl === false) { $this->initialize(); } @@ -105,7 +111,6 @@ class PageBuilder */ public function assignAll($data) { - // Lazy initialization if ($this->tpl === false) { $this->initialize(); } @@ -117,6 +122,7 @@ class PageBuilder foreach ($data as $key => $value) { $this->assign($key, $value); } + return true; } /** @@ -127,10 +133,10 @@ class PageBuilder */ public function renderPage($page) { - // Lazy initialization - if ($this->tpl===false) { + if ($this->tpl === false) { $this->initialize(); } + $this->tpl->draw($page); } -- cgit v1.2.3 From 894a3c4bf38d8dcadb6941049b9167e5101805bd Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 11 Jun 2016 09:08:02 +0200 Subject: Rename configuration key for better sections --- application/PageBuilder.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'application/PageBuilder.php') diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 843cc0dc..88dbfa8a 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -41,17 +41,17 @@ class PageBuilder try { $version = ApplicationUtils::checkUpdate( shaarli_version, - $this->conf->get('path.update_check'), - $this->conf->get('general.check_updates_interval'), - $this->conf->get('general.check_updates'), + $this->conf->get('resource.update_check'), + $this->conf->get('updates.check_updates_interval'), + $this->conf->get('updates.check_updates'), isLoggedIn(), - $this->conf->get('general.check_updates_branch') + $this->conf->get('updates.check_updates_branch') ); $this->tpl->assign('newVersion', escape($version)); $this->tpl->assign('versionError', ''); } catch (Exception $exc) { - logm($this->conf->get('path.log'), $_SERVER['REMOTE_ADDR'], $exc->getMessage()); + logm($this->conf->get('resource.log'), $_SERVER['REMOTE_ADDR'], $exc->getMessage()); $this->tpl->assign('newVersion', ''); $this->tpl->assign('versionError', escape($exc->getMessage())); } @@ -80,9 +80,9 @@ class PageBuilder $this->tpl->assign('pagetitle', $this->conf->get('pagetitle')); } $this->tpl->assign('shaarlititle', $this->conf->get('title', 'Shaarli')); - $this->tpl->assign('openshaarli', $this->conf->get('extras.open_shaarli', false)); - $this->tpl->assign('showatom', $this->conf->get('extras.show_atom', false)); - $this->tpl->assign('hide_timestamps', $this->conf->get('extras.hide_timestamps', false)); + $this->tpl->assign('openshaarli', $this->conf->get('security.open_shaarli', false)); + $this->tpl->assign('showatom', $this->conf->get('feed.show_atom', false)); + $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); if (!empty($GLOBALS['plugin_errors'])) { $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); } -- cgit v1.2.3 From b302c77c74a09cb271b711248b8f433555524ef0 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 15 Jun 2016 18:22:19 +0200 Subject: Pass the configuration manager to templates --- application/PageBuilder.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'application/PageBuilder.php') diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 88dbfa8a..7cd88370 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -86,6 +86,8 @@ class PageBuilder if (!empty($GLOBALS['plugin_errors'])) { $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); } + // To be removed with a proper theme configuration. + $this->tpl->assign('conf', $this->conf); } /** -- cgit v1.2.3 From 97ef33bb7296cea995b19932a95c6aaec7242dc6 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 19 Jul 2016 18:03:09 +0200 Subject: Fixes #600 - Shaarli's title is not set with the new config manager - Fixed title config key - Page title (in head tag) is no longer set through the config manager --- application/PageBuilder.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'application/PageBuilder.php') diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 7cd88370..1ca0260a 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -68,18 +68,12 @@ class PageBuilder $this->tpl->assign('source', index_url($_SERVER)); $this->tpl->assign('version', shaarli_version); $this->tpl->assign('scripturl', index_url($_SERVER)); - $this->tpl->assign('pagetitle', 'Shaarli'); $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? - if ($this->conf->exists('general.title')) { - $this->tpl->assign('pagetitle', $this->conf->get('general.title')); - } + $this->tpl->assign('pagetitle', $this->conf->get('general.title', 'Shaarli')); if ($this->conf->exists('general.header_link')) { $this->tpl->assign('titleLink', $this->conf->get('general.header_link')); } - if ($this->conf->exists('pagetitle')) { - $this->tpl->assign('pagetitle', $this->conf->get('pagetitle')); - } - $this->tpl->assign('shaarlititle', $this->conf->get('title', 'Shaarli')); + $this->tpl->assign('shaarlititle', $this->conf->get('general.title', 'Shaarli')); $this->tpl->assign('openshaarli', $this->conf->get('security.open_shaarli', false)); $this->tpl->assign('showatom', $this->conf->get('feed.show_atom', false)); $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); -- cgit v1.2.3 From fd5ac47ea27353e641a521b5e1867bfd20ff0512 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 6 Aug 2016 14:09:26 +0200 Subject: Generate a token for every pages --- application/PageBuilder.php | 1 + 1 file changed, 1 insertion(+) (limited to 'application/PageBuilder.php') diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 1ca0260a..42932f32 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -80,6 +80,7 @@ class PageBuilder if (!empty($GLOBALS['plugin_errors'])) { $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); } + $this->tpl->assign('token', getToken($this->conf)); // To be removed with a proper theme configuration. $this->tpl->assign('conf', $this->conf); } -- cgit v1.2.3 From 7fde6de1212323418401c15efba06026c704ca87 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 14 Oct 2016 13:22:58 +0200 Subject: New init function for plugins, supports errors reporting All plugins can optionally add an init function named `pluginname_init()` which is called when the plugin is loaded. This function is aware of the config, and can return initialization errors, which are displayed in the header template. Note that the previous error system hack no longer work. --- application/PageBuilder.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'application/PageBuilder.php') diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 42932f32..32c7f9f1 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -77,9 +77,6 @@ class PageBuilder $this->tpl->assign('openshaarli', $this->conf->get('security.open_shaarli', false)); $this->tpl->assign('showatom', $this->conf->get('feed.show_atom', false)); $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); - if (!empty($GLOBALS['plugin_errors'])) { - $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); - } $this->tpl->assign('token', getToken($this->conf)); // To be removed with a proper theme configuration. $this->tpl->assign('conf', $this->conf); -- cgit v1.2.3