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;
15 use Friendica\Model\Contact;
16 use Friendica\Model\Profile;
17 use Friendica\Util\Network;
18 use Friendica\Util\Proxy as ProxyUtils;
21 * @brief Controller for /match.
23 * It takes keywords from your profile and queries the directory server for
24 * matching keywords from other profiles.
29 * @throws ImagickException
30 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
33 function match_content(App $a)
39 $a->page['aside'] .= Widget::findPeople();
40 $a->page['aside'] .= Widget::follow();
42 $_SESSION['return_path'] = DI::args()->getCommand();
44 $profile = Profile::getByUID(local_user());
46 if (!DBA::isResult($profile)) {
49 if (!$profile['pub_keywords'] && (!$profile['prv_keywords'])) {
50 notice(L10n::t('No keywords to match. Please add keywords to your default profile.') . EOL);
55 $tags = trim($profile['pub_keywords'] . ' ' . $profile['prv_keywords']);
60 if (strlen(Config::get('system', 'directory'))) {
63 $host = System::baseUrl();
66 $msearch_json = Network::post($host . '/msearch', $params)->getBody();
68 $msearch = json_decode($msearch_json);
70 $start = $_GET['start'] ?? 0;
74 if (!empty($msearch->results)) {
75 for ($i = $start;count($entries) < 10 && $i < $msearch->total; $i++) {
76 $profile = $msearch->results[$i];
78 // Already known contact
79 if (!$profile || Contact::getIdForURL($profile->url, local_user(), true)) {
83 // Workaround for wrong directory photo URL
84 $profile->photo = str_replace('http:///photo/', get_server() . '/photo/', $profile->photo);
86 $connlnk = System::baseUrl() . '/follow/?url=' . $profile->url;
88 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile->url)],
89 'follow' => [L10n::t("Connect/Follow"), $connlnk]
92 $contact_details = Contact::getDetailsByURL($profile->url, 0);
95 'url' => Contact::magicLink($profile->url),
96 'itemurl' => $contact_details['addr'] ?? $profile->url,
97 'name' => $profile->name,
98 'details' => $contact_details['location'] ?? '',
99 'tags' => $contact_details['keywords'] ?? '',
100 'about' => $contact_details['about'] ?? '',
101 'account_type' => Contact::getAccountType($contact_details),
102 'thumb' => ProxyUtils::proxifyUrl($profile->photo, false, ProxyUtils::SIZE_THUMB),
103 'conntxt' => L10n::t('Connect'),
104 'connlnk' => $connlnk,
105 'img_hover' => $profile->tags,
106 'photo_menu' => $photo_menu,
116 'text' => L10n::t('first'),
117 'class' => 'previous' . ($start == 0 ? 'disabled' : '')
120 'url' => 'match?start=' . $i,
121 'text' => L10n::t('next'),
122 'class' => 'next' . ($i >= $msearch->total ? ' disabled' : '')
126 $tpl = Renderer::getMarkupTemplate('paginate.tpl');
127 $paginate = Renderer::replaceMacros($tpl, ['pager' => $data]);
130 if (empty($entries)) {
131 info(L10n::t('No matches') . EOL);
134 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
135 $o = Renderer::replaceMacros($tpl, [
136 '$title' => L10n::t('Profile Match'),
137 '$contacts' => $entries,
138 '$paginate' => $paginate