. * */ namespace SP; defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo')); /** * Class Themes para el manejo de los temas visuales * * @package SP */ class Themes { /** * @var string */ public static $themeUri = ''; /** * @var string */ public static $themePath = ''; /** * @var string */ public static $theme = ''; /** * Obtener los temas disponibles desde el directorio de temas * * @return array Con la información del tema */ public static function getThemesAvailable() { $themesAvailable = array(); $dirThemes = dir(VIEW_PATH); while (false !== ($theme = $dirThemes->read())) { if ($theme != '.' && $theme != '..') { $themeFile = VIEW_PATH . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'index.php'; if (file_exists($themeFile)) { include $themeFile; $themesAvailable[$theme] = $themeInfo['name']; } } } $dirThemes->close(); return $themesAvailable; } /** * Establecer el tema visual a utilizar * * @param bool $force Forzar la detección del tema para los inicios de sesión */ public static function setTheme($force = false) { $theme = Session::getTheme(); if (empty($theme) || $force === true) { $Theme = new Themes(); $userTheme = $Theme->getUserTheme(); $globalTheme = $Theme->getGlobalTheme(); $theme = ($userTheme) ? $userTheme : $globalTheme; Session::setTheme($theme); } self::setThemePaths($theme); Session::setTheme($theme); } /** * Obtener el tema visual del usuario * * @return string */ private function getUserTheme() { return (Session::getUserId() > 0) ? UserPreferences::getPreferences(Session::getUserId())->getTheme() : ''; } /** * Devolver el tema visual de sysPass desde la configuración */ private function getGlobalTheme() { self::$theme = Config::getValue('sitetheme', 'material-blue'); return self::$theme; } /** * Establecer las variables de rutas para el tema visual * * @param string $theme El tema a utilizar */ private static function setThemePaths($theme) { self::$theme = $theme; self::$themeUri = Init::$WEBURI . '/inc/themes/' . $theme; self::$themePath = DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme; } /** * Obtener la información del tema desde el archivo de información * * @return array * */ public static function getThemeInfo() { $themeFile = Init::$SERVERROOT . self::$themePath . DIRECTORY_SEPARATOR . 'index.php'; $themeInfo = array(); if (file_exists($themeFile)) { include $themeFile; } return $themeInfo; } }