]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Theme.php
Avoid memory issue in exception
[friendica.git] / src / Core / Theme.php
index c64ed08d3babdd315dd570c041878c89b8ea644d..62dfaa51f3072f45ce8d3bc56e871b2f0f4e3d5a 100644 (file)
@@ -6,7 +6,8 @@
 
 namespace Friendica\Core;
 
-use Friendica\Core\System;
+use Friendica\BaseObject;
+use Friendica\Model\Profile;
 
 require_once 'boot.php';
 
@@ -47,10 +48,10 @@ class Theme
                        return $info;
                }
 
-               $a = get_app();
+               $a = \get_app();
                $stamp1 = microtime(true);
                $theme_file = file_get_contents("view/theme/$theme/theme.php");
-               $a->save_timestamp($stamp1, "file");
+               $a->saveTimestamp($stamp1, "file");
 
                $result = preg_match("|/\*.*\*/|msU", $theme_file, $matches);
 
@@ -89,8 +90,9 @@ class Theme
         *
         * The screenshot is expected as view/theme/$theme/screenshot.[png|jpg].
         *
-        * @param sring $theme The name of the theme
+        * @param string $theme The name of the theme
         * @return string
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function getScreenshot($theme)
        {
@@ -106,7 +108,7 @@ class Theme
        // install and uninstall theme
        public static function uninstall($theme)
        {
-               logger("Addons: uninstalling theme " . $theme);
+               Logger::log("Addons: uninstalling theme " . $theme);
 
                include_once "view/theme/$theme/theme.php";
                if (function_exists("{$theme}_uninstall")) {
@@ -123,7 +125,7 @@ class Theme
                        return false;
                }
 
-               logger("Addons: installing theme $theme");
+               Logger::log("Addons: installing theme $theme");
 
                include_once "view/theme/$theme/theme.php";
 
@@ -132,7 +134,7 @@ class Theme
                        $func();
                        return true;
                } else {
-                       logger("Addons: FAILED installing theme $theme");
+                       Logger::log("Addons: FAILED installing theme $theme");
                        return false;
                }
        }
@@ -147,6 +149,7 @@ class Theme
         * @param string $file Filename
         * @param string $root Full root path
         * @return string Path to the file or empty string if the file isn't found
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function getPathForFile($file, $root = '')
        {
@@ -156,13 +159,13 @@ class Theme
                if ($root !== '' && $root[strlen($root) - 1] !== '/') {
                        $root = $root . '/';
                }
-               $theme_info = get_app()->theme_info;
+               $theme_info = \get_app()->theme_info;
                if (is_array($theme_info) && array_key_exists('extends', $theme_info)) {
                        $parent = $theme_info['extends'];
                } else {
                        $parent = 'NOPATH';
                }
-               $theme = get_app()->getCurrentTheme();
+               $theme = \get_app()->getCurrentTheme();
                $thname = $theme;
                $ext = substr($file, strrpos($file, '.') + 1);
                $paths = [
@@ -192,13 +195,19 @@ class Theme
         */
        public static function getStylesheetPath($theme)
        {
-               $a = get_app();
+               if (!file_exists('view/theme/' . $theme . '/style.php')) {
+                       return 'view/theme/' . $theme . '/style.css';
+               }
+
+               $a = BaseObject::getApp();
+
+               $query_params = [];
 
-               $opts = (($a->profile_uid) ? '?f=&puid=' . $a->profile_uid : '');
-               if (file_exists('view/theme/' . $theme . '/style.php')) {
-                       return 'view/theme/' . $theme . '/style.pcss' . $opts;
+               $puid = Profile::getThemeUid($a);
+               if ($puid) {
+                       $query_params['puid'] = $puid;
                }
 
-               return 'view/theme/' . $theme . '/style.css';
+               return 'view/theme/' . $theme . '/style.pcss' . (!empty($query_params) ? '?' . http_build_query($query_params) : '');
        }
 }