3 * @file src/Render/FriendicaSmartyEngine.php
5 namespace Friendica\Render;
7 use Friendica\Core\Addon;
10 * Smarty implementation of the Friendica template engine interface
12 * @author Hypolite Petovan <hypolite@mrpetovan.com>
14 class FriendicaSmartyEngine implements ITemplateEngine
16 static $name = "smarty3";
18 public function __construct()
20 if (!is_writable('view/smarty3/')) {
21 echo "<b>ERROR:</b> folder <tt>view/smarty3/</tt> must be writable by webserver.";
26 // ITemplateEngine interface
27 public function replaceMacros($s, $r)
30 if (gettype($s) === 'string') {
32 $s = new FriendicaSmarty();
35 $r['$APP'] = \get_app();
37 // "middleware": inject variables into templates
39 "template" => basename($s->filename),
42 Addon::callHooks("template_vars", $arr);
45 foreach ($r as $key => $value) {
46 if ($key[0] === '$') {
47 $key = substr($key, 1);
50 $s->assign($key, $value);
52 return $s->parsed($template);
55 public function getTemplateFile($file, $root = '')
58 $template = new FriendicaSmarty();
60 // Make sure $root ends with a slash /
61 if ($root !== '' && substr($root, -1, 1) !== '/') {
65 $theme = $a->getCurrentTheme();
66 $filename = $template::SMARTY3_TEMPLATE_FOLDER . '/' . $file;
68 if (file_exists("{$root}view/theme/$theme/$filename")) {
69 $template_file = "{$root}view/theme/$theme/$filename";
70 } elseif (!empty($a->theme_info['extends']) && file_exists(sprintf('%sview/theme/%s}/%s', $root, $a->theme_info['extends'], $filename))) {
71 $template_file = sprintf('%sview/theme/%s}/%s', $root, $a->theme_info['extends'], $filename);
72 } elseif (file_exists("{$root}/$filename")) {
73 $template_file = "{$root}/$filename";
75 $template_file = "{$root}view/$filename";
78 $template->filename = $template_file;