]> git.mxchange.org Git - friendica.git/commitdiff
Move mod/home to src/Module/Home
authorPhilipp Holzer <admin@philipp.info>
Sat, 4 May 2019 11:08:31 +0000 (13:08 +0200)
committerPhilipp Holzer <admin@philipp.info>
Sat, 4 May 2019 11:08:31 +0000 (13:08 +0200)
mod/home.php [deleted file]
src/App/Router.php
src/Module/Home.php [new file with mode: 0644]
view/templates/home.tpl

diff --git a/mod/home.php b/mod/home.php
deleted file mode 100644 (file)
index 9f18101..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-/**
- * @file mod/home.php
- */
-use Friendica\App;
-use Friendica\Core\Config;
-use Friendica\Core\Hook;
-use Friendica\Core\L10n;
-use Friendica\Core\Renderer;
-use Friendica\Core\System;
-use Friendica\Module\Login;
-
-if(! function_exists('home_init')) {
-function home_init(App $a) {
-
-       $ret = [];
-       Hook::callAll('home_init',$ret);
-
-       if (local_user() && ($a->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 = '<h1>' . (Config::get('config', 'sitename') ? L10n::t('Welcome to %s', Config::get('config', 'sitename')) : '') . '</h1>';
-
-       $homefilepath = $a->getBasePath() . "/home.html";
-       $cssfilepath = $a->getBasePath() . "/home.css";
-       if (file_exists($homefilepath)) {
-               $customhome = $homefilepath;
-               if (file_exists($cssfilepath)) {
-                       $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'.System::baseUrl().'/home.css'.'" media="all" />';
-               }
-       }
-
-       $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
-       ]);
-}}
index 6612936e1b250b7448880c5777f28bf3848d6d87..12d5d21569f61e27cdd3343902539c97493d4e5c 100644 (file)
@@ -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 (file)
index 0000000..f58664f
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\Hook;
+use Friendica\Core\L10n;
+use Friendica\Core\Renderer;
+
+/**
+ * Home module - Landing page of the current node
+ */
+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'])) {
+                       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'] .= '<link rel="stylesheet" type="text/css" href="' . $app->getBaseURL() . '/home.css' . '" media="all" />';
+                       }
+               }
+
+               $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,
+               ]);
+       }
+}
index eb3f402fc634199e737efbf1cc30a13ef49295e0..d2ce589fdda0568b6f33e4c4f96752bc05a87249 100644 (file)
@@ -7,7 +7,7 @@
        {{if $customhome != false }}
                {{include file="$customhome"}}
        {{else}}
-               {{$defaultheader nofilter}}
+               <h1>{{$defaultheader nofilter}}</h1>
        {{/if}}
 
        {{$login nofilter}}