Skip to content

Commit

Permalink
Merge branch 'feature/integrate-cookieconsent'
Browse files Browse the repository at this point in the history
  • Loading branch information
mystralkk committed Aug 18, 2019
2 parents 4afe012 + 67c7bdd commit 79e6d94
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 13 deletions.
3 changes: 2 additions & 1 deletion language/english.php
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion language/english_utf-8.php
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion language/japanese_utf-8.php
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions public_html/admin/install/config-install.php
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions 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"
}
});
19 changes: 19 additions & 0 deletions public_html/lib-common.php
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions sql/updates/mysql_2.2.0_to_2.2.1.php
Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions sql/updates/pgsql_2.2.0_to_2.2.1.php
Expand Up @@ -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;
}

Expand Down
60 changes: 50 additions & 10 deletions system/classes/Resource.php
Expand Up @@ -41,7 +41,7 @@ class Resource
const DEFAULT_CACHE_LIFESPAN = 604800; // 1 week

const JS_TAG_TEMPLATE = '<script type="text/javascript" src="%s"></script>';
const EXTERNAL_JS_TAG_TEMPLATE = '<script type="text/javascript" src="%s" async defer></script>';
const EXTERNAL_JS_TAG_TEMPLATE = '<script type="text/javascript" src="%s"%s%s></script>';

// Default theme
const DEFAULT_THEME = 'denim';
Expand Down Expand Up @@ -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;
Expand All @@ -517,17 +519,20 @@ 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;
} else {
// 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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 79e6d94

Please sign in to comment.