فهرست منبع

Mise à jour nom thèmes + chargement robuste des thèmes

Renomme : default -> Origine
En cas de thème introuvable, charge le thème par défaut, sinon le
premier disponible.
https://github.com/marienfressinaud/FreshRSS/issues/120
Alexandre Alapetite 12 سال پیش
والد
کامیت
f720d41cbf

+ 5 - 1
app/Controllers/configureController.php

@@ -157,7 +157,11 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
 				'scroll' => Minz_Request::param('mark_scroll', false),
 				'reception' => Minz_Request::param('mark_upon_reception', false),
 			));
-			$this->view->conf->_theme(Minz_Request::param('theme', 'default'));
+			$themeId = Minz_Request::param('theme', '');
+			if ($themeId == '') {
+				$themeId = FreshRSS_Themes::defaultTheme;
+			}
+			$this->view->conf->_theme($themeId);
 			$this->view->conf->_topline_read(Minz_Request::param('topline_read', false));
 			$this->view->conf->_topline_favorite(Minz_Request::param('topline_favorite', false));
 			$this->view->conf->_topline_date(Minz_Request::param('topline_date', false));

+ 2 - 3
app/FreshRSS.php

@@ -114,11 +114,10 @@ class FreshRSS extends Minz_FrontController {
 	}
 
 	private function loadStylesAndScripts ($loginOk) {
-		$theme = FreshRSS_Themes::get_infos($this->conf->theme);
+		$theme = FreshRSS_Themes::load($this->conf->theme);
 		if ($theme) {
-			FreshRSS_Themes::setThemeId($this->conf->theme);
 			foreach($theme['files'] as $file) {
-				Minz_View::appendStyle (Minz_Url::display ('/themes/' . $theme['path'] . '/' . $file . '?' . @filemtime(PUBLIC_PATH . '/themes/' . $theme['path'] . '/' . $file)));
+				Minz_View::appendStyle (Minz_Url::display ('/themes/' . $theme['id'] . '/' . $file . '?' . @filemtime(PUBLIC_PATH . '/themes/' . $theme['path'] . '/' . $file)));
 			}
 		}
 

+ 1 - 1
app/Models/Configuration.php

@@ -25,7 +25,7 @@ class FreshRSS_Configuration {
 			'scroll' => false,
 			'reception' => false,
 		),
-		'theme' => 'default',
+		'theme' => 'Origine',
 		'shortcuts' => array(
 			'mark_read' => 'r',
 			'mark_favorite' => 'f',

+ 23 - 5
app/Models/Themes.php

@@ -3,13 +3,17 @@
 class FreshRSS_Themes extends Minz_Model {
 	private static $themesUrl = '/themes/';
 	private static $defaultIconsUrl = '/themes/icons/';
+	public static $defaultTheme = 'Origine';
 
-	public static function get() {
-		$themes_list = array_diff(
+	public static function getList() {
+		return array_values(array_diff(
 			scandir(PUBLIC_PATH . self::$themesUrl),
 			array('..', '.')
-		);
+		));
+	}
 
+	public static function get() {
+		$themes_list = self::getList();
 		$list = array();
 		foreach ($themes_list as $theme_dir) {
 			$theme = self::get_infos($theme_dir);
@@ -28,7 +32,7 @@ class FreshRSS_Themes extends Minz_Model {
 				$content = file_get_contents($json_filename);
 				$res = json_decode($content, true);
 				if ($res && isset($res['files']) && is_array($res['files'])) {
-					$res['path'] = $theme_id;
+					$res['id'] = $theme_id;
 					return $res;
 				}
 			}
@@ -39,12 +43,26 @@ class FreshRSS_Themes extends Minz_Model {
 	private static $themeIconsUrl;
 	private static $themeIcons;
 
-	public static function setThemeId($theme_id) {
+	public static function load($theme_id) {
+		$infos = self::get_infos($theme_id);
+		if (!$infos) {
+			if ($theme_id !== self::$defaultTheme) {	//Fall-back to default theme
+				return self::load(self::$defaultTheme);
+			}
+			$themes_list = self::getList();
+			if (!empty($themes_list)) {
+				if ($theme_id !== $themes_list[0]) {	//Fall-back to first theme
+					return self::load($themes_list[0]);
+				}
+			}
+			return false;
+		}
 		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();
+		return $infos;
 	}
 
 	public static function icon($name, $urlOnly = false) {

+ 3 - 2
app/views/configure/display.phtml

@@ -21,9 +21,10 @@
 		<div class="form-group">
 			<label class="group-name" for="theme"><?php echo Minz_Translate::t ('theme'); ?></label>
 			<div class="group-controls">
-				<select name="theme" id="theme">
+				<select name="theme" id="theme" required="">
+				<option></option>
 				<?php foreach ($this->themes as $theme) { ?>
-				<option value="<?php echo $theme['path']; ?>"<?php echo $this->conf->theme === $theme['path'] ? ' selected="selected"' : ''; ?>>
+				<option value="<?php echo $theme['id']; ?>"<?php echo $this->conf->theme === $theme['id'] ? ' selected="selected"' : ''; ?>>
 					<?php echo $theme['name'] . ' — ' . Minz_Translate::t ('by') . ' ' . $theme['author']; ?> 
 				</option>
 				<?php } ?>

+ 0 - 0
p/themes/default_dark/freshrss.css → p/themes/Dark/freshrss.css


+ 0 - 0
p/themes/default_dark/global.css → p/themes/Dark/global.css


+ 0 - 0
p/themes/default_dark/loader.gif → p/themes/Dark/loader.gif


+ 7 - 0
p/themes/Dark/metadata.json

@@ -0,0 +1,7 @@
+{
+	"name": "Dark",
+	"author": "AD",
+	"description": "Le coté obscur du thème “Origine”",
+	"version": 0.1,
+	"files": ["global.css", "freshrss.css"]
+}

+ 0 - 0
p/themes/flat-design/freshrss.css → p/themes/Flat/freshrss.css


+ 0 - 0
p/themes/flat-design/global.css → p/themes/Flat/global.css


+ 0 - 0
p/themes/flat-design/icons/add.svg → p/themes/Flat/icons/add.svg


+ 0 - 0
p/themes/flat-design/icons/all.svg → p/themes/Flat/icons/all.svg


+ 0 - 0
p/themes/flat-design/icons/close.svg → p/themes/Flat/icons/close.svg


+ 0 - 0
p/themes/flat-design/icons/configure.svg → p/themes/Flat/icons/configure.svg


+ 0 - 0
p/themes/flat-design/icons/down.svg → p/themes/Flat/icons/down.svg


+ 0 - 0
p/themes/flat-design/icons/next.svg → p/themes/Flat/icons/next.svg


+ 0 - 0
p/themes/flat-design/icons/prev.svg → p/themes/Flat/icons/prev.svg


+ 0 - 0
p/themes/flat-design/icons/refresh.svg → p/themes/Flat/icons/refresh.svg


+ 0 - 0
p/themes/flat-design/icons/search.svg → p/themes/Flat/icons/search.svg


+ 0 - 0
p/themes/flat-design/icons/up.svg → p/themes/Flat/icons/up.svg


+ 0 - 0
p/themes/flat-design/loader.gif → p/themes/Flat/loader.gif


+ 0 - 0
p/themes/flat-design/metadata.json → p/themes/Flat/metadata.json


+ 0 - 0
p/themes/default/freshrss.css → p/themes/Origine/freshrss.css


+ 0 - 0
p/themes/default/global.css → p/themes/Origine/global.css


+ 0 - 0
p/themes/default/loader.gif → p/themes/Origine/loader.gif


+ 1 - 1
p/themes/default/metadata.json → p/themes/Origine/metadata.json

@@ -1,5 +1,5 @@
 {
-  "name": "Default",
+  "name": "Origine",
   "author": "Marien Fressinaud",
   "description": "Le thème par défaut pour FreshRSS",
   "version": 0.1,

+ 0 - 7
p/themes/default_dark/metadata.json

@@ -1,7 +0,0 @@
-{
-  "name": "Dark",
-  "author": "AD",
-  "description": "Le coté obscur du thème par défaut pour FreshRSS",
-  "version": 0.1,
-  "files": ["global.css", "freshrss.css"]
-}