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\Network\HTTPException;
15 use Friendica\Util\Proxy as ProxyUtils;
16 use Friendica\Util\Strings;
19 * Shows the local directory of this node
21 class Directory extends BaseModule
23 public static function init()
25 $app = self::getApp();
28 $app->page['aside'] .= Widget::findPeople();
29 $app->page['aside'] .= Widget::follow();
31 unset($_SESSION['theme']);
32 unset($_SESSION['mobile-theme']);
36 public static function content()
38 $app = self::getApp();
39 $config = $app->getConfig();
41 if (($config->get('system', 'block_public') && !local_user() && !remote_user()) ||
42 ($config->get('system', 'block_local_dir') && !local_user() && !remote_user())) {
43 throw new HTTPException\ForbiddenException();
49 Nav::setSelected('directory');
51 $search = (!empty($_REQUEST['search']) ?
52 Strings::escapeTags(trim(rawurldecode($_REQUEST['search']))) :
56 $dirURL = $config->get('system', 'directory');
57 if (strlen($dirURL)) {
58 $gDirPath = Profile::zrl($dirURL, true);
61 $pager = new Pager($app->query_string, 60);
63 $profiles = Profile::searchProfiles($pager->getStart(), $pager->getItemsPerPage(), $search);
65 if ($profiles['total'] === 0) {
66 info(L10n::t('No entries (some entries may be hidden).') . EOL);
68 if (in_array('small', $app->argv)) {
74 foreach ($profiles['entries'] as $entry) {
75 $entries[] = self::formatEntry($entry, $photo);
79 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
81 $output .= Renderer::replaceMacros($tpl, [
83 '$globaldir' => L10n::t('Global Directory'),
84 '$gDirPath' => $gDirPath,
85 '$desc' => L10n::t('Find on this site'),
86 '$contacts' => $profiles['entries'],
87 '$finding' => L10n::t('Results for:'),
88 '$findterm' => (strlen($search) ? $search : ""),
89 '$title' => L10n::t('Site Directory'),
90 '$search_mod' => 'directory',
91 '$submit' => L10n::t('Find'),
92 '$paginate' => $pager->renderFull($profiles['total']),
99 * Format contact/profile/user data from the database into an usable
100 * array for displaying directory entries.
102 * @param array $contact The directory entry from the database.
103 * @param string $photo_size Avatar size (thumb, photo or micro).
109 public static function formatEntry(array $contact, $photo_size = 'photo')
111 $itemurl = (($contact['addr'] != "") ? $contact['addr'] : $contact['profile_url']);
113 $profile_link = $contact['profile_url'];
115 $pdesc = (($contact['pdesc']) ? $contact['pdesc'] . '<br />' : '');
118 if (strlen($contact['locality'])) {
119 $details .= $contact['locality'];
121 if (strlen($contact['region'])) {
122 if (strlen($contact['locality'])) {
125 $details .= $contact['region'];
127 if (strlen($contact['country-name'])) {
128 if (strlen($details)) {
131 $details .= $contact['country-name'];
136 if (!empty($profile['address'])
137 || !empty($profile['locality'])
138 || !empty($profile['region'])
139 || !empty($profile['postal-code'])
140 || !empty($profile['country-name'])
142 $location = L10n::t('Location:');
147 $gender = (!empty($profile['gender']) ? L10n::t('Gender:') : false);
148 $marital = (!empty($profile['marital']) ? L10n::t('Status:') : false);
149 $homepage = (!empty($profile['homepage']) ? L10n::t('Homepage:') : false);
150 $about = (!empty($profile['about']) ? L10n::t('About:') : false);
152 $location_e = $location;
155 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
159 'id' => $contact['id'],
160 'url' => Contact::magicLInk($profile_link),
161 'itemurl' => $itemurl,
162 'thumb' => ProxyUtils::proxifyUrl($contact[$photo_size], false, ProxyUtils::SIZE_THUMB),
163 'img_hover' => $contact['name'],
164 'name' => $contact['name'],
165 'details' => $details,
166 'account_type' => Contact::getAccountType($contact),
167 'profile' => $profile,
168 'location' => $location_e,
169 'tags' => $contact['pub_keywords'],
172 'marital' => $marital,
173 'homepage' => $homepage,
175 'photo_menu' => $photo_menu,
179 $hook = ['contact' => $contact, 'entry' => $entry];
181 Hook::callAll('directory_item', $hook);
186 return $hook['entry'];