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;
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)) {
114 while ($rr = DBA::fetch($r)) {
117 $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
119 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
121 $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
124 if (strlen($rr['locality'])) {
125 $details .= $rr['locality'];
127 if (strlen($rr['region'])) {
128 if (strlen($rr['locality'])) {
131 $details .= $rr['region'];
133 if (strlen($rr['country-name'])) {
134 if (strlen($details)) {
137 $details .= $rr['country-name'];
139 // if(strlen($rr['dob'])) {
140 // if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
141 // $details .= '<br />' . L10n::t('Age: ') . $years;
143 // if(strlen($rr['gender']))
144 // $details .= '<br />' . L10n::t('Gender: ') . $rr['gender'];
148 if (!empty($profile['address'])
149 || !empty($profile['locality'])
150 || !empty($profile['region'])
151 || !empty($profile['postal-code'])
152 || !empty($profile['country-name'])
154 $location = L10n::t('Location:');
159 $gender = (!empty($profile['gender']) ? L10n::t('Gender:') : false);
160 $marital = (!empty($profile['marital']) ? L10n::t('Status:') : false);
161 $homepage = (!empty($profile['homepage']) ? L10n::t('Homepage:') : false);
162 $about = (!empty($profile['about']) ? L10n::t('About:') : false);
164 $location_e = $location;
167 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
172 'url' => $profile_link,
173 'itemurl' => $itemurl,
174 'thumb' => ProxyUtils::proxifyUrl($rr[$photo], false, ProxyUtils::SIZE_THUMB),
175 'img_hover' => $rr['name'],
176 'name' => $rr['name'],
177 'details' => $details,
178 'account_type' => Contact::getAccountType($rr),
179 'profile' => $profile,
180 'location' => $location_e,
181 'tags' => $rr['pub_keywords'],
184 'marital' => $marital,
185 'homepage' => $homepage,
187 'photo_menu' => $photo_menu,
191 $arr = ['contact' => $rr, 'entry' => $entry];
193 Addon::callHooks('directory_item', $arr);
198 if (!$arr['entry']) {
202 $entries[] = $arr['entry'];
206 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
208 $o .= Renderer::replaceMacros($tpl, [
209 '$search' => $search,
210 '$globaldir' => L10n::t('Global Directory'),
211 '$gdirpath' => $gdirpath,
212 '$desc' => L10n::t('Find on this site'),
213 '$contacts' => $entries,
214 '$finding' => L10n::t('Results for:'),
215 '$findterm' => (strlen($search) ? $search : ""),
216 '$title' => L10n::t('Site Directory'),
217 '$submit' => L10n::t('Find'),
218 '$paginate' => $pager->renderFull($total),
221 info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);