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