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>
|
|
|
|
*/
|
|
|
|
|
2018-07-28 07:33:39 +02:00
|
|
|
use Friendica\App;
|
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;
|
2017-11-07 00:55:24 +01:00
|
|
|
use Friendica\Core\Config;
|
2018-12-26 08:28:16 +01:00
|
|
|
use Friendica\Core\Hook;
|
2018-01-22 20:03:11 +01:00
|
|
|
use Friendica\Core\L10n;
|
2019-02-18 03:01:24 +01:00
|
|
|
use Friendica\Core\Logger;
|
2018-10-31 15:55:15 +01:00
|
|
|
use Friendica\Core\Renderer;
|
2018-07-21 14:42:08 +02:00
|
|
|
use Friendica\Database\DBA;
|
2018-01-20 15:30:08 +01:00
|
|
|
use Friendica\Model\Profile;
|
2019-01-07 05:38:21 +01:00
|
|
|
use Friendica\Model\User;
|
2018-11-08 17:45:19 +01:00
|
|
|
use Friendica\Util\Strings;
|
2018-02-03 18:31:33 +01:00
|
|
|
use Friendica\Util\Temporal;
|
2018-01-20 15:30:08 +01:00
|
|
|
|
2019-02-18 03:01:24 +01:00
|
|
|
include_once 'mod/directory.php';
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-01-22 20:03:11 +01:00
|
|
|
function forumdirectory_uninstall()
|
|
|
|
{
|
2018-12-26 08:28:16 +01:00
|
|
|
Hook::unregister('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
|
2012-11-04 22:53:53 +01:00
|
|
|
}
|
|
|
|
|
2018-01-19 01:36:05 +01:00
|
|
|
function forumdirectory_module()
|
|
|
|
{
|
|
|
|
return;
|
2012-11-04 22:53:53 +01:00
|
|
|
}
|
|
|
|
|
2018-07-28 07:33:39 +02:00
|
|
|
function forumdirectory_app_menu(App $a, array &$b)
|
2018-01-19 01:36:05 +01:00
|
|
|
{
|
2018-01-22 20:03:11 +01:00
|
|
|
$b['app_menu'][] = '<div class="app-title"><a href="forumdirectory">' . L10n::t('Forum Directory') . '</a></div>';
|
2012-11-04 23:18:24 +01:00
|
|
|
}
|
|
|
|
|
2018-07-28 07:33:39 +02:00
|
|
|
function forumdirectory_init(App $a)
|
2018-01-19 01:36:05 +01:00
|
|
|
{
|
|
|
|
if (local_user()) {
|
|
|
|
$a->page['aside'] .= Widget::findPeople();
|
|
|
|
} else {
|
2012-11-04 22:53:53 +01:00
|
|
|
unset($_SESSION['theme']);
|
2018-01-19 01:36:05 +01:00
|
|
|
}
|
2012-11-04 22:53:53 +01:00
|
|
|
}
|
|
|
|
|
2018-07-28 07:33:39 +02:00
|
|
|
function forumdirectory_post(App $a)
|
2018-01-19 01:36:05 +01:00
|
|
|
{
|
2018-07-28 07:33:39 +02:00
|
|
|
if (!empty($_POST['search'])) {
|
2012-11-04 22:53:53 +01:00
|
|
|
$a->data['search'] = $_POST['search'];
|
2018-01-19 01:36:05 +01:00
|
|
|
}
|
2012-11-04 22:53:53 +01:00
|
|
|
}
|
|
|
|
|
2018-07-28 07:33:39 +02:00
|
|
|
function forumdirectory_content(App $a)
|
2018-01-19 01:36:05 +01:00
|
|
|
{
|
|
|
|
if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
|
2018-01-22 20:03:11 +01:00
|
|
|
notice(L10n::t('Public access denied.') . EOL);
|
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
|
|
|
|
2018-07-28 07:33:39 +02:00
|
|
|
if (!empty($a->data['search'])) {
|
2018-11-09 19:32:45 +01:00
|
|
|
$search = Strings::escapeTags(trim($a->data['search']));
|
2018-01-19 01:36:05 +01:00
|
|
|
} else {
|
2018-11-30 15:11:56 +01:00
|
|
|
$search = (!empty($_GET['search']) ? Strings::escapeTags(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 = '';
|
|
|
|
$dirurl = Config::get('system', 'directory');
|
|
|
|
if (strlen($dirurl)) {
|
|
|
|
$gdirpath = Profile::zrl($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
|
|
|
|
(`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%'))";
|
2018-01-19 01:36:05 +01:00
|
|
|
}
|
2012-11-04 22:53:53 +01:00
|
|
|
|
2018-01-19 01:36:05 +01:00
|
|
|
$publish = Config::get('system', 'publish_all') ? '' : " AND `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`
|
|
|
|
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'];
|
2018-01-19 01:36:05 +01:00
|
|
|
}
|
2012-11-04 22:53:53 +01:00
|
|
|
|
2018-10-25 02:18:22 +02:00
|
|
|
$pager = new Pager($a->query_string, 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();
|
|
|
|
|
|
|
|
$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"
|
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)) {
|
2018-01-19 01:36:05 +01:00
|
|
|
if (in_array('small', $a->argv)) {
|
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)) {
|
|
|
|
$entries[] = format_directory_entry($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 {
|
2018-01-22 20:03:11 +01:00
|
|
|
info(L10n::t("No entries \x28some entries may be hidden\x29.") . EOL);
|
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,
|
|
|
|
'$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),
|
|
|
|
]);
|
|
|
|
|
2012-11-04 22:53:53 +01:00
|
|
|
return $o;
|
|
|
|
}
|