simplyFavicon/_public.php

84 lines
2.6 KiB
PHP
Raw Normal View History

2021-08-16 20:36:26 +00:00
<?php
2021-09-02 21:01:31 +00:00
/**
* @brief simplyFavicon, a plugin for Dotclear 2
2021-11-06 01:23:40 +00:00
*
2021-09-02 21:01:31 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-06 01:23:40 +00:00
*
2021-09-02 21:01:31 +00:00
* @author Jean-Christian Denis
2021-11-06 01:23:40 +00:00
*
2021-09-02 21:01:31 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-11-06 01:23:40 +00:00
if (!defined('DC_RC_PATH')) {
2021-08-19 21:33:19 +00:00
return;
2021-08-16 21:44:38 +00:00
}
2021-08-16 20:36:26 +00:00
2022-11-14 22:02:42 +00:00
dcCore::app()->addBehavior('publicHeadContent', ['publicSimplyFavicon', 'publicHeadContent']);
2021-08-16 20:36:26 +00:00
class publicSimplyFavicon extends dcUrlHandlers
{
2021-11-06 01:23:40 +00:00
public static $mimetypes = [
2021-08-19 21:33:19 +00:00
'ico' => 'image/x-icon',
'png' => 'image/png',
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpg' => 'image/jpeg',
2022-11-14 22:02:42 +00:00
'mng' => 'video/x-mng',
2021-11-06 01:23:40 +00:00
];
2021-09-02 21:01:31 +00:00
2021-08-19 21:33:19 +00:00
public static function simplyFaviconUrl($arg)
{
2022-11-14 22:02:42 +00:00
$public_path = path::fullFromRoot(dcCore::app()->blog->settings->system->public_path, DC_ROOT);
2021-09-02 21:01:31 +00:00
2022-11-14 22:02:42 +00:00
if (dcCore::app()->blog->settings->system->simply_favicon
2021-11-06 09:19:54 +00:00
&& !empty($arg)
&& array_key_exists($arg, self::$mimetypes)
&& file_exists($public_path . '/favicon.' . $arg)
2021-08-19 21:33:19 +00:00
) {
2021-11-06 09:19:54 +00:00
header('Content-Type: ' . self::$mimetypes[$arg] . ';');
readfile($public_path . '/favicon.' . $arg);
exit;
2021-08-19 21:33:19 +00:00
}
2021-11-06 01:23:40 +00:00
2021-11-06 09:19:54 +00:00
self::p404();
return null;
2021-08-19 21:33:19 +00:00
}
2021-09-02 21:01:31 +00:00
2022-11-14 22:02:42 +00:00
public static function publicHeadContent()
2021-08-19 21:33:19 +00:00
{
2022-11-14 22:02:42 +00:00
if (!dcCore::app()->blog->settings->system->simply_favicon) {
2021-11-06 09:19:54 +00:00
return null;
2021-08-19 21:33:19 +00:00
}
2021-09-02 21:01:31 +00:00
2022-11-14 22:02:42 +00:00
$public_path = path::fullFromRoot(dcCore::app()->blog->settings->system->public_path, DC_ROOT) . '/favicon.';
$public_url = dcCore::app()->blog->url . dcCore::app()->url->getBase('simplyFavicon') . '.';
2021-09-02 21:01:31 +00:00
2021-08-19 21:33:19 +00:00
// ico : IE6
2022-11-14 22:02:42 +00:00
if (file_exists($public_path . 'ico') && '?' != substr(dcCore::app()->blog->url, -1)) {
2021-11-06 01:23:40 +00:00
echo
2021-08-19 21:33:19 +00:00
'<link rel="SHORTCUT ICON" type="image/x-icon" href="' . $public_url . 'ico" />' . "\n";
}
// png: apple and others
if (file_exists($public_path . 'png')) {
2021-11-06 01:23:40 +00:00
echo
2021-08-19 21:33:19 +00:00
'<link rel="apple-touch-icon" href="' . $public_url . 'png" />' . "\n" .
'<link rel="icon" type="image/png" href="' . $public_url . 'png" />' . "\n";
// all others
2021-11-06 09:19:54 +00:00
} else {
foreach (self::$mimetypes as $ext => $mime) {
if (in_array($ext, ['ico', 'png'])) {
continue;
}
2021-08-19 21:33:19 +00:00
if (file_exists($public_path . $ext)) {
echo
'<link rel="icon" type="' . $mime . '" href="' . $public_url . $ext . '" />' . "\n";
2021-11-06 01:23:40 +00:00
2021-08-19 21:33:19 +00:00
break;
}
}
}
}
2021-11-06 01:23:40 +00:00
}