From 6c5b540cb069f332b45207e6a2bc72b6af4b8910 Mon Sep 17 00:00:00 2001 From: gerarmedina1708 Date: Mon, 3 Apr 2023 17:47:25 -0400 Subject: [PATCH 1/3] changes error array and reviews --- app/campaigns_list.php | 12 +++++++----- app/wpematico_functions.php | 20 +++++++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/campaigns_list.php b/app/campaigns_list.php index 7d14f80..18c4616 100644 --- a/app/campaigns_list.php +++ b/app/campaigns_list.php @@ -66,11 +66,13 @@ public static function wpematico_debug_notice() { if ($post_type != 'wpematico') return; $danger_options = WPeMatico::get_danger_options(); - if ($danger_options['wpe_debug_logs_campaign']) { - $class = 'notice notice-warning notice-alt'; - $message = __('WARNING! WPeMatico Debug mode has been activated at Settings->System Status->Danger Zone.', 'wpematico') . '
' - . __('Be sure to deactivate it after your tests to avoid performance issues.', 'wpematico'); - printf('

%2$s

', esc_attr($class), $message); + if(is_array($danger_options)){ + if ($danger_options['wpe_debug_logs_campaign']) { + $class = 'notice notice-warning notice-alt'; + $message = __('WARNING! WPeMatico Debug mode has been activated at Settings->System Status->Danger Zone.', 'wpematico') . '
' + . __('Be sure to deactivate it after your tests to avoid performance issues.', 'wpematico'); + printf('

%2$s

', esc_attr($class), $message); + } } } diff --git a/app/wpematico_functions.php b/app/wpematico_functions.php index c4204b9..a3233f9 100644 --- a/app/wpematico_functions.php +++ b/app/wpematico_functions.php @@ -17,10 +17,13 @@ header('HTTP/1.1 403 Forbidden'); exit(); } +const URL_REVIEWS = 'https://wordpress.org/support/plugin/wpematico/reviews/?filter=5'; if (!class_exists('WPeMatico_functions')) { - + class WPeMatico_functions { + //Constant defined for a condition and don't put the argunments in request + public static $current_feed = ''; // The current feed that is running. @@ -1581,7 +1584,12 @@ public static function wpematico_get_contents($url, $arg = true) { $args = wp_parse_args($aux, $defaults); if (!$data) { // if stil getting error on get file content try WP func, this may give timeouts - $response = wp_remote_request($url, $args); + if($url == URL_REVIEWS){ + $response = wp_remote_request($url); + }else{ + $response = wp_remote_request($url, $args); + } + if (!is_wp_error($response)) { if (isset($response['response']['code']) && 200 === $response['response']['code']) { $data = wp_remote_retrieve_body($response); @@ -1616,9 +1624,11 @@ public static function get_curl_version() { public static function get_danger_options() { $danger = get_option('WPeMatico_danger'); - $danger['wpemdeleoptions'] = (isset($danger['wpemdeleoptions']) && !empty($danger['wpemdeleoptions']) ) ? $danger['wpemdeleoptions'] : false; - $danger['wpemdelecampaigns'] = (isset($danger['wpemdelecampaigns']) && !empty($danger['wpemdelecampaigns']) ) ? $danger['wpemdelecampaigns'] : false; - $danger['wpe_debug_logs_campaign'] = (isset($danger['wpe_debug_logs_campaign']) && !empty($danger['wpe_debug_logs_campaign']) ) ? $danger['wpe_debug_logs_campaign'] : false; + if(isset($danger) && !empty($danger) && is_array($danger)){ + $danger['wpemdeleoptions'] = (isset($danger['wpemdeleoptions']) && !empty($danger['wpemdeleoptions']) ) ? $danger['wpemdeleoptions'] : false; + $danger['wpemdelecampaigns'] = (isset($danger['wpemdelecampaigns']) && !empty($danger['wpemdelecampaigns']) ) ? $danger['wpemdelecampaigns'] : false; + $danger['wpe_debug_logs_campaign'] = (isset($danger['wpe_debug_logs_campaign']) && !empty($danger['wpe_debug_logs_campaign']) ) ? $danger['wpe_debug_logs_campaign'] : false; + } return $danger; } From 1e46304fa84d69ee0c0ae9865a612cb48928e261 Mon Sep 17 00:00:00 2001 From: gerarmedina1708 Date: Tue, 4 Apr 2023 15:53:38 -0400 Subject: [PATCH 2/3] changes code, return array and conditions --- app/wpematico_functions.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/app/wpematico_functions.php b/app/wpematico_functions.php index a3233f9..38651fb 100644 --- a/app/wpematico_functions.php +++ b/app/wpematico_functions.php @@ -17,14 +17,9 @@ header('HTTP/1.1 403 Forbidden'); exit(); } -const URL_REVIEWS = 'https://wordpress.org/support/plugin/wpematico/reviews/?filter=5'; - if (!class_exists('WPeMatico_functions')) { class WPeMatico_functions { - //Constant defined for a condition and don't put the argunments in request - - public static $current_feed = ''; // The current feed that is running. /** @@ -1584,11 +1579,7 @@ public static function wpematico_get_contents($url, $arg = true) { $args = wp_parse_args($aux, $defaults); if (!$data) { // if stil getting error on get file content try WP func, this may give timeouts - if($url == URL_REVIEWS){ - $response = wp_remote_request($url); - }else{ - $response = wp_remote_request($url, $args); - } + $response = wp_remote_request($url, array()); if (!is_wp_error($response)) { if (isset($response['response']['code']) && 200 === $response['response']['code']) { @@ -1624,15 +1615,27 @@ public static function get_curl_version() { public static function get_danger_options() { $danger = get_option('WPeMatico_danger'); - if(isset($danger) && !empty($danger) && is_array($danger)){ + //Function call for the better distribution of code + $getDanger = WPeMatico_functions::wpematico_get_danger_options($danger); + + return $getDanger; + } + + protected static function wpematico_get_danger_options($danger=false) : array + { + if(is_array($danger)){ $danger['wpemdeleoptions'] = (isset($danger['wpemdeleoptions']) && !empty($danger['wpemdeleoptions']) ) ? $danger['wpemdeleoptions'] : false; $danger['wpemdelecampaigns'] = (isset($danger['wpemdelecampaigns']) && !empty($danger['wpemdelecampaigns']) ) ? $danger['wpemdelecampaigns'] : false; $danger['wpe_debug_logs_campaign'] = (isset($danger['wpe_debug_logs_campaign']) && !empty($danger['wpe_debug_logs_campaign']) ) ? $danger['wpe_debug_logs_campaign'] : false; + }else{ + $danger = []; + $danger['wpemdeleoptions'] = false; + $danger['wpemdelecampaigns'] = false; + $danger['wpe_debug_logs_campaign'] = false; } return $danger; } - } // Class WPeMatico_functions From 77ad0735614da2534e63d293095c5667ad6f9429 Mon Sep 17 00:00:00 2001 From: gerarmedina1708 Date: Tue, 4 Apr 2023 21:54:40 -0400 Subject: [PATCH 3/3] changes in campaings and ratings functions --- app/campaigns_list.php | 2 -- app/lib/wp_ratings.php | 4 ++-- app/wpematico_functions.php | 10 +--------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/app/campaigns_list.php b/app/campaigns_list.php index 18c4616..ec59a74 100644 --- a/app/campaigns_list.php +++ b/app/campaigns_list.php @@ -66,14 +66,12 @@ public static function wpematico_debug_notice() { if ($post_type != 'wpematico') return; $danger_options = WPeMatico::get_danger_options(); - if(is_array($danger_options)){ if ($danger_options['wpe_debug_logs_campaign']) { $class = 'notice notice-warning notice-alt'; $message = __('WARNING! WPeMatico Debug mode has been activated at Settings->System Status->Danger Zone.', 'wpematico') . '
' . __('Be sure to deactivate it after your tests to avoid performance issues.', 'wpematico'); printf('

%2$s

', esc_attr($class), $message); } - } } /** diff --git a/app/lib/wp_ratings.php b/app/lib/wp_ratings.php index 15ce520..2e55956 100644 --- a/app/lib/wp_ratings.php +++ b/app/lib/wp_ratings.php @@ -18,14 +18,14 @@ $cookie_jar = @tempnam('./tmp','cookie'); $args = array( 'user-agent'=> "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1", - 'cookies' => array($cookie_jar) + // 'cookies' => array($cookie_jar) ); $html = WPeMatico_functions::wpematico_get_contents($url, $args); //print_r( $html,1 ); //exit; // remove the cookie jar -unlink($cookie_jar) /*or die("Can't unlink $cookie_jar")*/; +// unlink($cookie_jar) /*or die("Can't unlink $cookie_jar")*/; if (!$html) { echo '
'. __('Can\t connect to Wordpress Site', 'wpematico' ).'
'; diff --git a/app/wpematico_functions.php b/app/wpematico_functions.php index 38651fb..c986be7 100644 --- a/app/wpematico_functions.php +++ b/app/wpematico_functions.php @@ -1579,8 +1579,7 @@ public static function wpematico_get_contents($url, $arg = true) { $args = wp_parse_args($aux, $defaults); if (!$data) { // if stil getting error on get file content try WP func, this may give timeouts - $response = wp_remote_request($url, array()); - + $response = wp_remote_request($url, $args); if (!is_wp_error($response)) { if (isset($response['response']['code']) && 200 === $response['response']['code']) { $data = wp_remote_retrieve_body($response); @@ -1615,14 +1614,7 @@ public static function get_curl_version() { public static function get_danger_options() { $danger = get_option('WPeMatico_danger'); - //Function call for the better distribution of code - $getDanger = WPeMatico_functions::wpematico_get_danger_options($danger); - return $getDanger; - } - - protected static function wpematico_get_danger_options($danger=false) : array - { if(is_array($danger)){ $danger['wpemdeleoptions'] = (isset($danger['wpemdeleoptions']) && !empty($danger['wpemdeleoptions']) ) ? $danger['wpemdeleoptions'] : false; $danger['wpemdelecampaigns'] = (isset($danger['wpemdelecampaigns']) && !empty($danger['wpemdelecampaigns']) ) ? $danger['wpemdelecampaigns'] : false;