From 91b0f2c486840035d021d53fc5cdc1c5932283ca Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 30 Jul 2020 21:16:15 +0000 Subject: [PATCH 1/7] Use a single function to create the template data for contacts --- mod/common.php | 28 +++----------------- mod/match.php | 31 +++------------------- mod/suggest.php | 16 +---------- src/Model/Contact.php | 19 +++++++++++++ src/Module/AllFriends.php | 36 +++---------------------- src/Module/BaseSearch.php | 56 +++------------------------------------ 6 files changed, 34 insertions(+), 152 deletions(-) diff --git a/mod/common.php b/mod/common.php index b59b36ee7d..29b3a9432d 100644 --- a/mod/common.php +++ b/mod/common.php @@ -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 = ''; diff --git a/mod/match.php b/mod/match.php index f50a454ba9..75728b7043 100644 --- a/mod/match.php +++ b/mod/match.php @@ -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 = [ diff --git a/mod/suggest.php b/mod/suggest.php index f3421de47e..c818bd010e 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -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'); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 9ebc12375a..cceab3a02f 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -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, + ]; + } } diff --git a/src/Module/AllFriends.php b/src/Module/AllFriends.php index 1c254b2094..10d3313465 100644 --- a/src/Module/AllFriends.php +++ b/src/Module/AllFriends.php @@ -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); diff --git a/src/Module/BaseSearch.php b/src/Module/BaseSearch.php index 08970f67d7..594f562055 100644 --- a/src/Module/BaseSearch.php +++ b/src/Module/BaseSearch.php @@ -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); + } } } From 893f6bd692efa94202dd472ea160eef68a420cf9 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 31 Jul 2020 03:55:01 +0000 Subject: [PATCH 2/7] Use the function from the contact template instead --- mod/common.php | 6 ++---- mod/match.php | 5 +++-- mod/suggest.php | 4 ++-- src/Model/Contact.php | 18 ------------------ src/Module/AllFriends.php | 5 ++--- src/Module/BaseSearch.php | 5 ++--- src/Module/Contact.php | 13 ++++++++++++- 7 files changed, 23 insertions(+), 33 deletions(-) diff --git a/mod/common.php b/mod/common.php index 29b3a9432d..edcb81983f 100644 --- a/mod/common.php +++ b/mod/common.php @@ -20,13 +20,11 @@ */ use Friendica\App; -use Friendica\Content\ContactSelector; use Friendica\Content\Pager; use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model; -use Friendica\Model\Contact; use Friendica\Module; use Friendica\Util\Strings; @@ -123,9 +121,9 @@ function common_content(App $a) $entries = []; foreach ($common_friends as $common_friend) { - $contact = Model\Contact::getByURL($common_friend['url']); + $contact = Model\Contact::getByURLForUser($common_friend['url'], local_user()); if (!empty($contact)) { - $entries[] = Model\Contact::getTemplateData($contact, ++$id); + $entries[] = Module\Contact::getContactTemplateVars($contact, ++$id); } } diff --git a/mod/match.php b/mod/match.php index 75728b7043..6a2e350bcc 100644 --- a/mod/match.php +++ b/mod/match.php @@ -27,6 +27,7 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Profile; +use Friendica\Module\Contact as ModuleContact; /** * Controller for /match. @@ -91,9 +92,9 @@ function match_content(App $a) continue; } - $contact = Contact::getByURL($profile->url); + $contact = Contact::getByURLForUser($profile->url, local_user()); if (!empty($contact)) { - $entries[] = Contact::getTemplateData($contact, $i); + $entries[] = ModuleContact::getContactTemplateVars($contact, $i); } } diff --git a/mod/suggest.php b/mod/suggest.php index c818bd010e..03d0e77fc7 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -20,12 +20,12 @@ */ use Friendica\App; -use Friendica\Content\ContactSelector; use Friendica\Content\Widget; use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; +use Friendica\Module\Contact as ModuleContact; function suggest_init(App $a) { @@ -93,7 +93,7 @@ function suggest_content(App $a) $entries = []; foreach ($contacts as $contact) { - $entries[] = Contact::getTemplateData($contact, ++$id); + $entries[] = ModuleContact::getContactTemplateVars($contact, ++$id); } $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl'); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index cceab3a02f..7443d32a2e 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -3069,22 +3069,4 @@ 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, - ]; - } } diff --git a/src/Module/AllFriends.php b/src/Module/AllFriends.php index 10d3313465..30418f5c2a 100644 --- a/src/Module/AllFriends.php +++ b/src/Module/AllFriends.php @@ -22,7 +22,6 @@ namespace Friendica\Module; use Friendica\BaseModule; -use Friendica\Content\ContactSelector; use Friendica\Content\Pager; use Friendica\Core\Renderer; use Friendica\DI; @@ -77,9 +76,9 @@ class AllFriends extends BaseModule $entries = []; foreach ($friends as $friend) { - $contact = Model\Contact::getByURL($friend['url']); + $contact = Model\Contact::getByURLForUser($friend['url'], local_user()); if (!empty($contact)) { - $entries[] = Model\Contact::getTemplateData($contact, ++$id); + $entries[] = Contact::getContactTemplateVars($contact, ++$id); } } diff --git a/src/Module/BaseSearch.php b/src/Module/BaseSearch.php index 594f562055..5863a94050 100644 --- a/src/Module/BaseSearch.php +++ b/src/Module/BaseSearch.php @@ -22,7 +22,6 @@ namespace Friendica\Module; use Friendica\BaseModule; -use Friendica\Content\ContactSelector; use Friendica\Content\Pager; use Friendica\Core\Renderer; use Friendica\Core\Search; @@ -125,9 +124,9 @@ class BaseSearch extends BaseModule // in case the result is a contact result, add a contact-specific entry if ($result instanceof ContactResult) { - $contact = Model\Contact::getByURL($result->getUrl()); + $contact = Model\Contact::getByURLForUser($result->getUrl(), local_user()); if (!empty($contact)) { - $entries[] = Model\Contact::getTemplateData($contact, ++$id); + $entries[] = Contact::getContactTemplateVars($contact, ++$id); } } } diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 3fa89cde91..2d06aa3240 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -1009,7 +1009,14 @@ class Contact extends BaseModule return $o; } - public static function getContactTemplateVars(array $rr) + /** + * Return the fields for the contact template + * + * @param array $rr Contact array + * @param integer $id + * @return array Template fields + */ + public static function getContactTemplateVars(array $rr, int $id = 0) { $dir_icon = ''; $alt_text = ''; @@ -1069,12 +1076,16 @@ class Contact extends BaseModule 'thumb' => Model\Contact::getThumb($rr), 'name' => $rr['name'], 'username' => $rr['name'], + 'details' => $rr['location'], + 'tags' => $rr['keywords'], + 'about' => $rr['about'], 'account_type' => Model\Contact::getAccountType($rr), 'sparkle' => $sparkle, 'itemurl' => ($rr['addr'] ?? '') ?: $rr['url'], 'url' => $url, 'network' => ContactSelector::networkToName($rr['network'], $rr['url'], $rr['protocol']), 'nick' => $rr['nick'], + 'id' => $id, ]; } From 48424334490b23b47fedbd58460f93f29a078be7 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 31 Jul 2020 03:58:19 +0000 Subject: [PATCH 3/7] Unused "use" removed --- src/Model/Contact.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 7443d32a2e..9ebc12375a 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -22,7 +22,6 @@ namespace Friendica\Model; use Friendica\App\BaseURL; -use Friendica\Content\ContactSelector; use Friendica\Content\Pager; use Friendica\Core\Hook; use Friendica\Core\Logger; From a4b5536d17559263f3395d8affc4bd0363abfbd7 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 31 Jul 2020 04:19:20 +0000 Subject: [PATCH 4/7] The local directory is now using the template function as well --- src/Module/Directory.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Module/Directory.php b/src/Module/Directory.php index 38be89b93c..93d14cc176 100644 --- a/src/Module/Directory.php +++ b/src/Module/Directory.php @@ -29,7 +29,7 @@ use Friendica\Core\Hook; use Friendica\Core\Session; use Friendica\Core\Renderer; use Friendica\DI; -use Friendica\Model\Contact; +use Friendica\Model; use Friendica\Model\Profile; use Friendica\Network\HTTPException; use Friendica\Util\Strings; @@ -83,7 +83,10 @@ class Directory extends BaseModule } foreach ($profiles['entries'] as $entry) { - $entries[] = self::formatEntry($entry, $photo); + $contact = Model\Contact::getByURLForUser($entry['url'], local_user()); + if (!empty($contact)) { + $entries[] = Contact::getContactTemplateVars($contact); + } } } @@ -160,18 +163,18 @@ class Directory extends BaseModule $location_e = $location; $photo_menu = [ - 'profile' => [DI::l10n()->t("View Profile"), Contact::magicLink($profile_link)] + 'profile' => [DI::l10n()->t("View Profile"), Model\Contact::magicLink($profile_link)] ]; $entry = [ 'id' => $contact['id'], - 'url' => Contact::magicLink($profile_link), + 'url' => Model\Contact::magicLink($profile_link), 'itemurl' => $itemurl, - 'thumb' => Contact::getThumb($contact), + 'thumb' => Model\Contact::getThumb($contact), 'img_hover' => $contact['name'], 'name' => $contact['name'], 'details' => $details, - 'account_type' => Contact::getAccountType($contact), + 'account_type' => Model\Contact::getAccountType($contact), 'profile' => $profile, 'location' => $location_e, 'tags' => $contact['pub_keywords'], From ce7f192f35cb0493c96283fac701d51bd30dc777 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 31 Jul 2020 04:28:26 +0000 Subject: [PATCH 5/7] "id" is not needed as a parameter --- mod/common.php | 4 +--- mod/match.php | 2 +- mod/suggest.php | 4 +--- src/Module/AllFriends.php | 4 +--- src/Module/BaseSearch.php | 3 +-- src/Module/Contact.php | 3 +-- 6 files changed, 6 insertions(+), 14 deletions(-) diff --git a/mod/common.php b/mod/common.php index edcb81983f..7d9caf8d1e 100644 --- a/mod/common.php +++ b/mod/common.php @@ -117,13 +117,11 @@ function common_content(App $a) return $o; } - $id = 0; - $entries = []; foreach ($common_friends as $common_friend) { $contact = Model\Contact::getByURLForUser($common_friend['url'], local_user()); if (!empty($contact)) { - $entries[] = Module\Contact::getContactTemplateVars($contact, ++$id); + $entries[] = Module\Contact::getContactTemplateVars($contact); } } diff --git a/mod/match.php b/mod/match.php index 6a2e350bcc..8e0baacd1e 100644 --- a/mod/match.php +++ b/mod/match.php @@ -94,7 +94,7 @@ function match_content(App $a) $contact = Contact::getByURLForUser($profile->url, local_user()); if (!empty($contact)) { - $entries[] = ModuleContact::getContactTemplateVars($contact, $i); + $entries[] = ModuleContact::getContactTemplateVars($contact); } } diff --git a/mod/suggest.php b/mod/suggest.php index 03d0e77fc7..d501e3a3f2 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -89,11 +89,9 @@ function suggest_content(App $a) ]); } - $id = 0; $entries = []; - foreach ($contacts as $contact) { - $entries[] = ModuleContact::getContactTemplateVars($contact, ++$id); + $entries[] = ModuleContact::getContactTemplateVars($contact); } $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl'); diff --git a/src/Module/AllFriends.php b/src/Module/AllFriends.php index 30418f5c2a..68a4f304e6 100644 --- a/src/Module/AllFriends.php +++ b/src/Module/AllFriends.php @@ -72,13 +72,11 @@ class AllFriends extends BaseModule return DI::l10n()->t('No friends to display.'); } - $id = 0; - $entries = []; foreach ($friends as $friend) { $contact = Model\Contact::getByURLForUser($friend['url'], local_user()); if (!empty($contact)) { - $entries[] = Contact::getContactTemplateVars($contact, ++$id); + $entries[] = Contact::getContactTemplateVars($contact); } } diff --git a/src/Module/BaseSearch.php b/src/Module/BaseSearch.php index 5863a94050..77abae007a 100644 --- a/src/Module/BaseSearch.php +++ b/src/Module/BaseSearch.php @@ -118,7 +118,6 @@ class BaseSearch extends BaseModule return ''; } - $id = 0; $entries = []; foreach ($results->getResults() as $result) { @@ -126,7 +125,7 @@ class BaseSearch extends BaseModule if ($result instanceof ContactResult) { $contact = Model\Contact::getByURLForUser($result->getUrl(), local_user()); if (!empty($contact)) { - $entries[] = Contact::getContactTemplateVars($contact, ++$id); + $entries[] = Contact::getContactTemplateVars($contact); } } } diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 2d06aa3240..310bf8029b 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -1016,7 +1016,7 @@ class Contact extends BaseModule * @param integer $id * @return array Template fields */ - public static function getContactTemplateVars(array $rr, int $id = 0) + public static function getContactTemplateVars(array $rr) { $dir_icon = ''; $alt_text = ''; @@ -1085,7 +1085,6 @@ class Contact extends BaseModule 'url' => $url, 'network' => ContactSelector::networkToName($rr['network'], $rr['url'], $rr['protocol']), 'nick' => $rr['nick'], - 'id' => $id, ]; } From 45aff10ff866787f2ddf9fa98b435e82410f3278 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 31 Jul 2020 04:50:24 +0000 Subject: [PATCH 6/7] Replaced with general function --- src/Module/Profile/Contacts.php | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/Module/Profile/Contacts.php b/src/Module/Profile/Contacts.php index e7931bdb02..e55c0d9a84 100644 --- a/src/Module/Profile/Contacts.php +++ b/src/Module/Profile/Contacts.php @@ -21,7 +21,6 @@ namespace Friendica\Module\Profile; -use Friendica\Content\ContactSelector; use Friendica\Content\Nav; use Friendica\Content\Pager; use Friendica\Core\Protocol; @@ -29,9 +28,9 @@ use Friendica\Core\Renderer; use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Module\BaseProfile; +use Friendica\Module\Contact as ModuleContact; class Contacts extends BaseProfile { @@ -101,25 +100,7 @@ class Contacts extends BaseProfile if ($contact['self']) { continue; } - - $contact_details = Contact::getByURLForUser($contact['url'], $a->profile['uid']) ?: $contact; - - $contacts[] = [ - 'id' => $contact['id'], - 'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']), - 'photo_menu' => Contact::photoMenu($contact), - 'thumb' => Contact::getThumb($contact_details), - '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'], $contact['protocol']), - ]; + $contacts[] = ModuleContact::getContactTemplateVars($contact); } DBA::close($contacts_stmt); From 71415094cb92de900926639bec1b3a8e2982c57e Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 31 Jul 2020 06:00:43 +0000 Subject: [PATCH 7/7] Removed unused template variables --- src/Module/Contact.php | 62 ++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 310bf8029b..40148c50d1 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -483,21 +483,17 @@ class Contact extends BaseModule $contact['blocked'] = Model\Contact::isBlockedByUser($contact['id'], local_user()); $contact['readonly'] = Model\Contact::isIgnoredByUser($contact['id'], local_user()); - $dir_icon = ''; $relation_text = ''; switch ($contact['rel']) { case Model\Contact::FRIEND: - $dir_icon = 'images/lrarrow.gif'; $relation_text = DI::l10n()->t('You are mutual friends with %s'); break; case Model\Contact::FOLLOWER; - $dir_icon = 'images/larrow.gif'; $relation_text = DI::l10n()->t('You are sharing with %s'); break; case Model\Contact::SHARING; - $dir_icon = 'images/rarrow.gif'; $relation_text = DI::l10n()->t('%s is sharing with you'); break; @@ -612,7 +608,6 @@ class Contact extends BaseModule '$ffi_keyword_denylist' => ['ffi_keyword_denylist', DI::l10n()->t('Keyword Deny List'), $contact['ffi_keyword_denylist'], DI::l10n()->t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')], '$photo' => Model\Contact::getPhoto($contact), '$name' => $contact['name'], - '$dir_icon' => $dir_icon, '$sparkle' => $sparkle, '$url' => $url, '$profileurllabel'=> DI::l10n()->t('Profile URL'), @@ -1012,29 +1007,24 @@ class Contact extends BaseModule /** * Return the fields for the contact template * - * @param array $rr Contact array - * @param integer $id + * @param array $contact Contact array * @return array Template fields */ - public static function getContactTemplateVars(array $rr) + public static function getContactTemplateVars(array $contact) { - $dir_icon = ''; $alt_text = ''; - if (!empty($rr['uid']) && !empty($rr['rel'])) { - switch ($rr['rel']) { + if (!empty($contact['uid']) && !empty($contact['rel'])) { + switch ($contact['rel']) { case Model\Contact::FRIEND: - $dir_icon = 'images/lrarrow.gif'; $alt_text = DI::l10n()->t('Mutual Friendship'); break; case Model\Contact::FOLLOWER; - $dir_icon = 'images/larrow.gif'; $alt_text = DI::l10n()->t('is a fan of yours'); break; case Model\Contact::SHARING; - $dir_icon = 'images/rarrow.gif'; $alt_text = DI::l10n()->t('you are a fan of'); break; @@ -1043,7 +1033,7 @@ class Contact extends BaseModule } } - $url = Model\Contact::magicLink($rr['url']); + $url = Model\Contact::magicLink($contact['url']); if (strpos($url, 'redir/') === 0) { $sparkle = ' class="sparkle" '; @@ -1051,40 +1041,36 @@ class Contact extends BaseModule $sparkle = ''; } - if ($rr['pending']) { - if (in_array($rr['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) { + if ($contact['pending']) { + if (in_array($contact['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) { $alt_text = DI::l10n()->t('Pending outgoing contact request'); } else { $alt_text = DI::l10n()->t('Pending incoming contact request'); } } - if ($rr['self']) { - $dir_icon = 'images/larrow.gif'; + if ($contact['self']) { $alt_text = DI::l10n()->t('This is you'); - $url = $rr['url']; + $url = $contact['url']; $sparkle = ''; } return [ - 'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $rr['name'], $rr['url']), - 'edit_hover'=> DI::l10n()->t('Edit contact'), - 'photo_menu'=> Model\Contact::photoMenu($rr), - 'id' => $rr['id'], - 'alt_text' => $alt_text, - 'dir_icon' => $dir_icon, - 'thumb' => Model\Contact::getThumb($rr), - 'name' => $rr['name'], - 'username' => $rr['name'], - 'details' => $rr['location'], - 'tags' => $rr['keywords'], - 'about' => $rr['about'], - 'account_type' => Model\Contact::getAccountType($rr), - 'sparkle' => $sparkle, - 'itemurl' => ($rr['addr'] ?? '') ?: $rr['url'], - 'url' => $url, - 'network' => ContactSelector::networkToName($rr['network'], $rr['url'], $rr['protocol']), - 'nick' => $rr['nick'], + 'id' => $contact['id'], + 'url' => $url, + 'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $contact['name'], $contact['url']), + 'photo_menu' => Model\Contact::photoMenu($contact), + 'thumb' => Model\Contact::getThumb($contact), + 'alt_text' => $alt_text, + 'name' => $contact['name'], + 'nick' => $contact['nick'], + 'details' => $contact['location'], + 'tags' => $contact['keywords'], + 'about' => $contact['about'], + 'account_type' => Model\Contact::getAccountType($contact), + 'sparkle' => $sparkle, + 'itemurl' => ($contact['addr'] ?? '') ?: $contact['url'], + 'network' => ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol']), ]; }