]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Conversation/Network.php
Merge pull request #12026 from annando/no-boot-src-module-2
[friendica.git] / src / Module / Conversation / Network.php
index f2dc1fae1c744f98550d48c84d0bcaa3e70c32a3..a7696a0ec6e6cfc24fa731fbacf0439aa84f8ca2 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Module\Conversation;
 
@@ -57,23 +76,23 @@ class Network extends BaseModule
        /** @var string */
        protected static $order;
 
-       public static function content(array $parameters = [])
+       protected function content(array $request = []): string
        {
-               if (!local_user()) {
+               if (!Session::getLocalUser()) {
                        return Login::form();
                }
 
-               self::parseRequest($parameters, $_GET);
+               $this->parseRequest($_GET);
 
                $module = 'network';
 
-               DI::page()['aside'] .= Widget::accounttypes($module, self::$accountTypeString);
+               DI::page()['aside'] .= Widget::accountTypes($module, self::$accountTypeString);
                DI::page()['aside'] .= Group::sidebarWidget($module, $module . '/group', 'standard', self::$groupId);
-               DI::page()['aside'] .= ForumManager::widget($module . '/forum', local_user(), self::$forumContactId);
-               DI::page()['aside'] .= Widget::postedByYear($module . '/archive', local_user(), false);
+               DI::page()['aside'] .= ForumManager::widget($module . '/forum', Session::getLocalUser(), self::$forumContactId);
+               DI::page()['aside'] .= Widget::postedByYear($module . '/archive', Session::getLocalUser(), false);
                DI::page()['aside'] .= Widget::networks($module, !self::$forumContactId ? self::$network : '');
                DI::page()['aside'] .= Widget\SavedSearches::getHTML(DI::args()->getQueryString());
-               DI::page()['aside'] .= Widget::fileAs('filed', null);
+               DI::page()['aside'] .= Widget::fileAs('filed', '');
 
                $arr = ['query' => DI::args()->getQueryString()];
                Hook::callAll('network_content_init', $arr);
@@ -86,7 +105,7 @@ class Network extends BaseModule
 
                $items = self::getItems($table, $params);
 
-               if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
+               if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
                        $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
                        $o .= Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
                }
@@ -100,7 +119,7 @@ class Network extends BaseModule
 
                        if (self::$forumContactId) {
                                // If self::$forumContactId belongs to a communitity forum or a privat goup,.add a mention to the status editor
-                               $condition = ["`id` = ? AND (`forum` OR `prv`)", self::$forumContactId];
+                               $condition = ["`id` = ? AND `contact-type` = ?", self::$forumContactId, Contact::TYPE_COMMUNITY];
                                $contact = DBA::selectFirst('contact', ['addr'], $condition);
                                if (!empty($contact['addr'])) {
                                        $content = '!' . $contact['addr'];
@@ -119,7 +138,7 @@ class Network extends BaseModule
                                $allowedCids[] = (int) self::$forumContactId;
                        } elseif (self::$network) {
                                $condition = [
-                                       'uid'     => local_user(),
+                                       'uid'     => Session::getLocalUser(),
                                        'network' => self::$network,
                                        'self'    => false,
                                        'blocked' => false,
@@ -149,9 +168,9 @@ class Network extends BaseModule
                }
 
                if (self::$groupId) {
-                       $group = DBA::selectFirst('group', ['name'], ['id' => self::$groupId, 'uid' => local_user()]);
+                       $group = DBA::selectFirst('group', ['name'], ['id' => self::$groupId, 'uid' => Session::getLocalUser()]);
                        if (!DBA::isResult($group)) {
-                               notice(DI::l10n()->t('No such group'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('No such group'));
                        }
 
                        $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
@@ -165,7 +184,7 @@ class Network extends BaseModule
                                        'id' => DI::args()->get(0),
                                ]) . $o;
                        } else {
-                               notice(DI::l10n()->t('Invalid contact.'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Invalid contact.'));
                        }
                } elseif (!DI::config()->get('theme', 'hide_eventlist')) {
                        $o .= Profile::getBirthdays();
@@ -174,13 +193,15 @@ class Network extends BaseModule
 
                if (self::$order === 'received') {
                        $ordering = '`received`';
+               } elseif (self::$order === 'created') {
+                       $ordering = '`created`';
                } else {
                        $ordering = '`commented`';
                }
 
-               $o .= DI::conversation()->create($items, 'network', false, false, $ordering, local_user());
+               $o .= DI::conversation()->create($items, 'network', false, false, $ordering, Session::getLocalUser());
 
-               if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+               if (DI::pConfig()->get(Session::getLocalUser(), 'system', 'infinite_scroll')) {
                        $o .= HTML::scrollLoader();
                } else {
                        $pager = new BoundariesPager(
@@ -246,6 +267,14 @@ class Network extends BaseModule
                                'id'    => 'post-order-tab',
                                'accesskey' => 't',
                        ],
+                       [
+                               'label' => DI::l10n()->t('Latest Creation'),
+                               'url'   => $cmd . '?' . http_build_query(['order' => 'created']),
+                               'sel'   => $selectedTab == 'created' ? 'active' : '',
+                               'title' => DI::l10n()->t('Sort by post creation date'),
+                               'id'    => 'creation-order-tab',
+                               'accesskey' => 'q',
+                       ],
                        [
                                'label' => DI::l10n()->t('Personal'),
                                'url'   => $cmd . '?' . http_build_query(['mention' => true]),
@@ -272,15 +301,13 @@ class Network extends BaseModule
                return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
        }
 
-       protected static function parseRequest(array $parameters, array $get)
+       protected function parseRequest(array $get)
        {
-               self::$groupId = $parameters['group_id'] ?? 0;
+               self::$groupId = $this->parameters['group_id'] ?? 0;
 
-               self::$forumContactId = $parameters['contact_id'] ?? 0;
+               self::$forumContactId = $this->parameters['contact_id'] ?? 0;
 
-               self::$selectedTab = Session::get('network-tab', DI::pConfig()->get(local_user(), 'network.view', 'selected_tab', ''));
-
-               self::$order = 'commented';
+               self::$selectedTab = DI::session()->get('network-tab', DI::pConfig()->get(Session::getLocalUser(), 'network.view', 'selected_tab', ''));
 
                if (!empty($get['star'])) {
                        self::$selectedTab = 'star';
@@ -301,8 +328,12 @@ class Network extends BaseModule
                        self::$order = $get['order'];
                        self::$star = false;
                        self::$mention = false;
-               } elseif (in_array(self::$selectedTab, ['received', 'star', 'mention'])) {
+               } elseif (in_array(self::$selectedTab, ['received', 'star'])) {
                        self::$order = 'received';
+               } elseif (self::$selectedTab == 'created') {
+                       self::$order = 'created';
+               } else {
+                       self::$order = 'commented';
                }
 
                self::$selectedTab = self::$selectedTab ?? self::$order;
@@ -314,22 +345,22 @@ class Network extends BaseModule
                        self::$star = false;
                }
 
-               Session::set('network-tab', self::$selectedTab);
-               DI::pConfig()->set(local_user(), 'network.view', 'selected_tab', self::$selectedTab);
+               DI::session()->set('network-tab', self::$selectedTab);
+               DI::pConfig()->set(Session::getLocalUser(), 'network.view', 'selected_tab', self::$selectedTab);
 
-               self::$accountTypeString = $get['accounttype'] ?? $parameters['accounttype'] ?? '';
+               self::$accountTypeString = $get['accounttype'] ?? $this->parameters['accounttype'] ?? '';
                self::$accountType = User::getAccountTypeByString(self::$accountTypeString);
 
                self::$network = $get['nets'] ?? '';
 
-               self::$dateFrom = $parameters['from'] ?? '';
-               self::$dateTo = $parameters['to'] ?? '';
+               self::$dateFrom = $this->parameters['from'] ?? '';
+               self::$dateTo = $this->parameters['to'] ?? '';
 
                if (DI::mode()->isMobile()) {
-                       self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
+                       self::$itemsPerPage = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_mobile_network',
                                DI::config()->get('system', 'itemspage_network_mobile'));
                } else {
-                       self::$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
+                       self::$itemsPerPage = DI::pConfig()->get(Session::getLocalUser(), 'system', 'itemspage_network',
                                DI::config()->get('system', 'itemspage_network'));
                }
 
@@ -354,7 +385,7 @@ class Network extends BaseModule
 
        protected static function getItems(string $table, array $params, array $conditionFields = [])
        {
-               $conditionFields['uid'] = local_user();
+               $conditionFields['uid'] = Session::getLocalUser();
                $conditionStrings = [];
 
                if (!is_null(self::$accountType)) {
@@ -382,8 +413,8 @@ class Network extends BaseModule
                        $conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", self::$groupId]);
                } elseif (self::$forumContactId) {
                        $conditionStrings = DBA::mergeConditions($conditionStrings, 
-                               ["((`contact-id` = ?) OR EXISTS(SELECT `uri-id` FROM `post-user-view` WHERE `post-user-view`.`parent-uri-id` = " . DBA::quoteIdentifier($table) . ".`uri-id` AND (`contact-id` = ? AND `gravity` = ? AND `vid` = ? AND `uid` = ?)))",
-                               self::$forumContactId, self::$forumContactId, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), local_user()]);
+                               ["((`contact-id` = ?) OR `uri-id` IN (SELECT `parent-uri-id` FROM `post-user-view` WHERE (`contact-id` = ? AND `gravity` = ? AND `vid` = ? AND `uid` = ?)))",
+                               self::$forumContactId, self::$forumContactId, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Session::getLocalUser()]);
                }
 
                // Currently only the order modes "received" and "commented" are in use
@@ -447,10 +478,10 @@ class Network extends BaseModule
                // level which items you've seen and which you haven't. If you're looking
                // at the top level network page just mark everything seen.
                if (!self::$groupId && !self::$forumContactId && !self::$star && !self::$mention) {
-                       $condition = ['unseen' => true, 'uid' => local_user()];
+                       $condition = ['unseen' => true, 'uid' => Session::getLocalUser()];
                        self::setItemsSeenByCondition($condition);
                } elseif (!empty($parents)) {
-                       $condition = ['unseen' => true, 'uid' => local_user(), 'parent-uri-id' => $parents];
+                       $condition = ['unseen' => true, 'uid' => Session::getLocalUser(), 'parent-uri-id' => $parents];
                        self::setItemsSeenByCondition($condition);
                }