3 * @file mod/directory.php
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;
17 function directory_init(App $a)
19 $a->set_pager_itemspage(60);
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 " );
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']);
93 $order = " ORDER BY `name` ASC ";
95 $limit = intval($a->pager['start'])."," . intval($a->pager['itemspage']);
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"
104 if (DBA::isResult($r)) {
105 if (in_array('small', $a->argv)) {
111 while ($rr = DBA::fetch($r)) {
114 $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
116 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
118 $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
121 if (strlen($rr['locality'])) {
122 $details .= $rr['locality'];
124 if (strlen($rr['region'])) {
125 if (strlen($rr['locality'])) {
128 $details .= $rr['region'];
130 if (strlen($rr['country-name'])) {
131 if (strlen($details)) {
134 $details .= $rr['country-name'];
136 // if(strlen($rr['dob'])) {
137 // if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
138 // $details .= '<br />' . L10n::t('Age: ') . $years ;
140 // if(strlen($rr['gender']))
141 // $details .= '<br />' . L10n::t('Gender: ') . $rr['gender'];
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)
151 $location = L10n::t('Location:');
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);
161 $location_e = $location;
164 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
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'],
181 'marital' => $marital,
182 'homepage' => $homepage,
184 'photo_menu' => $photo_menu,
188 $arr = ['contact' => $rr, 'entry' => $entry];
190 Addon::callHooks('directory_item', $arr);
195 if (!$arr['entry']) {
199 $entries[] = $arr['entry'];
203 $tpl = get_markup_template('directory_header.tpl');
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),
218 info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);