diff --git a/language/english.php b/language/english.php
index 701d2214f..f7413f394 100644
--- a/language/english.php
+++ b/language/english.php
@@ -2498,7 +2498,8 @@
'filemanager_videos_player_width' => 'Video player width (px)',
'filemanager_videos_player_height' => 'Video player height (px)',
'filemanager_show_audio_player' => 'Show audio player?',
- 'filemanager_audios_ext' => 'Audio file extensions'
+ 'filemanager_audios_ext' => 'Audio file extensions',
+ 'cookie_consent' => 'Enable Cookie Consent'
);
$LANG_configsubgroups['Core'] = array(
diff --git a/language/english_utf-8.php b/language/english_utf-8.php
index 544de2135..bdd5aeb58 100644
--- a/language/english_utf-8.php
+++ b/language/english_utf-8.php
@@ -2498,7 +2498,8 @@
'filemanager_videos_player_width' => 'Video player width (px)',
'filemanager_videos_player_height' => 'Video player height (px)',
'filemanager_show_audio_player' => 'Show audio player?',
- 'filemanager_audios_ext' => 'Audio file extensions'
+ 'filemanager_audios_ext' => 'Audio file extensions',
+ 'cookie_consent' => 'Enable Cookie Consent'
);
$LANG_configsubgroups['Core'] = array(
diff --git a/language/japanese_utf-8.php b/language/japanese_utf-8.php
index 8cde07a4e..bb5b7dbdf 100644
--- a/language/japanese_utf-8.php
+++ b/language/japanese_utf-8.php
@@ -2496,7 +2496,8 @@
'filemanager_videos_player_width' => '動画プレーヤーの幅',
'filemanager_videos_player_height' => '動画プレーヤーの高さ',
'filemanager_show_audio_player' => 'オーディオプレーヤーを表示する',
- 'filemanager_audios_ext' => 'オーディオファイルの拡張子'
+ 'filemanager_audios_ext' => 'オーディオファイルの拡張子',
+ 'cookie_consent' => 'Cookie Consent(クッキー使用通知)を有効にする'
);
$LANG_configsubgroups['Core'] = array(
diff --git a/public_html/admin/install/config-install.php b/public_html/admin/install/config-install.php
index b0c3957d1..aafb37af0 100644
--- a/public_html/admin/install/config-install.php
+++ b/public_html/admin/install/config-install.php
@@ -35,6 +35,11 @@
die('This file can not be used on its own!');
}
+/**
+ * Install configuration values
+ *
+ * @param ConfigInterface $c
+ */
function install_config(ConfigInterface $c)
{
global $_CONF, $_TABLES;
@@ -61,6 +66,7 @@ function install_config(ConfigInterface $c)
$c->add('meta_tags',0,'select',0,0,23,2000,TRUE, $me, 0);
$c->add('meta_description','Geeklog - The secure Content Management System.','textarea',0,0,NULL,2010,TRUE, $me, 0);
$c->add('meta_keywords','Geeklog, Content Management System, CMS, Open Source, Secure, Security, Blog, Weblog','textarea',0,0,NULL,2020,TRUE, $me, 0);
+ $c->add('cookie_consent',true,'select',0,0,1,2030,true, $me, 0);
$c->add('tab_mail', NULL, 'tab', 0, 1, NULL, 0, TRUE, $me, 1);
$c->add('fs_mail', NULL, 'fieldset', 0, 1, NULL, 0, TRUE, $me, 1);
diff --git a/public_html/javascript/cookie_consent.js b/public_html/javascript/cookie_consent.js
new file mode 100644
index 000000000..9286cca6a
--- /dev/null
+++ b/public_html/javascript/cookie_consent.js
@@ -0,0 +1,20 @@
+/**
+ * Cookie consent v3.1.1
+ */
+
+// To customize appearance and behavior, please visit https://cookieconsent.osano.com/download/
+window.cookieconsent.initialise({
+ "palette": {
+ "popup": {
+ "background": "#000"
+ },
+ "button": {
+ "background": "#f1d600"
+ }
+ },
+ "content": {
+ "message": "This website uses cookies to ensure you get the best experience on our website.",
+ "dismiss": "Got it!",
+ "link": "Learn more"
+ }
+});
diff --git a/public_html/lib-common.php b/public_html/lib-common.php
index 6e2b02855..cfc7b51d5 100644
--- a/public_html/lib-common.php
+++ b/public_html/lib-common.php
@@ -1293,6 +1293,25 @@ function COM_createHTMLDocument(&$content = '', $information = array())
$header->set_var('breadcrumb_trail', $breadcrumbs);
+ // Add Cookie Consent ( https://cookieconsent.osano.com )
+ if (isset($_CONF['cookie_consent']) && $_CONF['cookie_consent']) {
+ $_SCRIPTS->setCssFile(
+ 'cookiconsent', 'https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css',
+ true, array(), 100
+ );
+ $_SCRIPTS->setJavaScriptFile(
+ 'cookie_consent', 'https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js',
+ false, 100, false,
+ array('data-cfasync' => 'false')
+ );
+
+ // To customize appearance and behavior, edit the following file
+ $_SCRIPTS->setJavaScriptFile(
+ 'cookie_consent_config', '/javascript/cookie_consent.js',
+ true, 110
+ );
+ }
+
COM_hit();
// Set template directory
diff --git a/sql/updates/mysql_2.2.0_to_2.2.1.php b/sql/updates/mysql_2.2.0_to_2.2.1.php
index a3f69b886..9de3e1aa9 100644
--- a/sql/updates/mysql_2.2.0_to_2.2.1.php
+++ b/sql/updates/mysql_2.2.0_to_2.2.1.php
@@ -123,6 +123,9 @@ function update_ConfValuesFor221()
$c->del('cookie_password', $me);
$c->del('cookie_ip', $me);
+ // Add cookie consent
+ $c->add('cookie_consent',true,'select',0,0,1,2030,true, $me, 0);
+
return true;
}
diff --git a/sql/updates/pgsql_2.2.0_to_2.2.1.php b/sql/updates/pgsql_2.2.0_to_2.2.1.php
index e7d746234..0f729068f 100644
--- a/sql/updates/pgsql_2.2.0_to_2.2.1.php
+++ b/sql/updates/pgsql_2.2.0_to_2.2.1.php
@@ -125,6 +125,9 @@ function update_ConfValuesFor221()
$c->del('cookie_password', $me);
$c->del('cookie_ip', $me);
+ // Add cookie consent
+ $c->add('cookie_consent',true,'select',0,0,1,2030,true, $me, 0);
+
return true;
}
diff --git a/system/classes/Resource.php b/system/classes/Resource.php
index 199491c9c..78bb9f541 100644
--- a/system/classes/Resource.php
+++ b/system/classes/Resource.php
@@ -41,7 +41,7 @@ class Resource
const DEFAULT_CACHE_LIFESPAN = 604800; // 1 week
const JS_TAG_TEMPLATE = '';
- const EXTERNAL_JS_TAG_TEMPLATE = '';
+ const EXTERNAL_JS_TAG_TEMPLATE = '';
// Default theme
const DEFAULT_THEME = 'denim';
@@ -501,13 +501,15 @@ public function setJavaScript($code, $wrap = false, $isFooter = true)
/**
* Set JavaScript file to load
*
- * @param string $name (not used)
- * @param string $file relative to public_html (must start with '/')
+ * @param string $name (not used)
+ * @param string $file relative to public_html (must start with '/')
* @param bool $isFooter
* @param int $priority
+ * @param bool $isDefer whether to set "defer" property for external files
+ * @param array $attributes additional attributes for script tag
* @return bool
*/
- public function setJavaScriptFile($name, $file, $isFooter = true, $priority = 100)
+ public function setJavaScriptFile($name, $file, $isFooter = true, $priority = 100, $isDefer = true, array $attributes = array())
{
if ($this->isHeaderSet && !$isFooter) {
return false;
@@ -517,8 +519,10 @@ public function setJavaScriptFile($name, $file, $isFooter = true, $priority = 10
if ($this->isExternal($file) && array_search($file, array_column($this->externalJsFiles[$position], 'file')) == 0) {
$this->externalJsFiles[$position][] = array(
- 'file' => $file,
- 'priority' => $priority,
+ 'file' => $file,
+ 'priority' => (int) $priority,
+ 'isDefer' => (bool) $isDefer,
+ 'attributes' => $attributes,
);
return true;
@@ -526,8 +530,9 @@ public function setJavaScriptFile($name, $file, $isFooter = true, $priority = 10
// See if file exists and has not already been added (could happen on multiple calls of the same function by different plugins)
if ($this->exists($this->config['path_html'] . $file) && array_search($file, array_column($this->localJsFiles[$position], 'file')) == 0) {
$this->localJsFiles[$position][] = array(
- 'file' => $file,
- 'priority' => $priority,
+ 'file' => $file,
+ 'priority' => (int) $priority,
+ 'attributes' => $attributes,
);
return true;
@@ -1055,6 +1060,29 @@ private function makeTagsForSystemLibraries($isFooter = true)
return $retval;
}
+ /**
+ * Format attributes for script tag
+ *
+ * @param array $attributes
+ * @return string
+ */
+ private function formatAttributes(array $attributes = array())
+ {
+ $retval = '';
+
+ if (count($attributes) > 0) {
+ foreach ($attributes as $key => $value) {
+ $retval .= sprintf(
+ ' %s="%s"',
+ htmlspecialchars($key, ENT_QUOTES, 'utf-8'),
+ htmlspecialchars($value, ENT_QUOTES, 'utf-8')
+ );
+ }
+ }
+
+ return $retval;
+ }
+
/**
* Returns header code (JavaScript and CSS) to include in the Head of the web page
*
@@ -1138,7 +1166,13 @@ public function getHeader()
usort($this->externalJsFiles['header'], array('\\Geeklog\\Resource', 'comparePriority'));
foreach ($this->externalJsFiles['header'] as $jsFile) {
- $retval .= sprintf(self::EXTERNAL_JS_TAG_TEMPLATE, $jsFile['file']) . PHP_EOL;
+ $defer = isset($jsFile['isDefer']) && $jsFile['isDefer'] ? ' defer' : '';
+ $attributes = '';
+ if (isset($jsFile['attributes'])) {
+ $attributes = $this->formatAttributes($jsFile['attributes']);
+ }
+
+ $retval .= sprintf(self::EXTERNAL_JS_TAG_TEMPLATE, $jsFile['file'], $defer, $attributes) . PHP_EOL;
}
}
@@ -1213,7 +1247,13 @@ public function getFooter()
usort($this->externalJsFiles['footer'], array('\\Geeklog\\Resource', 'comparePriority'));
foreach ($this->externalJsFiles['footer'] as $jsFile) {
- $retval .= sprintf(self::EXTERNAL_JS_TAG_TEMPLATE, $jsFile['file']) . PHP_EOL;
+ $defer = isset($jsFile['isDefer']) && $jsFile['isDefer'] ? ' defer' : '';
+ $attributes = '';
+ if (isset($jsFile['attributes'])) {
+ $attributes = $this->formatAttributes($jsFile['attributes']);
+ }
+
+ $retval .= sprintf(self::EXTERNAL_JS_TAG_TEMPLATE, $jsFile['file'], $defer, $attributes) . PHP_EOL;
}
}