From 44232942723b575314425d29b5d8a0bf5ae6fe5f Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Wed, 22 Apr 2026 02:14:18 -0500 Subject: [PATCH] feat: move favicons to template media folder and clean up old locations - Favicons now output to media/templates/site/mokoonyx/images/favicons/ - On install/update: removes old /images/favicons/ directory - On install/update: removes stale favicon files from site root Co-Authored-By: Claude Opus 4.6 (1M context) --- src/index.php | 4 ++-- src/script.php | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/index.php b/src/index.php index add7e31..8e863ff 100644 --- a/src/index.php +++ b/src/index.php @@ -97,8 +97,8 @@ if ($params_favicon_source) { } } } - $faviconOutputDir = JPATH_ROOT . '/images/favicons'; - $faviconUrlBase = Uri::root(true) . '/images/favicons'; + $faviconOutputDir = JPATH_ROOT . '/media/templates/site/' . $this->template . '/images/favicons'; + $faviconUrlBase = Uri::root(true) . '/media/templates/site/' . $this->template . '/images/favicons'; if (MokoFaviconHelper::generate($faviconSourceAbs, $faviconOutputDir)) { $faviconHeadTags = MokoFaviconHelper::getHeadTags($faviconUrlBase); diff --git a/src/script.php b/src/script.php index 83947fe..fa08acb 100644 --- a/src/script.php +++ b/src/script.php @@ -100,14 +100,40 @@ class Tpl_MokoonyxInstallerScript implements InstallerScriptInterface /** * Delete the favicon stamp file so favicons and site.webmanifest * are regenerated on the next page load after install/update. + * Also removes the old /images/favicons/ location. */ private function clearFaviconStamp(): void { - $stampFile = JPATH_ROOT . '/images/favicons/.favicon_generated'; + // Clear new location stamp + $stampFile = JPATH_ROOT . '/media/templates/site/' . self::NEW_NAME . '/images/favicons/.favicon_generated'; if (is_file($stampFile)) { @unlink($stampFile); $this->logMessage('Cleared favicon stamp — will regenerate on next page load.'); } + + // Remove old /images/favicons/ directory from previous versions + $oldDir = JPATH_ROOT . '/images/favicons'; + if (is_dir($oldDir)) { + $files = glob($oldDir . '/*'); + if ($files) { + foreach ($files as $file) { + @unlink($file); + } + } + @unlink($oldDir . '/.favicon_generated'); + @rmdir($oldDir); + $this->logMessage('Removed old favicon directory: images/favicons/'); + } + + // Remove any favicon files left in the site root + $rootFavicons = ['favicon.ico', 'favicon.png', 'apple-touch-icon.png', 'site.webmanifest']; + foreach ($rootFavicons as $file) { + $path = JPATH_ROOT . '/' . $file; + if (is_file($path)) { + @unlink($path); + $this->logMessage('Removed root favicon: ' . $file); + } + } } /**