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