diff --git a/src/Extension/MokoWaaS.php b/src/Extension/MokoWaaS.php index 7506d27..680c55f 100644 --- a/src/Extension/MokoWaaS.php +++ b/src/Extension/MokoWaaS.php @@ -85,6 +85,7 @@ class MokoWaaS extends CMSPlugin { $this->enforceMasterUser(); $this->enforceLoginSupportUrls(); + $this->enforceAtumBranding(); $this->enforceAdminSessionTimeout(); $this->enforceUploadRestrictions(); } @@ -628,8 +629,6 @@ class MokoWaaS extends CMSPlugin } $this->injectFavicon($doc); - $this->injectAdminLogo($doc); - $this->injectLoginLogo($doc); $this->injectColorScheme($doc); $this->injectCustomCss($doc); } @@ -1066,6 +1065,85 @@ class MokoWaaS extends CMSPlugin return array_unique($hidden); } + // ------------------------------------------------------------------ + // Atum Template Branding (called from onAfterInitialise) + // ------------------------------------------------------------------ + + /** + * Enforce Atum admin template branding params. + * + * Sets logoBrandLarge, logoBrandSmall, loginLogo, and alt text + * in the Atum template style params. Uses the plugin's media + * folder as the image source. Only writes to DB when values + * have drifted. + * + * @return void + * + * @since 02.00.00 + */ + protected function enforceAtumBranding() + { + $mediaBase = 'media/plg_system_mokowaas/'; + + $expected = [ + 'logoBrandLarge' => $mediaBase . 'logo.png', + 'logoBrandSmall' => $mediaBase . 'favicon_256.png', + 'loginLogo' => $mediaBase . 'logo.png', + 'logoBrandLargeAlt' => '', + 'logoBrandSmallAlt' => '', + 'loginLogoAlt' => '', + 'emptyLogoBrandLargeAlt' => '1', + 'emptyLogoBrandSmallAlt' => '1', + 'emptyLoginLogoAlt' => '1', + ]; + + $db = Factory::getDbo(); + $query = $db->getQuery(true) + ->select([$db->quoteName('id'), $db->quoteName('params')]) + ->from($db->quoteName('#__template_styles')) + ->where($db->quoteName('template') . ' = ' + . $db->quote('atum')) + ->where($db->quoteName('client_id') . ' = 1'); + + $db->setQuery($query); + $styles = $db->loadObjectList(); + + if (empty($styles)) + { + return; + } + + foreach ($styles as $style) + { + $params = new \Joomla\Registry\Registry( + $style->params ?: '{}' + ); + $needsFix = false; + + foreach ($expected as $key => $value) + { + if ($params->get($key) !== $value) + { + $params->set($key, $value); + $needsFix = true; + } + } + + if ($needsFix) + { + $update = $db->getQuery(true) + ->update($db->quoteName('#__template_styles')) + ->set($db->quoteName('params') . ' = ' + . $db->quote($params->toString())) + ->where($db->quoteName('id') . ' = ' + . (int) $style->id); + + $db->setQuery($update); + $db->execute(); + } + } + } + // ------------------------------------------------------------------ // Visual Branding (called from onBeforeCompileHead) // ------------------------------------------------------------------ @@ -1081,19 +1159,11 @@ class MokoWaaS extends CMSPlugin */ protected function injectFavicon($doc) { - $favicon = $this->params->get('custom_favicon', ''); + $mediaBase = 'media/plg_system_mokowaas/'; + $root = Uri::root(); - if (empty($favicon)) - { - return; - } - - $faviconUrl = Uri::root() . $favicon; - - // Remove existing favicons - $links = $doc->_links; - - foreach ($links as $href => $attrs) + // Remove all existing favicon/icon links + foreach ($doc->_links as $href => $attrs) { if (isset($attrs['relation']) && strpos($attrs['relation'], 'icon') !== false) @@ -1102,70 +1172,26 @@ class MokoWaaS extends CMSPlugin } } - $doc->addFavicon($faviconUrl); - } - - /** - * Inject CSS to replace the admin header logo. - * - * @param \Joomla\CMS\Document\HtmlDocument $doc - * - * @return void - * - * @since 02.00.00 - */ - protected function injectAdminLogo($doc) - { - $logo = $this->params->get('admin_logo', ''); - - if (empty($logo)) - { - return; - } - - $logoUrl = Uri::root() . $logo; - - $doc->addStyleDeclaration( - ".logo img {" - . " content: url('" . $logoUrl . "');" - . " max-height: 40px; width: auto;" - . "}" + // SVG favicon (modern browsers, preferred) + $doc->addHeadLink( + $root . $mediaBase . 'favicon.svg', + 'icon', + 'rel', + ['type' => 'image/svg+xml'] ); - } - - /** - * Inject CSS to replace the login page logo. - * - * @param \Joomla\CMS\Document\HtmlDocument $doc - * - * @return void - * - * @since 02.00.00 - */ - protected function injectLoginLogo($doc) - { - $logo = $this->params->get('login_logo', ''); - - if (empty($logo)) - { - return; - } - - $user = $this->app->getIdentity(); - - if (!$user || !$user->guest) - { - return; - } - - $logoUrl = Uri::root() . $logo; - - $doc->addStyleDeclaration( - ".main-brand-logo img," - . " .login-logo img {" - . " content: url('" . $logoUrl . "');" - . " max-height: 80px; width: auto;" - . "}" + // ICO fallback (legacy browsers) + $doc->addHeadLink( + $root . $mediaBase . 'favicon.ico', + 'alternate icon', + 'rel', + ['type' => 'image/vnd.microsoft.icon'] + ); + // PNG for Apple/Android + $doc->addHeadLink( + $root . $mediaBase . 'favicon_256.png', + 'apple-touch-icon', + 'rel', + ['sizes' => '256x256'] ); } diff --git a/src/language/en-GB/plg_system_mokowaas.ini b/src/language/en-GB/plg_system_mokowaas.ini index 58f0a0f..433a5a9 100644 --- a/src/language/en-GB/plg_system_mokowaas.ini +++ b/src/language/en-GB/plg_system_mokowaas.ini @@ -56,14 +56,10 @@ PLG_SYSTEM_MOKOWAAS_DELETE_VERSIONS_DESC="Purge all content version history from ; ===== Visual Branding fieldset ===== PLG_SYSTEM_MOKOWAAS_FIELDSET_VISUAL_LABEL="Visual Branding" -PLG_SYSTEM_MOKOWAAS_FIELDSET_VISUAL_DESC="Custom logos, favicon, admin color scheme, and CSS injection." +PLG_SYSTEM_MOKOWAAS_FIELDSET_VISUAL_DESC="Admin color scheme and CSS injection. Logos and favicon are shipped in the plugin media folder." -PLG_SYSTEM_MOKOWAAS_ADMIN_LOGO_LABEL="Admin Logo" -PLG_SYSTEM_MOKOWAAS_ADMIN_LOGO_DESC="Replaces the Joomla logo in the admin header. Recommended size: 200x40px." -PLG_SYSTEM_MOKOWAAS_LOGIN_LOGO_LABEL="Login Page Logo" -PLG_SYSTEM_MOKOWAAS_LOGIN_LOGO_DESC="Replaces the Joomla logo on the admin login page. Recommended size: 300x80px." -PLG_SYSTEM_MOKOWAAS_FAVICON_LABEL="Favicon" -PLG_SYSTEM_MOKOWAAS_FAVICON_DESC="Custom favicon displayed in browser tabs. Supports .ico, .png, .svg." +PLG_SYSTEM_MOKOWAAS_BRANDING_NOTE_LABEL="Logos & Favicon" +PLG_SYSTEM_MOKOWAAS_BRANDING_NOTE_DESC="Logos and favicon are automatically applied from the plugin media folder (/media/plg_system_mokowaas/). Replace logo.png, favicon.ico, and favicon_256.png to change them." PLG_SYSTEM_MOKOWAAS_COLOR_PRIMARY_LABEL="Primary Color" PLG_SYSTEM_MOKOWAAS_COLOR_PRIMARY_DESC="Main accent color used in the admin template header and buttons." PLG_SYSTEM_MOKOWAAS_COLOR_SIDEBAR_LABEL="Sidebar Color" diff --git a/src/language/en-US/plg_system_mokowaas.ini b/src/language/en-US/plg_system_mokowaas.ini index 58f0a0f..433a5a9 100644 --- a/src/language/en-US/plg_system_mokowaas.ini +++ b/src/language/en-US/plg_system_mokowaas.ini @@ -56,14 +56,10 @@ PLG_SYSTEM_MOKOWAAS_DELETE_VERSIONS_DESC="Purge all content version history from ; ===== Visual Branding fieldset ===== PLG_SYSTEM_MOKOWAAS_FIELDSET_VISUAL_LABEL="Visual Branding" -PLG_SYSTEM_MOKOWAAS_FIELDSET_VISUAL_DESC="Custom logos, favicon, admin color scheme, and CSS injection." +PLG_SYSTEM_MOKOWAAS_FIELDSET_VISUAL_DESC="Admin color scheme and CSS injection. Logos and favicon are shipped in the plugin media folder." -PLG_SYSTEM_MOKOWAAS_ADMIN_LOGO_LABEL="Admin Logo" -PLG_SYSTEM_MOKOWAAS_ADMIN_LOGO_DESC="Replaces the Joomla logo in the admin header. Recommended size: 200x40px." -PLG_SYSTEM_MOKOWAAS_LOGIN_LOGO_LABEL="Login Page Logo" -PLG_SYSTEM_MOKOWAAS_LOGIN_LOGO_DESC="Replaces the Joomla logo on the admin login page. Recommended size: 300x80px." -PLG_SYSTEM_MOKOWAAS_FAVICON_LABEL="Favicon" -PLG_SYSTEM_MOKOWAAS_FAVICON_DESC="Custom favicon displayed in browser tabs. Supports .ico, .png, .svg." +PLG_SYSTEM_MOKOWAAS_BRANDING_NOTE_LABEL="Logos & Favicon" +PLG_SYSTEM_MOKOWAAS_BRANDING_NOTE_DESC="Logos and favicon are automatically applied from the plugin media folder (/media/plg_system_mokowaas/). Replace logo.png, favicon.ico, and favicon_256.png to change them." PLG_SYSTEM_MOKOWAAS_COLOR_PRIMARY_LABEL="Primary Color" PLG_SYSTEM_MOKOWAAS_COLOR_PRIMARY_DESC="Main accent color used in the admin template header and buttons." PLG_SYSTEM_MOKOWAAS_COLOR_SIDEBAR_LABEL="Sidebar Color" diff --git a/src/mokowaas.xml b/src/mokowaas.xml index 98a4ebc..1d2011e 100644 --- a/src/mokowaas.xml +++ b/src/mokowaas.xml @@ -49,6 +49,10 @@ index.html + favicon.ico + favicon.svg + favicon_256.png + logo.png @@ -182,18 +186,10 @@ label="PLG_SYSTEM_MOKOWAAS_FIELDSET_VISUAL_LABEL" description="PLG_SYSTEM_MOKOWAAS_FIELDSET_VISUAL_DESC" > - - - + installLanguageOverrides(); $this->updateLoginSupportUrls(); + $this->updateAtumBranding(); } return true; @@ -370,6 +371,72 @@ class plgSystemMokoWaaSInstallerScript implements InstallerScriptInterface ); } + /** + * Set Atum admin template branding params at install time. + * + * @return void + * + * @since 02.00.00 + */ + private function updateAtumBranding() + { + $mediaBase = 'media/plg_system_mokowaas/'; + + $expected = [ + 'logoBrandLarge' => $mediaBase . 'logo.png', + 'logoBrandSmall' => $mediaBase . 'favicon_256.png', + 'loginLogo' => $mediaBase . 'logo.png', + 'logoBrandLargeAlt' => '', + 'logoBrandSmallAlt' => '', + 'loginLogoAlt' => '', + 'emptyLogoBrandLargeAlt' => '1', + 'emptyLogoBrandSmallAlt' => '1', + 'emptyLoginLogoAlt' => '1', + ]; + + $db = Factory::getDbo(); + $query = $db->getQuery(true) + ->select([$db->quoteName('id'), $db->quoteName('params')]) + ->from($db->quoteName('#__template_styles')) + ->where($db->quoteName('template') . ' = ' + . $db->quote('atum')) + ->where($db->quoteName('client_id') . ' = 1'); + + $db->setQuery($query); + $styles = $db->loadObjectList(); + + if (empty($styles)) + { + return; + } + + foreach ($styles as $style) + { + $params = new \Joomla\Registry\Registry( + $style->params ?: '{}' + ); + + foreach ($expected as $key => $value) + { + $params->set($key, $value); + } + + $update = $db->getQuery(true) + ->update($db->quoteName('#__template_styles')) + ->set($db->quoteName('params') . ' = ' + . $db->quote($params->toString())) + ->where($db->quoteName('id') . ' = ' + . (int) $style->id); + + $db->setQuery($update); + $db->execute(); + } + + Factory::getApplication()->enqueueMessage( + 'Updated Atum template branding.', 'message' + ); + } + /** * Remove only MokoWaaS overrides from Joomla's global override files. *