diff options
| author | 2013-11-24 23:05:06 +0100 | |
|---|---|---|
| committer | 2013-11-24 23:05:06 +0100 | |
| commit | eae19e13634593d919811f527eff9e1efd34c03b (patch) | |
| tree | b961f9585f56ec2e63c3035ca2c77a11d684d6d9 /app/models/RSSThemes.php | |
| parent | d85e6c5b83a45ac2084ac5bca75e6b8a069e07a0 (diff) | |
Refactorise RSSThemes
* Évite de charger les informations de tous les thèmes lorsque ce n'est
pas nécessaire (c.à.d. en dehors de la page de configuration).
* Permettra de choisir des icônes différentes selon les thèmes sans
nécessairement passer par une CSS.
* Contribue à https://github.com/marienfressinaud/FreshRSS/issues/284
Diffstat (limited to 'app/models/RSSThemes.php')
| -rw-r--r-- | app/models/RSSThemes.php | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/app/models/RSSThemes.php b/app/models/RSSThemes.php index 54420048b..6e4ddbf6d 100644 --- a/app/models/RSSThemes.php +++ b/app/models/RSSThemes.php @@ -1,48 +1,50 @@ <?php class RSSThemes extends Model { - private static $themes_dir = '/themes'; - - private static $list = array(); - - public static function init() { - $basedir = PUBLIC_PATH . self::$themes_dir; + private static $themesUrl = '/themes/'; + private static $defaultIconsUrl = '/themes/icons/'; + public static function get() { $themes_list = array_diff( - scandir($basedir), + scandir(PUBLIC_PATH . self::$themesUrl), array('..', '.') ); + $list = array(); foreach ($themes_list as $theme_dir) { - $json_filename = $basedir . '/' . $theme_dir . '/metadata.json'; - if(file_exists($json_filename)) { + $theme = self::get_infos($theme_dir); + if ($theme) { + $list[$theme_dir] = $theme; + } + } + return $list; + } + + public static function get_infos($theme_id) { + $theme_dir = PUBLIC_PATH . self::$themesUrl . $theme_id ; + if (is_dir($theme_dir)) { + $json_filename = $theme_dir . '/metadata.json'; + if (file_exists($json_filename)) { $content = file_get_contents($json_filename); $res = json_decode($content, true); - - if($res && - isset($res['name']) && - isset($res['author']) && - isset($res['description']) && - isset($res['version']) && - isset($res['files']) && is_array($res['files'])) { - $theme = $res; - $theme['path'] = $theme_dir; - self::$list[$theme_dir] = $theme; + if ($res && isset($res['files']) && is_array($res['files'])) { + $res['path'] = $theme_id; + return $res; } } } + return false; } - public static function get() { - return self::$list; - } - - public static function get_infos($theme_id) { - if (isset(self::$list[$theme_id])) { - return self::$list[$theme_id]; - } + private static $themeIconsUrl; + private static $themeIcons; - return false; + public static function setThemeId($theme_id) { + self::$themeIconsUrl = self::$themesUrl . $theme_id . '/icons/'; + self::$themeIcons = is_dir(PUBLIC_PATH . self::$themeIconsUrl) ? array_fill_keys(array_diff( + scandir(PUBLIC_PATH . self::$themeIconsUrl), + array('..', '.') + ), 1) : array(); } public static function icon($name) { @@ -72,8 +74,15 @@ class RSSThemes extends Model { 'tag' => '⚐', 'up' => '△', ); - $alt = isset($alts[$name]) ? $alts[$name] : '?'; + if (!isset($alts[$name])) { + return ''; + } + + $url = $name . '.svg'; + $url = isset(self::$themeIcons[$url]) ? (self::$themeIconsUrl . $url) : + (self::$defaultIconsUrl . $url); + return '<i class="icon i_' . $name . '">' . $alts[$name] . '</i>'; - //return '<img class="icon" src="' . Url::display('/themes/icons/' . $name . '.svg') . '" alt="' . $alts[$name] . '" />'; + //return '<img class="icon" src="' . Url::display($url) . '" alt="' . $alts[$name] . '" />'; } } |
