]> git.mxchange.org Git - friendica.git/commitdiff
Template Engine and props to Renderer
authorAdam Magness <adam.magness@gmail.com>
Wed, 31 Oct 2018 17:25:38 +0000 (13:25 -0400)
committerAdam Magness <adam.magness@gmail.com>
Wed, 31 Oct 2018 17:25:38 +0000 (13:25 -0400)
move methods and props from App to Renderer

mod/admin.php
src/App.php
src/Core/Renderer.php
src/Model/Profile.php
src/Module/Install.php
view/theme/duepuntozero/theme.php
view/theme/frio/theme.php
view/theme/smoothly/theme.php
view/theme/vier/theme.php

index ff37c8b611c9cca487ebe39e7b61c580b79f6a4a..5604cd5aa387da0fd122aec4f1c4fc40f144acbd 100644 (file)
@@ -91,7 +91,7 @@ function admin_post(App $a)
 
                                $theme = $a->argv[2];
                                if (is_file("view/theme/$theme/config.php")) {
-                                       $orig_theme = $a->theme;
+                                       $orig_theme = Renderer::$theme;
                                        $orig_page = $a->page;
                                        $orig_session_theme = $_SESSION['theme'];
                                        require_once "view/theme/$theme/theme.php";
@@ -107,7 +107,7 @@ function admin_post(App $a)
                                        }
 
                                        $_SESSION['theme'] = $orig_session_theme;
-                                       $a->theme = $orig_theme;
+                                       Renderer::$theme = $orig_theme;
                                        $a->page = $orig_page;
                                }
 
@@ -2271,7 +2271,7 @@ function admin_page_themes(App $a)
 
                $admin_form = '';
                if (is_file("view/theme/$theme/config.php")) {
-                       $orig_theme = $a->theme;
+                       $orig_theme = Renderer::$theme;
                        $orig_page = $a->page;
                        $orig_session_theme = $_SESSION['theme'];
                        require_once "view/theme/$theme/theme.php";
@@ -2288,7 +2288,7 @@ function admin_page_themes(App $a)
                        }
 
                        $_SESSION['theme'] = $orig_session_theme;
-                       $a->theme = $orig_theme;
+                       Renderer::$theme = $orig_theme;
                        $a->page = $orig_page;
                }
 
index deb15f702c5dbc98713c34ab523bc7ad622bdf3b..3cfcc67186d44fb7bb4571cd9ac97e9c42eeab24 100644 (file)
@@ -136,30 +136,6 @@ class App
                $this->footerScripts[] = trim($url, '/');
        }
 
-       /**
-        * @brief An array for all theme-controllable parameters
-        *
-        * Mostly unimplemented yet. Only options 'template_engine' and
-        * beyond are used.
-        */
-       public $theme = [
-               'sourcename' => '',
-               'videowidth' => 425,
-               'videoheight' => 350,
-               'force_max_items' => 0,
-               'stylesheet' => '',
-               'template_engine' => 'smarty3',
-       ];
-
-       /**
-        * @brief An array of registered template engines ('name'=>'class name')
-        */
-       public $template_engines = [];
-
-       /**
-        * @brief An array of instanced template engines ('name'=>'instance')
-        */
-       public $template_engine_instance = [];
        public $process_id;
        public $queue;
        private $scheme;
@@ -301,7 +277,7 @@ class App
                $this->isAjax = strtolower(defaults($_SERVER, 'HTTP_X_REQUESTED_WITH', '')) == 'xmlhttprequest';
 
                // Register template engines
