3 use Friendica\Render\ITemplateEngine;
5 require_once("library/Smarty/libs/Smarty.class.php");
6 require_once "include/plugin.php";
8 define('SMARTY3_TEMPLATE_FOLDER','templates');
10 class FriendicaSmarty extends Smarty {
13 function __construct() {
14 parent::__construct();
17 $theme = current_theme();
19 // setTemplateDir can be set to an array, which Smarty will parse in order.
20 // The order is thus very important here
21 $template_dirs = array('theme' => "view/theme/$theme/".SMARTY3_TEMPLATE_FOLDER."/");
22 if ( x($a->theme_info,"extends") )
23 $template_dirs = $template_dirs + array('extends' => "view/theme/".$a->theme_info["extends"]."/".SMARTY3_TEMPLATE_FOLDER."/");
24 $template_dirs = $template_dirs + array('base' => "view/".SMARTY3_TEMPLATE_FOLDER."/");
25 $this->setTemplateDir($template_dirs);
27 $this->setCompileDir('view/smarty3/compiled/');
28 $this->setConfigDir('view/smarty3/config/');
29 $this->setCacheDir('view/smarty3/cache/');
31 $this->left_delimiter = $a->get_template_ldelim('smarty3');
32 $this->right_delimiter = $a->get_template_rdelim('smarty3');
34 // Don't report errors so verbosely
35 $this->error_reporting = E_ALL & ~E_NOTICE;
38 function parsed($template = '') {
40 return $this->fetch('string:' . $template);
42 return $this->fetch('file:' . $this->filename);
48 class FriendicaSmartyEngine implements ITemplateEngine {
49 static $name ="smarty3";
51 public function __construct(){
52 if (!is_writable('view/smarty3/')){
53 echo "<b>ERROR:</b> folder <tt>view/smarty3/</tt> must be writable by webserver."; killme();
57 // ITemplateEngine interface
58 public function replaceMacros($s, $r) {
60 if (gettype($s) === 'string') {
62 $s = new FriendicaSmarty();
65 $r['$APP'] = get_app();
67 // "middleware": inject variables into templates
69 "template"=> basename($s->filename),
72 call_hooks("template_vars", $arr);
75 foreach ($r as $key=>$value) {
76 if ($key[0] === '$') {
77 $key = substr($key, 1);
79 $s->assign($key, $value);
81 return $s->parsed($template);
84 public function getTemplateFile($file, $root=''){
86 $template_file = get_template_file($a, SMARTY3_TEMPLATE_FOLDER.'/'.$file, $root);
87 $template = new FriendicaSmarty();
88 $template->filename = $template_file;