move to Dotclear 2.26-dev
This commit is contained in:
parent
b0a1e09c99
commit
8d0047ddcd
8 changed files with 212 additions and 104 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
xxxx.xx.xx
|
||||||
|
- require Dotclear 2.26
|
||||||
|
- use PHP namespace
|
||||||
|
- use new plugin structure
|
||||||
|
- use new Form class
|
||||||
|
- add icon url on blog pref
|
||||||
|
|
||||||
2022.12.23
|
2022.12.23
|
||||||
- use anonymlous functions
|
- use anonymlous functions
|
||||||
- code review (phpstan, php-cs-fixer)
|
- code review (phpstan, php-cs-fixer)
|
||||||
|
|
14
_define.php
14
_define.php
|
@ -18,17 +18,17 @@ $this->registerModule(
|
||||||
'Simply favicon',
|
'Simply favicon',
|
||||||
'Multi-agents favicon',
|
'Multi-agents favicon',
|
||||||
'Jean-Christian Denis',
|
'Jean-Christian Denis',
|
||||||
'2022.12.23',
|
'2023.03.06',
|
||||||
[
|
[
|
||||||
'requires' => [['core', '2.24']],
|
'requires' => [['core', '2.26-dev']],
|
||||||
'permissions' => dcCore::app()->auth->makePermissions([
|
'permissions' => dcCore::app()->auth->makePermissions([
|
||||||
dcAuth::PERMISSION_ADMIN,
|
dcAuth::PERMISSION_ADMIN,
|
||||||
]),
|
]),
|
||||||
'type' => 'plugin',
|
'type' => 'plugin',
|
||||||
'support' => 'https://github.com/JcDenis/' . basename(__DIR__),
|
'support' => 'https://github.com/JcDenis/' . basename(__DIR__),
|
||||||
'details' => 'http://plugins.dotaddict.org/dc2/details/' . basename(__DIR__),
|
'details' => 'http://plugins.dotaddict.org/dc2/details/' . basename(__DIR__),
|
||||||
'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml',
|
'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml',
|
||||||
'settings' => [
|
'settings' => [
|
||||||
'blog' => '#params.simply_favicon_params',
|
'blog' => '#params.simply_favicon_params',
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|
|
@ -9,8 +9,9 @@
|
||||||
# DOT NOT MODIFY THIS FILE !
|
# DOT NOT MODIFY THIS FILE !
|
||||||
#
|
#
|
||||||
|
|
||||||
l10n::$locales['Enable "%s" extension'] = 'Activer l\'extension "%s"';
|
l10n::$locales['Enable favorite icon'] = 'Activer l\'icône de favori';
|
||||||
l10n::$locales['You must place an image called favicon.png or .jpg or .ico into your blog\'s public directory.'] = 'Vous devez placer une image nommée favicon.png, .jpg ou .ico dans le répertoire publique du blog.';
|
l10n::$locales['You must place an image called favicon.png or .jpg or .ico into your blog\'s public directory.'] = 'Vous devez placer une image nommée favicon.png, .jpg ou .ico dans le répertoire publique du blog.';
|
||||||
l10n::$locales['There are no favicon in blog public directory'] = 'Il n\'y a pas de Favicon dans le répertoire public du blog.';
|
l10n::$locales['There are no favicon in blog public directory'] = 'Il n\'y a pas de Favicon dans le répertoire public du blog.';
|
||||||
l10n::$locales['Current favicons:'] = 'Favicons actuels :';
|
l10n::$locales['Current favicons:'] = 'Favicons actuels :';
|
||||||
l10n::$locales['Multi-agents favicon'] = 'Favicon multi-agents';
|
l10n::$locales['Multi-agents favicon'] = 'Favicon multi-agents';
|
||||||
|
l10n::$locales['Simply favicon'] = 'Simple favicon';
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
"Project-Id-Version: simplyFavicon 2021.09.02.1\n"
|
"Project-Id-Version: simplyFavicon 2023.03.06\n"
|
||||||
"POT-Creation-Date: \n"
|
"POT-Creation-Date: \n"
|
||||||
"PO-Revision-Date: 2021-11-06T09:13:24+00:00\n"
|
"PO-Revision-Date: 2023-03-06T22:03:39+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 "Enable \"%s\" extension"
|
msgid "Enable favorite icon"
|
||||||
msgstr "Activer l'extension \"Simply favicon\""
|
msgstr "Activer l'icône de favori"
|
||||||
|
|
||||||
msgid "You must place an image called favicon.png or .jpg or .ico into your blog's public directory."
|
msgid "You must place an image called favicon.png or .jpg or .ico into your blog's public directory."
|
||||||
msgstr "Vous devez placer une image nommée favicon.png, .jpg ou .ico dans le répertoire publique du blog."
|
msgstr "Vous devez placer une image nommée favicon.png, .jpg ou .ico dans le répertoire publique du blog."
|
||||||
|
@ -24,3 +24,7 @@ msgstr "Favicons actuels :"
|
||||||
|
|
||||||
msgid "Multi-agents favicon"
|
msgid "Multi-agents favicon"
|
||||||
msgstr "Favicon multi-agents"
|
msgstr "Favicon multi-agents"
|
||||||
|
|
||||||
|
msgid "Simply favicon"
|
||||||
|
msgstr "Simple favicon"
|
||||||
|
|
||||||
|
|
|
@ -10,37 +10,71 @@
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
|
|
||||||
dcCore::app()->addBehaviors([
|
namespace Dotclear\Plugin\simplyFavicon;
|
||||||
'adminBlogPreferencesFormV2' => function ($blog_settings) {
|
|
||||||
$exists = [];
|
use dcCore;
|
||||||
$path = path::fullFromRoot((string) $blog_settings->get('system')->get('public_path'), DC_ROOT);
|
use dcNsProcess;
|
||||||
foreach (['ico', 'png', 'bmp', 'gif', 'jpg', 'mng'] as $ext) {
|
use path;
|
||||||
if (file_exists($path . '/favicon.' . $ext)) {
|
|
||||||
$exists[] = sprintf('<li title="%s">%s</li>', $path . '/favicon.' . $ext, 'favicon.' . $ext);
|
use Dotclear\Helper\Html\Form\{
|
||||||
}
|
Checkbox,
|
||||||
|
Div,
|
||||||
|
Label,
|
||||||
|
Note,
|
||||||
|
Para
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo
|
dcCore::app()->addBehaviors([
|
||||||
'<div class="fieldset clear"><h4 id="simply_favicon_params">' . __('Favicon') . '</h4>' .
|
'adminBlogPreferencesFormV2' => function ($blog_settings) {
|
||||||
'<div class="two-cols"><div class="col">' .
|
$exists = [];
|
||||||
'<p><label class="classic">' .
|
$path = path::fullFromRoot((string) $blog_settings->get('system')->get('public_path'), DC_ROOT);
|
||||||
form::checkbox('simply_favicon', '1', (bool) $blog_settings->get('system')->get('simply_favicon')) .
|
foreach (['ico', 'png', 'bmp', 'gif', 'jpg', 'mng'] as $ext) {
|
||||||
sprintf(__('Enable "%s" extension'), __('Simply favicon')) . '</label></p>' .
|
if (file_exists($path . '/favicon.' . $ext)) {
|
||||||
'<p class="form-note">' .
|
$url = dcCore::app()->blog->url . dcCore::app()->url->getURLFor('simplyFavicon', $ext);
|
||||||
__("You must place an image called favicon.png or .jpg or .ico into your blog's public directory.") .
|
$exists[] = '<li><a href="' . $url . '">' . $url . '</a></li>';
|
||||||
'</p></div><div class="col">' .
|
}
|
||||||
(
|
}
|
||||||
empty($exists) ?
|
|
||||||
'<p>' . __('There are no favicon in blog public directory') . '</p>' :
|
echo
|
||||||
'<p>' . __('Current favicons:') . '</p><ul class="nice">' . implode($exists) . '</ul>'
|
'<div class="fieldset clear"><h4 id="simply_favicon_params">' . __('Favicon') . '</h4>' .
|
||||||
) .
|
'<div class="two-cols"><div class="col">' .
|
||||||
'</div></div><br class="clear" /></div>';
|
(new Div())->class('box')->items([
|
||||||
},
|
(new Para())->items([
|
||||||
'adminBeforeBlogSettingsUpdate' => function ($blog_settings) {
|
(new Checkbox('simply_favicon', (bool) $blog_settings->get('system')->get('simply_favicon')))->value('1'),
|
||||||
$blog_settings->get('system')->put('simply_favicon', !empty($_POST['simply_favicon']));
|
(new Label(__('Enable favorite icon')))->for('simply_favicon')->class('classic'),
|
||||||
},
|
]),
|
||||||
]);
|
(new Note())->text(__("You must place an image called favicon.png or .jpg or .ico into your blog's public directory."))->class('form-note'),
|
||||||
|
])->render() .
|
||||||
|
'</p></div><div class="col">' .
|
||||||
|
(
|
||||||
|
empty($exists) ?
|
||||||
|
'<p>' . __('There are no favicon in blog public directory') . '</p>' :
|
||||||
|
'<p>' . __('Current favicons:') . '</p><ul class="nice">' . implode($exists) . '</ul>'
|
||||||
|
) .
|
||||||
|
'</div></div><br class="clear" /></div>';
|
||||||
|
},
|
||||||
|
'adminBeforeBlogSettingsUpdate' => function ($blog_settings) {
|
||||||
|
$blog_settings->get('system')->put('simply_favicon', !empty($_POST['simply_favicon']));
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,74 +10,63 @@
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
|
|
||||||
dcCore::app()->addBehavior('publicHeadContent', ['publicSimplyFavicon', 'publicHeadContent']);
|
namespace Dotclear\Plugin\simplyFavicon;
|
||||||
|
|
||||||
class publicSimplyFavicon extends dcUrlHandlers
|
use dcCore;
|
||||||
|
use dcNsProcess;
|
||||||
|
use path;
|
||||||
|
|
||||||
|
class Frontend extends dcNsProcess
|
||||||
{
|
{
|
||||||
public static $mimetypes = [
|
public static function init(): bool
|
||||||
'ico' => 'image/x-icon',
|
|
||||||
'png' => 'image/png',
|
|
||||||
'bmp' => 'image/bmp',
|
|
||||||
'gif' => 'image/gif',
|
|
||||||
'jpg' => 'image/jpeg',
|
|
||||||
'mng' => 'video/x-mng',
|
|
||||||
];
|
|
||||||
|
|
||||||
public static function simplyFaviconUrl($arg)
|
|
||||||
{
|
{
|
||||||
$public_path = path::fullFromRoot(dcCore::app()->blog->settings->get('system')->get('public_path'), DC_ROOT);
|
self::$init = defined('DC_RC_PATH');
|
||||||
|
|
||||||
if (dcCore::app()->blog->settings->get('system')->get('simply_favicon')
|
return self::$init;
|
||||||
&& !empty($arg)
|
|
||||||
&& array_key_exists($arg, self::$mimetypes)
|
|
||||||
&& file_exists($public_path . '/favicon.' . $arg)
|
|
||||||
) {
|
|
||||||
header('Content-Type: ' . self::$mimetypes[$arg] . ';');
|
|
||||||
readfile($public_path . '/favicon.' . $arg);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
self::p404();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function publicHeadContent()
|
public static function process(): bool
|
||||||
{
|
{
|
||||||
if (!dcCore::app()->blog->settings->get('system')->get('simply_favicon')) {
|
if (!self::$init) {
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$public_path = path::fullFromRoot(dcCore::app()->blog->settings->get('system')->get('public_path'), DC_ROOT) . '/favicon.';
|
dcCore::app()->addBehavior('publicHeadContent', function () {
|
||||||
$public_url = dcCore::app()->blog->url . dcCore::app()->url->getBase('simplyFavicon') . '.';
|
if (!dcCore::app()->blog->settings->get('system')->get('simply_favicon')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// ico : IE6
|
$public_path = path::fullFromRoot(dcCore::app()->blog->settings->get('system')->get('public_path'), DC_ROOT) . '/favicon.';
|
||||||
if (file_exists($public_path . 'ico') && '?' != substr(dcCore::app()->blog->url, -1)) {
|
$public_url = dcCore::app()->blog->url . dcCore::app()->url->getBase('simplyFavicon') . '.';
|
||||||
echo
|
|
||||||
'<link rel="SHORTCUT ICON" type="image/x-icon" href="' . $public_url . 'ico" />' . "\n";
|
|
||||||
}
|
|
||||||
// png: apple and others
|
|
||||||
if (file_exists($public_path . 'png')) {
|
|
||||||
echo
|
|
||||||
'<link rel="apple-touch-icon" href="' . $public_url . 'png" />' . "\n" .
|
|
||||||
'<link rel="icon" type="image/png" href="' . $public_url . 'png" />' . "\n";
|
|
||||||
// all others
|
|
||||||
} else {
|
|
||||||
foreach (self::$mimetypes as $ext => $mime) {
|
|
||||||
if (in_array($ext, ['ico', 'png'])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (file_exists($public_path . $ext)) {
|
|
||||||
echo
|
|
||||||
'<link rel="icon" type="' . $mime . '" href="' . $public_url . $ext . '" />' . "\n";
|
|
||||||
|
|
||||||
break;
|
// ico : IE6
|
||||||
|
if (file_exists($public_path . 'ico') && '?' != substr(dcCore::app()->blog->url, -1)) {
|
||||||
|
echo
|
||||||
|
'<link rel="SHORTCUT ICON" type="image/x-icon" href="' . $public_url . 'ico" />' . "\n";
|
||||||
|
}
|
||||||
|
// png: apple and others
|
||||||
|
if (file_exists($public_path . 'png')) {
|
||||||
|
echo
|
||||||
|
'<link rel="apple-touch-icon" href="' . $public_url . 'png" />' . "\n" .
|
||||||
|
'<link rel="icon" type="image/png" href="' . $public_url . 'png" />' . "\n";
|
||||||
|
// all others
|
||||||
|
} else {
|
||||||
|
foreach (Urlhandler::$mimetypes as $ext => $mime) {
|
||||||
|
if (in_array($ext, ['ico', 'png'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (file_exists($public_path . $ext)) {
|
||||||
|
echo
|
||||||
|
'<link rel="icon" type="' . $mime . '" href="' . $public_url . $ext . '" />' . "\n";
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,35 @@
|
||||||
* @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;
|
|
||||||
|
namespace Dotclear\Plugin\simplyFavicon;
|
||||||
|
|
||||||
|
use dcCore;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
dcCore::app()->url->register(
|
||||||
|
'simplyFavicon',
|
||||||
|
'favicon',
|
||||||
|
'^favicon.(.*?)$',
|
||||||
|
[UrlHandler::class, 'simplyFaviconUrl']
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Clearbricks::lib()->autoload(['publicSimplyFavicon' => __DIR__ . '/_public.php']);
|
|
||||||
|
|
||||||
dcCore::app()->url->register('simplyFavicon', 'favicon', '^favicon.(.*?)$', ['publicSimplyFavicon', 'simplyFaviconUrl']);
|
|
||||||
|
|
48
src/UrlHandler.php
Normal file
48
src/UrlHandler.php
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @brief simplyFavicon, a plugin for Dotclear 2
|
||||||
|
*
|
||||||
|
* @package Dotclear
|
||||||
|
* @subpackage Plugin
|
||||||
|
*
|
||||||
|
* @author Jean-Christian Denis
|
||||||
|
*
|
||||||
|
* @copyright Jean-Christian Denis
|
||||||
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Dotclear\Plugin\simplyFavicon;
|
||||||
|
|
||||||
|
use dcCore;
|
||||||
|
use dcUrlHandlers;
|
||||||
|
use path;
|
||||||
|
|
||||||
|
class UrlHandler extends dcUrlHandlers
|
||||||
|
{
|
||||||
|
public static $mimetypes = [
|
||||||
|
'ico' => 'image/x-icon',
|
||||||
|
'png' => 'image/png',
|
||||||
|
'bmp' => 'image/bmp',
|
||||||
|
'gif' => 'image/gif',
|
||||||
|
'jpg' => 'image/jpeg',
|
||||||
|
'mng' => 'video/x-mng',
|
||||||
|
];
|
||||||
|
|
||||||
|
public static function simplyFaviconUrl($arg)
|
||||||
|
{
|
||||||
|
$public_path = path::fullFromRoot(dcCore::app()->blog->settings->get('system')->get('public_path'), DC_ROOT);
|
||||||
|
|
||||||
|
if (dcCore::app()->blog->settings->get('system')->get('simply_favicon')
|
||||||
|
&& !empty($arg)
|
||||||
|
&& array_key_exists($arg, self::$mimetypes)
|
||||||
|
&& file_exists($public_path . '/favicon.' . $arg)
|
||||||
|
) {
|
||||||
|
header('Content-Type: ' . self::$mimetypes[$arg] . ';');
|
||||||
|
readfile($public_path . '/favicon.' . $arg);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::p404();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue