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