A free, self-hostable news aggregator…
Refactorise RSSThemes
Alexandre Alapetiteeae19e136345
diff --git a/app/App_FrontController.php b/app/App_FrontController.phpindex b1e6787dc..1f270c0b1 100644--- a/app/App_FrontController.php+++ b/app/App_FrontController.php@@ -11,7 +11,6 @@ class App_FrontController extends FrontController {$this->loadModels ();Session::init ();- RSSThemes::init ();Translate::init ();$this->loadParamsView ();diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.phpindex 741dd84a1..ef562bdcb 100755--- a/app/models/RSSConfiguration.php+++ b/app/models/RSSConfiguration.php@@ -49,6 +49,7 @@ class RSSConfiguration extends Model {$this->_markWhen ($confDAO->mark_when);$this->_urlShaarli ($confDAO->url_shaarli);$this->_theme ($confDAO->theme);+ RSSThemes::setThemeId ($confDAO->theme);$this->_anonAccess ($confDAO->anon_access);$this->_token ($confDAO->token);$this->_autoLoadMore ($confDAO->auto_load_more);diff --git a/app/models/RSSThemes.php b/app/models/RSSThemes.phpindex 54420048b..6e4ddbf6d 100644--- a/app/models/RSSThemes.php+++ b/app/models/RSSThemes.php@@ -1,48 +1,50 @@<?phpclass 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] . '" />';}}