]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Renderer.php
Merge pull request #11520 from annando/display-polls
[friendica.git] / src / Core / Renderer.php
index 24f00341733530a24d097a1a1bf01f00049bda94..29bbb2b89491f83fdd63bfd554108bf5f7eeb65b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -23,7 +23,7 @@ namespace Friendica\Core;
 
 use Exception;
 use Friendica\DI;
-use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Network\HTTPException\ServiceUnavailableException;
 use Friendica\Render\TemplateEngine;
 
 /**
@@ -48,10 +48,8 @@ class Renderer
         * beyond are used.
         */
        public static $theme = [
-               'sourcename' => '',
                'videowidth' => 425,
                'videoheight' => 350,
-               'force_max_items' => 0,
                'stylesheet' => '',
                'template_engine' => 'smarty3',
        ];
@@ -71,11 +69,11 @@ class Renderer
         * @param string $template
         * @param array  $vars
         * @return string
-        * @throws InternalServerErrorException
+        * @throws ServiceUnavailableException
         */
        public static function replaceMacros(string $template, array $vars = [])
        {
-               $stamp1 = microtime(true);
+               DI::profiler()->startRecording('rendering');
 
                // pass $baseurl to all templates if it isn't set
                $vars = array_merge(['$baseurl' => DI::baseUrl()->get(), '$APP' => DI::app()], $vars);
@@ -86,13 +84,13 @@ class Renderer
                        $output = $t->replaceMacros($template, $vars);
                } catch (Exception $e) {
                        DI::logger()->critical($e->getMessage(), ['template' => $template, 'vars' => $vars]);
-                       $message = is_site_admin() ?
+                       $message = DI::app()->isSiteAdmin() ?
                                $e->getMessage() :
                                DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
-                       throw new InternalServerErrorException($message);
+                       throw new ServiceUnavailableException($message);
                }
 
-               DI::profiler()->saveTimestamp($stamp1, "rendering");
+               DI::profiler()->stopRecording();
 
                return $output;
        }
@@ -104,24 +102,24 @@ class Renderer
         * @param string $subDir Subdirectory (Optional)
         *
         * @return string template.
-        * @throws InternalServerErrorException
+        * @throws ServiceUnavailableException
         */
        public static function getMarkupTemplate($file, $subDir = '')
        {
-               $stamp1 = microtime(true);
+               DI::profiler()->startRecording('file');
                $t = self::getTemplateEngine();
 
                try {
                        $template = $t->getTemplateFile($file, $subDir);
                } catch (Exception $e) {
                        DI::logger()->critical($e->getMessage(), ['file' => $file, 'subDir' => $subDir]);
-                       $message = is_site_admin() ?
+                       $message = DI::app()->isSiteAdmin() ?
                                $e->getMessage() :
                                DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
-                       throw new InternalServerErrorException($message);
+                       throw new ServiceUnavailableException($message);
                }
 
-               DI::profiler()->saveTimestamp($stamp1, "file");
+               DI::profiler()->stopRecording();
 
                return $template;
        }
@@ -130,7 +128,7 @@ class Renderer
         * Register template engine class
         *
         * @param string $class
-        * @throws InternalServerErrorException
+        * @throws ServiceUnavailableException
         */
        public static function registerTemplateEngine($class)
        {
@@ -142,10 +140,10 @@ class Renderer
                } else {
                        $admin_message = DI::l10n()->t('template engine cannot be registered without a name.');
                        DI::logger()->critical($admin_message, ['class' => $class]);
-                       $message = is_site_admin() ?
+                       $message = DI::app()->isSiteAdmin() ?
                                $admin_message :
                                DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
-                       throw new InternalServerErrorException($message);
+                       throw new ServiceUnavailableException($message);
                }
        }
 
@@ -156,7 +154,7 @@ class Renderer
         * or default
         *
         * @return TemplateEngine Template Engine instance
-        * @throws InternalServerErrorException
+        * @throws ServiceUnavailableException
         */
        public static function getTemplateEngine()
        {
@@ -168,7 +166,7 @@ class Renderer
                        } else {
                                $a = DI::app();
                                $class = self::$template_engines[$template_engine];
-                               $obj = new $class($a->getCurrentTheme(), $a->theme_info);
+                               $obj = new $class($a->getCurrentTheme(), $a->getThemeInfo());
                                self::$template_engine_instance[$template_engine] = $obj;
                                return $obj;
                        }
@@ -176,10 +174,10 @@ class Renderer
 
                $admin_message = DI::l10n()->t('template engine is not registered!');
                DI::logger()->critical($admin_message, ['template_engine' => $template_engine]);
-               $message = is_site_admin() ?
+               $message = DI::app()->isSiteAdmin() ?
                        $admin_message :
                        DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
-               throw new InternalServerErrorException($message);
+               throw new ServiceUnavailableException($message);
        }
 
        /**