]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
directory.php: move html to templates
[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         global $db;
30
31         require_once("mod/proxy.php");
32
33         if((get_config('system','block_public')) && (! local_user()) && (! remote_user()) || 
34                 (get_config('system','block_local_dir')) && (! local_user()) && (! remote_user())) {
35                 notice( t('Public access denied.') . EOL);
36                 return;
37         }
38
39         $o = '';
40         nav_set_selected('directory');
41
42         if(x($a->data,'search'))
43                 $search = notags(trim($a->data['search']));
44         else
45                 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
46
47         $gdirpath = '';
48         $dirurl = get_config('system','directory');
49         if(strlen($dirurl)) {
50                 $gdirpath = zrl($dirurl,true);
51         }
52
53         if($search) {
54                 $search = dbesc($search);
55
56                 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
57                                 (`user`.`nickname` LIKE '%$search%') OR
58                                 (`pdesc` LIKE '%$search%') OR
59                                 (`locality` LIKE '%$search%') OR
60                                 (`region` LIKE '%$search%') OR
61                                 (`country-name` LIKE '%$search%') OR
62                                 (`gender` LIKE '%$search%') OR
63                                 (`marital` LIKE '%$search%') OR
64                                 (`sexual` LIKE '%$search%') OR
65                                 (`about` LIKE '%$search%') OR
66                                 (`romance` LIKE '%$search%') OR
67                                 (`work` LIKE '%$search%') OR
68                                 (`education` LIKE '%$search%') OR
69                                 (`pub_keywords` LIKE '%$search%') OR
70                                 (`prv_keywords` LIKE '%$search%'))";
71         }
72
73         $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
74
75
76         $r = $db->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 ");
77         if(count($r))
78                 $a->set_pager_total($r[0]['total']);
79
80         $order = " ORDER BY `name` ASC ";
81
82         $limit = intval($a->pager['start']).",".intval($a->pager['itemspage']);
83
84         $r = $db->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 ".$limit);
85         if(count($r)) {
86
87                 if(in_array('small', $a->argv))
88                         $photo = 'thumb';
89                 else
90                         $photo = 'photo';
91
92                 foreach($r as $rr) {
93
94
95                         $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
96
97                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
98
99                         $details = '';
100                         if(strlen($rr['locality']))
101                                 $details .= $rr['locality'];
102                         if(strlen($rr['region'])) {
103                                 if(strlen($rr['locality']))
104                                         $details .= ', ';
105                                 $details .= $rr['region'];
106                         }
107                         if(strlen($rr['country-name'])) {
108                                 if(strlen($details))
109                                         $details .= ', ';
110                                 $details .= $rr['country-name'];
111                         }
112                         if(strlen($rr['dob'])) {
113                                 if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
114                                         $details .= '<br />' . t('Age: ') . $years ; 
115                         }
116                         if(strlen($rr['gender']))
117                                 $details .= '<br />' . t('Gender: ') . $rr['gender'];
118
119                         if($rr['page-flags'] == PAGE_NORMAL)
120                                 $page_type = "Personal Profile";
121                         if($rr['page-flags'] == PAGE_SOAPBOX)
122                                 $page_type = "Fan Page";
123                         if($rr['page-flags'] == PAGE_COMMUNITY)
124                                 $page_type = "Community Forum";
125                         if($rr['page-flags'] == PAGE_FREELOVE)
126                                 $page_type = "Open Forum";
127                         if($rr['page-flags'] == PAGE_PRVGROUP)
128                                 $page_type = "Private Group";
129
130                         $profile = $rr;
131
132                         if((x($profile,'address') == 1)
133                                 || (x($profile,'locality') == 1)
134                                 || (x($profile,'region') == 1)
135                                 || (x($profile,'postal-code') == 1)
136                                 || (x($profile,'country-name') == 1))
137                         $location = t('Location:');
138
139                         $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
140
141                         $marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
142
143                         $homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);
144
145                         $about = ((x($profile,'about') == 1) ?  t('About:') : False);
146
147                         if($a->theme['template_engine'] === 'internal') {
148                                 $location_e = template_escape($location);
149                         }
150                         else {
151                                 $location_e = $location;
152                         }
153
154                         $entry = array(
155                                 'id' => $rr['id'],
156                                 'profile_link' => $profile_link,
157                                 'photo' => proxy_url($a->get_cached_avatar_image($rr[$photo]), false, PROXY_SIZE_THUMB),
158                                 'alt_text' => $rr['name'],
159                                 'name' => $rr['name'],
160                                 'details' => $pdesc . $details,
161                                 'page_type' => $page_type,
162                                 'profile' => $profile,
163                                 'location' => $location_e,
164                                 'gender'   => $gender,
165                                 'pdesc' => $pdesc,
166                                 'marital'  => $marital,
167                                 'homepage' => $homepage,
168                                 'about' => $about,
169
170                         );
171
172                         $arr = array('contact' => $rr, 'entry' => $entry);
173
174                         call_hooks('directory_item', $arr);
175
176                         unset($profile);
177                         unset($location);
178
179                         if(! $arr['entry'])
180                                 continue;
181
182                         $entries[] = $arr['entry'];
183
184                 }
185
186                 $tpl = get_markup_template('directory_header.tpl');
187
188                 $o .= replace_macros($tpl, array(
189                         '$search' => $search,
190                         '$globaldir' => t('Global Directory'),
191                         '$gdirpath' => $gdirpath,
192                         '$desc' => t('Find on this site'),
193                         '$entries' => $entries,
194                         '$finding' => t('Finding:'),
195                         '$findterm' => (strlen($search) ? $search : ""),
196                         '$sitedir' => t('Site Directory'),
197                         '$submit' => t('Find')
198                 ));
199
200                 $o .= paginate($a);
201
202         }
203         else
204                 info( t("No entries \x28some entries may be hidden\x29.") . EOL);
205
206         return $o;
207 }