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.
29 function match_content(App $a)
35 $a->page['aside'] .= Widget::findPeople();
36 $a->page['aside'] .= Widget::follow();
38 $_SESSION['return_path'] = $a->cmd;
40 $profile = Profile::getByUID(local_user());
42 if (!DBA::isResult($profile)) {
45 if (!$profile['pub_keywords'] && (!$profile['prv_keywords'])) {
46 notice(L10n::t('No keywords to match. Please add keywords to your default profile.') . EOL);
51 $tags = trim($profile['pub_keywords'] . ' ' . $profile['prv_keywords']);
56 if (strlen(Config::get('system', 'directory'))) {
59 $host = System::baseUrl();
62 $msearch_json = Network::post($host . '/msearch', $params)->getBody();
64 $msearch = json_decode($msearch_json);
66 $start = defaults($_GET, 'start', 0);
70 if (!empty($msearch->results)) {
71 for ($i = $start;count($entries) < 10 && $i < $msearch->total; $i++) {
72 $profile = $msearch->results[$i];
74 // Already known contact
75 if (Contact::getIdForURL($profile->url, local_user(), true)) {
79 // Workaround for wrong directory photo URL
80 $profile->photo = str_replace('http:///photo/', get_server() . '/photo/', $profile->photo);
82 $connlnk = System::baseUrl() . '/follow/?url=' . $profile->url;
84 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile->url)],
85 'follow' => [L10n::t("Connect/Follow"), $connlnk]
88 $contact_details = Contact::getDetailsByURL($profile->url, 0);
91 'url' => Contact::magicLink($profile->url),
92 'itemurl' => defaults($contact_details, 'addr', $profile->url),
93 'name' => $profile->name,
94 'details' => defaults($contact_details, 'location', ''),
95 'tags' => defaults($contact_details, 'keywords', ''),
96 'about' => defaults($contact_details, 'about', ''),
97 'account_type' => Contact::getAccountType($contact_details),
98 'thumb' => ProxyUtils::proxifyUrl($profile->photo, false, ProxyUtils::SIZE_THUMB),
99 'conntxt' => L10n::t('Connect'),
100 'connlnk' => $connlnk,
101 'img_hover' => $profile->tags,
102 'photo_menu' => $photo_menu,
112 'text' => L10n::t('first'),
113 'class' => 'previous' . ($start == 0 ? 'disabled' : '')
116 'url' => 'match?start=' . $i,
117 'text' => L10n::t('next'),
118 'class' => 'next' . ($i >= $msearch->total ? ' disabled' : '')
122 $tpl = Renderer::getMarkupTemplate('paginate.tpl');
123 $paginate = Renderer::replaceMacros($tpl, ['pager' => $data]);
126 if (empty($entries)) {
127 info(L10n::t('No matches') . EOL);
130 $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
131 $o = Renderer::replaceMacros($tpl, [
132 '$title' => L10n::t('Profile Match'),
133 '$contacts' => $entries,
134 '$paginate' => $paginate