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\Session;
12 use Friendica\Core\Renderer;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Profile;
16 use Friendica\Network\HTTPException;
17 use Friendica\Util\Proxy as ProxyUtils;
18 use Friendica\Util\Strings;
21 * Shows the local directory of this node
23 class Directory extends BaseModule
25 public static function content(array $parameters = [])
28 $config = DI::config();
30 if (($config->get('system', 'block_public') && !Session::isAuthenticated()) ||
31 ($config->get('system', 'block_local_dir') && !Session::isAuthenticated())) {
32 throw new HTTPException\ForbiddenException(L10n::t('Public access denied.'));
36 $app->page['aside'] .= Widget::findPeople();
37 $app->page['aside'] .= Widget::follow();
43 Nav::setSelected('directory');
45 $search = (!empty($_REQUEST['search']) ?
46 Strings::escapeTags(trim(rawurldecode($_REQUEST['search']))) :
50 $dirURL = $config->get('system', 'directory');
51 if (strlen($dirURL)) {
52 $gDirPath = Profile::zrl($dirURL, true);
55 $pager = new Pager($app->query_string, 60);
57 $profiles = Profile::searchProfiles($pager->getStart(), $pager->getItemsPerPage(), $search);
59 if ($profiles['total'] === 0) {
60 info(L10n::t('No entries (some entries may be hidden).') . EOL);
62 if (in_array('small', $app->argv)) {
68 foreach ($profiles['entries'] as $entry) {
69 $entries[] = self::formatEntry($entry, $photo);
73 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
75 $output .= Renderer::replaceMacros($tpl, [
77 '$globaldir' => L10n::t('Global Directory'),
78 '$gDirPath' => $gDirPath,
79 '$desc' => L10n::t('Find on this site'),
80 '$contacts' => $entries,
81 '$finding' => L10n::t('Results for:'),
82 '$findterm' => (strlen($search) ? $search : ""),
83 '$title' => L10n::t('Site Directory'),
84 '$search_mod' => 'directory',
85 '$submit' => L10n::t('Find'),
86 '$paginate' => $pager->renderFull($profiles['total']),
93 * Format contact/profile/user data from the database into an usable
94 * array for displaying directory entries.
96 * @param array $contact The directory entry from the database.
97 * @param string $photo_size Avatar size (thumb, photo or micro).
103 public static function formatEntry(array $contact, $photo_size = 'photo')
105 $itemurl = (($contact['addr'] != "") ? $contact['addr'] : $contact['profile_url']);
107 $profile_link = $contact['profile_url'];
109 $pdesc = (($contact['pdesc']) ? $contact['pdesc'] . '<br />' : '');
112 if (strlen($contact['locality'])) {
113 $details .= $contact['locality'];
115 if (strlen($contact['region'])) {
116 if (strlen($contact['locality'])) {
119 $details .= $contact['region'];
121 if (strlen($contact['country-name'])) {
122 if (strlen($details)) {
125 $details .= $contact['country-name'];
130 if (!empty($profile['address'])
131 || !empty($profile['locality'])
132 || !empty($profile['region'])
133 || !empty($profile['postal-code'])
134 || !empty($profile['country-name'])
136 $location = L10n::t('Location:');
141 $gender = (!empty($profile['gender']) ? L10n::t('Gender:') : false);
142 $marital = (!empty($profile['marital']) ? L10n::t('Status:') : false);
143 $homepage = (!empty($profile['homepage']) ? L10n::t('Homepage:') : false);
144 $about = (!empty($profile['about']) ? L10n::t('About:') : false);
146 $location_e = $location;
149 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
153 'id' => $contact['id'],
154 'url' => Contact::magicLink($profile_link),
155 'itemurl' => $itemurl,
156 'thumb' => ProxyUtils::proxifyUrl($contact[$photo_size], false, ProxyUtils::SIZE_THUMB),
157 'img_hover' => $contact['name'],
158 'name' => $contact['name'],
159 'details' => $details,
160 'account_type' => Contact::getAccountType($contact),
161 'profile' => $profile,
162 'location' => $location_e,
163 'tags' => $contact['pub_keywords'],
166 'marital' => $marital,
167 'homepage' => $homepage,
169 'photo_menu' => $photo_menu,
173 $hook = ['contact' => $contact, 'entry' => $entry];
175 Hook::callAll('directory_item', $hook);
180 return $hook['entry'];