PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / 4.1.1
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets v4.1.1
4.1.1 3.9.5 3.9.6 4.0.0 4.0.1 4.1.0 trunk 2.12 2.13 2.14 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.3-beta-1.0 3.7.4 3.7.4-beta-1.0 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4
wp-all-import / classes / helper.php
wp-all-import / classes Last commit date
XmlStreamReader 1 month ago partner-discount-sdk 1 month ago api.php 1 month ago arraytoxml.php 1 month ago chunk.php 1 month ago config.php 2 years ago download.php 1 month ago error.php 1 month ago handler.php 1 month ago helper.php 1 month ago input.php 1 month ago nested.php 1 month ago rapidaddon.php 1 month ago render.php 1 month ago session.php 10 months ago upload.php 1 month ago zip.php 10 years ago
helper.php
141 lines
1 <?php
2 /**
3 * Helper class which defnes a namespace for some commonly used functions
4 *
5 * @author Maksym Tsypliakov <maksym.tsypliakov@gmail.com>
6 */
7 class PMXI_Helper {
8 const GLOB_MARK = 1;
9 const GLOB_NOSORT = 2;
10 const GLOB_ONLYDIR = 4;
11
12 const GLOB_NODIR = 256;
13 const GLOB_PATH = 512;
14 const GLOB_NODOTS = 1024;
15 const GLOB_RECURSE = 2048;
16
17 const FNM_PATHNAME = 1;
18 const FNM_NOESCAPE = 2;
19 const FNM_PERIOD = 4;
20 const FNM_CASEFOLD = 16;
21
22 /**
23 * A safe empowered glob().
24 *
25 * Function glob() is prohibited on some server (probably in safe mode)
26 * (Message "Warning: glob() has been disabled for security reasons in
27 * (script) on line (line)") for security reasons as stated on:
28 * http://seclists.org/fulldisclosure/2005/Sep/0001.html
29 *
30 * safe_glob() intends to replace glob() using readdir() & fnmatch() instead.
31 * Supported flags: self::GLOB_MARK, self::GLOB_NOSORT, self::GLOB_ONLYDIR
32 * Additional flags: self::GLOB_NODIR, self::GLOB_PATH, self::GLOB_NODOTS, self::GLOB_RECURSE
33 * (not original glob() flags)
34 * @author BigueNique AT yahoo DOT ca
35 * @updates
36 * - 080324 Added support for additional flags: self::GLOB_NODIR, self::GLOB_PATH,
37 * self::GLOB_NODOTS, self::GLOB_RECURSE
38 * - 100607 Recurse is_dir check fixed by Pavel Kulbakin <p.kulbakin@gmail.com>
39 */
40 public static function safe_glob($pattern, $flags=0) {
41 $split = explode('/', str_replace('\\', '/', $pattern));
42 $mask = array_pop($split);
43 $path = implode('/', $split);
44
45 if (($dir = @opendir($path . '/')) !== false or ($dir = @opendir($path)) !== false) {
46 $glob = array();
47 while(($file = readdir($dir)) !== false) {
48 // Recurse subdirectories (self::GLOB_RECURSE)
49 if (($flags & self::GLOB_RECURSE) && is_dir($path . '/' . $file) && ( ! in_array($file, array('.', '..')))) {
50 $glob = array_merge($glob, self::array_prepend(self::safe_glob($path . '/' . $file . '/' . $mask, $flags), ($flags & self::GLOB_PATH ? '' : $file . '/')));
51 }
52 // Match file mask
53 if (self::fnmatch($mask, $file, self::FNM_CASEFOLD)) {
54 if ((( ! ($flags & self::GLOB_ONLYDIR)) || is_dir("$path/$file"))
55 && (( ! ($flags & self::GLOB_NODIR)) || ( ! is_dir($path . '/' . $file)))
56 && (( ! ($flags & self::GLOB_NODOTS)) || ( ! in_array($file, array('.', '..'))))
57 ) {
58 $glob[] = ($flags & self::GLOB_PATH ? $path . '/' : '') . $file . ($flags & self::GLOB_MARK ? '/' : '');
59 }
60 }
61 }
62 closedir($dir);
63 if ( ! ($flags & self::GLOB_NOSORT)) sort($glob);
64 return $glob;
65 } else {
66 return (strpos($pattern, "*") === false) ? array($pattern) : false;
67 }
68 }
69
70 /**
71 * Prepends $string to each element of $array
72 * If $deep is true, will indeed also apply to sub-arrays
73 * @author BigueNique AT yahoo DOT ca
74 * @since 080324
75 */
76 public static function array_prepend($array, $string, $deep=false) {
77 if(empty($array)||empty($string)) {
78 return $array;
79 }
80 foreach ($array as $key => $element) {
81 if (is_array($element)) {
82 if ($deep) {
83 $array[$key] = self::array_prepend($element,$string,$deep);
84 } else {
85 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
86 trigger_error(__METHOD__ . ': array element', E_USER_WARNING);
87 }
88 } else {
89 $array[$key] = $string.$element;
90 }
91 }
92 return $array;
93
94 }
95
96 /**
97 * non-POSIX complient remplacement for the fnmatch
98 */
99 public static function fnmatch($pattern, $string, $flags = 0) {
100
101 $modifiers = null;
102 $transforms = array(
103 '\*' => '.*',
104 '\?' => '.',
105 '\[\!' => '[^',
106 '\[' => '[',
107 '\]' => ']',
108 '\.' => '\.',
109 '\\' => '\\\\',
110 '\-' => '-',
111 );
112
113 // Forward slash in string must be in pattern:
114 if ($flags & self::FNM_PATHNAME) {
115 $transforms['\*'] = '[^/]*';
116 }
117
118 // Back slash should not be escaped:
119 if ($flags & self::FNM_NOESCAPE) {
120 unset($transforms['\\']);
121 }
122
123 // Perform case insensitive match:
124 if ($flags & self::FNM_CASEFOLD) {
125 $modifiers .= 'i';
126 }
127
128 // Period at start must be the same as pattern:
129 if ($flags & self::FNM_PERIOD) {
130 if (strpos($string, '.') === 0 && strpos($pattern, '.') !== 0) return false;
131 }
132
133 $pattern = '#^'
134 .strtr(preg_quote($pattern, '#'), $transforms)
135 .'$#'
136 .$modifiers;
137
138 return (bool)preg_match($pattern, $string);
139 }
140 }
141