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);
50 Nav::setSelected('directory');
52 if (!empty($a->data['search'])) {
53 $search = Strings::escapeTags(trim($a->data['search']));
55 $search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : '');
59 $dirurl = Config::get('system', 'directory');
60 if (strlen($dirurl)) {
61 $gdirpath = Profile::zrl($dirurl, true);
65 $search = DBA::escape($search);
67 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
68 (`user`.`nickname` LIKE '%$search%') OR
69 (`profile`.`pdesc` LIKE '%$search%') OR
70 (`profile`.`locality` LIKE '%$search%') OR
71 (`profile`.`region` LIKE '%$search%') OR
72 (`profile`.`country-name` LIKE '%$search%') OR
73 (`profile`.`gender` LIKE '%$search%') OR
74 (`profile`.`marital` LIKE '%$search%') OR
75 (`profile`.`sexual` LIKE '%$search%') OR
76 (`profile`.`about` LIKE '%$search%') OR
77 (`profile`.`romance` LIKE '%$search%') OR
78 (`profile`.`work` LIKE '%$search%') OR
79 (`profile`.`education` LIKE '%$search%') OR
80 (`profile`.`pub_keywords` LIKE '%$search%') OR
81 (`profile`.`prv_keywords` LIKE '%$search%'))";
86 $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 " );
90 $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `profile`
91 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
92 WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` $sql_extra");
93 if (DBA::isResult($cnt)) {
94 $total = $cnt['total'];
96 $pager = new Pager($a->query_string, 60);
98 $order = " ORDER BY `name` ASC ";
100 $limit = $pager->getStart()."," . $pager->getItemsPerPage();
102 $r = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
103 `contact`.`addr`, `contact`.`url` AS `profile_url` FROM `profile`
104 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
105 LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
106 WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
107 $sql_extra $order LIMIT $limit"
109 if (DBA::isResult($r)) {
110 if (in_array('small', $a->argv)) {
116 while ($rr = DBA::fetch($r)) {
117 $entries[] = format_directory_entry($rr, $photo);
121 info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);
124 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
126 $o .= Renderer::replaceMacros($tpl, [
127 '$search' => $search,
128 '$globaldir' => L10n::t('Global Directory'),
129 '$gdirpath' => $gdirpath,
130 '$desc' => L10n::t('Find on this site'),
131 '$contacts' => $entries,
132 '$finding' => L10n::t('Results for:'),
133 '$findterm' => (strlen($search) ? $search : ""),
134 '$title' => L10n::t('Site Directory'),
135 '$search_mod' => 'directory',
136 '$submit' => L10n::t('Find'),
137 '$paginate' => $pager->renderFull($total),
144 * Format contact/profile/user data from the database into an usable
145 * array for displaying directory entries.
147 * @param array $arr The directory entry from the database.
148 * @param string $photo_size Avatar size (thumb, photo or micro).
152 function format_directory_entry(array $arr, $photo_size = 'photo')
154 $itemurl = (($arr['addr'] != "") ? $arr['addr'] : $arr['profile_url']);
156 $profile_link = $arr['profile_url'];
158 $pdesc = (($arr['pdesc']) ? $arr['pdesc'] . '<br />' : '');
161 if (strlen($arr['locality'])) {
162 $details .= $arr['locality'];
164 if (strlen($arr['region'])) {
165 if (strlen($arr['locality'])) {
168 $details .= $arr['region'];
170 if (strlen($arr['country-name'])) {
171 if (strlen($details)) {
174 $details .= $arr['country-name'];
179 if (!empty($profile['address'])
180 || !empty($profile['locality'])
181 || !empty($profile['region'])
182 || !empty($profile['postal-code'])
183 || !empty($profile['country-name'])
185 $location = L10n::t('Location:');
190 $gender = (!empty($profile['gender']) ? L10n::t('Gender:') : false);
191 $marital = (!empty($profile['marital']) ? L10n::t('Status:') : false);
192 $homepage = (!empty($profile['homepage']) ? L10n::t('Homepage:') : false);
193 $about = (!empty($profile['about']) ? L10n::t('About:') : false);
195 $location_e = $location;
198 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
203 'url' => Contact::magicLInk($profile_link),
204 'itemurl' => $itemurl,
205 'thumb' => ProxyUtils::proxifyUrl($arr[$photo_size], false, ProxyUtils::SIZE_THUMB),
206 'img_hover' => $arr['name'],
207 'name' => $arr['name'],
208 'details' => $details,
209 'account_type' => Contact::getAccountType($arr),
210 'profile' => $profile,
211 'location' => $location_e,
212 'tags' => $arr['pub_keywords'],
215 'marital' => $marital,
216 'homepage' => $homepage,
218 'photo_menu' => $photo_menu,
222 $hook = ['contact' => $arr, 'entry' => $entry];
224 Hook::callAll('directory_item', $hook);
229 return $hook['entry'];