root vor 1 Monat
Commit
3f04561d7f
12 geänderte Dateien mit 457 neuen und 0 gelöschten Zeilen
  1. 30 0
      Cookie.php
  2. 79 0
      hooks.php
  3. 0 0
      index.php
  4. 5 0
      lang/english.php
  5. 0 0
      lang/index.php
  6. 79 0
      lib/css/ihavecookies.css
  7. 0 0
      lib/css/index.php
  8. 0 0
      lib/index.php
  9. 228 0
      lib/js/ihavecookies.js
  10. 0 0
      lib/js/index.php
  11. BIN
      logo.png
  12. 36 0
      whmcs.json

+ 30 - 0
Cookie.php

@@ -0,0 +1,30 @@
+<?php
+
+if (!defined("WHMCS")) { die("This file cannot be accessed directly");}
+
+function Cookie_config()
+{
+  $message = 'We use cookies to ensure that we give you the best experience on our website. By continuing to visit this site you agree to our use of cookies.';
+
+  return [
+    'name'        => 'Cookie Consent',
+    'description' => 'A lightweight addon module that displays a cookie consent message. The addon module displays a message on the user\'s first visit to your website.',
+    'author'      => '<a href="https://www.hardsoftcode.com" target="_blank">HSCode</a>',
+    'language'    => 'english',
+    'version'     => '1.0.1',
+    'fields'      => [
+      'Enable'      => ['FriendlyName' => 'Enable', 'Type' => 'yesno', 'Description' => 'Tick this box to enable the cookie dialog'],
+      'Title'       => ['FriendlyName' => 'Title', 'Type' => 'text', 'Size' => '40', 'Default' => 'Cookies'],
+      'Message'     => ['FriendlyName' => 'Message', 'Type' => 'textarea', 'Rows' => '4', 'Default' => $message, 'Description' => 'HTML can be included within this message'],
+      'Expires'     => ['FriendlyName' => 'Expires', 'Type' => 'text', 'Size' => '10', 'Default' => '30', 'Description' => 'Enter the days for the cookie to expire'],
+      'PolicyURL'   => ['FriendlyName' => 'Cookie Policy URL', 'Type' => 'text', 'Size' => '60'],
+      'RedirectURL' => ['FriendlyName' => 'Decline Redirect URL', 'Type' => 'text', 'Size' => '60'],
+    ]
+  ];
+}
+
+function Cookie_output($vars)
+{
+  header('Location: configaddonmods.php#Cookie');
+  exit;
+}

+ 79 - 0
hooks.php

@@ -0,0 +1,79 @@
+<?php
+
+use WHMCS\Database\Capsule;
+use WHMCS\Config\Setting;
+use WHMCS\Session;
+
+class HSCodeConfig
+{
+  public static function get($config)
+  {
+    $result = Capsule::table('tbladdonmodules')->where(['module' => 'Cookie', 'setting' => $config])->value('value');
+
+    return $result;
+  }
+}
+
+class HSCodeLang
+{
+  public static function get()
+  {
+    if(file_exists(ROOTDIR.'/modules/addons/Cookie/lang/'.strtolower(Session::get('Language')).'.php'))
+    {
+      require(ROOTDIR.'/modules/addons/Cookie/lang/'.strtolower(Session::get('Language')).'.php');
+    }
+    elseif(file_exists(ROOTDIR.'/modules/addons/Cookie/lang/'.strtolower(Setting::getValue('Language')).'.php'))
+    {
+      require(ROOTDIR.'/modules/addons/Cookie/lang/'.strtolower(Setting::getValue('Language')).'.php');
+    }
+    else
+    {
+      require(ROOTDIR.'/modules/addons/Cookie/lang/english.php');
+    }
+
+    return $_ADDONLANG;
+  }
+}
+
+add_hook('ClientAreaFooterOutput', 699855, function($vars)
+{
+  $systemUrl = Setting::getValue('SystemURL');
+  $lang      = HSCodeLang::get();
+  $enable    = HSCodeConfig::get('Enable');
+  $title     = HSCodeConfig::get('Title');
+  $message   = HSCodeConfig::get('Message');
+  $expires   = HSCodeConfig::get('Expires');
+  $policy    = HSCodeConfig::get('PolicyURL');
+  $redirect  = HSCodeConfig::get('RedirectURL');
+
+  if($enable)
+  {
+    return <<<HTML
+    <link href="{$systemUrl}/modules/addons/Cookie/lib/css/ihavecookies.css" rel="stylesheet">
+    <script src="{$systemUrl}/modules/addons/Cookie/lib/js/ihavecookies.js" type="text/javascript"></script>
+
+    <script type="text/javascript">
+    var options = {
+        title: '{$title}',
+        message: '{$message}',
+        delay: 600,
+        expires: '{$expires}',
+        link: '{$policy}',
+        redirect: '{$redirect}',
+        uncheckBoxes: true,
+        acceptBtnLabel: '{$lang["accept"]}',
+        declineBtnLabel: '{$lang["decline"]}',
+        moreInfoLabel: '{$lang["cookiepolicy"]}'
+    }
+
+    $(document).ready(function() {
+        $('body').ihavecookies(options);
+
+        $('#ihavecookiesBtn').on('click', function(){
+            $('body').ihavecookies(options, 'reinit');
+        });
+    });
+    </script>
+HTML;
+  }
+});

