]> git.mxchange.org Git - friendica.git/blob - mod/directory.php
"dba" is now a static class
[friendica.git] / mod / directory.php
1 <?php
2
3 use Friendica\App;
4
5 function directory_init(App $a) {
6         $a->set_pager_itemspage(60);
7
8         if(local_user()) {
9                 require_once('include/contact_widgets.php');
10
11                 $a->page['aside'] .= findpeople_widget();
12
13                 $a->page['aside'] .= follow_widget();
14         }
15         else {
16                 unset($_SESSION['theme']);
17                 unset($_SESSION['mobile-theme']);
18         }
19 }
20
21 function directory_post(App $a) {
22         if(x($_POST,'search'))
23                 $a->data['search'] = $_POST['search'];
24 }
25
26 function directory_content(App $a) {
27         require_once("mod/proxy.php");
28
29         if((get_config('system','block_public')) && (! local_user()) && (! remote_user()) ||
30                 (get_config('system','block_local_dir')) && (! 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         $gdirpath = '';
44         $dirurl = get_config('system','directory');
45         if(strlen($dirurl)) {
46                 $gdirpath = zrl($dirurl,true);
47         }
48
49         if($search) {
50                 $search = dbesc($search);
51
52                 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
53                                 (`user`.`nickname` LIKE '%$search%') OR
54                                 (`profile`.`pdesc` LIKE '%$search%') OR
55                                 (`profile`.`locality` LIKE '%$search%') OR
56                                 (`profile`.`region` LIKE '%$search%') OR
57                                 (`profile`.`country-name` LIKE '%$search%') OR
58                                 (`profile`.`gender` LIKE '%$search%') OR
59                                 (`profile`.`marital` LIKE '%$search%') OR
60                                 (`profile`.`sexual` LIKE '%$search%') OR
61                                 (`profile`.`about` LIKE '%$search%') OR
62                                 (`profile`.`romance` LIKE '%$search%') OR
63                                 (`profile`.`work` LIKE '%$search%') OR
64                                 (`profile`.`education` LIKE '%$search%') OR
65                                 (`profile`.`pub_keywords` LIKE '%$search%') OR
66                                 (`profile`.`prv_keywords` LIKE '%$search%'))";
67         }
68
69         $publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
70
71
72         $r = q("SELECT COUNT(*) AS `total` FROM `profile`
73                         LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
74                         WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ");
75         if (dbm::is_result($r))
76                 $a->set_pager_total($r[0]['total']);
77
78         $order = " ORDER BY `name` ASC ";
79
80         $limit = intval($a->pager['start']).",".intval($a->pager['itemspage']);
81
82         $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
83                         `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
84                         LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
85                         LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
86                         WHERE `is-default` $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit);
87         if (dbm::is_result($r)) {
88
89                 if (in_array('small', $a->argv)) {
90                         $photo = 'thumb';
91                 }
92                 else {
93                         $photo = 'photo';
94                 }
95
96                 foreach ($r as $rr) {
97
98                         $itemurl= '';
99
100                         $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
101
102                         $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
103
104                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
105
106                         $details = '';
107                         if(strlen($rr['locality']))
108                                 $details .= $rr['locality'];
109                         if(strlen($rr['region'])) {
110                                 if(strlen($rr['locality']))
111                                         $details .= ', ';
112                                 $details .= $rr['region'];
113                         }
114                         if(strlen($rr['country-name'])) {
115                                 if(strlen($details))
116                                         $details .= ', ';
117                                 $details .= $rr['country-name'];
118                         }
119 //                      if(strlen($rr['dob'])) {
120 //                              if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
121 //                                      $details .= '<br />' . t('Age: ') . $years ;
122 //                      }
123 //                      if(strlen($rr['gender']))
124 //                              $details .= '<br />' . t('Gender: ') . $rr['gender'];
125
126                         $profile = $rr;
127
128                         if((x($profile,'address') == 1)
129                                 || (x($profile,'locality') == 1)
130                                 || (x($profile,'region') == 1)
131                                 || (x($profile,'postal-code') == 1)
132                                 || (x($profile,'country-name') == 1))
133                         $location = t('Location:');
134
135                         $gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
136
137                         $marital = ((x($profile,'marital') == 1) ?  t('Status:') : False);
138
139                         $homepage = ((x($profile,'homepage') == 1) ?  t('Homepage:') : False);
140
141                         $about = ((x($profile,'about') == 1) ?  t('About:') : False);
142
143                         if($a->theme['template_engine'] === 'internal') {
144                                 $location_e = template_escape($location);
145                         }
146                         else {
147                                 $location_e = $location;
148                         }
149
150                         $photo_menu = array(
151                                 'profile' => array(t("View Profile"), zrl($profile_link))
152                         );
153
154                         $entry = array(
155                                 'id' => $rr['id'],
156                                 'url' => $profile_link,
157                                 'itemurl' => $itemurl,
158                                 'thumb' => proxy_url($rr[$photo], false, PROXY_SIZE_THUMB),
159                                 'img_hover' => $rr['name'],
160                                 'name' => $rr['name'],
161                                 'details' => $details,
162                                 'account_type' => account_type($rr),
163                                 'profile' => $profile,
164                                 'location' => $location_e,
165                                 'tags' => $rr['pub_keywords'],
166                                 'gender'   => $gender,
167                                 'pdesc' => $pdesc,
168                                 'marital'  => $marital,
169                                 'homepage' => $homepage,
170                                 'about' => $about,
171                                 'photo_menu' => $photo_menu,
172
173                         );
174
175                         $arr = array('contact' => $rr, 'entry' => $entry);
176
177                         call_hooks('directory_item', $arr);
178
179                         unset($profile);
180                         unset($location);
181
182                         if(! $arr['entry'])
183                                 continue;
184
185                         $entries[] = $arr['entry'];
186
187                 }
188
189                 $tpl = get_markup_template('directory_header.tpl');
190
191                 $o .= replace_macros($tpl, array(
192                         '$search' => $search,
193                         '$globaldir' => t('Global Directory'),
194                         '$gdirpath' => $gdirpath,
195                         '$desc' => t('Find on this site'),
196                         '$contacts' => $entries,
197                         '$finding' => t('Results for:'),
198                         '$findterm' => (strlen($search) ? $search : ""),
199                         '$title' => t('Site Directory'),
200                         '$submit' => t('Find'),
201                         '$paginate' => paginate($a),
202                 ));
203
204         }
205         else
206                 info( t("No entries \x28some entries may be hidden\x29.") . EOL);
207
208         return $o;
209 }