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