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