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 content()
25 $app = self::getApp();
26 $config = $app->getConfig();
28 if (($config->get('system', 'block_public') && !local_user() && !remote_user()) ||
29 ($config->get('system', 'block_local_dir') && !local_user() && !remote_user())) {
30 throw new HTTPException\ForbiddenException(L10n::t('Public access denied.'));
34 $app->page['aside'] .= Widget::findPeople();
35 $app->page['aside'] .= Widget::follow();
37 unset($_SESSION['theme']);
38 unset($_SESSION['mobile-theme']);
44 Nav::setSelected('directory');
46 $search = (!empty($_REQUEST['search']) ?
47 Strings::escapeTags(trim(rawurldecode($_REQUEST['search']))) :
51 $dirURL = $config->get('system', 'directory');
52 if (strlen($dirURL)) {
53 $gDirPath = Profile::zrl($dirURL, true);
56 $pager = new Pager($app->query_string, 60);
58 $profiles = Profile::searchProfiles($pager->getStart(), $pager->getItemsPerPage(), $search);
60 if ($profiles['total'] === 0) {
61 info(L10n::t('No entries (some entries may be hidden).') . EOL);
63 if (in_array('small', $app->argv)) {
69 foreach ($profiles['entries'] as $entry) {
70 $entries[] = self::formatEntry($entry, $photo);
74 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
76 $output .= Renderer::replaceMacros($tpl, [
78 '$globaldir' => L10n::t('Global Directory'),
79 '$gDirPath' => $gDirPath,
80 '$desc' => L10n::t('Find on this site'),
81 '$contacts' => $entries,
82 '$finding' => L10n::t('Results for:'),
83 '$findterm' => (strlen($search) ? $search : ""),
84 '$title' => L10n::t('Site Directory'),
85 '$search_mod' => 'directory',
86 '$submit' => L10n::t('Find'),
87 '$paginate' => $pager->renderFull($profiles['total']),
94 * Format contact/profile/user data from the database into an usable
95 * array for displaying directory entries.
97 * @param array $contact The directory entry from the database.
98 * @param string $photo_size Avatar size (thumb, photo or micro).
104 public static function formatEntry(array $contact, $photo_size = 'photo')
106 $itemurl = (($contact['addr'] != "") ? $contact['addr'] : $contact['profile_url']);
108 $profile_link = $contact['profile_url'];
110 $pdesc = (($contact['pdesc']) ? $contact['pdesc'] . '<br />' : '');
113 if (strlen($contact['locality'])) {
114 $details .= $contact['locality'];
116 if (strlen($contact['region'])) {
117 if (strlen($contact['locality'])) {
120 $details .= $contact['region'];
122 if (strlen($contact['country-name'])) {
123 if (strlen($details)) {
126 $details .= $contact['country-name'];
131 if (!empty($profile['address'])
132 || !empty($profile['locality'])
133 || !empty($profile['region'])
134 || !empty($profile['postal-code'])
135 || !empty($profile['country-name'])
137 $location = L10n::t('Location:');
142 $gender = (!empty($profile['gender']) ? L10n::t('Gender:') : false);
143 $marital = (!empty($profile['marital']) ? L10n::t('Status:') : false);
144 $homepage = (!empty($profile['homepage']) ? L10n::t('Homepage:') : false);
145 $about = (!empty($profile['about']) ? L10n::t('About:') : false);
147 $location_e = $location;
150 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
154 'id' => $contact['id'],
155 'url' => Contact::magicLink($profile_link),
156 'itemurl' => $itemurl,
157 'thumb' => ProxyUtils::proxifyUrl($contact[$photo_size], false, ProxyUtils::SIZE_THUMB),
158 'img_hover' => $contact['name'],
159 'name' => $contact['name'],
160 'details' => $details,
161 'account_type' => Contact::getAccountType($contact),
162 'profile' => $profile,
163 'location' => $location_e,
164 'tags' => $contact['pub_keywords'],
167 'marital' => $marital,
168 'homepage' => $homepage,
170 'photo_menu' => $photo_menu,
174 $hook = ['contact' => $contact, 'entry' => $entry];
176 Hook::callAll('directory_item', $hook);
181 return $hook['entry'];