mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2026-01-23 02:35:23 +00:00
Added the ability to web users to change the theme
This commit is contained in:
parent
6ba9fe5a93
commit
c7a4ced9e1
45 changed files with 367 additions and 43 deletions
117
lib/TemplateSwitcher.php
Normal file
117
lib/TemplateSwitcher.php
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* PrivateBin
|
||||
*
|
||||
* a zero-knowledge paste bin
|
||||
*
|
||||
* @link https://github.com/PrivateBin/PrivateBin
|
||||
* @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
|
||||
* @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
|
||||
*/
|
||||
|
||||
namespace PrivateBin;
|
||||
|
||||
|
||||
/**
|
||||
* TemplateSwitcher
|
||||
*
|
||||
* Provides tool to change application template
|
||||
*/
|
||||
class TemplateSwitcher {
|
||||
|
||||
/**
|
||||
* template fallback
|
||||
*
|
||||
* @access protected
|
||||
* @static
|
||||
* @var string
|
||||
*/
|
||||
protected static $_templateFallback = "bootstrap";
|
||||
|
||||
|
||||
/**
|
||||
* available templates
|
||||
*
|
||||
* @access protected
|
||||
* @static
|
||||
* @var array
|
||||
*/
|
||||
protected static $_availableTemplates = [
|
||||
'page',
|
||||
'bootstrap',
|
||||
'bootstrap-compact',
|
||||
'bootstrap-dark',
|
||||
'bootstrap-page',
|
||||
'bootstrap5',
|
||||
];
|
||||
|
||||
/**
|
||||
* set the default template
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param string $template
|
||||
*/
|
||||
public static function setTemplateFallback(string $template)
|
||||
{
|
||||
if (self::isTemplateAvailable($template)) {
|
||||
self::$_templateFallback = $template;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get currently loaded template
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @return string
|
||||
*/
|
||||
public static function getTemplate(): string
|
||||
{
|
||||
$selectedTemplate = self::getSelectedByUserTemplate();
|
||||
return $selectedTemplate ?? self::$_templateFallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* get list of available templates
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @return array
|
||||
*/
|
||||
public static function getAvailableTemplates(): array
|
||||
{
|
||||
return self::$_availableTemplates;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the provided template is available
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @return bool
|
||||
*/
|
||||
public static function isTemplateAvailable(string $template): bool
|
||||
{
|
||||
return in_array($template, self::getAvailableTemplates());
|
||||
}
|
||||
|
||||
/**
|
||||
* get the template selected by user
|
||||
*
|
||||
* @access private
|
||||
* @static
|
||||
* @return string
|
||||
*/
|
||||
private static function getSelectedByUserTemplate(): ?string
|
||||
{
|
||||
$selectedTemplate = null;
|
||||
$templateCookieValue = $_COOKIE['template'] ?? "";
|
||||
|
||||
if (self::isTemplateAvailable($templateCookieValue)) {
|
||||
$selectedTemplate = $templateCookieValue;
|
||||
}
|
||||
|
||||
return $selectedTemplate;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue