7 use Friendica\Content\Pager;
8 use Friendica\Content\Widget;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Renderer;
12 use Friendica\Core\System;
13 use Friendica\Database\DBA;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Profile;
16 use Friendica\Util\Network;
17 use Friendica\Util\Proxy as ProxyUtils;
20 * @brief Controller for /match.
22 * It takes keywords from your profile and queries the directory server for
23 * matching keywords from other profiles.
28 * @throws ImagickException
29 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
32 function match_content(App $a)
38 $a->page['aside'] .= Widget::findPeople();
39 $a->page['aside'] .= Widget::follow();
41 $_SESSION['return_path'] = $a->cmd;
43 $profile = Profile::getByUID(local_user());
45 if (!DBA::isResult($profile)) {
48 if (!$profile['pub_keywords'] && (!$profile['prv_keywords'])) {
49 notice(L10n::t('No keywords to match. Please add keywords to your default profile.') . EOL);
54 $tags = trim($profile['pub_keywords'] . ' ' . $profile['prv_keywords']);
59 if (strlen(Config::get('system', 'directory'))) {
62 $host = System::baseUrl();
65 $msearch_json = Network::post($host . '/msearch', $params)->getBody();
67 $msearch = json_decode($msearch_json);
69 $start = $_GET['start'] ?? 0;
73 if (!empty($msearch->results)) {
74 for ($i = $start;count($entries) < 10 && $i < $msearch->total; $i++) {
75 $profile = $msearch->results[$i];
77 // Already known contact
78 if (!$profile || Contact::getIdForURL($profile->url, local_user(), true)) {
82 // Workaround for wrong directory photo URL
83 $profile->photo = str_replace('http:///photo/', get_server() . '/photo/', $profile->photo);
85 $connlnk = System::baseUrl() . '/follow/?url=' . $profile->url;
87 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile->url)],
88 'follow' => [L10n::t("Connect/Follow"), $connlnk]
91 $contact_details = Contact::getDetailsByURL($profile->url, 0);
94 'url' => Contact::magicLink($profile->url),
95 'itemurl' => $contact_details['addr'] ?? $profile->url,
96 'name' => $profile->name,
97 'details' => $contact_details['location'] ?? '',
98 'tags' => $contact_details['keywords'] ?? '',
99 'about' => $contact_details['about'] ?? '',
100 'account_type' => Contact::getAccountType($contact_details),
101 'thumb' => ProxyUtils::proxifyUrl($profile->photo, false, ProxyUtils::SIZE_THUMB),
102 'conntxt' => L10n::t('Connect'),
103 'connlnk' => $connlnk,
104 'img_hover' => $profile->tags,
105 'photo_menu' => $photo_menu,
115 'text' => L10n::t('first'),
116 'class' => 'previous' . ($start == 0 ? 'disabled' : '')
119 'url' => 'match?start=' . $i,
120 'text' => L10n::t('next'),
121 'class' => 'next' . ($i >= $msearch->total ? ' disabled' : '')
125 $tpl = Renderer::getMarkupTemplate('paginate.tpl');
126 $paginate = Renderer::replaceMacros($tpl, ['pager' => $data]);
129 if (empty($entries)) {
130 info(L10n::t('No matches') . EOL);
133 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
134 $o = Renderer::replaceMacros($tpl, [
135 '$title' => L10n::t('Profile Match'),
136 '$contacts' => $entries,
137 '$paginate' => $paginate