3 * Name: Group Directory
4 * Description: Add a directory of groups hosted on your server, with verbose descriptions.
6 * Author: Thomas Willingham <https://beardyunixer.com/profile/beardyunixer>
9 use Friendica\Content\Nav;
10 use Friendica\Content\Pager;
11 use Friendica\Content\Widget;
12 use Friendica\Core\Hook;
13 use Friendica\Core\Renderer;
14 use Friendica\Database\DBA;
16 use Friendica\Model\Profile;
17 use Friendica\Model\User;
19 global $groupdirectory_search;
21 function groupdirectory_install()
23 Hook::register('app_menu', __FILE__, 'groupdirectory_app_menu');
27 * This is a statement rather than an actual function definition. The simple
28 * existence of this method is checked to figure out if the addon offers a
32 * This is a statement rather than an actual function definition. The simple
33 * existence of this method is checked to figure out if the addon offers a
36 function groupdirectory_module() {}
38 function groupdirectory_app_menu(array &$b)
40 $b['app_menu'][] = '<div class="app-title"><a href="groupdirectory">' . DI::l10n()->t('Group Directory') . '</a></div>';
43 function groupdirectory_init()
45 if (DI::userSession()->getLocalUserId()) {
46 DI::page()['aside'] .= Widget::findPeople();
50 function groupdirectory_post()
52 global $groupdirectory_search;
54 if (!empty($_POST['search'])) {
55 $groupdirectory_search = $_POST['search'];
59 function groupdirectory_content()
61 global $groupdirectory_search;
63 if (DI::config()->get('system', 'block_public') && !DI::userSession()->getLocalUserId() && !DI::userSession()->getRemoteUserId()) {
64 DI::sysmsg()->addNotice(DI::l10n()->t('Public access denied.'));
71 Nav::setSelected('directory');
73 if (!empty($groupdirectory_search)) {
74 $search = trim($groupdirectory_search);
76 $search = (!empty($_GET['search']) ? trim(rawurldecode($_GET['search'])) : '');
80 $dirurl = DI::config()->get('system', 'directory');
81 if (strlen($dirurl)) {
82 $gdirpath = Profile::zrl($dirurl, true);
86 if (strlen($search)) {
87 $search = DBA::escape($search);
89 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
90 (`user`.`nickname` LIKE '%$search%') OR
91 (`profile`.`about` LIKE '%$search%') OR
92 (`profile`.`locality` LIKE '%$search%') OR
93 (`profile`.`region` LIKE '%$search%') OR
94 (`profile`.`country-name` LIKE '%$search%') OR
95 (`profile`.`pub_keywords` LIKE '%$search%') OR
96 (`profile`.`prv_keywords` LIKE '%$search%'))";
99 $publish = DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1";
102 $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `profile`
103 INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
104 WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `user`.`page-flags` = ? $sql_extra",
105 User::PAGE_FLAGS_COMMUNITY);
106 if (DBA::isResult($cnt)) {
107 $total = $cnt['total'];
110 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 60);
112 $order = " ORDER BY `name` ASC ";
114 $limit = $pager->getStart() . "," . $pager->getItemsPerPage();
116 $r = DBA::p("SELECT `profile`.*, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
117 `contact`.`addr`, `contact`.`url` FROM `profile`
118 INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
119 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid`
120 WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `user`.`page-flags` = ? AND `contact`.`self`
121 $sql_extra $order LIMIT $limit", User::PAGE_FLAGS_COMMUNITY
124 if (DBA::isResult($r)) {
125 if (in_array('small', DI::args()->getArgv())) {
131 while ($rr = DBA::fetch($r)) {
132 $entries[] = Friendica\Module\Directory::formatEntry($rr, $photo);
136 DI::sysmsg()->addNotice(DI::l10n()->t('No entries (some entries may be hidden).'));
139 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
140 $o .= Renderer::replaceMacros($tpl, [
141 '$search' => $search,
142 '$globaldir' => DI::l10n()->t('Global Directory'),
143 '$gdirpath' => $gdirpath,
144 '$desc' => DI::l10n()->t('Find on this site'),
145 '$contacts' => $entries,
146 '$finding' => DI::l10n()->t('Results for:'),
147 '$findterm' => (strlen($search) ? $search : ""),
148 '$title' => DI::l10n()->t('Group Directory'),
149 '$search_mod' => 'groupdirectory',
150 '$submit' => DI::l10n()->t('Find'),
151 '$paginate' => $pager->renderFull($total),