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\Database\DBA;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Profile;
16 use Friendica\Util\Proxy as ProxyUtils;
18 function directory_init(App $a)
21 $a->page['aside'] .= Widget::findPeople();
22 $a->page['aside'] .= Widget::follow();
24 unset($_SESSION['theme']);
25 unset($_SESSION['mobile-theme']);
29 function directory_post(App $a)
31 if (x($_POST, 'search')) {
32 $a->data['search'] = $_POST['search'];
36 function directory_content(App $a)
38 if ((Config::get('system', 'block_public') && !local_user() && !remote_user())
39 || (Config::get('system', 'block_local_dir') && !local_user() && !remote_user())
41 notice(L10n::t('Public access denied.') . EOL);
46 Nav::setSelected('directory');
48 if (x($a->data, 'search')) {
49 $search = notags(trim($a->data['search']));
51 $search = ((x($_GET, 'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
55 $dirurl = Config::get('system', 'directory');
56 if (strlen($dirurl)) {
57 $gdirpath = Profile::zrl($dirurl, true);
61 $search = DBA::escape($search);
63 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
64 (`user`.`nickname` LIKE '%$search%') OR
65 (`profile`.`pdesc` LIKE '%$search%') OR
66 (`profile`.`locality` LIKE '%$search%') OR
67 (`profile`.`region` LIKE '%$search%') OR
68 (`profile`.`country-name` LIKE '%$search%') OR
69 (`profile`.`gender` LIKE '%$search%') OR
70 (`profile`.`marital` LIKE '%$search%') OR
71 (`profile`.`sexual` LIKE '%$search%') OR
72 (`profile`.`about` LIKE '%$search%') OR
73 (`profile`.`romance` LIKE '%$search%') OR
74 (`profile`.`work` LIKE '%$search%') OR
75 (`profile`.`education` LIKE '%$search%') OR
76 (`profile`.`pub_keywords` LIKE '%$search%') OR
77 (`profile`.`prv_keywords` LIKE '%$search%'))";
82 $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 $total = $cnt['total'];
92 $pager = new Pager($a->query_string, $total, 60);
94 $order = " ORDER BY `name` ASC ";
96 $limit = $pager->getStart()."," . $pager->getItemsPerPage();
98 $r = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
99 `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
100 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
101 LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
102 WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
103 $sql_extra $order LIMIT $limit"
105 if (DBA::isResult($r)) {
106 if (in_array('small', $a->argv)) {
112 while ($rr = DBA::fetch($r)) {
115 $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
117 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
119 $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
122 if (strlen($rr['locality'])) {
123 $details .= $rr['locality'];
125 if (strlen($rr['region'])) {
126 if (strlen($rr['locality'])) {
129 $details .= $rr['region'];
131 if (strlen($rr['country-name'])) {
132 if (strlen($details)) {
135 $details .= $rr['country-name'];
137 // if(strlen($rr['dob'])) {
138 // if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
139 // $details .= '<br />' . L10n::t('Age: ') . $years ;
141 // if(strlen($rr['gender']))
142 // $details .= '<br />' . L10n::t('Gender: ') . $rr['gender'];
146 if ((x($profile, 'address') == 1)
147 || (x($profile, 'locality') == 1)
148 || (x($profile, 'region') == 1)
149 || (x($profile, 'postal-code') == 1)
150 || (x($profile, 'country-name') == 1)
152 $location = L10n::t('Location:');
157 $gender = ((x($profile, 'gender') == 1) ? L10n::t('Gender:') : false);
158 $marital = ((x($profile, 'marital') == 1) ? L10n::t('Status:') : false);
159 $homepage = ((x($profile, 'homepage') == 1) ? L10n::t('Homepage:') : false);
160 $about = ((x($profile, 'about') == 1) ? L10n::t('About:') : false);
162 $location_e = $location;
165 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
170 'url' => $profile_link,
171 'itemurl' => $itemurl,
172 'thumb' => ProxyUtils::proxifyUrl($rr[$photo], false, ProxyUtils::SIZE_THUMB),
173 'img_hover' => $rr['name'],
174 'name' => $rr['name'],
175 'details' => $details,
176 'account_type' => Contact::getAccountType($rr),
177 'profile' => $profile,
178 'location' => $location_e,
179 'tags' => $rr['pub_keywords'],
182 'marital' => $marital,
183 'homepage' => $homepage,
185 'photo_menu' => $photo_menu,
189 $arr = ['contact' => $rr, 'entry' => $entry];
191 Addon::callHooks('directory_item', $arr);
196 if (!$arr['entry']) {
200 $entries[] = $arr['entry'];
204 $tpl = get_markup_template('directory_header.tpl');
206 $o .= replace_macros($tpl, [
207 '$search' => $search,
208 '$globaldir' => L10n::t('Global Directory'),
209 '$gdirpath' => $gdirpath,
210 '$desc' => L10n::t('Find on this site'),
211 '$contacts' => $entries,
212 '$finding' => L10n::t('Results for:'),
213 '$findterm' => (strlen($search) ? $search : ""),
214 '$title' => L10n::t('Site Directory'),
215 '$submit' => L10n::t('Find'),
216 '$paginate' => $pager->renderFull(),
219 info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);