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