<?php
/**
- * @file src/Render/FriendicaSmartyEngine.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
*/
+
namespace Friendica\Render;
-use Friendica\Core\Addon;
+use Friendica\Core\Hook;
+use Friendica\DI;
/**
* Smarty implementation of the Friendica template engine interface
- *
- * @author Hypolite Petovan <mrpetovan@gmail.com>
*/
class FriendicaSmartyEngine implements ITemplateEngine
{
public function __construct()
{
- if (!is_writable('view/smarty3/')) {
+ if (!is_writable(__DIR__ . '/../../view/smarty3/')) {
echo "<b>ERROR:</b> folder <tt>view/smarty3/</tt> must be writable by webserver.";
- killme();
+ exit();
}
}
$s = new FriendicaSmarty();
}
- $r['$APP'] = get_app();
+ $r['$APP'] = DI::app();
// "middleware": inject variables into templates
$arr = [
"template" => basename($s->filename),
"vars" => $r
];
- Addon::callHooks("template_vars", $arr);
+ Hook::callAll("template_vars", $arr);
$r = $arr['vars'];
foreach ($r as $key => $value) {
return $s->parsed($template);
}
- public function getTemplateFile($file, $root = '')
+ public function getTemplateFile($file, $subDir = '')
{
- $a = get_app();
+ $a = DI::app();
$template = new FriendicaSmarty();
// Make sure $root ends with a slash /
- if ($root !== '' && substr($root, -1, 1) !== '/') {
- $root = $root . '/';
+ if ($subDir !== '' && substr($subDir, -1, 1) !== '/') {
+ $subDir = $subDir . '/';
}
+ $root = DI::basePath() . '/' . $subDir;
+
$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))) {
+ } elseif (!empty($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";