]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
Merge pull request #927 from annando/master
[friendica.git] / mod / directory.php
1 <?php
2
3 function directory_init(&$a) {
4         $a->set_pager_itemspage(60);
5
6         if(local_user()) {
7                 require_once('include/contact_widgets.php');
8
9                 $a->page['aside'] .= findpeople_widget();
10
11         }
12         else {
13                 unset($_SESSION['theme']);
14                 unset($_SESSION['mobile-theme']);
15         }
16
17
18 }
19
20
21 function directory_post(&$a) {
22         if(x($_POST,'search'))
23                 $a->data['search'] = $_POST['search'];
24 }
25
26
27
28 function directory_content(&$a) {
29
30         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
31                 notice( t('Public access denied.') . EOL);
32                 return;
33         }
34
35         $o = '';
36         nav_set_selected('directory');
37
38         if(x($a->data,'search'))
39                 $search = notags(trim($a->data['search']));
40         else
41                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
42
43         $tpl = get_markup_template('directory_header.tpl');
44
45         $globaldir = '';
46         $gdirpath = dirname(get_config('system','directory_submit_url'));
47         if(strlen($gdirpath)) {
48                 $globaldir = '<ul><li><div id="global-directory-link"><a href="'
49                 . zrl($gdirpath,true) . '">' . t('Global Directory') . '</a></div></li></ul>';
50         }
51
52         $admin = '';
53
54         $o .= replace_macros($tpl, array(
55                 '$search' => $search,
56                 '$globaldir' => $globaldir,
57                 '$desc' => t('Find on this site'),
58                 '$admin' => $admin,
59                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
60                 '$sitedir' => t('Site Directory'),
61                 '$submit' => t('Find')
62         ));
63
64         if($search)
65                 $search = dbesc($search);
66         $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) " : "");
67
68         $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
69
70
71         $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 ");
72         if(count($r))
73                 $a->set_pager_total($r[0]['total']);
74
75         $order = " ORDER BY `name` ASC "; 
76
77
78         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
79                 intval($a->pager['start']),
80                 intval($a->pager['itemspage'])
81         );
82         if(count($r)) {
83
84                 if(in_array('small', $a->argv))
85                         $photo = 'thumb';
86                 else
87                         $photo = 'photo';
88
89                 foreach($r as $rr) {
90
91
92                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
93                 
94                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
95
96                         $details = '';
97                         if(strlen($rr['locality']))
98                                 $details .= $rr['locality'];
99                         if(strlen($rr['region'])) {
100                                 if(strlen($rr['locality']))
101                                         $details .= ', ';
102                                 $details .= $rr['region'];
103                         }
104                         if(strlen($rr['country-name'])) {
105                                 if(strlen($details))
106                                         $details .= ', ';
107                                 $details .= $rr['country-name'];
108                         }
109                         if(strlen($rr['dob'])) {
110                                 if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
111                                         $details .= '<br />' . t('Age: ') . $years ; 
112                         }
113                         if(strlen($rr['gender']))
114                                 $details .= '<br />' . t('Gender: ') . $rr['gender'];
115
116                         if($rr['page-flags'] == PAGE_NORMAL)
117                                 $page_type = "Personal Profile";
118                         if($rr['page-flags'] == PAGE_SOAPBOX)
119                                 $page_type = "Fan Page";
120                         if($rr['page-flags'] == PAGE_COMMUNITY)
121                                 $page_type = "Community Forum";
122                         if($rr['page-flags'] == PAGE_FREELOVE)
123                                 $page_type = "Open Forum";
124                         if($rr['page-flags'] == PAGE_PRVGROUP)
125                                 $page_type = "Private Group";
126
127                         $profile = $rr;
128
129                         if((x($profile,'address') == 1)
130                                 || (x($profile,'locality') == 1)
131                                 || (x($profile,'region') == 1)
132                                 || (x($profile,'postal-code') == 1)
133                                 || (x($profile,'country-name') == 1))
134                         $location = t('Location:');
135
136                         $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
137
138                         $marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
139
140                         $homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);
141
142                         $about = ((x($profile,'about') == 1) ?  t('About:') : False);
143                         
144                         $tpl = get_markup_template('directory_item.tpl');
145
146                         if($a->theme['template_engine'] === 'internal') {
147                                 $location_e = template_escape($location);
148                         }
149                         else {
150                                 $location_e = $location;
151                         }
152
153                         $entry = replace_macros($tpl,array(
154                                 '$id' => $rr['id'],
155                                 '$profile_link' => $profile_link,
156                                 '$photo' => $a->get_cached_avatar_image($rr[$photo]),
157                                 '$alt_text' => $rr['name'],
158                                 '$name' => $rr['name'],
159                                 '$details' => $pdesc . $details,
160                                 '$page_type' => $page_type,
161                                 '$profile' => $profile,
162                                 '$location' => $location_e,
163                                 '$gender'   => $gender,
164                                 '$pdesc'        => $pdesc,
165                                 '$marital'  => $marital,
166                                 '$homepage' => $homepage,
167                                 '$about' => $about,
168
169                         ));
170
171                         $arr = array('contact' => $rr, 'entry' => $entry);
172
173                         call_hooks('directory_item', $arr);
174                         
175                         unset($profile);
176                         unset($location);
177
178                         $o .= $entry;
179
180                 }
181
182                 $o .= "<div class=\"directory-end\" ></div>\r\n";
183                 $o .= paginate($a);
184
185         }
186         else
187                 info( t("No entries \x28some entries may be hidden\x29.") . EOL);
188
189         return $o;
190 }