7 use Friendica\Content\Widget;
8 use Friendica\Core\Config;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\Search;
11 use Friendica\Database\DBA;
13 use Friendica\Model\Contact;
14 use Friendica\Model\Profile;
15 use Friendica\Util\Network;
16 use Friendica\Util\Proxy as ProxyUtils;
19 * Controller for /match.
21 * It takes keywords from your profile and queries the directory server for
22 * matching keywords from other profiles.
27 * @throws ImagickException
28 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
31 function match_content(App $a)
37 DI::page()['aside'] .= Widget::findPeople();
38 DI::page()['aside'] .= Widget::follow();
40 $_SESSION['return_path'] = DI::args()->getCommand();
42 $profile = Profile::getByUID(local_user());
44 if (!DBA::isResult($profile)) {
47 if (!$profile['pub_keywords'] && (!$profile['prv_keywords'])) {
48 notice(DI::l10n()->t('No keywords to match. Please add keywords to your default profile.') . EOL);
53 $tags = trim($profile['pub_keywords'] . ' ' . $profile['prv_keywords']);
58 if (strlen(Config::get('system', 'directory'))) {
59 $host = Search::getGlobalDirectory();
61 $host = DI::baseUrl();
64 $msearch_json = Network::post($host . '/msearch', $params)->getBody();
66 $msearch = json_decode($msearch_json);
68 $start = $_GET['start'] ?? 0;
72 if (!empty($msearch->results)) {
73 for ($i = $start;count($entries) < 10 && $i < $msearch->total; $i++) {
74 $profile = $msearch->results[$i];
76 // Already known contact
77 if (!$profile || Contact::getIdForURL($profile->url, local_user(), true)) {
81 // Workaround for wrong directory photo URL
82 $profile->photo = str_replace('http:///photo/', Search::getGlobalDirectory() . '/photo/', $profile->photo);
84 $connlnk = DI::baseUrl() . '/follow/?url=' . $profile->url;
86 'profile' => [DI::l10n()->t("View Profile"), Contact::magicLink($profile->url)],
87 'follow' => [DI::l10n()->t("Connect/Follow"), $connlnk]
90 $contact_details = Contact::getDetailsByURL($profile->url, 0);
93 'url' => Contact::magicLink($profile->url),
94 'itemurl' => $contact_details['addr'] ?? $profile->url,
95 'name' => $profile->name,
96 'details' => $contact_details['location'] ?? '',
97 'tags' => $contact_details['keywords'] ?? '',
98 'about' => $contact_details['about'] ?? '',
99 'account_type' => Contact::getAccountType($contact_details),
100 'thumb' => ProxyUtils::proxifyUrl($profile->photo, false, ProxyUtils::SIZE_THUMB),
101 'conntxt' => DI::l10n()->t('Connect'),
102 'connlnk' => $connlnk,
103 'img_hover' => $profile->tags,
104 'photo_menu' => $photo_menu,
114 'text' => DI::l10n()->t('first'),
115 'class' => 'previous' . ($start == 0 ? 'disabled' : '')
118 'url' => 'match?start=' . $i,
119 'text' => DI::l10n()->t('next'),
120 'class' => 'next' . ($i >= $msearch->total ? ' disabled' : '')
124 $tpl = Renderer::getMarkupTemplate('paginate.tpl');
125 $paginate = Renderer::replaceMacros($tpl, ['pager' => $data]);
128 if (empty($entries)) {
129 info(DI::l10n()->t('No matches') . EOL);
132 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
133 $o = Renderer::replaceMacros($tpl, [
134 '$title' => DI::l10n()->t('Profile Match'),
135 '$contacts' => $entries,
136 '$paginate' => $paginate