3 * Name: Forum Directory
4 * Description: Add a directory of forums hosted on your server, with verbose descriptions.
6 * Author: Thomas Willingham <https://beardyunixer.com/profile/beardyunixer>
8 * Note: Please use Group Directory instead
12 use Friendica\Content\Nav;
13 use Friendica\Content\Pager;
14 use Friendica\Content\Widget;
15 use Friendica\Core\Hook;
16 use Friendica\Core\Renderer;
17 use Friendica\Database\DBA;
19 use Friendica\Model\Profile;
20 use Friendica\Model\User;
22 global $forumdirectory_search;
24 function forumdirectory_install()
26 Hook::register('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
30 * This is a statement rather than an actual function definition. The simple
31 * existence of this method is checked to figure out if the addon offers a
35 * This is a statement rather than an actual function definition. The simple
36 * existence of this method is checked to figure out if the addon offers a
39 function forumdirectory_module() {}
41 function forumdirectory_app_menu(array &$b)
43 $b['app_menu'][] = '<div class="app-title"><a href="forumdirectory">' . DI::l10n()->t('Forum Directory') . '</a></div>';
46 function forumdirectory_init()
48 if (DI::userSession()->getLocalUserId()) {
49 DI::page()['aside'] .= Widget::findPeople();
53 function forumdirectory_post()
55 global $forumdirectory_search;
57 if (!empty($_POST['search'])) {
58 $forumdirectory_search = $_POST['search'];
62 function forumdirectory_content()
64 global $forumdirectory_search;
66 if (DI::config()->get('system', 'block_public') && !DI::userSession()->getLocalUserId() && !DI::userSession()->getRemoteUserId()) {
67 DI::sysmsg()->addNotice(DI::l10n()->t('Public access denied.'));
74 Nav::setSelected('directory');
76 if (!empty($forumdirectory_search)) {
77 $search = trim($forumdirectory_search);
79 $search = (!empty($_GET['search']) ? trim(rawurldecode($_GET['search'])) : '');
83 $dirurl = DI::config()->get('system', 'directory');
84 if (strlen($dirurl)) {
85 $gdirpath = Profile::zrl($dirurl, true);
89 if (strlen($search)) {
90 $search = DBA::escape($search);
92 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
93 (`user`.`nickname` LIKE '%$search%') OR
94 (`profile`.`about` LIKE '%$search%') OR
95 (`profile`.`locality` LIKE '%$search%') OR
96 (`profile`.`region` LIKE '%$search%') OR
97 (`profile`.`country-name` LIKE '%$search%') OR
98 (`profile`.`pub_keywords` LIKE '%$search%') OR
99 (`profile`.`prv_keywords` LIKE '%$search%'))";
102 $publish = DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1";
105 $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `profile`
106 INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
107 WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `user`.`page-flags` = ? $sql_extra",
108 User::PAGE_FLAGS_COMMUNITY);
109 if (DBA::isResult($cnt)) {
110 $total = $cnt['total'];
113 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 60);
115 $order = " ORDER BY `name` ASC ";
117 $limit = $pager->getStart()."," . $pager->getItemsPerPage();
119 $r = DBA::p("SELECT `profile`.*, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
120 `contact`.`addr`, `contact`.`url` FROM `profile`
121 INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
122 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid`
123 WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `user`.`page-flags` = ? AND `contact`.`self`
124 $sql_extra $order LIMIT $limit", User::PAGE_FLAGS_COMMUNITY
127 if (DBA::isResult($r)) {
128 if (in_array('small', DI::args()->getArgv())) {
134 while ($rr = DBA::fetch($r)) {
135 $entries[] = Friendica\Module\Directory::formatEntry($rr, $photo);
139 DI::sysmsg()->addNotice(DI::l10n()->t("No entries \x28some entries may be hidden\x29."));
142 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
143 $o .= Renderer::replaceMacros($tpl, [
144 '$search' => $search,
145 '$globaldir' => DI::l10n()->t('Global Directory'),
146 '$gdirpath' => $gdirpath,
147 '$desc' => DI::l10n()->t('Find on this site'),
148 '$contacts' => $entries,
149 '$finding' => DI::l10n()->t('Results for:'),
150 '$findterm' => (strlen($search) ? $search : ""),
151 '$title' => DI::l10n()->t('Forum Directory'),
152 '$search_mod' => 'forumdirectory',
153 '$submit' => DI::l10n()->t('Find'),
154 '$paginate' => $pager->renderFull($total),