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