use Friendica\Core\Addon;
-define('SMARTY3_TEMPLATE_FOLDER', 'templates');
-
+/**
+ * Smarty implementation of the Friendica template engine interface
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ */
class FriendicaSmartyEngine implements ITemplateEngine
{
static $name = "smarty3";
public function getTemplateFile($file, $root = '')
{
$a = get_app();
- $template_file = get_template_file($a, SMARTY3_TEMPLATE_FOLDER . '/' . $file, $root);
$template = new FriendicaSmarty();
+
+ // Make sure $root ends with a slash /
+ if ($root !== '' && substr($root, -1, 1) !== '/') {
+ $root = $root . '/';
+ }
+
+ $theme = current_theme();
+ $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;