]> git.mxchange.org Git - friendica.git/blob - mod/match.php
Merge remote-tracking branch 'upstream/develop' into 1509-new-feed-import
[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
6 function match_content(&$a) {
7
8         $o = '';
9         if(! local_user())
10                 return;
11
12         $a->page['aside'] .= follow_widget();
13         $a->page['aside'] .= findpeople_widget();
14
15         $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
16
17         $o .= replace_macros(get_markup_template("section_title.tpl"),array(
18                 '$title' => t('Profile Match')
19         ));
20
21         $r = q("SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
22                 intval(local_user())
23         );
24         if(! count($r))
25                 return;
26         if(! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
27                 notice( t('No keywords to match. Please add keywords to your default profile.') . EOL);
28                 return;
29
30         }
31
32         $params = array();
33         $tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
34
35         if($tags) {
36                 $params['s'] = $tags;
37                 if($a->pager['page'] != 1)
38                         $params['p'] = $a->pager['page'];
39
40                 if(strlen(get_config('system','directory')))
41                         $x = post_url(get_server().'/msearch', $params);
42                 else
43                         $x = post_url($a->get_baseurl() . '/msearch', $params);
44
45                 $j = json_decode($x);
46
47                 if($j->total) {
48                         $a->set_pager_total($j->total);
49                         $a->set_pager_itemspage($j->items_page);
50                 }
51
52                 if(count($j->results)) {
53
54
55
56                         $tpl = get_markup_template('match.tpl');
57                         foreach($j->results as $jj) {
58                                 $match_nurl = normalise_link($jj->url);
59                                 $match = q("SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
60                                         intval(local_user()),
61                                         dbesc($match_nurl));
62                                 if (!count($match)) {
63                                         $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo);
64                                         $connlnk = $a->get_baseurl() . '/follow/?url=' . $jj->url;
65                                         $o .= replace_macros($tpl,array(
66                                                 '$url' => zrl($jj->url),
67                                                 '$name' => $jj->name,
68                                                 '$photo' => proxy_url($jj->photo),
69                                                 '$inttxt' => ' ' . t('is interested in:'),
70                                                 '$conntxt' => t('Connect'),
71                                                 '$connlnk' => $connlnk,
72                                                 '$tags' => $jj->tags
73                                         ));
74                                 }
75                         }
76                 } else {
77                         info( t('No matches') . EOL);
78                 }
79
80         }
81
82         $o .= cleardiv();
83         $o .= paginate($a);
84         return $o;
85 }