release 2023.03.11 for Dotclear 2.25

This commit is contained in:
Jean-Christian Paul Denis 2023-03-11 12:16:12 +01:00
parent 1dca765741
commit c9e3ea8f3f
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
12 changed files with 408 additions and 205 deletions

9
CHANGELOG.md Normal file
View File

@ -0,0 +1,9 @@
2023.03.11
* Update to Dotclear 2.25
* use abstract pligin id
* use php namespace
* use json instead of serialize
* rename settings
2022.11.26
* update to Dotclear 2.24

View File

@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/JcDenis/myUrlHandlers)](https://github.com/JcDenis/myUrlHandlers/releases)
[![Date](https://img.shields.io/github/release-date/JcDenis/myUrlHandlers)](https://github.com/JcDenis/myUrlHandlers/releases)
[![Issues](https://img.shields.io/github/issues/JcDenis/myUrlHandlers)](https://github.com/JcDenis/myUrlHandlers/issues)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.24-blue.svg)](https://fr.dotclear.org/download)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.25-blue.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/myUrlHandlers)
[![License](https://img.shields.io/github/license/JcDenis/myUrlHandlers)](https://github.com/JcDenis/myUrlHandlers/blob/master/LICENSE)

View File

@ -18,9 +18,9 @@ $this->registerModule(
'My URL handlers',
'Change Dotclear URL handlers',
'Alex Pirine and contributors',
'2022.11.26',
'2023.03.11',
[
'requires' => [['core', '2.24']],
'requires' => [['core', '2.25']],
'permissions' => dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
]),

View File

@ -2,12 +2,12 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="myUrlHandlers">
<name>My URL handlers</name>
<version>2022.11.26</version>
<version>2023.03.11</version>
<author>Alex Pirine and contributors</author>
<desc>Change Dotclear URL handlers</desc>
<file>https://github.com/JcDenis/myUrlHandlers/releases/download/v2022.11.26/plugin-myUrlHandlers.zip</file>
<da:dcmin>2.24</da:dcmin>
<file>https://github.com/JcDenis/myUrlHandlers/releases/download/v2023.03.11/plugin-myUrlHandlers.zip</file>
<da:dcmin>2.25</da:dcmin>
<da:details>http://plugins.dotaddict.org/dc2/details/myUrlHandlers</da:details>
<da:support>http://forum.dotclear.org/viewforum.php?id=16</da:support>
<da:support>https://github.com/JcDenis/myUrlHandlers</da:support>
</module>
</modules>

20
locales/fr/main.lang.php Normal file
View File

@ -0,0 +1,20 @@
<?php
/**
* @package Dotclear
*
* @copyright Olivier Meunier & Association Dotclear
* @copyright GPL-2.0-only
*/
#
# DOT NOT MODIFY THIS FILE !
#
l10n::$locales['Uknown handler "%s".'] = 'Le gestionnaire "%s" n\'existe pas.';
l10n::$locales['Invalid URL for handler "%s".'] = 'URL invalide pour le gestionnaire "%s".';
l10n::$locales['Duplicate URL in handlers "%s".'] = 'Doublon d\'URL dans les gestionnaires "%s".';
l10n::$locales['URL handlers have been successfully updated.'] = 'Les gestionnaires d\'URL ont été mis à jour avec succès.';
l10n::$locales['URL handlers have been successfully restored.'] = 'Les gestionnaires d\'URL ont été restaurés avec succès.';
l10n::$locales['No URL handler to configure.'] = 'Il n\'y a aucun gestionnaire d\'URL à définir.';
l10n::$locales['URL handlers list'] = 'Liste des gestionnaires d\'URL';
l10n::$locales['You can write your own URL for each handler of this list.'] = 'Vous pouvez écrire votre propre URL pour chaque gestionnaire de cette liste.';
l10n::$locales['URL handlers'] = 'Gestionnaires d\'URL';

View File

@ -1,18 +1,15 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: myUrlHandlers 2022.11.26\n"
"Project-Id-Version: myUrlHandlers 2023.03.11\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2022-12-09T23:55:36+00:00\n"
"PO-Revision-Date: 2023-03-11T11:13:57+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"
msgid "URL handlers"
msgstr "Gestionnaires d'URL"
msgid "Uknown handler \"%s\"."
msgstr "Le gestionnaire \"%s\" n'existe pas."
@ -31,9 +28,12 @@ msgstr "Les gestionnaires d'URL ont été restaurés avec succès."
msgid "No URL handler to configure."
msgstr "Il n'y a aucun gestionnaire d'URL à définir."
msgid "You can write your own URL for each handler of this list."
msgstr "Vous pouvez écrire votre propre URL pour chaque gestionnaire de cette liste."
msgid "URL handlers list"
msgstr "Liste des gestionnaires d'URL"
msgid "You can write your own URL for each handler of this list."
msgstr "Vous pouvez écrire votre propre URL pour chaque gestionnaire de cette liste."
msgid "URL handlers"
msgstr "Gestionnaires d'URL"

View File

@ -10,24 +10,50 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return;
declare(strict_types=1);
namespace Dotclear\Plugin\myUrlHandlers;
use dcAuth;
use dcAdmin;
use dcCore;
use dcFavorites;
use dcPage;
use dcNsProcess;
class Backend extends dcNsProcess
{
public static function init(): bool
{
self::$init = defined('DC_CONTEXT_ADMIN');
return self::$init;
}
public static function process(): bool
{
if (!self::$init) {
return false;
}
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
__('URL handlers'),
dcCore::app()->adminurl->get('admin.plugin.myUrlHandlers'),
dcPage::getPF('myUrlHandlers/icon.png'),
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.myUrlHandlers')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
My::name(),
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
dcPage::getPF(My::id() . '/icon.png'),
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id)
);
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function ($favs) {
$favs->register('myUrlHandlers', [
'title' => __('URL handlers'),
'url' => dcCore::app()->adminurl->get('admin.plugin.myUrlHandlers'),
'small-icon' => dcPage::getPF('myUrlHandlers/icon.png'),
'large-icon' => dcPage::getPF('myUrlHandlers/icon-big.png'),
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
$favs->register(My::id(), [
'title' => My::name(),
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
'small-icon' => dcPage::getPF(My::id() . '/icon.png'),
'large-icon' => dcPage::getPF(My::id() . '/icon-big.png'),
'permissions' => dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]),
]);
});
return true;
}
}

View File

@ -10,30 +10,64 @@
* @copyright 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);
namespace Dotclear\Plugin\myUrlHandlers;
use dcCore;
use dcNamespace;
use dcNsProcess;
class Install extends dcNsProcess
{
public static function init(): bool
{
self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version'));
return self::$init;
}
try {
if (!dcCore::app()->newVersion(
basename(__DIR__),
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
)) {
return null;
public static function process(): bool
{
if (!self::$init) {
return false;
}
dcCore::app()->blog->settings->addNamespace('myurlhandlers');
dcCore::app()->blog->settings->myurlhandlers->put(
'url_handlers',
'',
self::growUp();
dcCore::app()->blog->settings->get(My::id())->put(
My::NS_SETTING_ID,
json_encode([]),
'string',
'Personalized URL handlers',
false
);
return true;
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
return false;
private static function growUp(): void
{
$current = dcCore::app()->getVersion(My::id());
// Update settings id, ns, value
if ($current && version_compare($current, '2023.03.11', '<')) {
$record = dcCore::app()->con->select(
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
"WHERE setting_ns = 'myurlhandlers' AND setting_id = 'url_handlers' "
);
while ($record->fetch()) {
$value = @unserialize($record->f('setting_value'));
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
$cur->setting_id = My::NS_SETTING_ID;
$cur->setting_ns = My::id();
$cur->setting_value = json_encode(is_array($value) ? $value : []);
$cur->update(
"WHERE setting_id = '" . $record->f('setting_id') . "' and setting_ns = '" . $record->f('setting_ns') . "' " .
'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->f('blog_id')) . "' "))
);
}
}
}
}

View File

@ -10,26 +10,45 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
declare(strict_types=1);
namespace Dotclear\Plugin\myUrlHandlers;
use dcAuth;
use dcCore;
use dcNsProcess;
use dcPage;
use Exception;
use form;
use html;
use text;
/**
* Manage contributions list
*/
class Manage extends dcNsProcess
{
public static function init(): bool
{
if (defined('DC_CONTEXT_ADMIN')) {
dcPage::check(dcCore::app()->auth->makePermissions([
dcAuth::PERMISSION_CONTENT_ADMIN,
]));
self::$init = true;
}
dcPage::check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]));
return self::$init;
}
public static function process(): bool
{
if (!self::$init) {
return false;
}
try {
# Read default handlers
$handlers = myUrlHandlers::getDefaults();
# Overwrite with user settings
$settings = @unserialize(dcCore::app()->blog->settings->myurlhandlers->url_handlers);
if (is_array($settings)) {
foreach ($settings as $name => $url) {
if (isset($handlers[$name])) {
$handlers[$name] = $url;
}
}
}
unset($settings);
$handlers = self::getHandlers();
if (!empty($_POST['handlers']) && is_array($_POST['handlers'])) {
foreach ($_POST['handlers'] as $name => $url) {
@ -81,33 +100,36 @@ try {
}
if (isset($_POST['act_save'])) {
dcCore::app()->blog->settings->myurlhandlers->put('url_handlers', serialize($handlers));
dcCore::app()->blog->triggerBlog();
dcAdminNotices::addSuccessNotice(__('URL handlers have been successfully updated.'));
MyUrlHandlers::saveBlogHandlers($handlers);
dcPage::addSuccessNotice(__('URL handlers have been successfully updated.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
} elseif (isset($_POST['act_restore'])) {
dcCore::app()->blog->settings->myurlhandlers->put('url_handlers', serialize([]));
dcCore::app()->blog->triggerBlog();
$handlers = myUrlHandlers::getDefaults();
dcAdminNotices::addSuccessNotice(__('URL handlers have been successfully restored.'));
MyUrlHandlers::saveBlogHandlers([]);
dcPage::addSuccessNotice(__('URL handlers have been successfully restored.'));
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
}
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
/* DISPLAY
--------------------------------------------------- */
return true;
}
?>
<html><head>
<title><?php echo __('URL handlers'); ?></title>
</head><body>
<?php
public static function render(): void
{
if (!self::$init) {
return;
}
$handlers = self::getHandlers();
dcPage::openModule(My::name());
echo
dcPage::breadcrumb(
[
html::escapeHTML(dcCore::app()->blog->name) => '',
__('URL handlers') => '',
My::name() => '',
]
) .
dcPage::notices();
@ -148,5 +170,22 @@ if (empty($handlers)) {
dcCore::app()->formNonce() . '</p>' .
'</form>';
}
?>
</body></html>
dcPage::closeModule();
}
private static function getHandlers(): array
{
# Read default handlers
$handlers = MyUrlHandlers::getDefaults();
# Overwrite with user settings
foreach (MyUrlHandlers::getBlogHandlers() as $name => $url) {
if (isset($handlers[$name])) {
$handlers[$name] = $url;
}
}
return $handlers;
}
}

38
src/My.php Normal file
View File

@ -0,0 +1,38 @@
<?php
/**
* @brief myUrlHandlers, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Alex Pirine 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\myUrlHandlers;
use dcCore;
class My
{
public const NS_SETTING_ID = 'handlers';
/**
* This module id
*/
public static function id(): string
{
return basename(dirname(__DIR__));
}
/**
* This module name
*/
public static function name(): string
{
return __((string) dcCore::app()->plugins->moduleInfo(self::id(), 'name'));
}
}

View File

@ -10,13 +10,19 @@
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class myUrlHandlers
declare(strict_types=1);
namespace Dotclear\Plugin\myUrlHandlers;
use dcCore;
class MyUrlHandlers
{
private static $defaults = [];
private static $url2post = [];
private static $post_adm_url = [];
public static function init()
public static function init(): void
{
# Set defaults
foreach (dcCore::app()->url->getTypes() as $k => $v) {
@ -39,13 +45,12 @@ class myUrlHandlers
}
# Read user settings
$handlers = (array) @unserialize(dcCore::app()->blog->settings->myurlhandlers->url_handlers);
foreach ($handlers as $name => $url) {
foreach (self::getBlogHandlers() as $name => $url) {
self::overrideHandler($name, $url);
}
}
public static function overrideHandler($name, $url)
public static function overrideHandler(string $name, string $url): void
{
if (!isset(self::$defaults[$name])) {
return;
@ -65,7 +70,7 @@ class myUrlHandlers
}
}
public static function getDefaults()
public static function getDefaults(): array
{
$res = [];
foreach (self::$defaults as $k => $v) {
@ -74,4 +79,17 @@ class myUrlHandlers
return $res;
}
public static function getBlogHandlers(): array
{
$handlers = json_decode((string) dcCore::app()->blog->settings->get(My::id())->get(My::NS_SETTING_ID), true);
return is_array($handlers) ? $handlers : [];
}
public static function saveBlogHandlers(array $handlers): void
{
dcCore::app()->blog->settings->get(My::id())->put(My::NS_SETTING_ID, json_encode($handlers));
dcCore::app()->blog->triggerBlog();
}
}

View File

@ -10,10 +10,29 @@
* @copyright 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);
namespace Dotclear\Plugin\myUrlHandlers;
use dcNsProcess;
class Prepend extends dcNsProcess
{
public static function init(): bool
{
self::$init = true;
return self::$init;
}
Clearbricks::lib()->autoload(['myUrlHandlers' => __DIR__ . '/inc/class.myurlhandlers.php']);
public static function process(): bool
{
if (!self::$init) {
return false;
}
myUrlHandlers::init();
MyUrlHandlers::init();
return true;
}
}