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