PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.7
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.7
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / classes / class-imagify-files-recursive-iterator.php

class-imagify-files-recursive-iterator.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.7, at inc/classes/class-imagify-files-recursive-iterator.php

71 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' );
3
4 /**
5 * Class allowing to filter RecursiveDirectoryIterator, to return only files that Imagify can optimize.
6 * It also allows to remove forbidden folders.
7 *
8 * @since 1.7
9 * @author Grégory Viguier
10 */
11 class Imagify_Files_Recursive_Iterator extends RecursiveFilterIterator {
12
13 /**
14 * Class version.
15 *
16 * @var string
17 * @since 1.7
18 * @author Grégory Viguier
19 */
20 const VERSION = '1.0';
21
22 /**
23 * Check whether the current element of the iterator is acceptable.
24 *
25 * @since 1.7
26 * @access public
27 * @author Grégory Viguier
28 *
29 * @return bool Returns whether the current element of the iterator is acceptable through this filter.
30 */
31 public function accept() {
32 static $extensions, $has_extension_method;
33
34 // Forbidden file/folder paths and names.
35 $file_path = $this->current()->getPathname();
36
37 if ( Imagify_Files_Scan::is_path_forbidden( $file_path ) ) {
38 return false;
39 }
40
41 // OK for folders.
42 if ( $this->hasChildren() ) {
43 return true;
44 }
45
46 // Only files.
47 if ( ! $this->current()->isFile() ) {
48 return false;
49 }
50
51 // Only files with the required extension.
52 if ( ! isset( $extensions ) ) {
53 $extensions = array_keys( imagify_get_mime_types() );
54 $extensions = implode( '|', $extensions );
55 }
56
57 if ( ! isset( $has_extension_method ) ) {
58 // This method was introduced in php 5.3.6.
59 $has_extension_method = method_exists( $this->current(), 'getExtension' );
60 }
61
62 if ( $has_extension_method ) {
63 $file_extension = strtolower( $this->current()->getExtension() );
64 } else {
65 $file_extension = strtolower( pathinfo( $file_path, PATHINFO_EXTENSION ) );
66 }
67
68 return preg_match( '@^' . $extensions . '$@', $file_extension );
69 }
70 }
71