]> git.mxchange.org Git - friendica.git/commitdiff
Move /viewcontacts to /profile/{nickname}/contacts[/{type}]
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 18 May 2019 15:47:39 +0000 (11:47 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 20 May 2019 18:50:09 +0000 (14:50 -0400)
- Add contact relationship filter to profile contacts page
- Include feed contacts in contacts page and contact widget

mod/viewcontacts.php [deleted file]
src/App/Router.php
src/Content/Widget/ContactBlock.php
src/Model/Profile.php
src/Module/Profile/Contacts.php [new file with mode: 0644]
src/Protocol/OStatus.php
view/templates/profile/contacts.tpl [new file with mode: 0644]
view/theme/duepuntozero/style.css
view/theme/frio/css/style.css
view/theme/frio/templates/profile/contacts.tpl [new file with mode: 0644]
view/theme/smoothly/style.css

diff --git a/mod/viewcontacts.php b/mod/viewcontacts.php
deleted file mode 100644 (file)
index 1491982..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-<?php
-/**
- * @file mod/viewcontacts.php
- */
-
-use Friendica\App;
-use Friendica\Content\ContactSelector;
-use Friendica\Content\Nav;
-use Friendica\Content\Pager;
-use Friendica\Core\Config;
-use Friendica\Core\L10n;
-use Friendica\Core\Protocol;
-use Friendica\Core\Renderer;
-use Friendica\Core\System;
-use Friendica\Database\DBA;
-use Friendica\Model\Contact;
-use Friendica\Model\Profile;
-use Friendica\Util\Proxy as ProxyUtils;
-
-function viewcontacts_init(App $a)
-{
-       if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
-               throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
-       }
-
-       if ($a->argc < 2) {
-               throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
-       }
-
-       Nav::setSelected('home');
-
-       $user = DBA::selectFirst('user', [], ['nickname' => $a->argv[1], 'blocked' => false]);
-       if (!DBA::isResult($user)) {
-               throw new \Friendica\Network\HTTPException\NotFoundException();
-       }
-
-       $a->data['user'] = $user;
-       $a->profile_uid  = $user['uid'];
-
-       Profile::load($a, $a->argv[1]);
-}
-
-function viewcontacts_content(App $a)
-{
-       if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
-               notice(L10n::t('Public access denied.') . EOL);
-               return;
-       }
-
-       $is_owner = $a->profile['profile_uid'] == local_user();
-
-       // tabs
-       $o = Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
-
-       if (!count($a->profile) || $a->profile['hide-friends']) {
-               notice(L10n::t('Permission denied.') . EOL);
-               return $o;
-       }
-
-       $condition = [
-               'uid'     => $a->profile['uid'],
-               'blocked' => false,
-               'pending' => false,
-               'hidden'  => false,
-               'archive' => false,
-               'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]
-       ];
-
-       $total = DBA::count('contact', $condition);
-
-       $pager = new Pager($a->query_string);
-
-       $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
-
-       $contacts_stmt = DBA::select('contact', [], $condition, $params);
-
-       if (!DBA::isResult($contacts_stmt)) {
-               info(L10n::t('No contacts.') . EOL);
-               return $o;
-       }
-
-       $contacts = [];
-
-       while ($contact = DBA::fetch($contacts_stmt)) {
-               /// @TODO This triggers an E_NOTICE if 'self' is not there
-               if ($contact['self']) {
-                       continue;
-               }
-
-               $contact_details = Contact::getDetailsByURL($contact['url'], $a->profile['uid'], $contact);
-
-               $contacts[] = [
-                       'id'           => $contact['id'],
-                       'img_hover'    => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
-                       'photo_menu'   => Contact::photoMenu($contact),
-                       'thumb'        => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
-                       'name'         => substr($contact_details['name'], 0, 20),
-                       'username'     => $contact_details['name'],
-                       'details'      => $contact_details['location'],
-                       'tags'         => $contact_details['keywords'],
-                       'about'        => $contact_details['about'],
-                       'account_type' => Contact::getAccountType($contact_details),
-                       'url'          => Contact::magicLink($contact['url']),
-                       'sparkle'      => '',
-                       'itemurl'      => (($contact_details['addr'] != "") ? $contact_details['addr'] : $contact['url']),
-                       'network'      => ContactSelector::networkToName($contact['network'], $contact['url']),
-               ];
-       }
-
-       DBA::close($contacts_stmt);
-
-       $tpl = Renderer::getMarkupTemplate("viewcontact_template.tpl");
-       $o .= Renderer::replaceMacros($tpl, [
-               '$title'    => L10n::t('Contacts'),
-               '$contacts' => $contacts,
-               '$paginate' => $pager->renderFull($total),
-       ]);
-
-       return $o;
-}
index be81c143d1aa845c32f520573077b3fd7170b565..f7ee24730dfed3ea0bb7fd2b576887daaf4978b5 100644 (file)
@@ -187,6 +187,7 @@ class Router
                $this->routeCollector->addRoute(['GET'],         '/probe',               Module\Debug\Probe::class);
                $this->routeCollector->addGroup('/profile', function (RouteCollector $collector) {
                        $collector->addRoute(['GET'], '/{nickname}',                         Module\Profile::class);
+                       $collector->addRoute(['GET'], '/{nickname}/contacts[/{type}]',       Module\Profile\Contacts::class);
                        $collector->addRoute(['GET'], '/{profile:\d+}/view',                 Module\Profile::class);
                });
                $this->routeCollector->addGroup('/proxy', function (RouteCollector $collector) {
index f4fdea2fb4c3b6be90212defe83ddadf87d1e19d..bc33b9c9c928672a24de0d9712bf0a52562a0c73 100644 (file)
@@ -52,7 +52,7 @@ class ContactBlock
                        'pending' => false,
                        'hidden' => false,
                        'archive' => false,
-                       'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA],
+                       'network' => [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::FEED],
                ]);
 
                $contacts_title = L10n::t('No contacts');
