]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
b0cee76cb72330e59ae8e537dd24b72de0e2dcee
[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(rawurldecode($_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         $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
43
44
45         $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 ");
46         if(count($r))
47                 $a->set_pager_total($r[0]['total']);
48
49
50
51         $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 ",
52                 intval($a->pager['start']),
53                 intval($a->pager['itemspage'])
54         );
55         if(count($r)) {
56
57                 $tpl = load_view_file('view/directory_item.tpl');
58
59                 if(in_array('small', $a->argv))
60                         $photo = 'thumb';
61                 else
62                         $photo = 'photo';
63
64                 foreach($r as $rr) {
65
66
67                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
68                         $details = '';
69                         if(strlen($rr['locality']))
70                                 $details .= $rr['locality'];
71                         if(strlen($rr['region'])) {
72                                 if(strlen($rr['locality']))
73                                         $details .= ', ';
74                                 $details .= $rr['region'];
75                         }
76                         if(strlen($rr['country-name'])) {
77                                 if(strlen($details))
78                                         $details .= ', ';
79                                 $details .= $rr['country-name'];
80                         }
81                         if(strlen($rr['dob'])) {
82                                 if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
83                                         $details .= "<br />Age: $years" ; 
84                         }
85                         if(strlen($rr['gender']))
86                                 $details .= '<br />Gender: ' . $rr['gender'];
87
88                         $entry = replace_macros($tpl,array(
89                                 '$id' => $rr['id'],
90                                 '$profile-link' => $profile_link,
91                                 '$photo' => $rr[$photo],
92                                 '$alt-text' => $rr['name'],
93                                 '$name' => $rr['name'],
94                                 '$details' => $details  
95
96
97                         ));
98
99                         $arr = array('contact' => $rr, 'entry' => $entry);
100
101                         call_hooks('directory_item', $arr);
102
103                         $o .= $entry;
104
105                 }
106
107                 $o .= "<div class=\"directory-end\" ></div>\r\n";
108                 $o .= paginate($a);
109
110         }
111         else
112                 notice("No entries (some entries may be hidden).");
113
114         return $o;
115 }