]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
rev update
[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                         $entry = replace_macros($tpl,array(
147                                 '$id' => $rr['id'],
148                                 '$profile-link' => $profile_link,
149                                 '$photo' => $a->get_cached_avatar_image($rr[$photo]),
150                                 '$alt-text' => $rr['name'],
151                                 '$name' => $rr['name'],
152                                 '$details' => $pdesc . $details,
153                                 '$page-type' => $page_type,
154                                 '$profile' => $profile,
155                                 '$location' => template_escape($location),
156                                 '$gender'   => $gender,
157                                 '$pdesc'        => $pdesc,
158                                 '$marital'  => $marital,
159                                 '$homepage' => $homepage,
160                                 '$about' => $about,
161
162                         ));
163
164                         $arr = array('contact' => $rr, 'entry' => $entry);
165
166                         call_hooks('directory_item', $arr);
167                         
168                         unset($profile);
169                         unset($location);
170
171                         $o .= $entry;
172
173                 }
174
175                 $o .= "<div class=\"directory-end\" ></div>\r\n";
176                 $o .= paginate($a);
177
178         }
179         else
180                 info( t("No entries \x28some entries may be hidden\x29.") . EOL);
181
182         return $o;
183 }