+class FriendicaSmartyEngine implements ITemplateEngine
+{
+ static $name = "smarty3";
+
+ public function __construct()
+ {
+ if (!is_writable('view/smarty3/')) {
+ echo "<b>ERROR:</b> folder <tt>view/smarty3/</tt> must be writable by webserver.";
+ killme();
+ }
+ }
+
+ // ITemplateEngine interface
+ public function replaceMacros($s, $r)
+ {
+ $template = '';
+ if (gettype($s) === 'string') {
+ $template = $s;
+ $s = new FriendicaSmarty();
+ }
+
+ $r['$APP'] = get_app();
+
+ // "middleware": inject variables into templates
+ $arr = array(
+ "template" => basename($s->filename),
+ "vars" => $r
+ );
+ call_hooks("template_vars", $arr);
+ $r = $arr['vars'];