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_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');
+define('GLM_SERVERSTATS_PLUGIN_RELAY_DISMISS', 'glm_info_notice_dismiss');
// Determine which system we're running on - If not provided, assume PRODUCTION
$host = getenv('GLM_HOST_ID');
define('GLM_SERVERSTATS_PLUGIN_VIEW_PATH', GLM_SERVERSTATS_PLUGIN_PATH.'/views');
// Update Server
-define('GLM_SERVERSTATS_PLUGIN_UPDATE_SERVER', 'http://www.gaslightmedia.com/update_server');
\ No newline at end of file
+define('GLM_SERVERSTATS_PLUGIN_UPDATE_SERVER', 'http://www.gaslightmedia.com/update_server');
{
public function model()
{
- $messages = false;
- $url = 'http://develop.localhost/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=relay';
+ // Initiate Variables.
+ $messages = false;
+ $view_type = 'main';
+ $url = GLM_SERVERSTATS_PLUGIN_RELAY_URL;
+
+ // Setup the option.
+ $option = isset( $_REQUEST['option'] ) ? filter_var( $_REQUEST['option'] ) : 'latest';
+
+ // Add option to $url based on the current option.
+ switch ( $option ) {
+
+ case 'view':
+ $url .= '&option=view';
+ if ( isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
+ $url .= '&id=' . $id;
+ }
+ break;
+
+ case 'full':
+ $url .= '&option=full';
+ $view_type = 'list';
+ break;
+
+ case 'latest':
+ default:
+ $url .= '&option=latest';
+ break;
+
+ }
+
+ // echo '<pre>$url: ' . print_r( $url, true ) . '</pre>';
// Get the messages from the main plugin.
$fetchData = wp_remote_get( $url );
if ( $status == 200 ) {
$messages = json_decode( $messageData, true );
+ } else {
}
- // If there's no message id then only get the first one.
- $messages = array_slice( $messages, 0, 1 );
+ // echo '<pre>$messages: ' . print_r( $messages, true ) . '</pre>';
// Compile template data
$templateData = array(
- 'messages' => $messages,
- 'status' => $status,
+ 'messages' => $messages,
+ 'status' => $status,
+ 'view_type' => $view_type,
);
// Return status, suggested view, and data to controller
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members Misc Admin Hooks and Filters
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release adminHooks.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+/*
+ * Place Misc Hooks and Filters here. If this file exists, it will be included
+ * by the add-on main plugin script.
+ *
+ * Note that filter and hook callback functions must be included in-line as shown below...
+ *
+ * add_filter( 'filter_title', function( $parameter ) {
+ * // Function code
+ * });
+ *
+ * Also note that parameters will be in the context of the main admin controller constructor.
+ */
+
+/*
+ * Add an action to GLM Associate Cron
+ *
+ * See description for "GLM Associate Cron" in main plugin index.php file.
+ */
+/* Sample add cron request for testing.
+add_filter('glm_associate_cron_request', function($request) {
+
+ // Sanity check - Must be passed an array
+ if (is_array($request)) {
+
+ $request[] = array(
+ 'menu' => GLM_MEMBERS_PLUGIN_UNDERSCORED_NAME, // Menu where action exists
+ 'action' => 'test_action', // Name of action to run
+ 'daysOfWeek'=> false, // All Days
+ 'times' => false, // All Hours
+ 'params' => false // Any parameters needed by the triggered action
+ );
+
+ } else {
+ trigger_error('Cron Request filter recieved bad request array!', E_USER_WARNING);
+ }
+
+ return $request;
+
+}, 10, 1);
+*/
+
+// Need to see if the cache is old and then to see if there's a new version for the notice
+// on the server.
+add_action(
+ 'admin_init',
+ function(){
+ $fetch_latest = false;
+ $latest_version = $id = $updated = '';
+
+ // Save the default for later
+ $default_timezone = date_default_timezone_get();
+ date_default_timezone_set( 'America/Detroit' );
+
+ // Get current time
+ $current_time = strtotime( 'now' );
+
+ $latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false );
+ $latest_data = unserialize( $latest );
+
+ // echo '<div><pre>$latest_data: ' . print_r( $latest_data, true ) . '</pre></div>';
+
+ // 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;
+ }
+ if ( $latest ) {
+ if ( $latest_data['cached'] <= $stale_time ) {
+ $fetch_latest = true;
+ }
+ } else {
+ $fetch_latest = true;
+ }
+
+ if ( $fetch_latest ) {
+ // Get the messages from the main plugin.
+ $response = wp_remote_get( GLM_SERVERSTATS_PLUGIN_RELAY_URL . '&option=latest' );
+ $message_data = wp_remote_retrieve_body( $response );
+ $status = wp_remote_retrieve_response_code( $response);
+
+ // echo '<pre>$response: ' . print_r( $response, true ) . '</pre>';
+ if ( $status == 200 ) {
+ $messages = json_decode( $message_data, true );
+ // echo '<pre>$messages: ' . print_r( $messages, true ) . '</pre>';
+ foreach ( $messages as $message ) {
+ $title = $message['title'];
+ $id = $message['id'];
+ $updated = $message['updated']['timestamp'];
+ }
+ } else {
+ // echo '<pre>$status: ' . print_r( $status, true ) . '</pre>';
+ }
+ if ( $id && $updated ) {
+ $latest_version = $id . '-' . $updated;
+ } else {
+ $latest_version = false;
+ }
+ // echo '<pre>$latest_version: ' . print_r( $latest_version, true ) . '</pre>';
+ if ( isset( $latest_data ) && isset( $latest_data['version'] ) && $latest_version == $latest_data['version'] ) {
+ // use the cached data
+ } else {
+ delete_option( GLM_SERVERSTATS_PLUGIN_RELAY_DISMISS );
+ }
+
+ $latest_data = array(
+ 'id' => $id,
+ 'title' => $title,
+ 'cached' => $current_time,
+ 'version' => $id . '-' . $updated
+ );
+
+ }
+
+ // Store as option
+ update_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, serialize( $latest_data ), true );
+ if ( $latest_version ) {
+ update_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST_VERSION, $latest_version, true );
+ }
+
+
+ // Reset the default timezone
+ date_default_timezone_set( $default_timezone );
+
+ }
+);
+
+if ( empty( get_option( GLM_SERVERSTATS_PLUGIN_RELAY_DISMISS ) ) ) {
+ add_action(
+ 'admin_notices',
+ function(){
+ $page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '';
+ if ( $page === 'glm-info-main-menu' ) {
+ return false;
+ }
+ echo '<div class="glm-serverstatus-notice updated notice is-dismissible">';
+ // Grab the cached notice.
+ $latest = get_option( GLM_SERVERSTATS_PLUGIN_RELAY_LATEST, false );
+ $latest_data = unserialize( $latest );
+
+ echo '<p><b>Gaslight Media Notification: </b><br>';
+ echo '<p><b>'.$latest_data['title'].'</b><br>';
+ echo '<a href="' . admin_url( '/' ) . 'index.php?page=glm-info-main-menu">More Details</a></p>';
+ echo '</div>';
+ }, 10, 1
+ );
+}
+
+add_action( 'admin_enqueue_scripts', function(){
+ wp_enqueue_script(
+ 'glm-serverstats-notice-update',
+ GLM_SERVERSTATS_PLUGIN_URL . '/js/notice-update.js',
+ array( 'jquery' ),
+ '1.0',
+ true
+ );
+} );
+
+add_action( 'wp_ajax_my_dismiss_glm_notice', function(){
+ // Set option for dismissing notices.
+ update_option( GLM_SERVERSTATS_PLUGIN_RELAY_DISMISS, 1, true );
+} );