2012-11-04 22:53:53 +01:00
|
|
|
<?php
|
2018-01-19 01:36:05 +01:00
|
|
|
/**
|
|
|
|
* Name: Forum Directory
|
|
|
|
* Description: Add a directory of forums hosted on your server, with verbose descriptions.
|
2019-02-18 03:01:24 +01:00
|
|
|
* Version: 1.1
|
2018-01-19 01:36:05 +01:00
|
|
|
* Author: Thomas Willingham <https://beardyunixer.com/profile/beardyunixer>
|
2023-06-03 21:57:29 +02:00
|
|
|
* Status: Unsupported
|
|
|
|
* Note: Please use Group Directory instead
|
2018-01-19 01:36:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
use Friendica\Content\Nav;
|
2018-10-24 08:38:54 +02:00
|
|
|
use Friendica\Content\Pager;
|
2018-01-19 01:36:05 +01:00
|
|
|
use Friendica\Content\Widget;
|
2018-12-26 08:28:16 +01:00
|
|
|
use Friendica\Core\Hook;
|
2018-10-31 15:55:15 +01:00
|
|
|
use Friendica\Core\Renderer;
|
2018-07-21 14:42:08 +02:00
|
|
|
use Friendica\Database\DBA;
|
2019-12-16 01:30:33 +01:00
|
|
|
use Friendica\DI;
|
2020-07-12 14:49:55 +02:00
|
|
|
use Friendica\Model\User;
|
2024-05-27 06:45:17 +02:00
|
|
|
use Friendica\Security\OpenWebAuth;
|
2018-01-20 15:30:08 +01:00
|
|
|
|
2021-07-25 19:28:07 +02:00
|
|
|
global $forumdirectory_search;
|
|
|
|
|
2018-01-22 20:03:11 +01:00
|
|
|
function forumdirectory_install()
|
|
|
|
{
|
2018-12-26 08:28:16 +01:00
|
|
|
Hook::register('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
|
2012-11-04 22:53:53 +01:00
|
|
|
}
|
|
|
|
|
2022-06-24 23:27:58 +02:00
|
|
|
/**
|
|
|
|
* This is a statement rather than an actual function definition. The simple
|
|
|
|
* existence of this method is checked to figure out if the addon offers a
|
|
|
|
* module.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* This is a statement rather than an actual function definition. The simple
|
|
|
|
* existence of this method is checked to figure out if the addon offers a
|
|
|
|
* module.
|
|
|
|
*/
|
|
|
|
function forumdirectory_module() {}
|
2012-11-04 22:53:53 +01:00
|
|
|
|
2023-01-14 03:16:09 +01:00
|
|
|
function forumdirectory_app_menu(array &$b)
|
2018-01-19 01:36:05 +01:00
|
|
|
{
|
2020-01-18 20:52:33 +01:00
|
|
|
$b['app_menu'][] = '<div class="app-title"><a href="forumdirectory">' . DI::l10n()->t('Forum Directory') . '</a></div>';
|
2012-11-04 23:18:24 +01:00
|
|
|
}
|
|
|
|
|
2023-01-14 03:16:09 +01:00
|
|
|
function forumdirectory_init()
|
2018-01-19 01:36:05 +01:00
|
|
|
{
|
2022-10-20 23:51:49 +02:00
|
|
|
if (DI::userSession()->getLocalUserId()) {
|
2019-12-30 20:02:08 +01:00
|
|
|
DI::page()['aside'] .= Widget::findPeople();
|
2018-01-19 01:36:05 +01:00
|
|
|
}
|
2012-11-04 22:53:53 +01:00
|
|
|
}
|
|
|
|
|
2023-01-14 03:16:09 +01:00
|
|
|
function forumdirectory_post()
|
2018-01-19 01:36:05 +01:00
|
|
|
{
|
2021-07-25 19:28:07 +02:00
|
|
|
global $forumdirectory_search;
|
|
|
|
|
2018-07-28 07:33:39 +02:00
|
|
|
if (!empty($_POST['search'])) {
|
2021-07-25 19:28:07 +02:00
|
|
|
$forumdirectory_search = $_POST['search'];
|
2018-01-19 01:36:05 +01:00
|
|
|
}
|
2012-11-04 22:53:53 +01:00
|
|
|
}
|
|
|
|
|
2023-01-14 03:16:09 +01:00
|
|
|
function forumdirectory_content()
|
2018-01-19 01:36:05 +01:00
|
|
|
{
|
2021-07-25 19:28:07 +02:00
|
|
|
global $forumdirectory_search;
|
|
|
|
|
2022-10-20 23:51:49 +02:00
|
|
|
if (DI::config()->get('system', 'block_public') && !DI::userSession()->getLocalUserId() && !DI::userSession()->getRemoteUserId()) {
|
2022-10-17 23:00:03 +02:00
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t('Public access denied.'));
|
2012-11-04 22:53:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$o = '';
|
2019-02-18 03:01:24 +01:00
|
|
|
$entries = [];
|
|
|
|
|
2018-01-19 01:36:05 +01:00
|
|
|
Nav::setSelected('directory');
|
2012-11-04 22:53:53 +01:00
|
|
|
|
2021-07-25 19:28:07 +02:00
|
|
|
if (!empty($forumdirectory_search)) {
|
2021-11-07 09:49:34 +01:00
|
|
|
$search = trim($forumdirectory_search);
|
2018-01-19 01:36:05 +01:00
|
|
|
} else {
|
2021-11-07 09:49:34 +01:00
|
|
|
$search = (!empty($_GET['search']) ? trim(rawurldecode($_GET['search'])) : '');
|
2018-01-19 01:36:05 +01:00
|
|
|
}
|
2012-11-04 22:53:53 +01:00
|
|
|
|
2019-02-18 03:01:24 +01:00
|
|
|
$gdirpath = '';
|
2020-01-19 21:21:12 +01:00
|
|
|
$dirurl = DI::config()->get('system', 'directory');
|
2019-02-18 03:01:24 +01:00
|
|
|
if (strlen($dirurl)) {
|
2024-05-29 08:07:48 +02:00
|
|
|
$gdirpath = OpenWebAuth::getZrlUrl($dirurl, true);
|
2012-11-04 22:53:53 +01:00
|
|
|
}
|
|
|
|
|
2018-01-19 01:36:05 +01:00
|
|
|
$sql_extra = '';
|
|
|
|
if (strlen($search)) {
|
2019-02-18 03:01:24 +01:00
|
|
|
$search = DBA::escape($search);
|
|
|
|
|
|
|
|
$sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
|
|
|
|
(`user`.`nickname` LIKE '%$search%') OR
|
2020-02-16 19:06:06 +01:00
|
|
|
(`profile`.`about` LIKE '%$search%') OR
|
2019-02-18 03:01:24 +01:00
|
|
|
(`profile`.`locality` LIKE '%$search%') OR
|
|
|
|
(`profile`.`region` LIKE '%$search%') OR
|
|
|
|
(`profile`.`country-name` LIKE '%$search%') OR
|
|
|
|
(`profile`.`pub_keywords` LIKE '%$search%') OR
|
|
|
|
(`profile`.`prv_keywords` LIKE '%$search%'))";
|
2018-01-19 01:36:05 +01:00
|
|
|
}
|
2012-11-04 22:53:53 +01:00
|
|
|
|
2020-01-28 05:09:29 +01:00
|
|
|
$publish = DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1";
|
2012-11-04 22:53:53 +01:00
|
|
|
|
2018-10-24 08:38:54 +02:00
|
|
|
$total = 0;
|
2019-02-18 03:01:24 +01:00
|
|
|
$cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `profile`
|
2020-07-12 14:49:55 +02:00
|
|
|
INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
|
2024-04-16 06:43:54 +02:00
|
|
|
WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `user`.`page-flags` IN (?, ?) $sql_extra",
|
|
|
|
User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_COMM_MAN);
|
2019-02-18 03:01:24 +01:00
|
|
|
if (DBA::isResult($cnt)) {
|
|
|
|
$total = $cnt['total'];
|
2018-01-19 01:36:05 +01:00
|
|
|
}
|
2012-11-04 22:53:53 +01:00
|
|
|
|
2020-02-16 19:06:30 +01:00
|
|
|
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 60);
|
2018-10-24 08:38:54 +02:00
|
|
|
|
2018-01-15 14:15:33 +01:00
|
|
|
$order = " ORDER BY `name` ASC ";
|
2012-11-04 22:53:53 +01:00
|
|
|
|
2019-02-18 03:01:24 +01:00
|
|
|
$limit = $pager->getStart()."," . $pager->getItemsPerPage();
|
|
|
|
|
2019-12-28 02:48:47 +01:00
|
|
|
$r = DBA::p("SELECT `profile`.*, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
|
2020-07-12 14:49:55 +02:00
|
|
|
`contact`.`addr`, `contact`.`url` FROM `profile`
|
|
|
|
INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
|
|
|
|
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid`
|
2024-04-16 06:43:54 +02:00
|
|
|
WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `user`.`page-flags` IN (?, ?) AND `contact`.`self`
|
|
|
|
$sql_extra $order LIMIT $limit", User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_COMM_MAN
|
2012-11-04 22:53:53 +01:00
|
|
|
);
|
2018-01-20 22:03:48 +01:00
|
|
|
|
2018-07-21 14:46:13 +02:00
|
|
|
if (DBA::isResult($r)) {
|
2021-07-25 14:29:43 +02:00
|
|
|
if (in_array('small', DI::args()->getArgv())) {
|
2012-11-04 22:53:53 +01:00
|
|
|
$photo = 'thumb';
|
2018-01-19 01:36:05 +01:00
|
|
|
} else {
|
2012-11-04 22:53:53 +01:00
|
|
|
$photo = 'photo';
|
2018-01-19 01:36:05 +01:00
|
|
|
}
|
2012-11-04 22:53:53 +01:00
|
|
|
|
2019-02-18 03:01:24 +01:00
|
|
|
while ($rr = DBA::fetch($r)) {
|
2019-05-02 22:49:33 +02:00
|
|
|
$entries[] = Friendica\Module\Directory::formatEntry($rr, $photo);
|
2012-11-04 22:53:53 +01:00
|
|
|
}
|
2019-02-18 03:01:24 +01:00
|
|
|
DBA::close($r);
|
2018-01-19 01:36:05 +01:00
|
|
|
} else {
|
2022-10-17 22:17:25 +02:00
|
|
|
DI::sysmsg()->addNotice(DI::l10n()->t("No entries \x28some entries may be hidden\x29."));
|
2012-11-04 22:53:53 +01:00
|
|
|
}
|
|
|
|
|
2019-02-18 03:01:24 +01:00
|
|
|
$tpl = Renderer::getMarkupTemplate('directory_header.tpl');
|
|
|
|
$o .= Renderer::replaceMacros($tpl, [
|
|
|
|
'$search' => $search,
|
2020-01-18 20:52:33 +01:00
|
|
|
'$globaldir' => DI::l10n()->t('Global Directory'),
|
2019-02-18 03:01:24 +01:00
|
|
|
'$gdirpath' => $gdirpath,
|
2020-01-18 20:52:33 +01:00
|
|
|
'$desc' => DI::l10n()->t('Find on this site'),
|
2019-02-18 03:01:24 +01:00
|
|
|
'$contacts' => $entries,
|
2020-01-18 20:52:33 +01:00
|
|
|
'$finding' => DI::l10n()->t('Results for:'),
|
2019-02-18 03:01:24 +01:00
|
|
|
'$findterm' => (strlen($search) ? $search : ""),
|
2020-01-18 20:52:33 +01:00
|
|
|
'$title' => DI::l10n()->t('Forum Directory'),
|
2019-02-18 03:01:24 +01:00
|
|
|
'$search_mod' => 'forumdirectory',
|
2020-01-18 20:52:33 +01:00
|
|
|
'$submit' => DI::l10n()->t('Find'),
|
2019-02-18 03:01:24 +01:00
|
|
|
'$paginate' => $pager->renderFull($total),
|
|
|
|
]);
|
|
|
|
|
2012-11-04 22:53:53 +01:00
|
|
|
return $o;
|
|
|
|
}
|