3 * @file src/Render/FriendicaSmartyEngine.php
5 namespace Friendica\Render;
7 use Friendica\Core\Hook;
11 * Smarty implementation of the Friendica template engine interface
13 * @author Hypolite Petovan <hypolite@mrpetovan.com>
15 class FriendicaSmartyEngine implements ITemplateEngine
17 static $name = "smarty3";
19 public function __construct()
21 if (!is_writable(__DIR__ . '/../../view/smarty3/')) {
22 echo "<b>ERROR:</b> folder <tt>view/smarty3/</tt> must be writable by webserver.";
27 // ITemplateEngine interface
28 public function replaceMacros($s, $r)
31 if (gettype($s) === 'string') {
33 $s = new FriendicaSmarty();
36 $r['$APP'] = DI::app();
38 // "middleware": inject variables into templates
40 "template" => basename($s->filename),
43 Hook::callAll("template_vars", $arr);
46 foreach ($r as $key => $value) {
47 if ($key[0] === '$') {
48 $key = substr($key, 1);
51 $s->assign($key, $value);
53 return $s->parsed($template);
56 public function getTemplateFile($file, $root = '')
59 $template = new FriendicaSmarty();
61 // Make sure $root ends with a slash /
62 if ($root !== '' && substr($root, -1, 1) !== '/') {
66 $theme = $a->getCurrentTheme();
67 $filename = $template::SMARTY3_TEMPLATE_FOLDER . '/' . $file;
69 if (file_exists("{$root}view/theme/$theme/$filename")) {
70 $template_file = "{$root}view/theme/$theme/$filename";
71 } elseif (!empty($a->theme_info['extends']) && file_exists(sprintf('%sview/theme/%s}/%s', $root, $a->theme_info['extends'], $filename))) {
72 $template_file = sprintf('%sview/theme/%s}/%s', $root, $a->theme_info['extends'], $filename);
73 } elseif (file_exists("{$root}/$filename")) {
74 $template_file = "{$root}/$filename";
76 $template_file = "{$root}view/$filename";
79 $template->filename = $template_file;