Merge pull request #8952 from annando/contact-template
Use a single function to create the template data for contacts
This commit is contained in:
commit
2b9ef97adc
|
@ -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;
|
||||
|
||||
|
@ -119,34 +117,12 @@ function common_content(App $a)
|
|||
return $o;
|
||||
}
|
||||
|
||||
$id = 0;
|
||||
|
||||
$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::getByURLForUser($common_friend['url'], local_user());
|
||||
if (!empty($contact)) {
|
||||
$entries[] = Module\Contact::getContactTemplateVars($contact);
|
||||
}
|
||||
}
|
||||
|
||||
$title = '';
|
||||
|
|
|
@ -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,33 +92,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::getByURLForUser($profile->url, local_user());
|
||||
if (!empty($contact)) {
|
||||
$entries[] = ModuleContact::getContactTemplateVars($contact);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
@ -89,25 +89,9 @@ function suggest_content(App $a)
|
|||
]);
|
||||
}
|
||||
|
||||
$id = 0;
|
||||
$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[] = ModuleContact::getContactTemplateVars($contact);
|
||||
}
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
|
||||
|
|
|
@ -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;
|
||||
|
@ -73,44 +72,12 @@ class AllFriends extends BaseModule
|
|||
return DI::l10n()->t('No friends to display.');
|
||||
}
|
||||
|
||||
$id = 0;
|
||||
|
||||
$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::getByURLForUser($friend['url'], local_user());
|
||||
if (!empty($contact)) {
|
||||
$entries[] = Contact::getContactTemplateVars($contact);
|
||||
}
|
||||
|
||||
$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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -119,66 +118,15 @@ class BaseSearch extends BaseModule
|
|||
return '';
|
||||
}
|
||||
|
||||
$id = 0;
|
||||
$entries = [];
|
||||
foreach ($results->getResults() as $result) {
|
||||
|
||||
// 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()
|
||||
);
|
||||
|
||||
$contact = Model\Contact::getByURLForUser($result->getUrl(), local_user());
|
||||
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 = [];
|
||||
$entries[] = Contact::getContactTemplateVars($contact);
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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'),
|
||||
|
@ -1009,25 +1004,27 @@ class Contact extends BaseModule
|
|||
return $o;
|
||||
}
|
||||
|
||||
public static function getContactTemplateVars(array $rr)
|
||||
/**
|
||||
* Return the fields for the contact template
|
||||
*
|
||||
* @param array $contact Contact array
|
||||
* @return array Template fields
|
||||
*/
|
||||
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;
|
||||
|
||||
|
@ -1036,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" ';
|
||||
|
@ -1044,37 +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'],
|
||||
'account_type' => Model\Contact::getAccountType($rr),
|
||||
'sparkle' => $sparkle,
|
||||
'itemurl' => ($rr['addr'] ?? '') ?: $rr['url'],
|
||||
'id' => $contact['id'],
|
||||
'url' => $url,
|
||||
'network' => ContactSelector::networkToName($rr['network'], $rr['url'], $rr['protocol']),
|
||||
'nick' => $rr['nick'],
|
||||
'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']),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user