3 require_once "object/TemplateEngine.php";
4 require_once("library/Smarty/libs/Smarty.class.php");
5 require_once "include/plugin.php";
7 define('SMARTY3_TEMPLATE_FOLDER','templates');
9 class FriendicaSmarty extends Smarty {
12 function __construct() {
13 parent::__construct();
16 $theme = current_theme();
18 // setTemplateDir can be set to an array, which Smarty will parse in order.
19 // The order is thus very important here
20 $template_dirs = array('theme' => "view/theme/$theme/".SMARTY3_TEMPLATE_FOLDER."/");
21 if( x($a->theme_info,"extends") )
22 $template_dirs = $template_dirs + array('extends' => "view/theme/".$a->theme_info["extends"]."/".SMARTY3_TEMPLATE_FOLDER."/");
23 $template_dirs = $template_dirs + array('base' => "view/".SMARTY3_TEMPLATE_FOLDER."/");
24 $this->setTemplateDir($template_dirs);
26 $this->setCompileDir('view/smarty3/compiled/');
27 $this->setConfigDir('view/smarty3/config/');
28 $this->setCacheDir('view/smarty3/cache/');
30 $this->left_delimiter = $a->get_template_ldelim('smarty3');
31 $this->right_delimiter = $a->get_template_rdelim('smarty3');
33 // Don't report errors so verbosely
34 $this->error_reporting = E_ALL & ~E_NOTICE;
37 function parsed($template = '') {
39 return $this->fetch('string:' . $template);
41 return $this->fetch('file:' . $this->filename);
47 class FriendicaSmartyEngine implements ITemplateEngine {
48 static $name ="smarty3";
50 public function __construct(){
51 if(!is_writable('view/smarty3/')){
52 echo "<b>ERROR:</b> folder <tt>view/smarty3/</tt> must be writable by webserver."; killme();
56 // ITemplateEngine interface
57 public function replace_macros($s, $r) {
59 if(gettype($s) === 'string') {
61 $s = new FriendicaSmarty();
64 $r['$APP'] = get_app();
66 // "middleware": inject variables into templates
68 "template"=> basename($s->filename),
71 call_hooks("template_vars", $arr);
74 foreach($r as $key=>$value) {
76 $key = substr($key, 1);
78 $s->assign($key, $value);
80 return $s->parsed($template);
83 public function get_template_file($file, $root=''){
85 $template_file = get_template_file($a, SMARTY3_TEMPLATE_FOLDER.'/'.$file, $root);
86 $template = new FriendicaSmarty();
87 $template->filename = $template_file;