]> git.mxchange.org Git - friendica.git/commitdiff
Use a single function to create the template data for contacts
authorMichael <heluecht@pirati.ca>
Thu, 30 Jul 2020 21:16:15 +0000 (21:16 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 30 Jul 2020 21:16:15 +0000 (21:16 +0000)
mod/common.php
mod/match.php
mod/suggest.php
src/Model/Contact.php
src/Module/AllFriends.php
src/Module/BaseSearch.php

index b59b36ee7d79267be9cff33bd8ddd0c7404d188b..29b3a9432d68832db86154949b7a75ace33c6eb8 100644 (file)
@@ -123,30 +123,10 @@ function common_content(App $a)
 
        $entries = [];
        foreach ($common_friends as $common_friend) {
-               //get further details of the contact
-               $contact_details = Model\Contact::getByURLForUser($common_friend['url'], $uid);
-
-               // $rr['id'] is needed to use contact_photo_menu()
-               /// @TODO Adding '/" here avoids E_NOTICE on missing constants
-               $common_friend['id'] = $common_friend['cid'];
-
-               $photo_menu = Model\Contact::photoMenu($common_friend);
-
-               $entry = [
-                       'url'          => Model\Contact::magicLink($common_friend['url']),
-                       'itemurl'      => ($contact_details['addr'] ?? '') ?: $common_friend['url'],
-                       'name'         => $contact_details['name'],
-                       'thumb'        => Contact::getThumb($contact_details),
-                       'img_hover'    => $contact_details['name'],
-                       'details'      => $contact_details['location'],
-                       'tags'         => $contact_details['keywords'],
-                       'about'        => $contact_details['about'],
-                       'account_type' => Model\Contact::getAccountType($contact_details),
-                       'network'      => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
-                       'photo_menu'   => $photo_menu,
-                       'id'           => ++$id,
-               ];
-               $entries[] = $entry;
+               $contact = Model\Contact::getByURL($common_friend['url']);
+               if (!empty($contact)) {
+                       $entries[] = Model\Contact::getTemplateData($contact, ++$id);
+               }
        }
 
        $title = '';
index f50a454ba9da919c05bbd578fe16ecbff70f387d..75728b7043e9f28f49b4af769f15da31e7266da8 100644 (file)
@@ -91,33 +91,10 @@ function match_content(App $a)
                                continue;
                        }
 