index a854b1c9e019d3c6c11e753eb1cd94a13aabf6bd..38f5c036231b0ae6d610e2de988698c819dd3e15 100644 (file)
@@ -894,7 +894,7 @@ class Profile
                        [
                                'label' => L10n::t('Status'),
                                'url'   => $url,
-                               'sel'   => !$tab && $a->argv[0] == 'profile' ? 'active' : '',
+                               'sel'   => !$tab && $a->argv[0] == 'profile' && (empty($a->argv[2]) || $a->argv[2] !== 'contacts') ? 'active' : '',
                                'title' => L10n::t('Status Messages and Posts'),
                                'id'    => 'status-tab',
                                'accesskey' => 'm',
@@ -969,11 +969,11 @@ class Profile
                        ];
                }
 
-               if (!$is_owner && empty($a->profile['hide-friends'])) {
+               if ($is_owner || empty($a->profile['hide-friends'])) {
                        $tabs[] = [
                                'label' => L10n::t('Contacts'),
-                               'url'   => System::baseUrl() . '/viewcontacts/' . $nickname,
-                               'sel'   => !$tab && $a->argv[0] == 'viewcontacts' ? 'active' : '',
+                               'url'   => System::baseUrl() . '/profile/' . $nickname . '/contacts',
+                               'sel'   => !$tab && !empty($a->argv[2]) && $a->argv[2] == 'contacts' ? 'active' : '',
                                'title' => L10n::t('Contacts'),
                                'id'    => 'viewcontacts-tab',
                                'accesskey' => 'k',
diff --git a/src/Module/Profile/Contacts.php b/src/Module/Profile/Contacts.php
new file mode 100644 (file)
index 0000000..340c9ef
--- /dev/null
@@ -0,0 +1,137 @@
+<?php
+
+namespace Friendica\Module\Profile;
+
+use Friendica\BaseModule;
+use Friendica\Content\ContactSelector;
+use Friendica\Content\Nav;
+use Friendica\Content\Pager;
+use Friendica\Core\Config;
+use Friendica\Core\L10n;
+use Friendica\Core\Protocol;
+use Friendica\Core\Renderer;
+use Friendica\Database\DBA;
+use Friendica\Model\Contact;
+use Friendica\Model\Profile;
+use Friendica\Util\Proxy as ProxyUtils;
+
+class Contacts extends BaseModule
+{
+       public static function content()
+       {
+               if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+                       throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('User not found.'));
+               }
+
+               $a = self::getApp();
+
+               //@TODO: Get value from router parameters
+               $nickname = $a->argv[1];
+               $type = defaults($a->argv, 3, 'all');
+
+               Nav::setSelected('home');
+
+               $user = DBA::selectFirst('user', [], ['nickname' => $nickname, 'blocked' => false]);
+               if (!DBA::isResult($user)) {
+                       throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('User not found.'));
+               }
+
+               $a->data['user'] = $user;
+               $a->profile_uid  = $user['uid'];
+
+               Profile::load($a, $nickname);
+
+               $is_owner = $a->profile['profile_uid'] == local_user();
+
+               // tabs
+               $o = Profile::getTabs($a, $is_owner, $nickname);
+
+               if (!count($a->profile) || $a->profile['hide-friends']) {
+                       notice(L10n::t('Permission denied.') . EOL);
+                       return $o;
+               }
+
+               $condition = [
+                       'uid'     => $a->profile['uid'],
+                       'blocked' => false,
+                       'pending' => false,
+                       'hidden'  => false,
+                       'archive' => false,
+                       'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED]
+               ];
+
+               switch ($type) {
+                       case 'followers': $condition['rel'] = [1, 3]; break;
+                       case 'following': $condition['rel'] = [2, 3]; break;
+                       case 'mutuals': $condition['rel'] = 3; break;
+               }
+
+               $total = DBA::count('contact', $condition);
+
+               $pager = new Pager($a->query_string);
+
+               $params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
+
+               $contacts_stmt = DBA::select('contact', [], $condition, $params);
+
+               if (!DBA::isResult($contacts_stmt)) {
+                       info(L10n::t('No contacts.') . EOL);
+                       return $o;
+               }
+
+               $contacts = [];
+
+               while ($contact = DBA::fetch($contacts_stmt)) {
+                       /// @TODO This triggers an E_NOTICE if 'self' is not there
+                       if ($contact['self']) {
+                               continue;
+                       }
+
+                       $contact_details = Contact::getDetailsByURL($contact['url'], $a->profile['uid'], $contact);
+
+                       $contacts[] = [
+                               'id'           => $contact['id'],
+                               'img_hover'    => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
+                               'photo_menu'   => Contact::photoMenu($contact),
+                               'thumb'        => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
+                               'name'         => substr($contact_details['name'], 0, 20),
+                               'username'     => $contact_details['name'],
+                               'details'      => $contact_details['location'],
+                               'tags'         => $contact_details['keywords'],
+                               'about'        => $contact_details['about'],
+                               'account_type' => Contact::getAccountType($contact_details),
+                               'url'          => Contact::magicLink($contact['url']),
+                               'sparkle'      => '',
+                               'itemurl'      => $contact_details['addr'] ? : $contact['url'],
+                               'network'      => ContactSelector::networkToName($contact['network'], $contact['url']),
+                       ];
+               }
+
+               DBA::close($contacts_stmt);
+
+               switch ($type) {
+                       case 'followers':    $title = L10n::tt('Follower (%s)', 'Followers (%s)', $total); break;
+                       case 'following':    $title = L10n::tt('Following (%s)', 'Following (%s)', $total); break;
+                       case 'mutuals':      $title = L10n::tt('Mutual friend (%s)', 'Mutual friends (%s)', $total); break;
+
+                       case 'all': default: $title = L10n::tt('Contact (%s)', 'Contacts (%s)', $total); break;
+               }
+
+               $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
+               $o .= Renderer::replaceMacros($tpl, [
+                       '$title'    => $title,
+                       '$nickname' => $nickname,
+                       '$type'     => $type,
+
+                       '$all_label' => L10n::t('All contacts'),
+                       '$followers_label' => L10n::t('Followers'),
+                       '$following_label' => L10n::t('Following'),
+                       '$mutuals_label' => L10n::t('Mutual friends'),
+
+                       '$contacts' => $contacts,
+                       '$paginate' => $pager->renderFull($total),
+               ]);
+
+               return $o;
+       }
+}
index dec5c4c80b021a572da0d951304a7234dcbab6bc..c7747e8cfc79b79c095edfde8fe113a8aef9f969 100644 (file)
@@ -1515,7 +1515,7 @@ class OStatus
                                $author->appendChild($urls);
                        }
 
