switch to dotclear 2.24

This commit is contained in:
Jean-Christian Paul Denis 2022-11-26 23:43:34 +01:00
parent 06d8275d22
commit 0923f870e4
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
8 changed files with 248 additions and 180 deletions

View File

@ -1,3 +1,46 @@
# myUrlHandlers
# README
Version actualisée de lextension [myUrlHandlers](https://lab.dotclear.org/wiki/plugin/myUrlHandlers) pour Dotclear afin dassurer son fonctionnement avec les nouvelles versions de Dotclear et de PHP.
[![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)
[![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)
## WHAT IS MYURLHANLDERS ?
_myUrlHandlers_ is a plugin for the open-source
web publishing software called Dotclear.
You can change public URL of each Dotclear parts,
like post, category, etc and some plugins having public parts.
## REQUIREMENTS
_myUrlHandlers_ requires:
* contentadmin permissions for management
* Dotclear 2.24
## USAGE
First install _myUrlHandlers_, manualy from a zip package or from
Dotaddict repository. (See Dotclear's documentation to know how do this)
You can manage your URLs from menu ''URL handlers'' on sidebar
or you can add dashboard icon.
## LINKS
* License : [GNU GPL v2](https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html)
* Source & contribution : [GitHub Page](https://github.com/JcDenis/myUrlHandlers)
* Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/myUrlHandlers)
* Discuss and help : [Dotclear Forum](https://forum.dotclear.org/viewtopic.php?id=40893)
## CONTRIBUTORS
* Alex pirine (First author)
* te2dy
* Jean-Christian Denis
You are welcome to contribute to this code.

View File

@ -1,31 +1,33 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# This file is part of My URL handlers, a plugin for Dotclear.
#
# Copyright (c) 2007-2015 Alex Pirine
# <alex pirine.fr>
#
# Licensed under the GPL version 2.0 license.
# A copy is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { return; }
$_menu['Blog']->addItem(__('URL handlers'),'plugin.php?p=myUrlHandlers',
'index.php?pf=myUrlHandlers/icon.png',
preg_match('/plugin.php\?p=myUrlHandlers$/',$_SERVER['REQUEST_URI']),
dcCore::app()->auth->check('contentadmin',dcCore::app()->blog->id));
dcCore::app()->addBehavior('adminDashboardFavorites','myUrlHandlersDashboardFavorites');
function myUrlHandlersDashboardFavorites($core,$favs)
{
$favs->register('myUrlHandlers', array(
'title' => __('URL handlers'),
'url' => 'plugin.php?p=myUrlHandlers',
'small-icon' => 'index.php?pf=myUrlHandlers/icon.png',
'large-icon' => 'index.php?pf=myUrlHandlers/icon-big.png',
'permissions' => 'contentadmin'
));
/**
* @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
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return;
}
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(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' => dcAuth::PERMISSION_CONTENT_ADMIN,
]);
});

View File

@ -1,28 +1,31 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# This file is part of My URL handlers, a plugin for Dotclear.
#
# Copyright (c) 2007-2015 Alex Pirine
# <alex pirine.fr>
#
# Licensed under the GPL version 2.0 license.
# A copy is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }
/**
* @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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
$this->registerModule(
'My URL handlers', // Name
'Change Dotclear URL handlers', // Description
'Alex Pirine and contributors', // Author
'2022.08', // Version
'My URL handlers',
'Change Dotclear URL handlers',
'Alex Pirine and contributors',
'2022.11.26',
[
'permissions' => 'contentadmin',
'requires' => [['core', '2.24']],
'permissions' => dcAuth::PERMISSION_CONTENT_ADMIN,
'priority' => 150000,
'type' => 'plugin',
'dc_min' => '2.7',
'support' => 'http://forum.dotclear.org/viewforum.php?id=16',
'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',
]
);

View File

@ -1,28 +1,40 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# This file is part of My URL handlers, a plugin for Dotclear.
#
# Copyright (c) 2007-2015 Alex Pirine
# <alex pirine.fr>
#
# Licensed under the GPL version 2.0 license.
# A copy is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------
/**
* @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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
if (!defined('DC_CONTEXT_ADMIN')) { return; }
$label = basename(__DIR__);
$new_version = dcCore::app()->plugins->moduleInfo($label, 'version');
$label = basename(dirname(__FILE__));
$m_version = dcCore::app()->plugins->moduleInfo($label,'version');
$i_version = dcCore::app()->getVersion($label);
if (version_compare($i_version,$m_version,'>=')) {
if (version_compare(dcCore::app()->getVersion($label), $new_version, '>=')) {
return;
}
dcCore::app()->blog->settings->addNamespace('myurlhandlers');
$s = &dcCore::app()->blog->settings->myurlhandlers;
$s->put('url_handlers','','string','Personalized URL handlers',false);
try {
dcCore::app()->blog->settings->addNamespace('myurlhandlers');
dcCore::app()->blog->settings->myurlhandlers->put(
'url_handlers',
'',
'string',
'Personalized URL handlers',
false
);
dcCore::app()->setVersion($label, $new_version);
dcCore::app()->setVersion($label,$m_version);
return true;
return true;
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
return false;

View File

@ -1,17 +1,19 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# This file is part of My URL handlers, a plugin for Dotclear.
#
# Copyright (c) 2007-2015 Alex Pirine
# <alex pirine.fr>
#
# Licensed under the GPL version 2.0 license.
# A copy is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------
/**
* @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
*/
if (!defined('DC_RC_PATH')) {
return null;
}
if (!defined('DC_RC_PATH')) { return; }
Clearbricks::lib()->autoload(['myUrlHandlers' => __DIR__ . '/inc/class.myurlhandlers.php']);
$__autoload['myUrlHandlers'] = dirname(__FILE__).'/class.myurlhandlers.php';
myUrlHandlers::init(dcCore::app());
myUrlHandlers::init();

13
dcstore.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<modules xmlns:da="http://dotaddict.org/da/">
<module id="myUrlHandlers">
<name>My URL handlers</name>
<version>2022.11.26</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>
<da:details>http://plugins.dotaddict.org/dc2/details/myUrlHandlers</da:details>
<da:support>http://forum.dotclear.org/viewforum.php?id=16</da:support>
</module>
</modules>

View File

@ -1,81 +1,80 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# This file is part of My URL handlers, a plugin for Dotclear.
#
# Copyright (c) 2007-2015 Alex Pirine
# <alex pirine.fr>
#
# Licensed under the GPL version 2.0 license.
# A copy is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------
/**
* @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
*/
class myUrlHandlers
{
private $sets;
private $handlers = array();
private $handlers = [];
private static $defaults = array();
private static $url2post = array();
private static $post_adm_url = array();
private static $defaults = [];
private static $url2post = [];
private static $post_adm_url = [];
public static function init($core)
public static function init()
{
# Set defaults
foreach (dcCore::app()->url->getTypes() as $k=>$v)
{
foreach (dcCore::app()->url->getTypes() as $k => $v) {
if (empty($v['url'])) {
continue;
}
$p = '/'.preg_quote($v['url'],'/').'/';
$v['representation'] = str_replace('%','%%',$v['representation']);
$v['representation'] = preg_replace($p,'%s',$v['representation'],1,$c);
$p = '/' . preg_quote($v['url'], '/') . '/';
$v['representation'] = str_replace('%', '%%', $v['representation']);
$v['representation'] = preg_replace($p, '%s', $v['representation'], 1, $c);
if ($c) {
self::$defaults[$k] = $v;
}
}
foreach (dcCore::app()->getPostTypes() as $k=>$v)
{
foreach (dcCore::app()->getPostTypes() as $k => $v) {
self::$url2post[$v['public_url']] = $k;
self::$post_adm_url[$k] = $v['admin_url'];
}
# Read user settings
$handlers = (array) @unserialize(dcCore::app()->blog->settings->myurlhandlers->url_handlers);
foreach ($handlers as $name => $url)
{
self::overrideHandler($name,$url);
foreach ($handlers as $name => $url) {
self::overrideHandler($name, $url);
}
}
public static function overrideHandler($name,$url)
public static function overrideHandler($name, $url)
{
if (!isset(self::$defaults[$name])) {
return;
}
dcCore::app()->url->register($name,$url,
sprintf(self::$defaults[$name]['representation'],$url),
self::$defaults[$name]['handler']);
dcCore::app()->url->register(
$name,
$url,
sprintf(self::$defaults[$name]['representation'], $url),
self::$defaults[$name]['handler']
);
$k = isset(self::$url2post[self::$defaults[$name]['url'].'/%s'])
? self::$url2post[self::$defaults[$name]['url'].'/%s'] : '';
$k = self::$url2post[self::$defaults[$name]['url'] . '/%s'] ?? '';
if ($k) {
dcCore::app()->setPostType($k,self::$post_adm_url[$k],dcCore::app()->url->getBase($name).'/%s');
dcCore::app()->setPostType($k, self::$post_adm_url[$k], dcCore::app()->url->getBase($name) . '/%s');
}
}
public static function getDefaults()
{
$res = array();
foreach (self::$defaults as $k=>$v)
{
$res = [];
foreach (self::$defaults as $k => $v) {
$res[$k] = $v['url'];
}
return $res;
}
}

108
index.php
View File

@ -1,29 +1,31 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# This file is part of My URL handlers, a plugin for Dotclear.
#
# Copyright (c) 2007-2015 Alex Pirine
# <alex pirine.fr>
#
# Licensed under the GPL version 2.0 license.
# A copy is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------
/**
* @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
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
if (!defined('DC_CONTEXT_ADMIN')) { return; }
dcPage::check(dcAuth::PERMISSION_CONTENT_ADMIN);
$page_title = __('URL handlers');
try
{
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)
{
foreach ($settings as $name => $url) {
if (isset($handlers[$name])) {
$handlers[$name] = $url;
}
@ -31,71 +33,66 @@ try
}
unset($settings);
if (!empty($_POST['handlers']) && is_array($_POST['handlers']))
{
foreach ($_POST['handlers'] as $name=>$url)
{
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(
__('Handler "%s" doesn\'t exist.'),html::escapeHTML($name)));
__('Handler "%s" doesn\'t exist.'),
html::escapeHTML($name)
));
}
if (empty($url)) {
throw new Exception(sprintf(
__('Invalid URL for handler "%s".'),html::escapeHTML($name)));
__('Invalid URL for handler "%s".'),
html::escapeHTML($name)
));
}
$handlers[$name] = $url;
}
# Get duplicates
$w = array_unique(array_diff_key($handlers,array_unique($handlers)));
$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);
$v = function (&$v, $k, $h) {
return array_keys($h, $v);
};
array_walk($w,$v,$handlers);
array_walk($w, $v, $handlers);
/**
* End fix
*/
$w = call_user_func_array('array_merge',$w);
$w = call_user_func_array('array_merge', $w);
if (!empty($w)) {
throw new Exception(sprintf(
__('Duplicate URL in handlers "%s".'),implode('", "',$w)));
__('Duplicate URL in handlers "%s".'),
implode('", "', $w)
));
}
}
if (isset($_POST['act_save']))
{
dcCore::app()->blog->settings->myurlhandlers->put('url_handlers',serialize($handlers));
if (isset($_POST['act_save'])) {
dcCore::app()->blog->settings->myurlhandlers->put('url_handlers', serialize($handlers));
dcCore::app()->blog->triggerBlog();
$msg = __('URL handlers have been successfully updated.');
}
elseif (isset($_POST['act_restore']))
{
dcCore::app()->blog->settings->myurlhandlers->put('url_handlers',serialize(array()));
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();
$msg = __('URL handlers have been successfully restored.');
dcAdminNotices::addSuccessNotice(__('URL handlers have been successfully restored.'));
}
}
catch (Exception $e)
{
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
}
@ -109,36 +106,33 @@ catch (Exception $e)
<?php
echo dcPage::breadcrumb(
array(
[
html::escapeHTML(dcCore::app()->blog->name) => '',
'<span class="page-title">'.$page_title.'</span>' => ''
)
);
'<span class="page-title">' . $page_title . '</span>' => '',
]
) .
dcPage::notices();
if (!empty($msg)) {
dcPage::success($msg);
}
?>
<?php if (empty($handlers)): ?>
<p class="message"><?php echo __('No URL handler to configure.'); ?></p>
<?php else: ?>
<p><?php echo __('You can write your own URL for each handler of this list.'); ?></p>
<form action="<?php echo $p_url; ?>" method="post">
<form action="<?php echo dcCore::app()->admin->getPageURL(); ?>" method="post">
<table>
<thead>
<tr><th>Type</th><th>URL</th></tr>
</thead>
<tbody>
<?php
foreach ($handlers as $name=>$url)
{
foreach ($handlers as $name => $url) {
echo
'<tr><td>'.html::escapeHTML($name).'</td><td>'.
form::field(array('handlers['.$name.']'),20,255,html::escapeHTML($url)).
'</td></tr>'."\n";
'<tr><td>' . html::escapeHTML($name) . '</td><td>' .
form::field(['handlers[' . $name . ']'], 20, 255, html::escapeHTML($url)) .
'</td></tr>' . "\n";
}
?>
?>
</tbody>
</table>
<p><input type="submit" name="act_save" value="<?php echo __('Save'); ?>" />