]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
fix json_encode on url's
[friendica.git] / mod / directory.php
1 <?php
2
3 function directory_init(&$a) {
4         $a->set_pager_itemspage(60);
5 }
6
7
8 function directory_post(&$a) {
9         if(x($_POST,'search'))
10                 $a->data['search'] = $_POST['search'];
11 }
12
13
14
15 function directory_content(&$a) {
16
17         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
18                 notice( t('Public access denied.') . EOL);
19                 return;
20         }
21
22         $o = '';
23         $o .= '<script> $(document).ready(function() { $(\'#nav-directory-link\').addClass(\'nav-selected\'); });</script>';
24         if(x($_SESSION,'theme'))
25                 unset($_SESSION['theme']);
26
27         if(x($a->data,'search'))
28                 $search = notags(trim($a->data['search']));
29         else
30                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
31
32         $tpl = get_markup_template('directory_header.tpl');
33
34         $globaldir = '';
35         $gdirpath = dirname(get_config('system','directory_submit_url'));
36         if(strlen($gdirpath)) {
37                 $globaldir = '<ul><li><div id="global-directory-link"><a href="'
38                 . $gdirpath . '">' . t('Global Directory') . '</a></div></li></ul>';
39         }
40
41         $o .= replace_macros($tpl, array(
42                 '$search' => $search,
43                 '$globaldir' => $globaldir,
44                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
45                 '$sitedir' => t('Site Directory'),
46                 '$submit' => t('Find')
47         ));
48
49         if($search)
50                 $search = dbesc($search);
51         $sql_extra = ((strlen($search)) ? " AND MATCH (`profile`.`name`, `user`.`nickname`, `pdesc`, `locality`,`region`,`country-name`,`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`,`pub_keywords`,`prv_keywords` ) AGAINST ('$search' IN BOOLEAN MODE) " : "");
52
53         $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
54
55
56         $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ");
57         if(count($r))
58                 $a->set_pager_total($r[0]['total']);
59
60
61
62         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ORDER BY `name` ASC LIMIT %d , %d ",
63                 intval($a->pager['start']),
64                 intval($a->pager['itemspage'])
65         );
66         if(count($r)) {
67
68                 $tpl = get_markup_template('directory_item.tpl');
69
70                 if(in_array('small', $a->argv))
71                         $photo = 'thumb';
72                 else
73                         $photo = 'photo';
74
75                 foreach($r as $rr) {
76
77
78                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
79                 
80                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
81
82                         $details = '';
83                         if(strlen($rr['locality']))
84                                 $details .= $rr['locality'];
85                         if(strlen($rr['region'])) {
86                                 if(strlen($rr['locality']))
87                                         $details .= ', ';
88                                 $details .= $rr['region'];
89                         }
90                         if(strlen($rr['country-name'])) {
91                                 if(strlen($details))
92                                         $details .= ', ';
93                                 $details .= $rr['country-name'];
94                         }
95                         if(strlen($rr['dob'])) {
96                                 if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
97                                         $details .= '<br />' . t('Age: ') . $years ; 
98                         }
99                         if(strlen($rr['gender']))
100                                 $details .= '<br />' . t('Gender: ') . $rr['gender'];
101
102                         $entry = replace_macros($tpl,array(
103                                 '$id' => $rr['id'],
104                                 '$profile-link' => $profile_link,
105                                 '$photo' => $rr[$photo],
106                                 '$alt-text' => $rr['name'],
107                                 '$name' => $rr['name'],
108                                 '$details' => $pdesc . $details  
109
110
111                         ));
112
113                         $arr = array('contact' => $rr, 'entry' => $entry);
114
115                         call_hooks('directory_item', $arr);
116
117                         $o .= $entry;
118
119                 }
120
121                 $o .= "<div class=\"directory-end\" ></div>\r\n";
122                 $o .= paginate($a);
123
124         }
125         else
126                 notice( t("No entries \x28some entries may be hidden\x29.") . EOL);
127
128         return $o;
129 }