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