From a4b0a993c7476c1890afa0e97d3b2c5f3a89bd3d Mon Sep 17 00:00:00 2001 From: ribas160 Date: Sat, 8 Feb 2025 14:31:09 +0200 Subject: [PATCH] Doc blocks added, available templates may be set in the general configuration file --- js/privatebin.js | 8 ++++++++ lib/Configuration.php | 10 +++++++++- lib/Controller.php | 15 ++++++++++++++- lib/TemplateSwitcher.php | 24 +++++++++++++++--------- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 8dcff38a..836ddb80 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -3940,6 +3940,14 @@ jQuery.PrivateBin = (function($, RawDeflate) { event.preventDefault(); } + /** + * save the template in a cookie and reloads the page + * + * @name TopNav.setTemplate + * @private + * @function + * @param {Event} event + */ function setTemplate(event) { let template = $(event.target).data('template') || event.target.value; diff --git a/lib/Configuration.php b/lib/Configuration.php index 2849d32a..9fad6267 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -78,6 +78,14 @@ class Configuration 'syntaxhighlighting' => 'Source Code', 'markdown' => 'Markdown', ), + 'available_templates' => array( + 'page', + 'bootstrap', + 'bootstrap-compact', + 'bootstrap-dark', + 'bootstrap-page', + 'bootstrap5', + ), 'traffic' => array( 'limit' => 10, 'header' => '', @@ -109,7 +117,7 @@ class Configuration 'js/kjua-0.9.0.js' => 'sha512-CVn7af+vTMBd9RjoS4QM5fpLFEOtBCoB0zPtaqIDC7sF4F8qgUSRFQQpIyEDGsr6yrjbuOLzdf20tkHHmpaqwQ==', 'js/legacy.js' => 'sha512-UxW/TOZKon83n6dk/09GsYKIyeO5LeBHokxyIq+r7KFS5KMBeIB/EM7NrkVYIezwZBaovnyNtY2d9tKFicRlXg==', 'js/prettify.js' => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==', - 'js/privatebin.js' => 'sha512-YDgd0cFfFHP/DLHQH2CWkGMjdFC5YjwDuWSoEsc1gU4h5sRd+T88mPYva1cdoviKEoty6F8pDe3E6chcMEzRag==', + 'js/privatebin.js' => 'sha512-BfzmQFxBXq4lOVT6wVzcDUnBXCvZaeqiq+Xapp9eyIg8nPC2B6x96LMwSZgA+QwCAE/Ps7P9/a4P5wYEfKNnOA==', 'js/purify-3.2.4.js' => 'sha512-Mu9BqoHURMeycg6AgqTpokUv9guq88pajfaFqz53fx1OxohyROkydXPLEIbdKCQ7EdDs9hgcrYeZ9zTiPQQ4CA==', 'js/rawinflate-0.3.js' => 'sha512-g8uelGgJW9A/Z1tB6Izxab++oj5kdD7B4qC7DHwZkB6DGMXKyzx7v5mvap2HXueI2IIn08YlRYM56jwWdm2ucQ==', 'js/showdown-2.1.0.js' => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==', diff --git a/lib/Controller.php b/lib/Controller.php index 1df117a4..538b5db7 100644 --- a/lib/Controller.php +++ b/lib/Controller.php @@ -183,6 +183,12 @@ class Controller $this->_setDefaultTemplate(); } + + /** + * Set default language + * + * @access private + */ private function _setDefaultLanguage() { $this->_conf = new Configuration; @@ -197,14 +203,21 @@ class Controller } + /** + * Set default template + * + * @access private + */ private function _setDefaultTemplate() { $this->_conf = new Configuration; + $templates = $this->_conf->getSection('available_templates'); $template = $this->_conf->getKey('templatedefault'); + TemplateSwitcher::setAvailableTemplates($templates); TemplateSwitcher::setTemplateFallback($template); // force default template, if template selection is disabled and a default is set - if (!$this->_conf->getKey('languageselection') && strlen($template) == 2) { + if (!$this->_conf->getKey('templateselection') && !empty($template)) { $_COOKIE['template'] = $template; setcookie('template', $template, array('SameSite' => 'Lax', 'Secure' => true)); } diff --git a/lib/TemplateSwitcher.php b/lib/TemplateSwitcher.php index f2f063d5..700f7730 100644 --- a/lib/TemplateSwitcher.php +++ b/lib/TemplateSwitcher.php @@ -36,14 +36,20 @@ class TemplateSwitcher { * @static * @var array */ - protected static $_availableTemplates = [ - 'page', - 'bootstrap', - 'bootstrap-compact', - 'bootstrap-dark', - 'bootstrap-page', - 'bootstrap5', - ]; + protected static $_availableTemplates = array(); + + + /** + * set available templates + * + * @access public + * @static + * @param array $templates + */ + public static function setAvailableTemplates(array $templates) + { + self::$_availableTemplates = $templates; + } /** * set the default template @@ -101,7 +107,7 @@ class TemplateSwitcher { * * @access private * @static - * @return string + * @return string|null */ private static function getSelectedByUserTemplate(): ?string {