From 708ffaff51d3f5112af6b1fbd25d7ff6391e496e Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 4 May 2019 13:08:31 +0200 Subject: [PATCH 1/2] Move mod/home to src/Module/Home --- mod/home.php | 64 ----------------------------------- src/App/Router.php | 3 ++ src/Module/Home.php | 74 +++++++++++++++++++++++++++++++++++++++++ view/templates/home.tpl | 2 +- 4 files changed, 78 insertions(+), 65 deletions(-) delete mode 100644 mod/home.php create mode 100644 src/Module/Home.php diff --git a/mod/home.php b/mod/home.php deleted file mode 100644 index 9f18101202..0000000000 --- a/mod/home.php +++ /dev/null @@ -1,64 +0,0 @@ -user['nickname'])) { - $a->internalRedirect('network'); - } - - if (strlen(Config::get('system','singleuser'))) { - $a->internalRedirect('profile/' . Config::get('system','singleuser')); - } - -}} - -if(! function_exists('home_content')) { -function home_content(App $a) { - - if (!empty($_SESSION['theme'])) { - unset($_SESSION['theme']); - } - if (!empty($_SESSION['mobile-theme'])) { - unset($_SESSION['mobile-theme']); - } - - $customhome = false; - $defaultheader = '

' . (Config::get('config', 'sitename') ? L10n::t('Welcome to %s', Config::get('config', 'sitename')) : '') . '

'; - - $homefilepath = $a->getBasePath() . "/home.html"; - $cssfilepath = $a->getBasePath() . "/home.css"; - if (file_exists($homefilepath)) { - $customhome = $homefilepath; - if (file_exists($cssfilepath)) { - $a->page['htmlhead'] .= ''; - } - } - - $login = Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 0 : 1); - - $content = ''; - Hook::callAll("home_content",$content); - - - $tpl = Renderer::getMarkupTemplate('home.tpl'); - return Renderer::replaceMacros($tpl, [ - '$defaultheader' => $defaultheader, - '$customhome' => $customhome, - '$login' => $login, - '$content' => $content - ]); -}} diff --git a/src/App/Router.php b/src/App/Router.php index 6612936e1b..12d5d21569 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -40,6 +40,7 @@ class Router */ public function collectRoutes() { + $this->routeCollector->addRoute(['GET'], '[/]', Module\Home::class); $this->routeCollector->addGroup('/.well-known', function (RouteCollector $collector) { $collector->addRoute(['GET'], '/host-meta' , Module\WellKnown\HostMeta::class); $collector->addRoute(['GET'], '/nodeinfo[/1.0]' , Module\NodeInfo::class); @@ -118,6 +119,7 @@ class Router $collector->addRoute(['POST'], '/{group:\d+}/remove/{contact:\d+}', Module\Group::class); }); $this->routeCollector->addRoute(['GET'], '/hashtag', Module\Hashtag::class); + $this->routeCollector->addRoute(['GET'], '/home', Module\Home::class); $this->routeCollector->addRoute(['GET'], '/inbox[/{nickname}]', Module\Inbox::class); $this->routeCollector->addGroup('/install', function (RouteCollector $collector) { $collector->addRoute(['GET', 'POST'], '[/]', Module\Install::class); @@ -126,6 +128,7 @@ class Router $this->routeCollector->addRoute(['GET', 'POST'], '/itemsource[/{guid}]', Module\Itemsource::class); $this->routeCollector->addRoute(['GET', 'POST'], '/localtime', Module\Localtime::class); $this->routeCollector->addRoute(['GET', 'POST'], '/login', Module\Login::class); + $this->routeCollector->addRoute(['GET', 'POST'], '/logout', Module\Logout::class); $this->routeCollector->addRoute(['GET'], '/magic', Module\Magic::class); $this->routeCollector->addRoute(['GET'], '/manifest', Module\Manifest::class); $this->routeCollector->addRoute(['GET'], '/nodeinfo/1.0', Module\NodeInfo::class); diff --git a/src/Module/Home.php b/src/Module/Home.php new file mode 100644 index 0000000000..f58664f9d7 --- /dev/null +++ b/src/Module/Home.php @@ -0,0 +1,74 @@ +getConfig(); + + if (local_user() && ($app->user['nickname'])) { + $app->internalRedirect('network'); + } + + if (strlen($config->get('system', 'singleuser'))) { + $app->internalRedirect('/profile/' . $config->get('system', 'singleuser')); + } + } + + public static function content() + { + if (!empty($_SESSION['theme'])) { + unset($_SESSION['theme']); + } + + if (!empty($_SESSION['mobile-theme'])) { + unset($_SESSION['mobile-theme']); + } + + $app = self::getApp(); + $config = $app->getConfig(); + + $customHome = ''; + $defaultHeader = ($config->get('config', 'sitename') ? L10n::t('Welcome to %s', $config->get('config', 'sitename')) : ''); + + $homeFilePath = $app->getBaseURL() . '/home.html'; + $cssFilePath = $app->getBaseURL() . '/home.css'; + + if (file_exists($homeFilePath)) { + $customHome = $homeFilePath; + + if (file_exists($cssFilePath)) { + $app->page['htmlhead'] .= ''; + } + } + + $login = Login::form($app->query_string, $config->get('config', 'register_policy') === Register::CLOSED ? 0 : 1); + + $content = ''; + Hook::callAll('home_content', $content); + + $tpl = Renderer::getMarkupTemplate('home.tpl'); + return Renderer::replaceMacros($tpl, [ + '$defaultheader' => $defaultHeader, + '$customhome' => $customHome, + '$login' => $login, + '$content' => $content, + ]); + } +} diff --git a/view/templates/home.tpl b/view/templates/home.tpl index eb3f402fc6..d2ce589fdd 100644 --- a/view/templates/home.tpl +++ b/view/templates/home.tpl @@ -7,7 +7,7 @@ {{if $customhome != false }} {{include file="$customhome"}} {{else}} - {{$defaultheader nofilter}} +

{{$defaultheader nofilter}}

{{/if}} {{$login nofilter}} From 35d4daa4f991dcfcfc0e353b4bc10664e8ba7e3d Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 4 May 2019 16:26:32 +0200 Subject: [PATCH 2/2] Kept the hook, ditched the init --- src/Module/Home.php | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/Module/Home.php b/src/Module/Home.php index f58664f9d7..adcdb02a63 100644 --- a/src/Module/Home.php +++ b/src/Module/Home.php @@ -12,25 +12,6 @@ use Friendica\Core\Renderer; */ class Home extends BaseModule { - public static function init() - { - // currently no returned data is used - $ret = []; - - Hook::callAll('home_init', $ret); - - $app = self::getApp(); - $config = $app->getConfig(); - - if (local_user() && ($app->user['nickname'])) { - $app->internalRedirect('network'); - } - - if (strlen($config->get('system', 'singleuser'))) { - $app->internalRedirect('/profile/' . $config->get('system', 'singleuser')); - } - } - public static function content() { if (!empty($_SESSION['theme'])) { @@ -44,6 +25,19 @@ class Home extends BaseModule $app = self::getApp(); $config = $app->getConfig(); + // currently no returned data is used + $ret = []; + + Hook::callAll('home_init', $ret); + + if (local_user() && ($app->user['nickname'])) { + $app->internalRedirect('network'); + } + + if (strlen($config->get('system', 'singleuser'))) { + $app->internalRedirect('/profile/' . $config->get('system', 'singleuser')); + } + $customHome = ''; $defaultHeader = ($config->get('config', 'sitename') ? L10n::t('Welcome to %s', $config->get('config', 'sitename')) : '');