+ 0 - 0
index.php


+ 5 - 0
lang/english.php

@@ -0,0 +1,5 @@
+<?php
+
+$_ADDONLANG['accept']                                                           = "Accept";
+$_ADDONLANG['decline']                                                          = "Decline";
+$_ADDONLANG['cookiepolicy']                                                     = "Cookie policy";

+ 0 - 0
lang/index.php


+ 79 - 0
lib/css/ihavecookies.css

@@ -0,0 +1,79 @@
+:root {
+    --dialog-width: 600px;
+    --dialog-color: #043d5f;
+    --title-color: #ffffff;
+    --message-color: #ffffff;
+    --white: #ffffff;
+    --links: #25a2c7;
+    --accept-btn: #4ab98b;
+    --accept-btn-hover: #16a369;
+    --decline-btn: #ee4b5a;
+    --decline-btn-hover: #de2c3d;
+}
+
+/* Cookie Dialog */
+#gdpr-cookie-message {
+    position: fixed;
+    right: 30px;
+    bottom: 30px;
+    max-width: var(--dialog-width);
+    background-color: var(--dialog-color);
+    padding: 20px;
+    border-radius: 5px;
+    box-shadow: 0 6px 6px rgba(0,0,0,0.25);
+    margin-left: 30px;
+}
+#gdpr-cookie-message h4 {
+    color: var(--title-color);
+    font-size: 20px;
+    font-weight: 700;
+    margin-bottom: 10px;
+}
+#gdpr-cookie-message p {
+    color: var(--message-color);
+    font-size: 15px;
+    line-height: 1.5em;
+}
+#gdpr-cookie-message p:last-child {
+    margin-bottom: 0;
+    text-align: right;
+}
+#gdpr-cookie-message a {
+    color: var(--links);
+    text-decoration: none;
+    font-size: 15px;
+    padding-bottom: 2px;
+    border-bottom: 1px dotted rgba(255,255,255,0.75);
+    transition: all 0.3s ease-in;
+}
+#gdpr-cookie-message a:hover {
+    color: var(--white);
+    border-bottom-color: var(--links);
+    transition: all 0.3s ease-in;
+}
+#gdpr-cookie-message button,
+button#ihavecookiesBtn {
+    border: none;
+    background: var(--accept-btn);
+    color: var(--white);
+    font-size: 15px;
+    padding: 7px 40px;
+    border-radius: 3px;
+    margin-left: 15px;
+    cursor: pointer;
+    transition: all 0.3s ease-in;
+}
+#gdpr-cookie-message button:hover {
+    background: var(--accept-btn-hover);
+    color: var(--white);
+    transition: all 0.3s ease-in;
+}
+button#gdpr-cookie-advanced {
+    background: var(--decline-btn);
+    color: var(--white);
+}
+button#gdpr-cookie-advanced:hover {
+  background: var(--decline-btn-hover);
+  color: var(--white);
+  transition: all 0.3s ease-in;
+}

+ 0 - 0
lib/css/index.php


+ 0 - 0
lib/index.php


+ 228 - 0
lib/js/ihavecookies.js

