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