]> git.mxchange.org Git - friendica.git/blob - src/Render/FriendicaSmarty.php
e544a76d1bd4fb562fbf8a82f27798bd3bd09b07
[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 (x($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                 // Don't report errors so verbosely
46                 $this->error_reporting = E_ALL & ~E_NOTICE;
47         }
48
49         function parsed($template = '')
50         {
51                 if ($template) {
52                         return $this->fetch('string:' . $template);
53                 }
54                 return $this->fetch('file:' . $this->filename);
55         }
56
57 }