From: Steve Sutton Date: Wed, 15 Aug 2018 17:18:14 +0000 (-0400) Subject: Update glm notification cache X-Git-Tag: v2.0.0~10 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=1130ce73b9126cc08ade7905cc7d5d5f1cb6e4e8;p=WP-Plugins%2Fglm-serverstats.git Update glm notification cache Testing the caching of the glm notice (latest) Should only pull ever 20 minutes. --- diff --git a/css/admin.css b/css/admin.css index 21aa3f9..6bd060a 100644 --- a/css/admin.css +++ b/css/admin.css @@ -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; +} diff --git a/defines.php b/defines.php index cb74a7f..9bdc026 100644 --- a/defines.php +++ b/defines.php @@ -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'); diff --git a/setup/adminHooks.php b/setup/adminHooks.php index a3cb316..dfc61a2 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -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 '
$status: ' . print_r( $status, true ) . '
'; @@ -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 '
'; echo '

Gaslight Media Notification:
'; echo '

'.$latest_data['title'].'
'; - echo 'More Details

'; + echo wpautop( $latest_data['dashboard_message'] ); + echo '

'; + echo '

More Details

'; echo ''; }, 10, 1 ); diff --git a/views/glmInfoNotifications.html b/views/glmInfoNotifications.html index 8b5345a..9eff792 100644 --- a/views/glmInfoNotifications.html +++ b/views/glmInfoNotifications.html @@ -1,10 +1,11 @@ +{* GLM Notification Menu Page *}

GLM Notifications

@@ -14,14 +15,14 @@ {if $view_type == 'main'} {foreach $messages as $m}
+
{$m.updated.datetime}

{$m.title}

-
posted on {$m.updated.datetime}
{$m.message}
{/foreach} {else} {foreach $messages as $m} -