-                       // Workaround for wrong directory photo URL
-                       $profile->photo = str_replace('http:///photo/', Search::getGlobalDirectory() . '/photo/', $profile->photo);
-
-                       $connlnk = DI::baseUrl() . '/follow/?url=' . $profile->url;
-                       $photo_menu = [
-                               'profile' => [DI::l10n()->t("View Profile"), Contact::magicLink($profile->url)],
-                               'follow' => [DI::l10n()->t("Connect/Follow"), $connlnk]
-                       ];
-
-                       $contact_details = Contact::getByURL($profile->url, false);
-
-                       $entry = [
-                               'url'          => Contact::magicLink($profile->url),
-                               'itemurl'      => $contact_details['addr'] ?? $profile->url,
-                               'name'         => $profile->name,
-                               'details'      => $contact_details['location'] ?? '',
-                               'tags'         => $contact_details['keywords'] ?? '',
-                               'about'        => $contact_details['about'] ?? '',
-                               'account_type' => Contact::getAccountType($contact_details),
-                               'thumb'        => Contact::getThumb($contact_details, $profile->photo),
-                               'conntxt'      => DI::l10n()->t('Connect'),
-                               'connlnk'      => $connlnk,
-                               'img_hover'    => $profile->tags,
-                               'photo_menu'   => $photo_menu,
-                               'id'           => $i,
-                       ];
-                       $entries[] = $entry;
+                       $contact = Contact::getByURL($profile->url);
+                       if (!empty($contact)) {
+                               $entries[] = Contact::getTemplateData($contact, $i);
+                       }
                }
 
                $data = [
index f3421de47e420f84256d13facef3a1fc86c421ff..c818bd010ec977fb4cd1c508c20644ee5b7d3d5c 100644 (file)
@@ -93,21 +93,7 @@ function suggest_content(App $a)
        $entries = [];
 
        foreach ($contacts as $contact) {
-               $entry = [
-                       'url'          => Contact::magicLink($contact['url']),
-                       'itemurl'      => $contact['addr'] ?: $contact['url'],
-                       'name'         => $contact['name'],
-                       'thumb'        => Contact::getThumb($contact),
-                       'img_hover'    => $contact['url'],
-                       'details'      => $contact['location'],
-                       'tags'         => $contact['keywords'],
-                       'about'        => $contact['about'],
-                       'account_type' => Contact::getAccountType($contact),
-                       'network'      => ContactSelector::networkToName($contact['network'], $contact['url']),
-                       'photo_menu'   => Contact::photoMenu($contact),
-                       'id'           => ++$id,
-               ];
-               $entries[] = $entry;
+               $entries[] = Contact::getTemplateData($contact, ++$id);
        }
 
        $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
index 9ebc12375a1aa161ed63ba283af38b5d431bd269..cceab3a02fc34c11a8ec3d74ca948f039f04c71c 100644 (file)
@@ -22,6 +22,7 @@
 namespace Friendica\Model;
 
 use Friendica\App\BaseURL;
+use Friendica\Content\ContactSelector;
 use Friendica\Content\Pager;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
@@ -3068,4 +3069,22 @@ class Contact
 
                return array_slice($contacts, $start, $limit);
        }
+
+       public static function getTemplateData(array $contact, int $id)
+       {
+               return [
+                       'url'          => self::magicLink($contact['url']),
+                       'itemurl'      => $contact['addr'] ?: $contact['url'],
+                       'name'         => $contact['name'],
+                       'thumb'        => self::getThumb($contact),
+                       'img_hover'    => $contact['url'],
+                       'details'      => $contact['location'],
+                       'tags'         => $contact['keywords'],
+                       'about'        => $contact['about'],
+                       'account_type' => self::getAccountType($contact),
+                       'network'      => ContactSelector::networkToName($contact['network'], $contact['url']),
+                       'photo_menu'   => self::photoMenu($contact),
+                       'id'           => $id,
+               ];
+       }
 }
