3 require_once "object/TemplateEngine.php";
4 require_once("library/Smarty/libs/Smarty.class.php");
6 class FriendicaSmarty extends Smarty {
9 function __construct() {
10 parent::__construct();
13 $theme = current_theme();
15 // setTemplateDir can be set to an array, which Smarty will parse in order.
16 // The order is thus very important here
17 $template_dirs = array('theme' => "view/theme/$theme/smarty3/");
18 if( x($a->theme_info,"extends") )
19 $template_dirs = $template_dirs + array('extends' => "view/theme/".$a->theme_info["extends"]."/smarty3/");
20 $template_dirs = $template_dirs + array('base' => 'view/smarty3/');
21 $this->setTemplateDir($template_dirs);
23 $this->setCompileDir('view/smarty3/compiled/');
24 $this->setConfigDir('view/smarty3/config/');
25 $this->setCacheDir('view/smarty3/cache/');
27 $this->left_delimiter = $a->get_template_ldelim('smarty3');
28 $this->right_delimiter = $a->get_template_rdelim('smarty3');
30 // Don't report errors so verbosely
31 $this->error_reporting = E_ALL & ~E_NOTICE;
34 function parsed($template = '') {
36 return $this->fetch('string:' . $template);
38 return $this->fetch('file:' . $this->filename);
44 class FriendicaSmartyEngine implements ITemplateEngine {
45 static $name ="smarty3";
46 // ITemplateEngine interface
47 public function replace_macros($s, $r) {
49 if(gettype($s) === 'string') {
51 $s = new FriendicaSmarty();
53 foreach($r as $key=>$value) {
55 $key = substr($key, 1);
57 $s->assign($key, $value);
59 return $s->parsed($template);
62 public function get_template_file($file, $root=''){
64 $template_file = get_template_file($a, 'smarty3/' . $file, $root);
65 $template = new FriendicaSmarty();
66 $template->filename = $template_file;