3 namespace Friendica\Module;
5 use Friendica\BaseModule;
6 use Friendica\Content\Nav;
7 use Friendica\Content\Pager;
8 use Friendica\Content\Widget;
9 use Friendica\Core\Hook;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Renderer;
12 use Friendica\Model\Contact;
13 use Friendica\Model\Profile;
14 use Friendica\Util\Proxy as ProxyUtils;
15 use Friendica\Util\Strings;
18 * Shows the local directory of this node
20 class Directory extends BaseModule
22 public static function init()
24 $app = self::getApp();
27 $app->page['aside'] .= Widget::findPeople();
28 $app->page['aside'] .= Widget::follow();
30 unset($_SESSION['theme']);
31 unset($_SESSION['mobile-theme']);
35 public static function post()
37 if (!empty($_POST['search'])) {
38 self::getApp()->data['search'] = $_POST['search'];
42 public static function content()
44 $app = self::getApp();
45 $config = $app->getConfig();
47 if (($config->get('system', 'block_public') && !local_user() && !remote_user()) ||
48 ($config->get('system', 'block_local_dir') && !local_user() && !remote_user())) {
49 notice(L10n::t('Public access denied.') . EOL);
56 Nav::setSelected('directory');
58 if (!empty($app->data['search'])) {
59 $search = Strings::escapeTags(trim($app->data['search']));
61 $search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : '');
65 $dirURL = $config->get('system', 'directory');
66 if (strlen($dirURL)) {
67 $gDirPath = Profile::zrl($dirURL, true);
70 $pager = new Pager($app->query_string, 60);
72 $profiles = Profile::searchProfiles($pager->getStart(), $pager->getItemsPerPage(), $search);
74 if ($profiles['total'] === 0) {
75 info(L10n::t('No entries (some entries may be hidden).') . EOL);
77 if (in_array('small', $app->argv)) {
83 foreach ($profiles['entries'] as $entry) {
84 $entries[] = self::formatEntry($entry, $photo);
88 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
90 $output .= Renderer::replaceMacros($tpl, [
92 '$globaldir' => L10n::t('Global Directory'),
93 '$gDirPath' => $gDirPath,
94 '$desc' => L10n::t('Find on this site'),
95 '$contacts' => $profiles['entries'],
96 '$finding' => L10n::t('Results for:'),
97 '$findterm' => (strlen($search) ? $search : ""),
98 '$title' => L10n::t('Site Directory'),
99 '$search_mod' => 'directory',
100 '$submit' => L10n::t('Find'),
101 '$paginate' => $pager->renderFull($profiles['total']),
108 * Format contact/profile/user data from the database into an usable
109 * array for displaying directory entries.
111 * @param array $contact The directory entry from the database.
112 * @param string $photo_size Avatar size (thumb, photo or micro).
118 public static function formatEntry(array $contact, $photo_size = 'photo')
120 $itemurl = (($contact['addr'] != "") ? $contact['addr'] : $contact['profile_url']);
122 $profile_link = $contact['profile_url'];
124 $pdesc = (($contact['pdesc']) ? $contact['pdesc'] . '<br />' : '');
127 if (strlen($contact['locality'])) {
128 $details .= $contact['locality'];
130 if (strlen($contact['region'])) {
131 if (strlen($contact['locality'])) {
134 $details .= $contact['region'];
136 if (strlen($contact['country-name'])) {
137 if (strlen($details)) {
140 $details .= $contact['country-name'];
145 if (!empty($profile['address'])
146 || !empty($profile['locality'])
147 || !empty($profile['region'])
148 || !empty($profile['postal-code'])
149 || !empty($profile['country-name'])
151 $location = L10n::t('Location:');
156 $gender = (!empty($profile['gender']) ? L10n::t('Gender:') : false);
157 $marital = (!empty($profile['marital']) ? L10n::t('Status:') : false);
158 $homepage = (!empty($profile['homepage']) ? L10n::t('Homepage:') : false);
159 $about = (!empty($profile['about']) ? L10n::t('About:') : false);
161 $location_e = $location;
164 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
168 'id' => $contact['id'],
169 'url' => Contact::magicLInk($profile_link),
170 'itemurl' => $itemurl,
171 'thumb' => ProxyUtils::proxifyUrl($contact[$photo_size], false, ProxyUtils::SIZE_THUMB),
172 'img_hover' => $contact['name'],
173 'name' => $contact['name'],
174 'details' => $details,
175 'account_type' => Contact::getAccountType($contact),
176 'profile' => $profile,
177 'location' => $location_e,
178 'tags' => $contact['pub_keywords'],
181 'marital' => $marital,
182 'homepage' => $homepage,
184 'photo_menu' => $photo_menu,
188 $hook = ['contact' => $contact, 'entry' => $entry];
190 Hook::callAll('directory_item', $hook);
195 return $hook['entry'];