forked from jbanety/plg_system_etdeucookie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetdeucookie.php
68 lines (53 loc) · 2.44 KB
/
etdeucookie.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* @package ETD EU Cookie
*
* @version 1.0
* @copyright Copyright (C) 2015 ETD Solutions. Tous droits réservés.
* @license Apache Version 2 (https://raw.githubusercontent.com/jbanety/etdeucookie/master/LICENSE.md)
* @author ETD Solutions http://etd-solutions.com
**/
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.plugin.plugin');
class plgSystemEtdeucookie extends JPlugin {
function onBeforeRender() {
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
// Seulement sur le site.
if ($app->isSite()) {
// On récupère le cookie.
$cookie = $app->input->cookie->get('etdeucookie');
// On ne travaille que si le cookie n'est pas accepté.
if ($cookie !== "ok") {
// On récupère les paramètres.
$bg = $this->params->get('bg', '#000000');
$color = $this->params->get('color', '#FFFFFF');
$message = $this->params->get('message', '');
//$article_id = $this->params->get('article_id', '');
$html = array();
$doc->addStyleDeclaration('
#etd-cookie{font:normal 12px/16px Arial,Verdana,sans-serif;position:fixed;z-index:99999;top:0;right:0;margin:0 auto;color:' . $color . ';background:' . $bg. ';padding:5px}
#etd-cookie-t{float:left;padding:5px;width:85%}
#etd-cookie-b{float:left;padding:5px;width:15%}
@media(max-width:767px){#etd-cookie-t,#etd-cookie-b{float:none;width:100%;text-align:center}}');
$html[] = '<div id="etd-cookie">';
$html[] = ' <div id="etd-cookie-t">' . addslashes($message) . '</div>';
$html[] = ' <div id="etd-cookie-b"><button type="button" class="btn btn-default btn-sm">Poursuivre</button>';
$html[] = '</div>';
JHtml::_('jquery.framework');
$doc->addScriptDeclaration("
jQuery(document).on('ready', function() {
$('body').append('" . implode($html) . "');
$('#etd-cookie-b button').on('click', function(e) {
e.preventDefault();
var t = new Date();
t.setMilliseconds(t.getMilliseconds() + 30 * 864e+5)
document.cookie = 'etdeucookie=ok; expires=' + t.toUTCString();
$('#etd-cookie').remove();
});
});");
}
}
}
}