index 1c254b209488d8e32323ed11dc4b4e3c284d0622..10d33134654e593451a0dd037a598913d343269b 100644 (file)
@@ -77,40 +77,10 @@ class AllFriends extends BaseModule
 
                $entries = [];
                foreach ($friends as $friend) {
-                       //get further details of the contact
-                       $contactDetails = Model\Contact::getByURLForUser($friend['url'], $uid) ?: $friend;
-
-                       $connlnk = '';
-                       // $friend[cid] is only available for common contacts. So if the contact is a common one, use contact_photo_menu to generate the photoMenu
-                       // If the contact is not common to the user, Connect/Follow' will be added to the photo menu
-                       if ($friend['cid']) {
-                               $friend['id'] = $friend['cid'];
-                               $photoMenu = Model\Contact::photoMenu($friend);
-                       } else {
-                               $connlnk = DI::baseUrl()->get() . '/follow/?url=' . $friend['url'];
-                               $photoMenu = [
-                                       'profile' => [DI::l10n()->t('View Profile'), Model\Contact::magicLinkbyId($friend['id'], $friend['url'])],
-                                       'follow'  => [DI::l10n()->t('Connect/Follow'), $connlnk]
-                               ];
+                       $contact = Model\Contact::getByURL($friend['url']);
+                       if (!empty($contact)) {
+                               $entries[] = Model\Contact::getTemplateData($contact, ++$id);
                        }
-
-                       $entry = [
-                               'url'          => Model\Contact::magicLinkbyId($friend['id'], $friend['url']),
-                               'itemurl'      => ($contactDetails['addr'] ?? '') ?: $friend['url'],
-                               'name'         => $contactDetails['name'],
-                               'thumb'        => Model\Contact::getThumb($contactDetails),
-                               'img_hover'    => $contactDetails['name'],
-                               'details'      => $contactDetails['location'],
-                               'tags'         => $contactDetails['keywords'],
-                               'about'        => $contactDetails['about'],
-                               'account_type' => Model\Contact::getAccountType($contactDetails),
-                               'network'      => ContactSelector::networkToName($contactDetails['network'], $contactDetails['url']),
-                               'photoMenu'    => $photoMenu,
-                               'conntxt'      => DI::l10n()->t('Connect'),
-                               'connlnk'      => $connlnk,
-                               'id'           => ++$id,
-                       ];
-                       $entries[] = $entry;
                }
 
                $tab_str = Contact::getTabsHTML($app, $contact, 4);
index 08970f67d77d52417cbdbcdd5dd5aab8d327e358..594f5620554e66e44ae67ebcb733a55cc205fce4 100644 (file)
@@ -125,60 +125,10 @@ class BaseSearch extends BaseModule
 
                        // in case the result is a contact result, add a contact-specific entry
                        if ($result instanceof ContactResult) {
-
-                               $alt_text    = '';
-                               $location    = '';
-                               $about       = '';
-                               $accountType = '';
-                               $photo_menu  = [];
-
-                               // If We already know this contact then don't show the "connect" button
-                               if ($result->getCid() > 0 || $result->getPCid() > 0) {
-                                       $connLink = "";
-                                       $connTxt  = "";
-                                       $contact  = Model\Contact::getById(
-                                               ($result->getCid() > 0) ? $result->getCid() : $result->getPCid()
-                                       );
-
-                                       if (!empty($contact)) {
-                                               $photo_menu  = Model\Contact::photoMenu($contact);
-                                               $details     = Contact::getContactTemplateVars($contact);
-                                               $alt_text    = $details['alt_text'];
-                                               $location    = $contact['location'];
-                                               $about       = $contact['about'];
-                                               $accountType = Model\Contact::getAccountType($contact);
-                                       } else {
-                                               $photo_menu = [];
-                                       }
-                               } else {
-                                       $connLink = DI::baseUrl()->get() . '/follow/?url=' . $result->getUrl();
-                                       $connTxt  = DI::l10n()->t('Connect');
-
-                                       $photo_menu['profile'] = [DI::l10n()->t("View Profile"), Model\Contact::magicLink($result->getUrl())];
-                                       $photo_menu['follow']  = [DI::l10n()->t("Connect/Follow"), $connLink];
-                               }
-
-                               $photo = str_replace("http:///photo/", Search::getGlobalDirectory() . "/photo/", $result->getPhoto());
                                $contact = Model\Contact::getByURL($result->getUrl());
-
-                               $entry     = [
-                                       'alt_text'     => $alt_text,
-                                       'url'          => Model\Contact::magicLink($result->getUrl()),
-                                       'itemurl'      => $result->getItem(),
-                                       'name'         => $contact['name'] ?? $result->getName(),
-                                       'thumb'        => Model\Contact::getThumb($contact, $photo),
-                                       'img_hover'    => $result->getTags(),
-                                       'conntxt'      => $connTxt,
-                                       'connlnk'      => $connLink,
-                                       'photo_menu'   => $photo_menu,
-                                       'details'      => $location,
-                                       'tags'         => $result->getTags(),
-                                       'about'        => $about,
-                                       'account_type' => $accountType,
-                                       'network'      => ContactSelector::networkToName($result->getNetwork(), $result->getUrl()),
-                                       'id'           => ++$id,
-                               ];
-                               $entries[] = $entry;
+                               if (!empty($contact)) {
+                                       $entries[] = Model\Contact::getTemplateData($contact, ++$id);
+                               }
                        }
                }