@@ -0,0 +1,228 @@
+/*!
+ * ihavecookies - jQuery plugin for displaying cookie/privacy message
+ * v0.3.2
+ *
+ * Copyright (c) 2018 Ketan Mistry (https://iamketan.com.au)
+ * Licensed under the MIT license:
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ */
+(function($) {
+
+    /*
+    |--------------------------------------------------------------------------
+    | Cookie Message
+    |--------------------------------------------------------------------------
+    |
+    | Displays the cookie message on first visit or 30 days after their
+    | last visit.
+    |
+    | @param event - 'reinit' to reopen the cookie message
+    |
+    */
+    $.fn.ihavecookies = function(options, event) {
+
+        var $element = $(this);
+
+        // Set defaults
+        var settings = $.extend({
+            cookieTypes: [
+                {
+                    type: 'Site Preferences',
+                    value: 'preferences',
+                    description: 'These are cookies that are related to your site preferences, e.g. remembering your username, site colours, etc.'
+                },
+                {
+                    type: 'Analytics',
+                    value: 'analytics',
+                    description: 'Cookies related to site visits, browser types, etc.'
+                },
+                {
+                    type: 'Marketing',
+                    value: 'marketing',
+                    description: 'Cookies related to marketing, e.g. newsletters, social media, etc'
+                }
+            ],
+            title: 'Cookies & Privacy',
+            message: 'Cookies enable you to use shopping carts and to personalize your experience on our sites, tell us which parts of our websites people have visited, help us measure the effectiveness of ads and web searches, and give us insights into user behavior so we can improve our communications and products.',
+            link: '/privacy-policy',
+            delay: 2000,
+            expires: 30,
+            redirect: '#',
+            declineBtnLabel: 'Decline',
+            moreInfoLabel: 'More information',
+            acceptBtnLabel: 'Accept Cookies',
+            advancedBtnLabel: 'Customise Cookies',
+            cookieTypesTitle: 'Select cookies to accept',
+            fixedCookieTypeLabel:'Necessary',
+            fixedCookieTypeDesc: 'These are cookies that are essential for the website to work correctly.',
+            onAccept: function(){},
+            uncheckBoxes: false
+        }, options);
+
+        var myCookie = getCookie('cookieControl');
+        var myCookiePrefs = getCookie('cookieControlPrefs');
+        if (!myCookie || !myCookiePrefs || event == 'reinit') {
+            // Remove all instances of the cookie message so it's not duplicated
+            $('#gdpr-cookie-message').remove();
+
+            // Set the 'necessary' cookie type checkbox which can not be unchecked
+            var cookieTypes = '<li><input type="checkbox" name="gdpr[]" value="necessary" checked="checked" disabled="disabled"> <label title="' + settings.fixedCookieTypeDesc + '">' + settings.fixedCookieTypeLabel + '</label></li>';
+
+            // Generate list of cookie type checkboxes
+            preferences = JSON.parse(myCookiePrefs);
+            $.each(settings.cookieTypes, function(index, field) {
+                if (field.type !== '' && field.value !== '') {
+                    var cookieTypeDescription = '';
+                    if (field.description !== false) {
+                        cookieTypeDescription = ' title="' + field.description + '"';
+                    }
+                    cookieTypes += '<li><input type="checkbox" id="gdpr-cookietype-' + field.value + '" name="gdpr[]" value="' + field.value + '" data-auto="on"> <label for="gdpr-cookietype-' + field.value + '"' + cookieTypeDescription + '>' + field.type + '</label></li>';
+                }
+            });
+
+            var declineBtn = settings.redirect? '<button id="gdpr-cookie-advanced" type="button">' + settings.declineBtnLabel + '</button>' : '';
+            var policyLink = settings.link? '<a href="' + settings.link + '">' + settings.moreInfoLabel + '</a>' : '';
+
+            // Display cookie message on page
+            var cookieMessage = '<div id="gdpr-cookie-message"><h4>' + settings.title + '</h4><p>' + settings.message + ' ' + policyLink + '<div id="gdpr-cookie-types" style="display:none;"><h5>' + settings.cookieTypesTitle + '</h5><ul>' + cookieTypes + '</ul></div><p><button id="gdpr-cookie-accept" type="button">' + settings.acceptBtnLabel + '</button>' + declineBtn + '</p></div>';
+            setTimeout(function(){
+                $($element).append(cookieMessage);
+                $('#gdpr-cookie-message').hide().fadeIn('slow', function(){
+                    // If reinit'ing, open the advanced section of message
+                    // and re-check all previously selected options.
+                    if (event == 'reinit') {
+                        $('#gdpr-cookie-advanced').trigger('click');
+                        $.each(preferences, function(index, field) {
+                            $('input#gdpr-cookietype-' + field).prop('checked', true);
+                        });
+                    }
+                });
+            }, settings.delay);
+
+            // When accept button is clicked drop cookie
+            $('body').on('click','#gdpr-cookie-accept', function(){
+                // Set cookie
+                dropCookie(true, settings.expires);
+
+                // If 'data-auto' is set to ON, tick all checkboxes because
+                // the user hasn't clicked the customise cookies button
+                $('input[name="gdpr[]"][data-auto="on"]').prop('checked', true);
+
+                // Save users cookie preferences (in a cookie!)
+                var prefs = [];
+                $.each($('input[name="gdpr[]"]').serializeArray(), function(i, field){
+                    prefs.push(field.value);
+                });
+                setCookie('cookieControlPrefs', encodeURIComponent(JSON.stringify(prefs)), 365);
+
+                // Run callback function
+                settings.onAccept.call(this);
+            });
+
+            // Toggle advanced cookie options
+
+            $('body').on('click', '#gdpr-cookie-advanced', function(){
+                // Uncheck all checkboxes except for the disabled 'necessary'
+                // one and set 'data-auto' to OFF for all. The user can now
+                // select the cookies they want to accept.
+                /*$('input[name="gdpr[]"]:not(:disabled)').attr('data-auto', 'off').prop('checked', false);
+                $('#gdpr-cookie-types').slideDown('fast', function(){
+                    $('#gdpr-cookie-advanced').prop('disabled', true);
+                });*/
+
+                location.href = settings.redirect;
+            });
+
+
+        } else {
+            var cookieVal = true;
+            if (myCookie == 'false') {
+                cookieVal = false;
+            }
+            dropCookie(cookieVal, settings.expires);
+        }
+
+        // Uncheck any checkboxes on page load
+        if (settings.uncheckBoxes === true) {
+            $('input[type="checkbox"].ihavecookies').prop('checked', false);
+        }
+
+    };
+
+    // Method to get cookie value
+    $.fn.ihavecookies.cookie = function() {
+        var preferences = getCookie('cookieControlPrefs');
+        return JSON.parse(preferences);
+    };
+
+    // Method to check if user cookie preference exists
+    $.fn.ihavecookies.preference = function(cookieTypeValue) {
+        var control = getCookie('cookieControl');
+        var preferences = getCookie('cookieControlPrefs');
+        preferences = JSON.parse(preferences);
+        if (control === false) {
+            return false;
+        }
+        if (preferences === false || preferences.indexOf(cookieTypeValue) === -1) {
+            return false;
+        }
+        return true;
+    };
+
+    /*
+    |--------------------------------------------------------------------------
+    | Drop Cookie
+    |--------------------------------------------------------------------------
+    |
+    | Function to drop the cookie with a boolean value of true.
+    |
+    */
+    var dropCookie = function(value, expiryDays) {
+        setCookie('cookieControl', value, expiryDays);
+        $('#gdpr-cookie-message').fadeOut('fast', function() {
+            $(this).remove();
+        });
+    };
+
+    /*
+    |--------------------------------------------------------------------------
+    | Set Cookie
+    |--------------------------------------------------------------------------
+    |
+    | Sets cookie with 'name' and value of 'value' for 'expiry_days'.
+    |
+    */
+    var setCookie = function(name, value, expiry_days) {
+        var d = new Date();
+        d.setTime(d.getTime() + (expiry_days*24*60*60*1000));
+        var expires = "expires=" + d.toUTCString();
+        document.cookie = name + "=" + value + ";" + expires + ";path=/";
+        return getCookie(name);
+    };
+
+    /*
+    |--------------------------------------------------------------------------
+    | Get Cookie
+    |--------------------------------------------------------------------------
+    |
+    | Gets cookie called 'name'.
+    |
+    */
+    var getCookie = function(name) {
+        var cookie_name = name + "=";
+        var decodedCookie = decodeURIComponent(document.cookie);
+        var ca = decodedCookie.split(';');
+        for (var i = 0; i < ca.length; i++) {
+            var c = ca[i];
+            while (c.charAt(0) == ' ') {
+                c = c.substring(1);
+            }
+            if (c.indexOf(cookie_name) === 0) {
+                return c.substring(cookie_name.length, c.length);
+            }
+        }
+        return false;
+    };
+
+}(jQuery));

