diff --git a/changelog b/CHANGELOG.md similarity index 55% rename from changelog rename to CHANGELOG.md index 0e9d7db..5b96f5d 100644 --- a/changelog +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +1.5 - 2022.12.31 +* update to dotclear 2.24 +* use json intead of serialize +* use short settings names +* use anonymous functions +* use abstract plugin id +* fix phpstan and php-cs-fixer errors + v1.4 - 20-12-2022 - Pierre Van Glebeke * màj partielle dc2.24 diff --git a/README.md b/README.md index 571c872..fa197a9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,45 @@ -# construction -Cette extension permet de placer son blog en maintenance. Il est possible également de renseigner plusieurs IP autorisées. +# README + +[![Release](https://img.shields.io/github/v/release/JcDenis/construction)](https://github.com/JcDenis/construction/releases) +[![Date](https://img.shields.io/github/release-date/JcDenis/construction)](https://github.com/JcDenis/construction/releases) +[![Issues](https://img.shields.io/github/issues/JcDenis/construction)](https://github.com/JcDenis/construction/issues) +[![Dotclear](https://img.shields.io/badge/dotclear-v2.24-blue.svg)](https://fr.dotclear.org/download) +[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/construction) +[![License](https://img.shields.io/github/license/JcDenis/construction)](https://github.com/JcDenis/construction/blob/master/LICENSE) + +## WHAT IS DISCLAIMER ? + +_construction_ is a plugin for the open-source +web publishing software called Dotclear. + +Put your blog on construction mode with a custom message on frontend. +Blog can be accessible to defined IP addresses. + +## REQUIREMENTS + + _construction_ requires: + + * admin permissions on blog + * Dotclear 2.24 + +## USAGE + +First install _construction_, manualy from a zip package or from +Dotaddict repository. (See Dotclear's documentation to know how do this) + +You can activate and setup _construction_ from sidebar menu "Construction". + +## LINKS + + * License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html) + * Source & contribution : [GitHub Page](https://github.com/JcDenis/construction) + * Packages & details : [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/construction) + * Help & discuss : [Dotclear forum](http://forum.dotclear.org/viewtopic.php?id=42875) + +## CONTRIBUTORS + + * Osku (author) + * Pierre Van Glabeke + * Jean-Christian Denis + + You are welcome to contribute to this code. diff --git a/_admin.php b/_admin.php index 4f064f2..cecc92e 100644 --- a/_admin.php +++ b/_admin.php @@ -1,47 +1,41 @@ blog->settings->addNamespace('construction'); -$menu_class = ''; - -if (dcCore::app()->blog->settings->construction->construction_flag) -{ - dcCore::app()->addBehavior('adminPageHTMLHead','constructionadminPageHTMLHead'); - $menu_class = 'construction-blog'; +/** + * @brief construction, a plugin for Dotclear 2 + * + * @package Dotclear + * @subpackage Plugin + * + * @author Osku and contributors + * + * @copyright Jean-Christian Denis + * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html + */ +if (!defined('DC_CONTEXT_ADMIN')) { + return null; } -$_menu['Blog']->addItem(__('Construction'), - 'plugin.php?p=construction','index.php?pf=construction/icon.png', - preg_match('/plugin.php\?p=construction(&.*)?$/',$_SERVER['REQUEST_URI']), - dcCore::app()->auth->check('admin',dcCore::app()->blog->id), - $menu_class +dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( + __('Construction'), + dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), + urldecode(dcPage::getPF(basename(__DIR__) . '/icon.png')), + preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__))) . '(&.*)?$/', $_SERVER['REQUEST_URI']), + dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]), dcCore::app()->blog->id), + dcCore::app()->blog->settings->get(basename(__DIR__))->get('flag') ? 'construction-blog' : '' ); -function constructionadminPageHTMLHead() -{ - echo ''."\n"; -} - -dcCore::app()->addBehavior('adminDashboardFavorites','constructionDashboardFavorites'); - -function constructionDashboardFavorites($core,$favs) -{ - $favs->register('construction', array( - 'title' => __('Construction'), - 'url' => 'plugin.php?p=construction', - 'small-icon' => 'index.php?pf=construction/icon.png', - 'large-icon' => 'index.php?pf=construction/icon-big.png', - 'permissions' => 'usage,contentadmin' - )); -} \ No newline at end of file +dcCore::app()->addBehaviors([ + 'adminPageHTMLHead' => function () { + if (dcCore::app()->blog->settings->get(basename(__DIR__))->get('flag')) { + echo dcPage::cssModuleLoad(basename(__DIR__) . '/css/admin.css'); + } + }, + 'adminDashboardFavoritesV2' => function (dcFavorites $favs) { + $favs->register(basename(__DIR__), [ + 'title' => __('Construction'), + 'url' => dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)), + 'small-icon' => urldecode(dcPage::getPF(basename(__DIR__) . '/icon.png')), + 'large-icon' => urldecode(dcPage::getPF(basename(__DIR__) . '/icon-big.png')), + 'permissions' => dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_ADMIN]), + ]); + }, +]); diff --git a/_define.php b/_define.php index e98f22e..c5fdb56 100644 --- a/_define.php +++ b/_define.php @@ -1,29 +1,33 @@ registerModule( - /* Name */ "Construction", - /* Description*/ "Place your blog maintenance", - /* Author */ "Osku and contributors", - /* Version */ '1.4', - /* Properties */ - array( - 'permissions' => 'admin', - 'priority' => 2000, - 'type' => 'plugin', - 'dc_min' => '2.24', - 'support' => 'http://forum.dotclear.org/viewtopic.php?id=42875', - 'details' => 'http://plugins.dotaddict.org/dc2/details/construction' - ) -); \ No newline at end of file + 'Construction', + 'Place your blog maintenance', + 'Osku and contributors', + '1.5', + [ + 'requires' => [['core', '2.24']], + 'permissions' => dcCore::app()->auth->makePermissions([ + dcAuth::PERMISSION_ADMIN, + ]), + 'priority' => 2000, + 'type' => 'plugin', + 'support' => 'http://forum.dotclear.org/viewtopic.php?id=42875', + 'details' => 'https://plugins.dotaddict.org/dc2/details/' . basename(__DIR__), + 'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml', + ] +); diff --git a/_install.php b/_install.php index ac8ff91..90c3e9b 100644 --- a/_install.php +++ b/_install.php @@ -1,67 +1,78 @@ plugins->moduleInfo('construction','version'); - -$current_version = dcCore::app()->getVersion('construction'); - -if (version_compare($current_version,$new_version,'>=')) { - return; +/** + * @brief construction, a plugin for Dotclear 2 + * + * @package Dotclear + * @subpackage Plugin + * + * @author Osku and contributors + * + * @copyright Jean-Christian Denis + * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html + */ +if (!defined('DC_CONTEXT_ADMIN')) { + return null; } -dcCore::app()->blog->settings->addNamespace('construction'); -$s =& dcCore::app()->blog->settings->construction; +try { + // Version + if (!dcCore::app()->newVersion( + basename(__DIR__), + dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') + )) { + return null; + } -$s->put('construction_flag', - false, - 'boolean', - 'Construction blog flag', - true, - true -); + $s = dcCore::app()->blog->settings->get(basename(__DIR__)); -$s->put('construction_allowed_ip', - serialize(array('127.0.0.1')), - 'string', - 'Construction blog allowed ip', - true, - true -); + $s->put( + 'flag', + false, + 'boolean', + 'Construction blog flag', + false, + true + ); -$s->put('construction_title', - __('Work in progress'), - 'string', - 'Construction blog title', - true, - true -); + $s->put( + 'allowed_ip', + json_encode(['127.0.0.1']), + 'string', + 'Construction blog allowed ip', + false, + true + ); -$s->put('construction_message', - __('
The blog is currently under construction.
'), - 'string', - 'Construction blog message', - true, - true -); + $s->put( + 'title', + __('Work in progress'), + 'string', + 'Construction blog title', + false, + true + ); -$s->put('construction_extra_urls', - serialize(array()), - 'string', - 'Construction blog message', - true, - true -); + $s->put( + 'message', + __('The blog is currently under construction.
'), + 'string', + 'Construction blog message', + false, + true + ); -dcCore::app()->setVersion('construction',$new_version); -return true; \ No newline at end of file + $s->put( + 'extra_urls', + json_encode([]), + 'string', + 'Construction blog message', + false, + true + ); + + return true; +} catch (Exception $e) { + dcCore::app()->error->add($e->getMessage()); +} + +return false; diff --git a/_prepend.php b/_prepend.php deleted file mode 100644 index 39c6412..0000000 --- a/_prepend.php +++ /dev/null @@ -1,15 +0,0 @@ -blog->settings->construction->construction_flag) -{ - dcCore::app()->addBehavior('publicBeforeDocument',array('publicBehaviorsConstruction','checkVisitor')); +/** + * @brief construction, a plugin for Dotclear 2 + * + * @package Dotclear + * @subpackage Plugin + * + * @author Osku and contributors + * + * @copyright Jean-Christian Denis + * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html + */ +if (!defined('DC_RC_PATH')) { + return null; } -dcCore::app()->tpl->addValue('ConstructionMessage',array('tplConstruction','ConstructionMessage')); -dcCore::app()->tpl->addValue('ConstructionTitle',array('tplConstruction','ConstructionTitle')); +dcCore::app()->addBehavior('publicBeforeDocument', function () { + if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('flag')) { + return; + } -class publicBehaviorsConstruction -{ - public static function checkVisitor($core) - { - $tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->system->theme,'tplset'); - if (!empty($tplset) && is_dir(dirname(__FILE__).'/default-templates/'.$tplset)) { - dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), dirname(__FILE__).'/default-templates/'.$tplset); - } else { - dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), dirname(__FILE__).'/default-templates/'.DC_DEFAULT_TPLSET); + $tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->get('system')->get('theme'), 'tplset'); + if (!empty($tplset) && is_dir(implode(DIRECTORY_SEPARATOR, [__DIR__, 'default-templates', $tplset]))) { + dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), implode(DIRECTORY_SEPARATOR, [__DIR__, 'default-templates', $tplset])); + } else { + dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), implode(DIRECTORY_SEPARATOR, [__DIR__, 'default-templates', DC_DEFAULT_TPLSET])); + } + + $all_allowed_ip = json_decode(dcCore::app()->blog->settings->get(basename(__DIR__))->get('allowed_ip'), true); + if (!is_array($all_allowed_ip)) { + $all_allowed_ip = []; + } + $extra_urls = json_decode(dcCore::app()->blog->settings->get(basename(__DIR__))->get('extra_urls'), true); + if (!in_array(http::realIP(), $all_allowed_ip)) { + dcCore::app()->url->registerDefault(function ($args) { + dcCore::app()->url->type = 'default'; + + throw new Exception('Blog under construction', 503); + }); + dcCore::app()->url->registerError(function ($args, $type, $e) { + header('Content-Type: text/html; charset=UTF-8'); + http::head(503, 'Service Unavailable'); + dcCore::app()->url->type = '503'; + dcCore::app()->ctx->__set('current_tpl', '503.html'); + dcCore::app()->ctx->__set('content_type', 'text/html'); + + echo dcCore::app()->tpl->getData(dcCore::app()->ctx->__get('current_tpl')); + + # --BEHAVIOR-- publicAfterDocument + dcCore::app()->callBehavior('publicAfterDocumentV2'); + exit; + }); + + foreach (dcCore::app()->url->getTypes() as $k => $v) { + if (($k != 'contactme') && !in_array($k, $extra_urls)) { + dcCore::app()->url->register($k, $v['url'], $v['representation'], function () { + throw new Exception('Blog under construction', 503); + }); + } } - $all_allowed_ip = unserialize(dcCore::app()->blog->settings->construction->construction_allowed_ip); - $extra_urls = unserialize(dcCore::app()->blog->settings->construction->construction_extra_urls); - if (!in_array(http::realIP(),$all_allowed_ip)) - { - dcCore::app()->url->registerDefault(array('urlConstruction','constructionHandler')); - dcCore::app()->url->registerError(array('urlConstruction','default503')); - - foreach (dcCore::app()->url->getTypes() as $k=>$v) - { - if (($k != 'contactme') && !in_array($k,$extra_urls)) - { - dcCore::app()->url->register($k,$v['url'],$v['representation'],array('urlConstruction','p503')); - } - } + } +}); - } - } -} - -class urlConstruction extends dcUrlHandlers -{ - public static function p503() - { - throw new Exception ("Blog under construction",503); - } - - public static function default503($args,$type,$e) - { - //if ($e->getCode() == 503) { - $_ctx =& $GLOBALS['_ctx']; - $core =& $GLOBALS['core']; - - header('Content-Type: text/html; charset=UTF-8'); - http::head(503,'Service Unavailable'); - dcCore::app()->url->type = '503'; - $_ctx->current_tpl = '503.html'; - $_ctx->content_type = 'text/html'; - - echo dcCore::app()->tpl->getData($_ctx->current_tpl); - - # --BEHAVIOR-- publicAfterDocument - dcCore::app()->callBehavior('publicAfterDocument',$core); - exit; - //} - } - - public static function constructionHandler($args) - { - $core =& $GLOBALS['core']; - dcCore::app()->url->type = 'default'; - self::p503(); - return; - } -} - -class tplConstruction -{ - public static function ConstructionMessage($attr) - { - $core =& $GLOBALS['core']; - $f = dcCore::app()->tpl->getFilters($attr); - return 'blog->settings->construction->construction_message').'; ?>'; - } - - public static function ConstructionTitle($attr) - { - $core =& $GLOBALS['core']; - $f = dcCore::app()->tpl->getFilters($attr); - return 'blog->settings->construction->construction_title').'; ?>'; - } -} \ No newline at end of file +dcCore::app()->tpl->addValue('ConstructionMessage', function ($attr) { + return 'tpl->getFilters($attr), + 'dcCore::app()->blog->settings->get("' . basename(__DIR__) . '")->get("message")' + ) . '; ?>'; +}); +dcCore::app()->tpl->addValue('ConstructionTitle', function ($attr) { + return 'tpl->getFilters($attr), + 'dcCore::app()->blog->settings->get("' . basename(__DIR__) . '")->get("title")' + ) . '; ?>'; +}); diff --git a/dcstore.xml b/dcstore.xml new file mode 100644 index 0000000..83a9919 --- /dev/null +++ b/dcstore.xml @@ -0,0 +1,13 @@ + +Le blog est actuellement en construction.
'; - -#index.php:94 -$GLOBALS['__l10n']['Configuration'] = 'Configuration'; - -#index.php:99 -$GLOBALS['__l10n']['Allowed IP:'] = 'IP autorisées :'; - -#index.php:102 -$GLOBALS['__l10n']['Your IP is %s - the allowed IP can view the blog normally.'] = 'Votre IP est %s - les IP autorisées peuvent visualiser le blog normalement.'; - -#index.php:103 -$GLOBALS['__l10n']['Extra allowed URL types:'] = 'Autres types d\'URL autorisées :'; - -#index.php:108 -$GLOBALS['__l10n']['Presentation'] = 'Présentation'; - -#index.php:112 -$GLOBALS['__l10n']['Message:'] = 'Message :'; - -$GLOBALS['__l10n']['Place your blog maintenance'] = 'Mettez votre blog en maintenance'; - -$GLOBALS['__l10n']['construction'] = 'construction'; +/** + * @package Dotclear + * + * @copyright Olivier Meunier & Association Dotclear + * @copyright GPL-2.0-only + */ +# +# DOT NOT MODIFY THIS FILE ! +# +l10n::$locales['Construction'] = 'Construction'; +l10n::$locales['Work in progress'] = 'Travaux en cours'; +l10n::$locales['The blog is currently under construction.
'] = 'Le blog est actuellement en construction.
'; +l10n::$locales['Settings successfully updated.'] = 'Paramètres mis à jour.'; +l10n::$locales['Configuration'] = 'Configuration'; +l10n::$locales['Allowed IP:'] = 'IP autorisées :'; +l10n::$locales['Your IP is %s - the allowed IP can view the blog normally.'] = 'Votre IP est %s - les IP autorisées peuvent visualiser le blog normalement.'; +l10n::$locales['Extra allowed URL types:'] = 'Autres types d\'URL autorisées :'; +l10n::$locales['Presentation'] = 'Présentation'; +l10n::$locales['Message:'] = 'Message :'; +l10n::$locales['Place your blog maintenance'] = 'Mettez votre blog en maintenance'; diff --git a/locales/fr/main.po b/locales/fr/main.po index 9a19641..12876f1 100644 --- a/locales/fr/main.po +++ b/locales/fr/main.po @@ -1,61 +1,45 @@ -# Language: Français -# Module: construction - 1.3.1 -# Date: 2018-02-18 16:09:52 -# Translated with translater 2018.02.14 - msgid "" msgstr "" "Content-Type: text/plain; charset=UTF-8\n" -"Project-Id-Version: construction 1.3.1\n" +"Project-Id-Version: construction 1.5\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2018-02-18T16:09:52+00:00\n" -"Last-Translator: brol\n" +"PO-Revision-Date: 2022-12-31T18:01:51+00:00\n" +"Last-Translator: Jean-Christian Denis\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: _admin.php:24 -#: _admin.php:41 -#: index.php:15 msgid "Construction" msgstr "Construction" -#: _install.php:43 msgid "Work in progress" msgstr "Travaux en cours" -#: _install.php:51 msgid "The blog is currently under construction.
" msgstr "Le blog est actuellement en construction.
" -#: index.php:94 +msgid "Settings successfully updated." +msgstr "Paramètres mis à jour." + msgid "Configuration" msgstr "Configuration" -#: index.php:99 msgid "Allowed IP:" msgstr "IP autorisées :" -#: index.php:102 msgid "Your IP is %s - the allowed IP can view the blog normally." msgstr "Votre IP est %s - les IP autorisées peuvent visualiser le blog normalement." -#: index.php:103 msgid "Extra allowed URL types:" msgstr "Autres types d'URL autorisées :" -#: index.php:108 msgid "Presentation" msgstr "Présentation" -#: index.php:112 msgid "Message:" msgstr "Message :" msgid "Place your blog maintenance" msgstr "Mettez votre blog en maintenance" -msgid "construction" -msgstr "construction" -