From: Chuck Scott Date: Fri, 14 Apr 2017 15:18:33 +0000 (-0400) Subject: Updated Update Server related code. X-Git-Tag: v1.1.1^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=3dd21f0cd4bb7ce1cda0d97a5673138a085fea82;p=WP-Plugins%2Fglm-serverstats.git Updated Update Server related code. --- diff --git a/defines.php b/defines.php index 29d59bf..edee637 100644 --- a/defines.php +++ b/defines.php @@ -36,7 +36,7 @@ define('GLM_SERVERSTATS_PLUGIN_DEBUG_SMARTY', false); * global instances from clashing with instances in other plugins. */ $vprefix = str_replace('-', '_', GLM_SERVERSTATS_PLUGIN_SLUG); -define('GLM_SERVERSTATS_PREFIX', $vprefix.'_'); +define('GLM_SERVERSTATS_PLUGIN_PREFIX', $vprefix.'_'); // URLs define('GLM_SERVERSTATS_SITE_BASE_URL', home_url('/') ); @@ -60,3 +60,5 @@ define('GLM_SERVERSTATS_PLUGIN_CONFIG_PATH', GLM_SERVERSTATS_PLUGIN_PATH.'/confi define('GLM_SERVERSTATS_PLUGIN_MODEL_PATH', GLM_SERVERSTATS_PLUGIN_PATH.'/models'); 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 diff --git a/index.php b/index.php index 3431ce7..6b668e2 100644 --- a/index.php +++ b/index.php @@ -180,23 +180,19 @@ function serverStatsController($model) } - /* * Plugin Update Support - uses Gaslight Media update server */ -require GLM_SERVERSTATS_PLUGIN_LIB_PATH.'/opentools-update-checker/opentools-update-checker.php'; -${GLM_SERVERSTATS_PREFIX."updateChecker"} = new OpenToolsPluginUpdateChecker( - 'http://www.gaslightmedia.com/update_server/?action=get_metadata&slug='.GLM_SERVERSTATS_PLUGIN_SLUG, +require_once GLM_SERVERSTATS_PLUGIN_LIB_PATH.'/opentools-update-checker/opentools-update-checker.php'; +${GLM_SERVERSTATS_PLUGIN_PREFIX."updateChecker"} = new OpenToolsPluginUpdateChecker( + GLM_SERVERSTATS_PLUGIN_UPDATE_SERVER.'/?action=get_metadata&slug='.GLM_SERVERSTATS_PLUGIN_SLUG, __FILE__, GLM_SERVERSTATS_PLUGIN_SLUG ); - -${GLM_SERVERSTATS_PREFIX."updateChecker"}->declareCredentials(array( - 'license_key' => __('License Key:') +${GLM_SERVERSTATS_PLUGIN_PREFIX."updateChecker"}->declareCredentials(array( + 'license_key' => __('License Key:') )); - - /* * * Activate and Deactivate hooks diff --git a/lib/opentools-update-checker/js/opentools-updatecheck.js b/lib/opentools-update-checker/js/opentools-updatecheck.js index 662a5cf..c064289 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 853ef8f..6f0b4bb 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/languages/plugin-update-checker-fr_FR.po b/lib/plugin-update-checker/languages/plugin-update-checker-fr_FR.po index bcbcd15..b5df93a 100644 --- a/lib/plugin-update-checker/languages/plugin-update-checker-fr_FR.po +++ b/lib/plugin-update-checker/languages/plugin-update-checker-fr_FR.po @@ -25,7 +25,7 @@ msgid "Check for updates" msgstr "Vérifier les mises à jour" #: plugin-update-checker.php:681 -msgid "This plugin is up to date." +msgid "No plugin update available." msgstr "Ce plugin est à jour." #: plugin-update-checker.php:683 diff --git a/lib/plugin-update-checker/languages/plugin-update-checker-hu_HU.po b/lib/plugin-update-checker/languages/plugin-update-checker-hu_HU.po index df22657..13c71f5 100644 --- a/lib/plugin-update-checker/languages/plugin-update-checker-hu_HU.po +++ b/lib/plugin-update-checker/languages/plugin-update-checker-hu_HU.po @@ -25,7 +25,7 @@ msgid "Check for updates" msgstr "Frissítés ellenőrzése" #: plugin-update-checker.php:896 -msgid "This plugin is up to date." +msgid "No plugin update available." msgstr "Ez a plugin naprakész." #: plugin-update-checker.php:898 diff --git a/lib/plugin-update-checker/languages/plugin-update-checker.pot b/lib/plugin-update-checker/languages/plugin-update-checker.pot index bcbbd84..6923604 100644 --- a/lib/plugin-update-checker/languages/plugin-update-checker.pot +++ b/lib/plugin-update-checker/languages/plugin-update-checker.pot @@ -26,7 +26,7 @@ msgid "Check for updates" msgstr "" #: plugin-update-checker.php:896 -msgid "This plugin is up to date." +msgid "No plugin update available." msgstr "" #: plugin-update-checker.php:898 diff --git a/lib/plugin-update-checker/plugin-update-checker.php b/lib/plugin-update-checker/plugin-update-checker.php index 4855629..38760f4 100644 --- a/lib/plugin-update-checker/plugin-update-checker.php +++ b/lib/plugin-update-checker/plugin-update-checker.php @@ -196,18 +196,22 @@ class PluginUpdateChecker_3_1 { //Try to parse the response $status = $this->validateApiResponse($result); $pluginInfo = null; - if ( !is_wp_error($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 $this->triggerError( sprintf('The URL %s does not point to a valid plugin metadata file. ', $url) . $status->get_error_message(), E_USER_WARNING ); + */ } $pluginInfo = apply_filters('puc_request_info_result-'.$this->slug, $pluginInfo, $result); @@ -805,7 +809,7 @@ class PluginUpdateChecker_3_1 { if ( isset($_GET['puc_update_check_result'], $_GET['puc_slug']) && ($_GET['puc_slug'] == $this->slug) ) { $status = strval($_GET['puc_update_check_result']); if ( $status == 'no_update' ) { - $message = __('This plugin is up to date.', 'plugin-update-checker'); + $message = __('No plugin update available.', 'plugin-update-checker'); } else if ( $status == 'update_available' ) { $message = __('A new version of this plugin is available.', 'plugin-update-checker'); } else {