+ 0 - 0
lib/js/index.php


BIN
logo.png


+ 36 - 0
whmcs.json

@@ -0,0 +1,36 @@
+{
+  "schema": "1.0",
+  "type": "hardsoftcode-addons",
+  "name": "Cookie",
+  "version": "1.0.1",
+  "license": "proprietary",
+  "category": "utilities",
+  "description": {
+    "name": "Cookie Consent",
+    "tagline": "Cookie consent when installed and activated will add a dialog that can be seen across the website until visitors act upon it.",
+    "long": "Cookie consent addon module for WHMCS set up a cookie dialog on your website in 2 minutes with little to no coding required. Cookie consent when installed and activated will add a dialog that can be seen across the website until visitors act upon it. The dialog can be used to inform the user about the use of cookies and prompt them to take explicit and informed action accept or reject.",
+    "features": [
+      "Enable the cookie dialog",
+      "Dialog title",
+      "Dialog message",
+      "Include HTML in message",
+      "Set up days for the cookie to expire",
+      "Cookie Policy URL",
+      "Decline Redirect URL",
+      "Responsive & Mobile Friendly"
+    ]
+  },
+  "logo": {
+    "filename": "logo.png"
+  },
+  "support": {
+    "homepage": "https:\/\/www.hardsoftcode.com\/products.php?p=product&a=cookie-consent",
+    "docs_url": "https:\/\/www.hardsoftcode.com\/documentation.php?p=articles&a=cookie-consent"
+  },
+  "authors": [
+    {
+      "name": "HardSoftCode",
+      "homepage": "https:\/\/www.hardsoftcode.com\/"
+    }
+  ]
+}