Fix favicon path: try multiple candidate paths for media field value
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:
@@ -71,12 +71,25 @@ $templatePath = 'media/templates/site/mokocassiopeia';
|
|||||||
$faviconHeadTags = '';
|
$faviconHeadTags = '';
|
||||||
if ($params_favicon_source) {
|
if ($params_favicon_source) {
|
||||||
require_once __DIR__ . '/helper/favicon.php';
|
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, '/');
|
$faviconSourceRel = ltrim($params_favicon_source, '/');
|
||||||
$faviconSourceAbs = JPATH_ROOT . '/' . $faviconSourceRel;
|
$faviconSourceAbs = JPATH_ROOT . '/' . $faviconSourceRel;
|
||||||
// If not found, try prepending images/
|
// Try common prefixes if not found
|
||||||
if (!is_file($faviconSourceAbs) && !str_starts_with($faviconSourceRel, 'images/')) {
|
if (!is_file($faviconSourceAbs)) {
|
||||||
$faviconSourceAbs = JPATH_ROOT . '/images/' . $faviconSourceRel;
|
$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';
|
$faviconOutputDir = JPATH_ROOT . '/images/favicons';
|
||||||
$faviconUrlBase = Uri::root(true) . '/images/favicons';
|
$faviconUrlBase = Uri::root(true) . '/images/favicons';
|
||||||
|
|||||||
Reference in New Issue
Block a user