]> git.mxchange.org Git - friendica.git/blob - src/Render/FriendicaSmarty.php
Merge pull request #5109 from rabuzarus/20180522_-_frio_nav_about_instance
[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
9 /**
10  * Friendica extension of the Smarty3 template engine
11  *
12  * @author Hypolite Petovan <mrpetovan@gmail.com>
13  */
14 class FriendicaSmarty extends Smarty
15 {
16         const SMARTY3_TEMPLATE_FOLDER = 'templates';
17
18         public $filename;
19
20         function __construct()
21         {
22                 parent::__construct();
23
24                 $a = get_app();
25                 $theme = $a->getCurrentTheme();
26
27                 // setTemplateDir can be set to an array, which Smarty will parse in order.
28                 // The order is thus very important here
29                 $template_dirs = ['theme' => "view/theme/$theme/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
30                 if (x($a->theme_info, "extends")) {
31                         $template_dirs = $template_dirs + ['extends' => "view/theme/" . $a->theme_info["extends"] . "/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
32                 }
33
34                 $template_dirs = $template_dirs + ['base' => "view/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
35                 $this->setTemplateDir($template_dirs);
36
37                 $this->setCompileDir('view/smarty3/compiled/');
38                 $this->setConfigDir('view/smarty3/config/');
39                 $this->setCacheDir('view/smarty3/cache/');
40
41                 $this->left_delimiter = $a->get_template_ldelim('smarty3');
42                 $this->right_delimiter = $a->get_template_rdelim('smarty3');
43
44                 // Don't report errors so verbosely
45                 $this->error_reporting = E_ALL & ~E_NOTICE;
46         }
47
48         function parsed($template = '')
49         {
50                 if ($template) {
51                         return $this->fetch('string:' . $template);
52                 }
53                 return $this->fetch('file:' . $this->filename);
54         }
55
56 }