]> git.mxchange.org Git - friendica.git/blob - src/Render/FriendicaSmartyEngine.php
2cfce760adc2cba53c6e62950638f61097e5208c
[friendica.git] / src / Render / FriendicaSmartyEngine.php
1 <?php\r
2 /**\r
3  * @file src/Render/FriendicaSmartyEngine.php\r
4  */\r
5 namespace Friendica\Render;\r
6 \r
7 use Friendica\Core\Addon;\r
8 \r
9 class FriendicaSmartyEngine implements ITemplateEngine\r
10 {\r
11         static $name = "smarty3";\r
12 \r
13         public function __construct()\r
14         {\r
15                 if (!is_writable('view/smarty3/')) {\r
16                         echo "<b>ERROR:</b> folder <tt>view/smarty3/</tt> must be writable by webserver.";\r
17                         killme();\r
18                 }\r
19         }\r
20 \r
21         // ITemplateEngine interface\r
22         public function replaceMacros($s, $r)\r
23         {\r
24                 $template = '';\r
25                 if (gettype($s) === 'string') {\r
26                         $template = $s;\r
27                         $s = new FriendicaSmarty();\r
28                 }\r
29 \r
30                 $r['$APP'] = get_app();\r
31 \r
32                 // "middleware": inject variables into templates\r
33                 $arr = [\r
34                         "template" => basename($s->filename),\r
35                         "vars" => $r\r
36                 ];\r
37                 Addon::callHooks("template_vars", $arr);\r
38                 $r = $arr['vars'];\r
39 \r
40                 foreach ($r as $key => $value) {\r
41                         if ($key[0] === '$') {\r
42                                 $key = substr($key, 1);\r
43                         }\r
44 \r
45                         $s->assign($key, $value);\r
46                 }\r
47                 return $s->parsed($template);\r
48         }\r
49 \r
50         public function getTemplateFile($file, $root = '')\r
51         {\r
52                 $a = get_app();\r
53                 $template_file = get_template_file($a, SMARTY3_TEMPLATE_FOLDER . '/' . $file, $root);\r
54                 $template = new FriendicaSmarty();\r
55                 $template->filename = $template_file;\r
56 \r
57                 return $template;\r
58         }\r
59 }\r