Compare commits
No commits in common. "dc477014c7a0ee3ea8d6b67f9d1a9eedf6ab5269" and "f3457039cb10e8bb60dd8976fb6077997cb262fd" have entirely different histories.
dc477014c7
...
f3457039cb
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -1,16 +1,3 @@
|
|||
todo
|
||||
* disable widgets
|
||||
|
||||
1.7 - 2023.05.13
|
||||
* require dotclear 2.26
|
||||
* fix editor ID
|
||||
* fix nullsafe warnings
|
||||
* add plugin Unnistaller features
|
||||
|
||||
1.6 - 2023.04.10
|
||||
* require dotclear 2.26
|
||||
* use namespace
|
||||
|
||||
1.5 - 2022.12.31
|
||||
* update to dotclear 2.24
|
||||
* use json intead of serialize
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[![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.26-blue.svg)](https://fr.dotclear.org/download)
|
||||
[![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)
|
||||
|
||||
|
@ -20,7 +20,7 @@ Blog can be accessible to defined IP addresses.
|
|||
_construction_ requires:
|
||||
|
||||
* admin permissions on blog
|
||||
* Dotclear 2.26
|
||||
* Dotclear 2.24
|
||||
|
||||
## USAGE
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* @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()->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' : ''
|
||||
);
|
||||
|
||||
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]),
|
||||
]);
|
||||
},
|
||||
]);
|
|
@ -18,9 +18,9 @@ $this->registerModule(
|
|||
'Construction',
|
||||
'Place your blog maintenance',
|
||||
'Osku and contributors',
|
||||
'1.7',
|
||||
'1.5',
|
||||
[
|
||||
'requires' => [['core', '2.26']],
|
||||
'requires' => [['core', '2.24']],
|
||||
'permissions' => dcCore::app()->auth->makePermissions([
|
||||
dcAuth::PERMISSION_ADMIN,
|
||||
]),
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
try {
|
||||
// Version
|
||||
if (!dcCore::app()->newVersion(
|
||||
basename(__DIR__),
|
||||
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
|
||||
)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$s = dcCore::app()->blog->settings->get(basename(__DIR__));
|
||||
|
||||
$s->put(
|
||||
'flag',
|
||||
false,
|
||||
'boolean',
|
||||
'Construction blog flag',
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$s->put(
|
||||
'allowed_ip',
|
||||
json_encode(['127.0.0.1']),
|
||||
'string',
|
||||
'Construction blog allowed ip',
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$s->put(
|
||||
'title',
|
||||
__('Work in progress'),
|
||||
'string',
|
||||
'Construction blog title',
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$s->put(
|
||||
'message',
|
||||
__('<p>The blog is currently under construction.</p>'),
|
||||
'string',
|
||||
'Construction blog message',
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$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;
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/**
|
||||
* @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()->addBehavior('publicBeforeDocument', function () {
|
||||
if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('flag')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dcCore::app()->tpl->addValue('ConstructionMessage', function ($attr) {
|
||||
return '<?php echo ' . sprintf(
|
||||
dcCore::app()->tpl->getFilters($attr),
|
||||
'dcCore::app()->blog->settings->get("' . basename(__DIR__) . '")->get("message")'
|
||||
) . '; ?>';
|
||||
});
|
||||
dcCore::app()->tpl->addValue('ConstructionTitle', function ($attr) {
|
||||
return '<?php echo ' . sprintf(
|
||||
dcCore::app()->tpl->getFilters($attr),
|
||||
'dcCore::app()->blog->settings->get("' . basename(__DIR__) . '")->get("title")'
|
||||
) . '; ?>';
|
||||
});
|
|
@ -2,11 +2,11 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="construction">
|
||||
<name>Construction</name>
|
||||
<version>1.7</version>
|
||||
<version>1.5</version>
|
||||
<author>Osku and contributors</author>
|
||||
<desc>Place your blog maintenance</desc>
|
||||
<file>https://github.com/JcDenis/construction/releases/download/v1.7/plugin-construction.zip</file>
|
||||
<da:dcmin>2.26</da:dcmin>
|
||||
<file>https://github.com/JcDenis/construction/releases/download/v1.5/plugin-construction.zip</file>
|
||||
<da:dcmin>2.24</da:dcmin>
|
||||
<da:details>https://plugins.dotaddict.org/dc2/details/construction</da:details>
|
||||
<da:support>http://forum.dotclear.org/viewtopic.php?id=42875</da:support>
|
||||
</module>
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
2
icon.svg
2
icon.svg
|
@ -1,2 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg width="64px" height="64px" viewBox="0 0 36 36" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--twemoji" preserveAspectRatio="xMidYMid meet"><path fill="#FFCC4D" d="M36 15a4 4 0 0 1-4 4H4a4 4 0 0 1-4-4V7a4 4 0 0 1 4-4h28a4 4 0 0 1 4 4v8z"></path><path d="M6 3H4a4 4 0 0 0-4 4v2l6-6zm6 0L0 15c0 1.36.682 2.558 1.72 3.28L17 3h-5zM7 19h5L28 3h-5zm16 0L35.892 6.108A3.995 3.995 0 0 0 33.64 3.36L18 19h5zm13-4v-3l-7 7h3a4 4 0 0 0 4-4z" fill="#292F33"></path><path fill="#99AAB5" d="M4 19h5v14H4zm23 0h5v14h-5z"></path></svg>
|
Before Width: | Height: | Size: 646 B |
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
dcPage::check(dcCore::app()->auth->makePermissions([
|
||||
dcAuth::PERMISSION_ADMIN,
|
||||
]));
|
||||
|
||||
$s = dcCore::app()->blog->settings->get(basename(__DIR__));
|
||||
|
||||
if (!empty($_POST['saveconfig'])) {
|
||||
try {
|
||||
$allowed_ip = [];
|
||||
foreach (explode("\n", $_POST['construction_allowed_ip']) as $ip) {
|
||||
$allowed_ip[] = trim($ip);
|
||||
}
|
||||
$extra_urls = [];
|
||||
foreach (explode(',', $_POST['construction_extra_urls']) as $url) {
|
||||
$extra_urls[] = trim($url);
|
||||
}
|
||||
|
||||
$s->put('flag', empty($_POST['construction_flag']) ? false : true);
|
||||
$s->put('allowed_ip', json_encode($allowed_ip));
|
||||
$s->put('title', $_POST['construction_title']);
|
||||
$s->put('message', $_POST['construction_message']);
|
||||
$s->put('extra_urls', json_encode($extra_urls));
|
||||
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
|
||||
dcAdminNotices::addSuccessNotice(
|
||||
__('Settings successfully updated.')
|
||||
);
|
||||
|
||||
dcCore::app()->adminurl->redirect(
|
||||
'admin.plugin.' . basename(__DIR__)
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$nb_rows = count(json_decode($s->get('allowed_ip'), true));
|
||||
if ($nb_rows < 2) {
|
||||
$nb_rows = 2;
|
||||
} elseif ($nb_rows > 10) {
|
||||
$nb_rows = 10;
|
||||
}
|
||||
|
||||
$editor = dcCore::app()->auth->getOption('editor');
|
||||
|
||||
echo '
|
||||
<html><head><title>' . __('Construction') . '</title>' .
|
||||
dcPage::jsConfirmClose('opts-forms') .
|
||||
dcCore::app()->callBehavior('adminPostEditor', $editor['xhtml'], 'construction', ['#construction_message'], 'xhtml') .
|
||||
dcPage::jsModuleLoad(basename(__DIR__) . '/js/index.js') . '
|
||||
</head><body>' .
|
||||
|
||||
dcPage::breadcrumb([
|
||||
__('Plugins') => '',
|
||||
__('Construction') => '',
|
||||
]) .
|
||||
dcPage::notices() . '
|
||||
|
||||
<div id="construction_options">
|
||||
<form method="post" action="' . dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__)) . '">
|
||||
<div class="fieldset">
|
||||
<h4>' . __('Configuration') . '</h4>
|
||||
|
||||
<p class="field">' .
|
||||
form::checkbox('construction_flag', 1, $s->get('flag')) . '
|
||||
<label class="classic" for="construction_flag">' . __('Plugin activation') . '</label>
|
||||
</p>
|
||||
|
||||
<p><label for="construction_allowed_ip">' . __('Allowed IP:') . '</label> ' .
|
||||
form::textarea('construction_allowed_ip', 20, $nb_rows, html::escapeHTML(implode("\n", json_decode($s->get('allowed_ip'), true)))) .
|
||||
'</p>
|
||||
<p class="form-note">' . sprintf(__('Your IP is <strong>%s</strong> - the allowed IP can view the blog normally.'), (string) http::realIP()) . '</p>
|
||||
|
||||
<p class="area"><label for="construction_extra_urls">' . __('Extra allowed URL types:') . '</label>' .
|
||||
form::field('construction_extra_urls', 20, 255, html::escapeHTML(implode(',', json_decode($s->get('extra_urls'), true))), 'maximal') .
|
||||
'</p>
|
||||
|
||||
</div>
|
||||
<div class="fieldset">
|
||||
<h4>' . __('Presentation') . '</h4>
|
||||
<p class="area"><label for="construction_title">' . __('Title:') . '</label>' .
|
||||
form::field('construction_title', 20, 255, html::escapeHTML($s->get('title')), 'maximal') .
|
||||
'</p>
|
||||
|
||||
<p class="area"><label for="construction_message">' . __('Message:') . '</label>' .
|
||||
form::textarea('construction_message', 40, 10, html::escapeHTML($s->get('message'))) .
|
||||
'</p>
|
||||
</div>
|
||||
<p>' .
|
||||
form::hidden(['p'], 'construction') .
|
||||
dcCore::app()->formNonce() . '
|
||||
<input type="submit" name="saveconfig" value="' . __('Save') . '" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>';
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
$(() => {
|
||||
if (typeof jsToolBar === 'function') {
|
||||
$('#construction_message').each(function () {
|
||||
$('#disclaimer_text').each(function () {
|
||||
const tbWidgetTextDisclaimer = new jsToolBar(this);
|
||||
tbWidgetTextDisclaimer.context = 'construction_message';
|
||||
tbWidgetTextDisclaimer.context = 'disclaimer_text';
|
||||
tbWidgetTextDisclaimer.draw('xhtml');
|
||||
});
|
||||
}
|
|
@ -9,16 +9,14 @@
|
|||
# DOT NOT MODIFY THIS FILE !
|
||||
#
|
||||
|
||||
use Dotclear\Helper\L10n;
|
||||
|
||||
L10n::$locales['Construction'] = 'Construction';
|
||||
L10n::$locales['Work in progress'] = 'Travaux en cours';
|
||||
L10n::$locales['<p>The blog is currently under construction.</p>'] = '<p>Le blog est actuellement en construction.</p>';
|
||||
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 <strong>%s</strong> - the allowed IP can view the blog normally.'] = 'Votre IP est <strong>%s</strong> - 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';
|
||||
l10n::$locales['Construction'] = 'Construction';
|
||||
l10n::$locales['Work in progress'] = 'Travaux en cours';
|
||||
l10n::$locales['<p>The blog is currently under construction.</p>'] = '<p>Le blog est actuellement en construction.</p>';
|
||||
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 <strong>%s</strong> - the allowed IP can view the blog normally.'] = 'Votre IP est <strong>%s</strong> - 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';
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\construction;
|
||||
|
||||
use dcAdmin;
|
||||
use dcCore;
|
||||
use dcPage;
|
||||
use dcFavorites;
|
||||
use dcNsProcess;
|
||||
|
||||
class Backend extends dcNsProcess
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) // nullsafe PHP < 8.0
|
||||
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
||||
]), dcCore::app()->blog->id);
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
||||
My::name(),
|
||||
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
||||
dcPage::getPF(My::id() . '/icon.svg'),
|
||||
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
||||
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_ADMIN]), dcCore::app()->blog->id),
|
||||
dcCore::app()->blog->settings->get(My::id())->get('flag') ? 'construction-blog' : ''
|
||||
);
|
||||
|
||||
dcCore::app()->addBehaviors([
|
||||
'adminPageHTMLHead' => function (): void {
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
if (dcCore::app()->blog->settings->get(My::id())->get('flag')) {
|
||||
echo dcPage::cssModuleLoad(My::id() . '/css/backend.css');
|
||||
}
|
||||
},
|
||||
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) {
|
||||
return;
|
||||
}
|
||||
$favs->register(My::id(), [
|
||||
'title' => My::name(),
|
||||
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
||||
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
'permissions' => dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_ADMIN]),
|
||||
]);
|
||||
},
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
110
src/Frontend.php
110
src/Frontend.php
|
@ -1,110 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\construction;
|
||||
|
||||
use ArrayObject;
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Helper\Network\Http;
|
||||
use Exception;
|
||||
|
||||
class Frontend extends dcNsProcess
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_RC_PATH');
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dcCore::app()->addBehavior('publicBeforeDocument', function (): void {
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dcCore::app()->blog->settings->get(My::id())->get('flag')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->get('system')->get('theme'), 'tplset');
|
||||
if (!empty($tplset) && is_dir(implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]))) {
|
||||
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', $tplset]));
|
||||
} else {
|
||||
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), implode(DIRECTORY_SEPARATOR, [My::path(), 'default-templates', DC_DEFAULT_TPLSET]));
|
||||
}
|
||||
|
||||
$all_allowed_ip = json_decode(dcCore::app()->blog->settings->get(My::id())->get('allowed_ip'), true);
|
||||
if (!is_array($all_allowed_ip)) {
|
||||
$all_allowed_ip = [];
|
||||
}
|
||||
$extra_urls = json_decode(dcCore::app()->blog->settings->get(My::id())->get('extra_urls'), true);
|
||||
if (!in_array(Http::realIP(), $all_allowed_ip)) {
|
||||
dcCore::app()->url->registerDefault(function (?string $args): void {
|
||||
dcCore::app()->url->type = 'default';
|
||||
|
||||
throw new Exception('Blog under construction', 503);
|
||||
});
|
||||
dcCore::app()->url->registerError(function (?string $args, ?string $type, Exception $e): void {
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->ctx)) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dcCore::app()->tpl->addValue('ConstructionMessage', function (ArrayObject $attr): string {
|
||||
return '<?php echo ' . sprintf(
|
||||
dcCore::app()->tpl->getFilters($attr),
|
||||
'dcCore::app()->blog->settings->get("' . My::id() . '")->get("message")'
|
||||
) . '; ?>';
|
||||
});
|
||||
dcCore::app()->tpl->addValue('ConstructionTitle', function (ArrayObject $attr): string {
|
||||
return '<?php echo ' . sprintf(
|
||||
dcCore::app()->tpl->getFilters($attr),
|
||||
'dcCore::app()->blog->settings->get("' . My::id() . '")->get("title")'
|
||||
) . '; ?>';
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\construction;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Exception;
|
||||
|
||||
class Install extends dcNsProcess
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
|
||||
$s->put(
|
||||
'flag',
|
||||
false,
|
||||
'boolean',
|
||||
'Construction blog flag',
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$s->put(
|
||||
'allowed_ip',
|
||||
json_encode(['127.0.0.1']),
|
||||
'string',
|
||||
'Construction blog allowed ip',
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$s->put(
|
||||
'title',
|
||||
__('Work in progress'),
|
||||
'string',
|
||||
'Construction blog title',
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$s->put(
|
||||
'message',
|
||||
__('<p>The blog is currently under construction.</p>'),
|
||||
'string',
|
||||
'Construction blog message',
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$s->put(
|
||||
'extra_urls',
|
||||
json_encode([]),
|
||||
'string',
|
||||
'Construction blog message',
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
171
src/Manage.php
171
src/Manage.php
|
@ -1,171 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\construction;
|
||||
|
||||
use dcAuth;
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use dcPage;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Checkbox,
|
||||
Div,
|
||||
Form,
|
||||
Hidden,
|
||||
Input,
|
||||
Label,
|
||||
Note,
|
||||
Para,
|
||||
Submit,
|
||||
Text,
|
||||
Textarea
|
||||
};
|
||||
use Dotclear\Helper\Html\Html;
|
||||
use Dotclear\Helper\Network\Http;
|
||||
use Exception;
|
||||
|
||||
class Manage extends dcNsProcess
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog) // nullsafe PHP < 8.0
|
||||
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
||||
dcAuth::PERMISSION_CONTENT_ADMIN,
|
||||
]), dcCore::app()->blog->id);
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
|
||||
if (!empty($_POST['saveconfig'])) {
|
||||
try {
|
||||
$allowed_ip = [];
|
||||
foreach (explode("\n", $_POST['construction_allowed_ip']) as $ip) {
|
||||
$allowed_ip[] = trim($ip);
|
||||
}
|
||||
$extra_urls = [];
|
||||
foreach (explode(',', $_POST['construction_extra_urls']) as $url) {
|
||||
$extra_urls[] = trim($url);
|
||||
}
|
||||
|
||||
$s->put('flag', !empty($_POST['construction_flag']));
|
||||
$s->put('allowed_ip', json_encode($allowed_ip));
|
||||
$s->put('title', $_POST['construction_title']);
|
||||
$s->put('message', $_POST['construction_message']);
|
||||
$s->put('extra_urls', json_encode($extra_urls));
|
||||
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
|
||||
dcPage::addSuccessNotice(
|
||||
__('Settings successfully updated.')
|
||||
);
|
||||
|
||||
dcCore::app()->adminurl->redirect(
|
||||
'admin.plugin.' . My::id()
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function render(): void
|
||||
{
|
||||
if (!static::$init) {
|
||||
return;
|
||||
}
|
||||
|
||||
// nullsafe PHP < 8.0
|
||||
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
$editor = dcCore::app()->auth->getOption('editor');
|
||||
$nb_rows = count(json_decode($s->get('allowed_ip'), true));
|
||||
if ($nb_rows < 2) {
|
||||
$nb_rows = 2;
|
||||
} elseif ($nb_rows > 10) {
|
||||
$nb_rows = 10;
|
||||
}
|
||||
|
||||
dcPage::openModule(
|
||||
My::name(),
|
||||
dcPage::jsConfirmClose('opts-forms') .
|
||||
dcCore::app()->callBehavior('adminPostEditor', $editor['xhtml'], 'construction', ['#construction_message'], 'xhtml') .
|
||||
dcPage::jsModuleLoad(My::id() . '/js/backend.js')
|
||||
);
|
||||
|
||||
echo
|
||||
dcPage::breadcrumb([
|
||||
__('Plugins') => '',
|
||||
My::name() => '',
|
||||
]) .
|
||||
dcPage::notices() .
|
||||
|
||||
(new Div())->id('construction_options')->items([
|
||||
(new Form(My::id() . 'form'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->fields([
|
||||
(new Div())->class('fieldset')->items([
|
||||
(new Text('h4', __('Configuration'))),
|
||||
(new Para())->class('filed')->items([
|
||||
(new Checkbox('construction_flag', (bool) $s->get('flag')))->value(1),
|
||||
(new Label(__('Plugin activation'), Label::OUTSIDE_LABEL_AFTER))->for('construction_flag')->class('classic'),
|
||||
]),
|
||||
(new Para())->items([
|
||||
(new Label(__('Allowed IP:'), Label::OUTSIDE_LABEL_BEFORE))->for('construction_allowed_ip'),
|
||||
(new Textarea('construction_allowed_ip', Html::escapeHTML(implode("\n", json_decode($s->get('allowed_ip'), true)))))->cols(20)->rows($nb_rows),
|
||||
]),
|
||||
(new Note())->class('form-note')->text(sprintf(__('Your IP is <strong>%s</strong> - the allowed IP can view the blog normally.'), (string) Http::realIP())),
|
||||
(new Para())->class('area')->items([
|
||||
(new Label(__('Extra allowed URL types:'), Label::OUTSIDE_LABEL_BEFORE))->for('construction_extra_urls'),
|
||||
(new Input('construction_extra_urls'))->size(20)->maxlenght(255)->class('maximal')->value(Html::escapeHTML(implode(',', json_decode($s->get('extra_urls'), true)))),
|
||||
]),
|
||||
]),
|
||||
(new Div())->class('fieldset')->items([
|
||||
(new Text('h4', __('Presentation'))),
|
||||
(new Para())->class('area')->items([
|
||||
(new Label(__('Title:'), Label::OUTSIDE_LABEL_BEFORE))->for('construction_title'),
|
||||
(new Input('construction_title'))->size(20)->maxlenght(255)->class('maximal')->value(Html::escapeHTML($s->get('title'))),
|
||||
]),
|
||||
(new Para())->class('area')->items([
|
||||
(new Label(__('Message:'), Label::OUTSIDE_LABEL_BEFORE))->for('construction_message'),
|
||||
(new Textarea('construction_message', Html::escapeHTML($s->get('message'))))->cols(40)->rows(10),
|
||||
]),
|
||||
]),
|
||||
(new Para())->items([
|
||||
dcCore::app()->formNonce(false),
|
||||
(new Hidden(['p'], 'construction')),
|
||||
(new Submit(['saveconfig']))->value(__('Save')),
|
||||
]),
|
||||
]),
|
||||
])->render();
|
||||
|
||||
dcPage::closeModule();
|
||||
}
|
||||
}
|
49
src/My.php
49
src/My.php
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\construction;
|
||||
|
||||
use dcCore;
|
||||
|
||||
/**
|
||||
* This module definitions.
|
||||
*/
|
||||
class My
|
||||
{
|
||||
/**
|
||||
* This module id.
|
||||
*/
|
||||
public static function id(): string
|
||||
{
|
||||
return basename(dirname(__DIR__));
|
||||
}
|
||||
|
||||
/**
|
||||
* This module name.
|
||||
*/
|
||||
public static function name(): string
|
||||
{
|
||||
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
|
||||
|
||||
return __(is_string($name) ? $name : self::id());
|
||||
}
|
||||
|
||||
/**
|
||||
* This module path.
|
||||
*/
|
||||
public static function path(): string
|
||||
{
|
||||
return dirname(__DIR__);
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\construction;
|
||||
|
||||
use dcCore;
|
||||
use dcNsProcess;
|
||||
use Dotclear\Plugin\Uninstaller\Uninstaller;
|
||||
|
||||
class Uninstall extends dcNsProcess
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN');
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init || !dcCore::app()->plugins->moduleExists('Uninstaller')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Uninstaller::instance()
|
||||
->addUserAction(
|
||||
'settings',
|
||||
'delete_all',
|
||||
My::id()
|
||||
)
|
||||
->addUserAction(
|
||||
'plugins',
|
||||
'delete',
|
||||
My::id()
|
||||
)
|
||||
->addUserAction(
|
||||
'versions',
|
||||
'delete',
|
||||
My::id()
|
||||
)
|
||||
->addDirectAction(
|
||||
'settings',
|
||||
'delete_all',
|
||||
My::id()
|
||||
)
|
||||
->addDirectAction(
|
||||
'plugins',
|
||||
'delete',
|
||||
My::id()
|
||||
)
|
||||
->addDirectAction(
|
||||
'versions',
|
||||
'delete',
|
||||
My::id()
|
||||
)
|
||||
;
|
||||
|
||||
// no custom action
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue