Merge pull request #4386 from MrPetovan/task/3878-move-friendica_smarty-to-src
Move SMARTY3_TEMPLATE_FOLDER to FriendicaSmarty
This commit is contained in:
commit
e5a5a7dc7b
|
@ -615,36 +615,6 @@ function get_markup_template($s, $root = '') {
|
|||
return $template;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param App $a
|
||||
* @param string $filename
|
||||
* @param string $root
|
||||
* @return string
|
||||
*/
|
||||
function get_template_file($a, $filename, $root = '') {
|
||||
$theme = current_theme();
|
||||
|
||||
// Make sure $root ends with a slash /
|
||||
if ($root !== '' && substr($root, -1, 1) !== '/') {
|
||||
$root = $root . '/';
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
return $template_file;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* for html,xml parsing - let's say you've got
|
||||
* an attribute foobar="class1 class2 class3"
|
||||
|
|
|
@ -6,15 +6,15 @@ namespace Friendica\Render;
|
|||
|
||||
use Smarty;
|
||||
|
||||
define('SMARTY3_TEMPLATE_FOLDER', 'templates');
|
||||
|
||||
/**
|
||||
* Description of FriendicaSmarty
|
||||
* Friendica extension of the Smarty3 template engine
|
||||
*
|
||||
* @author benlo
|
||||
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||
*/
|
||||
class FriendicaSmarty extends Smarty
|
||||
{
|
||||
const SMARTY3_TEMPLATE_FOLDER = 'templates';
|
||||
|
||||
public $filename;
|
||||
|
||||
function __construct()
|
||||
|
@ -26,12 +26,12 @@ class FriendicaSmarty extends Smarty
|
|||
|
||||
// setTemplateDir can be set to an array, which Smarty will parse in order.
|
||||
// The order is thus very important here
|
||||
$template_dirs = ['theme' => "view/theme/$theme/" . SMARTY3_TEMPLATE_FOLDER . "/"];
|
||||
$template_dirs = ['theme' => "view/theme/$theme/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
|
||||
if (x($a->theme_info, "extends")) {
|
||||
$template_dirs = $template_dirs + ['extends' => "view/theme/" . $a->theme_info["extends"] . "/" . SMARTY3_TEMPLATE_FOLDER . "/"];
|
||||
$template_dirs = $template_dirs + ['extends' => "view/theme/" . $a->theme_info["extends"] . "/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
|
||||
}
|
||||
|
||||
$template_dirs = $template_dirs + ['base' => "view/" . SMARTY3_TEMPLATE_FOLDER . "/"];
|
||||
$template_dirs = $template_dirs + ['base' => "view/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
|
||||
$this->setTemplateDir($template_dirs);
|
||||
|
||||
$this->setCompileDir('view/smarty3/compiled/');
|
||||
|
|
|
@ -6,8 +6,11 @@ namespace Friendica\Render;
|
|||
|
||||
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";
|
||||
|
@ -52,8 +55,26 @@ class FriendicaSmartyEngine implements ITemplateEngine
|
|||
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;
|
||||
|
|
Loading…
Reference in a new issue