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