Skip to content
This repository has been archived by the owner on Mar 18, 2020. It is now read-only.

Commit

Permalink
Updated version-check fallback code
Browse files Browse the repository at this point in the history
  • Loading branch information
drbyte committed Dec 15, 2017
1 parent 6663294 commit cd64352
Showing 1 changed file with 51 additions and 48 deletions.
99 changes: 51 additions & 48 deletions includes/modules/payment/payeezyjszc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

}
}

0 comments on commit cd64352

Please sign in to comment.