| @@ -1,12 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); | |
| 2 | +use Imagify\Notices\Notices; | |
| 3 | +use Imagify\User\User; | |
| 3 | 4 | |
| 5 | +defined( 'ABSPATH' ) || exit; | |
| 6 | + | |
| 4 | 7 | /** |
| 5 | 8 | * Tell if the current screen is what we're looking for. |
| 6 | 9 | * |
| 7 | - * @since 1.6.10 | |
| 8 | - * @author Grégory Viguier | |
| 10 | + * @since 1.6.10 | |
| 9 | 11 | * |
| 10 | 12 | * @param string $identifier The screen "name". |
| 11 | 13 | * @return bool |
| 12 | 14 | */ |
| @@ -87,10 +89,10 @@ | ||
| 87 | 89 | * @return string The URL of the specific admin page or action. |
| 88 | 90 | */ |
| 89 | 91 | function get_imagify_admin_url( $action = 'settings', $arg = [] ) { |
| 90 | 92 | if ( is_array( $arg ) ) { |
| 91 | - $id = isset( $arg['attachment_id'] ) ? $arg['attachment_id'] : 0; | |
| 92 | - $context = isset( $arg['context'] ) ? $arg['context'] : 'wp'; | |
| 93 | + $id = isset( $arg['attachment_id'] ) ? $arg['attachment_id'] : 0; | |
| 94 | + $context = isset( $arg['context'] ) ? $arg['context'] : 'wp'; | |
| 93 | 95 | $level = isset( $arg['optimization_level'] ) ? $arg['optimization_level'] : ''; |
| 94 | 96 | } |
| 95 | 97 | |
| 96 | 98 | switch ( $action ) { |
| @@ -100,13 +102,13 @@ | ||
| 100 | 102 | |
| 101 | 103 | case 'optimize-missing-sizes': |
| 102 | 104 | return wp_nonce_url( admin_url( 'admin-post.php?action=imagify_optimize_missing_sizes&attachment_id=' . $id . '&context=' . $context ), 'imagify-optimize-missing-sizes-' . $id . '-' . $context ); |
| 103 | 105 | |
| 104 | - case 'generate-webp-versions': | |
| 105 | - return wp_nonce_url( admin_url( 'admin-post.php?action=imagify_generate_webp_versions&attachment_id=' . $id . '&context=' . $context ), 'imagify-generate-webp-versions-' . $id . '-' . $context ); | |
| 106 | + case 'generate-nextgen-versions': | |
| 107 | + return wp_nonce_url( admin_url( 'admin-post.php?action=imagify_generate_nextgen_versions&attachment_id=' . $id . '&context=' . $context ), 'imagify-generate-nextgen-versions-' . $id . '-' . $context ); | |
| 106 | 108 | |
| 107 | - case 'delete-webp-versions': | |
| 108 | - return wp_nonce_url( admin_url( 'admin-post.php?action=imagify_delete_webp_versions&attachment_id=' . $id . '&context=' . $context ), 'imagify-delete-webp-versions-' . $id . '-' . $context ); | |
| 109 | + case 'delete-nextgen-versions': | |
| 110 | + return wp_nonce_url( admin_url( 'admin-post.php?action=imagify_delete_nextgen_versions&attachment_id=' . $id . '&context=' . $context ), 'imagify-delete-nextgen-versions-' . $id . '-' . $context ); | |
| 109 | 111 | |
| 110 | 112 | case 'optimize': |
| 111 | 113 | case 'manual-upload': // Deprecated. |
| 112 | 114 | case 'manual-optimize': |
| @@ -142,23 +144,28 @@ | ||
| 142 | 144 | |
| 143 | 145 | case 'folder-errors': |
| 144 | 146 | switch ( $arg ) { |
| 145 | 147 | case 'wp': |
| 146 | - return add_query_arg( array( | |
| 147 | - 'mode' => 'list', | |
| 148 | - 'imagify-status' => 'errors', | |
| 149 | - ), admin_url( 'upload.php' ) ); | |
| 148 | + return add_query_arg( | |
| 149 | + [ | |
| 150 | + 'mode' => 'list', | |
| 151 | + 'imagify-status' => 'errors', | |
| 152 | + ], | |
| 153 | + admin_url( 'upload.php' ) | |
| 154 | + ); | |
| 150 | 155 | |
| 151 | 156 | case 'custom-folders': |
| 152 | - return add_query_arg( array( | |
| 153 | - 'status-filter' => 'errors', | |
| 154 | - ), get_imagify_admin_url( 'files-list' ) ); | |
| 157 | + return add_query_arg( | |
| 158 | + [ | |
| 159 | + 'status-filter' => 'errors', | |
| 160 | + ], | |
| 161 | + get_imagify_admin_url( 'files-list' ) | |
| 162 | + ); | |
| 155 | 163 | } |
| 156 | 164 | /** |
| 157 | 165 | * Provide a URL to a page displaying optimization errors for the given context. |
| 158 | 166 | * |
| 159 | - * @since 1.9 | |
| 160 | - * @author Grégory Viguier | |
| 167 | + * @since 1.9 | |
| 161 | 168 | * |
| 162 | 169 | * @param string $url The URL. |
| 163 | 170 | * @param string $arg The context. |
| 164 | 171 | */ |
| @@ -163,10 +170,19 @@ | ||
| 163 | 170 | * @param string $arg The context. |
| 164 | 171 | */ |
| 165 | 172 | return apply_filters( 'imagify_optimization_errors_url', '', $arg ); |
| 166 | 173 | |
| 174 | + case 'missing-nextgen': | |
| 175 | + return add_query_arg( | |
| 176 | + [ | |
| 177 | + 'mode' => 'list', | |
| 178 | + 'imagify-status' => 'missing-nextgen', | |
| 179 | + ], | |
| 180 | + admin_url( 'upload.php' ) | |
| 181 | + ); | |
| 182 | + | |
| 167 | 183 | case 'dismiss-notice': |
| 168 | - return wp_nonce_url( admin_url( 'admin-post.php?action=imagify_dismiss_notice¬ice=' . $arg ), Imagify_Notices::DISMISS_NONCE_ACTION ); | |
| 184 | + return wp_nonce_url( admin_url( 'admin-post.php?action=imagify_dismiss_notice¬ice=' . $arg ), Notices::DISMISS_NONCE_ACTION ); | |
| 169 | 185 | |
| 170 | 186 | default: |
| 171 | 187 | $page = '?page=' . Imagify_Views::get_instance()->get_settings_page_slug(); |
| 172 | 188 | return imagify_is_active_for_network() ? network_admin_url( 'admin.php' . $page ) : admin_url( 'options-general.php' . $page ); |
| @@ -194,12 +210,12 @@ | ||
| 194 | 210 | $height = $_size['height']; |
| 195 | 211 | } |
| 196 | 212 | } |
| 197 | 213 | |
| 198 | - return array( | |
| 214 | + return [ | |
| 199 | 215 | 'width' => $width, |
| 200 | 216 | 'height' => $height, |
| 201 | - ); | |
| 217 | + ]; | |
| 202 | 218 | } |
| 203 | 219 | |
| 204 | 220 | /** |
| 205 | 221 | * Simple helper to get the WP Rocket's site URL. |
| @@ -204,21 +220,20 @@ | ||
| 204 | 220 | /** |
| 205 | 221 | * Simple helper to get the WP Rocket's site URL. |
| 206 | 222 | * The URL is localized and contains some utm_*** parameters. |
| 207 | 223 | * |
| 208 | - * @since 1.6.8 | |
| 209 | - * @since 1.6.9 Added $path and $query parameters. | |
| 210 | - * @author Grégory Viguier | |
| 224 | + * @since 1.6.8 | |
| 225 | + * @since 1.6.9 Added $path and $query parameters. | |
| 211 | 226 | * |
| 212 | 227 | * @param string $path A path to add to the URL (URI). Not in use yet. |
| 213 | 228 | * @param array $query An array of query arguments (utm_*). |
| 214 | 229 | * @return string The URL. |
| 215 | 230 | */ |
| 216 | -function imagify_get_wp_rocket_url( $path = false, $query = array() ) { | |
| 217 | - $wprocket_url = 'https://wp-rocket.me/'; | |
| 231 | +function imagify_get_wp_rocket_url( $path = false, $query = [] ) { | |
| 232 | + $wprocket_url = 'https://wp-rocket.me/wp-rocket-for-imagify-users/'; | |
| 218 | 233 | |
| 219 | 234 | // Current lang. |
| 220 | - $lang = imagify_get_current_lang_in( array( 'de', 'es', 'fr', 'it' ) ); | |
| 235 | + $lang = imagify_get_current_lang_in( [ 'de', 'es', 'fr', 'it' ] ); | |
| 221 | 236 | |
| 222 | 237 | if ( 'en' !== $lang ) { |
| 223 | 238 | $wprocket_url .= $lang . '/'; |
| 224 | 239 | } |
| @@ -223,17 +238,17 @@ | ||
| 223 | 238 | $wprocket_url .= $lang . '/'; |
| 224 | 239 | } |
| 225 | 240 | |
| 226 | 241 | // URI. |
| 227 | - $paths = array( | |
| 228 | - 'pricing' => array( | |
| 242 | + $paths = [ | |
| 243 | + 'pricing' => [ | |
| 229 | 244 | 'de' => 'preise', |
| 230 | 245 | 'en' => 'pricing', |
| 231 | 246 | 'es' => 'precios', |
| 232 | 247 | 'fr' => 'offres', |
| 233 | 248 | 'it' => 'offerte', |
| 234 | - ), | |
| 235 | - ); | |
| 249 | + ], | |
| 250 | + ]; | |
| 236 | 251 | |
| 237 | 252 | if ( $path ) { |
| 238 | 253 | $path = trim( $path, '/' ); |
| 239 | 254 | |
| @@ -244,13 +259,16 @@ | ||
| 244 | 259 | } |
| 245 | 260 | } |
| 246 | 261 | |
| 247 | 262 | // Query args. |
| 248 | - $query = array_merge( array( | |
| 249 | - 'utm_source' => 'imagify-coupon', | |
| 250 | - 'utm_medium' => 'plugin', | |
| 251 | - 'utm_campaign' => 'imagify', | |
| 252 | - ), $query ); | |
| 263 | + $query = array_merge( | |
| 264 | + [ | |
| 265 | + 'utm_source' => 'imagify', | |
| 266 | + 'utm_medium' => 'partners', | |
| 267 | + 'utm_campaign' => 'imagify-benefits', | |
| 268 | + ], | |
| 269 | + $query | |
| 270 | + ); | |
| 253 | 271 | |
| 254 | 272 | return add_query_arg( $query, $wprocket_url ); |
| 255 | 273 | } |
| 256 | 274 | |
| @@ -256,11 +274,10 @@ | ||
| 256 | 274 | |
| 257 | 275 | /** |
| 258 | 276 | * Check for nonce. |
| 259 | 277 | * |
| 260 | - * @since 1.9.11 Return true when nonce is good. | |
| 261 | - * @since 1.6.10 | |
| 262 | - * @author Grégory Viguier | |
| 278 | + * @since 1.9.11 Return true when nonce is good. | |
| 279 | + * @since 1.6.10 | |
| 263 | 280 | * |
| 264 | 281 | * @param string $action Action nonce. |
| 265 | 282 | * @param string|bool $query_arg Optional. Key to check for the nonce in `$_REQUEST`. If false, `$_REQUEST` values will be evaluated for '_ajax_nonce', and '_wpnonce' (in that order). Default false. |
| 266 | 283 | * |
| @@ -277,10 +294,9 @@ | ||
| 277 | 294 | |
| 278 | 295 | /** |
| 279 | 296 | * Die Today. |
| 280 | 297 | * |
| 281 | - * @since 1.6.10 | |
| 282 | - * @author Grégory Viguier | |
| 298 | + * @since 1.6.10 | |
| 283 | 299 | * |
| 284 | 300 | * @param string $message A message to display. |
| 285 | 301 | */ |
| 286 | 302 | function imagify_die( $message = null ) { |
| @@ -292,9 +308,9 @@ | ||
| 292 | 308 | } |
| 293 | 309 | |
| 294 | 310 | if ( is_array( $message ) ) { |
| 295 | 311 | if ( ! empty( $message['error'] ) ) { |
| 296 | - $message['error'] = imagify_translate_api_message( $message['error'] ); | |
| 312 | + $message['error'] = imagify_translate_api_message( $message['error'] ); | |
| 297 | 313 | } elseif ( ! empty( $message['detail'] ) ) { |
| 298 | 314 | $message['detail'] = imagify_translate_api_message( $message['detail'] ); |
| 299 | 315 | } |
| 300 | 316 | } |
| @@ -314,9 +330,10 @@ | ||
| 314 | 330 | } |
| 315 | 331 | |
| 316 | 332 | if ( wp_get_referer() ) { |
| 317 | 333 | $message .= '</p><p>'; |
| 318 | - $message .= sprintf( '<a href="%s">%s</a>', | |
| 334 | + $message .= sprintf( | |
| 335 | + '<a href="%s">%s</a>', | |
| 319 | 336 | esc_url( remove_query_arg( 'updated', wp_get_referer() ) ), |
| 320 | 337 | /* translators: This sentense already exists in WordPress. */ |
| 321 | 338 | __( 'Go back', 'imagify' ) |
| 322 | 339 | ); |
| @@ -322,21 +339,20 @@ | ||
| 322 | 339 | ); |
| 323 | 340 | } |
| 324 | 341 | |
| 325 | 342 | /* translators: %s is the plugin name. */ |
| 326 | - wp_die( $message, sprintf( __( '%s Failure Notice', 'imagify' ), 'Imagify' ), 403 ); | |
| 343 | + wp_die( $message, sprintf( esc_html__( '%s Failure Notice', 'imagify' ), 'Imagify' ), 403 ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 327 | 344 | } |
| 328 | 345 | |
| 329 | 346 | /** |
| 330 | 347 | * Redirect if not an ajax request. |
| 331 | 348 | * |
| 332 | - * @since 1.6.10 | |
| 333 | - * @author Grégory Viguier | |
| 349 | + * @since 1.6.10 | |
| 334 | 350 | * |
| 335 | 351 | * @param string $message A message to display in an admin notice once redirected. |
| 336 | 352 | * @param array|string $args_or_url An array of query args to add to the redirection URL. If a string, the complete URL. |
| 337 | 353 | */ |
| 338 | -function imagify_maybe_redirect( $message = false, $args_or_url = array() ) { | |
| 354 | +function imagify_maybe_redirect( $message = false, $args_or_url = [] ) { | |
| 339 | 355 | if ( wp_doing_ajax() ) { |
| 340 | 356 | return; |
| 341 | 357 | } |
| 342 | 358 | |
| @@ -350,10 +366,9 @@ | ||
| 350 | 366 | |
| 351 | 367 | /** |
| 352 | 368 | * Filter the URL to redirect to. |
| 353 | 369 | * |
| 354 | - * @since 1.6.10 | |
| 355 | - * @author Grégory Viguier | |
| 370 | + * @since 1.6.10 | |
| 356 | 371 | * |
| 357 | 372 | * @param string $redirect The URL to redirect to. |
| 358 | 373 | */ |
| 359 | 374 | $redirect = apply_filters( 'imagify_redirect_to', $redirect ); |
| @@ -359,11 +374,11 @@ | ||
| 359 | 374 | $redirect = apply_filters( 'imagify_redirect_to', $redirect ); |
| 360 | 375 | |
| 361 | 376 | if ( $message ) { |
| 362 | 377 | if ( is_multisite() && strpos( $redirect, network_admin_url( '/' ) ) === 0 ) { |
| 363 | - Imagify_Notices::get_instance()->add_network_temporary_notice( $message ); | |
| 378 | + Notices::get_instance()->add_network_temporary_notice( $message ); | |
| 364 | 379 | } else { |
| 365 | - Imagify_Notices::get_instance()->add_site_temporary_notice( $message ); | |
| 380 | + Notices::get_instance()->add_site_temporary_notice( $message ); | |
| 366 | 381 | } |
| 367 | 382 | } |
| 368 | 383 | |
| 369 | 384 | wp_safe_redirect( esc_url_raw( $redirect ) ); |
| @@ -373,10 +388,9 @@ | ||
| 373 | 388 | /** |
| 374 | 389 | * Get cached Imagify user data. |
| 375 | 390 | * This is usefull to prevent triggering an HTTP request to our server on every page load, but it can be used only where the data doesn't need to be in real time. |
| 376 | 391 | * |
| 377 | - * @since 1.7 | |
| 378 | - * @author Grégory Viguier | |
| 392 | + * @since 1.7 | |
| 379 | 393 | * |
| 380 | 394 | * @return object|bool An object on success. False otherwise. |
| 381 | 395 | */ |
| 382 | 396 | function imagify_get_cached_user() { |
| @@ -396,10 +410,9 @@ | ||
| 396 | 410 | /** |
| 397 | 411 | * Cache Imagify user data for 5 minutes. |
| 398 | 412 | * Runs every methods to store the results. Also stores formatted data like the quota and the next update date. |
| 399 | 413 | * |
| 400 | - * @since 1.7 | |
| 401 | - * @author Grégory Viguier | |
| 414 | + * @since 1.7 | |
| 402 | 415 | * |
| 403 | 416 | * @return object|bool An object on success. False otherwise. |
| 404 | 417 | */ |
| 405 | 418 | function imagify_cache_user() { |
| @@ -406,9 +419,9 @@ | ||
| 406 | 419 | if ( ! Imagify_Requirements::is_api_key_valid() ) { |
| 407 | 420 | return false; |
| 408 | 421 | } |
| 409 | 422 | |
| 410 | - $user = new Imagify_User(); | |
| 423 | + $user = new User(); | |
| 411 | 424 | $data = (object) get_object_vars( $user ); |
| 412 | 425 | $methods = get_class_methods( $user ); |
| 413 | 426 | |
| 414 | 427 | foreach ( $methods as $method ) { |
| @@ -416,9 +429,9 @@ | ||
| 416 | 429 | $data->$method = $user->$method(); |
| 417 | 430 | } |
| 418 | 431 | } |
| 419 | 432 | |
| 420 | - $data->quota_formatted = imagify_size_format( $user->quota * pow( 1024, 2 ) ); | |
| 433 | + $data->quota_formatted = imagify_size_format( $user->get_quota() * pow( 1024, 2 ) ); | |
| 421 | 434 | $data->next_date_update_formatted = date_i18n( get_option( 'date_format' ), strtotime( $user->next_date_update ) ); |
| 422 | 435 | |
| 423 | 436 | if ( imagify_is_active_for_network() ) { |
| 424 | 437 | set_site_transient( 'imagify_user', $data, 5 * MINUTE_IN_SECONDS ); |
| @@ -431,10 +444,9 @@ | ||
| 431 | 444 | |
| 432 | 445 | /** |
| 433 | 446 | * Delete cached Imagify user data. |
| 434 | 447 | * |
| 435 | - * @since 1.9.5 | |
| 436 | - * @author Grégory Viguier | |
| 448 | + * @since 1.9.5 | |
| 437 | 449 | */ |
| 438 | 450 | function imagify_delete_cached_user() { |
| 439 | 451 | if ( imagify_is_active_for_network() ) { |
| 440 | 452 | delete_site_transient( 'imagify_user' ); |