simplyFavicon/_public.php

85 lines
2.3 KiB
PHP
Raw Normal View History

2021-08-16 20:36:26 +00:00
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
# This file is part of simplyFavicon, a plugin for Dotclear 2.
#
# Copyright (c) 2009-2011 JC Denis and contributors
# jcdenis@gdwd.com
#
# Licensed under the GPL version 2.0 license.
# A copy of this license is available in LICENSE file or at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------
2021-08-16 21:44:38 +00:00
if (!defined('DC_RC_PATH')){
return;
}
2021-08-16 20:36:26 +00:00
2021-08-16 21:44:38 +00:00
$core->addBehavior('publicHeadContent', ['publicSimplyFavicon','publicHeadContent']);
2021-08-16 20:36:26 +00:00
class publicSimplyFavicon extends dcUrlHandlers
{
public static $mimetypes = array(
'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)
{
global $core;
$mimetypes = self::$mimetypes;
2021-08-16 21:46:51 +00:00
$public_path = path::real(path::fullFromRoot($core->blog->settings->system->public_path, DC_ROOT)) . '/favicon.';
2021-08-16 20:36:26 +00:00
if (!$core->blog->settings->system->simply_favicon
|| empty($arg)
2021-08-16 21:44:38 +00:00
|| !array_key_exists($arg, $mimetypes)
|| file_exists($public_path . 'favicon' . $arg)
2021-08-16 20:36:26 +00:00
) {
2021-08-16 21:44:38 +00:00
throw new Exception ("Page not found", 404);
2021-08-16 20:36:26 +00:00
}
else {
2021-08-16 21:44:38 +00:00
header('Content-Type: ' . $mimetypes[$arg] . ';');
readfile($public_path . $arg);
2021-08-16 20:36:26 +00:00
exit;
}
}
public static function publicHeadContent($core)
{
2021-08-16 21:44:38 +00:00
if (!$core->blog->settings->system->simply_favicon){
return;
}
2021-08-16 20:36:26 +00:00
$mimetypes = self::$mimetypes;
2021-08-16 21:46:51 +00:00
$public_path = path::real(path::fullFromRoot($core->blog->settings->system->public_path, DC_ROOT)) . '/favicon.';
2021-08-16 21:44:38 +00:00
$public_url = $core->blog->url.$core->url->getBase('simplyFavicon') . '.';
2021-08-16 20:36:26 +00:00
// ico : IE6
2021-08-16 21:44:38 +00:00
if (file_exists($public_path . 'ico') && '?' != substr($core->blog->url, -1)) {
2021-08-16 20:36:26 +00:00
echo
2021-08-16 21:44:38 +00:00
'<link rel="SHORTCUT ICON" type="image/x-icon" href="' . $public_url . 'ico" />' . "\n";
2021-08-16 20:36:26 +00:00
}
// png: apple and others
2021-08-16 21:44:38 +00:00
if (file_exists($public_path . 'png')) {
2021-08-16 20:36:26 +00:00
echo
2021-08-16 21:44:38 +00:00
'<link rel="apple-touch-icon" href="' . $public_url . 'png" />' . "\n" .
'<link rel="icon" type="image/png" href="' . $public_url . 'png" />' . "\n";
2021-08-16 20:36:26 +00:00
}
// all others
else {
foreach($mimetypes as $ext => $mime)
{
2021-08-16 21:44:38 +00:00
if (file_exists($public_path . $ext)) {
2021-08-16 20:36:26 +00:00
echo
2021-08-16 21:44:38 +00:00
'<link rel="icon" type="' . $mime . '" href="' . $public_url . $ext . '" />' . "\n";
2021-08-16 20:36:26 +00:00
break;
}
}
}
}
}