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