\r
use Smarty;\r
\r
-define('SMARTY3_TEMPLATE_FOLDER', 'templates');\r
-\r
/**\r
- * Description of FriendicaSmarty\r
+ * Friendica extension of the Smarty3 template engine\r
*\r
- * @author benlo\r
+ * @author Hypolite Petovan <mrpetovan@gmail.com>\r
*/\r
class FriendicaSmarty extends Smarty\r
{\r
+ const SMARTY3_TEMPLATE_FOLDER = 'templates';\r
+\r
public $filename;\r
\r
function __construct()\r
\r
// setTemplateDir can be set to an array, which Smarty will parse in order.\r
// The order is thus very important here\r
- $template_dirs = ['theme' => "view/theme/$theme/" . SMARTY3_TEMPLATE_FOLDER . "/"];\r
+ $template_dirs = ['theme' => "view/theme/$theme/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];\r
if (x($a->theme_info, "extends")) {\r
- $template_dirs = $template_dirs + ['extends' => "view/theme/" . $a->theme_info["extends"] . "/" . SMARTY3_TEMPLATE_FOLDER . "/"];\r
+ $template_dirs = $template_dirs + ['extends' => "view/theme/" . $a->theme_info["extends"] . "/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];\r
}\r
\r
- $template_dirs = $template_dirs + ['base' => "view/" . SMARTY3_TEMPLATE_FOLDER . "/"];\r
+ $template_dirs = $template_dirs + ['base' => "view/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];\r
$this->setTemplateDir($template_dirs);\r
\r
$this->setCompileDir('view/smarty3/compiled/');\r
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;