3 * @file mod/directory.php
7 use Friendica\Content\Nav;
8 use Friendica\Content\Pager;
9 use Friendica\Content\Widget;
10 use Friendica\Core\Config;
11 use Friendica\Core\Hook;
12 use Friendica\Core\L10n;
13 use Friendica\Core\Renderer;
14 use Friendica\Database\DBA;
15 use Friendica\Model\Contact;
16 use Friendica\Model\Profile;
17 use Friendica\Util\Proxy as ProxyUtils;
18 use Friendica\Util\Strings;
20 function directory_init(App $a)
23 $a->page['aside'] .= Widget::findPeople();
24 $a->page['aside'] .= Widget::follow();
26 unset($_SESSION['theme']);
27 unset($_SESSION['mobile-theme']);
31 function directory_post(App $a)
33 if (!empty($_POST['search'])) {
34 $a->data['search'] = $_POST['search'];
38 function directory_content(App $a)
40 if ((Config::get('system', 'block_public') && !local_user() && !remote_user())
41 || (Config::get('system', 'block_local_dir') && !local_user() && !remote_user())
43 notice(L10n::t('Public access denied.') . EOL);
48 Nav::setSelected('directory');
50 if (!empty($a->data['search'])) {
51 $search = Strings::escapeTags(trim($a->data['search']));
53 $search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : '');
57 $dirurl = Config::get('system', 'directory');
58 if (strlen($dirurl)) {
59 $gdirpath = Profile::zrl($dirurl, true);
63 $search = DBA::escape($search);
65 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
66 (`user`.`nickname` LIKE '%$search%') OR
67 (`profile`.`pdesc` LIKE '%$search%') OR
68 (`profile`.`locality` LIKE '%$search%') OR
69 (`profile`.`region` LIKE '%$search%') OR
70 (`profile`.`country-name` LIKE '%$search%') OR
71 (`profile`.`gender` LIKE '%$search%') OR
72 (`profile`.`marital` LIKE '%$search%') OR
73 (`profile`.`sexual` LIKE '%$search%') OR
74 (`profile`.`about` LIKE '%$search%') OR
75 (`profile`.`romance` LIKE '%$search%') OR
76 (`profile`.`work` LIKE '%$search%') OR
77 (`profile`.`education` LIKE '%$search%') OR
78 (`profile`.`pub_keywords` LIKE '%$search%') OR
79 (`profile`.`prv_keywords` LIKE '%$search%'))";
84 $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 " );
88 $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `profile`
89 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
90 WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` $sql_extra");
91 if (DBA::isResult($cnt)) {
92 $total = $cnt['total'];
94 $pager = new Pager($a->query_string, 60);
96 $order = " ORDER BY `name` ASC ";
98 $limit = $pager->getStart()."," . $pager->getItemsPerPage();
100 $r = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
101 `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
102 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
103 LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
104 WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
105 $sql_extra $order LIMIT $limit"
107 if (DBA::isResult($r)) {
108 if (in_array('small', $a->argv)) {
116 while ($rr = DBA::fetch($r)) {
118 while ($rr = DBA::fetch($r)) {
119 $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
121 $profile_link = $rr['profile_url'];
123 $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
126 if (strlen($rr['locality'])) {
127 $details .= $rr['locality'];
129 if (strlen($rr['region'])) {
130 if (strlen($rr['locality'])) {
133 $details .= $rr['region'];
135 if (strlen($rr['country-name'])) {
136 if (strlen($details)) {
139 $details .= $rr['country-name'];
141 // if(strlen($rr['dob'])) {
142 // if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
143 // $details .= '<br />' . L10n::t('Age: ') . $years;
145 // if(strlen($rr['gender']))
146 // $details .= '<br />' . L10n::t('Gender: ') . $rr['gender'];
150 if (!empty($profile['address'])
151 || !empty($profile['locality'])
152 || !empty($profile['region'])
153 || !empty($profile['postal-code'])
154 || !empty($profile['country-name'])
156 $location = L10n::t('Location:');
161 $gender = (!empty($profile['gender']) ? L10n::t('Gender:') : false);
162 $marital = (!empty($profile['marital']) ? L10n::t('Status:') : false);
163 $homepage = (!empty($profile['homepage']) ? L10n::t('Homepage:') : false);
164 $about = (!empty($profile['about']) ? L10n::t('About:') : false);
166 $location_e = $location;
169 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
174 'url' => Contact::magicLInk($profile_link),
175 'itemurl' => $itemurl,
176 'thumb' => ProxyUtils::proxifyUrl($rr[$photo], false, ProxyUtils::SIZE_THUMB),
177 'img_hover' => $rr['name'],
178 'name' => $rr['name'],
179 'details' => $details,
180 'account_type' => Contact::getAccountType($rr),
181 'profile' => $profile,
182 'location' => $location_e,
183 'tags' => $rr['pub_keywords'],
186 'marital' => $marital,
187 'homepage' => $homepage,
189 'photo_menu' => $photo_menu,
193 $arr = ['contact' => $rr, 'entry' => $entry];
195 Hook::callAll('directory_item', $arr);
200 if (!$arr['entry']) {
204 $entries[] = $arr['entry'];
208 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
210 $o .= Renderer::replaceMacros($tpl, [
211 '$search' => $search,
212 '$globaldir' => L10n::t('Global Directory'),
213 '$gdirpath' => $gdirpath,
214 '$desc' => L10n::t('Find on this site'),
215 '$contacts' => $entries,
216 '$finding' => L10n::t('Results for:'),
217 '$findterm' => (strlen($search) ? $search : ""),
218 '$title' => L10n::t('Site Directory'),
219 '$submit' => L10n::t('Find'),
220 '$paginate' => $pager->renderFull($total),
223 info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);