Merge pull request #4385 from tobiasd/20180203-smarties

added missing constant
This commit is contained in:
Michael Vogel 2018-02-03 13:38:55 +01:00 committed by GitHub
commit 2a00ac790f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,59 +1,61 @@
<?php <?php
/** /**
* @file src/Render/FriendicaSmartyEngine.php * @file src/Render/FriendicaSmartyEngine.php
*/ */
namespace Friendica\Render; namespace Friendica\Render;
use Friendica\Core\Addon; use Friendica\Core\Addon;
class FriendicaSmartyEngine implements ITemplateEngine define('SMARTY3_TEMPLATE_FOLDER', 'templates');
{
static $name = "smarty3"; class FriendicaSmartyEngine implements ITemplateEngine
{
public function __construct() static $name = "smarty3";
{
if (!is_writable('view/smarty3/')) { public function __construct()
echo "<b>ERROR:</b> folder <tt>view/smarty3/</tt> must be writable by webserver."; {
killme(); if (!is_writable('view/smarty3/')) {
} echo "<b>ERROR:</b> folder <tt>view/smarty3/</tt> must be writable by webserver.";
} killme();
}
// ITemplateEngine interface }
public function replaceMacros($s, $r)
{ // ITemplateEngine interface
$template = ''; public function replaceMacros($s, $r)
if (gettype($s) === 'string') { {
$template = $s; $template = '';
$s = new FriendicaSmarty(); if (gettype($s) === 'string') {
} $template = $s;
$s = new FriendicaSmarty();
$r['$APP'] = get_app(); }
// "middleware": inject variables into templates $r['$APP'] = get_app();
$arr = [
"template" => basename($s->filename), // "middleware": inject variables into templates
"vars" => $r $arr = [
]; "template" => basename($s->filename),
Addon::callHooks("template_vars", $arr); "vars" => $r
$r = $arr['vars']; ];
Addon::callHooks("template_vars", $arr);
foreach ($r as $key => $value) { $r = $arr['vars'];
if ($key[0] === '$') {
$key = substr($key, 1); foreach ($r as $key => $value) {
} if ($key[0] === '$') {
$key = substr($key, 1);
$s->assign($key, $value); }
}
return $s->parsed($template); $s->assign($key, $value);
} }
return $s->parsed($template);
public function getTemplateFile($file, $root = '') }
{
$a = get_app(); public function getTemplateFile($file, $root = '')
$template_file = get_template_file($a, SMARTY3_TEMPLATE_FOLDER . '/' . $file, $root); {
$template = new FriendicaSmarty(); $a = get_app();
$template->filename = $template_file; $template_file = get_template_file($a, SMARTY3_TEMPLATE_FOLDER . '/' . $file, $root);
$template = new FriendicaSmarty();
return $template; $template->filename = $template_file;
}
} return $template;
}
}