]> git.mxchange.org Git - friendica.git/blob - mod/match.php
DE update to the strings
[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(! count($r))
31                 return;
32         if(! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
33                 notice( t('No keywords to match. Please add keywords to your default profile.') . EOL);
34                 return;
35         }
36
37         $params = array();
38         $tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
39
40         if($tags) {
41                 $params['s'] = $tags;
42                 if($a->pager['page'] != 1)
43                         $params['p'] = $a->pager['page'];
44
45                 if(strlen(get_config('system','directory')))
46                         $x = post_url(get_server().'/msearch', $params);
47                 else
48                         $x = post_url($a->get_baseurl() . '/msearch', $params);
49
50                 $j = json_decode($x);
51
52                 if($j->total) {
53                         $a->set_pager_total($j->total);
54                         $a->set_pager_itemspage($j->items_page);
55                 }
56
57                 if(count($j->results)) {
58
59                         $id = 0;
60
61                         foreach($j->results as $jj) {
62                                 $match_nurl = normalise_link($jj->url);
63                                 $match = q("SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
64                                         intval(local_user()),
65                                         dbesc($match_nurl));
66
67                                 if (!count($match)) {
68                                         $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
69                                         $connlnk = $a->get_baseurl() . '/follow/?url=' . $jj->url;
70                                         $photo_menu = array(array(t("View Profile"), zrl($jj->url)));
71                                         $photo_menu[] = array(t("Connect/Follow"), $connlnk);
72
73                                         $contact_details = get_contact_details_by_url($jj->url, local_user());
74
75                                         $entry = array(
76                                                 'url' => zrl($jj->url),
77                                                 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $jj->url),
78                                                 'name' => $jj->name,
79                                                 'details'       => $contact_details['location'],
80                                                 'tags'          => $contact_details['keywords'],
81                                                 'about'         => $contact_details['about'],
82                                                 'account_type'  => (($contact_details['community']) ? t('Forum') : ''),
83                                                 'thumb' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
84                                                 'inttxt' => ' ' . t('is interested in:'),
85                                                 'conntxt' => t('Connect'),
86                                                 'connlnk' => $connlnk,
87                                                 'img_hover' => $jj->tags,
88                                                 'photo_menu' => $photo_menu,
89                                                 'id' => ++$id,
90                                         );
91                                         $entries[] = $entry;
92                                 }
93                         }
94
95                 $tpl = get_markup_template('viewcontact_template.tpl');
96
97                 $o .= replace_macros($tpl,array(
98                         '$title' => t('Profile Match'),
99                         '$contacts' => $entries,
100                         '$paginate' => paginate($a),
101                 ));
102
103                 }
104                 else {
105                         info( t('No matches') . EOL);
106                 }
107
108         }
109
110         return $o;
111 }