| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); | |
| 3 | 2 | |
| 4 | 3 | /** |
| 5 | 4 | * Class handling everything that is related to "custom folders optimization". |
| 6 | 5 | * |
| @@ -54,9 +53,9 @@ | ||
| 54 | 53 | if ( $filesystem->is_site_root( $folder ) ) { |
| 55 | 54 | // For the site's root, we don't look in sub-folders. |
| 56 | 55 | $dir = new DirectoryIterator( $folder ); |
| 57 | 56 | $dir = new Imagify_Files_Iterator( $dir, false ); |
| 58 | - $images = array(); | |
| 57 | + $images = []; | |
| 59 | 58 | |
| 60 | 59 | foreach ( new IteratorIterator( $dir ) as $file ) { |
| 61 | 60 | $images[] = $file->getPathname(); |
| 62 | 61 | } |
| @@ -170,14 +169,14 @@ | ||
| 170 | 169 | |
| 171 | 170 | $filesystem = imagify_get_filesystem(); |
| 172 | 171 | $site_root = $filesystem->get_site_root(); |
| 173 | 172 | $abspath = $filesystem->get_abspath(); |
| 174 | - $folders = array( | |
| 173 | + $folders = [ | |
| 175 | 174 | // Server. |
| 176 | 175 | $site_root . 'cgi-bin', // `cgi-bin` |
| 177 | 176 | // WordPress. |
| 178 | - $abspath . 'wp-admin', // `wp-admin` | |
| 179 | - $abspath . WPINC, // `wp-includes` | |
| 177 | + $abspath . 'wp-admin', | |
| 178 | + $abspath . WPINC, | |
| 180 | 179 | WP_CONTENT_DIR . '/mu-plugins', // MU plugins. |
| 181 | 180 | WP_CONTENT_DIR . '/upgrade', // Upgrade. |
| 182 | 181 | // Plugins. |
| 183 | 182 | WP_CONTENT_DIR . '/bps-backup', // BulletProof Security. |
| @@ -189,9 +188,9 @@ | ||
| 189 | 188 | WP_CONTENT_DIR . '/wp-rocket-config', // WP Rocket. |
| 190 | 189 | Imagify_Custom_Folders::get_backup_dir_path(), // Imagify "Custom folders" backup: /imagify-backup. |
| 191 | 190 | IMAGIFY_PATH, // Imagify plugin: /wp-content/plugins/imagify. |
| 192 | 191 | self::get_shortpixel_path(), // ShortPixel: /wp-content/uploads/ShortpixelBackups. |
| 193 | - ); | |
| 192 | + ]; | |
| 194 | 193 | |
| 195 | 194 | if ( ! is_multisite() ) { |
| 196 | 195 | $uploads_dir = $filesystem->get_upload_basedir( true ); |
| 197 | 196 | $ngg_galleries = self::get_ngg_galleries_path(); |
| @@ -205,9 +204,9 @@ | ||
| 205 | 204 | $folders[] = self::get_wc_logs_path(); // WooCommerce Logs: /wp-content/uploads/wc-logs. |
| 206 | 205 | $folders[] = $uploads_dir . 'woocommerce_uploads'; // WooCommerce uploads: /wp-content/uploads/woocommerce_uploads. |
| 207 | 206 | } |
| 208 | 207 | |
| 209 | - $folders = array_map( array( $filesystem, 'normalize_dir_path' ), $folders ); | |
| 208 | + $folders = array_map( [ $filesystem, 'normalize_dir_path' ], $folders ); | |
| 210 | 209 | |
| 211 | 210 | /** |
| 212 | 211 | * Add folders to the list of forbidden ones. |
| 213 | 212 | * |
| @@ -216,9 +215,9 @@ | ||
| 216 | 215 | * |
| 217 | 216 | * @param array $added_folders List of absolute paths. |
| 218 | 217 | * @param array $folders List of folders already forbidden. |
| 219 | 218 | */ |
| 220 | - $added_folders = apply_filters( 'imagify_add_forbidden_folders', array(), $folders ); | |
| 219 | + $added_folders = apply_filters( 'imagify_add_forbidden_folders', [], $folders ); | |
| 221 | 220 | $added_folders = array_filter( (array) $added_folders ); |
| 222 | 221 | $added_folders = array_filter( $added_folders, 'is_string' ); |
| 223 | 222 | |
| 224 | 223 | if ( ! $added_folders ) { |
| @@ -224,9 +223,9 @@ | ||
| 224 | 223 | if ( ! $added_folders ) { |
| 225 | 224 | return $folders; |
| 226 | 225 | } |
| 227 | 226 | |
| 228 | - $added_folders = array_map( array( $filesystem, 'normalize_dir_path' ), $added_folders ); | |
| 227 | + $added_folders = array_map( [ $filesystem, 'normalize_dir_path' ], $added_folders ); | |
| 229 | 228 | |
| 230 | 229 | $folders = array_merge( $folders, $added_folders ); |
| 231 | 230 | $folders = array_flip( array_flip( $folders ) ); |
| 232 | 231 | |
| @@ -251,9 +250,9 @@ | ||
| 251 | 250 | if ( isset( $folders ) ) { |
| 252 | 251 | return $folders; |
| 253 | 252 | } |
| 254 | 253 | |
| 255 | - $folders = array(); | |
| 254 | + $folders = []; | |
| 256 | 255 | |
| 257 | 256 | // Media Library: /wp\-content/uploads/(sites/\d+/)?\d{4}/\d{2}/. |
| 258 | 257 | $folders[] = self::get_media_library_pattern(); |
| 259 | 258 | |
| @@ -279,9 +278,9 @@ | ||
| 279 | 278 | * |
| 280 | 279 | * @param array $added_folders List of patterns. |
| 281 | 280 | * @param array $folders List of patterns already forbidden. |
| 282 | 281 | */ |
| 283 | - $added_folders = apply_filters( 'imagify_add_forbidden_folder_patterns', array(), $folders ); | |
| 282 | + $added_folders = apply_filters( 'imagify_add_forbidden_folder_patterns', [], $folders ); | |
| 284 | 283 | $added_folders = array_filter( (array) $added_folders ); |
| 285 | 284 | $added_folders = array_filter( $added_folders, 'is_string' ); |
| 286 | 285 | |
| 287 | 286 | if ( ! $added_folders ) { |
| @@ -330,9 +329,9 @@ | ||
| 330 | 329 | if ( isset( $file_names ) ) { |
| 331 | 330 | return $file_names; |
| 332 | 331 | } |
| 333 | 332 | |
| 334 | - $file_names = array( | |
| 333 | + $file_names = [ | |
| 335 | 334 | '.', |
| 336 | 335 | '..', |
| 337 | 336 | '.DS_Store', |
| 338 | 337 | '.git', |
| @@ -344,9 +343,9 @@ | ||
| 344 | 343 | 'langs', |
| 345 | 344 | 'languages', |
| 346 | 345 | 'node_modules', |
| 347 | 346 | 'Thumbs.db', |
| 348 | - ); | |
| 347 | + ]; | |
| 349 | 348 | $file_names = array_map( 'strtolower', $file_names ); |
| 350 | 349 | |
| 351 | 350 | /** |
| 352 | 351 | * Add file names to the list of forbidden ones. |
| @@ -356,9 +355,9 @@ | ||
| 356 | 355 | * |
| 357 | 356 | * @param array $added_file_names List of file names. |
| 358 | 357 | * @param array $file_names List of file names already forbidden. |
| 359 | 358 | */ |
| 360 | - $added_file_names = apply_filters( 'imagify_add_forbidden_file_names', array(), $file_names ); | |
| 359 | + $added_file_names = apply_filters( 'imagify_add_forbidden_file_names', [], $file_names ); | |
| 361 | 360 | |
| 362 | 361 | if ( ! $added_file_names || ! is_array( $added_file_names ) ) { |
| 363 | 362 | return $file_names; |
| 364 | 363 | } |
| @@ -445,9 +444,9 @@ | ||
| 445 | 444 | return $replacements; |
| 446 | 445 | } |
| 447 | 446 | |
| 448 | 447 | $filesystem = imagify_get_filesystem(); |
| 449 | - $replacements = array( | |
| 448 | + $replacements = [ | |
| 450 | 449 | '{{PLUGINS}}/' => WP_PLUGIN_DIR, |
| 451 | 450 | '{{MU_PLUGINS}}/' => WPMU_PLUGIN_DIR, |
| 452 | 451 | '{{THEMES}}/' => WP_CONTENT_DIR . '/themes', |
| 453 | 452 | '{{UPLOADS}}/' => $filesystem->get_main_upload_basedir(), |
| @@ -452,10 +451,10 @@ | ||
| 452 | 451 | '{{THEMES}}/' => WP_CONTENT_DIR . '/themes', |
| 453 | 452 | '{{UPLOADS}}/' => $filesystem->get_main_upload_basedir(), |
| 454 | 453 | '{{CONTENT}}/' => WP_CONTENT_DIR, |
| 455 | 454 | '{{ROOT}}/' => $filesystem->get_site_root(), |
| 456 | - ); | |
| 457 | - $replacements = array_map( array( $filesystem, 'normalize_dir_path' ), $replacements ); | |
| 455 | + ]; | |
| 456 | + $replacements = array_map( [ $filesystem, 'normalize_dir_path' ], $replacements ); | |
| 458 | 457 | |
| 459 | 458 | return $replacements; |
| 460 | 459 | } |
| 461 | 460 | |
| @@ -475,9 +474,9 @@ | ||
| 475 | 474 | return $replacements; |
| 476 | 475 | } |
| 477 | 476 | |
| 478 | 477 | $filesystem = imagify_get_filesystem(); |
| 479 | - $replacements = array( | |
| 478 | + $replacements = [ | |
| 480 | 479 | '{{PLUGINS}}/' => plugins_url( '/' ), |
| 481 | 480 | '{{MU_PLUGINS}}/' => plugins_url( '/', WPMU_PLUGIN_DIR . '/.' ), |
| 482 | 481 | '{{THEMES}}/' => content_url( 'themes/' ), |
| 483 | 482 | '{{UPLOADS}}/' => $filesystem->get_main_upload_baseurl(), |
| @@ -482,9 +481,9 @@ | ||
| 482 | 481 | '{{THEMES}}/' => content_url( 'themes/' ), |
| 483 | 482 | '{{UPLOADS}}/' => $filesystem->get_main_upload_baseurl(), |
| 484 | 483 | '{{CONTENT}}/' => content_url( '/' ), |
| 485 | 484 | '{{ROOT}}/' => $filesystem->get_site_root_url(), |
| 486 | - ); | |
| 485 | + ]; | |
| 487 | 486 | |
| 488 | 487 | return $replacements; |
| 489 | 488 | } |
| 490 | 489 | |
| @@ -532,10 +531,10 @@ | ||
| 532 | 531 | if ( $galleries_path && 'content' === $ngg_root ) { |
| 533 | 532 | $ngg_root = $filesystem->normalize_dir_path( WP_CONTENT_DIR ); |
| 534 | 533 | $ngg_root = trim( $ngg_root, '/' ); // Something like `abs-path/to/wp-content`. |
| 535 | 534 | |
| 536 | - $exploded_root = explode( '/', $ngg_root ); | |
| 537 | - $exploded_galleries = explode( '/', $galleries_path ); | |
| 535 | + $exploded_root = explode( '/', $ngg_root ); | |
| 536 | + $exploded_galleries = explode( '/', $galleries_path ); | |
| 538 | 537 | $first_gallery_dirname = reset( $exploded_galleries ); |
| 539 | 538 | $last_root_dirname = end( $exploded_root ); |
| 540 | 539 | |
| 541 | 540 | if ( $last_root_dirname === $first_gallery_dirname ) { |
| @@ -673,9 +672,9 @@ | ||
| 673 | 672 | return false; |
| 674 | 673 | } |
| 675 | 674 | |
| 676 | 675 | $galleries_path = self::normalize_path_for_regex( $galleries_path ); |
| 677 | - $galleries_path = str_replace( array( '%blog_name%', '%blog_id%' ), array( '.+', '\d+' ), $galleries_path ); | |
| 676 | + $galleries_path = str_replace( [ '%blog_name%', '%blog_id%' ], [ '.+', '\d+' ], $galleries_path ); | |
| 678 | 677 | |
| 679 | 678 | return $galleries_path; |
| 680 | 679 | } |
| 681 | 680 | |