]> git.mxchange.org Git - friendica.git/blob - mod/match.php
Merge pull request #4312 from zeroadam/feature/L10n
[friendica.git] / mod / match.php
1 <?php
2 /**
3  * @file mod/match.php
4  */
5 use Friendica\App;
6 use Friendica\Content\Widget;
7 use Friendica\Core\Config;
8 use Friendica\Core\L10n;
9 use Friendica\Core\System;
10 use Friendica\Database\DBM;
11 use Friendica\Model\Contact;
12 use Friendica\Model\Profile;
13
14 require_once 'include/text.php';
15 require_once 'mod/proxy.php';
16
17 /**
18  * @brief Controller for /match.
19  *
20  * It takes keywords from your profile and queries the directory server for
21  * matching keywords from other profiles.
22  *
23  * @param App $a App
24  *
25  * @return void|string
26  */
27 function match_content(App $a)
28 {
29         $o = '';
30         if (! local_user()) {
31                 return;
32         }
33
34         $a->page['aside'] .= Widget::findPeople();
35         $a->page['aside'] .= Widget::follow();
36
37         $_SESSION['return_url'] = System::baseUrl() . '/' . $a->cmd;
38
39         $r = q(
40                 "SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
41                 intval(local_user())
42         );
43         if (! DBM::is_result($r)) {
44                 return;
45         }
46         if (! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
47                 notice(L10n::t('No keywords to match. Please add keywords to your default profile.') . EOL);
48                 return;
49         }
50
51         $params = [];
52         $tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
53
54         if ($tags) {
55                 $params['s'] = $tags;
56                 if ($a->pager['page'] != 1) {
57                         $params['p'] = $a->pager['page'];
58                 }
59
60                 if (strlen(Config::get('system', 'directory'))) {
61                         $x = post_url(get_server().'/msearch', $params);
62                 } else {
63                         $x = post_url(System::baseUrl() . '/msearch', $params);
64                 }
65
66                 $j = json_decode($x);
67
68                 if ($j->total) {
69                         $a->set_pager_total($j->total);
70                         $a->set_pager_itemspage($j->items_page);
71                 }
72
73                 if (count($j->results)) {
74                         $id = 0;
75
76                         foreach ($j->results as $jj) {
77                                 $match_nurl = normalise_link($jj->url);
78                                 $match = q(
79                                         "SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
80                                         intval(local_user()),
81                                         dbesc($match_nurl)
82                                 );
83
84                                 if (!count($match)) {
85                                         $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
86                                         $connlnk = System::baseUrl() . '/follow/?url=' . $jj->url;
87                                         $photo_menu = [
88                                                 'profile' => [L10n::t("View Profile"), Profile::zrl($jj->url)],
89                                                 'follow' => [L10n::t("Connect/Follow"), $connlnk]
90                                         ];
91
92                                         $contact_details = Contact::getDetailsByURL($jj->url, local_user());
93
94                                         $entry = [
95                                                 'url' => Profile::zrl($jj->url),
96                                                 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $jj->url),
97                                                 'name' => $jj->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' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
103                                                 'inttxt' => ' ' . L10n::t('is interested in:'),
104                                                 'conntxt' => L10n::t('Connect'),
105                                                 'connlnk' => $connlnk,
106                                                 'img_hover' => $jj->tags,
107                                                 'photo_menu' => $photo_menu,
108                                                 'id' => ++$id,
109                                         ];
110                                         $entries[] = $entry;
111                                 }
112                         }
113
114                         $tpl = get_markup_template('viewcontact_template.tpl');
115
116                         $o .= replace_macros(
117                                 $tpl,
118                                 [
119                                 '$title' => L10n::t('Profile Match'),
120                                 '$contacts' => $entries,
121                                 '$paginate' => paginate($a)]
122                         );
123                 } else {
124                         info(L10n::t('No matches') . EOL);
125                 }
126         }
127
128         return $o;
129 }