From f5f62d3f42faf6fda931f2c28de9e58c2a665d5c Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 26 Apr 2020 15:45:25 +0200 Subject: [PATCH 1/3] Template Engine with Subdirectory - Use explicit root path for template engine - Replace "__DIR__" calls in addons with subdirectories - Fixes local tests, where call is made out of '/' and not '/vagrant/' --- src/Core/Renderer.php | 7 +++---- src/DI.php | 8 ++++++++ src/Render/FriendicaSmartyEngine.php | 8 +++++--- src/Render/ITemplateEngine.php | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index 98915e70fa..5ce47ad931 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -99,19 +99,18 @@ class Renderer * Load a given template $s * * @param string $s Template to load. - * @param string $root Optional. + * @param string $subDir Subdirectory (Optional) * * @return string template. * @throws Exception */ - public static function getMarkupTemplate($s, $root = '') + public static function getMarkupTemplate($s, $subDir = '') { $stamp1 = microtime(true); - $a = DI::app(); $t = self::getTemplateEngine(); try { - $template = $t->getTemplateFile($s, $root); + $template = $t->getTemplateFile($s, $subDir); } catch (Exception $e) { echo "
" . __FUNCTION__ . ": " . $e->getMessage() . "
"; exit(); diff --git a/src/DI.php b/src/DI.php index 39efe2a97b..c89315c0ec 100644 --- a/src/DI.php +++ b/src/DI.php @@ -383,6 +383,14 @@ abstract class DI return self::$dice->create(Util\ACLFormatter::class); } + /** + * @return string + */ + public static function basePath() + { + return self::$dice->create('$basepath'); + } + /** * @return Util\DateTimeFormat */ diff --git a/src/Render/FriendicaSmartyEngine.php b/src/Render/FriendicaSmartyEngine.php index 1e419bcf76..6984daa158 100644 --- a/src/Render/FriendicaSmartyEngine.php +++ b/src/Render/FriendicaSmartyEngine.php @@ -68,16 +68,18 @@ class FriendicaSmartyEngine implements ITemplateEngine return $s->parsed($template); } - public function getTemplateFile($file, $root = '') + public function getTemplateFile($file, $subDir = '') { $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; diff --git a/src/Render/ITemplateEngine.php b/src/Render/ITemplateEngine.php index 456bb268b9..b18af69f22 100644 --- a/src/Render/ITemplateEngine.php +++ b/src/Render/ITemplateEngine.php @@ -27,5 +27,5 @@ namespace Friendica\Render; interface ITemplateEngine { public function replaceMacros($s, $v); - public function getTemplateFile($file, $root = ''); + public function getTemplateFile($file, $subDir = ''); } From 6c59e0380593c7dd5dbe41024aa21159999d85fa Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Apr 2020 16:20:17 +0000 Subject: [PATCH 2/3] Renamed comment --- src/Database/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/View.php b/src/Database/View.php index c7f55ee752..e1335d9df6 100644 --- a/src/Database/View.php +++ b/src/Database/View.php @@ -28,7 +28,7 @@ use Friendica\DI; class View { /** - * view definition loaded from config/dbview.config.php + * view definition loaded from static/dbview.config.php * * @var array */ From 53b0401d6adf4230a2b44f4547d406911e1b7bdd Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Apr 2020 16:25:46 +0000 Subject: [PATCH 3/3] Fix tests - hopefully --- tests/datasets/api.fixture.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 8bb701da1d..c9c16a33fc 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -256,6 +256,12 @@ return [ 'wall' => 1, ], ], + 'profile' => [ + [ + 'id' => 1, + 'uid' => 42, + ], + ], 'group' => [ [ 'id' => 1,