Fix favicon path: try multiple candidate paths for media field value
Some checks failed
Repo Health / Access control (push) Successful in 1s
Repo Health / Release configuration (push) Failing after 4s
Repo Health / Scripts governance (push) Successful in 4s
Repo Health / Repository health (push) Failing after 4s

Joomla's media field returns various path formats. Now tries:
direct path, images/ prefix, template media dir, and basename fallback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan Miller
2026-04-18 13:58:12 -05:00
parent 687a939448
commit cd0f21be5c

View File

@@ -71,12 +71,25 @@ $templatePath = 'media/templates/site/mokocassiopeia';
$faviconHeadTags = '';
if ($params_favicon_source) {
require_once __DIR__ . '/helper/favicon.php';
// Joomla's media field may return 'images/file.png' or just 'file.png'
// Joomla's media field returns paths like:
// 'images/logo.png' (images folder)
// 'media/templates/site/mokocassiopeia/images/logo.png' (template media)
// 'logo.png' (bare filename)
$faviconSourceRel = ltrim($params_favicon_source, '/');
$faviconSourceAbs = JPATH_ROOT . '/' . $faviconSourceRel;
// If not found, try prepending images/
if (!is_file($faviconSourceAbs) && !str_starts_with($faviconSourceRel, 'images/')) {
$faviconSourceAbs = JPATH_ROOT . '/images/' . $faviconSourceRel;
// Try common prefixes if not found
if (!is_file($faviconSourceAbs)) {
$candidates = [
JPATH_ROOT . '/images/' . $faviconSourceRel,
JPATH_ROOT . '/media/templates/site/' . $this->template . '/' . $faviconSourceRel,
JPATH_ROOT . '/media/templates/site/' . $this->template . '/images/' . basename($faviconSourceRel),
];
foreach ($candidates as $candidate) {
if (is_file($candidate)) {
$faviconSourceAbs = $candidate;
break;
}
}
}
$faviconOutputDir = JPATH_ROOT . '/images/favicons';
$faviconUrlBase = Uri::root(true) . '/images/favicons';