]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
Merge branch 'master' of git://github.com/friendika/friendika
[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         if(x($_SESSION,'theme'))
18                 unset($_SESSION['theme']);
19
20         if(x($a->data,'search'))
21                 $search = notags(trim($a->data['search']));
22         else
23                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
24
25         $tpl = load_view_file('view/directory_header.tpl');
26
27         $globaldir = '';
28         $gdirpath = dirname(get_config('system','directory_submit_url'));
29         if(strlen($gdirpath)) {
30                 $globaldir = '<ul><li><div id="global-directory-link"><a href="'
31                 . $gdirpath . '">' . t('Global Directory') . '</a></div></li></ul>';
32         }
33
34         $o .= replace_macros($tpl, array(
35                 '$search' => $search,
36                 '$globaldir' => $globaldir,
37                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : "")
38         ));
39
40         if($search)
41                 $search = dbesc($search);
42         $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) " : "");
43
44         $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
45
46
47         $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 ");
48         if(count($r))
49                 $a->set_pager_total($r[0]['total']);
50
51
52
53         $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 ",
54                 intval($a->pager['start']),
55                 intval($a->pager['itemspage'])
56         );
57         if(count($r)) {
58
59                 $tpl = load_view_file('view/directory_item.tpl');
60
61                 if(in_array('small', $a->argv))
62                         $photo = 'thumb';
63                 else
64                         $photo = 'photo';
65
66                 foreach($r as $rr) {
67
68
69                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
70                         $details = '';
71                         if(strlen($rr['locality']))
72                                 $details .= $rr['locality'];
73                         if(strlen($rr['region'])) {
74                                 if(strlen($rr['locality']))
75                                         $details .= ', ';
76                                 $details .= $rr['region'];
77                         }
78                         if(strlen($rr['country-name'])) {
79                                 if(strlen($details))
80                                         $details .= ', ';
81                                 $details .= $rr['country-name'];
82                         }
83                         if(strlen($rr['dob'])) {
84                                 if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
85                                         $details .= "<br />Age: $years" ; 
86                         }
87                         if(strlen($rr['gender']))
88                                 $details .= '<br />Gender: ' . $rr['gender'];
89
90                         $entry = replace_macros($tpl,array(
91                                 '$id' => $rr['id'],
92                                 '$profile-link' => $profile_link,
93                                 '$photo' => $rr[$photo],
94                                 '$alt-text' => $rr['name'],
95                                 '$name' => $rr['name'],
96                                 '$details' => $details  
97
98
99                         ));
100
101                         $arr = array('contact' => $rr, 'entry' => $entry);
102
103                         call_hooks('directory_item', $arr);
104
105                         $o .= $entry;
106
107                 }
108
109                 $o .= "<div class=\"directory-end\" ></div>\r\n";
110                 $o .= paginate($a);
111
112         }
113         else
114                 notice("No entries (some entries may be hidden).");
115
116         return $o;
117 }