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) {
16 $a->set_pager_itemspage(60);
19 $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) {
29 if(x($_POST,'search'))
30 $a->data['search'] = $_POST['search'];
33 function directory_content(App $a) {
34 require_once("mod/proxy.php");
36 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user()) ||
37 (Config::get('system','block_local_dir')) && (! local_user()) && (! remote_user())) {
38 notice(L10n::t('Public access denied.') . EOL);
43 Nav::setSelected('directory');
45 if(x($a->data,'search'))
46 $search = notags(trim($a->data['search']));
48 $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
51 $dirurl = Config::get('system','directory');
53 $gdirpath = Profile::zrl($dirurl,true);
57 $search = dbesc($search);
59 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
60 (`user`.`nickname` LIKE '%$search%') OR
61 (`profile`.`pdesc` LIKE '%$search%') OR
62 (`profile`.`locality` LIKE '%$search%') OR
63 (`profile`.`region` LIKE '%$search%') OR
64 (`profile`.`country-name` LIKE '%$search%') OR
65 (`profile`.`gender` LIKE '%$search%') OR
66 (`profile`.`marital` LIKE '%$search%') OR
67 (`profile`.`sexual` LIKE '%$search%') OR
68 (`profile`.`about` LIKE '%$search%') OR
69 (`profile`.`romance` LIKE '%$search%') OR
70 (`profile`.`work` LIKE '%$search%') OR
71 (`profile`.`education` LIKE '%$search%') OR
72 (`profile`.`pub_keywords` LIKE '%$search%') OR
73 (`profile`.`prv_keywords` LIKE '%$search%'))";
76 $publish = ((Config::get('system','publish_all')) ? '' : " AND `publish` = 1 " );
79 $r = q("SELECT COUNT(*) AS `total` FROM `profile`
80 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
81 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ");
82 if (DBM::is_result($r))
83 $a->set_pager_total($r[0]['total']);
85 $order = " ORDER BY `name` ASC ";
87 $limit = intval($a->pager['start']).",".intval($a->pager['itemspage']);
89 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
90 `contact`.`addr`, `contact`.`url` AS profile_url FROM `profile`
91 LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
92 LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
93 WHERE `is-default` $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit);
94 if (DBM::is_result($r)) {
96 if (in_array('small', $a->argv)) {
103 foreach ($r as $rr) {
107 $itemurl = (($rr['addr'] != "") ? $rr['addr'] : $rr['profile_url']);
109 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
111 $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '<br />' : '');
114 if(strlen($rr['locality']))
115 $details .= $rr['locality'];
116 if(strlen($rr['region'])) {
117 if(strlen($rr['locality']))
119 $details .= $rr['region'];
121 if(strlen($rr['country-name'])) {
124 $details .= $rr['country-name'];
126 // if(strlen($rr['dob'])) {
127 // if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
128 // $details .= '<br />' . L10n::t('Age: ') . $years ;
130 // if(strlen($rr['gender']))
131 // $details .= '<br />' . L10n::t('Gender: ') . $rr['gender'];
135 if((x($profile,'address') == 1)
136 || (x($profile,'locality') == 1)
137 || (x($profile,'region') == 1)
138 || (x($profile,'postal-code') == 1)
139 || (x($profile,'country-name') == 1))
140 $location = L10n::t('Location:');
142 $gender = ((x($profile,'gender') == 1) ? L10n::t('Gender:') : False);
144 $marital = ((x($profile,'marital') == 1) ? L10n::t('Status:') : False);
146 $homepage = ((x($profile,'homepage') == 1) ? L10n::t('Homepage:') : False);
148 $about = ((x($profile,'about') == 1) ? L10n::t('About:') : False);
150 $location_e = $location;
153 'profile' => [L10n::t("View Profile"), Profile::zrl($profile_link)]
158 'url' => $profile_link,
159 'itemurl' => $itemurl,
160 'thumb' => proxy_url($rr[$photo], false, PROXY_SIZE_THUMB),
161 'img_hover' => $rr['name'],
162 'name' => $rr['name'],
163 'details' => $details,
164 'account_type' => Contact::getAccountType($rr),
165 'profile' => $profile,
166 'location' => $location_e,
167 'tags' => $rr['pub_keywords'],
170 'marital' => $marital,
171 'homepage' => $homepage,
173 'photo_menu' => $photo_menu,
177 $arr = ['contact' => $rr, 'entry' => $entry];
179 Addon::callHooks('directory_item', $arr);
184 if (!$arr['entry']) {
188 $entries[] = $arr['entry'];
191 $tpl = get_markup_template('directory_header.tpl');
193 $o .= replace_macros($tpl, [
194 '$search' => $search,
195 '$globaldir' => L10n::t('Global Directory'),
196 '$gdirpath' => $gdirpath,
197 '$desc' => L10n::t('Find on this site'),
198 '$contacts' => $entries,
199 '$finding' => L10n::t('Results for:'),
200 '$findterm' => (strlen($search) ? $search : ""),
201 '$title' => L10n::t('Site Directory'),
202 '$submit' => L10n::t('Find'),
203 '$paginate' => paginate($a),
206 info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);