]> git.mxchange.org Git - friendica.git/blob - src/Render/FriendicaSmarty.php
wrapping up 2019.12
[friendica.git] / src / Render / FriendicaSmarty.php
1 <?php
2 /**
3  * @file src/Render/FriendicaSmarty.php
4  */
5 namespace Friendica\Render;
6
7 use Smarty;
8 use Friendica\Core\Renderer;
9
10 /**
11  * Friendica extension of the Smarty3 template engine
12  *
13  * @author Hypolite Petovan <hypolite@mrpetovan.com>
14  */
15 class FriendicaSmarty extends Smarty
16 {
17         const SMARTY3_TEMPLATE_FOLDER = 'templates';
18
19         public $filename;
20
21         function __construct()
22         {
23                 parent::__construct();
24
25                 $a = \get_app();
26                 $theme = $a->getCurrentTheme();
27
28                 // setTemplateDir can be set to an array, which Smarty will parse in order.
29                 // The order is thus very important here
30                 $template_dirs = ['theme' => "view/theme/$theme/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
31                 if (!empty($a->theme_info['extends'])) {
32                         $template_dirs = $template_dirs + ['extends' => "view/theme/" . $a->theme_info["extends"] . "/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
33                 }
34
35                 $template_dirs = $template_dirs + ['base' => "view/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
36                 $this->setTemplateDir($template_dirs);
37
38                 $this->setCompileDir('view/smarty3/compiled/');
39                 $this->setConfigDir('view/smarty3/config/');
40                 $this->setCacheDir('view/smarty3/cache/');
41
42                 $this->left_delimiter = Renderer::getTemplateLeftDelimiter('smarty3');
43                 $this->right_delimiter = Renderer::getTemplateRightDelimiter('smarty3');
44
45                 $this->escape_html = true;
46
47                 // Don't report errors so verbosely
48                 $this->error_reporting = E_ALL & ~E_NOTICE;
49         }
50
51         function parsed($template = '')
52         {
53                 if ($template) {
54                         return $this->fetch('string:' . $template);
55                 }
56                 return $this->fetch('file:' . $this->filename);
57         }
58
59 }