3 * @file mod/directory.php
7 use Friendica\Content\Nav;
8 use Friendica\Content\Pager;
9 use Friendica\Content\Widget;
10 use Friendica\Core\Addon;
11 use Friendica\Core\Config;
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;
19 function directory_init(App $a)
22 $a->page['aside'] .= Widget::findPeople();
23 $a->page['aside'] .= Widget::follow();
25 unset($_SESSION['theme']);
26 unset($_SESSION['mobile-theme']);
30 function directory_post(App $a)
32 if (x($_POST, 'search')) {
33 $a->data['search'] = $_POST['search'];
37 function directory_content(App $a)
39 if ((Config::get('system', 'block_public') && !local_user() && !remote_user())
40 || (Config::get('system', 'block_local_dir') && !local_user() && !remote_user())
42 notice(L10n::t('Public access denied.') . EOL);
47 Nav::setSelected('directory');
49 if (x($a->data, 'search')) {
50 $search = notags(trim($a->data['search']));
52 $search = ((x($_GET, 'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
56 $dirurl = Config::get('system', 'directory');
57 if (strlen($dirurl)) {
58 $gdirpath = Profile::zrl($dirurl, true);
62 $search = DBA::escape($search);
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%'))";
83 $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 " );
87 $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `profile`
88 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
89 WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` $sql_extra");
90 if (DBA::isResult($cnt)) {
91 $total = $cnt['total'];
93 $pager = new Pager($a->query_string, 60);
95 $order = " ORDER BY `name` ASC ";
97 $limit = $pager->getStart()."," . $pager->getItemsPerPage();
99 $r = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
100 `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
101 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
102 LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
103 WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
104 $sql_extra $order LIMIT $limit"
106 if (DBA::isResult($r)) {
107 if (in_array('small', $a->argv)) {
113 while ($rr = DBA::fetch($r)) {
116 $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
118 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
120 $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
123 if (strlen($rr['locality'])) {
124 $details .= $rr['locality'];
126 if (strlen($rr['region'])) {
127 if (strlen($rr['locality'])) {
130 $details .= $rr['region'];
132 if (strlen($rr['country-name'])) {
133 if (strlen($details)) {
136 $details .= $rr['country-name'];
138 // if(strlen($rr['dob'])) {
139 // if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
140 // $details .= '<br />' . L10n::t('Age: ') . $years ;
142 // if(strlen($rr['gender']))
143 // $details .= '<br />' . L10n::t('Gender: ') . $rr['gender'];
147 if ((x($profile, 'address') == 1)
148 || (x($profile, 'locality') == 1)
149 || (x($profile, 'region') == 1)
150 || (x($profile, 'postal-code') == 1)
151 || (x($profile, 'country-name') == 1)
153 $location = L10n::t('Location:');
158 $gender = ((x($profile, 'gender') == 1) ? L10n::t('Gender:') : false);
159 $marital = ((x($profile, 'marital') == 1) ? L10n::t('Status:') : false);
160 $homepage = ((x($profile, 'homepage') == 1) ? L10n::t('Homepage:') : false);
161 $about = ((x($profile, 'about') == 1) ? L10n::t('About:') : false);
163 $location_e = $location;
166 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
171 'url' => $profile_link,
172 'itemurl' => $itemurl,
173 'thumb' => ProxyUtils::proxifyUrl($rr[$photo], false, ProxyUtils::SIZE_THUMB),
174 'img_hover' => $rr['name'],
175 'name' => $rr['name'],
176 'details' => $details,
177 'account_type' => Contact::getAccountType($rr),
178 'profile' => $profile,
179 'location' => $location_e,
180 'tags' => $rr['pub_keywords'],
183 'marital' => $marital,
184 'homepage' => $homepage,
186 'photo_menu' => $photo_menu,
190 $arr = ['contact' => $rr, 'entry' => $entry];
192 Addon::callHooks('directory_item', $arr);
197 if (!$arr['entry']) {
201 $entries[] = $arr['entry'];
205 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
207 $o .= Renderer::replaceMacros($tpl, [
208 '$search' => $search,
209 '$globaldir' => L10n::t('Global Directory'),
210 '$gdirpath' => $gdirpath,
211 '$desc' => L10n::t('Find on this site'),
212 '$contacts' => $entries,
213 '$finding' => L10n::t('Results for:'),
214 '$findterm' => (strlen($search) ? $search : ""),
215 '$title' => L10n::t('Site Directory'),
216 '$submit' => L10n::t('Find'),
217 '$paginate' => $pager->renderFull($total),
220 info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);