aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Themes.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models/Themes.php')
-rw-r--r--app/Models/Themes.php33
1 files changed, 22 insertions, 11 deletions
diff --git a/app/Models/Themes.php b/app/Models/Themes.php
index 2a55a84db..cd66723bf 100644
--- a/app/Models/Themes.php
+++ b/app/Models/Themes.php
@@ -7,7 +7,7 @@ class FreshRSS_Themes extends Minz_Model {
private static string $defaultIconsUrl = '/themes/icons/';
public static string $defaultTheme = 'Origine';
- /** @return array<string> */
+ /** @return list<string> */
public static function getList(): array {
return array_values(array_diff(
scandir(PUBLIC_PATH . self::$themesUrl) ?: [],
@@ -15,7 +15,7 @@ class FreshRSS_Themes extends Minz_Model {
));
}
- /** @return array<string,array{'id':string,'name':string,'author':string,'description':string,'version':float|string,'files':array<string>,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}}> */
+ /** @return array<string,array{id:string,name:string,author:string,description:string,version:float|string,files:array<string>,theme-color?:string|array{dark?:string,light?:string,default?:string}}> */
public static function get(): array {
$themes_list = self::getList();
$list = [];
@@ -29,7 +29,7 @@ class FreshRSS_Themes extends Minz_Model {
}
/**
- * @return false|array{'id':string,'name':string,'author':string,'description':string,'version':float|string,'files':array<string>,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}}
+ * @return false|array{id:string,name:string,author:string,description:string,version:float|string,files:array<string>,theme-color?:string|array{dark?:string,light?:string,default?:string}}
*/
public static function get_infos(string $theme_id): array|false {
$theme_dir = PUBLIC_PATH . self::$themesUrl . $theme_id;
@@ -38,13 +38,24 @@ class FreshRSS_Themes extends Minz_Model {
if (file_exists($json_filename)) {
$content = file_get_contents($json_filename) ?: '';
$res = json_decode($content, true);
- if (is_array($res) &&
- !empty($res['name']) &&
- isset($res['files']) &&
- is_array($res['files'])) {
- $res['id'] = $theme_id;
- /** @var array{'id':string,'name':string,'author':string,'description':string,'version':float|string,'files':array<string>,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}} */
- return $res;
+ if (is_array($res)) {
+ $result = [
+ 'id' => $theme_id,
+ 'name' => is_string($res['name'] ?? null) ? $res['name'] : '',
+ 'author' => is_string($res['author'] ?? null) ? $res['author'] : '',
+ 'description' => is_string($res['description'] ?? null) ? $res['description'] : '',
+ 'version' => is_string($res['version'] ?? null) || is_numeric($res['version'] ?? null) ? $res['version'] : '0',
+ 'files' => is_array($res['files']) && is_array_values_string($res['files']) ? array_values($res['files']) : [],
+ 'theme-color' => is_string($res['theme-color'] ?? null) ? $res['theme-color'] : '',
+ ];
+ if (empty($result['theme-color']) && is_array($res['theme-color'])) {
+ $result['theme-color'] = [
+ 'dark' => is_string($res['theme-color']['dark'] ?? null) ? $res['theme-color']['dark'] : '',
+ 'light' => is_string($res['theme-color']['light'] ?? null) ? $res['theme-color']['light'] : '',
+ 'default' => is_string($res['theme-color']['default'] ?? null) ? $res['theme-color']['default'] : '',
+ ];
+ }
+ return $result;
}
}
}
@@ -56,7 +67,7 @@ class FreshRSS_Themes extends Minz_Model {
private static array $themeIcons;
/**
- * @return false|array{'id':string,'name':string,'author':string,'description':string,'version':float|string,'files':array<string>,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}}
+ * @return false|array{id:string,name:string,author:string,description:string,version:float|string,files:array<string>,theme-color?:string|array{dark?:string,light?:string,default?:string}}
*/
public static function load(string $theme_id): array|false {
$infos = self::get_infos($theme_id);