friendica-addons/forumdirectory/forumdirectory.php

164 lines
4.6 KiB
PHP
Raw Normal View History

<?php
/**
* Name: Forum Directory
* Description: Add a directory of forums hosted on your server, with verbose descriptions.
* Version: 1.1
* Author: Thomas Willingham <https://beardyunixer.com/profile/beardyunixer>
*/
use Friendica\App;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Content\Widget;
use Friendica\Core\Config;
use Friendica\Core\Hook;
2018-01-22 19:03:11 +00:00
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
2018-01-20 14:30:08 +00:00
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
2018-01-20 14:30:08 +00:00
include_once 'mod/directory.php';
2018-01-22 19:03:11 +00:00
function forumdirectory_install()
{
Hook::register('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
}
2018-01-22 19:03:11 +00:00
function forumdirectory_uninstall()
{
Hook::unregister('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
}
function forumdirectory_module()
{
return;
}
function forumdirectory_app_menu(App $a, array &$b)
{
2018-01-22 19:03:11 +00:00
$b['app_menu'][] = '<div class="app-title"><a href="forumdirectory">' . L10n::t('Forum Directory') . '</a></div>';
}
function forumdirectory_init(App $a)
{
if (local_user()) {
$a->page['aside'] .= Widget::findPeople();
} else {
unset($_SESSION['theme']);
}
}
function forumdirectory_post(App $a)
{
if (!empty($_POST['search'])) {
$a->data['search'] = $_POST['search'];
}
Logger::log(print_r($_POST, true));
}
function forumdirectory_content(App $a)
{
if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
2018-01-22 19:03:11 +00:00
notice(L10n::t('Public access denied.') . EOL);
return;
}
$o = '';
$entries = [];
Nav::setSelected('directory');
if (!empty($a->data['search'])) {
2018-11-09 18:32:45 +00:00
$search = Strings::escapeTags(trim($a->data['search']));
} else {
$search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : '');
}
$gdirpath = '';
$dirurl = Config::get('system', 'directory');
if (strlen($dirurl)) {
$gdirpath = Profile::zrl($dirurl, true);
}
$sql_extra = '';
if (strlen($search)) {
$search = DBA::escape($search);
$sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR
(`user`.`nickname` LIKE '%$search%') OR
(`profile`.`pdesc` LIKE '%$search%') OR
(`profile`.`locality` LIKE '%$search%') OR
(`profile`.`region` LIKE '%$search%') OR
(`profile`.`country-name` LIKE '%$search%') OR
(`profile`.`gender` LIKE '%$search%') OR
(`profile`.`marital` LIKE '%$search%') OR
(`profile`.`sexual` LIKE '%$search%') OR
(`profile`.`about` LIKE '%$search%') OR
(`profile`.`romance` LIKE '%$search%') OR
(`profile`.`work` LIKE '%$search%') OR
(`profile`.`education` LIKE '%$search%') OR
(`profile`.`pub_keywords` LIKE '%$search%') OR
(`profile`.`prv_keywords` LIKE '%$search%'))";
}
$publish = Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 ";
$total = 0;
$cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `profile`
LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` `user`.`page-flags` = 2 $sql_extra");
if (DBA::isResult($cnt)) {
$total = $cnt['total'];
}
$pager = new Pager($a->query_string, 60);
2018-01-15 13:15:33 +00:00
$order = " ORDER BY `name` ASC ";
$limit = $pager->getStart()."," . $pager->getItemsPerPage();
$r = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
`contact`.`addr`, `contact`.`url` AS `profile_url` FROM `profile`
LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `user`.`page-flags` = 2 AND `contact`.`self`
$sql_extra $order LIMIT $limit"
);
2018-01-20 21:03:48 +00:00
2018-07-21 12:46:13 +00:00
if (DBA::isResult($r)) {
if (in_array('small', $a->argv)) {
$photo = 'thumb';
} else {
$photo = 'photo';
}
while ($rr = DBA::fetch($r)) {
$entries[] = format_directory_entry($rr, $photo);
}
DBA::close($r);
} else {
2018-01-22 19:03:11 +00:00
info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);
}
$tpl = Renderer::getMarkupTemplate('directory_header.tpl');
$o .= Renderer::replaceMacros($tpl, [
'$search' => $search,
'$globaldir' => L10n::t('Global Directory'),
'$gdirpath' => $gdirpath,
'$desc' => L10n::t('Find on this site'),
'$contacts' => $entries,
'$finding' => L10n::t('Results for:'),
'$findterm' => (strlen($search) ? $search : ""),
'$title' => L10n::t('Forum Directory'),
'$search_mod' => 'forumdirectory',
'$submit' => L10n::t('Find'),
'$paginate' => $pager->renderFull($total),
]);
return $o;
}