| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | */ |
| 27 | 27 | class MainWP_Api_Manager_Plugin_Update { |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Protected static variable to hold the instance. | |
| 30 | + * Protected static varibale to hold the instance. | |
| 31 | 31 | * |
| 32 | 32 | * @var null Default value. |
| 33 | 33 | */ |
| 34 | 34 | protected static $instance = null; |
| @@ -64,16 +64,14 @@ | ||
| 64 | 64 | * @param array $args Request arguments. |
| 65 | 65 | * @param bool $bulk_check Bulk check request. |
| 66 | 66 | * |
| 67 | 67 | * @return string Build URL. |
| 68 | - * | |
| 69 | - * @uses \MainWP\Dashboard\MainWP_Api_Manager::get_upgrade_url() | |
| 70 | 68 | */ |
| 71 | 69 | private function create_upgrade_api_url( $args, $bulk_check = true ) { |
| 72 | 70 | if ( $bulk_check ) { |
| 73 | 71 | $upgrade_url = esc_url_raw( add_query_arg( 'mainwp-api', 'am-software-api', MainWP_Api_Manager::instance()->get_upgrade_url() ) ); |
| 74 | 72 | } else { |
| 75 | - $upgrade_url = esc_url_raw( add_query_arg( 'mainwp-api', 'am-software-api', MainWP_Api_Manager::instance()->get_upgrade_url() ) ); // old: wc-api/upgrade-api. | |
| 73 | + $upgrade_url = esc_url_raw( add_query_arg( 'wc-api', 'upgrade-api', MainWP_Api_Manager::instance()->get_upgrade_url() ) ); | |
| 76 | 74 | } |
| 77 | 75 | |
| 78 | 76 | $query_url = ''; |
| 79 | 77 | foreach ( $args as $key => $value ) { |
| @@ -98,15 +96,17 @@ | ||
| 98 | 96 | 'plugin_name' => $plugin['plugin_name'], |
| 99 | 97 | 'version' => $plugin['software_version'], |
| 100 | 98 | 'product_id' => $plugin['product_id'], |
| 101 | 99 | 'api_key' => $plugin['api_key'], |
| 100 | + 'activation_email' => $plugin['activation_email'], | |
| 102 | 101 | 'instance' => $plugin['instance'], |
| 102 | + 'domain' => $plugin['domain'], | |
| 103 | 103 | 'software_version' => $plugin['software_version'], |
| 104 | 104 | 'extra' => isset( $plugin['extra'] ) ? $plugin['extra'] : '', |
| 105 | 105 | ); |
| 106 | 106 | |
| 107 | 107 | // Check for a plugin update. |
| 108 | - return $this->plugin_information( $args ); // pluginupdatecheck. | |
| 108 | + return $this->plugin_information( $args ); | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | /** |
| @@ -116,36 +116,28 @@ | ||
| 116 | 116 | * |
| 117 | 117 | * @return array Plugin Information & bulkupdatecheck. |
| 118 | 118 | */ |
| 119 | 119 | public function bulk_update_check( $plugins ) { |
| 120 | - | |
| 121 | 120 | $args = array( |
| 122 | 121 | 'request' => 'bulkupdatecheck', |
| 123 | - 'extensions' => base64_encode( wp_json_encode( $plugins ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. | |
| 124 | - 'json' => true, | |
| 122 | + 'domain' => MainWP_Api_Manager::instance()->get_domain(), | |
| 123 | + 'extensions' => base64_encode( serialize( $plugins ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. | |
| 125 | 124 | ); |
| 126 | - | |
| 127 | - $mainwp_api_key = MainWP_Api_Manager_Key::instance()->get_decrypt_master_api_key(); | |
| 128 | - | |
| 129 | - if ( ! empty( $mainwp_api_key ) ) { | |
| 130 | - $args['api_key'] = $mainwp_api_key; | |
| 131 | - } | |
| 132 | - | |
| 133 | - return $this->plugin_information( $args, true ); // bulkupdatecheck. | |
| 125 | + return $this->plugin_information( $args, true ); // bulk update check. | |
| 134 | 126 | } |
| 135 | 127 | |
| 136 | 128 | |
| 137 | 129 | /** |
| 138 | - * Check $args, if there is a response, an object exists & response is not false. | |
| 130 | + * Check $args, if there is a response, an object eists & response is not false. | |
| 139 | 131 | * |
| 140 | 132 | * @param array $args Request arguments. |
| 141 | 133 | * |
| 142 | - * @return array|false $response Plugin information. | |
| 134 | + * @return object $response Plugin information. | |
| 143 | 135 | */ |
| 144 | 136 | public function request( $args ) { |
| 145 | 137 | $args['request'] = 'plugininformation'; |
| 146 | 138 | |
| 147 | - $response = $this->plugin_information( $args ); // plugininformation. | |
| 139 | + $response = $this->plugin_information( $args ); | |
| 148 | 140 | |
| 149 | 141 | // If everything is okay return the response. |
| 150 | 142 | if ( isset( $response ) && is_object( $response ) && false !== $response ) { |
| 151 | 143 | return $response; |
| @@ -154,45 +146,37 @@ | ||
| 154 | 146 | |
| 155 | 147 | /** |
| 156 | 148 | * Sends and receives data to and from the server API. |
| 157 | 149 | * |
| 158 | - * @access public | |
| 150 | + * @access public | |
| 159 | 151 | * |
| 152 | + * @since 1.0.0 | |
| 153 | + * | |
| 160 | 154 | * @param array $args Request arguments. |
| 161 | 155 | * @param bool $bulk_check Check if updating in bulk true|false. |
| 162 | 156 | * |
| 163 | - * @return array|false Plugin information. | |
| 164 | - * @since 1.0.0 | |
| 165 | - * | |
| 166 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::maybe_unserialyze() | |
| 157 | + * @return object Plugin information. | |
| 167 | 158 | */ |
| 168 | 159 | public function plugin_information( $args, $bulk_check = false ) { |
| 169 | - | |
| 170 | - $args['object'] = MainWP_Api_Manager::instance()->get_domain(); | |
| 171 | - | |
| 172 | - $target_url = $this->create_upgrade_api_url( $args, $bulk_check ); | |
| 173 | - $default = array( | |
| 174 | - 'timeout' => 150, | |
| 175 | - 'sslverify' => 1, | |
| 176 | - ); | |
| 177 | - | |
| 178 | - $params = apply_filters( 'mainwp_plugin_information_sslverify', $default, $args ); | |
| 179 | - | |
| 180 | - $request = wp_remote_get( | |
| 160 | + $target_url = $this->create_upgrade_api_url( $args, $bulk_check ); | |
| 161 | + $apisslverify = ( ( get_option( 'mainwp_api_sslVerifyCertificate' ) === false ) || ( get_option( 'mainwp_api_sslVerifyCertificate' ) == 1 ) ) ? 1 : 0; | |
| 162 | + $request = wp_remote_get( | |
| 181 | 163 | $target_url, |
| 182 | - $params | |
| 164 | + array( | |
| 165 | + 'timeout' => 50, | |
| 166 | + 'sslverify' => $apisslverify, | |
| 167 | + ) | |
| 183 | 168 | ); |
| 184 | 169 | |
| 185 | - if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) { | |
| 170 | + if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) != 200 ) { | |
| 186 | 171 | return false; |
| 187 | 172 | } |
| 188 | 173 | |
| 189 | - $response = wp_remote_retrieve_body( $request ); | |
| 190 | - | |
| 191 | - if ( isset( $args['json'] ) ) { // bulkupdatecheck: json. | |
| 192 | - $response = json_decode( $response, true ); | |
| 193 | - } else { // pluginupdatecheck, plugininformation : serialize. | |
| 194 | - $response = unserialize( $response ); // phpcs:ignore -- data from extensions, to compatible. | |
| 174 | + if ( $bulk_check ) { | |
| 175 | + $response = wp_remote_retrieve_body( $request ); | |
| 176 | + $response = MainWP_System_Utility::maybe_unserialyze( $response ); | |
| 177 | + } else { | |
| 178 | + $response = MainWP_System_Utility::maybe_unserialyze( wp_remote_retrieve_body( $request ) ); | |
| 195 | 179 | } |
| 196 | 180 | |
| 197 | 181 | /** |
| 198 | 182 | * For debugging errors from the API |
| @@ -201,9 +185,9 @@ | ||
| 201 | 185 | */ |
| 202 | 186 | if ( ! $bulk_check ) { |
| 203 | 187 | if ( is_object( $response ) ) { |
| 204 | 188 | if ( isset( $response->package ) ) { |
| 205 | - $response->package = apply_filters( 'mainwp_api_manager_upgrade_package_url', $response->package, $response ); | |
| 189 | + $response->package = apply_filters( 'mainwp_api_manager_upgrade_url', $response->package ); | |
| 206 | 190 | } |
| 207 | 191 | return $response; |
| 208 | 192 | } |
| 209 | 193 | } elseif ( is_array( $response ) ) { |
| @@ -211,7 +195,8 @@ | ||
| 211 | 195 | } |
| 212 | 196 | |
| 213 | 197 | return false; |
| 214 | 198 | } |
| 199 | + | |
| 215 | 200 | } |
| 216 | 201 | |
| 217 | 202 | // End of class. |