Added Cookie Notification Feature
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 8 Jan 2019 18:44:54 +0000 (13:44 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 8 Jan 2019 18:44:54 +0000 (13:44 -0500)
front-end Cookie notice message that's displayed once to a user
Added configuration options for the Cookie notice message
Added configuraiton option to enable or disable the notification features of this plugin

index.php
models/adminServerStatsConfig.php
models/frontCookiePopUp.php [new file with mode: 0755]
readme.txt
setup/adminHooks.php
setup/adminMenus.php
views/adminServerStatsConfig.html

index 59a8c1d..f08bd0a 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -36,23 +36,21 @@ require_once ABSPATH . 'wp-includes/pluggable.php';
 // Include defines to tell if a plugin is active
 include_once ABSPATH . 'wp-admin/includes/plugin.php';
 
+require_once 'defines.php';
+
+require_once GLM_SERVERSTATS_PLUGIN_LIB_PATH.'/smartyTemplateSupport.php';
+
 // If this is an admin request
 if (is_admin()) {
 
-    require_once 'defines.php';
-    require_once GLM_SERVERSTATS_PLUGIN_LIB_PATH.'/smartyTemplateSupport.php';
 
     add_action('admin_menu', 'configureMenus');
 
     require_once GLM_SERVERSTATS_PLUGIN_PATH.'/setup/adminHooks.php';
 
-} else {
-
-    // No front-end functionality
-    return;
-
 }
 
+
 /*
  * Function to configure admin menus
  */
@@ -71,6 +69,17 @@ add_action( 'wp_ajax_glm_server_stats', 'glmServerStatsAjax');
  * Load CSS and Scripts
  *
  */
+
+function glmServerJqueryScipts()
+{
+    // jQuery scripts
+    wp_enqueue_script('jquery', false, array(), false, true);
+    wp_enqueue_script('jquery-style', false, array(), false, true);
+    wp_enqueue_script('jquery-ui-core', false, array(), false, true);
+    wp_enqueue_script('jquery-ui-widget', false, array(), false, true);
+    wp_enqueue_script('jquery-ui-dialog', false, array(), false, true);
+}
+
 function glmServerStatsScripts()
 {
 
@@ -150,6 +159,7 @@ function serverStatsController($model)
 {
 
     // Enque admin scripts and css here so that only happens when we're doing something
+    glmServerJqueryScipts();
     glmServerStatsScripts();
 
     // Load and execute the specified model
@@ -242,5 +252,34 @@ function do_glm_serverstats_cron() {
 
 }
 
+/*
+ * Cookie Notice Pop-Up
+ * Shows the pop-up once then sets a cookie to not show it again for some number of days.
+ *
+ * To test this pop-up add "cookie_notice_test=true" to URL.
+ */
+$cookieNoticeName = 'cookie_popup_displayed';
+$cookieNoticeDays = 10;
+
+// Get Configuration for Cookie info popup
+$serverstatsConfig = get_option(GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION);
 
+// If this is an admin request and the pop-up hasn't been displayed within the specified time
+if ($serverstatsConfig['show_cookie_popup'] && !is_admin() && (!isset($_COOKIE['cookie_popup_displayed']) || isset($_REQUEST['cookie_notice_test']))) {
 
+    // Make sure that the jQuery scripts are included
+    function enqueueJquery() {
+        glmServerJqueryScipts();
+    }
+    add_action( 'wp_enqueue_scripts', 'enqueueJquery' );
+
+    // Have WordPress include the cookie pop-up code just before the footer.
+    function doCookiePopUp() {
+        include(GLM_SERVERSTATS_PLUGIN_MODEL_PATH.'/frontCookiePopUp.php');
+    }
+    add_action( 'get_footer', 'doCookiePopUp' );
+
+    // Redisplay after set # of days
+    setcookie($cookieNoticeName, true, time()+(84600*$cookieNoticeDays), '/');
+
+}
index 5aa5c20..3a34102 100755 (executable)
@@ -49,8 +49,10 @@ class adminServerStatsConfig extends glmServerStatsBandwidthSupport
     public function model()
     {
 
-        $connectError           = False;
+        $connectError           = false;
         $connectionUpdated      = false;
+        $forceReload            = false;
+        $reloadUrl              = false;
 
         // If an update was submitted
         $option = 'none';
@@ -58,23 +60,50 @@ class adminServerStatsConfig extends glmServerStatsBandwidthSupport
             $option = $_REQUEST['option'];
         }
 
+        $startingConfig = $this->getConfig();
+
         // If this is a connection update, store that
         if ($option == 'update_connection') {
 
             // Filter the input data
             $config = filter_input_array( INPUT_POST,
-            array(
-            'db_name'       => FILTER_SANITIZE_STRING,
-            'db_host'       => FILTER_SANITIZE_STRING,
-            'db_user'       => FILTER_SANITIZE_STRING,
-            'db_pass'       => FILTER_SANITIZE_STRING,
-            'website'       => FILTER_SANITIZE_STRING
-            )
+                array(
+                    'show_usage'                    => FILTER_VALIDATE_BOOLEAN,
+                    'show_notifications'            => FILTER_VALIDATE_BOOLEAN,
+                    'show_cookie_popup'             => FILTER_VALIDATE_BOOLEAN,
+                    'cookie_message'                => FILTER_SANITIZE_STRING,
+                    'cookie_opt_gdpr'               => FILTER_VALIDATE_BOOLEAN,
+                    'cookie_opt_access_logs'        => FILTER_VALIDATE_BOOLEAN,
+                    'cookie_opt_permanent'          => FILTER_VALIDATE_BOOLEAN,
+                    'cookie_opt_tracking'           => FILTER_VALIDATE_BOOLEAN,
+                    'cookie_opt_shared_tracking'    => FILTER_VALIDATE_BOOLEAN,
+                    'cookie_opt_https'              => FILTER_VALIDATE_BOOLEAN,
+                    'cookie_opt_logged_in'          => FILTER_VALIDATE_BOOLEAN,
+                    'cookie_opt_forms'              => FILTER_VALIDATE_BOOLEAN,
+                    'cookie_opt_payment'            => FILTER_VALIDATE_BOOLEAN,
+                    'db_name'                       => FILTER_SANITIZE_STRING,
+                    'db_host'                       => FILTER_SANITIZE_STRING,
+                    'db_user'                       => FILTER_SANITIZE_STRING,
+                    'db_pass'                       => FILTER_SANITIZE_STRING,
+                    'website'                       => FILTER_SANITIZE_STRING
+                )
             );
 
             // Update the WordPress option where we store the configuration for this plugin
             update_option(GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION, $config);
 
+            $connectionUpdated = true;
+
+            // If turning off show_usage, make sure we reload with a valid URL
+            if ($startingConfig['show_usage'] != $config['show_usage']) {
+                if ($config['show_usage']) {
+                    $reloadUrl = '?page=glm-server-stats-configure';
+                } else {
+                    $reloadUrl = '?page=glm-server-stats-main-menu';
+                }
+                $forceReload = true;
+            }
+
         // Otherwise get existing connection configuration
         } else {
             $config = $this->getConfig();
@@ -86,21 +115,19 @@ class adminServerStatsConfig extends glmServerStatsBandwidthSupport
         // If we can connect to the database
         if ($connected) {
             $websiteId = $this->siteId;
-            if ($option == 'update_connection') {
-                $connectionUpdated = true;
-            }
 
         // If we can't, get the reason why
         } else {
             $connectError = $this->connectError;
         }
 
-
         // Compile template data
         $templateData = array_merge(
             $config,
             array(
-                'isProvider'                 => $this->isProvider(),
+                'forceReload'           => $forceReload,
+                'reloadUrl'             => $reloadUrl,
+                'isProvider'            => $this->isProvider(),
                 'connectionUpdated'     => $connectionUpdated,
                 'connectError'          => $connectError,
             )
diff --git a/models/frontCookiePopUp.php b/models/frontCookiePopUp.php
new file mode 100755 (executable)
index 0000000..5a1e19f
--- /dev/null
@@ -0,0 +1,151 @@
+<?php
+// Get Configuration for Cookie info popup
+$serverstatsConfig = get_option(GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION);
+?>
+<style>
+    #siteCookieDialog {
+        style="display: none;
+        font-size: 16px;
+    }
+    #siteCookieDialog .cookieButton {
+        background-color: WhiteSmoke;
+        border: 1px solid gray;
+        padding: 4px;
+        margin: 4px;
+    }
+    #siteCookieDialog p {
+    }
+    #siteCookieDialog $cookieMoreInfo {
+    }
+</style>
+<div id="siteCookieDialog">
+    <p>
+        This site uses temporary "Session Cookies" to store limited information that's required to provide
+        you with a consistent user experience. We don't store personally identifying or other sensitive
+        information in these Cookies and these Cookies are erased when you close your Web Browser.
+    </p>
+    <p>
+        If you're on a public computer, be sure to close all Web Browsers when you're done!
+    </p>
+<?php if ($serverstatsConfig['cookie_message'] != '') { echo '<p>'.$serverstatsConfig['cookie_message'].'</p>'; }  ?>
+    <p>
+        <a id="showMorePrivacyInfo" class="cookieButton">Show more</a>
+        <a id="privacyGotIt" class="cookieButton">Got it!</a>
+    </p>
+    <div id="cookieMoreInfo" style="display: none;">
+<?php if ($serverstatsConfig['cookie_opt_gdpr']) { ?>
+        <p>
+            <b>GDPR:</b> The EU GDPR legislation obligates us to tell you how we use information you supply through
+            this Website. We intentionally limit the information we ask you to supply to what is absolutely
+            necessary to provide the service you request. Unless otherwise stated, we don't share any supplied information
+            with any other person or organization other than as required and as authorized by you. Payment related
+            information you supply will only be used to complete a transaction and will not be stored on our systems.
+        </p>
+<?php } ?>
+<?php if ($serverstatsConfig['cookie_opt_access_logs']) { ?>
+        <p>
+            <b>ACCESS LOGS:</b> We retain for a certain period of time access log entries with minimal information
+            about your use of this Website for the sole purpose of ensuring security of our systems and compliance
+            of acceptable use by users of this site. We don't share log entries with anyone unless obligated to do
+            so by way of a lawful request from a law enforcement agency or court with appropriate jurisdiction.
+        </p>
+<?php } ?>
+<?php if ($serverstatsConfig['cookie_opt_permanent']) { ?>
+        <p>
+            <b>PERMANENT COOKIES:</b> This Website uses "Permanent Cookies" that are retained by your Web Browser.
+            This type of Cookie is used to help you when you return to this Website at a later time. If you're using
+            a public computer, be sure to delete all cookies before closing the Browser.
+        </p>
+<?php } ?>
+<?php if ($serverstatsConfig['cookie_opt_tracking']) { ?>
+        <p>
+            <b>TRACKING:</b> We may track where you go within this site. This helps us provide you with relevant
+            information and to evaluate how we may improve the site. We don't share this tracking information with anyone
+            unless otherwise stated here.
+        </p>
+<?php } ?>
+<?php if ($serverstatsConfig['cookie_opt_shared_tracking']) { ?>
+        <p>
+            <b>SHARED TRACKING:</b> This site may contain third-party shared tracking features. These features may
+            collect and share tracking information with affiliated Websites and advertisers to help them provide you with more relevant
+            information. This site may also contain third-party shared tracking features that permit a third-party
+            to collect and report traffic statistics to the owner of this site. We don't permit shared tracking
+            to include personal information of any user.
+        </p>
+<?php } ?>
+<?php if ($serverstatsConfig['cookie_opt_https']) { ?>
+        <p>
+            <b>HTTPS:</b> This Website uses the secure "HTTPS" protocol for all pages and content. This makes it very
+            difficult for anyone who may tap into Internet traffic to read what you submit and what is being sent
+            back to you. If you feel that the possibility of someone intercepting information you submit or knowledge
+            of the pages you access presents a significant risk to you, please don't use this Website.
+        </p>
+<?php } ?>
+<?php if ($serverstatsConfig['cookie_opt_logged_in']) { ?>
+        <p>
+            <b>LOGGED IN USERS:</b> We don't store passwords you use to log in as plain text, instead they're encrypted
+            before being stored in our systems. When you enter that password again to log in, we encrypt that and and
+            match it to the encrypted password that had been stored. There is no way to decrypt the stored passwords.
+            Still, you should try to avoid using the same password for everything you log into, should not make those
+            passwords easily accessible to anyone else, and you should always use more complex passwords that don't
+            include words or names people would associate with you.
+        </p>
+<?php } ?>
+<?php if ($serverstatsConfig['cookie_opt_forms']) { ?>
+        <p>
+            <b>FORMS:</b> Personal information requested in forms on this site is limited to what is required to provide
+            you with the information and services you request. Please don't provide additional personal information in
+            these forms that is not requested. If you are uncomfortable with submitting any requested information, please
+            call or write to us directly using the address and phone numbers on this site. We don't supply any of the
+            information you provide to any other individual or organization unless you check a box in the submission form
+            specifically authorizing us to do so.
+        </p>
+<?php } ?>
+<?php if ($serverstatsConfig['cookie_opt_payment']) { ?>
+        <p>
+            <b>PAYMENT INFORMATION:</b> We only use the payment information you provide to complete a paid transaction.
+             We don't retain any payment information beyond that point. If you check a box asking us to store credit
+             card or similar information for future use, we pass that request on to the credit card processing service
+             and they store that information on their systems. All we store on our systems is a "token" that can only
+             be used to process another authorized transaction on your behalf through this Website with the same credit
+             card processing service.
+         </p>
+<?php } ?>
+     </div>
+</div>
+
+<script type="text/javascript">
+    jQuery(function($){
+
+            // Setup dialog box
+            $( "#siteCookieDialog" ).dialog({
+                title: 'Please Note: This site uses Cookies',
+                position: { at: "center top+20%"},
+                autoOpen: false,
+                modal: true,
+                width: '80%'
+            });
+
+            // Show submit dialog box
+            $( "#siteCookieDialog" ).dialog( "open" );
+
+            var showMorePrivacyInfo = false;
+            $("#showMorePrivacyInfo").on('click', function() {
+                if (showMorePrivacyInfo) {
+                    $('#cookieMoreInfo').hide();
+                    $('#showMorePrivacyInfo').html('Show more');
+                    showMorePrivacyInfo = false;
+                } else {
+                    $('#cookieMoreInfo').show();
+                    $('#showMorePrivacyInfo').html('Show less');
+                    showMorePrivacyInfo = true;
+                }
+            });
+
+            $("#privacyGotIt").on('click', function() {
+                $( "#siteCookieDialog" ).dialog( "close" );
+            });
+
+    });
+</script>
+
index 024128e..d68ae2f 100755 (executable)
@@ -29,6 +29,11 @@ e.g.
 1. Activate the plugin through the 'Plugins' menu in WordPress
 
 == Changelog ==
+= Pending =
+* Added front-end Cookie notice message that's displayed once to a user
+* Added configuration options for the Cookie notice message
+* Added configuraiton option to enable or disable the notification features of this plugin
+
 = 2.1.0 =
 * Early Deployment Release
 * Updated Smarty Templates
index ca49aff..a8be7f9 100644 (file)
@@ -60,7 +60,11 @@ add_filter('glm_associate_cron_request', function($request) {
 $user_is_admin  = current_user_can( 'administrator' );
 $user_is_editor = current_user_can( 'editor' );
 
-if ( $user_is_admin || $user_is_editor ) {
+// Get Configuration
+$serverstatsConfig = get_option(GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION);
+
+// If this site should show notifications and is a high-level user - Check for notifications
+if ( $serverstatsConfig['show_notifications'] && ($user_is_admin || $user_is_editor) ) {
     add_action(
         'admin_init',
         function(){
index a2467ea..fec2eb4 100755 (executable)
  * @link     http://dev.gaslightmedia.com/
  */
 
+$serverstatsConfig = get_option(GLM_SERVERSTATS_PLUGIN_CONFIG_OPTION);
 $mainServerStatsMenuSlug = 'glm-server-stats-main-menu';
+
+// Have to be either an Editor or Administration to see usage
 if (current_user_can('editor') || current_user_can('administrator')) {
-    add_menu_page(
-        "GLM Data Usage",
-        'GLM Data Usage',
-        'edit_pages',
-        $mainServerStatsMenuSlug,
-        function() {
-            serverStatsController('adminServerStats');
-        },
-        GLM_SERVERSTATS_PLUGIN_ASSETS_URL.'/flame.png',
-        '3.100'
-    );
+
+    // If we're showing usage - Make that the menu item
+    if ($serverstatsConfig['show_usage']) {
+
+        add_menu_page(
+            "GLM Data Usage",
+            'GLM Data Usage',
+            'edit_pages',
+            $mainServerStatsMenuSlug,
+            function() {
+                serverStatsController('adminServerStats');
+            },
+            GLM_SERVERSTATS_PLUGIN_ASSETS_URL.'/flame.png',
+            '3.100'
+        );
+
+        // If the user is an administrator they can also do config
+        if (current_user_can('administrator')) {
+            add_submenu_page(
+                $mainServerStatsMenuSlug,
+                'Configure',
+                'Configure',
+                'manage_options',
+                'glm-server-stats-configure',
+                function() {
+                    serverStatsController('adminServerStatsConfig');
+                }
+            );
+        }
+
+    // Otherwise, if we're an administrator, then just show configuration
+    } elseif (current_user_can('administrator')) {
+
+        add_menu_page(
+            "GLM Data Usage",
+            'GLM Data Usage',
+            'edit_pages',
+            $mainServerStatsMenuSlug,
+            function() {
+                serverStatsController('adminServerStatsConfig');
+            },
+            GLM_SERVERSTATS_PLUGIN_ASSETS_URL.'/flame.png',
+            '3.100'
+        );
+
+    }
+
 /* Tempoorarily Dissabled
     add_menu_page(
         'GLM Notifications',
@@ -38,18 +77,5 @@ if (current_user_can('editor') || current_user_can('administrator')) {
         '3.200'
     );
 */
-}
 
-// Add a submeu for server Stats Server Config - For admin users only
-    if (current_user_can('administrator')) {
-    add_submenu_page(
-        $mainServerStatsMenuSlug,
-        'Configure',
-        'Configure',
-        'manage_options',
-        'glm-server-stats-configure',
-        function() {
-            serverStatsController('adminServerStatsConfig');
-        }
-    );
 }
index 43698d7..6c47f28 100755 (executable)
             <input type="hidden" name="option" value="update_connection">
 
             <table class="glm-admin-table" style="width: 95%">
+    {if $connectionUpdated}
                 <tr>
                     <td colspan="2">
                         <span class="glm-notice glm-flash-updated" style="font-size: 1.5em;">Settings Updated</span>
                     </td>
                 </tr>
+    {/if}
+                <tr>
+                    <th>Show Data Usage:</th>
+                    <td>
+                        <input type="checkbox" name="show_usage"{if $show_usage} checked{/if}>
+                    </td>
+                </tr>
+                <tr>
+                    <th>Show Notifications:</th>
+                    <td>
+                        <input type="checkbox" name="show_notifications"{if $show_notifications} checked{/if}>
+                    </td>
+                </tr>
+                <tr>
+                    <th>Show Cookie Pop-Up:</th>
+                    <td>
+                        <input type="checkbox" name="show_cookie_popup"{if $show_cookie_popup} checked{/if}>
+                        <br>Custom Message
+                        <br>&nbsp;&nbsp;<textarea name="cookie_message" cols="60">{$cookie_message}</textarea>
+                        <br>Include notices regarding ...
+                        <br>&nbsp;&nbsp;<input type="checkbox" name="cookie_opt_gdpr"{if $cookie_opt_gdpr} checked{/if}> GDPR
+                        <br>&nbsp;&nbsp;<input type="checkbox" name="cookie_opt_access_logs"{if $cookie_opt_access_logs} checked{/if}> Access Logs
+                        <br>&nbsp;&nbsp;<input type="checkbox" name="cookie_opt_permanent"{if $cookie_opt_permanent} checked{/if}> Permanent Cookies
+                        <br>&nbsp;&nbsp;<input type="checkbox" name="cookie_opt_tracking"{if $cookie_opt_tracking} checked{/if}> Tracking Cookies
+                        <br>&nbsp;&nbsp;<input type="checkbox" name="cookie_opt_shared_tracking"{if $cookie_opt_shared_tracking} checked{/if}> Shared Tracking Cookies
+                        <br>&nbsp;&nbsp;<input type="checkbox" name="cookie_opt_https"{if $cookie_opt_https} checked{/if}> HTTPS
+                        <br>&nbsp;&nbsp;<input type="checkbox" name="cookie_opt_logged_in"{if $cookie_opt_logged_in} checked{/if}> Logged-In Users
+                        <br>&nbsp;&nbsp;<input type="checkbox" name="cookie_opt_forms"{if $cookie_opt_forms} checked{/if}> Submission Forms
+                        <br>&nbsp;&nbsp;<input type="checkbox" name="cookie_opt_payment"{if $cookie_opt_payment} checked{/if}> Payment Forms
+                    </td>
+                </tr>
                 <tr>
                     <th colspan="2">
-                        {if $connectError}<br><span class="glm-error" style="font-size: 1.5em; border: 1px solid black; padding: 5px; margin-bottom: 4em;">Error {$connectError}</span>{/if}
+                        {if $connectError}<br><span class="glm-error" style="font-size: 1.5em; border: 1px solid black; padding: 5px; margin-bottom: 4em;">Unable To Connect</span>{/if}
                     </th>
                 </tr>
                 <tr>
 
         jQuery(document).ready(function($) {
 
+{if $forceReload}
+            alert('Redirecting due to menu change. Click "OK" to continue.');
+            window.location.href = '{$adminUrl}{$reloadUrl}';
+{/if}
+
             // Flash certain elements for a short time after display
             $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);