Use the function from the contact template instead

This commit is contained in:
Michael 2020-07-31 03:55:01 +00:00
parent 91b0f2c486
commit 893f6bd692
7 changed files with 23 additions and 33 deletions

View File

@ -20,13 +20,11 @@
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Content\ContactSelector;
use Friendica\Content\Pager; use Friendica\Content\Pager;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model; use Friendica\Model;
use Friendica\Model\Contact;
use Friendica\Module; use Friendica\Module;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -123,9 +121,9 @@ function common_content(App $a)
$entries = []; $entries = [];
foreach ($common_friends as $common_friend) { 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)) { if (!empty($contact)) {
$entries[] = Model\Contact::getTemplateData($contact, ++$id); $entries[] = Module\Contact::getContactTemplateVars($contact, ++$id);
} }
} }

View File

@ -27,6 +27,7 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Module\Contact as ModuleContact;
/** /**
* Controller for /match. * Controller for /match.
@ -91,9 +92,9 @@ function match_content(App $a)
continue; continue;
} }
$contact = Contact::getByURL($profile->url); $contact = Contact::getByURLForUser($profile->url, local_user());
if (!empty($contact)) { if (!empty($contact)) {
$entries[] = Contact::getTemplateData($contact, $i); $entries[] = ModuleContact::getContactTemplateVars($contact, $i);
} }
} }

View File

@ -20,12 +20,12 @@
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Content\ContactSelector;
use Friendica\Content\Widget; use Friendica\Content\Widget;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Module\Contact as ModuleContact;
function suggest_init(App $a) function suggest_init(App $a)
{ {
@ -93,7 +93,7 @@ function suggest_content(App $a)
$entries = []; $entries = [];
foreach ($contacts as $contact) { foreach ($contacts as $contact) {
$entries[] = Contact::getTemplateData($contact, ++$id); $entries[] = ModuleContact::getContactTemplateVars($contact, ++$id);
} }
$tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl'); $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');

View File

@ -3069,22 +3069,4 @@ class Contact
return array_slice($contacts, $start, $limit); 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,
];
}
} }

View File

@ -22,7 +22,6 @@
namespace Friendica\Module; namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Content\ContactSelector;
use Friendica\Content\Pager; use Friendica\Content\Pager;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\DI; use Friendica\DI;
@ -77,9 +76,9 @@ class AllFriends extends BaseModule
$entries = []; $entries = [];
foreach ($friends as $friend) { foreach ($friends as $friend) {
$contact = Model\Contact::getByURL($friend['url']); $contact = Model\Contact::getByURLForUser($friend['url'], local_user());
if (!empty($contact)) { if (!empty($contact)) {
$entries[] = Model\Contact::getTemplateData($contact, ++$id); $entries[] = Contact::getContactTemplateVars($contact, ++$id);
} }
} }

View File

@ -22,7 +22,6 @@
namespace Friendica\Module; namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Content\ContactSelector;
use Friendica\Content\Pager; use Friendica\Content\Pager;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\Search; 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 // in case the result is a contact result, add a contact-specific entry
if ($result instanceof ContactResult) { if ($result instanceof ContactResult) {
$contact = Model\Contact::getByURL($result->getUrl()); $contact = Model\Contact::getByURLForUser($result->getUrl(), local_user());
if (!empty($contact)) { if (!empty($contact)) {
$entries[] = Model\Contact::getTemplateData($contact, ++$id); $entries[] = Contact::getContactTemplateVars($contact, ++$id);
} }
} }
} }

View File

@ -1009,7 +1009,14 @@ class Contact extends BaseModule
return $o; 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 = ''; $dir_icon = '';
$alt_text = ''; $alt_text = '';
@ -1069,12 +1076,16 @@ class Contact extends BaseModule
'thumb' => Model\Contact::getThumb($rr), 'thumb' => Model\Contact::getThumb($rr),
'name' => $rr['name'], 'name' => $rr['name'],
'username' => $rr['name'], 'username' => $rr['name'],
'details' => $rr['location'],
'tags' => $rr['keywords'],
'about' => $rr['about'],
'account_type' => Model\Contact::getAccountType($rr), 'account_type' => Model\Contact::getAccountType($rr),
'sparkle' => $sparkle, 'sparkle' => $sparkle,
'itemurl' => ($rr['addr'] ?? '') ?: $rr['url'], 'itemurl' => ($rr['addr'] ?? '') ?: $rr['url'],
'url' => $url, 'url' => $url,
'network' => ContactSelector::networkToName($rr['network'], $rr['url'], $rr['protocol']), 'network' => ContactSelector::networkToName($rr['network'], $rr['url'], $rr['protocol']),
'nick' => $rr['nick'], 'nick' => $rr['nick'],
'id' => $id,
]; ];
} }