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 post()
38 if (!empty($_POST['search'])) {
39 self::getApp()->data['search'] = $_POST['search'];
43 public static function content()
45 $app = self::getApp();
46 $config = $app->getConfig();
48 if (($config->get('system', 'block_public') && !local_user() && !remote_user()) ||
49 ($config->get('system', 'block_local_dir') && !local_user() && !remote_user())) {
50 throw new HTTPException\ForbiddenException();
56 Nav::setSelected('directory');
58 $search = (!empty($_REQUEST['search']) ?
59 Strings::escapeTags(trim(rawurldecode($_REQUEST['search']))) :
63 $dirURL = $config->get('system', 'directory');
64 if (strlen($dirURL)) {
65 $gDirPath = Profile::zrl($dirURL, true);
68 $pager = new Pager($app->query_string, 60);
70 $profiles = Profile::searchProfiles($pager->getStart(), $pager->getItemsPerPage(), $search);
72 if ($profiles['total'] === 0) {
73 info(L10n::t('No entries (some entries may be hidden).') . EOL);
75 if (in_array('small', $app->argv)) {
81 foreach ($profiles['entries'] as $entry) {
82 $entries[] = self::formatEntry($entry, $photo);
86 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
88 $output .= Renderer::replaceMacros($tpl, [
90 '$globaldir' => L10n::t('Global Directory'),
91 '$gDirPath' => $gDirPath,
92 '$desc' => L10n::t('Find on this site'),
93 '$contacts' => $profiles['entries'],
94 '$finding' => L10n::t('Results for:'),
95 '$findterm' => (strlen($search) ? $search : ""),
96 '$title' => L10n::t('Site Directory'),
97 '$search_mod' => 'directory',
98 '$submit' => L10n::t('Find'),
99 '$paginate' => $pager->renderFull($profiles['total']),
106 * Format contact/profile/user data from the database into an usable
107 * array for displaying directory entries.
109 * @param array $contact The directory entry from the database.
110 * @param string $photo_size Avatar size (thumb, photo or micro).
116 public static function formatEntry(array $contact, $photo_size = 'photo')
118 $itemurl = (($contact['addr'] != "") ? $contact['addr'] : $contact['profile_url']);
120 $profile_link = $contact['profile_url'];
122 $pdesc = (($contact['pdesc']) ? $contact['pdesc'] . '<br />' : '');
125 if (strlen($contact['locality'])) {
126 $details .= $contact['locality'];
128 if (strlen($contact['region'])) {
129 if (strlen($contact['locality'])) {
132 $details .= $contact['region'];
134 if (strlen($contact['country-name'])) {
135 if (strlen($details)) {
138 $details .= $contact['country-name'];
143 if (!empty($profile['address'])
144 || !empty($profile['locality'])
145 || !empty($profile['region'])
146 || !empty($profile['postal-code'])
147 || !empty($profile['country-name'])
149 $location = L10n::t('Location:');
154 $gender = (!empty($profile['gender']) ? L10n::t('Gender:') : false);
155 $marital = (!empty($profile['marital']) ? L10n::t('Status:') : false);
156 $homepage = (!empty($profile['homepage']) ? L10n::t('Homepage:') : false);
157 $about = (!empty($profile['about']) ? L10n::t('About:') : false);
159 $location_e = $location;
162 'profile' => [L10n::t("View Profile"), Contact::magicLink($profile_link)]
166 'id' => $contact['id'],
167 'url' => Contact::magicLInk($profile_link),
168 'itemurl' => $itemurl,
169 'thumb' => ProxyUtils::proxifyUrl($contact[$photo_size], false, ProxyUtils::SIZE_THUMB),
170 'img_hover' => $contact['name'],
171 'name' => $contact['name'],
172 'details' => $details,
173 'account_type' => Contact::getAccountType($contact),
174 'profile' => $profile,
175 'location' => $location_e,
176 'tags' => $contact['pub_keywords'],
179 'marital' => $marital,
180 'homepage' => $homepage,
182 'photo_menu' => $photo_menu,
186 $hook = ['contact' => $contact, 'entry' => $entry];
188 Hook::callAll('directory_item', $hook);
193 return $hook['entry'];