7 use Friendica\Content\Widget;
8 use Friendica\Core\Renderer;
9 use Friendica\Core\Search;
10 use Friendica\Database\DBA;
12 use Friendica\Model\Contact;
13 use Friendica\Model\Profile;
14 use Friendica\Util\Network;
15 use Friendica\Util\Proxy as ProxyUtils;
18 * Controller for /match.
20 * It takes keywords from your profile and queries the directory server for
21 * matching keywords from other profiles.
26 * @throws ImagickException
27 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
30 function match_content(App $a)
36 DI::page()['aside'] .= Widget::findPeople();
37 DI::page()['aside'] .= Widget::follow();
39 $_SESSION['return_path'] = DI::args()->getCommand();
41 $profile = Profile::getByUID(local_user());
43 if (!DBA::isResult($profile)) {
46 if (!$profile['pub_keywords'] && (!$profile['prv_keywords'])) {
47 notice(DI::l10n()->t('No keywords to match. Please add keywords to your default profile.') . EOL);
52 $tags = trim($profile['pub_keywords'] . ' ' . $profile['prv_keywords']);
57 if (strlen(DI::config()->get('system', 'directory'))) {
58 $host = Search::getGlobalDirectory();
60 $host = DI::baseUrl();
63 $msearch_json = Network::post($host . '/msearch', $params)->getBody();
65 $msearch = json_decode($msearch_json);
67 $start = $_GET['start'] ?? 0;
71 if (!empty($msearch->results)) {
72 for ($i = $start;count($entries) < 10 && $i < $msearch->total; $i++) {
73 $profile = $msearch->results[$i];
75 // Already known contact
76 if (!$profile || Contact::getIdForURL($profile->url, local_user(), true)) {
80 // Workaround for wrong directory photo URL
81 $profile->photo = str_replace('http:///photo/', Search::getGlobalDirectory() . '/photo/', $profile->photo);
83 $connlnk = DI::baseUrl() . '/follow/?url=' . $profile->url;
85 'profile' => [DI::l10n()->t("View Profile"), Contact::magicLink($profile->url)],
86 'follow' => [DI::l10n()->t("Connect/Follow"), $connlnk]
89 $contact_details = Contact::getDetailsByURL($profile->url, 0);
92 'url' => Contact::magicLink($profile->url),
93 'itemurl' => $contact_details['addr'] ?? $profile->url,
94 'name' => $profile->name,
95 'details' => $contact_details['location'] ?? '',
96 'tags' => $contact_details['keywords'] ?? '',
97 'about' => $contact_details['about'] ?? '',
98 'account_type' => Contact::getAccountType($contact_details),
99 'thumb' => ProxyUtils::proxifyUrl($profile->photo, false, ProxyUtils::SIZE_THUMB),
100 'conntxt' => DI::l10n()->t('Connect'),
101 'connlnk' => $connlnk,
102 'img_hover' => $profile->tags,
103 'photo_menu' => $photo_menu,
113 'text' => DI::l10n()->t('first'),
114 'class' => 'previous' . ($start == 0 ? 'disabled' : '')
117 'url' => 'match?start=' . $i,
118 'text' => DI::l10n()->t('next'),
119 'class' => 'next' . ($i >= $msearch->total ? ' disabled' : '')
123 $tpl = Renderer::getMarkupTemplate('paginate.tpl');
124 $paginate = Renderer::replaceMacros($tpl, ['pager' => $data]);
127 if (empty($entries)) {
128 info(DI::l10n()->t('No matches') . EOL);
131 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
132 $o = Renderer::replaceMacros($tpl, [
133 '$title' => DI::l10n()->t('Profile Match'),
134 '$contacts' => $entries,
135 '$paginate' => $paginate