release 2023.03.11 for Dotclear 2.25
This commit is contained in:
parent
1dca765741
commit
c9e3ea8f3f
9
CHANGELOG.md
Normal file
9
CHANGELOG.md
Normal 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
|
@ -3,7 +3,7 @@
|
|||||||
[![Release](https://img.shields.io/github/v/release/JcDenis/myUrlHandlers)](https://github.com/JcDenis/myUrlHandlers/releases)
|
[![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)
|
[![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)
|
[![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)
|
[![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)
|
[![License](https://img.shields.io/github/license/JcDenis/myUrlHandlers)](https://github.com/JcDenis/myUrlHandlers/blob/master/LICENSE)
|
||||||
|
|
||||||
|
14
_define.php
14
_define.php
@ -18,16 +18,16 @@ $this->registerModule(
|
|||||||
'My URL handlers',
|
'My URL handlers',
|
||||||
'Change Dotclear URL handlers',
|
'Change Dotclear URL handlers',
|
||||||
'Alex Pirine and contributors',
|
'Alex Pirine and contributors',
|
||||||
'2022.11.26',
|
'2023.03.11',
|
||||||
[
|
[
|
||||||
'requires' => [['core', '2.24']],
|
'requires' => [['core', '2.25']],
|
||||||
'permissions' => dcCore::app()->auth->makePermissions([
|
'permissions' => dcCore::app()->auth->makePermissions([
|
||||||
dcAuth::PERMISSION_CONTENT_ADMIN,
|
dcAuth::PERMISSION_CONTENT_ADMIN,
|
||||||
]),
|
]),
|
||||||
'priority' => 150000,
|
'priority' => 150000,
|
||||||
'type' => 'plugin',
|
'type' => 'plugin',
|
||||||
'support' => 'https://github.com/JcDenis/myUrlHandlers',
|
'support' => 'https://github.com/JcDenis/myUrlHandlers',
|
||||||
'details' => 'http://plugins.dotaddict.org/dc2/details/myUrlHandlers',
|
'details' => 'http://plugins.dotaddict.org/dc2/details/myUrlHandlers',
|
||||||
'repository' => 'https://raw.githubusercontent.com/JcDenis/myUrlHandlers/master/dcstore.xml',
|
'repository' => 'https://raw.githubusercontent.com/JcDenis/myUrlHandlers/master/dcstore.xml',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
<modules xmlns:da="http://dotaddict.org/da/">
|
<modules xmlns:da="http://dotaddict.org/da/">
|
||||||
<module id="myUrlHandlers">
|
<module id="myUrlHandlers">
|
||||||
<name>My URL handlers</name>
|
<name>My URL handlers</name>
|
||||||
<version>2022.11.26</version>
|
<version>2023.03.11</version>
|
||||||
<author>Alex Pirine and contributors</author>
|
<author>Alex Pirine and contributors</author>
|
||||||
<desc>Change Dotclear URL handlers</desc>
|
<desc>Change Dotclear URL handlers</desc>
|
||||||
<file>https://github.com/JcDenis/myUrlHandlers/releases/download/v2022.11.26/plugin-myUrlHandlers.zip</file>
|
<file>https://github.com/JcDenis/myUrlHandlers/releases/download/v2023.03.11/plugin-myUrlHandlers.zip</file>
|
||||||
<da:dcmin>2.24</da:dcmin>
|
<da:dcmin>2.25</da:dcmin>
|
||||||
<da:details>http://plugins.dotaddict.org/dc2/details/myUrlHandlers</da:details>
|
<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>
|
</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
20
locales/fr/main.lang.php
Normal file
20
locales/fr/main.lang.php
Normal 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';
|
@ -1,18 +1,15 @@
|
|||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"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"
|
"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"
|
"Last-Translator: Jean-Christian Denis\n"
|
||||||
"Language-Team: \n"
|
"Language-Team: \n"
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||||
|
|
||||||
msgid "URL handlers"
|
|
||||||
msgstr "Gestionnaires d'URL"
|
|
||||||
|
|
||||||
msgid "Uknown handler \"%s\"."
|
msgid "Uknown handler \"%s\"."
|
||||||
msgstr "Le gestionnaire \"%s\" n'existe pas."
|
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."
|
msgid "No URL handler to configure."
|
||||||
msgstr "Il n'y a aucun gestionnaire d'URL à définir."
|
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"
|
msgid "URL handlers list"
|
||||||
msgstr "Liste des gestionnaires d'URL"
|
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"
|
||||||
|
|
||||||
|
@ -10,24 +10,50 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
declare(strict_types=1);
|
||||||
return;
|
|
||||||
|
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(
|
||||||
|
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 (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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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']),
|
|
||||||
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'),
|
|
||||||
'permissions' => dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]),
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
@ -10,30 +10,64 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_RC_PATH')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
namespace Dotclear\Plugin\myUrlHandlers;
|
||||||
if (!dcCore::app()->newVersion(
|
|
||||||
basename(__DIR__),
|
use dcCore;
|
||||||
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
|
use dcNamespace;
|
||||||
)) {
|
use dcNsProcess;
|
||||||
return null;
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
dcCore::app()->blog->settings->addNamespace('myurlhandlers');
|
public static function process(): bool
|
||||||
dcCore::app()->blog->settings->myurlhandlers->put(
|
{
|
||||||
'url_handlers',
|
if (!self::$init) {
|
||||||
'',
|
return false;
|
||||||
'string',
|
}
|
||||||
'Personalized URL handlers',
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
self::growUp();
|
||||||
} catch (Exception $e) {
|
|
||||||
dcCore::app()->error->add($e->getMessage());
|
dcCore::app()->blog->settings->get(My::id())->put(
|
||||||
|
My::NS_SETTING_ID,
|
||||||
|
json_encode([]),
|
||||||
|
'string',
|
||||||
|
'Personalized URL handlers',
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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')) . "' "))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
|
301
src/Manage.php
301
src/Manage.php
@ -10,143 +10,182 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
dcPage::check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]));
|
namespace Dotclear\Plugin\myUrlHandlers;
|
||||||
|
|
||||||
try {
|
use dcAuth;
|
||||||
# Read default handlers
|
use dcCore;
|
||||||
$handlers = myUrlHandlers::getDefaults();
|
use dcNsProcess;
|
||||||
|
use dcPage;
|
||||||
|
use Exception;
|
||||||
|
use form;
|
||||||
|
use html;
|
||||||
|
use text;
|
||||||
|
|
||||||
# Overwrite with user settings
|
/**
|
||||||
$settings = @unserialize(dcCore::app()->blog->settings->myurlhandlers->url_handlers);
|
* Manage contributions list
|
||||||
if (is_array($settings)) {
|
*/
|
||||||
foreach ($settings as $name => $url) {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function process(): bool
|
||||||
|
{
|
||||||
|
if (!self::$init) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$handlers = self::getHandlers();
|
||||||
|
|
||||||
|
if (!empty($_POST['handlers']) && is_array($_POST['handlers'])) {
|
||||||
|
foreach ($_POST['handlers'] as $name => $url) {
|
||||||
|
$url = text::tidyURL($url);
|
||||||
|
|
||||||
|
if (empty($handlers[$name])) {
|
||||||
|
throw new Exception(sprintf(
|
||||||
|
__('Uknown handler "%s".'),
|
||||||
|
html::escapeHTML($name)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($url)) {
|
||||||
|
throw new Exception(sprintf(
|
||||||
|
__('Invalid URL for handler "%s".'),
|
||||||
|
html::escapeHTML($name)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$handlers[$name] = $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get duplicates
|
||||||
|
$w = array_unique(array_diff_key($handlers, array_unique($handlers)));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error on the line
|
||||||
|
* array_walk($w,create_function('&$v,$k,$h','$v = array_keys($h,$v);'),$handlers);
|
||||||
|
*
|
||||||
|
* Begin fix
|
||||||
|
*/
|
||||||
|
$v = function (&$v, $k, $h) {
|
||||||
|
return array_keys($h, $v);
|
||||||
|
};
|
||||||
|
|
||||||
|
array_walk($w, $v, $handlers);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End fix
|
||||||
|
*/
|
||||||
|
$w = call_user_func_array('array_merge', $w);
|
||||||
|
|
||||||
|
if (!empty($w)) {
|
||||||
|
throw new Exception(sprintf(
|
||||||
|
__('Duplicate URL in handlers "%s".'),
|
||||||
|
implode('", "', $w)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['act_save'])) {
|
||||||
|
MyUrlHandlers::saveBlogHandlers($handlers);
|
||||||
|
dcPage::addSuccessNotice(__('URL handlers have been successfully updated.'));
|
||||||
|
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id());
|
||||||
|
} elseif (isset($_POST['act_restore'])) {
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) => '',
|
||||||
|
My::name() => '',
|
||||||
|
]
|
||||||
|
) .
|
||||||
|
dcPage::notices();
|
||||||
|
|
||||||
|
if (empty($handlers)) {
|
||||||
|
echo
|
||||||
|
'<p class="message">' . __('No URL handler to configure.') . '</p>';
|
||||||
|
} else {
|
||||||
|
echo
|
||||||
|
'<form action="' . dcCore::app()->admin->getPageURL() . '" method="post">' .
|
||||||
|
'<div class="table-outer">' .
|
||||||
|
'<table>' .
|
||||||
|
'<caption>' . __('URL handlers list') . '</caption>' .
|
||||||
|
'<thead>' .
|
||||||
|
'<tr>' .
|
||||||
|
'<th class="nowrap" scope="col">' . __('Type') . '</th>' .
|
||||||
|
'<th class="nowrap" scope="col">' . __('URL') . '</th>' .
|
||||||
|
'</tr>' .
|
||||||
|
'</thead>' .
|
||||||
|
'<tbody>';
|
||||||
|
|
||||||
|
foreach ($handlers as $name => $url) {
|
||||||
|
echo
|
||||||
|
'<tr class="line">' .
|
||||||
|
'<td class="nowrap minimal">' . html::escapeHTML($name) . '</td>' .
|
||||||
|
'<td>' .
|
||||||
|
form::field(['handlers[' . $name . ']'], 20, 255, html::escapeHTML($url)) .
|
||||||
|
'</td>' .
|
||||||
|
'</tr>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo
|
||||||
|
'</tbody></table></div>' .
|
||||||
|
'<p class="form-note">' . __('You can write your own URL for each handler of this list.') . '</p>' .
|
||||||
|
'<p>' .
|
||||||
|
'<input type="submit" name="act_save" value="' . __('Save') . '" /> ' .
|
||||||
|
'<input class="delete" type="submit" name="act_restore" value="' . __('Reset') . '" />' .
|
||||||
|
dcCore::app()->formNonce() . '</p>' .
|
||||||
|
'</form>';
|
||||||
|
}
|
||||||
|
|
||||||
|
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])) {
|
if (isset($handlers[$name])) {
|
||||||
$handlers[$name] = $url;
|
$handlers[$name] = $url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $handlers;
|
||||||
}
|
}
|
||||||
unset($settings);
|
|
||||||
|
|
||||||
if (!empty($_POST['handlers']) && is_array($_POST['handlers'])) {
|
|
||||||
foreach ($_POST['handlers'] as $name => $url) {
|
|
||||||
$url = text::tidyURL($url);
|
|
||||||
|
|
||||||
if (empty($handlers[$name])) {
|
|
||||||
throw new Exception(sprintf(
|
|
||||||
__('Uknown handler "%s".'),
|
|
||||||
html::escapeHTML($name)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($url)) {
|
|
||||||
throw new Exception(sprintf(
|
|
||||||
__('Invalid URL for handler "%s".'),
|
|
||||||
html::escapeHTML($name)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$handlers[$name] = $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get duplicates
|
|
||||||
$w = array_unique(array_diff_key($handlers, array_unique($handlers)));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error on the line
|
|
||||||
* array_walk($w,create_function('&$v,$k,$h','$v = array_keys($h,$v);'),$handlers);
|
|
||||||
*
|
|
||||||
* Begin fix
|
|
||||||
*/
|
|
||||||
$v = function (&$v, $k, $h) {
|
|
||||||
return array_keys($h, $v);
|
|
||||||
};
|
|
||||||
|
|
||||||
array_walk($w, $v, $handlers);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* End fix
|
|
||||||
*/
|
|
||||||
$w = call_user_func_array('array_merge', $w);
|
|
||||||
|
|
||||||
if (!empty($w)) {
|
|
||||||
throw new Exception(sprintf(
|
|
||||||
__('Duplicate URL in handlers "%s".'),
|
|
||||||
implode('", "', $w)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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.'));
|
|
||||||
} 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.'));
|
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
|
||||||
dcCore::app()->error->add($e->getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DISPLAY
|
|
||||||
--------------------------------------------------- */
|
|
||||||
|
|
||||||
?>
|
|
||||||
<html><head>
|
|
||||||
<title><?php echo __('URL handlers'); ?></title>
|
|
||||||
</head><body>
|
|
||||||
<?php
|
|
||||||
|
|
||||||
echo
|
|
||||||
dcPage::breadcrumb(
|
|
||||||
[
|
|
||||||
html::escapeHTML(dcCore::app()->blog->name) => '',
|
|
||||||
__('URL handlers') => '',
|
|
||||||
]
|
|
||||||
) .
|
|
||||||
dcPage::notices();
|
|
||||||
|
|
||||||
if (empty($handlers)) {
|
|
||||||
echo
|
|
||||||
'<p class="message">' . __('No URL handler to configure.') . '</p>';
|
|
||||||
} else {
|
|
||||||
echo
|
|
||||||
'<form action="' . dcCore::app()->admin->getPageURL() . '" method="post">' .
|
|
||||||
'<div class="table-outer">' .
|
|
||||||
'<table>' .
|
|
||||||
'<caption>' . __('URL handlers list') . '</caption>' .
|
|
||||||
'<thead>' .
|
|
||||||
'<tr>' .
|
|
||||||
'<th class="nowrap" scope="col">' . __('Type') . '</th>' .
|
|
||||||
'<th class="nowrap" scope="col">' . __('URL') . '</th>' .
|
|
||||||
'</tr>' .
|
|
||||||
'</thead>' .
|
|
||||||
'<tbody>';
|
|
||||||
|
|
||||||
foreach ($handlers as $name => $url) {
|
|
||||||
echo
|
|
||||||
'<tr class="line">' .
|
|
||||||
'<td class="nowrap minimal">' . html::escapeHTML($name) . '</td>' .
|
|
||||||
'<td>' .
|
|
||||||
form::field(['handlers[' . $name . ']'], 20, 255, html::escapeHTML($url)) .
|
|
||||||
'</td>'.
|
|
||||||
'</tr>';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo
|
|
||||||
'</tbody></table></div>' .
|
|
||||||
'<p class="form-note">' . __('You can write your own URL for each handler of this list.') . '</p>' .
|
|
||||||
'<p>' .
|
|
||||||
'<input type="submit" name="act_save" value="' . __('Save') . '" /> ' .
|
|
||||||
'<input class="delete" type="submit" name="act_restore" value="' . __('Reset') . '" />' .
|
|
||||||
dcCore::app()->formNonce() . '</p>' .
|
|
||||||
'</form>';
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</body></html>
|
|
||||||
|
38
src/My.php
Normal file
38
src/My.php
Normal 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'));
|
||||||
|
}
|
||||||
|
}
|
@ -10,13 +10,19 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @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 $defaults = [];
|
||||||
private static $url2post = [];
|
private static $url2post = [];
|
||||||
private static $post_adm_url = [];
|
private static $post_adm_url = [];
|
||||||
|
|
||||||
public static function init()
|
public static function init(): void
|
||||||
{
|
{
|
||||||
# Set defaults
|
# Set defaults
|
||||||
foreach (dcCore::app()->url->getTypes() as $k => $v) {
|
foreach (dcCore::app()->url->getTypes() as $k => $v) {
|
||||||
@ -39,13 +45,12 @@ class myUrlHandlers
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Read user settings
|
# Read user settings
|
||||||
$handlers = (array) @unserialize(dcCore::app()->blog->settings->myurlhandlers->url_handlers);
|
foreach (self::getBlogHandlers() as $name => $url) {
|
||||||
foreach ($handlers as $name => $url) {
|
|
||||||
self::overrideHandler($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])) {
|
if (!isset(self::$defaults[$name])) {
|
||||||
return;
|
return;
|
||||||
@ -65,7 +70,7 @@ class myUrlHandlers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDefaults()
|
public static function getDefaults(): array
|
||||||
{
|
{
|
||||||
$res = [];
|
$res = [];
|
||||||
foreach (self::$defaults as $k => $v) {
|
foreach (self::$defaults as $k => $v) {
|
||||||
@ -74,4 +79,17 @@ class myUrlHandlers
|
|||||||
|
|
||||||
return $res;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,29 @@
|
|||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
if (!defined('DC_RC_PATH')) {
|
declare(strict_types=1);
|
||||||
return null;
|
|
||||||
|
namespace Dotclear\Plugin\myUrlHandlers;
|
||||||
|
|
||||||
|
use dcNsProcess;
|
||||||
|
|
||||||
|
class Prepend extends dcNsProcess
|
||||||
|
{
|
||||||
|
public static function init(): bool
|
||||||
|
{
|
||||||
|
self::$init = true;
|
||||||
|
|
||||||
|
return self::$init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function process(): bool
|
||||||
|
{
|
||||||
|
if (!self::$init) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
MyUrlHandlers::init();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Clearbricks::lib()->autoload(['myUrlHandlers' => __DIR__ . '/inc/class.myurlhandlers.php']);
|
|
||||||
|
|
||||||
myUrlHandlers::init();
|
|
||||||
|
Loading…
Reference in New Issue
Block a user