From 9fcd472d3f7efe04f6762c12f64f43730a2461b8 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 25 Jun 2023 19:17:26 +0900 Subject: [PATCH] Display the current site's favicon if favicon.ico is requested --- common/framework/Router.php | 6 ++++++ modules/module/conf/module.xml | 13 ++++++------ modules/module/module.view.php | 38 ++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/common/framework/Router.php b/common/framework/Router.php index 4a6c13710..3908b864d 100644 --- a/common/framework/Router.php +++ b/common/framework/Router.php @@ -64,6 +64,12 @@ class Router 'extra_vars' => ['act' => 'dispAdminRewriteTest'], 'priority' => 0, ), + 'favicon\.ico' => array( + 'regexp' => '#^favicon\.ico$#', + 'vars' => [], + 'extra_vars' => ['module' => 'module', 'act' => 'dispModuleCurrentSiteFavicon'], + 'priority' => 0, + ) ); /** diff --git a/modules/module/conf/module.xml b/modules/module/conf/module.xml index 01b315c99..4ea9c0fc6 100644 --- a/modules/module/conf/module.xml +++ b/modules/module/conf/module.xml @@ -6,17 +6,18 @@ + - + - + - + @@ -26,7 +27,7 @@ - + @@ -36,12 +37,12 @@ - + - + diff --git a/modules/module/module.view.php b/modules/module/module.view.php index b93143cc2..a1eb7a6b9 100644 --- a/modules/module/module.view.php +++ b/modules/module/module.view.php @@ -143,6 +143,44 @@ class ModuleView extends Module $this->setTemplateFile('filebox_add'); } + /** + * Display the current site's favicon + */ + public function dispModuleCurrentSiteFavicon() + { + $domain = ModuleModel::getSiteInfoByDomain($_SERVER['HTTP_HOST']) ?: ModuleModel::getDefaultDomainInfo(); + $domain_srl = $domain->domain_srl ?? 0; + $filename = \RX_BASEDIR . 'files/attach/xeicon/' . ($domain_srl ? ($domain_srl . '/') : '') . 'favicon.ico'; + + if (Rhymix\Framework\Storage::exists($filename)) + { + // Handle 304 Not Modified + if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) > filemtime($uploaded_filename)) + { + header('HTTP/1.1 304 Not Modified'); + exit(); + } + + // Clear buffer + while(ob_get_level()) ob_end_clean(); + + // Set headers + header('Content-Type: image/x-icon'); + header('Content-Length: ' . filesize($filename)); + header('Cache-Control: private; max-age=3600'); + header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + + // Print icon and exit + readfile($filename); + exit(); + } + else + { + $this->stop('msg_not_founded'); + $this->setHttpStatusCode(404); + } + } + /** * Moved from mobile class */