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\Session;
11 use Friendica\Core\Renderer;
13 use Friendica\Model\Contact;
14 use Friendica\Model\Profile;
15 use Friendica\Network\HTTPException;
16 use Friendica\Util\Proxy as ProxyUtils;
17 use Friendica\Util\Strings;
20 * Shows the local directory of this node
22 class Directory extends BaseModule
24 public static function content(array $parameters = [])
27 $config = DI::config();
29 if (($config->get('system', 'block_public') && !Session::isAuthenticated()) ||
30 ($config->get('system', 'block_local_dir') && !Session::isAuthenticated())) {
31 throw new HTTPException\ForbiddenException(DI::l10n()->t('Public access denied.'));
35 DI::page()['aside'] .= Widget::findPeople();
36 DI::page()['aside'] .= Widget::follow();
42 Nav::setSelected('directory');
44 $search = (!empty($_REQUEST['search']) ?
45 Strings::escapeTags(trim(rawurldecode($_REQUEST['search']))) :
49 $dirURL = $config->get('system', 'directory');
50 if (strlen($dirURL)) {
51 $gDirPath = Profile::zrl($dirURL, true);
54 $pager = new Pager(DI::args()->getQueryString(), 60);
56 $profiles = Profile::searchProfiles($pager->getStart(), $pager->getItemsPerPage(), $search);
58 if ($profiles['total'] === 0) {
59 info(DI::l10n()->t('No entries (some entries may be hidden).') . EOL);
61 if (in_array('small', $app->argv)) {
67 foreach ($profiles['entries'] as $entry) {
68 $entries[] = self::formatEntry($entry, $photo);
72 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
74 $output .= Renderer::replaceMacros($tpl, [
76 '$globaldir' => DI::l10n()->t('Global Directory'),
77 '$gDirPath' => $gDirPath,
78 '$desc' => DI::l10n()->t('Find on this site'),
79 '$contacts' => $entries,
80 '$finding' => DI::l10n()->t('Results for:'),
81 '$findterm' => (strlen($search) ? $search : ""),
82 '$title' => DI::l10n()->t('Site Directory'),
83 '$search_mod' => 'directory',
84 '$submit' => DI::l10n()->t('Find'),
85 '$paginate' => $pager->renderFull($profiles['total']),
92 * Format contact/profile/user data from the database into an usable
93 * array for displaying directory entries.
95 * @param array $contact The directory entry from the database.
96 * @param string $photo_size Avatar size (thumb, photo or micro).
102 public static function formatEntry(array $contact, $photo_size = 'photo')
104 $itemurl = (($contact['addr'] != "") ? $contact['addr'] : $contact['profile_url']);
106 $profile_link = $contact['profile_url'];
108 $pdesc = (($contact['pdesc']) ? $contact['pdesc'] . '<br />' : '');
111 if (strlen($contact['locality'])) {
112 $details .= $contact['locality'];
114 if (strlen($contact['region'])) {
115 if (strlen($contact['locality'])) {
118 $details .= $contact['region'];
120 if (strlen($contact['country-name'])) {
121 if (strlen($details)) {
124 $details .= $contact['country-name'];
129 if (!empty($profile['address'])
130 || !empty($profile['locality'])
131 || !empty($profile['region'])
132 || !empty($profile['postal-code'])
133 || !empty($profile['country-name'])
135 $location = DI::l10n()->t('Location:');
140 $homepage = (!empty($profile['homepage']) ? DI::l10n()->t('Homepage:') : false);
141 $about = (!empty($profile['about']) ? DI::l10n()->t('About:') : false);
143 $location_e = $location;
146 'profile' => [DI::l10n()->t("View Profile"), Contact::magicLink($profile_link)]
150 'id' => $contact['id'],
151 'url' => Contact::magicLink($profile_link),
152 'itemurl' => $itemurl,
153 'thumb' => ProxyUtils::proxifyUrl($contact[$photo_size], false, ProxyUtils::SIZE_THUMB),
154 'img_hover' => $contact['name'],
155 'name' => $contact['name'],
156 'details' => $details,
157 'account_type' => Contact::getAccountType($contact),
158 'profile' => $profile,
159 'location' => $location_e,
160 'tags' => $contact['pub_keywords'],
162 'homepage' => $homepage,
164 'photo_menu' => $photo_menu,
168 $hook = ['contact' => $contact, 'entry' => $entry];
170 Hook::callAll('directory_item', $hook);
175 return $hook['entry'];