]> git.mxchange.org Git - friendica.git/blob - mod/match.php
match.php: restructure acdording to the change of match.tpl
[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'] .= follow_widget();
23         $a->page['aside'] .= findpeople_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                         foreach($j->results as $jj) {
60                                 $match_nurl = normalise_link($jj->url);
61                                 $match = q("SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
62                                         intval(local_user()),
63                                         dbesc($match_nurl));
64                                 if (!count($match)) {
65                                         $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
66                                         $connlnk = $a->get_baseurl() . '/follow/?url=' . $jj->url;
67                                         $entry = array(
68                                                 'url' => zrl($jj->url),
69                                                 'name' => $jj->name,
70                                                 'photo' => proxy_url($jj->photo, false, PROXY_SIZE_THUMB),
71                                                 'inttxt' => ' ' . t('is interested in:'),
72                                                 'conntxt' => t('Connect'),
73                                                 'connlnk' => $connlnk,
74                                                 'tags' => $jj->tags
75                                         );
76                                         $entries[] = $entry;
77                                 }
78                         }
79
80                 $tpl = get_markup_template('match.tpl');
81
82                 $o .= replace_macros($tpl,array(
83                         '$title' => t('Profile Match'),
84                         'entries' => $entries,
85                 ));
86
87                 }
88                 else {
89                         info( t('No matches') . EOL);
90                 }
91
92         }
93
94         $o .= paginate($a);
95         return $o;
96 }