-                       XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl()."/viewcontacts/".$owner["nick"]]);
+                       XML::addElement($doc, $author, "followers", "", ["url" => System::baseUrl() . "/profile/" . $owner["nick"] . "/contacts/followers"]);
                        XML::addElement($doc, $author, "statusnet:profile_info", "", ["local_id" => $owner["uid"]]);
 
                        if ($profile["publish"]) {
diff --git a/view/templates/profile/contacts.tpl b/view/templates/profile/contacts.tpl
new file mode 100644 (file)
index 0000000..4e78a7a
--- /dev/null
@@ -0,0 +1,20 @@
+<div class="generic-page-wrapper">
+       {{include file="section_title.tpl"}}
+
+       <ul role="menubar" class="tabs">
+               <li role="menuitem"><a href="profile/{{$nickname}}/contacts" class="tab button{{if !$type || $type == 'all'}} active{{/if}}">{{$all_label}}</a></li>
+               <li role="menuitem"><a href="profile/{{$nickname}}/contacts/followers" class="tab button{{if $type == 'followers'}} active{{/if}}">{{$followers_label}}</a></li>
+               <li role="menuitem"><a href="profile/{{$nickname}}/contacts/following" class="tab button{{if $type == 'following'}} active{{/if}}">{{$following_label}}</a></li>
+               <li role="menuitem"><a href="profile/{{$nickname}}/contacts/mutuals" class="tab button{{if $type == 'mutuals'}} active{{/if}}">{{$mutuals_label}}</a></li>
+       </ul>
+
+       <div id="viewcontact_wrapper-{{$id}}">
+{{foreach $contacts as $contact}}
+               {{include file="contact_template.tpl"}}
+{{/foreach}}
+       </div>
+       <div class="clear"></div>
+       <div id="view-contact-end"></div>
+
+       {{$paginate nofilter}}
+</div>
index f586d6e04d740fe705200e2364a8d25502bdc38e..7e66570ad57cddd532e82669e4c2d49197892818 100644 (file)
@@ -680,10 +680,6 @@ input#dfrn-url {
        clear: both;
 }
 
