Update glm notification cache
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 15 Aug 2018 17:18:14 +0000 (13:18 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 15 Aug 2018 17:18:14 +0000 (13:18 -0400)
Testing the caching of the glm notice (latest)
Should only pull ever 20 minutes.

css/admin.css
defines.php
setup/adminHooks.php
views/glmInfoNotifications.html

index 21aa3f9..6bd060a 100644 (file)
@@ -414,7 +414,7 @@ input[type=submit], input[type=file] {
     border: 1px solid darkgrey;
     padding: .8rem 1rem;
     display: inline-block;
-    width: 1200px;
+    max-width: 1200px;
 }
 
 #glm-info-container h2 {
@@ -432,3 +432,11 @@ input[type=submit], input[type=file] {
     margin: 1rem 0;
     position: relative;
 }
+#glm-info-container ul {
+    list-style: inherit;
+    padding: 0px 15px;
+}
+ul#glm-notices {
+    list-style: none;
+    padding: 0;
+}
index cb74a7f..9bdc026 100644 (file)
@@ -16,6 +16,7 @@ define('GLM_SERVERSTATS_PLUGIN_NAME', 'Gaslight Media ServerStats (serverstats)'
 define('GLM_SERVERSTATS_PLUGIN_SHORT_NAME', 'ServerStats');
 define('GLM_SERVERSTATS_PLUGIN_SLUG', 'glm-serverstats');
 define('GLM_SERVERSTATS_PLUGIN_RELAY_URL', 'https://www.gaslightmedia.com/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=relay');
+// define('GLM_SERVERSTATS_PLUGIN_RELAY_URL', 'http://develop.localhost/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=relay');
 define('GLM_SERVERSTATS_PLUGIN_RELAY_LATEST', 'glm_serverstats_relay_latest');
 define('GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_VERSION', 'glm_serverstats_relay_latest_version');
 define('GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_TIMEOUT', '20 minutes');
index a3cb316..dfc61a2 100644 (file)
@@ -68,17 +68,23 @@ add_action(
 
         // Get current time
         $current_time = strtotime( 'now' );
+        // trigger_error( '$current_time: ' . $current_time . ' ' . date( 'Y-m-d H:i:s', $current_time ), E_USER_NOTICE );
 
         $latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false );
+        // trigger_error( '$latest: ' . $latest, E_USER_NOTICE );
         $latest_data = unserialize( $latest );
+        // trigger_error( '$cached: ' . $latest_data['cached'] . ' ' . date( 'Y-m-d H:i:s', $latest_data['cached'] ), E_USER_NOTICE );
 
         // check latest for time if too old then fetch latest and update time.
         $stale_time   = strtotime( '-' . GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_TIMEOUT );
-        if ( $current_time <= $stale_time ) {
-            $fetch_latest = true;
-        }
+        // trigger_error( '$stale_time: ' . $stale_time . ' ' . date( 'Y-m-d H:i:s', $stale_time ), E_USER_NOTICE );
+        // if ( $current_time <= $stale_time ) {
+        //     trigger_error( 'state time occurred', E_USER_NOTICE );
+        //     $fetch_latest = true;
+        // }
         if ( $latest ) {
             if ( $latest_data['cached'] <= $stale_time ) {
+                // trigger_error( 'stale time occurred', E_USER_NOTICE );
                 $fetch_latest = true;
             }
         } else {
@@ -93,10 +99,12 @@ add_action(
 
             if ( $status == 200 ) {
                 $messages = json_decode( $message_data, true );
+                // trigger_error( '$messages: ' . print_r( $messages, true ), E_USER_NOTICE );
                 foreach ( $messages as $message ) {
-                    $title   = $message['title'];
-                    $id      = $message['id'];
-                    $updated = $message['updated']['timestamp'];
+                    $title             = $message['title'];
+                    $dashboard_message = $message['dashboard_message'];
+                    $id                = $message['id'];
+                    $updated           = $message['updated']['timestamp'];
                 }
             } else {
                 // echo '<pre>$status: ' . print_r( $status, true ) . '</pre>';
@@ -113,10 +121,11 @@ add_action(
             }
 
             $latest_data = array(
-                'id'      => $id,
-                'title'   => $title,
-                'cached'  => $current_time,
-                'version' => $id . '-' . $updated
+                'id'                => $id,
+                'title'             => $title,
+                'dashboard_message' => $dashboard_message,
+                'cached'            => $current_time,
+                'version'           => $id . '-' . $updated
             );
 
             // Store as option
@@ -147,9 +156,12 @@ if ( empty( get_option( GLM_SERVERSTATS_PLUGIN_RELAY_DISMISS ) ) ) {
             $latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false );
             $latest_data = unserialize( $latest );
 
+            echo '<div style="display:inline-block;clear: left;">';
             echo '<p><b>Gaslight Media Notification: </b><br>';
             echo '<p><b>'.$latest_data['title'].'</b><br>';
-            echo '<a href="' . admin_url( 'admin.php' ) . '?page=glm-info-main-menu">More Details</a></p>';
+            echo wpautop( $latest_data['dashboard_message'] );
+            echo '</p></div>';
+            echo '<p><a href="' . admin_url( 'admin.php' ) . '?page=glm-info-main-menu">More Details</a></p>';
             echo '</div>';
         }, 10, 1
     );
index 8b5345a..9eff792 100644 (file)
@@ -1,10 +1,11 @@
+{* GLM Notification Menu Page *}
 <div class="wrap">
 
     <h1>GLM Notifications</h1>
 
     <ul>
         <li>
-            <a href="{$thisUrl}?page={$thisPage}&glm_action=index&option=full">Show Full List</a>
+            <a href="{$thisUrl}?page={$thisPage}&glm_action=index&option=full">Show All</a>
         </li>
     </ul>
 
             {if $view_type == 'main'}
                 {foreach $messages as $m}
                     <div class="glm-info-message">
+                        <div style="float: right; width: 200px;text-align: right;">{$m.updated.datetime}</div>
                         <h2>{$m.title}</h2>
-                        <div>posted on {$m.updated.datetime}</div>
                         {$m.message}
                     </div>
                 {/foreach}
             {else}
                 {foreach $messages as $m}
-                    <ul>
+                    <ul id="glm-notices">
                         <li>
                             <strong><a href="{$admin_url}?page={$thisPage}&glm_action=index&option=view&id={$m.id}">{$m.title}</a> {$m.updated.datetime}</strong>
                         </li>