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\Module\Contact as ModuleContact;
33 * Controller for /match.
35 * It takes keywords from your profile and queries the directory server for
36 * matching keywords from other profiles.
41 * @throws ImagickException
42 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
45 function match_content(App $a)
51 DI::page()['aside'] .= Widget::findPeople();
52 DI::page()['aside'] .= Widget::follow();
54 $_SESSION['return_path'] = DI::args()->getCommand();
56 $profile = Profile::getByUID(local_user());
58 if (!DBA::isResult($profile)) {
61 if (!$profile['pub_keywords'] && (!$profile['prv_keywords'])) {
62 notice(DI::l10n()->t('No keywords to match. Please add keywords to your profile.'));
67 $tags = trim($profile['pub_keywords'] . ' ' . $profile['prv_keywords']);
72 if (strlen(DI::config()->get('system', 'directory'))) {
73 $host = Search::getGlobalDirectory();
75 $host = DI::baseUrl();
78 $msearch_json = DI::httpRequest()->post($host . '/msearch', $params)->getBody();
80 $msearch = json_decode($msearch_json);
82 $start = $_GET['start'] ?? 0;
86 if (!empty($msearch->results)) {
87 for ($i = $start;count($entries) < 10 && $i < $msearch->total; $i++) {
88 $profile = $msearch->results[$i];
90 // Already known contact
91 if (!$profile || Contact::getIdForURL($profile->url, local_user())) {
95 $contact = Contact::getByURLForUser($profile->url, local_user());
96 if (!empty($contact)) {
97 $entries[] = ModuleContact::getContactTemplateVars($contact);
105 'text' => DI::l10n()->t('first'),
106 'class' => 'previous' . ($start == 0 ? 'disabled' : '')
109 'url' => 'match?start=' . $i,
110 'text' => DI::l10n()->t('next'),
111 'class' => 'next' . ($i >= $msearch->total ? ' disabled' : '')
115 $tpl = Renderer::getMarkupTemplate('paginate.tpl');
116 $paginate = Renderer::replaceMacros($tpl, ['pager' => $data]);
119 if (empty($entries)) {
120 info(DI::l10n()->t('No matches'));
123 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
124 $o = Renderer::replaceMacros($tpl, [
125 '$title' => DI::l10n()->t('Profile Match'),
126 '$contacts' => $entries,
127 '$paginate' => $paginate