-
-#viewcontacts {
-       margin-top: 15px;
-}
 #profile-edit-default-desc {
        color: #FF0000;
        border: 1px solid #FF8888;
index 4a72628352891da6a7c77a7e4e8fc3bce158012f..2a5706c85968c5098919904e444232b468510d2e 100644 (file)
@@ -2317,7 +2317,7 @@ ul.dropdown-menu li:hover {
 .manage-content-wrapper, .notes-content-wrapper,
 .message-content-wrapper, .apps-content-wrapper,
 #adminpage, .delegate-content-wrapper, .uexport-content-wrapper,
-.viewcontacts-content-wrapper, .dfrn_request-content-wrapper,
+.dfrn_request-content-wrapper,
 .friendica-content-wrapper, .credits-content-wrapper, .nogroup-content-wrapper,
 .profperm-content-wrapper, .invite-content-wrapper, .tos-content-wrapper,
 .fsuggest-content-wrapper {
@@ -3547,7 +3547,7 @@ section .profile-match-wrapper {
                right: 10px;
        }
 
-       .generic-page-wrapper, .profile_photo-content-wrapper, .videos-content-wrapper, .suggest-content-wrapper, .common-content-wrapper, .help-content-wrapper, .allfriends-content-wrapper, .match-content-wrapper, .dirfind-content-wrapper, .directory-content-wrapper, .manage-content-wrapper, .notes-content-wrapper, .message-content-wrapper, .apps-content-wrapper, #adminpage, .delegate-content-wrapper, .uexport-content-wrapper, .viewcontacts-content-wrapper, .dfrn_request-content-wrapper, .friendica-content-wrapper, .credits-content-wrapper, .nogroup-content-wrapper, .profperm-content-wrapper, .invite-content-wrapper, .tos-content-wrapper, .fsuggest-content-wrapper {
+       .generic-page-wrapper, .profile_photo-content-wrapper, .videos-content-wrapper, .suggest-content-wrapper, .common-content-wrapper, .help-content-wrapper, .allfriends-content-wrapper, .match-content-wrapper, .dirfind-content-wrapper, .directory-content-wrapper, .manage-content-wrapper, .notes-content-wrapper, .message-content-wrapper, .apps-content-wrapper, #adminpage, .delegate-content-wrapper, .uexport-content-wrapper, .dfrn_request-content-wrapper, .friendica-content-wrapper, .credits-content-wrapper, .nogroup-content-wrapper, .profperm-content-wrapper, .invite-content-wrapper, .tos-content-wrapper, .fsuggest-content-wrapper {
                border-radius: 0;
                padding: 10px;
        }
diff --git a/view/theme/frio/templates/profile/contacts.tpl b/view/theme/frio/templates/profile/contacts.tpl
new file mode 100644 (file)
index 0000000..69d34d0
--- /dev/null
@@ -0,0 +1,20 @@
+<div class="generic-page-wrapper">
+       {{include file="section_title.tpl"}}
+
+       <ul class="nav nav-tabs">
+               <li role="presentation"{{if !$type || $type == 'all'}} class="active"{{/if}}><a href="profile/{{$nickname}}/contacts">{{$all_label}}</a></li>
+               <li role="presentation"{{if $type == 'followers'}} class="active"{{/if}}><a href="profile/{{$nickname}}/contacts/followers">{{$followers_label}}</a></li>
+               <li role="presentation"{{if $type == 'following'}} class="active"{{/if}}><a href="profile/{{$nickname}}/contacts/following">{{$following_label}}</a></li>
+               <li role="presentation"{{if $type == 'mutuals'}} class="active"{{/if}}><a href="profile/{{$nickname}}/contacts/mutuals">{{$mutuals_label}}</a></li>
+       </ul>
+
+       <ul id="viewcontact_wrapper{{if $id}}-{{$id}}{{/if}}" class="viewcontact_wrapper media-list">
+{{foreach $contacts as $contact}}
+               <li>{{include file="contact_template.tpl"}}</li>
+{{/foreach}}
+       </ul>
+       <div class="clear"></div>
+       <div id="view-contact-end"></div>
+
+       {{$paginate nofilter}}
+</div>
index 9bbf00c78030af7d751e570a2d0e933a3c6aec0f..fec5d2bda57889c1d13e8c30062237e8ff94b4c6 100644 (file)
@@ -2834,10 +2834,6 @@ margin-left: 0px;
        clear: both;
 }
 
-#viewcontacts {
-       margin-top: 15px;
-}
-
 .contact-entry-wrapper .contact-entry-photo-wrapper {
        float: left;
        margin-right: 10px;