Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/popup-bu.../com/libs
File: WOOSL_CodeAutoUpdate.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace sgpb;
[2] Fix | Delete
/**
[3] Fix | Delete
* Allows plugins to use their own update API.
[4] Fix | Delete
* Note: This updater is not used for Community/Hosted version of the plugin.
[5] Fix | Delete
* This class is included in addons to have an update system in a single file rather than including it in each extension.
[6] Fix | Delete
*/
[7] Fix | Delete
class WOOSL_CodeAutoUpdate
[8] Fix | Delete
{
[9] Fix | Delete
[10] Fix | Delete
// URL to check for updates, this is where the index.php script goes
[11] Fix | Delete
private $plugin;
[12] Fix | Delete
private $api_url;
[13] Fix | Delete
private $slug;
[14] Fix | Delete
private $API_VERSION = 1.1;
[15] Fix | Delete
private $product_unique_id;
[16] Fix | Delete
private $license;
[17] Fix | Delete
private $name;
[18] Fix | Delete
private $version;
[19] Fix | Delete
[20] Fix | Delete
private $cache_key = '';
[21] Fix | Delete
private $beta = '';
[22] Fix | Delete
[23] Fix | Delete
function __construct($api_url, $plugin, $product_unique_id, $license, $version)
[24] Fix | Delete
{
[25] Fix | Delete
$this->api_url = $api_url;
[26] Fix | Delete
$this->slug = basename($plugin, '.php');
[27] Fix | Delete
$this->plugin = $plugin;
[28] Fix | Delete
$this->product_unique_id = $product_unique_id;
[29] Fix | Delete
$this->license = $license;
[30] Fix | Delete
$this->name = plugin_basename($plugin);
[31] Fix | Delete
$this->cache_key = md5(serialize($this->slug.$this->license));
[32] Fix | Delete
$this->version = $version;
[33] Fix | Delete
[34] Fix | Delete
$this->init();
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
public function init()
[38] Fix | Delete
{
[39] Fix | Delete
add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'));
[40] Fix | Delete
add_filter('plugins_api', array($this, 'plugins_api_filter'), 10, 3);
[41] Fix | Delete
[42] Fix | Delete
remove_action('after_plugin_row_'.$this->name, 'wp_plugin_update_row', 10);
[43] Fix | Delete
add_action('after_plugin_row_'.$this->name, array($this, 'show_update_notification'), 10, 2);
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
public function getVersionInfoFromCache($cache_key = '')
[47] Fix | Delete
{
[48] Fix | Delete
if (empty($cache_key)) {
[49] Fix | Delete
$cache_key = $this->cache_key;
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
$cache = get_option($cache_key);
[53] Fix | Delete
if (empty($cache['timeout']) || current_time('timestamp') > $cache['timeout']) {
[54] Fix | Delete
return false;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
return json_decode($cache['value']);
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
public function updateVersionInfoInCache($value = '', $cache_key = '')
[61] Fix | Delete
{
[62] Fix | Delete
if (empty($cache_key)) {
[63] Fix | Delete
$cache_key = $this->cache_key;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
$data = array(
[67] Fix | Delete
'timeout' => strtotime('+3 hours', current_time('timestamp')),
[68] Fix | Delete
'value' => wp_json_encode($value)
[69] Fix | Delete
);
[70] Fix | Delete
[71] Fix | Delete
update_option($cache_key, $data, 'no');
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
private function getVersionInfoFromApi()
[75] Fix | Delete
{
[76] Fix | Delete
global $wp_version;
[77] Fix | Delete
[78] Fix | Delete
$request = $this->prepare_request('plugin_information');
[79] Fix | Delete
$request_uri = $this->api_url.'?'.http_build_query($request , '', '&');
[80] Fix | Delete
[81] Fix | Delete
$response = wp_remote_get($request_uri, array(
[82] Fix | Delete
'timeout' => 20,
[83] Fix | Delete
'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url'),
[84] Fix | Delete
));
[85] Fix | Delete
[86] Fix | Delete
$responseBody = wp_remote_retrieve_body($response);
[87] Fix | Delete
if (empty($responseBody)) {
[88] Fix | Delete
return [];
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
$response = json_decode($responseBody)[0];
[92] Fix | Delete
[93] Fix | Delete
if (is_object($response) && !empty($response)) {
[94] Fix | Delete
$response = $this->postprocess_response($response);
[95] Fix | Delete
return $response;
[96] Fix | Delete
}
[97] Fix | Delete
return [];
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
private function getVersionInfo()
[101] Fix | Delete
{
[102] Fix | Delete
$versionInfo = $this->getVersionInfoFromCache();
[103] Fix | Delete
if (empty($versionInfo)) {
[104] Fix | Delete
$versionInfo = $this->getVersionInfoFromApi();
[105] Fix | Delete
$this->updateVersionInfoInCache($versionInfo);
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
return $versionInfo;
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
public function show_update_notification($file, $plugin)
[112] Fix | Delete
{
[113] Fix | Delete
if (!current_user_can('update_plugins') || $this->name != $file) {
[114] Fix | Delete
return;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
// Remove our filter on the site transient
[118] Fix | Delete
remove_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'), 10);
[119] Fix | Delete
$update_cache = get_site_transient('update_plugins');
[120] Fix | Delete
$update_cache = is_object( $update_cache ) ? $update_cache : new \stdClass();
[121] Fix | Delete
if (empty($update_cache->response) || empty($update_cache->response[$this->name])) {
[122] Fix | Delete
$version_info = $this->getVersionInfo();
[123] Fix | Delete
if (!is_object($version_info) || !isset($version_info->version) || !isset($version_info->new_version)) {
[124] Fix | Delete
return;
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
if (version_compare($this->version, $version_info->new_version, '<')) {
[128] Fix | Delete
$update_cache->response[$this->name] = $version_info;
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
$update_cache->last_checked = current_time('timestamp');
[132] Fix | Delete
$update_cache->checked[$this->name] = $this->version;
[133] Fix | Delete
set_site_transient('update_plugins', $update_cache);
[134] Fix | Delete
} else {
[135] Fix | Delete
$version_info = $update_cache->response[$this->name];
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
// Restore our filter
[139] Fix | Delete
add_filter('pre_set_site_transient_update_plugins', array($this, 'check_update'));
[140] Fix | Delete
if (!empty($update_cache->response[$this->name]) && version_compare($this->version, $version_info->new_version, '<')) {
[141] Fix | Delete
do_action("in_plugin_update_message-{$file}", $plugin, $version_info);
[142] Fix | Delete
} else {
[143] Fix | Delete
set_site_transient('update_plugins', $update_cache);
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
public function check_update($checked_data)
[148] Fix | Delete
{
[149] Fix | Delete
if (!is_object($checked_data) || !isset($checked_data->response)) {
[150] Fix | Delete
return $checked_data;
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
$version_info = $this->getVersionInfo();
[154] Fix | Delete
if( !isset($version_info->version) || !isset($version_info->new_version))
[155] Fix | Delete
{
[156] Fix | Delete
return $checked_data;
[157] Fix | Delete
}
[158] Fix | Delete
if (version_compare($this->version, $version_info->new_version, '<')) {
[159] Fix | Delete
$checked_data->last_checked = current_time('timestamp');
[160] Fix | Delete
$checked_data->checked[$this->name] = $this->version;
[161] Fix | Delete
$checked_data->response[$this->name] = $version_info;
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
return $checked_data;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
public function plugins_api_filter($def, $action, $args)
[168] Fix | Delete
{
[169] Fix | Delete
if (!is_object($args) || !isset($args->slug) || $args->slug != $this->slug) {
[170] Fix | Delete
return $def;
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
$request_string = $this->prepare_request($action, $args);
[174] Fix | Delete
if ($request_string === FALSE) {
[175] Fix | Delete
return new \WP_Error('plugins_api_failed', __('An error occour when try to identify the plugin.' , 'popup-builder') . '&lt;/p> &lt;p>&lt;a href=&quot;?&quot; onclick=&quot;document.location.reload(); return false;&quot;>'. __( 'Try again', 'popup-builder' ) .'&lt;/a>');;
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
global $wp_version;
[179] Fix | Delete
[180] Fix | Delete
$request_uri = $this->api_url.'?'.http_build_query($request_string , '', '&');
[181] Fix | Delete
$data = wp_remote_get($request_uri, array(
[182] Fix | Delete
'timeout' => 20,
[183] Fix | Delete
'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url'),
[184] Fix | Delete
));
[185] Fix | Delete
[186] Fix | Delete
if (is_wp_error($data) || $data['response']['code'] != 200) {
[187] Fix | Delete
return new \WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.' , 'popup-builder') . '&lt;/p> &lt;p>&lt;a href=&quot;?&quot; onclick=&quot;document.location.reload(); return false;&quot;>'. __( 'Try again', 'popup-builder' ) .'&lt;/a>', $data->get_error_message());
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
$response_block = json_decode($data['body']);
[191] Fix | Delete
//retrieve the last message within the $response_block
[192] Fix | Delete
$response_block = $response_block[count($response_block) - 1];
[193] Fix | Delete
$response = $response_block->message;
[194] Fix | Delete
[195] Fix | Delete
if (is_object($response) && !empty($response)) {
[196] Fix | Delete
$response = $this->postprocess_response($response);
[197] Fix | Delete
return $response;
[198] Fix | Delete
}
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
public function prepare_request($action, $args = array())
[202] Fix | Delete
{
[203] Fix | Delete
global $wp_version;
[204] Fix | Delete
[205] Fix | Delete
return array(
[206] Fix | Delete
'woo_sl_action' => $action,
[207] Fix | Delete
'version' => '1.4.2',
[208] Fix | Delete
'product_unique_id' => $this->product_unique_id,
[209] Fix | Delete
'licence_key' => $this->license,
[210] Fix | Delete
'domain' => home_url(),
[211] Fix | Delete
'wp-version' => $wp_version,
[212] Fix | Delete
'api_version' => $this->API_VERSION
[213] Fix | Delete
);
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
private function postprocess_response($response)
[217] Fix | Delete
{
[218] Fix | Delete
//include slug and plugin data
[219] Fix | Delete
$response->slug = $this->slug;
[220] Fix | Delete
$response->plugin = $this->plugin;
[221] Fix | Delete
//if sections are being set
[222] Fix | Delete
if (isset($response->version)) {
[223] Fix | Delete
$response->new_version = $response->version;
[224] Fix | Delete
}
[225] Fix | Delete
else
[226] Fix | Delete
$response->new_version = $this->version;
[227] Fix | Delete
[228] Fix | Delete
//if sections are being set
[229] Fix | Delete
if (isset($response->sections)) {
[230] Fix | Delete
$response->sections = (array)$response->sections;
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
//if banners are being set
[234] Fix | Delete
if (isset($response->banners)) {
[235] Fix | Delete
$response->banners = (array)$response->banners;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
//if icons being set, convert to array
[239] Fix | Delete
if (isset($response->icons)) {
[240] Fix | Delete
$response->icons = (array)$response->icons;
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
return $response;
[244] Fix | Delete
}
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function