Last active
February 5, 2022 15:29
-
-
Save alexandreelise/68d3bddbb6b4633ded8e891c9c443df4 to your computer and use it in GitHub Desktop.
Load Custom Assets In Joomla! Core mod_custom using this layout override
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
/** | |
* Custom Assets | |
* | |
* @version 1.0.0 | |
* @package Customasset | |
* @author Alexandre ELISÉ <[email protected]> | |
* @copyright (c) 2009-2022 . Alexandre ELISÉ . Tous droits réservés. | |
* @license GPL-2.0-and-later GNU General Public License v2.0 or later | |
* @link https://alexapi.cloud | |
*/ | |
use Joomla\CMS\Factory; | |
use Joomla\CMS\HTML\HTMLHelper; | |
use Joomla\CMS\Uri\Uri; | |
defined('_JEXEC') or die; | |
$app = Factory::getApplication(); | |
/** | |
* @var \Joomla\CMS\Document\HtmlDocument $document | |
*/ | |
$document = $app->getDocument(); | |
$appIconsCustomPath = Uri::root() . 'images/touch'; | |
$customHeadTags = <<<CUSTOMHEAD | |
<link rel="apple-touch-icon" sizes="180x180" href="$appIconsCustomPath/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="$appIconsCustomPath/favicon-32x32.png"><link rel="icon" type="image/png" sizes="192x192" href="$appIconsCustomPath/android-chrome-192x192.png"><link rel="icon" type="image/png" sizes="16x16" href="$appIconsCustomPath/favicon-16x16.png"><link rel="manifest" href="/manifest.json"><link rel="mask-icon" href="$appIconsCustomPath/safari-pinned-tab.svg" color="#019aff"><meta name="msapplication-TileColor" content="#ffc40d"><meta name="msapplication-TileImage" content="$appIconsCustomPath/mstile-144x144.png"><meta name="theme-color" content="#ffffff"> | |
CUSTOMHEAD; | |
$document->addCustomTag($customHeadTags); | |
HTMLHelper::_('script', 'https://cdnjs.cloudflare.com/ajax/libs/tarteaucitronjs/1.9.5/tarteaucitron.min.js', | |
[], | |
[ | |
'integrity' => 'sha512-81BpselCKwXBQl7OCqIShbHVaqBx3g6qyPieqC7IPsCzWwAXlwLUKUnAMRvtii3RLp1ZoqLmtg4VLeGm2mUNfw==', | |
'crossorigin' => 'anonymous', | |
'referrerpolicy' => 'no-referrer', | |
]); | |
$cookieConsentScript = <<<COOKIECONSENTSCRIPT | |
tarteaucitron.init({ | |
"privacyUrl": "https://example.com/privacy", | |
"readmoreLink": "https://example.com/readmore", | |
"hashtag": "#cookies", | |
"cookieName": "tarteaucitron", | |
"orientation": "bottom", | |
"showAlertSmall": true, | |
"cookieslist": true, | |
"showIcon": false, | |
"iconPosition": "BottomLeft", | |
"adblocker": false, | |
"DenyAllCta" : true, | |
"AcceptAllCta" : true, | |
"highPrivacy": true, | |
"handleBrowserDNTRequest": false, | |
"removeCredit": true, | |
"moreInfoLink": true, | |
"useExternalCss": false, | |
"useExternalJs": false, | |
"mandatory": true | |
}); | |
COOKIECONSENTSCRIPT; | |
$document->addScriptDeclaration($cookieConsentScript); | |
$cookieConsentServiceScript = <<<COOKIECONSENTSERVICESCRIPT | |
(function (tarteaucitron) { | |
tarteaucitron.user.gtagUa = 'UA-XXXXXXXX-X'; | |
(tarteaucitron.job = tarteaucitron.job || []).push('gtag'); | |
(tarteaucitron.job = tarteaucitron.job || []).push('facebook'); | |
(tarteaucitron.job = tarteaucitron.job || []).push('twitter'); | |
(tarteaucitron.job = tarteaucitron.job || []).push('pinterest'); | |
(tarteaucitron.job = tarteaucitron.job || []).push('youtube'); | |
(tarteaucitron.job = tarteaucitron.job || []).push('vimeo'); | |
(tarteaucitron.job = tarteaucitron.job || []).push('googlemapssearch'); | |
}(window.tarteaucitron)); | |
COOKIECONSENTSERVICESCRIPT; | |
$currentBody = $app->getBody(); | |
$modifiedBody = str_replace('</body>', sprintf('%s%s',$cookieConsentServiceScript, '</body>'), $currentBody); | |
$app->setBody($modifiedBody); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment