Compare commits
4 Commits
v2023.08.1
...
master
Author | SHA1 | Date | |
---|---|---|---|
751b382952 | |||
7b12eda8a5 | |||
d65758cc69 | |||
26ca1289a5 |
12
CHANGELOG.md
12
CHANGELOG.md
@ -1,3 +1,15 @@
|
||||
saba 2023.11.04
|
||||
===========================================================
|
||||
* Require Dotclear 2.28
|
||||
* Require PHP 8.1
|
||||
* Code review (phpstan)
|
||||
|
||||
saba 2023.10.20
|
||||
===========================================================
|
||||
* Require Dotclear 2.28
|
||||
* Require PHP 8.1
|
||||
* Upgrade to Dotclear 2.28
|
||||
|
||||
saba 2023.08.13
|
||||
===========================================================
|
||||
* Require Dotclear 2.27
|
||||
|
33
README.md
33
README.md
@ -1,27 +1,23 @@
|
||||
# README
|
||||
|
||||
[![Release](https://img.shields.io/badge/release-2023.08.13-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/saba/releases)
|
||||
[![Date](https://img.shields.io/badge/date-2023.08.13-c44d58.svg)](https://git.dotclear.watch/JcDenis/saba/releases)
|
||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download)
|
||||
[![Release](https://img.shields.io/badge/release-2023.11.04-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/saba/releases)
|
||||
![Date](https://img.shields.io/badge/date-2023.11.04-c44d58.svg)
|
||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download)
|
||||
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/saba)
|
||||
[![License](https://img.shields.io/github/license/JcDenis/saba)](https://git.dotclear.watch/JcDenis/saba/blob/master/LICENSE)
|
||||
[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/saba/src/branch/master/LICENSE)
|
||||
|
||||
## WHAT IS SABA ?
|
||||
## ABOUT
|
||||
|
||||
_saba_ : Search Across Blog's Archive is a plugins for the open-source
|
||||
web publishing software called Dotclear.
|
||||
_saba_ is a plugin for the open-source web publishing software called [Dotclear](https://www.dotclear.org).
|
||||
|
||||
It replaces public search page and 404 page by a custom page that
|
||||
show related entries to visitor.
|
||||
> Replace public search page and 404 page by a custom page that show related entries to visitor.
|
||||
|
||||
## REQUIREMENTS
|
||||
|
||||
_saba_ requires:
|
||||
|
||||
* administrator permissions
|
||||
* Dotclear 2.27
|
||||
* PHP 7.4
|
||||
* Dotclear 2.28
|
||||
* PHP 8.1
|
||||
* Custom templates if default theme is not used.
|
||||
* Dotclear administrator permissions
|
||||
|
||||
## USAGE
|
||||
|
||||
@ -37,12 +33,13 @@ You can find exemple in plugins/saba/default-tempaltes.
|
||||
|
||||
## MORE
|
||||
|
||||
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
|
||||
* Source & contribution : [Gitea Page](https://git.dotclear.watch/JcDenis/saba) or [GitHub Page](https://github.com/JcDenis/saba)
|
||||
* Packages & details: [Gitea Page](https://git.dotclear.watch/JcDenis/saba/releases) or [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/saba)
|
||||
* [License](https://git.dotclear.watch/JcDenis/saba/src/branch/master/LICENSE)
|
||||
* [Packages & details](https://git.dotclear.watch/JcDenis/saba/releases) (or on [Dotaddict](https://plugins.dotaddict.org/dc2/details/saba))
|
||||
* [Sources & contributions](https://git.dotclear.watch/JcDenis/saba) (or on [GitHub](https://github.com/JcDenis/saba))
|
||||
* [Issues & security](https://git.dotclear.watch/JcDenis/saba/issues) (or on [GitHub](https://github.com/JcDenis/saba/issues))
|
||||
|
||||
## CONTRIBUTORS
|
||||
|
||||
* Jean-Christian Denis
|
||||
* Jean-Christian Denis (author)
|
||||
|
||||
You are welcome to contribute to this code.
|
||||
|
33
_define.php
33
_define.php
@ -1,32 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief saba, a plugin for Dotclear 2
|
||||
* @file
|
||||
* @brief The plugin saba definition
|
||||
* @ingroup saba
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
* @defgroup saba Plugin saba.
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
* Search across blog archive.
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @author Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
declare(strict_types=1);
|
||||
|
||||
$this->registerModule(
|
||||
'saba',
|
||||
'Search across blog archive',
|
||||
'Jean-Christian Denis and Contributors',
|
||||
'2023.08.13',
|
||||
'2023.11.04',
|
||||
[
|
||||
'requires' => [['core', '2.27']],
|
||||
'permissions' => dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_ADMIN,
|
||||
]),
|
||||
'type' => 'plugin',
|
||||
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
|
||||
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
|
||||
'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
|
||||
'requires' => [['core', '2.28']],
|
||||
'permissions' => 'My',
|
||||
'type' => 'plugin',
|
||||
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
|
||||
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
|
||||
'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
|
||||
]
|
||||
);
|
||||
|
@ -2,11 +2,11 @@
|
||||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="saba">
|
||||
<name>saba</name>
|
||||
<version>2023.08.13</version>
|
||||
<version>2023.11.04</version>
|
||||
<author>Jean-Christian Denis and Contributors</author>
|
||||
<desc>Search across blog archive</desc>
|
||||
<file>https://git.dotclear.watch/JcDenis/saba/releases/download/v2023.08.13/plugin-saba.zip</file>
|
||||
<da:dcmin>2.27</da:dcmin>
|
||||
<file>https://git.dotclear.watch/JcDenis/saba/releases/download/v2023.11.04/plugin-saba.zip</file>
|
||||
<da:dcmin>2.28</da:dcmin>
|
||||
<da:details>https://git.dotclear.watch/JcDenis/saba/src/branch/master/README.md</da:details>
|
||||
<da:support>https://git.dotclear.watch/JcDenis/saba/issues</da:support>
|
||||
</module>
|
||||
|
@ -1,19 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief saba, a plugin for Dotclear 2
|
||||
* @file
|
||||
* @brief The plugin saba locales resources
|
||||
* @ingroup saba
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @author Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!empty($_REQUEST['module']) && $_REQUEST['module'] == 'saba') {
|
||||
dcCore::app()->resources['help']['core_plugins_conf'] = __DIR__ . '/help/help.html';
|
||||
\Dotclear\App::backend()->resources()->set('help', 'core_plugins_conf', __DIR__ . '/help/help.html');
|
||||
}
|
||||
|
54
src/ActivityReportAction.php
Normal file
54
src/ActivityReportAction.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\saba;
|
||||
|
||||
use Dotclear\App;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Plugin\activityReport\{
|
||||
Action,
|
||||
ActivityReport,
|
||||
Group
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief saba plugin activityReport class.
|
||||
* @ingroup saba
|
||||
*
|
||||
* Add 404 to activity report
|
||||
*
|
||||
* @author Jean-Christian Denis (author)
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class ActivityReportAction extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
return self::status(true);
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$group = new Group(My::id(), My::name());
|
||||
|
||||
$group->add(new Action(
|
||||
'saba404',
|
||||
__('404 error (saba)'),
|
||||
__('New 404 error page at "%s"'),
|
||||
'sabaBeforeErrorDocument',
|
||||
function () {
|
||||
$logs = [App::blog()->url() . urldecode($_SERVER['QUERY_STRING'])];
|
||||
ActivityReport::instance()->addLog(My::id(), 'saba404', $logs);
|
||||
}
|
||||
));
|
||||
|
||||
ActivityReport::instance()->groups->add($group);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,28 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief saba, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\saba;
|
||||
|
||||
use dcCore;
|
||||
use dcSettings;
|
||||
use Dotclear\App;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Checkbox,
|
||||
Label,
|
||||
Para
|
||||
};
|
||||
use Dotclear\Interface\Core\BlogSettingsInterface;
|
||||
|
||||
/**
|
||||
* @brief saba backend class.
|
||||
* @ingroup saba
|
||||
*
|
||||
* @author Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Backend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
@ -36,9 +33,9 @@ class Backend extends Process
|
||||
return false;
|
||||
}
|
||||
|
||||
dcCore::app()->addBehaviors([
|
||||
App::behavior()->addBehaviors([
|
||||
// add blog preferences form
|
||||
'adminBlogPreferencesFormV2' => function (dcSettings $blog_settings): void {
|
||||
'adminBlogPreferencesFormV2' => function (BlogSettingsInterface $blog_settings): void {
|
||||
echo
|
||||
'<div class="fieldset">' .
|
||||
'<h4 id="saba_params">' . __('Search Across Blog Archive') . '</h4>' .
|
||||
@ -60,12 +57,12 @@ class Backend extends Process
|
||||
'</div>';
|
||||
},
|
||||
// save blog preference form
|
||||
'adminBeforeBlogSettingsUpdate' => function (dcSettings $blog_settings): void {
|
||||
'adminBeforeBlogSettingsUpdate' => function (BlogSettingsInterface $blog_settings): void {
|
||||
$blog_settings->get(My::id())->put('active', !empty($_POST['saba_active']));
|
||||
$blog_settings->get(My::id())->put('error', !empty($_POST['saba_error']));
|
||||
},
|
||||
// init widget
|
||||
'initWidgets' => [Widgets::class, 'initWidgets'],
|
||||
'initWidgets' => Widgets::initWidgets(...),
|
||||
]);
|
||||
|
||||
return true;
|
||||
|
@ -1,22 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief saba, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\saba;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\App;
|
||||
use Dotclear\Core\Process;
|
||||
|
||||
/**
|
||||
* @brief saba frontend class.
|
||||
* @ingroup saba
|
||||
*
|
||||
* @author Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Frontend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
@ -30,21 +27,21 @@ class Frontend extends Process
|
||||
return false;
|
||||
}
|
||||
|
||||
if (My::settings()->get('active')) {
|
||||
if (!My::settings()->get('active')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (My::settings()->get('error')) {
|
||||
dcCore::app()->url->registerError([UrlHandler::class, 'error']);
|
||||
App::url()->registerError(UrlHandler::error(...));
|
||||
}
|
||||
|
||||
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), My::path() . DIRECTORY_SEPARATOR . 'default-templates');
|
||||
App::frontend()->template()->appendPath(My::path() . DIRECTORY_SEPARATOR . 'default-templates');
|
||||
|
||||
dcCore::app()->addBehaviors([
|
||||
'templateCustomSortByAlias' => [FrontendBehaviors::class, 'templateCustomSortByAlias'],
|
||||
'urlHandlerBeforeGetData' => [FrontendBehaviors::class, 'urlHandlerBeforeGetData'],
|
||||
'coreBlogBeforeGetPosts' => [FrontendBehaviors::class, 'coreBlogBeforeGetPosts'],
|
||||
'initWidgets' => [Widgets::class, 'initWidgets'],
|
||||
App::behavior()->addBehaviors([
|
||||
'templateCustomSortByAlias' => FrontendBehaviors::templateCustomSortByAlias(...),
|
||||
'urlHandlerBeforeGetData' => FrontendBehaviors::urlHandlerBeforeGetData(...),
|
||||
'coreBlogBeforeGetPosts' => FrontendBehaviors::coreBlogBeforeGetPosts(...),
|
||||
'initWidgets' => Widgets::initWidgets(...),
|
||||
]);
|
||||
|
||||
return true;
|
||||
|
@ -1,28 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief saba, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\saba;
|
||||
|
||||
use ArrayObject;
|
||||
use dcCore;
|
||||
use Dotclear\App;
|
||||
use Dotclear\Helper\Date;
|
||||
use Dotclear\Helper\Text;
|
||||
|
||||
use context;
|
||||
use Dotclear\Core\Frontend\Ctx;
|
||||
|
||||
/**
|
||||
* @brief saba frontend behaviors class.
|
||||
* @ingroup saba
|
||||
*
|
||||
* @author Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class FrontendBehaviors
|
||||
{
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $alias
|
||||
*/
|
||||
public static function templateCustomSortByAlias(ArrayObject $alias): void
|
||||
{
|
||||
$alias['post'] = [
|
||||
@ -37,9 +37,9 @@ class FrontendBehaviors
|
||||
];
|
||||
}
|
||||
|
||||
public static function urlHandlerBeforeGetData(context $_): void
|
||||
public static function urlHandlerBeforeGetData(Ctx $_): void
|
||||
{
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->ctx)) {
|
||||
if (!App::blog()->isDefined()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -47,11 +47,11 @@ class FrontendBehaviors
|
||||
|
||||
if (!empty($_GET['q']) && 1 < strlen($_GET['q'])) {
|
||||
# pagintaion
|
||||
$_page_number = dcCore::app()->public->getPageNumber();
|
||||
$_page_number = App::frontend()->getPageNumber();
|
||||
if ($_page_number < 1) {
|
||||
$_page_number = 1;
|
||||
}
|
||||
$limit = (int) dcCore::app()->ctx->__get('nb_entry_per_page');
|
||||
$limit = (int) App::frontend()->context()->__get('nb_entry_per_page');
|
||||
|
||||
$params = [
|
||||
'limit' => [(($_page_number - 1) * $limit), $limit],
|
||||
@ -65,25 +65,30 @@ class FrontendBehaviors
|
||||
$options['q'] = rawurldecode($_GET['q']);
|
||||
|
||||
# count
|
||||
dcCore::app()->public->search = rawurldecode($_GET['q']);
|
||||
if (dcCore::app()->public->search) {
|
||||
dcCore::app()->public->search_count = dcCore::app()->blog->getPosts($params, true)->f(0);
|
||||
App::frontend()->search = rawurldecode($_GET['q']);
|
||||
if (App::frontend()->search) {
|
||||
App::frontend()->search_count = App::blog()->getPosts($params, true)->f(0);
|
||||
}
|
||||
|
||||
# get posts
|
||||
$posts = dcCore::app()->blog->getPosts($params);
|
||||
$posts = App::blog()->getPosts($params);
|
||||
if ($posts->isEmpty()) { // hack: don't breack context
|
||||
$params = ['limit' => $params['limit']];
|
||||
$posts = dcCore::app()->blog->getPosts($params);
|
||||
$posts = App::blog()->getPosts($params);
|
||||
}
|
||||
dcCore::app()->ctx->__set('post_params', $params);
|
||||
dcCore::app()->ctx->__set('posts', $posts);
|
||||
App::frontend()->context()->__set('post_params', $params);
|
||||
App::frontend()->context()->__set('posts', $posts);
|
||||
|
||||
unset($params);
|
||||
}
|
||||
dcCore::app()->ctx->__set('saba_options', $options);
|
||||
App::frontend()->context()->__set('saba_options', $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, mixed> $params
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function getPostsParams(ArrayObject $params): array
|
||||
{
|
||||
if (!isset($params['sql'])) {
|
||||
@ -94,7 +99,7 @@ class FrontendBehaviors
|
||||
|
||||
# retreive _GET
|
||||
$qs = $_SERVER['QUERY_STRING'];
|
||||
$qs = preg_replace('#(^|/)page/([0-9]+)#', '', $qs);
|
||||
$qs = (string) preg_replace('#(^|/)page/([0-9]+)#', '', $qs);
|
||||
parse_str($qs, $get);
|
||||
|
||||
# search string
|
||||
@ -135,7 +140,7 @@ class FrontendBehaviors
|
||||
|
||||
# post types
|
||||
if (!empty($get['q_type']) && is_array($get['q_type'])) {
|
||||
$types = dcCore::app()->getPostTypes();
|
||||
$types = App::postTypes()->getPostTypes();
|
||||
foreach ($get['q_type'] as $v) {
|
||||
if (!$types[$v]) {
|
||||
continue;
|
||||
@ -168,7 +173,7 @@ class FrontendBehaviors
|
||||
if (!empty($get['q_user']) && is_array($get['q_user'])) {
|
||||
$users = [];
|
||||
foreach ($get['q_user'] as $v) {
|
||||
$users[] = "U.user_id = '" . dcCore::app()->con->escapeStr((string) $v) . "'";
|
||||
$users[] = "U.user_id = '" . App::con()->escapeStr((string) $v) . "'";
|
||||
$options['q_user'][] = $v;
|
||||
}
|
||||
$params['sql'] .= 'AND (' . implode(' OR ', $users) . ') ';
|
||||
@ -183,7 +188,7 @@ class FrontendBehaviors
|
||||
$orders = Utils::getSabaFormOrders();
|
||||
if (!empty($get['q_order']) && in_array($get['q_order'], $orders)) {
|
||||
$options['q_order'] = $get['q_order'];
|
||||
$params['order'] = dcCore::app()->tpl->getSortByStr(
|
||||
$params['order'] = App::frontend()->template()->getSortByStr(
|
||||
new ArrayObject(['sortby' => $get['q_order'], 'order' => $sort]),
|
||||
'post'
|
||||
); //?! post_type
|
||||
@ -192,7 +197,11 @@ class FrontendBehaviors
|
||||
return $options;
|
||||
}
|
||||
|
||||
# Ajouter la condition "ou" à la recherche
|
||||
/**
|
||||
* Ajouter la condition "ou" à la recherche.
|
||||
*
|
||||
* @param ArrayObject<string, mixed> $p
|
||||
*/
|
||||
public static function coreBlogBeforeGetPosts(ArrayObject $p): void
|
||||
{
|
||||
if (empty($p['search'])) {
|
||||
@ -211,7 +220,7 @@ class FrontendBehaviors
|
||||
$AND = [];
|
||||
$words = Text::splitWords($sentence);
|
||||
foreach ($words as $word) {
|
||||
$AND[] = "post_words LIKE '%" . dcCore::app()->con->escapeStr((string) $word) . "%'";
|
||||
$AND[] = "post_words LIKE '%" . App::con()->escapeStr((string) $word) . "%'";
|
||||
}
|
||||
if (!empty($AND)) {
|
||||
$OR[] = ' (' . implode(' AND ', $AND) . ') ';
|
||||
|
19
src/My.php
19
src/My.php
@ -1,15 +1,5 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief saba, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\saba;
|
||||
@ -17,8 +7,13 @@ namespace Dotclear\Plugin\saba;
|
||||
use Dotclear\Module\MyPlugin;
|
||||
|
||||
/**
|
||||
* This module definitions.
|
||||
* @brief saba My helper.
|
||||
* @ingroup saba
|
||||
*
|
||||
* @author Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class My extends MyPlugin
|
||||
{
|
||||
// Use default permissions
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief saba, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\saba;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Plugin\activityReport\{
|
||||
Action,
|
||||
ActivityReport,
|
||||
Group
|
||||
};
|
||||
|
||||
class Prepend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
return self::status(My::checkContext(My::PREPEND));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// log frontend page 404 intercepted by saba
|
||||
if (defined('ACTIVITY_REPORT') && ACTIVITY_REPORT == 3) {
|
||||
$group = new Group(My::id(), My::name());
|
||||
$group->add(new Action(
|
||||
'saba404',
|
||||
__('404 error (saba)'),
|
||||
__('New 404 error page at "%s"'),
|
||||
'sabaBeforeErrorDocument',
|
||||
function () {
|
||||
$url = is_null(dcCore::app()->blog) ? '' : dcCore::app()->blog->url;
|
||||
|
||||
$logs = [$url . urldecode($_SERVER['QUERY_STRING'])];
|
||||
ActivityReport::instance()->addLog(My::id(), 'saba404', $logs);
|
||||
}
|
||||
));
|
||||
ActivityReport::instance()->groups->add($group);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,23 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief saba, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\saba;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Plugin\Uninstaller\Uninstaller;
|
||||
|
||||
/**
|
||||
* @brief saba uninstall class.
|
||||
* @ingroup saba
|
||||
*
|
||||
* @author Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Uninstall extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
@ -27,7 +23,7 @@ class Uninstall extends Process
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,24 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief saba, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\saba;
|
||||
|
||||
use dcCore;
|
||||
use dcUrlHandlers;
|
||||
use Dotclear\App;
|
||||
use Dotclear\Core\Frontend\Url;
|
||||
use Exception;
|
||||
|
||||
class UrlHandler extends dcUrlHandlers
|
||||
/**
|
||||
* @brief saba frontend URL handler class.
|
||||
* @ingroup saba
|
||||
*
|
||||
* @author Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class UrlHandler extends Url
|
||||
{
|
||||
public static function error(?string $args, string $type, Exception $e): void
|
||||
{
|
||||
@ -28,7 +25,7 @@ class UrlHandler extends dcUrlHandlers
|
||||
return;
|
||||
}
|
||||
|
||||
dcCore::app()->callBehavior('sabaBeforeErrorDocument');
|
||||
App::behavior()->callBehavior('sabaBeforeErrorDocument');
|
||||
|
||||
# Clean URI
|
||||
$_GET['q'] = implode('%20', $q);
|
||||
|
@ -1,23 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief saba, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\saba;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\App;
|
||||
|
||||
/**
|
||||
* @brief saba utils class.
|
||||
* @ingroup saba
|
||||
*
|
||||
* @author Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Utils
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function getSabaDefaultPostsOptions(): array
|
||||
{
|
||||
return [
|
||||
@ -32,6 +32,9 @@ class Utils
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getSabaFormOptions(): array
|
||||
{
|
||||
return [
|
||||
@ -41,6 +44,9 @@ class Utils
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getSabaFormOrders(): array
|
||||
{
|
||||
return [
|
||||
@ -54,6 +60,9 @@ class Utils
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getSabaFormAges(): array
|
||||
{
|
||||
return [
|
||||
@ -65,6 +74,9 @@ class Utils
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function getSabaFormTypes(): array
|
||||
{
|
||||
$know = [
|
||||
@ -76,7 +88,7 @@ class Utils
|
||||
// todo: add behavior for unknow types
|
||||
|
||||
$rs = [];
|
||||
$types = dcCore::app()->getPostTypes();
|
||||
$types = App::postTypes()->getPostTypes();
|
||||
|
||||
foreach ($types as $k => $v) {
|
||||
if (!$v['public_url']) {
|
||||
|
@ -1,25 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief saba, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\saba;
|
||||
|
||||
use dcCore;
|
||||
use dcUtils;
|
||||
use Dotclear\App;
|
||||
use Dotclear\Helper\Html\Html;
|
||||
use Dotclear\Plugin\widgets\WidgetsStack;
|
||||
use Dotclear\Plugin\widgets\WidgetsElement;
|
||||
|
||||
/**
|
||||
* @brief saba widgets class.
|
||||
* @ingroup saba
|
||||
*
|
||||
* @author Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
class Widgets
|
||||
{
|
||||
/**
|
||||
@ -33,7 +29,7 @@ class Widgets
|
||||
->create(
|
||||
'saba',
|
||||
__('Advanced search'),
|
||||
[self::class, 'parseWidget'],
|
||||
self::parseWidget(...),
|
||||
null,
|
||||
__('Add more search options on public side')
|
||||
)
|
||||
@ -90,23 +86,22 @@ class Widgets
|
||||
*/
|
||||
public static function parseWidget(WidgetsElement $w): string
|
||||
{
|
||||
if (is_null(dcCore::app()->blog)
|
||||
|| is_null(dcCore::app()->ctx)
|
||||
|| !dcCore::app()->blog->settings->get(My::id())->get('active')
|
||||
|| !dcCore::app()->blog->settings->get(My::id())->get('error') && dcCore::app()->url->type == '404'
|
||||
if (!App::blog()->isDefined()
|
||||
|| !App::blog()->settings()->get(My::id())->get('active')
|
||||
|| !App::blog()->settings()->get(My::id())->get('error') && App::url()->type == '404'
|
||||
|| $w->__get('offline')
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$saba_options = dcCore::app()->ctx->__get('saba_options') ?? [];
|
||||
$saba_options = App::frontend()->context()->__get('saba_options') ?? [];
|
||||
if (!is_array($saba_options) || empty($saba_options)) {
|
||||
$saba_options = Utils::getSabaDefaultPostsOptions();
|
||||
}
|
||||
$res = '';
|
||||
|
||||
# advanced search only on search page
|
||||
if (dcCore::app()->url->type == 'search') {
|
||||
if (App::url()->type == 'search') {
|
||||
# order
|
||||
if (!$w->__get('saba_filter_orders')) {
|
||||
$ct = '';
|
||||
@ -115,7 +110,7 @@ class Widgets
|
||||
$ct .= '<li><label><input name="q_order" type="radio" value="' .
|
||||
$v . '" ' .
|
||||
($v == $saba_options['q_order'] ? 'checked="checked" ' : '') .
|
||||
'/> ' . Html::escapeHTML($k) . '</label></li>';
|
||||
'/> ' . Html::escapeHTML((string) $k) . '</label></li>';
|
||||
}
|
||||
if (!empty($ct)) {
|
||||
$ct .= '<li><label><input name="q_rev" type="checkbox" value="1" ' .
|
||||
@ -137,7 +132,7 @@ class Widgets
|
||||
$ct .= '<li><label><input name="q_opt[]" type="checkbox" value="' .
|
||||
$v . '" ' .
|
||||
(in_array($v, $saba_options['q_opt']) ? 'checked="checked" ' : '') .
|
||||
'/> ' . Html::escapeHTML($k) . '</label></li>';
|
||||
'/> ' . Html::escapeHTML((string) $k) . '</label></li>';
|
||||
}
|
||||
if (!empty($ct)) {
|
||||
$res .= $w->renderTitle(__('Filter options')) . sprintf('<ul>%s</ul>', $ct);
|
||||
@ -152,7 +147,7 @@ class Widgets
|
||||
$ct .= '<li><label><input name="q_age" type="radio" value="' .
|
||||
$v . '" ' .
|
||||
($v == $saba_options['q_age'] ? 'checked="checked" ' : '') .
|
||||
'/> ' . Html::escapeHTML($k) . '</label></li>';
|
||||
'/> ' . Html::escapeHTML((string) $k) . '</label></li>';
|
||||
}
|
||||
if (!empty($ct)) {
|
||||
$res .= $w->renderTitle(__('Filter by age')) . sprintf('<ul>%s</ul>', $ct);
|
||||
@ -171,7 +166,7 @@ class Widgets
|
||||
$ct .= '<li><label><input name="q_type[]" type="checkbox" value="' .
|
||||
$v . '" ' .
|
||||
(in_array($v, $saba_options['q_type']) ? 'checked="checked" ' : '') .
|
||||
'/> ' . Html::escapeHTML($k) . '</label></li>';
|
||||
'/> ' . Html::escapeHTML((string) $k) . '</label></li>';
|
||||
}
|
||||
if (!empty($ct)) {
|
||||
$res .= $w->renderTitle(__('Filter by type')) . sprintf('<ul>%s</ul>', $ct);
|
||||
@ -182,7 +177,7 @@ class Widgets
|
||||
if (!$w->__get('saba_filter_categories')) {
|
||||
$ct = '';
|
||||
$rm = explode(',', $w->__get('saba_remove_categories'));
|
||||
$rs = dcCore::app()->blog->getCategories();
|
||||
$rs = App::blog()->getCategories();
|
||||
|
||||
while ($rs->fetch()) {
|
||||
if (in_array($rs->f('cat_id'), $rm) || in_array($rs->f('cat_url'), $rm)) {
|
||||
@ -191,7 +186,7 @@ class Widgets
|
||||
$ct .= '<li><label><input name="q_cat[]" type="checkbox" value="' .
|
||||
$rs->f('cat_id') . '" ' .
|
||||
(in_array($rs->f('cat_id'), $saba_options['q_cat']) ? 'checked="checked" ' : '') .
|
||||
'/> ' . Html::escapeHTML($rs->f('cat_title')) . '</label></li>';
|
||||
'/> ' . Html::escapeHTML((string) $rs->f('cat_title')) . '</label></li>';
|
||||
}
|
||||
if (!empty($ct)) {
|
||||
$res .= $w->renderTitle(__('Filter by category')) . sprintf('<ul>%s</ul>', $ct);
|
||||
@ -202,7 +197,7 @@ class Widgets
|
||||
if (!$w->__get('saba_filter_authors')) {
|
||||
$ct = '';
|
||||
$rm = explode(',', $w->__get('saba_remove_authors'));
|
||||
$rs = dcCore::app()->blog->getPostsUsers();
|
||||
$rs = App::blog()->getPostsUsers();
|
||||
|
||||
while ($rs->fetch()) {
|
||||
if (in_array($rs->f('user_id'), $rm)) {
|
||||
@ -212,7 +207,7 @@ class Widgets
|
||||
'<li><label><input name="q_user[]" type="checkbox" value="%s" %s/> %s</label></li>',
|
||||
$rs->f('user_id'),
|
||||
in_array($rs->f('user_id'), $saba_options['q_user']) ? 'checked="checked" ' : '',
|
||||
Html::escapeHTML(dcUtils::getUserCN($rs->f('user_id'), $rs->f('user_name'), $rs->f('user_firstname'), $rs->f('user_displayname')))
|
||||
Html::escapeHTML(App::users()->getUserCN($rs->f('user_id'), $rs->f('user_name'), $rs->f('user_firstname'), $rs->f('user_displayname')))
|
||||
);
|
||||
}
|
||||
if (!empty($ct)) {
|
||||
@ -226,7 +221,7 @@ class Widgets
|
||||
$w->__get('class'),
|
||||
'id="search"',
|
||||
($w->__get('title') ? $w->renderTitle('<label for="q">' . Html::escapeHTML($w->__get('title')) . '</label>') : '') .
|
||||
'<form action="' . dcCore::app()->blog->url . '" method="get" role="search">' .
|
||||
'<form action="' . App::blog()->url() . '" method="get" role="search">' .
|
||||
'<p><input type="text" size="10" maxlength="255" id="q" name="q" value="' .
|
||||
Html::escapeHTML($saba_options['q']) . '" ' .
|
||||
($w->__get('placeholder') ? 'placeholder="' . Html::escapeHTML($w->__get('placeholder')) . '"' : '') .
|
||||
|
Loading…
Reference in New Issue
Block a user