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>
10 use Friendica\Content\Nav;
11 use Friendica\Content\Pager;
12 use Friendica\Content\Widget;
13 use Friendica\Core\Hook;
14 use Friendica\Core\Renderer;
15 use Friendica\Database\DBA;
17 use Friendica\Model\Profile;
18 use Friendica\Model\User;
20 global $forumdirectory_search;
22 function forumdirectory_install()
24 Hook::register('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
28 * This is a statement rather than an actual function definition. The simple
29 * existence of this method is checked to figure out if the addon offers a
33 * This is a statement rather than an actual function definition. The simple
34 * existence of this method is checked to figure out if the addon offers a
37 function forumdirectory_module() {}
39 function forumdirectory_app_menu(array &$b)
41 $b['app_menu'][] = '<div class="app-title"><a href="forumdirectory">' . DI::l10n()->t('Forum Directory') . '</a></div>';
44 function forumdirectory_init()
46 if (DI::userSession()->getLocalUserId()) {
47 DI::page()['aside'] .= Widget::findPeople();
51 function forumdirectory_post()
53 global $forumdirectory_search;
55 if (!empty($_POST['search'])) {
56 $forumdirectory_search = $_POST['search'];
60 function forumdirectory_content()
62 global $forumdirectory_search;
64 if (DI::config()->get('system', 'block_public') && !DI::userSession()->getLocalUserId() && !DI::userSession()->getRemoteUserId()) {
65 DI::sysmsg()->addNotice(DI::l10n()->t('Public access denied.'));
72 Nav::setSelected('directory');
74 if (!empty($forumdirectory_search)) {
75 $search = trim($forumdirectory_search);
77 $search = (!empty($_GET['search']) ? trim(rawurldecode($_GET['search'])) : '');
81 $dirurl = DI::config()->get('system', 'directory');
82 if (strlen($dirurl)) {
83 $gdirpath = Profile::zrl($dirurl, true);
87 if (strlen($search)) {
88 $search = DBA::escape($search);
90 $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
91 (`user`.`nickname` LIKE '%$search%') OR
92 (`profile`.`about` LIKE '%$search%') OR
93 (`profile`.`locality` LIKE '%$search%') OR
94 (`profile`.`region` LIKE '%$search%') OR
95 (`profile`.`country-name` LIKE '%$search%') OR
96 (`profile`.`pub_keywords` LIKE '%$search%') OR
97 (`profile`.`prv_keywords` LIKE '%$search%'))";
100 $publish = DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1";
103 $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `profile`
104 INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
105 WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `user`.`page-flags` = ? $sql_extra",
106 User::PAGE_FLAGS_COMMUNITY);
107 if (DBA::isResult($cnt)) {
108 $total = $cnt['total'];
111 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 60);
113 $order = " ORDER BY `name` ASC ";
115 $limit = $pager->getStart()."," . $pager->getItemsPerPage();
117 $r = DBA::p("SELECT `profile`.*, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
118 `contact`.`addr`, `contact`.`url` FROM `profile`
119 INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
120 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid`
121 WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `user`.`page-flags` = ? AND `contact`.`self`
122 $sql_extra $order LIMIT $limit", User::PAGE_FLAGS_COMMUNITY
125 if (DBA::isResult($r)) {
126 if (in_array('small', DI::args()->getArgv())) {
132 while ($rr = DBA::fetch($r)) {
133 $entries[] = Friendica\Module\Directory::formatEntry($rr, $photo);
137 DI::sysmsg()->addNotice(DI::l10n()->t("No entries \x28some entries may be hidden\x29."));
140 $tpl = Renderer::getMarkupTemplate('directory_header.tpl');
141 $o .= Renderer::replaceMacros($tpl, [
142 '$search' => $search,
143 '$globaldir' => DI::l10n()->t('Global Directory'),
144 '$gdirpath' => $gdirpath,
145 '$desc' => DI::l10n()->t('Find on this site'),
146 '$contacts' => $entries,
147 '$finding' => DI::l10n()->t('Results for:'),
148 '$findterm' => (strlen($search) ? $search : ""),
149 '$title' => DI::l10n()->t('Forum Directory'),
150 '$search_mod' => 'forumdirectory',
151 '$submit' => DI::l10n()->t('Find'),
152 '$paginate' => $pager->renderFull($total),