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