Frio - bugfix - don't show new event button if the button isn't available
[friendica.git/.git] / mod / directory.php
1 <?php
2 /**
3  * @file mod/directory.php
4  */
5
6 use Friendica\App;
7 use Friendica\Content\Nav;
8 use Friendica\Content\Widget;
9 use Friendica\Core\Addon;
10 use Friendica\Core\Config;
11 use Friendica\Core\L10n;
12 use Friendica\Database\DBA;
13 use Friendica\Model\Contact;
14 use Friendica\Model\Profile;
15 use Friendica\Util\Proxy as ProxyUtils;
16
17 function directory_init(App $a)
18 {
19         $a->set_pager_itemspage(60);
20
21         if (local_user()) {
22                 $a->page['aside'] .= Widget::findPeople();
23                 $a->page['aside'] .= Widget::follow();
24         } else {
25                 unset($_SESSION['theme']);
26                 unset($_SESSION['mobile-theme']);
27         }
28 }
29
30 function directory_post(App $a)
31 {
32         if (x($_POST, 'search')) {
33                 $a->data['search'] = $_POST['search'];
34         }
35 }
36
37 function directory_content(App $a)
38 {
39         if ((Config::get('system', 'block_public') && !local_user() && !remote_user())
40                 || (Config::get('system', 'block_local_dir') && !local_user() && !remote_user())
41         ) {
42                 notice(L10n::t('Public access denied.') . EOL);
43                 return;
44         }
45
46         $o = '';
47         Nav::setSelected('directory');
48
49         if (x($a->data, 'search')) {
50                 $search = notags(trim($a->data['search']));
51         } else {
52                 $search = ((x($_GET, 'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
53         }
54
55         $gdirpath = '';
56         $dirurl = Config::get('system', 'directory');
57         if (strlen($dirurl)) {
58                 $gdirpath = Profile::zrl($dirurl, true);
59         }
60
61         if ($search) {
62                 $search = DBA::escape($search);
63
64                 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
65                                 (`user`.`nickname` LIKE '%$search%') OR
66                                 (`profile`.`pdesc` LIKE '%$search%') OR
67                                 (`profile`.`locality` LIKE '%$search%') OR
68                                 (`profile`.`region` LIKE '%$search%') OR
69                                 (`profile`.`country-name` LIKE '%$search%') OR
70                                 (`profile`.`gender` LIKE '%$search%') OR
71                                 (`profile`.`marital` LIKE '%$search%') OR
72                                 (`profile`.`sexual` LIKE '%$search%') OR
73                                 (`profile`.`about` LIKE '%$search%') OR
74                                 (`profile`.`romance` LIKE '%$search%') OR
75                                 (`profile`.`work` LIKE '%$search%') OR
76                                 (`profile`.`education` LIKE '%$search%') OR
77                                 (`profile`.`pub_keywords` LIKE '%$search%') OR
78                                 (`profile`.`prv_keywords` LIKE '%$search%'))";
79         } else {
80                 $sql_extra = '';
81         }
82
83         $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 " );
84
85
86         $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `profile`
87                                 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
88                                 WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` $sql_extra");
89         if (DBA::isResult($cnt)) {
90                 $a->set_pager_total($cnt['total']);
91         }
92
93         $order = " ORDER BY `name` ASC ";
94
95         $limit = intval($a->pager['start'])."," . intval($a->pager['itemspage']);
96
97         $r = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
98                         `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
99                         LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
100                         LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
101                         WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
102                         $sql_extra $order LIMIT $limit"
103         );
104         if (DBA::isResult($r)) {
105                 if (in_array('small', $a->argv)) {
106                         $photo = 'thumb';
107                 } else {
108                         $photo = 'photo';
109                 }
110
111                 while ($rr = DBA::fetch($r)) {
112                         $itemurl= '';
113
114                         $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
115
116                         $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
117
118                         $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
119
120                         $details = '';
121                         if (strlen($rr['locality'])) {
122                                 $details .= $rr['locality'];
123                         }
124                         if (strlen($rr['region'])) {
125                                 if (strlen($rr['locality'])) {
126                                         $details .= ', ';
127                                 }
128                                 $details .= $rr['region'];
129                         }
130                         if (strlen($rr['country-name'])) {
131                                 if (strlen($details)) {
132                                         $details .= ', ';
133                                 }
134                                 $details .= $rr['country-name'];
135                         }
136 //                      if(strlen($rr['dob'])) {
137 //                              if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
138 //                                      $details .= '<br />' . L10n::t('Age: ') . $years ;
139 //                      }
140 //                      if(strlen($rr['gender']))
141 //                              $details .= '<br />' . L10n::t('Gender: ') . $rr['gender'];
142
143                         $profile = $rr;
144
145                         if ((x($profile, 'address')             == 1)
146                                 || (x($profile, 'locality')     == 1)
147                                 || (x($profile, 'region')       == 1)
148                                 || (x($profile, 'postal-code')  == 1)
149                                 || (x($profile, 'country-name') == 1)
150                         ) {
151                                 $location = L10n::t('Location:');
152                         } else {
153                                 $location = '';
154                         }
155
156                         $gender   = ((x($profile, 'gender')   == 1) ? L10n::t('Gender:')   : false);
157                         $marital  = ((x($profile, 'marital')  == 1) ? L10n::t('Status:')   : false);
158                         $homepage = ((x($profile, 'homepage') == 1) ? L10n::t('Homepage:') : false);
159                         $about    = ((x($profile, 'about')    == 1) ? L10n::t('About:')    : false);
160
161                         $location_e = $location;
162
163                         $photo_menu = [
164                                 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
165                         ];
166
167                         $entry = [
168                                 'id'           => $rr['id'],
169                                 'url'          => $profile_link,
170                                 'itemurl'      => $itemurl,
171                                 'thumb'        => ProxyUtils::proxifyUrl($rr[$photo], false, ProxyUtils::SIZE_THUMB),
172                                 'img_hover'    => $rr['name'],
173                                 'name'         => $rr['name'],
174                                 'details'      => $details,
175                                 'account_type' => Contact::getAccountType($rr),
176                                 'profile'      => $profile,
177                                 'location'     => $location_e,
178                                 'tags'         => $rr['pub_keywords'],
179                                 'gender'       => $gender,
180                                 'pdesc'        => $pdesc,
181                                 'marital'      => $marital,
182                                 'homepage'     => $homepage,
183                                 'about'        => $about,
184                                 'photo_menu'   => $photo_menu,
185
186                         ];
187
188                         $arr = ['contact' => $rr, 'entry' => $entry];
189
190                         Addon::callHooks('directory_item', $arr);
191
192                         unset($profile);
193                         unset($location);
194
195                         if (!$arr['entry']) {
196                                 continue;
197                         }
198
199                         $entries[] = $arr['entry'];
200                 }
201                 DBA::close($r);
202
203                 $tpl = get_markup_template('directory_header.tpl');
204
205                 $o .= replace_macros($tpl, [
206                         '$search'    => $search,
207                         '$globaldir' => L10n::t('Global Directory'),
208                         '$gdirpath'  => $gdirpath,
209                         '$desc'      => L10n::t('Find on this site'),
210                         '$contacts'  => $entries,
211                         '$finding'   => L10n::t('Results for:'),
212                         '$findterm'  => (strlen($search) ? $search : ""),
213                         '$title'     => L10n::t('Site Directory'),
214                         '$submit'    => L10n::t('Find'),
215                         '$paginate'  => paginate($a),
216                 ]);
217         } else {
218                 info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);
219         }
220
221         return $o;
222 }