54 lines
1.6 KiB
PHP
Executable File
54 lines
1.6 KiB
PHP
Executable File
<?php
|
|
namespace Grav\Plugin;
|
|
|
|
use Grav\Common\Plugin;
|
|
|
|
class EuCookiePolicyPlugin extends Plugin
|
|
{
|
|
public static function getSubscribedEvents() {
|
|
return [
|
|
'onPluginsInitialized' => ['onPluginsInitialized', 0],
|
|
];
|
|
}
|
|
|
|
public function onPluginsInitialized()
|
|
{
|
|
if ($this->isAdmin()) {
|
|
$this->active = false;
|
|
return;
|
|
}
|
|
|
|
$this->enable([
|
|
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
|
|
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Add current directory to twig lookup paths.
|
|
*/
|
|
public function onTwigTemplatePaths()
|
|
{
|
|
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
|
|
}
|
|
|
|
/**
|
|
* if enabled on this page, load the JS + CSS theme.
|
|
*/
|
|
public function onTwigSiteVariables()
|
|
{
|
|
$type = strtolower($this->config->get('plugins.eucookiepolicy.type'));
|
|
$this->grav['assets']->addJs('plugin://eucookiepolicy/assets/js/cookiechoices.js');
|
|
$this->grav['assets']->addCss('plugin://eucookiepolicy/assets/css/cookiechoices.css', -999);
|
|
|
|
$twig = $this->grav['twig'];
|
|
$twig->twig_vars['eucookiepolicy_cookie_type'] = $type;
|
|
$twig->twig_vars['eucookiepolicy_url'] = $this->config->get('plugins.eucookiepolicy.url');
|
|
|
|
$twig->twig_vars['eucookiepolicy_markup'] = $twig->twig->render('partials/eucookiepolicy.html.twig', array(
|
|
'eucookiepolicy_cookie_type' => $twig->twig_vars['eucookiepolicy_cookie_type'],
|
|
'eucookiepolicy_url' => $twig->twig_vars['eucookiepolicy_url']
|
|
));
|
|
}
|
|
}
|