From 66aea0eed15c8afd8f1052e70ec9a09a01a64adb Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 1 Nov 2016 12:59:51 -0400 Subject: [PATCH] closes #5167 --- package.json | 1 + public/language/en_GB/global.json | 6 +- public/src/admin/settings/cookies.js | 15 ++++ public/src/app.js | 36 ++++++++++ src/controllers/api.js | 15 ++++ src/meta/css.js | 5 +- src/meta/js.js | 3 +- src/views/admin/partials/menu.tpl | 2 + src/views/admin/settings/advanced.tpl | 15 ---- src/views/admin/settings/cookies.tpl | 98 +++++++++++++++++++++++++++ 10 files changed, 177 insertions(+), 19 deletions(-) create mode 100644 public/src/admin/settings/cookies.js create mode 100644 src/views/admin/settings/cookies.tpl diff --git a/package.json b/package.json index 074b21da55..0bf043339d 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "connect-multiparty": "^2.0.0", "connect-redis": "~3.1.0", "cookie-parser": "^1.3.3", + "cookieconsent": "^3.0.1", "cron": "^1.0.5", "csurf": "^1.6.1", "daemon": "~1.1.0", diff --git a/public/language/en_GB/global.json b/public/language/en_GB/global.json index 69dddaf752..57be9a9468 100644 --- a/public/language/en_GB/global.json +++ b/public/language/en_GB/global.json @@ -125,5 +125,9 @@ "unsaved-changes": "You have unsaved changes. Are you sure you wish to navigate away?", "reconnecting-message": "Looks like your connection to %1 was lost, please wait while we try to reconnect.", - "play": "Play" + "play": "Play", + + "cookies.message": "This website uses cookies to ensure you get the best experience on our website.", + "cookies.accept": "Got it!", + "cookies.learn_more": "Learn More" } diff --git a/public/src/admin/settings/cookies.js b/public/src/admin/settings/cookies.js new file mode 100644 index 0000000000..d113d99dba --- /dev/null +++ b/public/src/admin/settings/cookies.js @@ -0,0 +1,15 @@ +'use strict'; + +/* globals define */ + +define('admin/settings/cookies', [ + 'admin/modules/colorpicker' +], function (colorpicker) { + var Module = {}; + + Module.init = function () { + colorpicker.enable($('[data-colorpicker="1"]')); + }; + + return Module; +}); \ No newline at end of file diff --git a/public/src/app.js b/public/src/app.js index 54992b0e7e..d8aa8cc979 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -55,6 +55,7 @@ app.cacheBuster = null; overrides.overrideTimeago(); createHeaderTooltips(); app.showEmailConfirmWarning(); + app.showCookieWarning(); socket.removeAllListeners('event:nodebb.ready'); socket.on('event:nodebb.ready', function (data) { @@ -622,4 +623,39 @@ app.cacheBuster = null; document.head.appendChild(linkEl); }; + + app.showCookieWarning = function () { + if (!config.cookies.enabled) { + // Only show warning if enabled (obviously) + return; + } else if (window.location.pathname.startsWith(config.relative_path + '/admin')) { + // No need to show cookie consent warning in ACP + return; + } + + var consentConfig = { + "palette": { + "popup": { + "background": config.cookies.palette.background, + "text": config.cookies.palette.text + }, + "button": { + "background": config.cookies.palette.button, + "text": config.cookies.palette.buttonText + } + }, + "theme": config.cookies.style, + "position": config.cookies.position, + "content": { + "dismiss": config.cookies.dismiss, + "link": config.cookies.link + } + }; + + if (config.cookies.message) { + consentConfig.content.message = config.cookies.message; + } + + window.cookieconsent.initialise(consentConfig); + }; }()); diff --git a/src/controllers/api.js b/src/controllers/api.js index ee35aaa55d..d904f7f331 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -63,6 +63,21 @@ apiController.getConfig = function (req, res, next) { config.searchEnabled = plugins.hasListeners('filter:search.query'); config.bootswatchSkin = 'default'; + config.cookies = { + enabled: parseInt(meta.config.cookieConsentEnabled, 10) === 1, + position: meta.config.cookieConsentPosition || 'bottom', + style: meta.config.cookieConsentStyle || 'edgeless', + message: meta.config.cookieConsentMessage || '[[global:cookies.message]]', + dismiss: meta.config.cookieConsentDismiss || '[[global:cookies.accept]]', + link: meta.config.cookieConsentLink || '[[global:cookies.learn_more]]', + palette: { + background: meta.config.cookieConsentPaletteBackground || '#edeff5', + text: meta.config.cookieConsentPaletteText || '#838391', + button: meta.config.cookieConsentPaletteButton || '#59b3d0', + buttonText: meta.config.cookieConsentPaletteButtonText || '#ffffff', + } + }; + async.waterfall([ function (next) { if (!req.user) { diff --git a/src/meta/css.js b/src/meta/css.js index ce31ea1f13..7284f12540 100644 --- a/src/meta/css.js +++ b/src/meta/css.js @@ -48,11 +48,11 @@ module.exports = function (Meta) { async.waterfall([ function (next) { - getStyleSource(plugins.lessFiles, '\n@import ".', '.less', next); + getStyleSource(plugins.cssFiles, '\n@import (inline) ".', '.css', next); }, function (src, next) { source += src; - getStyleSource(plugins.cssFiles, '\n@import (inline) ".', '.css', next); + getStyleSource(plugins.lessFiles, '\n@import ".', '.less', next); }, function (src, next) { source += src; @@ -67,6 +67,7 @@ module.exports = function (Meta) { source += '\n@import (inline) "..' + path.sep + '..' + path.sep + 'public/vendor/jquery/css/smoothness/jquery-ui.css";'; source += '\n@import (inline) "..' + path.sep + '..' + path.sep + 'public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.css";'; + source += '\n@import (inline) "..' + path.sep + '..' + path.sep + 'node_modules/cookieconsent/build/cookieconsent.min.css";'; source += '\n@import (inline) "..' + path.sep + 'public/vendor/colorpicker/colorpicker.css";'; source += '\n@import "..' + path.sep + '..' + path.sep + 'public/less/flags.less";'; source += '\n@import "..' + path.sep + '..' + path.sep + 'public/less/blacklist.less";'; diff --git a/src/meta/js.js b/src/meta/js.js index cfb588125d..f836d2e5f3 100644 --- a/src/meta/js.js +++ b/src/meta/js.js @@ -38,7 +38,8 @@ module.exports = function (Meta) { 'public/src/ajaxify.js', 'public/src/overrides.js', 'public/src/widgets.js', - "./node_modules/promise-polyfill/promise.js" + "./node_modules/promise-polyfill/promise.js", + "./node_modules/cookieconsent/build/cookieconsent.min.js" ], // files listed below are only available client-side, or are bundled in to reduce # of network requests on cold load diff --git a/src/views/admin/partials/menu.tpl b/src/views/admin/partials/menu.tpl index 712155a30b..7e4f890730 100644 --- a/src/views/admin/partials/menu.tpl +++ b/src/views/admin/partials/menu.tpl @@ -39,6 +39,7 @@
  • Pagination
  • Tags
  • Notifications
  • +
  • Cookies
  • Web Crawler
  • Sockets
  • Advanced
  • @@ -189,6 +190,7 @@
  • Pagination
  • Tags
  • Notifications
  • +
  • Cookies
  • Web Crawler
  • Sockets
  • Advanced
  • diff --git a/src/views/admin/settings/advanced.tpl b/src/views/admin/settings/advanced.tpl index f845d06a1c..6d9b6a94c0 100644 --- a/src/views/admin/settings/advanced.tpl +++ b/src/views/admin/settings/advanced.tpl @@ -53,21 +53,6 @@ -
    -
    Cookies
    -
    -
    -
    - -
    -

    - Leave blank for default -

    -
    -
    -
    -
    -
    Traffic Management
    diff --git a/src/views/admin/settings/cookies.tpl b/src/views/admin/settings/cookies.tpl new file mode 100644 index 0000000000..72424f96ec --- /dev/null +++ b/src/views/admin/settings/cookies.tpl @@ -0,0 +1,98 @@ + + +
    +
    EU Consent
    +
    +
    +
    +
    + +
    +
    +
    + + +

    + Leave blank to use NodeBB localised defaults +

    +
    +
    + + +

    + Leave blank to use NodeBB localised defaults +

    +
    +
    + + +

    + Leave blank to use NodeBB localised defaults +

    +
    +
    +
    +
    + +
    +
    EU Consent
    +
    +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    +
    +
    + +
    +
    Settings
    +
    +
    +
    + +
    +

    + Leave blank for default +

    +
    +
    +
    +
    + +