From cd643527b948f22f9729943b929e4ce611ec56a1 Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Fri, 15 Dec 2017 18:10:44 -0500 Subject: [PATCH] Updated version-check fallback code --- includes/modules/payment/payeezyjszc.php | 99 ++++++++++++------------ 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/includes/modules/payment/payeezyjszc.php b/includes/modules/payment/payeezyjszc.php index 951f6d8..6cadc32 100644 --- a/includes/modules/payment/payeezyjszc.php +++ b/includes/modules/payment/payeezyjszc.php @@ -31,7 +31,7 @@ class payeezyjszc extends base /** * $moduleVersion is the plugin version number */ - var $moduleVersion = '0.96'; + var $moduleVersion = '0.97'; /** * $title is the displayed name for this payment method * @@ -947,54 +947,59 @@ private function setAvsCvvMeanings() // for backward compatibility with older ZC versions before v152 which didn't have this function: if (!function_exists('plugin_version_check_for_updates')) { - function plugin_version_check_for_updates($plugin_file_id = 0, $version_string_to_compare = '', $strict_zc_version_compare = false) - { + function plugin_version_check_for_updates($plugin_file_id = 0, $version_string_to_compare = '', $strict_zc_version_compare = false) + { if ($plugin_file_id == 0) return false; $new_version_available = false; - $lookup_index = 0; - $url1 = 'https://plugins.zen-cart.com/versioncheck/' . (int)$plugin_file_id; - $url2 = 'https://www.zen-cart.com/versioncheck/' . (int)$plugin_file_id; - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url1); - curl_setopt($ch, CURLOPT_VERBOSE, 0); - curl_setopt($ch, CURLOPT_HEADER, false); - curl_setopt($ch, CURLOPT_TIMEOUT, 9); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 9); - curl_setopt($ch, CURLOPT_USERAGENT, 'Plugin Version Check [' . (int)$plugin_file_id . '] ' . HTTP_SERVER); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $response = curl_exec($ch); - $error = curl_error($ch); - $errno = curl_errno($ch); - - if ($error > 0) { - trigger_error('CURL error checking plugin versions: ' . $errno . ':' . $error . "\nTrying http instead."); - curl_setopt($ch, CURLOPT_URL, str_replace('tps:', 'tp:', $url1)); - $response = curl_exec($ch); - $error = curl_error($ch); - $errno = curl_errno($ch); - } - if ($error > 0) { - trigger_error('CURL error checking plugin versions: ' . $errno . ':' . $error . "\nTrying www instead."); - curl_setopt($ch, CURLOPT_URL, str_replace('tps:', 'tp:', $url2)); + $lookup_index = $errno = 0; + $response = $error = ''; + $url1 = 'https://plugins.zen-cart.com/versioncheck/'.(int)$plugin_file_id; + $url2 = 'https://www.zen-cart.com/versioncheck/'.(int)$plugin_file_id; + + if (function_exists('curl_init')) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL,$url1); + curl_setopt($ch, CURLOPT_VERBOSE, 0); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_TIMEOUT, 9); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 9); + curl_setopt($ch, CURLOPT_USERAGENT, 'Plugin Version Check [' . (int)$plugin_file_id . '] ' . HTTP_SERVER); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); - $error = curl_error($ch); - $errno = curl_errno($ch); - } - curl_close($ch); - if ($error > 0 || $response == '') { - trigger_error('CURL error checking plugin versions: ' . $errno . ':' . $error . "\nTrying file_get_contents() instead."); - $ctx = stream_context_create(['http' => ['timeout' => 5]]); - $response = file_get_contents($url1, null, $ctx); - if ($response === false) { - trigger_error('file_get_contents() error checking plugin versions.' . "\nTrying http instead."); - $response = file_get_contents(str_replace('tps:', 'tp:', $url1), null, $ctx); + $error = curl_error($ch); + $errno = curl_errno($ch); + + if ($errno > 0) { + trigger_error('CURL error checking plugin versions: ' . $errno . ':' . $error . "\nTrying http instead."); + curl_setopt($ch, CURLOPT_URL, str_replace('tps:', 'tp:', $url1)); + $response = curl_exec($ch); + $error = curl_error($ch); + $errno = curl_errno($ch); } - if ($response === false) { - trigger_error('file_get_contents() error checking plugin versions.' . "\nAborting."); - - return false; + if ($errno > 0) { + trigger_error('CURL error checking plugin versions: ' . $errno . ':' . $error . "\nTrying www instead."); + curl_setopt($ch, CURLOPT_URL, str_replace('tps:', 'tp:', $url2)); + $response = curl_exec($ch); + $error = curl_error($ch); + $errno = curl_errno($ch); } + curl_close($ch); + } else { + $errono = 9999; + $error = 'curl_init not found in PHP'; + } + if ($errno > 0 || $response == '') { + trigger_error('CURL error checking plugin versions: ' . $errno . ':' . $error . "\nTrying file_get_contents() instead."); + $ctx = stream_context_create(array('http' => array('timeout' => 5))); + $response = file_get_contents($url1, null, $ctx); + if ($response === false) { + trigger_error('file_get_contents() error checking plugin versions.' . "\nTrying http instead."); + $response = file_get_contents(str_replace('tps:', 'tp:', $url1), null, $ctx); + } + if ($response === false) { + trigger_error('file_get_contents() error checking plugin versions.' . "\nAborting."); + return false; + } } $data = json_decode($response, true); @@ -1004,9 +1009,7 @@ function plugin_version_check_for_updates($plugin_file_id = 0, $version_string_t // check whether present ZC version is compatible with the latest available plugin version $zc_version = PROJECT_VERSION_MAJOR . '.' . preg_replace('/[^0-9.]/', '', PROJECT_VERSION_MINOR); if ($strict_zc_version_compare) $zc_version = PROJECT_VERSION_MAJOR . '.' . PROJECT_VERSION_MINOR; - if (!in_array('v' . $zc_version, $data[$lookup_index]['zcversions'])) $new_version_available = false; - + if (!in_array('v'. $zc_version, $data[$lookup_index]['zcversions'])) $new_version_available = false; return ($new_version_available) ? $data[$lookup_index] : false; - } - + } }