X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FTheme.php;h=61798a3969d99e7345dc2f0559c9018db488bc96;hb=295d90d496a56217383481fa7a0153e0ac48e38a;hp=c972e09fc71a659c085a7a0288c7b69f3391d19c;hpb=b73caa83fc1febd943b232a83186cbdce6460866;p=friendica.git diff --git a/src/Core/Theme.php b/src/Core/Theme.php index c972e09fc7..61798a3969 100644 --- a/src/Core/Theme.php +++ b/src/Core/Theme.php @@ -20,7 +20,7 @@ class Theme public static function getAllowedList() { $allowed_themes_str = Config::get('system', 'allowed_themes'); - $allowed_themes_raw = explode(',', $allowed_themes_str); + $allowed_themes_raw = explode(',', str_replace(' ', '', $allowed_themes_str)); $allowed_themes = []; if (count($allowed_themes_raw)) { foreach ($allowed_themes_raw as $theme) { @@ -34,6 +34,11 @@ class Theme return $allowed_themes; } + public static function setAllowedList(array $allowed_themes) + { + Config::set('system', 'allowed_themes', implode(',', $allowed_themes)); + } + /** * @brief Parse theme comment in search of theme infos. * @@ -133,13 +138,20 @@ class Theme // silently fail if theme was removed or if $theme is funky if (file_exists("view/theme/$theme/theme.php")) { - Logger::log("Addons: uninstalling theme " . $theme); + include_once "view/theme/$theme/theme.php"; - if (function_exists("{$theme}_uninstall")) { - $func = "{$theme}_uninstall"; + $func = "{$theme}_uninstall"; + if (function_exists($func)) { $func(); } } + + $allowed_themes = Theme::getAllowedList(); + $key = array_search($theme, $allowed_themes); + if ($key !== false) { + unset($allowed_themes[$key]); + Theme::setAllowedList($allowed_themes); + } } public static function install($theme) @@ -151,16 +163,21 @@ class Theme return false; } - Logger::log("Addons: installing theme $theme"); - - include_once "view/theme/$theme/theme.php"; + try { + include_once "view/theme/$theme/theme.php"; - if (function_exists("{$theme}_install")) { $func = "{$theme}_install"; - $func(); + if (function_exists($func)) { + $func(); + } + + $allowed_themes = Theme::getAllowedList(); + $allowed_themes[] = $theme; + Theme::setAllowedList($allowed_themes); + return true; - } else { - Logger::log("Addons: FAILED installing theme $theme"); + } catch (\Exception $e) { + Logger::error('Theme installation failed', ['theme' => $theme, 'error' => $e->getMessage()]); return false; } }