]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
more lint
[friendica.git] / mod / directory.php
1 <?php
2 function directory_init(&$a) {
3         $a->set_pager_itemspage(60);
4 }
5
6 function directory_content(&$a) {
7         $o = '';
8         $o .= '<script> $(document).ready(function() { $(\'#nav-directory-link\').addClass(\'nav-selected\'); });</script>';
9
10         $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
11
12         $tpl = load_view_file('view/directory_header.tpl');
13
14         $globaldir = '';
15         $gdirpath = dirname(get_config('system','directory_submit_url'));
16         if(strlen($gdirpath)) {
17                 $globaldir = '<ul><li><div id="global-directory-link"><a href="'
18                 . $gdirpath . '">' . t('Global Directory') . '</a></div></li></ul>';
19         }
20
21         $o .= replace_macros($tpl, array(
22                 '$search' => $search,
23                 '$globaldir' => $globaldir,
24                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : "")
25         ));
26
27         if($search)
28                 $search = dbesc($search);
29         $sql_extra = ((strlen($search)) ? " AND MATCH (`profile`.`name`, `user`.`nickname`, `locality`,`region`,`country-name`,`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`) AGAINST ('$search' IN BOOLEAN MODE) " : "");
30
31
32         $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `publish` = 1 AND `user`.`blocked` = 0 $sql_extra ");
33         if(count($r))
34                 $a->set_pager_total($r[0]['total']);
35
36
37
38         $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 AND `publish` = 1 AND `user`.`blocked` = 0 $sql_extra ORDER BY `name` ASC LIMIT %d , %d ",
39                 intval($a->pager['start']),
40                 intval($a->pager['itemspage'])
41         );
42         if(count($r)) {
43
44                 $tpl = load_view_file('view/directory_item.tpl');
45
46                 if(in_array('small', $a->argv))
47                         $photo = 'thumb';
48                 else
49                         $photo = 'photo';
50
51                 foreach($r as $rr) {
52
53
54                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
55                         $details = '';
56                         if(strlen($rr['locality']))
57                                 $details .= $rr['locality'];
58                         if(strlen($rr['region'])) {
59                                 if(strlen($rr['locality']))
60                                         $details .= ', ';
61                                 $details .= $rr['region'];
62                         }
63                         if(strlen($rr['country-name'])) {
64                                 if(strlen($details))
65                                         $details .= ', ';
66                                 $details .= $rr['country-name'];
67                         }
68                         if(strlen($rr['dob'])) {
69                                 if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
70                                         $details .= "<br />Age: $years" ; 
71                         }
72                         if(strlen($rr['gender']))
73                                 $details .= '<br />Gender: ' . $rr['gender'];
74
75                         $o .= replace_macros($tpl,array(
76                                 '$id' => $rr['id'],
77                                 '$profile-link' => $profile_link,
78                                 '$photo' => $rr[$photo],
79                                 '$alt-text' => $rr['name'],
80                                 '$name' => $rr['name'],
81                                 '$details' => $details  
82
83
84                         ));
85
86                 }
87                 $o .= "<div class=\"directory-end\" ></div>\r\n";
88                 $o .= paginate($a);
89
90         }
91         else
92                 notice("No entries (some entries may be hidden).");
93
94         return $o;
95 }