3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 use Friendica\Content\Widget;
24 use Friendica\Core\Renderer;
25 use Friendica\Core\Search;
26 use Friendica\Database\DBA;
28 use Friendica\Model\Contact;
29 use Friendica\Model\Profile;
30 use Friendica\Util\Network;
31 use Friendica\Util\Proxy as ProxyUtils;
34 * Controller for /match.
36 * It takes keywords from your profile and queries the directory server for
37 * matching keywords from other profiles.
42 * @throws ImagickException
43 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
46 function match_content(App $a)
52 DI::page()['aside'] .= Widget::findPeople();
53 DI::page()['aside'] .= Widget::follow();
55 $_SESSION['return_path'] = DI::args()->getCommand();
57 $profile = Profile::getByUID(local_user());
59 if (!DBA::isResult($profile)) {
62 if (!$profile['pub_keywords'] && (!$profile['prv_keywords'])) {
63 notice(DI::l10n()->t('No keywords to match. Please add keywords to your profile.') . EOL);
68 $tags = trim($profile['pub_keywords'] . ' ' . $profile['prv_keywords']);
73 if (strlen(DI::config()->get('system', 'directory'))) {
74 $host = Search::getGlobalDirectory();
76 $host = DI::baseUrl();
79 $msearch_json = Network::post($host . '/msearch', $params)->getBody();
81 $msearch = json_decode($msearch_json);
83 $start = $_GET['start'] ?? 0;
87 if (!empty($msearch->results)) {
88 for ($i = $start;count($entries) < 10 && $i < $msearch->total; $i++) {
89 $profile = $msearch->results[$i];
91 // Already known contact
92 if (!$profile || Contact::getIdForURL($profile->url, local_user(), true)) {
96 // Workaround for wrong directory photo URL
97 $profile->photo = str_replace('http:///photo/', Search::getGlobalDirectory() . '/photo/', $profile->photo);
99 $connlnk = DI::baseUrl() . '/follow/?url=' . $profile->url;
101 'profile' => [DI::l10n()->t("View Profile"), Contact::magicLink($profile->url)],
102 'follow' => [DI::l10n()->t("Connect/Follow"), $connlnk]
105 $contact_details = Contact::getDetailsByURL($profile->url, 0);
108 'url' => Contact::magicLink($profile->url),
109 'itemurl' => $contact_details['addr'] ?? $profile->url,
110 'name' => $profile->name,
111 'details' => $contact_details['location'] ?? '',
112 'tags' => $contact_details['keywords'] ?? '',
113 'about' => $contact_details['about'] ?? '',
114 'account_type' => Contact::getAccountType($contact_details),
115 'thumb' => ProxyUtils::proxifyUrl($profile->photo, false, ProxyUtils::SIZE_THUMB),
116 'conntxt' => DI::l10n()->t('Connect'),
117 'connlnk' => $connlnk,
118 'img_hover' => $profile->tags,
119 'photo_menu' => $photo_menu,
129 'text' => DI::l10n()->t('first'),
130 'class' => 'previous' . ($start == 0 ? 'disabled' : '')
133 'url' => 'match?start=' . $i,
134 'text' => DI::l10n()->t('next'),
135 'class' => 'next' . ($i >= $msearch->total ? ' disabled' : '')
139 $tpl = Renderer::getMarkupTemplate('paginate.tpl');
140 $paginate = Renderer::replaceMacros($tpl, ['pager' => $data]);
143 if (empty($entries)) {
144 info(DI::l10n()->t('No matches') . EOL);
147 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
148 $o = Renderer::replaceMacros($tpl, [
149 '$title' => DI::l10n()->t('Profile Match'),
150 '$contacts' => $entries,
151 '$paginate' => $paginate