| @@ -7,15 +7,26 @@ | ||
| 7 | 7 | |
| 8 | 8 | if (!class_exists('Re_Smush_It_Task')) : |
| 9 | 9 | |
| 10 | 10 | class Re_Smush_It_Task extends Updraft_Smush_Task { |
| 11 | - | |
| 11 | + | |
| 12 | + /** | |
| 13 | + * Task name | |
| 14 | + * | |
| 15 | + * @var string | |
| 16 | + */ | |
| 12 | 17 | public $label = 're-smush-it'; |
| 13 | 18 | |
| 19 | + /** | |
| 20 | + * Maximum filesize | |
| 21 | + */ | |
| 14 | 22 | const MAX_FILESIZE = 5242880; |
| 23 | + | |
| 24 | + /** | |
| 25 | + * API URL | |
| 26 | + */ | |
| 27 | + const API_URL = 'https://api.resmush.it/'; | |
| 15 | 28 | |
| 16 | - const API_URL = 'http://api.resmush.it/'; | |
| 17 | - | |
| 18 | 29 | /** |
| 19 | 30 | * Checks if the server is online |
| 20 | 31 | * |
| 21 | 32 | * @return boolean - true if yes, false otherwise |
| @@ -23,9 +34,9 @@ | ||
| 23 | 34 | public static function is_server_online() { |
| 24 | 35 | |
| 25 | 36 | global $wp_version; |
| 26 | 37 | $test_image = WPO_PLUGIN_MAIN_PATH . 'images/icon/wpo.png'; |
| 27 | - $boundary = wp_generate_password(12); | |
| 38 | + $boundary = wp_generate_password(); | |
| 28 | 39 | $file_name = basename($test_image); |
| 29 | 40 | |
| 30 | 41 | $body = "--$boundary"; |
| 31 | 42 | $body .= "\r\n"; |
| @@ -67,15 +78,17 @@ | ||
| 67 | 78 | |
| 68 | 79 | /** |
| 69 | 80 | * Prepares the image as part of the post data for the specific implementation |
| 70 | 81 | * |
| 71 | - * @param String $local_file - The image to e optimised | |
| 82 | + * @param string $local_file - The image to e optimised | |
| 72 | 83 | * @param array $options - Eventual options |
| 84 | + * | |
| 85 | + * @return array | |
| 73 | 86 | */ |
| 74 | 87 | public function prepare_post_request($local_file, $options) { |
| 75 | 88 | global $wp_version; |
| 76 | 89 | |
| 77 | - $boundary = wp_generate_password(12); | |
| 90 | + $boundary = wp_generate_password(); | |
| 78 | 91 | $headers = array( "content-type" => "multipart/form-data; boundary=$boundary" ); |
| 79 | 92 | |
| 80 | 93 | $lossy = $this->get_option('lossy_compression'); |
| 81 | 94 | |
| @@ -119,12 +132,11 @@ | ||
| 119 | 132 | |
| 120 | 133 | /** |
| 121 | 134 | * Processes the response received from the remote server |
| 122 | 135 | * |
| 123 | - * @param String $response - The response object | |
| 136 | + * @param mixed $response - The response object | |
| 124 | 137 | */ |
| 125 | 138 | public function process_server_response($response) { |
| 126 | - global $http_response_header; | |
| 127 | 139 | |
| 128 | 140 | $response = parent::process_server_response($response); |
| 129 | 141 | $data = json_decode(wp_remote_retrieve_body($response)); |
| 130 | 142 | |
| @@ -139,9 +151,9 @@ | ||
| 139 | 151 | } |
| 140 | 152 | |
| 141 | 153 | if (!property_exists($data, 'dest')) { |
| 142 | 154 | $this->fail("invalid_response", "The response does not contain the compressed file URL"); |
| 143 | - $this->log("data: ".json_encode($data)); | |
| 155 | + $this->log("data: ".wp_json_encode($data)); | |
| 144 | 156 | return false; |
| 145 | 157 | } |
| 146 | 158 | |
| 147 | 159 | $compressed_image_response = wp_remote_get($data->dest); |
| @@ -155,12 +167,10 @@ | ||
| 155 | 167 | return false; |
| 156 | 168 | } |
| 157 | 169 | } else { |
| 158 | 170 | $this->fail("invalid_response", "The compression apparently succeeded, but WP-Optimize could not retrieve the compressed image from the remote server."); |
| 159 | - $this->log("data: ".json_encode($data)); | |
| 160 | - if (!empty($http_response_header) && is_array($http_response_header)) { | |
| 161 | - $this->log("headers: ".implode("\n", $http_response_header)); | |
| 162 | - } | |
| 171 | + $this->log("data: ".wp_json_encode($data)); | |
| 172 | + $this->log("error: ".$compressed_image_response->get_error_message()); | |
| 163 | 173 | return false; |
| 164 | 174 | } |
| 165 | 175 | } |
| 166 | 176 | |
| @@ -166,9 +176,9 @@ | ||
| 166 | 176 | |
| 167 | 177 | /** |
| 168 | 178 | * Retrieve features for this service |
| 169 | 179 | * |
| 170 | - * @return Array - an array of options | |
| 180 | + * @return array - an array of options | |
| 171 | 181 | */ |
| 172 | 182 | public static function get_features() { |
| 173 | 183 | return array( |
| 174 | 184 | 'max_filesize' => self::MAX_FILESIZE, |
| @@ -179,9 +189,9 @@ | ||
| 179 | 189 | |
| 180 | 190 | /** |
| 181 | 191 | * Retrieve default options for this task type. |
| 182 | 192 | * |
| 183 | - * @return Array - an array of options | |
| 193 | + * @return array - an array of options | |
| 184 | 194 | */ |
| 185 | 195 | public function get_default_options() { |
| 186 | 196 | return array( |
| 187 | 197 | 'allowed_file_types' => array('gif', 'png', 'jpg', 'tif', 'jpeg'), |