]> git.mxchange.org Git - friendica.git/commitdiff
Move contact posts to their own module class
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 7 Nov 2021 22:19:29 +0000 (17:19 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 22 Nov 2021 00:21:39 +0000 (19:21 -0500)
- Remove duplicated check for local_user() in Module\Contact
- [frio] Fix display issue for search items where the More button and icon would show but be inactive

src/Module/Contact.php
src/Module/Contact/Posts.php [new file with mode: 0644]
static/routes.config.php
view/theme/frio/templates/search_item.tpl
view/theme/frio/templates/wall_thread.tpl

index 243ec4be3e588fb5381ec6cb2953e1b15fe205ea..fc518d1045c2fa689d90de3489ab52b81b11268e 100644 (file)
@@ -252,7 +252,7 @@ class Contact extends BaseModule
                $contact = null;
                // @TODO: Replace with parameter from router
                if (DI::args()->getArgc() == 2 && intval(DI::args()->getArgv()[1])
-                       || DI::args()->getArgc() == 3 && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['posts', 'conversations'])
+                       || DI::args()->getArgc() == 3 && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['conversations'])
                ) {
                        $contact_id = intval(DI::args()->getArgv()[1]);
 
@@ -279,7 +279,7 @@ class Contact extends BaseModule
                if (DBA::isResult($contact)) {
                        if ($contact['self']) {
                                // @TODO: Replace with parameter from router
-                               if ((DI::args()->getArgc() == 3) && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['posts', 'conversations'])) {
+                               if ((DI::args()->getArgc() == 3) && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['conversations'])) {
                                        DI::baseUrl()->redirect('profile/' . $contact['nick']);
                                } else {
                                        DI::baseUrl()->redirect('profile/' . $contact['nick'] . '/profile');
@@ -324,11 +324,6 @@ class Contact extends BaseModule
                $o = '';
                Nav::setSelected('contact');
 
-               if (!local_user()) {
-                       notice(DI::l10n()->t('Permission denied.'));
-                       return Login::form();
-               }
-
                if (DI::args()->getArgc() == 3) {
                        $contact_id = intval(DI::args()->getArgv()[1]);
                        if (!$contact_id) {
@@ -343,10 +338,6 @@ class Contact extends BaseModule
                                throw new NotFoundException(DI::l10n()->t('Contact not found'));
                        }
 
-                       if ($cmd === 'posts') {
-                               return self::getPostsHTML($contact_id);
-                       }
-
                        if ($cmd === 'conversations') {
                                return self::getConversationsHMTL($a, $contact_id, $update);
                        }
@@ -910,31 +901,6 @@ class Contact extends BaseModule
                return $o;
        }
 
-       private static function getPostsHTML(int $contact_id)
-       {
-               $contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
-
-               $o = self::getTabsHTML($contact, self::TAB_POSTS);
-
-               if (DBA::isResult($contact)) {
-                       $profiledata = Model\Contact::getByURLForUser($contact['url'], local_user());
-
-                       if (local_user() && in_array($profiledata['network'], Protocol::FEDERATED)) {
-                               $profiledata['remoteconnect'] = DI::baseUrl() . '/follow?url=' . urlencode($profiledata['url']);
-                       }
-
-                       DI::page()['aside'] = Widget\VCard::getHTML($profiledata);
-
-                       if ($contact['uid'] == 0) {
-                               $o .= Model\Contact::getPostsFromId($contact['id']);
-                       } else {
-                               $o .= Model\Contact::getPostsFromUrl($contact['url']);
-                       }
-               }
-
-               return $o;
-       }
-
        /**
         * Return the fields for the contact template
         *
diff --git a/src/Module/Contact/Posts.php b/src/Module/Contact/Posts.php
new file mode 100644 (file)
index 0000000..3409d91
--- /dev/null
@@ -0,0 +1,102 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2021, 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\Contact;
+
+use Friendica\App;
+use Friendica\BaseModule;
+use Friendica\Contact\LocalRelationship\Repository\LocalRelationship;
+use Friendica\Content\Nav;
+use Friendica\Content\Widget;
+use Friendica\Core\L10n;
+use Friendica\Core\Protocol;
+use Friendica\Database\DBA;
+use Friendica\Model;
+use Friendica\Module\Contact;
+use Friendica\Module\Security\Login;
+use Friendica\Network\HTTPException\NotFoundException;
+
+/**
+ *  Show a contact posts and comments
+ */
+class Posts extends BaseModule
+{
+       /**
+        * @var LocalRelationship
+        */
+       private $localRelationship;
+       /**
+        * @var App\BaseURL
+        */
+       private $baseUrl;
+       /**
+        * @var App\Page
+        */
+       private $page;
+
+       public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Page $page, array $parameters = [])
+       {
+               parent::__construct($l10n, $parameters);
+
+               $this->localRelationship = $localRelationship;
+               $this->baseUrl           = $baseUrl;
+               $this->page              = $page;
+       }
+
+       public function content(): string
+       {
+               if (!local_user()) {
+                       return Login::form($_SERVER['REQUEST_URI']);
+               }
+
+               // Backward compatibility: Ensure to use the public contact when the user contact is provided
+               // Remove by version 2022.03
+               $data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), local_user());
+               if (empty($data)) {
+                       throw new NotFoundException($this->t('Contact not found.'));
+               }
+
+               $contact = Model\Contact::getById($data['public']);
+               if (!DBA::isResult($contact)) {
+                       throw new NotFoundException($this->t('Contact not found.'));
+               }
+
+               // Don't display contacts that are about to be deleted
+               if (DBA::isResult($contact) && (!empty($contact['deleted']) || !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM)) {
+                       throw new NotFoundException($this->t('Contact not found.'));
+               }
+
+               $localRelationship = $this->localRelationship->getForUserContact(local_user(), $contact['id']);
+               if ($localRelationship->rel === Model\Contact::SELF) {
+                       $this->baseUrl->redirect('profile/' . $contact['nick']);
+               }
+
+               $this->page['aside'] .= Widget\VCard::getHTML($contact);
+
+               Nav::setSelected('contact');
+
+               $o = Contact::getTabsHTML($contact, Contact::TAB_POSTS);
+
+               $o .= Model\Contact::getPostsFromId($contact['id']);
+
+               return $o;
+       }
+}
index e3ab6776101128e40e49acb2da6005917a74946e..36df142a64b047bb786b3ab22bff6420813261f7 100644 (file)
@@ -338,7 +338,7 @@ return [
                '/{id:\d+}/ignore'            => [Module\Contact::class,           [R::GET]],
                '/{id:\d+}/media'             => [Module\Contact\Media::class,     [R::GET]],
                '/{id:\d+}/poke'              => [Module\Contact\Poke::class,      [R::GET, R::POST]],
-               '/{id:\d+}/posts'             => [Module\Contact::class,           [R::GET]],
+               '/{id:\d+}/posts'             => [Module\Contact\Posts::class,     [R::GET]],
                '/{id:\d+}/revoke'            => [Module\Contact\Revoke::class,    [R::GET, R::POST]],
                '/{id:\d+}/update'            => [Module\Contact::class,           [R::GET]],
                '/{id:\d+}/updateprofile'     => [Module\Contact::class,           [R::GET]],
index 344e73f1d913d6ca432d3724db65a7f8941faf80..e31537b1597455baf6bd364cc40c634158cd412a 100644 (file)
 
 
                                {{* Put additional actions in a dropdown menu *}}
-                               {{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping}}
+                               {{if $item.menu && ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping)}}
                                        <span role="presentation" class="separator"></span>
                                        <span class="more-links btn-group{{if $item.thread_level> 1}} dropup{{/if}}">
                                                <button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" id="dropdownMenuOptions-{{$item.id}}" aria-haspopup="true" aria-expanded="false" title="{{$item.menu}}"><i class="fa fa-ellipsis-h" aria-hidden="true"></i>&nbsp;{{$item.menu}}</button>
index e91b1b99f8649acb648940046c2844c0a2831419..bbacdfc5b256e6acaf8de6da3081f53cc10777b1 100644 (file)
@@ -326,7 +326,7 @@ as the value of $top_child_total (this is done at the end of this file)
                        {{/if}}
 
                        {{* Put additional actions in a dropdown menu *}}
-                       {{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping}}
+                       {{if $item.menu && ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping)}}
                                <span role="presentation" class="separator"></span>
                                <span class="more-links btn-group{{if $item.thread_level > 1}} dropup{{/if}}">
                                        <button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" id="dropdownMenuOptions-{{$item.id}}" aria-haspopup="true" aria-expanded="false" title="{{$item.menu}}"><i class="fa fa-ellipsis-h" aria-hidden="true"></i>&nbsp;{{$item.menu}}</button>