diff --git a/CHANGELOG.md b/CHANGELOG.md index 334b498..5c5bf17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +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 diff --git a/README.md b/README.md index 1861cef..9e45fab 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,24 @@ # 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.10.20-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/saba/releases) +![Date](https://img.shields.io/badge/date-2023.10.20-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 +> 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 +34,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. diff --git a/_define.php b/_define.php index d75f8c6..28de5f2 100644 --- a/_define.php +++ b/_define.php @@ -1,32 +1,29 @@ registerModule( 'saba', 'Search across blog archive', 'Jean-Christian Denis and Contributors', - '2023.08.13', + '2023.10.20', [ - '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', ] ); diff --git a/dcstore.xml b/dcstore.xml index b78702c..03f8459 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ saba - 2023.08.13 + 2023.10.20 Jean-Christian Denis and Contributors Search across blog archive - https://git.dotclear.watch/JcDenis/saba/releases/download/v2023.08.13/plugin-saba.zip - 2.27 + https://git.dotclear.watch/JcDenis/saba/releases/download/v2023.10.20/plugin-saba.zip + 2.28 https://git.dotclear.watch/JcDenis/saba/src/branch/master/README.md https://git.dotclear.watch/JcDenis/saba/issues diff --git a/locales/fr/resources.php b/locales/fr/resources.php index 5a29f63..6ac4a61 100644 --- a/locales/fr/resources.php +++ b/locales/fr/resources.php @@ -1,19 +1,12 @@ resources['help']['core_plugins_conf'] = __DIR__ . '/help/help.html'; + \Dotclear\App::backend()->resources()->set('help', 'core_plugins_conf', __DIR__ . '/help/help.html'); } diff --git a/src/ActivityReportAction.php b/src/ActivityReportAction.php new file mode 100644 index 0000000..14baf82 --- /dev/null +++ b/src/ActivityReportAction.php @@ -0,0 +1,54 @@ +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; + } +} diff --git a/src/Backend.php b/src/Backend.php index ce419ee..5500e31 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -1,28 +1,25 @@ addBehaviors([ + App::behavior()->addBehaviors([ // add blog preferences form - 'adminBlogPreferencesFormV2' => function (dcSettings $blog_settings): void { + 'adminBlogPreferencesFormV2' => function (BlogSettingsInterface $blog_settings): void { echo '
' . '

' . __('Search Across Blog Archive') . '

' . @@ -60,12 +57,12 @@ class Backend extends Process '
'; }, // 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; diff --git a/src/Frontend.php b/src/Frontend.php index 5b3685a..0ae5853 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -1,22 +1,19 @@ 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()->setPath(App::frontend()->template()->getPath(), 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; diff --git a/src/FrontendBehaviors.php b/src/FrontendBehaviors.php index 6d0e11c..cfeb7a4 100644 --- a/src/FrontendBehaviors.php +++ b/src/FrontendBehaviors.php @@ -1,26 +1,23 @@ blog) || is_null(dcCore::app()->ctx)) { + if (!App::blog()->isDefined()) { return; } @@ -47,11 +44,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,23 +62,23 @@ 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); } public static function getPostsParams(ArrayObject $params): array @@ -135,7 +132,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 +165,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 +180,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 @@ -211,7 +208,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) . ') '; diff --git a/src/My.php b/src/My.php index 8b5e019..60f4ddb 100644 --- a/src/My.php +++ b/src/My.php @@ -1,15 +1,5 @@ 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; - } -} diff --git a/src/Uninstall.php b/src/Uninstall.php index 6df4d26..a4649ed 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -1,23 +1,19 @@ plugins->moduleExists('Uninstaller')) { + if (!self::status()) { return false; } diff --git a/src/UrlHandler.php b/src/UrlHandler.php index 95a69f4..7b565a4 100644 --- a/src/UrlHandler.php +++ b/src/UrlHandler.php @@ -1,24 +1,21 @@ callBehavior('sabaBeforeErrorDocument'); + App::behavior()->callBehavior('sabaBeforeErrorDocument'); # Clean URI $_GET['q'] = implode('%20', $q); diff --git a/src/Utils.php b/src/Utils.php index 1d5dc13..071d584 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -1,21 +1,18 @@ getPostTypes(); + $types = App::postTypes()->getPostTypes(); foreach ($types as $k => $v) { if (!$v['public_url']) { diff --git a/src/Widgets.php b/src/Widgets.php index 60f82f3..84f9262 100644 --- a/src/Widgets.php +++ b/src/Widgets.php @@ -1,25 +1,21 @@ 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 = ''; @@ -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)) { @@ -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 '
  • ', $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('') : '') . - '
    ' . + '' . '

    __get('placeholder') ? 'placeholder="' . Html::escapeHTML($w->__get('placeholder')) . '"' : '') .