Просмотр исходного кода

Doc blocks added, available templates may be set in the general configuration file

ribas160 1 год назад
Родитель
Сommit
a4b0a993c7
4 измененных файлов с 46 добавлено и 11 удалено
  1. 8 0
      js/privatebin.js
  2. 9 1
      lib/Configuration.php
  3. 14 1
      lib/Controller.php
  4. 15 9
      lib/TemplateSwitcher.php

+ 8 - 0
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;

+ 9 - 1
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==',

+ 14 - 1
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));
         }

+ 15 - 9
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
     {