X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FRender%2FFriendicaSmartyEngine.php;h=1053ab08e064b2121191fee4a39e327f69612334;hb=78a7e130ae7f5e5bca1fa51a49000ae3ef7a16f5;hp=2cfce760adc2cba53c6e62950638f61097e5208c;hpb=e805350ce465b9ff311698767f4bfab4a0080916;p=friendica.git
diff --git a/src/Render/FriendicaSmartyEngine.php b/src/Render/FriendicaSmartyEngine.php
index 2cfce760ad..1053ab08e0 100644
--- a/src/Render/FriendicaSmartyEngine.php
+++ b/src/Render/FriendicaSmartyEngine.php
@@ -1,59 +1,82 @@
-ERROR: folder view/smarty3/ 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 = [
- "template" => basename($s->filename),
- "vars" => $r
- ];
- Addon::callHooks("template_vars", $arr);
- $r = $arr['vars'];
-
- foreach ($r as $key => $value) {
- if ($key[0] === '$') {
- $key = substr($key, 1);
- }
-
- $s->assign($key, $value);
- }
- return $s->parsed($template);
- }
-
- public function getTemplateFile($file, $root = '')
- {
- $a = get_app();
- $template_file = get_template_file($a, SMARTY3_TEMPLATE_FOLDER . '/' . $file, $root);
- $template = new FriendicaSmarty();
- $template->filename = $template_file;
-
- return $template;
- }
-}
+
+ */
+class FriendicaSmartyEngine implements ITemplateEngine
+{
+ static $name = "smarty3";
+
+ public function __construct()
+ {
+ if (!is_writable('view/smarty3/')) {
+ echo "ERROR: folder view/smarty3/ 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 = [
+ "template" => basename($s->filename),
+ "vars" => $r
+ ];
+ Addon::callHooks("template_vars", $arr);
+ $r = $arr['vars'];
+
+ foreach ($r as $key => $value) {
+ if ($key[0] === '$') {
+ $key = substr($key, 1);
+ }
+
+ $s->assign($key, $value);
+ }
+ return $s->parsed($template);
+ }
+
+ public function getTemplateFile($file, $root = '')
+ {
+ $a = get_app();
+ $template = new FriendicaSmarty();
+
+ // Make sure $root ends with a slash /
+ if ($root !== '' && substr($root, -1, 1) !== '/') {
+ $root = $root . '/';
+ }
+
+ $theme = $a->getCurrentTheme();
+ $filename = $template::SMARTY3_TEMPLATE_FOLDER . '/' . $file;
+
+ if (file_exists("{$root}view/theme/$theme/$filename")) {
+ $template_file = "{$root}view/theme/$theme/$filename";
+ } elseif (x($a->theme_info, 'extends') && file_exists(sprintf('%sview/theme/%s}/%s', $root, $a->theme_info['extends'], $filename))) {
+ $template_file = sprintf('%sview/theme/%s}/%s', $root, $a->theme_info['extends'], $filename);
+ } elseif (file_exists("{$root}/$filename")) {
+ $template_file = "{$root}/$filename";
+ } else {
+ $template_file = "{$root}view/$filename";
+ }
+
+ $template->filename = $template_file;
+
+ return $template;
+ }
+}