construction/index.php

116 lines
3.6 KiB
PHP
Raw Normal View History

2022-12-30 16:52:56 +00:00
<?php
2022-12-31 18:07:05 +00:00
/**
* @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);
2022-12-30 16:52:56 +00:00
}
2022-12-31 18:07:05 +00:00
$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());
}
2022-12-30 16:52:56 +00:00
}
2022-12-31 18:07:05 +00:00
$nb_rows = count(json_decode($s->get('allowed_ip'), true));
2022-12-30 16:52:56 +00:00
if ($nb_rows < 2) {
2022-12-31 18:07:05 +00:00
$nb_rows = 2;
2022-12-30 16:52:56 +00:00
} elseif ($nb_rows > 10) {
2022-12-31 18:07:05 +00:00
$nb_rows = 10;
2022-12-30 16:52:56 +00:00
}
2022-12-31 18:07:05 +00:00
$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__)) . '">
2022-12-30 16:52:56 +00:00
<div class="fieldset">
2022-12-31 18:07:05 +00:00
<h4>' . __('Configuration') . '</h4>
<p class="field">' .
form::checkbox('construction_flag', 1, $s->get('flag')) . '
<label class="classic" for="construction_flag">' . __('Plugin activation') . '</label>
2022-12-30 16:52:56 +00:00
</p>
2022-12-31 18:07:05 +00:00
<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)))) .
2022-12-30 16:52:56 +00:00
'</p>
2022-12-31 18:07:05 +00:00
<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') .
2022-12-30 16:52:56 +00:00
'</p>
2022-12-31 18:07:05 +00:00
2022-12-30 16:52:56 +00:00
</div>
<div class="fieldset">
2022-12-31 18:07:05 +00:00
<h4>' . __('Presentation') . '</h4>
<p class="area"><label for="construction_title">' . __('Title:') . '</label>' .
form::field('construction_title', 20, 255, html::escapeHTML($s->get('title')), 'maximal') .
2022-12-30 16:52:56 +00:00
'</p>
2022-12-31 18:07:05 +00:00
<p class="area"><label for="construction_message">' . __('Message:') . '</label>' .
form::textarea('construction_message', 40, 10, html::escapeHTML($s->get('message'))) .
2022-12-30 16:52:56 +00:00
'</p>
</div>
2022-12-31 18:07:05 +00:00
<p>' .
form::hidden(['p'], 'construction') .
dcCore::app()->formNonce() . '
<input type="submit" name="saveconfig" value="' . __('Save') . '" />
2022-12-30 16:52:56 +00:00
</p>
</form>
2022-12-31 18:07:05 +00:00
</div>
2022-12-30 16:52:56 +00:00
</body>
2022-12-31 18:07:05 +00:00
</html>';