From 0923f870e4371c7b8bfc3d7a11a92fac0682a230 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 26 Nov 2022 23:43:34 +0100 Subject: [PATCH] switch to dotclear 2.24 --- README.md | 47 ++++++++++++++- _admin.php | 60 ++++++++++---------- _define.php | 41 +++++++------- _install.php | 54 +++++++++++------- _prepend.php | 30 +++++----- dcstore.xml | 13 +++++ inc/class.myurlhandlers.php | 73 ++++++++++++------------ index.php | 110 +++++++++++++++++------------------- 8 files changed, 248 insertions(+), 180 deletions(-) create mode 100644 dcstore.xml diff --git a/README.md b/README.md index d344c44..3adc720 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,46 @@ -# myUrlHandlers +# README -Version actualisée de l’extension [myUrlHandlers](https://lab.dotclear.org/wiki/plugin/myUrlHandlers) pour Dotclear afin d’assurer 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. \ No newline at end of file diff --git a/_admin.php b/_admin.php index 7b4fc93..f6710b3 100644 --- a/_admin.php +++ b/_admin.php @@ -1,31 +1,33 @@ -# -# 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, + ]); +}); diff --git a/_define.php b/_define.php index a1687e3..ac35550 100644 --- a/_define.php +++ b/_define.php @@ -1,28 +1,31 @@ -# -# 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', ] ); diff --git a/_install.php b/_install.php index 4fb68dc..a9a0280 100644 --- a/_install.php +++ b/_install.php @@ -1,28 +1,40 @@ -# -# 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; diff --git a/_prepend.php b/_prepend.php index f032896..9baf09d 100644 --- a/_prepend.php +++ b/_prepend.php @@ -1,17 +1,19 @@ -# -# 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(); diff --git a/dcstore.xml b/dcstore.xml new file mode 100644 index 0000000..22fa6d7 --- /dev/null +++ b/dcstore.xml @@ -0,0 +1,13 @@ + + + + My URL handlers + 2022.11.26 + Alex Pirine and contributors + Change Dotclear URL handlers + https://github.com/JcDenis/myUrlHandlers/releases/download/v2022.11.26/plugin-myUrlHandlers.zip + 2.24 + http://plugins.dotaddict.org/dc2/details/myUrlHandlers + http://forum.dotclear.org/viewforum.php?id=16 + + diff --git a/inc/class.myurlhandlers.php b/inc/class.myurlhandlers.php index 55f7348..0c97729 100644 --- a/inc/class.myurlhandlers.php +++ b/inc/class.myurlhandlers.php @@ -1,81 +1,80 @@ -# -# 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']; + 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; } } diff --git a/index.php b/index.php index d0c1565..584eb37 100644 --- a/index.php +++ b/index.php @@ -1,29 +1,31 @@ -# -# 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) blog->name) => '', - ''.$page_title.'' => '' - ) - ); + [ + html::escapeHTML(dcCore::app()->blog->name) => '', + '' . $page_title . '' => '', + ] + ) . + dcPage::notices(); -if (!empty($msg)) { - dcPage::success($msg); -} ?>

-
+ $url) -{ +foreach ($handlers as $name => $url) { echo - ''."\n"; + '' . "\n"; } -?> + ?>
TypeURL
'.html::escapeHTML($name).''. - form::field(array('handlers['.$name.']'),20,255,html::escapeHTML($url)). - '
' . html::escapeHTML($name) . '' . + form::field(['handlers[' . $name . ']'], 20, 255, html::escapeHTML($url)) . + '