3 * @file mod/directory.php
6 use Friendica\Content\Nav;
7 use Friendica\Content\Widget;
8 use Friendica\Core\Addon;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Database\DBM;
12 use Friendica\Model\Contact;
13 use Friendica\Model\Profile;
15 function directory_init(App $a)
17 $a->set_pager_itemspage(60);
20 $a->page['aside'] .= Widget::findPeople();
21 $a->page['aside'] .= Widget::follow();
23 unset($_SESSION['theme']);
24 unset($_SESSION['mobile-theme']);
28 function directory_post(App $a)
30 if (x($_POST, 'search')) {
31 $a->data['search'] = $_POST['search'];
35 function directory_content(App $a)
37 require_once("mod/proxy.php");
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 = dbesc($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%'))";
81 $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 " );
84 $cnt = dba::fetch_first("SELECT COUNT(*) AS `total` FROM `profile`
85 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
86 WHERE `is-default` $publish AND NOT `user`.`blocked` $sql_extra");
87 if (DBM::is_result($cnt)) {
88 $a->set_pager_total($cnt['total']);
91 $order = " ORDER BY `name` ASC ";
93 $limit = intval($a->pager['start'])."," . intval($a->pager['itemspage']);
95 $r = dba::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
96 `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
97 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
98 LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
99 WHERE `is-default` $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit
101 if (DBM::is_result($r)) {
102 if (in_array('small', $a->argv)) {
108 while ($rr = dba::fetch($r)) {
111 $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
113 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
115 $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
118 if (strlen($rr['locality'])) {
119 $details .= $rr['locality'];
121 if (strlen($rr['region'])) {
122 if (strlen($rr['locality'])) {
125 $details .= $rr['region'];
127 if (strlen($rr['country-name'])) {
128 if (strlen($details)) {
131 $details .= $rr['country-name'];
133 // if(strlen($rr['dob'])) {
134 // if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
135 // $details .= '<br />' . L10n::t('Age: ') . $years ;
137 // if(strlen($rr['gender']))
138 // $details .= '<br />' . L10n::t('Gender: ') . $rr['gender'];
142 if ((x($profile, 'address') == 1)
143 || (x($profile, 'locality') == 1)
144 || (x($profile, 'region') == 1)
145 || (x($profile, 'postal-code') == 1)
146 || (x($profile, 'country-name') == 1)
148 $location = L10n::t('Location:');
151 $gender = ((x($profile, 'gender') == 1) ? L10n::t('Gender:') : false);
152 $marital = ((x($profile, 'marital') == 1) ? L10n::t('Status:') : false);
153 $homepage = ((x($profile, 'homepage') == 1) ? L10n::t('Homepage:') : false);
154 $about = ((x($profile, 'about') == 1) ? L10n::t('About:') : false);
156 $location_e = $location;
159 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
164 'url' => $profile_link,
165 'itemurl' => $itemurl,
166 'thumb' => proxy_url($rr[$photo], false, PROXY_SIZE_THUMB),
167 'img_hover' => $rr['name'],
168 'name' => $rr['name'],
169 'details' => $details,
170 'account_type' => Contact::getAccountType($rr),
171 'profile' => $profile,
172 'location' => $location_e,
173 'tags' => $rr['pub_keywords'],
176 'marital' => $marital,
177 'homepage' => $homepage,
179 'photo_menu' => $photo_menu,
183 $arr = ['contact' => $rr, 'entry' => $entry];
185 Addon::callHooks('directory_item', $arr);
190 if (!$arr['entry']) {
194 $entries[] = $arr['entry'];
198 $tpl = get_markup_template('directory_header.tpl');
200 $o .= replace_macros($tpl, [
201 '$search' => $search,
202 '$globaldir' => L10n::t('Global Directory'),
203 '$gdirpath' => $gdirpath,
204 '$desc' => L10n::t('Find on this site'),
205 '$contacts' => $entries,
206 '$finding' => L10n::t('Results for:'),
207 '$findterm' => (strlen($search) ? $search : ""),
208 '$title' => L10n::t('Site Directory'),
209 '$submit' => L10n::t('Find'),
210 '$paginate' => paginate($a),
213 info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);