Compare commits
10 Commits
b0a1e09c99
...
46b22e1e0c
Author | SHA1 | Date |
---|---|---|
Jean-Christian Paul Denis | 46b22e1e0c | |
Jean-Christian Paul Denis | 578654653a | |
Jean-Christian Paul Denis | f59617f1ef | |
Jean-Christian Paul Denis | 9a2848128f | |
Jean-Christian Paul Denis | efe8358c78 | |
Jean-Christian Paul Denis | 00b27f226e | |
Jean-Christian Paul Denis | 0f74e5dff5 | |
Jean-Christian Paul Denis | 7ae7faa3a1 | |
Jean-Christian Paul Denis | f90d9104b1 | |
Jean-Christian Paul Denis | 8d0047ddcd |
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -1,3 +1,21 @@
|
|||
2023.07.29
|
||||
- require Dotclear 2.27
|
||||
- require PHP 7.4+
|
||||
- update to Dotclear 2.27-dev
|
||||
|
||||
2023.04.23
|
||||
- require Dotclear 2.26
|
||||
- use latest dotclear namespace
|
||||
- remove magix
|
||||
- fix nullsafe warnings
|
||||
|
||||
2023.03.21
|
||||
- require Dotclear 2.26
|
||||
- use PHP namespace
|
||||
- use new plugin structure
|
||||
- use new Form class
|
||||
- add icon url on blog pref
|
||||
|
||||
2022.12.23
|
||||
- use anonymlous functions
|
||||
- code review (phpstan, php-cs-fixer)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[![Release](https://img.shields.io/github/v/release/JcDenis/simplyFavicon)](https://github.com/JcDenis/simplyFavicon/releases)
|
||||
[![Date](https://img.shields.io/github/release-date/JcDenis/simplyFavicon)](https://github.com/JcDenis/simplyFavicon/releases)
|
||||
[![Issues](https://img.shields.io/github/issues/JcDenis/simplyFavicon)](https://github.com/JcDenis/simplyFavicon/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.27-blue.svg)](https://fr.dotclear.org/download)
|
||||
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/simplyFavicon)
|
||||
[![License](https://img.shields.io/github/license/JcDenis/simplyFavicon)](https://github.com/JcDenis/simplyFavicon/blob/master/LICENSE)
|
||||
|
||||
|
@ -19,7 +19,8 @@ It adds a favicon to your blog.
|
|||
_simplyFavicon_ requires:
|
||||
|
||||
* Administrator permissions
|
||||
* Dotclear 2.24
|
||||
* Dotclear 2.27
|
||||
* PHP 7.4+
|
||||
* A readable public directory.
|
||||
|
||||
## USAGE
|
||||
|
|
16
_define.php
16
_define.php
|
@ -18,17 +18,17 @@ $this->registerModule(
|
|||
'Simply favicon',
|
||||
'Multi-agents favicon',
|
||||
'Jean-Christian Denis',
|
||||
'2022.12.23',
|
||||
'2023.07.29',
|
||||
[
|
||||
'requires' => [['core', '2.24']],
|
||||
'requires' => [['core', '2.27']],
|
||||
'permissions' => dcCore::app()->auth->makePermissions([
|
||||
dcAuth::PERMISSION_ADMIN,
|
||||
dcCore::app()->auth::PERMISSION_ADMIN,
|
||||
]),
|
||||
'type' => 'plugin',
|
||||
'support' => 'https://github.com/JcDenis/' . basename(__DIR__),
|
||||
'details' => 'http://plugins.dotaddict.org/dc2/details/' . basename(__DIR__),
|
||||
'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml',
|
||||
'settings' => [
|
||||
'type' => 'plugin',
|
||||
'support' => 'https://github.com/JcDenis/' . basename(__DIR__),
|
||||
'details' => 'http://plugins.dotaddict.org/dc2/details/' . basename(__DIR__),
|
||||
'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml',
|
||||
'settings' => [
|
||||
'blog' => '#params.simply_favicon_params',
|
||||
],
|
||||
]
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="simplyFavicon">
|
||||
<name>Simply favicon</name>
|
||||
<version>2022.12.23</version>
|
||||
<version>2023.07.29</version>
|
||||
<author>Jean-Christian Denis</author>
|
||||
<desc>Multi-agents favicon</desc>
|
||||
<file>https://github.com/JcDenis/simplyFavicon/releases/download/v2022.12.23/plugin-simplyFavicon.zip</file>
|
||||
<da:dcmin>2.24</da:dcmin>
|
||||
<file>https://github.com/JcDenis/simplyFavicon/releases/download/v2023.07.29/plugin-simplyFavicon.zip</file>
|
||||
<da:dcmin>2.27</da:dcmin>
|
||||
<da:details>http://plugins.dotaddict.org/dc2/details/simplyFavicon</da:details>
|
||||
<da:support>https://github.com/JcDenis/simplyFavicon</da:support>
|
||||
</module>
|
||||
|
|
|
@ -9,8 +9,11 @@
|
|||
# DOT NOT MODIFY THIS FILE !
|
||||
#
|
||||
|
||||
l10n::$locales['Enable "%s" extension'] = 'Activer l\'extension "%s"';
|
||||
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['Current favicons:'] = 'Favicons actuels :';
|
||||
l10n::$locales['Multi-agents favicon'] = 'Favicon multi-agents';
|
||||
use Dotclear\Helper\L10n;
|
||||
|
||||
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['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['Multi-agents favicon'] = 'Favicon multi-agents';
|
||||
L10n::$locales['Simply favicon'] = 'Simple favicon';
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"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"
|
||||
"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"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
|
||||
msgid "Enable \"%s\" extension"
|
||||
msgstr "Activer l'extension \"Simply favicon\""
|
||||
msgid "Enable favorite icon"
|
||||
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."
|
||||
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"
|
||||
msgstr "Favicon multi-agents"
|
||||
|
||||
msgid "Simply favicon"
|
||||
msgstr "Simple favicon"
|
||||
|
||||
|
|
108
src/Backend.php
108
src/Backend.php
|
@ -10,37 +10,83 @@
|
|||
* @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);
|
||||
|
||||
dcCore::app()->addBehaviors([
|
||||
'adminBlogPreferencesFormV2' => function ($blog_settings) {
|
||||
$exists = [];
|
||||
$path = path::fullFromRoot((string) $blog_settings->get('system')->get('public_path'), DC_ROOT);
|
||||
foreach (['ico', 'png', 'bmp', 'gif', 'jpg', 'mng'] as $ext) {
|
||||
if (file_exists($path . '/favicon.' . $ext)) {
|
||||
$exists[] = sprintf('<li title="%s">%s</li>', $path . '/favicon.' . $ext, 'favicon.' . $ext);
|
||||
}
|
||||
namespace Dotclear\Plugin\simplyFavicon;
|
||||
|
||||
use dcCore;
|
||||
use dcSettings;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Helper\File\Path;
|
||||
use Dotclear\Helper\Html\Form\{
|
||||
Checkbox,
|
||||
Div,
|
||||
Label,
|
||||
Note,
|
||||
Para
|
||||
};
|
||||
|
||||
class Backend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
return self::status(My::checkContext(My::BACKEND));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
echo
|
||||
'<div class="fieldset clear"><h4 id="simply_favicon_params">' . __('Favicon') . '</h4>' .
|
||||
'<div class="two-cols"><div class="col">' .
|
||||
'<p><label class="classic">' .
|
||||
form::checkbox('simply_favicon', '1', (bool) $blog_settings->get('system')->get('simply_favicon')) .
|
||||
sprintf(__('Enable "%s" extension'), __('Simply favicon')) . '</label></p>' .
|
||||
'<p class="form-note">' .
|
||||
__("You must place an image called favicon.png or .jpg or .ico into your blog's public directory.") .
|
||||
'</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']));
|
||||
},
|
||||
]);
|
||||
dcCore::app()->addBehaviors([
|
||||
'adminBlogPreferencesFormV2' => function (dcSettings $blog_settings): void {
|
||||
// nullsafe
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$exists = [];
|
||||
$path = Path::fullFromRoot((string) $blog_settings->get('system')->get('public_path'), DC_ROOT);
|
||||
foreach (['ico', 'png', 'bmp', 'gif', 'jpg', 'mng'] as $ext) {
|
||||
if (file_exists($path . '/favicon.' . $ext)) {
|
||||
$url = dcCore::app()->blog->url . dcCore::app()->url->getURLFor('simplyFavicon', $ext);
|
||||
$exists[] = '<li><a href="' . $url . '">' . $url . '</a></li>';
|
||||
}
|
||||
}
|
||||
|
||||
echo
|
||||
'<div class="fieldset clear"><h4 id="simply_favicon_params">' . __('Favicon') . '</h4>' .
|
||||
'<div class="two-cols"><div class="col">' .
|
||||
(new Div())
|
||||
->__call('class', ['box'])
|
||||
->__call('items', [[
|
||||
(new Para())
|
||||
->__call('items', [[
|
||||
(new Checkbox('simply_favicon', (bool) $blog_settings->get('system')->get('simply_favicon')))
|
||||
->__call('value', ['1']),
|
||||
(new Label(__('Enable favorite icon'), Label::OUTSIDE_LABEL_AFTER))
|
||||
->__call('for', ['simply_favicon'])
|
||||
->__call('class', ['classic']),
|
||||
]]),
|
||||
(new Note())
|
||||
->__call('text', [__("You must place an image called favicon.png or .jpg or .ico into your blog's public directory.")])
|
||||
->__call('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 (dcSettings $blog_settings): void {
|
||||
$blog_settings->get('system')->put('simply_favicon', !empty($_POST['simply_favicon']));
|
||||
},
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,74 +10,61 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return;
|
||||
}
|
||||
declare(strict_types=1);
|
||||
|
||||
dcCore::app()->addBehavior('publicHeadContent', ['publicSimplyFavicon', 'publicHeadContent']);
|
||||
namespace Dotclear\Plugin\simplyFavicon;
|
||||
|
||||
class publicSimplyFavicon extends dcUrlHandlers
|
||||
use dcCore;
|
||||
use Dotclear\Core\Process;
|
||||
use Dotclear\Helper\File\Path;
|
||||
|
||||
class Frontend extends Process
|
||||
{
|
||||
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 static function init(): bool
|
||||
{
|
||||
$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();
|
||||
|
||||
return null;
|
||||
return self::status(My::checkContext(My::FRONTEND));
|
||||
}
|
||||
|
||||
public static function publicHeadContent()
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!dcCore::app()->blog->settings->get('system')->get('simply_favicon')) {
|
||||
return null;
|
||||
if (!self::status()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$public_path = path::fullFromRoot(dcCore::app()->blog->settings->get('system')->get('public_path'), DC_ROOT) . '/favicon.';
|
||||
$public_url = dcCore::app()->blog->url . dcCore::app()->url->getBase('simplyFavicon') . '.';
|
||||
dcCore::app()->addBehavior('publicHeadContent', function (): void {
|
||||
if (is_null(dcCore::app()->blog) || !dcCore::app()->blog->settings->get('system')->get('simply_favicon')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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 (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";
|
||||
$public_path = Path::fullFromRoot(dcCore::app()->blog->settings->get('system')->get('public_path'), DC_ROOT) . '/favicon.';
|
||||
$public_url = dcCore::app()->blog->url . dcCore::app()->url->getBase('simplyFavicon') . '.';
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?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 Dotclear\Module\MyPlugin;
|
||||
|
||||
class My extends MyPlugin
|
||||
{
|
||||
}
|
|
@ -10,10 +10,33 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return;
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\simplyFavicon;
|
||||
|
||||
use dcCore;
|
||||
use Dotclear\Core\Process;
|
||||
|
||||
class Prepend extends Process
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
return self::status(My::checkContext(My::PREPEND));
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!self::status()) {
|
||||
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']);
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<?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 Dotclear\Helper\File\Path;
|
||||
|
||||
class UrlHandler extends dcUrlHandlers
|
||||
{
|
||||
public static array $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(string $arg): void
|
||||
{
|
||||
// nullsafe
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$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 New Issue