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