-               $this->registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine');
+               Core\Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine');
        }
 
        /**
@@ -744,8 +720,8 @@ class App
                        $this->page['title'] = $this->config['sitename'];
                }
 
-               if (!empty($this->theme['stylesheet'])) {
-                       $stylesheet = $this->theme['stylesheet'];
+               if (!empty(Core\Renderer::$theme['stylesheet'])) {
+                       $stylesheet = Core\Renderer::$theme['stylesheet'];
                } else {
                        $stylesheet = $this->getCurrentThemeStylesheetPath();
                }
@@ -852,70 +828,6 @@ class App
                }
        }
 
-       /**
-        * @brief Register template engine class
-        *
-        * @param string $class
-        */
-       private function registerTemplateEngine($class)
-       {
-               $v = get_class_vars($class);
-               if (!empty($v['name'])) {
-                       $name = $v['name'];
-                       $this->template_engines[$name] = $class;
-               } else {
-                       echo "template engine <tt>$class</tt> cannot be registered without a name.\n";
-                       die();
-               }
-       }
-
-       /**
-        * @brief Return template engine instance.
-        *
-        * If $name is not defined, return engine defined by theme,
-        * or default
-        *
-        * @return object Template Engine instance
-        */
-       public function getTemplateEngine()
-       {
-               $template_engine = defaults($this->theme, 'template_engine', 'smarty3');
-
-               if (isset($this->template_engines[$template_engine])) {
-                       if (isset($this->template_engine_instance[$template_engine])) {
-                               return $this->template_engine_instance[$template_engine];
-                       } else {
-                               $class = $this->template_engines[$template_engine];
-                               $obj = new $class;
-                               $this->template_engine_instance[$template_engine] = $obj;
-                               return $obj;
-                       }
-               }
-
-               echo "template engine <tt>$template_engine</tt> is not registered!\n";
-               exit();
-       }
-
-       /**
-        * @brief Returns the active template engine.
-        *
-        * @return string the active template engine
-        */
-       public function getActiveTemplateEngine()
-       {
-               return $this->theme['template_engine'];
-       }
-
-       /**
-        * sets the active template engine
-        *
-        * @param string $engine the template engine (default is Smarty3)
-        */
-       public function setActiveTemplateEngine($engine = 'smarty3')
-       {
-               $this->theme['template_engine'] = $engine;
-       }
-
        /**
         * Saves a timestamp for a value - f.e. a call
         * Necessary for profiling Friendica
index 378652fe26b65942ee4c47ee413cfabd3d41245b..44b56fcba373afda90354e624efb2740db7070db 100644 (file)
@@ -15,6 +15,31 @@ use Friendica\Render\FriendicaSmarty;
  */
 class Renderer extends BaseObject
 {
+    /**
+        * @brief An array of registered template engines ('name'=>'class name')
+        */
+    public static $template_engines = [];
+
+    /**
+        * @brief An array of instanced template engines ('name'=>'instance')
+        */
+       public static $template_engine_instance = [];
+
+    /**
+        * @brief An array for all theme-controllable parameters
+        *
+        * Mostly unimplemented yet. Only options 'template_engine' and
+        * beyond are used.
+        */
+       public static $theme = [
+               'sourcename' => '',
+               'videowidth' => 425,
+               'videoheight' => 350,
+               'force_max_items' => 0,
+               'stylesheet' => '',
+               'template_engine' => 'smarty3',
+       ];
+    
     private static $ldelim = [
                'internal' => '',
                'smarty3' => '{{'
@@ -39,7 +64,7 @@ class Renderer extends BaseObject
 
         // pass $baseurl to all templates
         $r['$baseurl'] = System::baseUrl();
-        $t = $a->getTemplateEngine();
+        $t = self::getTemplateEngine();
 
         try {
             $output = $t->replaceMacros($s, $r);
@@ -65,7 +90,7 @@ class Renderer extends BaseObject
     {
         $stamp1 = microtime(true);
         $a = self::getApp();
-        $t = $a->getTemplateEngine();
+        $t = self::getTemplateEngine();
 
         try {
             $template = $t->getTemplateFile($s, $root);
@@ -79,6 +104,72 @@ class Renderer extends BaseObject
         return $template;
     }
 
+    /**
+        * @brief Register template engine class
+        *
+        * @param string $class
+        */
+       public static function registerTemplateEngine($class)
+       {
+        $v = get_class_vars($class);
+        
+        if (!empty($v['name']))
+        {
+                       $name = $v['name'];
+                       self::$template_engines[$name] = $class;
+               } else {
+                       echo "template engine <tt>$class</tt> cannot be registered without a name.\n";
+                       die();
+               }
+       }
+
+       /**
+        * @brief Return template engine instance.
+        *
+        * If $name is not defined, return engine defined by theme,
+        * or default
+        *
+        * @return object Template Engine instance
+        */
+       public static function getTemplateEngine()
+       {
+               $template_engine = defaults(self::$theme, 'template_engine', 'smarty3');
+
+               if (isset(self::$template_engines[$template_engine])) {
+                       if (isset(self::$template_engine_instance[$template_engine])) {
+                               return self::$template_engine_instance[$template_engine];
+                       } else {
+                               $class = self::$template_engines[$template_engine];
+                               $obj = new $class;
+                               self::$template_engine_instance[$template_engine] = $obj;
+                               return $obj;
+                       }
+               }
+
+               echo "template engine <tt>$template_engine</tt> is not registered!\n";
+               exit();
+    }
+    
+    /**
+        * @brief Returns the active template engine.
+        *
+        * @return string the active template engine
+        */
+       public static function getActiveTemplateEngine()
+       {
+               return self::$theme['template_engine'];
+       }
+
+       /**
+        * sets the active template engine
+        *
+        * @param string $engine the template engine (default is Smarty3)
+        */
+       public static function setActiveTemplateEngine($engine = 'smarty3')
+       {
+               self::$theme['template_engine'] = $engine;
+       }
+
     /**
         * Gets the right delimiter for a template engine
         *
index a98cb30d87ed68f59d562c9aea90022206427fa2..2cd3f7a86c67b46bbaf17c4583e196dabd1b8e94 100644 (file)
@@ -164,7 +164,7 @@ class Profile
                * load/reload current theme info
                */
 
-               $a->setActiveTemplateEngine(); // reset the template engine to the default in case the user's theme doesn't specify one
+               Renderer::setActiveTemplateEngine(); // reset the template engine to the default in case the user's theme doesn't specify one
 
                $theme_info_file = 'view/theme/' . $a->getCurrentTheme() . '/theme.php';
                if (file_exists($theme_info_file)) {
index b6b7027cb1b96a85e90ab10ab16710a882600ec4..09de23c080acb399b0a43fcd7f5e48e386408f8e 100644 (file)
@@ -53,7 +53,7 @@ class Install extends BaseModule
 
                // We overwrite current theme css, because during install we may not have a working mod_rewrite
                // so we may not have a css at all. Here we set a static css file for the install procedure pages
-               $a->theme['stylesheet'] = $a->getBaseURL() . '/view/install/style.css';
+               Renderer::$theme['stylesheet'] = $a->getBaseURL() . '/view/install/style.css';
 
                self::$installer = new Core\Installer();
                self::$currentWizardStep = defaults($_POST, 'pass', self::SYSTEM_CHECK);
index 588a6fa463468281fd4e51777c5f0be722e64335..015e8090fc7c655dc182590c7e0ef0028988f632 100644 (file)
@@ -3,10 +3,11 @@
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
 
 function duepuntozero_init(App $a) {
 
-$a->setActiveTemplateEngine('smarty3');
+Renderer::setActiveTemplateEngine('smarty3');
 
     $colorset = PConfig::get( local_user(), 'duepuntozero','colorset');
     if (!$colorset)
index 8cb4c342959293e754167d61563b932414bdfc59..c7d38baeb970edae0b865533fe8cae449d52e2a3 100644 (file)
@@ -15,6 +15,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model;
@@ -30,7 +31,7 @@ function frio_init(App $a)
        $a->theme_events_in_profile = false;
        $a->videowidth = 622;
 
-       $a->setActiveTemplateEngine('smarty3');
+       Renderer::setActiveTemplateEngine('smarty3');
 
        $baseurl = System::baseUrl();
 
index 727650ef23efa77e18e670889ab3b4e83c54322c..6168932e95242fc20548cc39a6862f08e9f11f03 100644 (file)
@@ -15,7 +15,7 @@ use Friendica\Core\Renderer;
 use Friendica\Core\System;
 
 function smoothly_init(App $a) {
-       $a->setActiveTemplateEngine('smarty3');
+       Renderer::setActiveTemplateEngine('smarty3');
 
        $cssFile = null;
        $ssl_state = null;
index 457816b24e012c30fb0573a925d879a83c0bbf69..fb4f66431b1bbb6470682edb48261ecca2dd70fa 100644 (file)
@@ -26,7 +26,7 @@ function vier_init(App $a)
 {
        $a->theme_events_in_profile = false;
 
-       $a->setActiveTemplateEngine('smarty3');
+       Renderer::setActiveTemplateEngine('smarty3');
 
        if (!empty($a->argv[0]) && $a->argv[0] . defaults($a->argv, 1, '') === "profile".$a->user['nickname'] || $a->argv[0] === "network" && local_user()) {
                vier_community_info();