From 0dc4b11c87ae0d228b297a80391f61d998d3af60 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 13 Apr 2017 17:29:07 -0400 Subject: [PATCH] Updated update server support code. --- defines.php | 6 +----- index.php | 2 +- .../js/opentools-updatecheck.js | 19 +++++++++++-------- .../opentools-update-checker.php | 10 +++++----- .../plugin-update-checker.php | 4 ++-- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/defines.php b/defines.php index 93e27b39..755902b1 100644 --- a/defines.php +++ b/defines.php @@ -89,8 +89,4 @@ define('GLM_MEMBERS_PLUGIN_CURRENT_THEME', $glmCurrentTheme->get_template()); define('GLM_MEMBERS_PLUGIN_CURRENT_THEME_DIR', $glmCurrentTheme->get_template_directory()); // Update Server -if (GLM_MEMBER_PLUGIN_HOST == 'CHUCK') { - define('GLM_MEMBERS_PLUGIN_UPDATE_SERVER', 'http://192.168.44.54/update_server'); -} else { - define('GLM_MEMBERS_PLUGIN_UPDATE_SERVER', 'http://www.gaslightmedia.com/update_server'); -} +define('GLM_MEMBERS_PLUGIN_UPDATE_SERVER', 'http://www.gaslightmedia.com/update_server'); diff --git a/index.php b/index.php index 4d31ce1a..1b3343bb 100644 --- a/index.php +++ b/index.php @@ -711,7 +711,7 @@ function glmCheckDatabase () * Plugin Update Support - uses Gaslight Media update server */ // Do not include this require statement in add-ons to this plugin. The update checker code should only be loaded here. -require GLM_MEMBERS_PLUGIN_LIB_PATH.'/opentools-update-checker/opentools-update-checker.php'; +require_once GLM_MEMBERS_PLUGIN_LIB_PATH.'/opentools-update-checker/opentools-update-checker.php'; ${GLM_MEMBERS_PLUGIN_PREFIX."updateChecker"} = new OpenToolsPluginUpdateChecker( GLM_MEMBERS_PLUGIN_UPDATE_SERVER.'/?action=get_metadata&slug='.GLM_MEMBERS_PLUGIN_SLUG, __FILE__, diff --git a/lib/opentools-update-checker/js/opentools-updatecheck.js b/lib/opentools-update-checker/js/opentools-updatecheck.js index 662a5cf2..c064289a 100644 --- a/lib/opentools-update-checker/js/opentools-updatecheck.js +++ b/lib/opentools-update-checker/js/opentools-updatecheck.js @@ -1,33 +1,36 @@ /** * OpenTools Update Check Admin JS */ +var credentialsRowDisplayed = []; var showUpdateCredentialsRow = function (btn) { - if (showUpdateCredentialsRow.credentialsRowDisplayed) { - return; - } - showUpdateCredentialsRow.credentialsRowDisplayed = true; var ajaxurl = jQuery(btn).data('ajaxurl'); var slug = jQuery(btn).data("slug"); var nonce = jQuery(btn).data("nonce"); + + if (credentialsRowDisplayed[slug]) { + return false; + } + credentialsRowDisplayed[slug] = true; var ajaxargs = { type: "POST", url: ajaxurl, data: { - action: 'getUpdateCredentialsRow', + action: 'getUpdateCredentialsRow_' + slug, slug: slug, _ajax_nonce: nonce }, success: function ( json ) { jQuery(btn).closest('tr').after(json['row']); }, - error: function() { }, - complete: function() { }, + error: function() { }, + complete: function() { }, }; jQuery.ajax(ajaxargs); return false; }; var submitUpdateCredentials = function(btn) { + var ajaxurl = jQuery(btn).data('ajaxurl'); var slug = jQuery(btn).data("slug"); var nonce = jQuery(btn).data("nonce"); @@ -36,7 +39,7 @@ var submitUpdateCredentials = function(btn) { var tr = jQuery(btn).closest('tr'); var data = { - action: 'submitUpdateCredentials', + action: 'submitUpdateCredentials_' + slug, slug: slug, _ajax_nonce: nonce, }; diff --git a/lib/opentools-update-checker/opentools-update-checker.php b/lib/opentools-update-checker/opentools-update-checker.php index 853ef8fc..6f0b4bb5 100644 --- a/lib/opentools-update-checker/opentools-update-checker.php +++ b/lib/opentools-update-checker/opentools-update-checker.php @@ -42,8 +42,8 @@ class OpenToolsPluginUpdateChecker extends PluginUpdateChecker_3_1 { // add_filter('plugin_row_meta', array($this, 'displayUpdateCredentialsLink'), 9, 2); add_filter('plugin_action_links_'.$this->pluginFile, array($this, 'displayUpdateCredentialsLink'), 9, 2); - add_action( 'wp_ajax_getUpdateCredentialsRow', array( &$this, 'getUpdateCredentialsRow') ); - add_action( 'wp_ajax_submitUpdateCredentials', array( &$this, 'submitUpdateCredentials') ); + add_action( 'wp_ajax_getUpdateCredentialsRow_'.$this->slug, array( &$this, 'getUpdateCredentialsRow') ); + add_action( 'wp_ajax_submitUpdateCredentials_'.$this->slug, array( &$this, 'submitUpdateCredentials') ); } protected function getCredentials($slug) @@ -124,14 +124,13 @@ class OpenToolsPluginUpdateChecker extends PluginUpdateChecker_3_1 { */ public function getUpdateCredentialsRow() { $json = array('row' => '', 'message'=>'Unsuccessful'); - $showCredentials = isset($_REQUEST['slug']) && $_REQUEST['slug'] == $this->slug && current_user_can('update_plugins') && check_ajax_referer('otup_enter_update_credentials'); $showCredentials = $showCredentials && !empty($this->credvars); - if ( $showCredentials && (is_network_admin() || !is_multisite() )) { + $slug = $this->slug; if ( is_network_admin() ) { $active_class = is_plugin_active_for_network( $this->pluginFile ) ? 'active': ''; @@ -152,7 +151,8 @@ class OpenToolsPluginUpdateChecker extends PluginUpdateChecker_3_1 { $tr .= $credname . "    "; } - $tr .= sprintf('', +// $tr .= sprintf('', + $tr .= sprintf('
Update License Key
', esc_attr($this->slug), esc_attr(wp_create_nonce( 'otup_enter_update_credentials_'.$slug )), esc_attr($this->ajaxurl), diff --git a/lib/plugin-update-checker/plugin-update-checker.php b/lib/plugin-update-checker/plugin-update-checker.php index a0569458..38760f4c 100644 --- a/lib/plugin-update-checker/plugin-update-checker.php +++ b/lib/plugin-update-checker/plugin-update-checker.php @@ -196,13 +196,13 @@ class PluginUpdateChecker_3_1 { //Try to parse the response $status = $this->validateApiResponse($result); $pluginInfo = null; -// *** CPS *** if ( !is_wp_error($status) && is_array($status)){ - if ( !is_wp_error($status) && is_array($status)){ + if ( !is_wp_error($status)){ $pluginInfo = PluginInfo_3_1::fromJson($result['body']); if ( $pluginInfo !== null ) { $pluginInfo->filename = $this->pluginFile; $pluginInfo->slug = $this->slug; } + } else { return false; /* Not generating error at this time as this could simply be a bad or missing key submitted -- 2.17.1