]> git.mxchange.org Git - friendica.git/blob - src/Core/Renderer.php
Move delimiter props and functions
[friendica.git] / src / Core / Renderer.php
1 <?php
2 /**
3  * @file src/Core/Renderer.php
4  */
5
6 namespace Friendica\Core;
7
8 use Exception;
9 use Friendica\BaseObject;
10 use Friendica\Core\System;
11 use Friendica\Render\FriendicaSmarty;
12
13 /**
14  * @brief This class handles Renderer related functions.
15  */
16 class Renderer extends BaseObject
17 {
18     private static $ldelim = [
19                 'internal' => '',
20                 'smarty3' => '{{'
21         ];
22         private static $rdelim = [
23                 'internal' => '',
24                 'smarty3' => '}}'
25     ];
26     
27     /**
28      * @brief This is our template processor
29      *
30      * @param string|FriendicaSmarty $s The string requiring macro substitution or an instance of FriendicaSmarty
31      * @param array $r                  key value pairs (search => replace)
32      * 
33      * @return string substituted string
34     */
35     public static function replaceMacros($s, $r)
36     {
37         $stamp1 = microtime(true);
38         $a = self::getApp();
39
40         // pass $baseurl to all templates
41         $r['$baseurl'] = System::baseUrl();
42         $t = $a->getTemplateEngine();
43
44         try {
45             $output = $t->replaceMacros($s, $r);
46         } catch (Exception $e) {
47             echo "<pre><b>" . __FUNCTION__ . "</b>: " . $e->getMessage() . "</pre>";
48             killme();
49         }
50
51         $a->saveTimestamp($stamp1, "rendering");
52
53         return $output;
54     }
55
56     /**
57      * @brief Load a given template $s
58      *
59      * @param string $s     Template to load.
60      * @param string $root  Optional.
61      * 
62      * @return string template.
63      */
64     public static function getMarkupTemplate($s, $root = '')
65     {
66         $stamp1 = microtime(true);
67         $a = self::getApp();
68         $t = $a->getTemplateEngine();
69
70         try {
71             $template = $t->getTemplateFile($s, $root);
72         } catch (Exception $e) {
73             echo "<pre><b>" . __FUNCTION__ . "</b>: " . $e->getMessage() . "</pre>";
74             killme();
75         }
76
77         $a->saveTimestamp($stamp1, "file");
78
79         return $template;
80     }
81
82     /**
83          * Gets the right delimiter for a template engine
84          *
85          * Currently:
86          * Internal = ''
87          * Smarty3 = '{{'
88          *
89          * @param string $engine The template engine (default is Smarty3)
90          *
91          * @return string the right delimiter
92          */
93         public static function getTemplateLeftDelimiter($engine = 'smarty3')
94         {
95                 return self::$ldelim[$engine];
96         }
97
98         /**
99          * Gets the left delimiter for a template engine
100          *
101          * Currently:
102          * Internal = ''
103          * Smarty3 = '}}'
104          *
105          * @param string $engine The template engine (default is Smarty3)
106          *
107          * @return string the left delimiter
108          */
109         public static function getTemplateRightDelimiter($engine = 'smarty3')
110         {
111                 return self::$rdelim[$engine];
112         }
113 }