From d41f2ea41af5793b18a6fcd787101e1bff20fc9f Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Thu, 3 Mar 2016 20:24:38 -0500 Subject: [PATCH 01/11] Multibyte String Enhancements: Add `u` modifier to `preg_match()` See websharks/comet-cache#703 --- src/includes/traits/Ac/ObUtils.php | 8 ++++---- src/includes/traits/Plugin/InstallUtils.php | 8 ++++---- src/includes/traits/Shared/CacheDirUtils.php | 8 ++++---- src/includes/traits/Shared/ConditionalUtils.php | 4 ++-- src/includes/traits/Shared/FsUtils.php | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/includes/traits/Ac/ObUtils.php b/src/includes/traits/Ac/ObUtils.php index 042bf077..e9d974da 100644 --- a/src/includes/traits/Ac/ObUtils.php +++ b/src/includes/traits/Ac/ObUtils.php @@ -140,13 +140,13 @@ public function maybeStartOutputBuffering() if (!COMET_CACHE_FEEDS_ENABLE && $this->isFeed()) { return $this->maybeSetDebugInfo($this::NC_DEBUG_FEED_REQUEST); } - if (preg_match('/\/(?:wp\-[^\/]+|xmlrpc)\.php(?:[?]|$)/i', $_SERVER['REQUEST_URI'])) { + if (preg_match('/\/(?:wp\-[^\/]+|xmlrpc)\.php(?:[?]|$)/ui', $_SERVER['REQUEST_URI'])) { return $this->maybeSetDebugInfo($this::NC_DEBUG_WP_SYSTEMATICS); } - if (is_admin() || preg_match('/\/wp-admin(?:[\/?]|$)/i', $_SERVER['REQUEST_URI'])) { + if (is_admin() || preg_match('/\/wp-admin(?:[\/?]|$)/ui', $_SERVER['REQUEST_URI'])) { return $this->maybeSetDebugInfo($this::NC_DEBUG_WP_ADMIN); } - if (is_multisite() && preg_match('/\/files(?:[\/?]|$)/i', $_SERVER['REQUEST_URI'])) { + if (is_multisite() && preg_match('/\/files(?:[\/?]|$)/ui', $_SERVER['REQUEST_URI'])) { return $this->maybeSetDebugInfo($this::NC_DEBUG_MS_FILES); } if ((!IS_PRO || !COMET_CACHE_WHEN_LOGGED_IN) && $this->isLikeUserLoggedIn()) { @@ -277,7 +277,7 @@ public function outputBufferCallbackHandler($buffer, $phase) if ((!IS_PRO || !COMET_CACHE_WHEN_LOGGED_IN) && $this->isLikeUserLoggedIn()) { return (boolean) $this->maybeSetDebugInfo($this::NC_DEBUG_IS_LIKE_LOGGED_IN_USER); } - if (!COMET_CACHE_CACHE_NONCE_VALUES && preg_match('/\b(?:_wpnonce|akismet_comment_nonce)\b/', $cache)) { + if (!COMET_CACHE_CACHE_NONCE_VALUES && preg_match('/\b(?:_wpnonce|akismet_comment_nonce)\b/u', $cache)) { if (IS_PRO && COMET_CACHE_WHEN_LOGGED_IN && $this->isLikeUserLoggedIn()) { if (!COMET_CACHE_CACHE_NONCE_VALUES_WHEN_LOGGED_IN) { return (boolean) $this->maybeSetDebugInfo($this::NC_DEBUG_IS_LOGGED_IN_USER_NONCE); diff --git a/src/includes/traits/Plugin/InstallUtils.php b/src/includes/traits/Plugin/InstallUtils.php index c999fd25..f1fe4bf2 100644 --- a/src/includes/traits/Plugin/InstallUtils.php +++ b/src/includes/traits/Plugin/InstallUtils.php @@ -149,7 +149,7 @@ public function addWpCacheToWpConfig() if (!($wp_config_file_contents_no_whitespace = php_strip_whitespace($wp_config_file))) { return ''; // Failure; file empty } - if (preg_match('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:\-?[1-9][0-9\.]*|TRUE|([\'"])(?:[^0\'"]|[^\'"]{2,})\\2)\s*\)\s*;/i', $wp_config_file_contents_no_whitespace)) { + if (preg_match('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:\-?[1-9][0-9\.]*|TRUE|([\'"])(?:[^0\'"]|[^\'"]{2,})\\2)\s*\)\s*;/ui', $wp_config_file_contents_no_whitespace)) { return $wp_config_file_contents; // It's already in there; no need to modify this file. } if (!($wp_config_file_contents = $this->removeWpCacheFromWpConfig())) { @@ -195,16 +195,16 @@ public function removeWpCacheFromWpConfig() if (!($wp_config_file_contents_no_whitespace = php_strip_whitespace($wp_config_file))) { return ''; // Failure; file empty } - if (!preg_match('/([\'"])WP_CACHE\\1/i', $wp_config_file_contents_no_whitespace)) { + if (!preg_match('/([\'"])WP_CACHE\\1/ui', $wp_config_file_contents_no_whitespace)) { return $wp_config_file_contents; // Already gone. } - if (preg_match('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:0|FALSE|NULL|([\'"])0?\\2)\s*\)\s*;/i', $wp_config_file_contents_no_whitespace) && !is_writable($wp_config_file)) { + if (preg_match('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:0|FALSE|NULL|([\'"])0?\\2)\s*\)\s*;/ui', $wp_config_file_contents_no_whitespace) && !is_writable($wp_config_file)) { return $wp_config_file_contents; // It's already disabled, and since we can't write to this file let's let this slide. } if (!($wp_config_file_contents = preg_replace('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:\-?[0-9\.]+|TRUE|FALSE|NULL|([\'"])[^\'"]*\\2)\s*\)\s*;/i', '', $wp_config_file_contents))) { return ''; // Failure; something went terribly wrong here. } - if (preg_match('/([\'"])WP_CACHE\\1/i', $wp_config_file_contents)) { + if (preg_match('/([\'"])WP_CACHE\\1/ui', $wp_config_file_contents)) { return ''; // Failure; perhaps the `/wp-config.php` file contains syntax we cannot remove safely. } if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) { diff --git a/src/includes/traits/Shared/CacheDirUtils.php b/src/includes/traits/Shared/CacheDirUtils.php index 8adf4c8b..2a71abf3 100644 --- a/src/includes/traits/Shared/CacheDirUtils.php +++ b/src/includes/traits/Shared/CacheDirUtils.php @@ -458,10 +458,10 @@ public function deleteAllFilesDirsIn($dir, $delete_dir_too = false) $wp_content_dir = $this->nDirSeps(WP_CONTENT_DIR); $wp_content_dir_regex = preg_quote($wp_content_dir, '/'); - if (!preg_match('/^'.$wp_content_dir_regex.'\/[^\/]+/i', $dir)) { + if (!preg_match('/^'.$wp_content_dir_regex.'\/[^\/]+/ui', $dir)) { return $counter; // Security flag; do nothing in this case. } - if (preg_match('/^'.$wp_content_dir_regex.'\/(?:mu\-plugins|themes|plugins)(?:\/|$)/i', $dir)) { + if (preg_match('/^'.$wp_content_dir_regex.'\/(?:mu\-plugins|themes|plugins)(?:\/|$)/ui', $dir)) { return $counter; // Security flag; do nothing in this case. } /* ------- Begin lock state... ----------- */ @@ -564,10 +564,10 @@ public function eraseAllFilesDirsIn($dir, $erase_dir_too = false) $wp_content_dir = $this->nDirSeps(WP_CONTENT_DIR); $wp_content_dir_regex = preg_quote($wp_content_dir, '/'); - if (!preg_match('/^'.$wp_content_dir_regex.'\/[^\/]+/i', $dir)) { + if (!preg_match('/^'.$wp_content_dir_regex.'\/[^\/]+/ui', $dir)) { return $counter; // Security flag; do nothing in this case. } - if (preg_match('/^'.$wp_content_dir_regex.'\/(?:mu\-plugins|themes|plugins)(?:\/|$)/i', $dir)) { + if (preg_match('/^'.$wp_content_dir_regex.'\/(?:mu\-plugins|themes|plugins)(?:\/|$)/ui', $dir)) { return $counter; // Security flag; do nothing in this case. } clearstatcache(); // Clear stat cache to be sure we have a fresh start below. diff --git a/src/includes/traits/Shared/ConditionalUtils.php b/src/includes/traits/Shared/ConditionalUtils.php index 3f20c393..5c317be2 100644 --- a/src/includes/traits/Shared/ConditionalUtils.php +++ b/src/includes/traits/Shared/ConditionalUtils.php @@ -191,7 +191,7 @@ public function isLocalhost() if (defined('LOCALHOST')) { return $is = (boolean) LOCALHOST; } - if (preg_match('/\b(?:localhost|127\.0\.0\.1)\b/i', $this->hostToken())) { + if (preg_match('/\b(?:localhost|127\.0\.0\.1)\b/ui', $this->hostToken())) { return $is = true; } return $is = false; @@ -323,7 +323,7 @@ public function hasACacheableStatus() return $is = false; // A non-2xx & non-404 status code. } foreach ($this->headersList() as $_key => $_header) { - if (preg_match('/^(?:Retry\-After\:\s+(?P.+)|Status\:\s+(?P[0-9]+)|HTTP\/[0-9]+(?:\.[0-9]+)?\s+(?P[0-9]+))/i', $_header, $_m)) { + if (preg_match('/^(?:Retry\-After\:\s+(?P.+)|Status\:\s+(?P[0-9]+)|HTTP\/[0-9]+(?:\.[0-9]+)?\s+(?P[0-9]+))/ui', $_header, $_m)) { if (!empty($_m['retry']) || (!empty($_m['status']) && $_m['status'][0] !== '2' && $_m['status'] !== '404') || (!empty($_m['http_status']) && $_m['http_status'][0] !== '2' && $_m['http_status'] !== '404') ) { diff --git a/src/includes/traits/Shared/FsUtils.php b/src/includes/traits/Shared/FsUtils.php index e8ccf641..5a2048f0 100644 --- a/src/includes/traits/Shared/FsUtils.php +++ b/src/includes/traits/Shared/FsUtils.php @@ -24,12 +24,12 @@ public function nDirSeps($dir_file, $allow_trailing_slash = false) return ''; // Catch empty string. } if (strpos($dir_file, '://' !== false)) { - if (preg_match('/^(?P[a-zA-Z0-9]+)\:\/\//', $dir_file, $stream_wrapper)) { + if (preg_match('/^(?P[a-zA-Z0-9]+)\:\/\//u', $dir_file, $stream_wrapper)) { $dir_file = preg_replace('/^(?P[a-zA-Z0-9]+)\:\/\//', '', $dir_file); } } if (strpos($dir_file, ':' !== false)) { - if (preg_match('/^(?P[a-zA-Z])\:[\/\\\\]/', $dir_file)) { + if (preg_match('/^(?P[a-zA-Z])\:[\/\\\\]/u', $dir_file)) { $dir_file = preg_replace_callback('/^(?P[a-zA-Z])\:[\/\\\\]/', create_function('$m', 'return strtoupper($m[0]);'), $dir_file); } } From e6aa315f55687353954dff4245b95f231903a585 Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Thu, 3 Mar 2016 20:36:36 -0500 Subject: [PATCH 02/11] Multibyte String Enhancements: Add `u` modifier to `preg_replace()` See websharks/comet-cache#703 --- src/includes/classes/CdnFilters.php | 10 +++++----- src/includes/classes/Conflicts.php | 4 ++-- src/includes/classes/FeedUtils.php | 10 +++++----- src/includes/classes/VsUpgrades.php | 2 +- src/includes/traits/Plugin/HtaccessUtils.php | 2 +- src/includes/traits/Plugin/InstallUtils.php | 8 ++++---- src/includes/traits/Shared/CachePathUtils.php | 14 ++++++------- .../traits/Shared/DomainMappingUtils.php | 6 +++--- src/includes/traits/Shared/FsUtils.php | 6 +++--- src/includes/traits/Shared/PatternUtils.php | 8 ++++---- src/includes/traits/Shared/StringUtils.php | 4 ++-- src/includes/traits/Shared/TokenUtils.php | 20 +++++++++---------- 12 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/includes/classes/CdnFilters.php b/src/includes/classes/CdnFilters.php index 7c67b358..b30a2e12 100644 --- a/src/includes/classes/CdnFilters.php +++ b/src/includes/classes/CdnFilters.php @@ -180,8 +180,8 @@ public function __construct() if ($cdn_whitelisted_uri_patterns) { $this->cdn_whitelisted_uri_patterns = '/(?:'.implode('|', array_map(function ($pattern) { - return preg_replace(['/\\\\\*/', '/\\\\\^/'], ['.*?', '[^\/]*?'], preg_quote('/'.ltrim($pattern, '/'), '/')); - }, $cdn_whitelisted_uri_patterns)).')/i'; // CaSe inSensitive. + return preg_replace(['/\\\\\*/u', '/\\\\\^/u'], ['.*?', '[^\/]*?'], preg_quote('/'.ltrim($pattern, '/'), '/')); + }, $cdn_whitelisted_uri_patterns)).')/ui'; // CaSe inSensitive. } // Blacklisted URI patterns; if applicable. @@ -199,8 +199,8 @@ public function __construct() if ($cdn_blacklisted_uri_patterns) { $this->cdn_blacklisted_uri_patterns = '/(?:'.implode('|', array_map(function ($pattern) { - return preg_replace(['/\\\\\*/', '/\\\\\^/'], ['.*?', '[^\/]*?'], preg_quote('/'.ltrim($pattern, '/'), '/')); - }, $cdn_blacklisted_uri_patterns)).')/i'; // CaSe inSensitive. + return preg_replace(['/\\\\\*/u', '/\\\\\^/u'], ['.*?', '[^\/]*?'], preg_quote('/'.ltrim($pattern, '/'), '/')); + }, $cdn_blacklisted_uri_patterns)).')/ui'; // CaSe inSensitive. } // Maybe attach filters. @@ -357,7 +357,7 @@ public function contentFilter($string) '(\>)'.// Tag close; group #9. - '/i'; // End regex pattern; case insensitive. + '/ui'; // End regex pattern; case insensitive. $orig_string = $string; // In case of regex errors. $string = preg_replace_callback($regex_url_attrs, function ($m) { diff --git a/src/includes/classes/Conflicts.php b/src/includes/classes/Conflicts.php index c7385021..d2427d39 100644 --- a/src/includes/classes/Conflicts.php +++ b/src/includes/classes/Conflicts.php @@ -78,8 +78,8 @@ protected function maybeEnqueueNotice() } $construct_name = function ($slug_or_ns) { $name = trim(strtolower((string) $slug_or_ns)); - $name = preg_replace('/[_\-]+(?:lite|pro)$/', '', $name); - $name = preg_replace('/[^a-z0-9]/', ' ', $name); + $name = preg_replace('/[_\-]+(?:lite|pro)$/u', '', $name); + $name = preg_replace('/[^a-z0-9]/u', ' ', $name); $name = str_replace('cache', 'Cache', ucwords($name)); return $name; // e.g., `x-cache` becomes `X Cache`. diff --git a/src/includes/classes/FeedUtils.php b/src/includes/classes/FeedUtils.php index 120c12f3..47cc4cb7 100644 --- a/src/includes/classes/FeedUtils.php +++ b/src/includes/classes/FeedUtils.php @@ -177,11 +177,11 @@ public function postTermFeedLinkVariations(\WP_Post $post, $include_regex_wildca if ($include_regex_wildcard_keys && $_term_feed_link && strpos($_term_feed_link, '?') === false) { // Quick example: `(?:123|slug)`; to consider both of these variations. $_term_id_or_slug = '(?:'.preg_quote($_post_term->term_id, '/'). - '|'.preg_quote(preg_replace('/[^a-z0-9\/.]/i', '-', $_post_term->slug), '/').')'; + '|'.preg_quote(preg_replace('/[^a-z0-9\/.]/ui', '-', $_post_term->slug), '/').')'; // Quick example: `http://www.example.com/tax/term/feed`; // with a wildcard this becomes: `http://www.example.com/tax/*/feed`. - $_term_feed_link_with_wildcard = preg_replace('/\/[^\/]+\/feed([\/?#]|$)/', '/*/feed'.'${1}', $_term_feed_link); + $_term_feed_link_with_wildcard = preg_replace('/\/[^\/]+\/feed([\/?#]|$)/u', '/*/feed'.'${1}', $_term_feed_link); // Quick example: `http://www.example.com/tax/*/feed`; // becomes: `\/http\/www\.example\.com\/tax\/.*?(?=[\/\-]?(?:123|slug)[\/\-]).*?\/feed` @@ -253,11 +253,11 @@ public function convertVariationsToHostCachePathRegexFrags(array $variations) if (is_string($_key) && strpos($_key, '::') !== false && strpos($_url, '*') !== false) { list($_feed_type, $_wildcard_regex) = explode('::', $_key, 2); // This regex replaces wildcards. $_cache_path = $this->plugin->buildCachePath($_url, '', '', $flags | $this::CACHE_PATH_ALLOW_WILDCARDS); - $_relative_cache_path = preg_replace('/^'.preg_quote($_host_cache_path, '/').'(?:\/|$)/i', '', $_cache_path); - $_relative_cache_path_regex = preg_replace('/\\\\\*/', $_wildcard_regex, preg_quote($_relative_cache_path, '/')); + $_relative_cache_path = preg_replace('/^'.preg_quote($_host_cache_path, '/').'(?:\/|$)/ui', '', $_cache_path); + $_relative_cache_path_regex = preg_replace('/\\\\\*/u', $_wildcard_regex, preg_quote($_relative_cache_path, '/')); } else { $_cache_path = $this->plugin->buildCachePath($_url, '', '', $flags); // Default flags. - $_relative_cache_path = preg_replace('/^'.preg_quote($_host_cache_path, '/').'(?:\/|$)/i', '', $_cache_path); + $_relative_cache_path = preg_replace('/^'.preg_quote($_host_cache_path, '/').'(?:\/|$)/ui', '', $_cache_path); $_relative_cache_path_regex = preg_quote($_relative_cache_path, '/'); } if ($_relative_cache_path_regex) { diff --git a/src/includes/classes/VsUpgrades.php b/src/includes/classes/VsUpgrades.php index d57700f7..2766acff 100644 --- a/src/includes/classes/VsUpgrades.php +++ b/src/includes/classes/VsUpgrades.php @@ -185,7 +185,7 @@ protected function fromZenCache() global $is_apache; // Remove htaccess rules added by ZenCache so that they can be re-added by Comet Cache if ($is_apache && $this->plugin->findHtaccessMarker('WmVuQ2FjaGU') && ($htaccess = $this->plugin->readHtaccessFile())) { - $regex = '/#\s*BEGIN\s+ZenCache\s+WmVuQ2FjaGU.*?#\s*END\s+ZenCache\s+WmVuQ2FjaGU\s*/is'; + $regex = '/#\s*BEGIN\s+ZenCache\s+WmVuQ2FjaGU.*?#\s*END\s+ZenCache\s+WmVuQ2FjaGU\s*/uis'; $htaccess['file_contents'] = preg_replace($regex, '', $htaccess['file_contents']); $this->plugin->writeHtaccessFile($htaccess, false); diff --git a/src/includes/traits/Plugin/HtaccessUtils.php b/src/includes/traits/Plugin/HtaccessUtils.php index cf35f0ab..685088ba 100644 --- a/src/includes/traits/Plugin/HtaccessUtils.php +++ b/src/includes/traits/Plugin/HtaccessUtils.php @@ -115,7 +115,7 @@ public function removeWpHtaccess() return false; // Failure; could not read file, create file, or invalid UTF8 encountered, file may be corrupt. } - $regex = '/#\s*BEGIN\s+'.preg_quote(NAME, '/').'\s+'.$this->htaccess_marker.'.*?#\s*END\s+'.preg_quote(NAME, '/').'\s+'.$this->htaccess_marker.'\s*/is'; + $regex = '/#\s*BEGIN\s+'.preg_quote(NAME, '/').'\s+'.$this->htaccess_marker.'.*?#\s*END\s+'.preg_quote(NAME, '/').'\s+'.$this->htaccess_marker.'\s*/uis'; $htaccess['file_contents'] = preg_replace($regex, '', $htaccess['file_contents']); if (!$this->writeHtaccessFile($htaccess, false)) { diff --git a/src/includes/traits/Plugin/InstallUtils.php b/src/includes/traits/Plugin/InstallUtils.php index f1fe4bf2..21346b50 100644 --- a/src/includes/traits/Plugin/InstallUtils.php +++ b/src/includes/traits/Plugin/InstallUtils.php @@ -155,7 +155,7 @@ public function addWpCacheToWpConfig() if (!($wp_config_file_contents = $this->removeWpCacheFromWpConfig())) { return ''; // Unable to remove previous value. } - if (!($wp_config_file_contents = preg_replace('/^\s*(\<\?php|\<\?)\s+/i', '${1}'."\n"."define('WP_CACHE', TRUE);"."\n", $wp_config_file_contents, 1))) { + if (!($wp_config_file_contents = preg_replace('/^\s*(\<\?php|\<\?)\s+/ui', '${1}'."\n"."define('WP_CACHE', TRUE);"."\n", $wp_config_file_contents, 1))) { return ''; // Failure; something went terribly wrong here. } if (strpos($wp_config_file_contents, "define('WP_CACHE', TRUE);") === false) { @@ -201,7 +201,7 @@ public function removeWpCacheFromWpConfig() if (preg_match('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:0|FALSE|NULL|([\'"])0?\\2)\s*\)\s*;/ui', $wp_config_file_contents_no_whitespace) && !is_writable($wp_config_file)) { return $wp_config_file_contents; // It's already disabled, and since we can't write to this file let's let this slide. } - if (!($wp_config_file_contents = preg_replace('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:\-?[0-9\.]+|TRUE|FALSE|NULL|([\'"])[^\'"]*\\2)\s*\)\s*;/i', '', $wp_config_file_contents))) { + if (!($wp_config_file_contents = preg_replace('/\bdefine\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:\-?[0-9\.]+|TRUE|FALSE|NULL|([\'"])[^\'"]*\\2)\s*\)\s*;/ui', '', $wp_config_file_contents))) { return ''; // Failure; something went terribly wrong here. } if (preg_match('/([\'"])WP_CACHE\\1/ui', $wp_config_file_contents)) { @@ -348,7 +348,7 @@ public function addAdvancedCache() str_ireplace( [ "'%%".GLOBAL_NS.'_'.$_option."%%'", - "'%%".GLOBAL_NS.'_'.preg_replace('/^cache_/i', '', $_option)."%%'", + "'%%".GLOBAL_NS.'_'.preg_replace('/^cache_/ui', '', $_option)."%%'", ], $_value, $advanced_cache_contents @@ -539,7 +539,7 @@ public function updateBlogPaths($enable_live_network_counts = null) foreach ($paths as $_key => &$_path) { if ($_path && $_path !== '/' && $host_base_token && $host_base_token !== '/') { // Note that each `path` in the DB looks like: `[/base]/path/` (i.e., it includes base). - $_path = '/'.ltrim(preg_replace('/^'.preg_quote($host_base_token, '/').'/', '', $_path), '/'); + $_path = '/'.ltrim(preg_replace('/^'.preg_quote($host_base_token, '/').'/u', '', $_path), '/'); } if (!$_path || $_path === '/') { unset($paths[$_key]); // Exclude main site. diff --git a/src/includes/traits/Shared/CachePathUtils.php b/src/includes/traits/Shared/CachePathUtils.php index 2cd61449..b8836411 100644 --- a/src/includes/traits/Shared/CachePathUtils.php +++ b/src/includes/traits/Shared/CachePathUtils.php @@ -110,7 +110,7 @@ public function buildCachePath($url, $with_user_token = '', $with_version_salt = // Put multisite sub-roots into a host directory of their own. // e.g., `example-com[[-base]-child1]` instead of `example-com`. if ($is_a_multisite_base_dir && $host_base_dir_tokens && $host_base_dir_tokens !== '/') { - $host_base_dir_suffix = preg_replace('/[^a-z0-9.]/i', '-', rtrim($host_base_dir_tokens, '/')); + $host_base_dir_suffix = preg_replace('/[^a-z0-9.]/ui', '-', rtrim($host_base_dir_tokens, '/')); $cache_path = rtrim($cache_path, '/').$host_base_dir_suffix.'/'; } } @@ -167,14 +167,14 @@ public function buildCachePath($url, $with_user_token = '', $with_version_salt = } } } - $cache_path = trim(preg_replace(['/\/+/', '/\.+/'], ['/', '.'], $cache_path), '/'); + $cache_path = trim(preg_replace(['/\/+/u', '/\.+/u'], ['/', '.'], $cache_path), '/'); if ($flags & $this::CACHE_PATH_ALLOW_WD_REGEX) { - $cache_path = preg_replace('/[^a-z0-9\/.*\^$]/i', '-', $cache_path); + $cache_path = preg_replace('/[^a-z0-9\/.*\^$]/ui', '-', $cache_path); } elseif ($flags & $this::CACHE_PATH_ALLOW_WILDCARDS) { - $cache_path = preg_replace('/[^a-z0-9\/.*]/i', '-', $cache_path); + $cache_path = preg_replace('/[^a-z0-9\/.*]/ui', '-', $cache_path); } else { - $cache_path = preg_replace('/[^a-z0-9\/.]/i', '-', $cache_path); + $cache_path = preg_replace('/[^a-z0-9\/.]/ui', '-', $cache_path); } if (!($flags & $this::CACHE_PATH_NO_EXT)) { $cache_path .= '.html'; @@ -249,7 +249,7 @@ public function buildHostCachePathRegex($url, $regex_suffix_frag = self::CACHE_P $host_cache_path = $this->buildCachePath($host_url, '', '', $flags); $cache_path = $this->buildCachePath($url, '', '', $flags); - $relative_cache_path = preg_replace('/^'.preg_quote($host_cache_path, '/').'(?:\/|$)/i', '', $cache_path); + $relative_cache_path = preg_replace('/^'.preg_quote($host_cache_path, '/').'(?:\/|$)/ui', '', $cache_path); $abs_relative_cache_path = isset($relative_cache_path[0]) ? '/'.$relative_cache_path : ''; $abs_relative_cache_path_regex = isset($abs_relative_cache_path[0]) ? preg_quote($abs_relative_cache_path, '/') : ''; @@ -321,7 +321,7 @@ public function buildHostCachePathRegexFragsFromWcUris($uris, $regex_suffix_frag foreach ($uri_patterns as $_key => &$_uri_pattern) { if (($_uri_pattern = trim($_uri_pattern, '^$'))) { $_cache_path = $this->buildCachePath($host_url.'/'.trim($_uri_pattern, '/'), '', '', $flags); - $_relative_cache_path = preg_replace('/^'.preg_quote($host_cache_path, '/').'(?:\/|$)/i', '', $_cache_path); + $_relative_cache_path = preg_replace('/^'.preg_quote($host_cache_path, '/').'(?:\/|$)/ui', '', $_cache_path); $_uri_pattern = $this->wdRegexToActualRegexFrag($_relative_cache_path); } if (!$_uri_pattern) { diff --git a/src/includes/traits/Shared/DomainMappingUtils.php b/src/includes/traits/Shared/DomainMappingUtils.php index e663737c..1b996ad5 100644 --- a/src/includes/traits/Shared/DomainMappingUtils.php +++ b/src/includes/traits/Shared/DomainMappingUtils.php @@ -86,7 +86,7 @@ public function domainMappingUrlFilter($url) $url_parts['host'] = $domain; // Filter the URL now. if (!empty($url_parts['path']) && $url_parts['path'] !== '/') { if (($host_base_dir_tokens = trim($this->hostBaseDirTokens(false, false, $url_parts['path']), '/'))) { - $url_parts['path'] = preg_replace('/^\/'.preg_quote($host_base_dir_tokens, '/').'(\/|$)/i', '${1}', $url_parts['path']); + $url_parts['path'] = preg_replace('/^\/'.preg_quote($host_base_dir_tokens, '/').'(\/|$)/ui', '${1}', $url_parts['path']); } } return $url = $this->unParseUrl($url_parts); @@ -159,7 +159,7 @@ public function domainMappingBlogId($url = '', $domain = '') if (!$url && !$domain && ($blog_details = $this->blogDetails())) { $domain = $blog_details->domain; } - $domain = strtolower(preg_replace('/^www\./i', '', $domain)); + $domain = strtolower(preg_replace('/^www\./ui', '', $domain)); if (!$domain || strpos($domain, '.') === false) { return 0; // Not possible. @@ -217,7 +217,7 @@ public function domainMappingBlogDomain($blog_id = 0, $fallback = false) if (!$enforcing_primary_domain) { if ($this->isDomainMapping() === $blog_id) { $domain = $this->hostToken(); - $domain = preg_replace('/^www\./i', '', $domain); + $domain = preg_replace('/^www\./ui', '', $domain); $domain = (string) $wpdb->get_var('SELECT `domain` FROM `'.esc_sql($wpdb->base_prefix.'domain_mapping').'` WHERE `blog_id` = \''.esc_sql($blog_id).'\' AND `domain` IN(\''.esc_sql('www.'.$domain).'\', \''.esc_sql($domain).'\') ORDER BY CHAR_LENGTH(`domain`) DESC LIMIT 1'); } elseif (($domains = $this->domainMappingBlogDomains($blog_id))) { $domain = $domains[0]; // Use the first of all possible domains. diff --git a/src/includes/traits/Shared/FsUtils.php b/src/includes/traits/Shared/FsUtils.php index 5a2048f0..d4a4f036 100644 --- a/src/includes/traits/Shared/FsUtils.php +++ b/src/includes/traits/Shared/FsUtils.php @@ -25,15 +25,15 @@ public function nDirSeps($dir_file, $allow_trailing_slash = false) } if (strpos($dir_file, '://' !== false)) { if (preg_match('/^(?P[a-zA-Z0-9]+)\:\/\//u', $dir_file, $stream_wrapper)) { - $dir_file = preg_replace('/^(?P[a-zA-Z0-9]+)\:\/\//', '', $dir_file); + $dir_file = preg_replace('/^(?P[a-zA-Z0-9]+)\:\/\//u', '', $dir_file); } } if (strpos($dir_file, ':' !== false)) { if (preg_match('/^(?P[a-zA-Z])\:[\/\\\\]/u', $dir_file)) { - $dir_file = preg_replace_callback('/^(?P[a-zA-Z])\:[\/\\\\]/', create_function('$m', 'return strtoupper($m[0]);'), $dir_file); + $dir_file = preg_replace_callback('/^(?P[a-zA-Z])\:[\/\\\\]/u', create_function('$m', 'return strtoupper($m[0]);'), $dir_file); } } - $dir_file = preg_replace('/\/+/', '/', str_replace([DIRECTORY_SEPARATOR, '\\', '/'], '/', $dir_file)); + $dir_file = preg_replace('/\/+/u', '/', str_replace([DIRECTORY_SEPARATOR, '\\', '/'], '/', $dir_file)); $dir_file = ($allow_trailing_slash) ? $dir_file : rtrim($dir_file, '/'); // Strip trailing slashes. if (!empty($stream_wrapper[0])) { diff --git a/src/includes/traits/Shared/PatternUtils.php b/src/includes/traits/Shared/PatternUtils.php index f92677e8..e1436cde 100644 --- a/src/includes/traits/Shared/PatternUtils.php +++ b/src/includes/traits/Shared/PatternUtils.php @@ -38,10 +38,10 @@ public function wdRegexToActualRegexFrag($string) { return preg_replace( [ - '/\\\\\^/', - '/\\\\\*\\\\\*/', - '/\\\\\*/', - '/\\\\\$/', + '/\\\\\^/u', + '/\\\\\*\\\\\*/u', + '/\\\\\*/u', + '/\\\\\$/u', ], [ '^', // Beginning of line. diff --git a/src/includes/traits/Shared/StringUtils.php b/src/includes/traits/Shared/StringUtils.php index 0fbf80c9..7a04ebb1 100644 --- a/src/includes/traits/Shared/StringUtils.php +++ b/src/includes/traits/Shared/StringUtils.php @@ -32,7 +32,7 @@ public function clip($value, $max_length = 80, $force_ellipsis = false) $max_length = max(4, $max_length); $string = strip_tags($string); - $string = preg_replace('/\s+/', ' ', strip_tags($string)); + $string = preg_replace('/\s+/u', ' ', strip_tags($string)); $string = trim($string); // Trim it up now. if (strlen($string) > $max_length) { @@ -71,7 +71,7 @@ public function midClip($value, $max_length = 80) $max_length = max(4, $max_length); $string = strip_tags($string); - $string = preg_replace('/\s+/', ' ', strip_tags($string)); + $string = preg_replace('/\s+/u', ' ', strip_tags($string)); $string = trim($string); // Trim it up now. if (strlen($string) <= $max_length) { diff --git a/src/includes/traits/Shared/TokenUtils.php b/src/includes/traits/Shared/TokenUtils.php index 3dc452c8..cfae4c82 100644 --- a/src/includes/traits/Shared/TokenUtils.php +++ b/src/includes/traits/Shared/TokenUtils.php @@ -55,7 +55,7 @@ public function hostToken($dashify = false, $consider_domain_mapping = false, $c if ($token) { // Have token? $token = strtolower($token); if ($dashify) { // Dashify it? - $token = preg_replace('/[^a-z0-9]/i', '-', $token); + $token = preg_replace('/[^a-z0-9]/ui', '-', $token); $token = trim($token, '-'); } } @@ -97,7 +97,7 @@ public function hostTokenForBlog($dashify = false, $consider_domain_mapping = fa if ($token) { // Have token? $token = strtolower($token); if ($dashify) { // Dashify it? - $token = preg_replace('/[^a-z0-9]/i', '-', $token); + $token = preg_replace('/[^a-z0-9]/ui', '-', $token); $token = trim($token, '-'); } } @@ -140,7 +140,7 @@ public function hostBaseToken($dashify = false, $consider_domain_mapping = false $token = isset($token[0]) ? '/'.$token.'/' : '/'; if ($token !== '/' && $dashify) { - $token = preg_replace('/[^a-z0-9\/]/i', '-', $token); + $token = preg_replace('/[^a-z0-9\/]/ui', '-', $token); $token = trim($token, '-'); } return $token; @@ -182,7 +182,7 @@ public function hostDirToken($dashify = false, $consider_domain_mapping = false, return $token; // Not applicable. } if ($path && $path !== '/' && ($host_base_token = trim($this->hostBaseToken(), '/'))) { - $path_minus_base = preg_replace('/^\/'.preg_quote($host_base_token, '/').'(\/|$)/i', '${1}', $path); + $path_minus_base = preg_replace('/^\/'.preg_quote($host_base_token, '/').'(\/|$)/ui', '${1}', $path); } else { $path_minus_base = $path; // Default value. } @@ -197,7 +197,7 @@ public function hostDirToken($dashify = false, $consider_domain_mapping = false, } } if ($token !== '/' && $dashify) { - $token = preg_replace('/[^a-z0-9\/]/i', '-', $token); + $token = preg_replace('/[^a-z0-9\/]/ui', '-', $token); $token = trim($token, '-'); } return $token; @@ -233,7 +233,7 @@ public function hostDirTokenForBlog($dashify = false, $consider_domain_mapping = if (($blog_details = $this->blogDetails($blog_id))) { $path = $blog_details->path; // e.g., `[/base]/path/` (includes base). if ($path && $path !== '/' && ($host_base_token = trim($this->hostBaseToken(), '/'))) { - $path_minus_base = preg_replace('/^\/'.preg_quote($host_base_token, '/').'(\/|$)/i', '${1}', $path); + $path_minus_base = preg_replace('/^\/'.preg_quote($host_base_token, '/').'(\/|$)/ui', '${1}', $path); } else { $path_minus_base = $path; // Default value. } @@ -249,7 +249,7 @@ public function hostDirTokenForBlog($dashify = false, $consider_domain_mapping = } } if ($token !== '/' && $dashify) { - $token = preg_replace('/[^a-z0-9\/]/i', '-', $token); + $token = preg_replace('/[^a-z0-9\/]/ui', '-', $token); $token = trim($token, '-'); } return $token; @@ -277,7 +277,7 @@ public function hostBaseDirTokens($dashify = false, $consider_domain_mapping = f $tokens = $this->hostBaseToken($dashify, $consider_domain_mapping); $tokens .= $this->hostDirToken($dashify, $consider_domain_mapping, $path); - return $tokens = preg_replace('/\/+/', '/', $tokens); + return $tokens = preg_replace('/\/+/u', '/', $tokens); } /** @@ -299,7 +299,7 @@ public function hostBaseDirTokensForBlog($dashify = false, $consider_domain_mapp $tokens = $this->hostBaseToken($dashify, $consider_domain_mapping); $tokens .= $this->hostDirTokenForBlog($dashify, $consider_domain_mapping, $blog_id); - return $tokens = preg_replace('/\/+/', '/', $tokens); + return $tokens = preg_replace('/\/+/u', '/', $tokens); } /*[pro strip-from="lite"]*/ @@ -336,7 +336,7 @@ public function userToken() } elseif (!empty($_COOKIE['wp-postpass_'.COOKIEHASH])) { return $token = md5(stripslashes((string) $_COOKIE['wp-postpass_'.COOKIEHASH])); } elseif (defined('SID') && SID) { - return $token = preg_replace('/[^a-z0-9]/i', '', (string) SID); + return $token = preg_replace('/[^a-z0-9]/ui', '', (string) SID); } return $token = ''; } From ea4d0b33d4cb83d51f81cdb7f3f5a0f56cee015a Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Thu, 3 Mar 2016 21:05:03 -0500 Subject: [PATCH 03/11] Multibyte String Enhancements: Update `strpos()` and `stripos()` See websharks/comet-cache#703 --- plugin.php | 2 +- src/includes/classes/AdvCacheBackCompat.php | 2 +- src/includes/classes/AutoCache.php | 2 +- src/includes/classes/CdnFilters.php | 6 +++--- src/includes/classes/FeedUtils.php | 4 ++-- src/includes/classes/MenuPageOptions.php | 4 ++-- src/includes/classes/VsUpgrades.php | 12 ++++++------ src/includes/traits/Ac/ObUtils.php | 4 ++-- src/includes/traits/Ac/PostloadUtils.php | 2 +- src/includes/traits/Plugin/AutoCacheUtils.php | 4 ++-- src/includes/traits/Plugin/HtaccessUtils.php | 4 ++-- src/includes/traits/Plugin/InstallUtils.php | 4 ++-- src/includes/traits/Plugin/MenuPageUtils.php | 6 +++--- src/includes/traits/Plugin/OptionUtils.php | 2 +- src/includes/traits/Plugin/WcpPostUtils.php | 2 +- src/includes/traits/Plugin/WcpTermUtils.php | 2 +- src/includes/traits/Plugin/WcpUrlUtils.php | 2 +- src/includes/traits/Shared/CacheDirUtils.php | 8 ++++---- src/includes/traits/Shared/CachePathUtils.php | 2 +- src/includes/traits/Shared/ConditionalUtils.php | 12 ++++++------ src/includes/traits/Shared/DomainMappingUtils.php | 2 +- src/includes/traits/Shared/FsUtils.php | 10 +++++----- src/includes/traits/Shared/HookUtils.php | 8 ++++---- src/includes/traits/Shared/HttpUtils.php | 2 +- src/includes/traits/Shared/ReplaceUtils.php | 4 ++-- src/includes/traits/Shared/ServerUtils.php | 10 +++++----- src/includes/traits/Shared/UrlUtils.php | 4 ++-- 27 files changed, 63 insertions(+), 63 deletions(-) diff --git a/plugin.php b/plugin.php index 792a5a87..ff9a84b1 100644 --- a/plugin.php +++ b/plugin.php @@ -9,7 +9,7 @@ update_site_option('comet_cache_mbstring_deprecated_warning_bypass', time()); } - ${__FILE__}['apc_enabled'] = (extension_loaded('apc') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) && filter_var(ini_get('apc.cache_by_default'), FILTER_VALIDATE_BOOLEAN) && stripos((string) ini_get('apc.filters'), 'comet-cache') === false) ? true : false; + ${__FILE__}['apc_enabled'] = (extension_loaded('apc') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) && filter_var(ini_get('apc.cache_by_default'), FILTER_VALIDATE_BOOLEAN) && mb_stripos((string) ini_get('apc.filters'), 'comet-cache') === false) ? true : false; if ((!version_compare(PHP_VERSION, '5.4', '>=') || ${__FILE__}['apc_enabled'])) { // If PHP <= 5.4 or APC is enabled diff --git a/src/includes/classes/AdvCacheBackCompat.php b/src/includes/classes/AdvCacheBackCompat.php index 338e5012..461aaa53 100644 --- a/src/includes/classes/AdvCacheBackCompat.php +++ b/src/includes/classes/AdvCacheBackCompat.php @@ -50,7 +50,7 @@ public static function zenCacheConstants() return; // Nothing to do; i.e. no user-defined constants. } foreach ($constants['user'] as $_constant => $_value) { - if (stripos($_constant, 'ZENCACHE_') !== 0) { + if (mb_stripos($_constant, 'ZENCACHE_') !== 0) { continue; // Nothing to do here. } if (!($_constant_sub_name = substr($_constant, 9))) { diff --git a/src/includes/classes/AutoCache.php b/src/includes/classes/AutoCache.php index 80328fef..6ce3e47c 100644 --- a/src/includes/classes/AutoCache.php +++ b/src/includes/classes/AutoCache.php @@ -140,7 +140,7 @@ protected function autoCacheUrl($url) if (!($url = trim((string) $url))) { return; // Nothing to do. } - if (!$this->plugin->options['get_requests'] && strpos($url, '?') !== false) { + if (!$this->plugin->options['get_requests'] && mb_strpos($url, '?') !== false) { return; // We're NOT caching URLs with a query string. } $cache_path = $this->plugin->buildCachePath($url); diff --git a/src/includes/classes/CdnFilters.php b/src/includes/classes/CdnFilters.php index b30a2e12..f0b460b1 100644 --- a/src/includes/classes/CdnFilters.php +++ b/src/includes/classes/CdnFilters.php @@ -337,7 +337,7 @@ public function contentFilter($string) if (!($string = (string) $string)) { return $string; // Nothing to do. } - if (strpos($string, '<') === false) { + if (mb_strpos($string, '<') === false) { return $string; // Nothing to do. } @@ -471,7 +471,7 @@ protected function localFile($url_uri_qsl) if (substr($parsed['path'], -1) === '/') { return; // Directory, not a file. } - if (strpos($parsed['path'], '..') !== false || strpos($parsed['path'], './') !== false) { + if (mb_strpos($parsed['path'], '..') !== false || mb_strpos($parsed['path'], './') !== false) { return; // A relative path that is not absolute. } $scheme = null; // Default scheme handling. @@ -533,7 +533,7 @@ protected function parseCdnHosts() if (!($_line = trim($_line))) { continue; // Invalid line. } - if (strpos($_line, '=') !== false) { + if (mb_strpos($_line, '=') !== false) { $_parts = explode('=', $_line, 2); } else { $_parts = [$this->local_host, $_line]; diff --git a/src/includes/classes/FeedUtils.php b/src/includes/classes/FeedUtils.php index 47cc4cb7..533440db 100644 --- a/src/includes/classes/FeedUtils.php +++ b/src/includes/classes/FeedUtils.php @@ -174,7 +174,7 @@ public function postTermFeedLinkVariations(\WP_Post $post, $include_regex_wildca $_term_feed_link = get_term_feed_link($_post_term->term_id, $_post_term->taxonomy, $_feed_type); $variations[] = $_term_feed_link; // Add this variation; always. - if ($include_regex_wildcard_keys && $_term_feed_link && strpos($_term_feed_link, '?') === false) { + if ($include_regex_wildcard_keys && $_term_feed_link && mb_strpos($_term_feed_link, '?') === false) { // Quick example: `(?:123|slug)`; to consider both of these variations. $_term_id_or_slug = '(?:'.preg_quote($_post_term->term_id, '/'). '|'.preg_quote(preg_replace('/[^a-z0-9\/.]/ui', '-', $_post_term->slug), '/').')'; @@ -250,7 +250,7 @@ public function convertVariationsToHostCachePathRegexFrags(array $variations) $_host_url = rtrim('http://'.$_url_parts['host'].$_host_base_dir_tokens, '/'); $_host_cache_path = $this->plugin->buildCachePath($_host_url, '', '', $flags); - if (is_string($_key) && strpos($_key, '::') !== false && strpos($_url, '*') !== false) { + if (is_string($_key) && mb_strpos($_key, '::') !== false && mb_strpos($_url, '*') !== false) { list($_feed_type, $_wildcard_regex) = explode('::', $_key, 2); // This regex replaces wildcards. $_cache_path = $this->plugin->buildCachePath($_url, '', '', $flags | $this::CACHE_PATH_ALLOW_WILDCARDS); $_relative_cache_path = preg_replace('/^'.preg_quote($_host_cache_path, '/').'(?:\/|$)/ui', '', $_cache_path); diff --git a/src/includes/classes/MenuPageOptions.php b/src/includes/classes/MenuPageOptions.php index 3e8ca884..44ece530 100644 --- a/src/includes/classes/MenuPageOptions.php +++ b/src/includes/classes/MenuPageOptions.php @@ -538,9 +538,9 @@ public function __construct() echo '

'.sprintf(__('If you have high traffic at certain times of the day, %1$s can be told to check the current load average via sys_getloadavg(). If your server\'s load average has been high in the last 15 minutes or so, cache expiration is disabled automatically to help reduce stress on the server; i.e., to avoid generating a new version of the cache while the server is very busy.', SLUG_TD), esc_html(NAME)).'

'."\n"; echo '

'.sprintf(__('To enable this functionality you should first determine what a high load average is for your server. If you log into your machine via SSH you can run the top command to get a feel for what a high load average looks like. Once you know the number, you can enter it in the field below; e.g., 1.05 might be a high load average for a server with one CPU. See also: Understanding Load Average', SLUG_TD), esc_html(NAME)).'

'."\n"; echo '

'."\n"; - if ($_sys_getloadavg_unavailable && stripos(PHP_OS, 'win') === 0) { // See: + if ($_sys_getloadavg_unavailable && mb_stripos(PHP_OS, 'win') === 0) { // See: echo '

'.__('Note: It appears that your server is running Windows. The sys_getloadavg() function has not been implemented in PHP for Windows servers yet.', SLUG_TD).'

'."\n"; - } elseif ($_sys_getloadavg_unavailable && stripos(PHP_OS, 'win') !== 0) { + } elseif ($_sys_getloadavg_unavailable && mb_stripos(PHP_OS, 'win') !== 0) { echo '

'.__('Note: sys_getloadavg() has been disabled by your web hosting company or is not available on your server.', SLUG_TD).'

'."\n"; } echo ' '."\n"; diff --git a/src/includes/classes/VsUpgrades.php b/src/includes/classes/VsUpgrades.php index 2766acff..6ea9f341 100644 --- a/src/includes/classes/VsUpgrades.php +++ b/src/includes/classes/VsUpgrades.php @@ -90,22 +90,22 @@ protected function fromLte151107() { if (version_compare($this->prev_version, '151107', '<=')) { if (is_array($existing_options = get_site_option(GLOBAL_NS.'_options'))) { - if (!empty($existing_options['cache_clear_xml_sitemap_patterns']) && strpos($existing_options['cache_clear_xml_sitemap_patterns'], '**') === false) { + if (!empty($existing_options['cache_clear_xml_sitemap_patterns']) && mb_strpos($existing_options['cache_clear_xml_sitemap_patterns'], '**') === false) { $this->plugin->options['cache_clear_xml_sitemap_patterns'] = str_replace('*', '**', $existing_options['cache_clear_xml_sitemap_patterns']); } - if (!empty($existing_options['exclude_uris']) && strpos($existing_options['exclude_uris'], '**') === false) { + if (!empty($existing_options['exclude_uris']) && mb_strpos($existing_options['exclude_uris'], '**') === false) { $this->plugin->options['exclude_uris'] = str_replace('*', '**', $existing_options['exclude_uris']); } - if (!empty($existing_options['exclude_refs']) && strpos($existing_options['exclude_refs'], '**') === false) { + if (!empty($existing_options['exclude_refs']) && mb_strpos($existing_options['exclude_refs'], '**') === false) { $this->plugin->options['exclude_refs'] = str_replace('*', '**', $existing_options['exclude_refs']); } - if (!empty($existing_options['exclude_agents']) && strpos($existing_options['exclude_agents'], '**') === false) { + if (!empty($existing_options['exclude_agents']) && mb_strpos($existing_options['exclude_agents'], '**') === false) { $this->plugin->options['exclude_agents'] = str_replace('*', '**', $existing_options['exclude_agents']); } - if (!empty($existing_options['htmlc_css_exclusions']) && strpos($existing_options['htmlc_css_exclusions'], '**') === false) { + if (!empty($existing_options['htmlc_css_exclusions']) && mb_strpos($existing_options['htmlc_css_exclusions'], '**') === false) { $this->plugin->options['htmlc_css_exclusions'] = str_replace('*', '**', $existing_options['htmlc_css_exclusions']); } - if (!empty($existing_options['htmlc_js_exclusions']) && strpos($existing_options['htmlc_js_exclusions'], '**') === false) { + if (!empty($existing_options['htmlc_js_exclusions']) && mb_strpos($existing_options['htmlc_js_exclusions'], '**') === false) { $this->plugin->options['htmlc_js_exclusions'] = str_replace('*', '**', $existing_options['htmlc_js_exclusions']); } if ($existing_options['cdn_blacklisted_extensions'] === 'eot,ttf,otf,woff') { diff --git a/src/includes/traits/Ac/ObUtils.php b/src/includes/traits/Ac/ObUtils.php index e9d974da..f0f5538c 100644 --- a/src/includes/traits/Ac/ObUtils.php +++ b/src/includes/traits/Ac/ObUtils.php @@ -208,7 +208,7 @@ public function maybeStartOutputBuffering() $headers_list = $this->headersList(); foreach (unserialize($headers) as $_header) { - if (!in_array($_header, $headers_list, true) && stripos($_header, 'Last-Modified:') !== 0) { + if (!in_array($_header, $headers_list, true) && mb_stripos($_header, 'Last-Modified:') !== 0) { header($_header); // Only cacheable/safe headers are stored in the cache. } } @@ -289,7 +289,7 @@ public function outputBufferCallbackHandler($buffer, $phase) if ($this->is_404 && !COMET_CACHE_CACHE_404_REQUESTS) { return (boolean) $this->maybeSetDebugInfo($this::NC_DEBUG_404_REQUEST); } - if (stripos($cache, '') !== false) { + if (mb_stripos($cache, '') !== false) { return (boolean) $this->maybeSetDebugInfo($this::NC_DEBUG_WP_ERROR_PAGE); } if (!$this->hasACacheableContentType()) { diff --git a/src/includes/traits/Ac/PostloadUtils.php b/src/includes/traits/Ac/PostloadUtils.php index df3174c3..6de2e0c4 100644 --- a/src/includes/traits/Ac/PostloadUtils.php +++ b/src/includes/traits/Ac/PostloadUtils.php @@ -188,7 +188,7 @@ public function maybeStartObWhenLoggedInPostload() $headers_list = $this->headersList(); foreach (unserialize($headers) as $_header) { - if (!in_array($_header, $headers_list, true) && stripos($_header, 'Last-Modified:') !== 0) { + if (!in_array($_header, $headers_list, true) && mb_stripos($_header, 'Last-Modified:') !== 0) { header($_header); // Only cacheable/safe headers are stored in the cache. } } diff --git a/src/includes/traits/Plugin/AutoCacheUtils.php b/src/includes/traits/Plugin/AutoCacheUtils.php index 6e446441..9edcd86e 100644 --- a/src/includes/traits/Plugin/AutoCacheUtils.php +++ b/src/includes/traits/Plugin/AutoCacheUtils.php @@ -141,12 +141,12 @@ public function autoCacheCheckXmlSitemap($sitemap, $is_nested_sitemap = false, $ if (is_wp_error($head = wp_remote_head($sitemap, ['redirection' => 5]))) { $failure = 'WP_Http says: '.$head->get_error_message().'.'; - if (stripos($head->get_error_message(), 'timed out') !== false || stripos($head->get_error_message(), 'timeout') !== false) { // $head->get_error_code() only returns generic `http_request_failed` + if (mb_stripos($head->get_error_message(), 'timed out') !== false || mb_stripos($head->get_error_message(), 'timeout') !== false) { // $head->get_error_code() only returns generic `http_request_failed` $failure .= '
'.__('Note: Most timeout errors are resolved by refreshing the page and trying again. If timeout errors persist, please see this article.', SLUG_TD).''; } } elseif (empty($head['response']['code']) || (int) $head['response']['code'] >= 400) { $failure = sprintf(__('HEAD response code (%1$s) indicates an error.', SLUG_TD), esc_html((int) @$head['response']['code'])); - } elseif (empty($head['headers']['content-type']) || stripos($head['headers']['content-type'], 'xml') === false) { + } elseif (empty($head['headers']['content-type']) || mb_stripos($head['headers']['content-type'], 'xml') === false) { $failure = sprintf(__('Content-Type (%1$s) indicates an error.', SLUG_TD), esc_html((string) @$head['headers']['content-type'])); } if ($failure) { // Failure encountered above? diff --git a/src/includes/traits/Plugin/HtaccessUtils.php b/src/includes/traits/Plugin/HtaccessUtils.php index 685088ba..cff69bec 100644 --- a/src/includes/traits/Plugin/HtaccessUtils.php +++ b/src/includes/traits/Plugin/HtaccessUtils.php @@ -187,7 +187,7 @@ public function findHtaccessMarker($htaccess_marker = '') if (empty($htaccess_marker)) { $htaccess_marker = $this->htaccess_marker; } - if (stripos($htaccess_file_contents, $htaccess_marker) === false) { + if (mb_stripos($htaccess_file_contents, $htaccess_marker) === false) { return false; // Htaccess marker is missing } @@ -253,7 +253,7 @@ public function writeHtaccessFile(array $htaccess, $require_marker = true, $htac } $htaccess_marker = $htaccess_marker ?: $this->htaccess_marker; - $_have_marker = stripos($htaccess['file_contents'], $htaccess_marker); + $_have_marker = mb_stripos($htaccess['file_contents'], $htaccess_marker); // Note: rewind() necessary here because we fread() above. if (($require_marker && $_have_marker === false) || !rewind($htaccess['fp']) || !ftruncate($htaccess['fp'], 0) || !fwrite($htaccess['fp'], $htaccess['file_contents'])) { diff --git a/src/includes/traits/Plugin/InstallUtils.php b/src/includes/traits/Plugin/InstallUtils.php index 21346b50..3297bd7f 100644 --- a/src/includes/traits/Plugin/InstallUtils.php +++ b/src/includes/traits/Plugin/InstallUtils.php @@ -158,7 +158,7 @@ public function addWpCacheToWpConfig() if (!($wp_config_file_contents = preg_replace('/^\s*(\<\?php|\<\?)\s+/ui', '${1}'."\n"."define('WP_CACHE', TRUE);"."\n", $wp_config_file_contents, 1))) { return ''; // Failure; something went terribly wrong here. } - if (strpos($wp_config_file_contents, "define('WP_CACHE', TRUE);") === false) { + if (mb_strpos($wp_config_file_contents, "define('WP_CACHE', TRUE);") === false) { return ''; // Failure; unable to add; unexpected PHP code. } if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) { @@ -356,7 +356,7 @@ public function addAdvancedCache() } unset($_option, $_value, $_values, $_response); // Housekeeping. - if (strpos(PLUGIN_FILE, WP_CONTENT_DIR) === 0) { + if (mb_strpos(PLUGIN_FILE, WP_CONTENT_DIR) === 0) { $plugin_file = "WP_CONTENT_DIR.'".$this->escSq(str_replace(WP_CONTENT_DIR, '', PLUGIN_FILE))."'"; } else { $plugin_file = "'".$this->escSq(PLUGIN_FILE)."'"; // Full absolute path. diff --git a/src/includes/traits/Plugin/MenuPageUtils.php b/src/includes/traits/Plugin/MenuPageUtils.php index ea0277dd..77203be0 100644 --- a/src/includes/traits/Plugin/MenuPageUtils.php +++ b/src/includes/traits/Plugin/MenuPageUtils.php @@ -14,7 +14,7 @@ trait MenuPageUtils */ public function enqueueAdminStyles() { - if (empty($_GET['page']) || strpos($_GET['page'], GLOBAL_NS) !== 0) { + if (empty($_GET['page']) || mb_strpos($_GET['page'], GLOBAL_NS) !== 0) { return; // NOT a plugin page in the administrative area. } $deps = []; // Plugin dependencies. @@ -31,7 +31,7 @@ public function enqueueAdminStyles() */ public function enqueueAdminScripts() { - if (empty($_GET['page']) || strpos($_GET['page'], GLOBAL_NS) !== 0) { + if (empty($_GET['page']) || mb_strpos($_GET['page'], GLOBAL_NS) !== 0) { return; // NOT a plugin page in the administrative area. } $deps = ['jquery', 'chartjs']; // Plugin dependencies. @@ -168,7 +168,7 @@ public function colorSvgMenuIcon($svg) $current_pagenow = !empty($GLOBALS['pagenow']) ? $GLOBALS['pagenow'] : ''; $current_page = !empty($_REQUEST['page']) ? $_REQUEST['page'] : ''; - if (strpos($current_pagenow, GLOBAL_NS) === 0 || strpos($current_page, GLOBAL_NS) === 0) { + if (mb_strpos($current_pagenow, GLOBAL_NS) === 0 || mb_strpos($current_page, GLOBAL_NS) === 0) { $use_icon_fill_color = $icon_colors['current']; } return str_replace(' fill="currentColor"', ' fill="'.esc_attr($use_icon_fill_color).'"', $svg); diff --git a/src/includes/traits/Plugin/OptionUtils.php b/src/includes/traits/Plugin/OptionUtils.php index 02273a77..98e90fc9 100644 --- a/src/includes/traits/Plugin/OptionUtils.php +++ b/src/includes/traits/Plugin/OptionUtils.php @@ -33,7 +33,7 @@ public function getOptions() unset($_key, $_value); // Housekeeping. $this->options['base_dir'] = trim($this->options['base_dir'], '\\/'." \t\n\r\0\x0B"); - if (!$this->options['base_dir'] || strpos(basename($this->options['base_dir']), 'wp-') === 0) { + if (!$this->options['base_dir'] || mb_strpos(basename($this->options['base_dir']), 'wp-') === 0) { $this->options['base_dir'] = $this->default_options['base_dir']; } return $this->options; // Plugin options. diff --git a/src/includes/traits/Plugin/WcpPostUtils.php b/src/includes/traits/Plugin/WcpPostUtils.php index 0f5075a8..179c6fdb 100644 --- a/src/includes/traits/Plugin/WcpPostUtils.php +++ b/src/includes/traits/Plugin/WcpPostUtils.php @@ -71,7 +71,7 @@ public function autoClearPostCache($post_id, $force = false) } if ($post_status === 'draft' && isset($GLOBALS['pagenow'], $_POST['publish']) && is_admin() && $GLOBALS['pagenow'] === 'post.php' && current_user_can('publish_posts') - && strpos(wp_get_referer(), '/post-new.php') !== false + && mb_strpos(wp_get_referer(), '/post-new.php') !== false ) { $post_status = 'publish'; // A new post being published now. } diff --git a/src/includes/traits/Plugin/WcpTermUtils.php b/src/includes/traits/Plugin/WcpTermUtils.php index 8b6e1a82..cf3f08b9 100644 --- a/src/includes/traits/Plugin/WcpTermUtils.php +++ b/src/includes/traits/Plugin/WcpTermUtils.php @@ -54,7 +54,7 @@ public function autoClearPostTermsCache($post_id, $force = false) if ($post_status === 'draft' && isset($GLOBALS['pagenow'], $_POST['publish']) && is_admin() && $GLOBALS['pagenow'] === 'post.php' && current_user_can('publish_posts') - && strpos(wp_get_referer(), '/post-new.php') !== false + && mb_strpos(wp_get_referer(), '/post-new.php') !== false ) { $post_status = 'publish'; // A new post being published now. } diff --git a/src/includes/traits/Plugin/WcpUrlUtils.php b/src/includes/traits/Plugin/WcpUrlUtils.php index 8ddef00d..563566d6 100644 --- a/src/includes/traits/Plugin/WcpUrlUtils.php +++ b/src/includes/traits/Plugin/WcpUrlUtils.php @@ -37,7 +37,7 @@ public function autoClearUrlsCache() return $counter; // Nothing to do. } foreach (preg_split('/['."\r\n".']+/', $this->options['cache_clear_urls'], -1, PREG_SPLIT_NO_EMPTY) as $_url) { - if (stripos($_url, 'http') === 0) { + if (mb_stripos($_url, 'http') === 0) { $_regex = $this->buildCachePathRegexFromWcUrl($_url); $counter += $this->deleteFilesFromCacheDir($_regex); } diff --git a/src/includes/traits/Shared/CacheDirUtils.php b/src/includes/traits/Shared/CacheDirUtils.php index 2a71abf3..d0a98c07 100644 --- a/src/includes/traits/Shared/CacheDirUtils.php +++ b/src/includes/traits/Shared/CacheDirUtils.php @@ -145,7 +145,7 @@ public function deleteFilesFromCacheDir($regex, $check_max_age = false) $cache_dir_tmp_regex = $this->strIreplaceOnce(preg_quote($cache_dir.'/', '/'), '', $cache_dir_tmp_regex); $cache_dir_tmp_regex = ltrim($cache_dir_tmp_regex, '^\\/'); - if (strpos($cache_dir_tmp_regex, '(?:\/') === 0 || strpos($cache_dir_tmp_regex, '(\/') === 0) { + if (mb_strpos($cache_dir_tmp_regex, '(?:\/') === 0 || mb_strpos($cache_dir_tmp_regex, '(\/') === 0) { $cache_dir_tmp_regex = '/^'.preg_quote($cache_dir_tmp, '/').$cache_dir_tmp_regex; } else { $cache_dir_tmp_regex = '/^'.preg_quote($cache_dir_tmp.'/', '/').$cache_dir_tmp_regex; @@ -161,7 +161,7 @@ public function deleteFilesFromCacheDir($regex, $check_max_age = false) $_sub_path_name = $_resource->getSubpathname(); $_path_name = $_resource->getPathname(); - if ($_resource_type !== 'dir' && strpos($_sub_path_name, '/') === false) { + if ($_resource_type !== 'dir' && mb_strpos($_sub_path_name, '/') === false) { continue; // Don't delete links/files in the immediate directory; e.g. `[SHORT_NAME]-advanced-cache` or `.htaccess`, etc. // Actual `http|https/...` cache links/files are nested. Links/files in the immediate directory are for other purposes. } @@ -311,7 +311,7 @@ public function deleteFilesFromHostCacheDir( $_host_cache_dir_tmp_regex = $this->strIreplaceOnce(preg_quote($_host_cache_dir.'/', '/'), '', $_host_cache_dir_tmp_regex); $_host_cache_dir_tmp_regex = ltrim($_host_cache_dir_tmp_regex, '^\\/'); - if (strpos($_host_cache_dir_tmp_regex, '(?:\/') === 0 || strpos($_host_cache_dir_tmp_regex, '(\/') === 0) { + if (mb_strpos($_host_cache_dir_tmp_regex, '(?:\/') === 0 || mb_strpos($_host_cache_dir_tmp_regex, '(\/') === 0) { $_host_cache_dir_tmp_regex = '/^'.preg_quote($_host_cache_dir_tmp, '/').$_host_cache_dir_tmp_regex; } else { $_host_cache_dir_tmp_regex = '/^'.preg_quote($_host_cache_dir_tmp.'/', '/').$_host_cache_dir_tmp_regex; @@ -327,7 +327,7 @@ public function deleteFilesFromHostCacheDir( $_sub_path_name = $_resource->getSubpathname(); $_path_name = $_resource->getPathname(); - if ($_host_cache_dir === $cache_dir && $_resource_type !== 'dir' && strpos($_sub_path_name, '/') === false) { + if ($_host_cache_dir === $cache_dir && $_resource_type !== 'dir' && mb_strpos($_sub_path_name, '/') === false) { continue; // Don't delete links/files in the immediate directory; e.g. `[SHORT_NAME]-advanced-cache` or `.htaccess`, etc. // Actual `http|https/...` cache links/files are nested. Links/files in the immediate directory are for other purposes. } diff --git a/src/includes/traits/Shared/CachePathUtils.php b/src/includes/traits/Shared/CachePathUtils.php index b8836411..da0cfe8e 100644 --- a/src/includes/traits/Shared/CachePathUtils.php +++ b/src/includes/traits/Shared/CachePathUtils.php @@ -94,7 +94,7 @@ public function buildCachePath($url, $with_user_token = '', $with_version_salt = $host_base_dir_tokens = $this->hostBaseDirTokens(false, $is_url_domain_mapped, !empty($url_parts['path']) ? $url_parts['path'] : '/'); $is_a_multisite_base_dir = $is_multisite && $host_base_dir_tokens && $host_base_dir_tokens !== '/' // Check? - && stripos(!empty($url_parts['path']) ? rtrim($url_parts['path'], '/').'/' : '/', $host_base_dir_tokens) === 0; + && mb_stripos(!empty($url_parts['path']) ? rtrim($url_parts['path'], '/').'/' : '/', $host_base_dir_tokens) === 0; $is_a_multisite_base_dir_root = $is_multisite && $is_a_multisite_base_dir // Save time by using the previous check here. && strcasecmp(trim($host_base_dir_tokens, '/'), trim(!empty($url_parts['path']) ? $url_parts['path'] : '/', '/')) === 0; diff --git a/src/includes/traits/Shared/ConditionalUtils.php b/src/includes/traits/Shared/ConditionalUtils.php index 5c317be2..95e15cc6 100644 --- a/src/includes/traits/Shared/ConditionalUtils.php +++ b/src/includes/traits/Shared/ConditionalUtils.php @@ -213,7 +213,7 @@ public function isAutoCacheEngine() return $is; // Already cached this. } if (!empty($_SERVER['HTTP_USER_AGENT']) && is_string($_SERVER['HTTP_USER_AGENT'])) { - if (stripos($_SERVER['HTTP_USER_AGENT'], GLOBAL_NS) !== false) { + if (mb_stripos($_SERVER['HTTP_USER_AGENT'], GLOBAL_NS) !== false) { return $is = true; } } @@ -263,10 +263,10 @@ public function isHtmlXmlDoc($doc) if (!is_null($is = &$this->staticKey('isHtmlXmlDoc', $doc_hash))) { return $is; // Already cached this. } - if (stripos($doc, '') !== false) { + if (mb_stripos($doc, '') !== false) { return $is = true; } - if (stripos($doc, 'headersList() as $_key => $_header) { - if (stripos($_header, 'Content-Type:') === 0) { + if (mb_stripos($_header, 'Content-Type:') === 0) { $content_type = $_header; // Last one. } } unset($_key, $_header); // Housekeeping. - if (isset($content_type[0]) && stripos($content_type, 'html') === false - && stripos($content_type, 'xml') === false && stripos($content_type, GLOBAL_NS) === false + if (isset($content_type[0]) && mb_stripos($content_type, 'html') === false + && mb_stripos($content_type, 'xml') === false && mb_stripos($content_type, GLOBAL_NS) === false ) { return $is = false; // Do NOT cache data sent by scripts serving other MIME types. } diff --git a/src/includes/traits/Shared/DomainMappingUtils.php b/src/includes/traits/Shared/DomainMappingUtils.php index 1b996ad5..32c52aa1 100644 --- a/src/includes/traits/Shared/DomainMappingUtils.php +++ b/src/includes/traits/Shared/DomainMappingUtils.php @@ -161,7 +161,7 @@ public function domainMappingBlogId($url = '', $domain = '') } $domain = strtolower(preg_replace('/^www\./ui', '', $domain)); - if (!$domain || strpos($domain, '.') === false) { + if (!$domain || mb_strpos($domain, '.') === false) { return 0; // Not possible. } if (!is_null($blog_id = &$this->staticKey('domainMappingBlogId', $domain))) { diff --git a/src/includes/traits/Shared/FsUtils.php b/src/includes/traits/Shared/FsUtils.php index d4a4f036..ef810651 100644 --- a/src/includes/traits/Shared/FsUtils.php +++ b/src/includes/traits/Shared/FsUtils.php @@ -23,12 +23,12 @@ public function nDirSeps($dir_file, $allow_trailing_slash = false) if (!isset($dir_file[0])) { return ''; // Catch empty string. } - if (strpos($dir_file, '://' !== false)) { + if (mb_strpos($dir_file, '://' !== false)) { if (preg_match('/^(?P[a-zA-Z0-9]+)\:\/\//u', $dir_file, $stream_wrapper)) { $dir_file = preg_replace('/^(?P[a-zA-Z0-9]+)\:\/\//u', '', $dir_file); } } - if (strpos($dir_file, ':' !== false)) { + if (mb_strpos($dir_file, ':' !== false)) { if (preg_match('/^(?P[a-zA-Z])\:[\/\\\\]/u', $dir_file)) { $dir_file = preg_replace_callback('/^(?P[a-zA-Z])\:[\/\\\\]/u', create_function('$m', 'return strtoupper($m[0]);'), $dir_file); } @@ -73,10 +73,10 @@ public function getTmpDir() if (!empty($_SERVER['TMP'])) { $possible_dirs[] = (string) $_SERVER['TMP']; } - if (stripos(PHP_OS, 'win') === 0) { + if (mb_stripos(PHP_OS, 'win') === 0) { $possible_dirs[] = 'C:/Temp'; } - if (stripos(PHP_OS, 'win') !== 0) { + if (mb_stripos(PHP_OS, 'win') !== 0) { $possible_dirs[] = '/tmp'; } if (defined('WP_CONTENT_DIR')) { @@ -280,7 +280,7 @@ public function getDirRegexStats($dir, $regex = '', $include_paths = false, $che if ($_resource_basename === '.htaccess') { continue; // Ignore `.htaccess`. } - if (stripos($_resource_sub_path, $short_name_lc.'-') === 0) { + if (mb_stripos($_resource_sub_path, $short_name_lc.'-') === 0) { continue; // Ignore [SHORT_NAME] files in base. } switch ($_resource->getType()) { // `link`, `file`, `dir`. diff --git a/src/includes/traits/Shared/HookUtils.php b/src/includes/traits/Shared/HookUtils.php index b8d8cd3b..dfefd520 100644 --- a/src/includes/traits/Shared/HookUtils.php +++ b/src/includes/traits/Shared/HookUtils.php @@ -60,7 +60,7 @@ public function hookId($function) public function addHook($hook, $function, $priority = 10, $accepted_args = 1) { $hook = (string) $hook; - if (stripos($hook, 'zencache') === 0) { + if (mb_stripos($hook, 'zencache') === 0) { $hook = GLOBAL_NS.substr($hook, strlen('zencache')); } $priority = (integer) $priority; @@ -128,7 +128,7 @@ public function add_filter() public function removeHook($hook, $function, $priority = 10) { $hook = (string) $hook; - if (stripos($hook, 'zencache') === 0) { + if (mb_stripos($hook, 'zencache') === 0) { $hook = GLOBAL_NS.substr($hook, strlen('zencache')); } $priority = (integer) $priority; @@ -244,7 +244,7 @@ public function doWpAction($hook) $args = func_get_args(); call_user_func_array('do_action', $args); - if (stripos($hook, GLOBAL_NS) === 0) { + if (mb_stripos($hook, GLOBAL_NS) === 0) { $zencache_filter = 'zencache'.substr($hook, strlen(GLOBAL_NS)); $zencache_args = $args; // Use a copy of the args. $zencache_args[0] = $zencache_filter; @@ -267,7 +267,7 @@ public function applyWpFilters($hook) $args = func_get_args(); $value = call_user_func_array('apply_filters', $args); - if (stripos($hook, GLOBAL_NS) === 0) { + if (mb_stripos($hook, GLOBAL_NS) === 0) { $zencache_hook = 'zencache'.substr($hook, strlen(GLOBAL_NS)); $zencache_args = $args; // Use a copy of the args. $zencache_args[0] = $zencache_hook; diff --git a/src/includes/traits/Shared/HttpUtils.php b/src/includes/traits/Shared/HttpUtils.php index 56f9fd05..af505ad7 100644 --- a/src/includes/traits/Shared/HttpUtils.php +++ b/src/includes/traits/Shared/HttpUtils.php @@ -20,7 +20,7 @@ public function httpProtocol() if (!empty($_SERVER['SERVER_PROTOCOL']) && is_string($_SERVER['SERVER_PROTOCOL'])) { $protocol = strtoupper($_SERVER['SERVER_PROTOCOL']); } - if (!$protocol || stripos($protocol, 'HTTP/') !== 0) { + if (!$protocol || mb_stripos($protocol, 'HTTP/') !== 0) { $protocol = 'HTTP/1.0'; // Default value. } return $protocol; diff --git a/src/includes/traits/Shared/ReplaceUtils.php b/src/includes/traits/Shared/ReplaceUtils.php index 76c8c417..c6a7b689 100644 --- a/src/includes/traits/Shared/ReplaceUtils.php +++ b/src/includes/traits/Shared/ReplaceUtils.php @@ -23,9 +23,9 @@ public function strReplaceOnce($needle, $replace, $haystack, $caSe_insensitive = $needle = (string) $needle; $replace = (string) $replace; $haystack = (string) $haystack; - $caSe_strpos = $caSe_insensitive ? 'stripos' : 'strpos'; + $caSe_mb_strpos = $caSe_insensitive ? 'mb_stripos' : 'mb_strpos'; - if (($needle_strpos = $caSe_strpos($haystack, $needle)) === false) { + if (($needle_strpos = $caSe_mb_strpos($haystack, $needle)) === false) { return $haystack; // Nothing to replace. } return (string) substr_replace($haystack, $replace, $needle_strpos, strlen($needle)); diff --git a/src/includes/traits/Shared/ServerUtils.php b/src/includes/traits/Shared/ServerUtils.php index a011f144..65825af6 100644 --- a/src/includes/traits/Shared/ServerUtils.php +++ b/src/includes/traits/Shared/ServerUtils.php @@ -18,10 +18,10 @@ public function isApache() return $is; // Already cached this. } if (!empty($_SERVER['SERVER_SOFTWARE']) && is_string($_SERVER['SERVER_SOFTWARE'])) { - if (stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) { + if (mb_stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) { return $is = true; } - if (stripos($_SERVER['SERVER_SOFTWARE'], 'litespeed') !== false) { + if (mb_stripos($_SERVER['SERVER_SOFTWARE'], 'litespeed') !== false) { return $is = true; } } @@ -41,7 +41,7 @@ public function isNginx() return $is; // Already cached this. } if (!empty($_SERVER['SERVER_SOFTWARE']) && is_string($_SERVER['SERVER_SOFTWARE'])) { - if (stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) { + if (mb_stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) { return $is = true; } } @@ -61,10 +61,10 @@ public function isIis() return $is; // Already cached this. } if (!empty($_SERVER['SERVER_SOFTWARE']) && is_string($_SERVER['SERVER_SOFTWARE'])) { - if (stripos($_SERVER['SERVER_SOFTWARE'], 'microsoft-iis') !== false) { + if (mb_stripos($_SERVER['SERVER_SOFTWARE'], 'microsoft-iis') !== false) { return $is = true; } - if (stripos($_SERVER['SERVER_SOFTWARE'], 'expressiondevserver') !== false) { + if (mb_stripos($_SERVER['SERVER_SOFTWARE'], 'expressiondevserver') !== false) { return $is = true; } } diff --git a/src/includes/traits/Shared/UrlUtils.php b/src/includes/traits/Shared/UrlUtils.php index 71262e6c..74e1e7ad 100644 --- a/src/includes/traits/Shared/UrlUtils.php +++ b/src/includes/traits/Shared/UrlUtils.php @@ -19,9 +19,9 @@ public function parseUrl($url_uri_qsl, $component = -1) { $url_uri_qsl = (string) $url_uri_qsl; $component = (integer) $component; - ${'//'} = strpos($url_uri_qsl, '//') === 0; + ${'//'} = mb_strpos($url_uri_qsl, '//') === 0; - if ($url_uri_qsl && strpos($url_uri_qsl, '&') !== false) { + if ($url_uri_qsl && mb_strpos($url_uri_qsl, '&') !== false) { $url_uri_qsl = str_replace('&', '&', $url_uri_qsl); } if ($component > -1) { From e013ea87b209878681ce48ea4c9478852c991caa Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Thu, 3 Mar 2016 21:11:42 -0500 Subject: [PATCH 04/11] Multibyte String Enhancements: Update `strtolower()` and `strtoupper()` See websharks/comet-cache#703 --- src/includes/classes/Actions.php | 4 +-- src/includes/classes/AdvCacheBackCompat.php | 2 +- src/includes/classes/AutoCache.php | 4 +-- src/includes/classes/CdnFilters.php | 28 +++++++++---------- src/includes/classes/Conflicts.php | 2 +- src/includes/classes/MenuPageOptions.php | 6 ++-- src/includes/stub.php | 2 +- src/includes/traits/Ac/BrowserUtils.php | 8 +++--- src/includes/traits/Ac/NcDebugUtils.php | 2 +- src/includes/traits/Ac/ObUtils.php | 2 +- src/includes/traits/Plugin/AdminBarUtils.php | 2 +- src/includes/traits/Plugin/InstallUtils.php | 10 +++---- src/includes/traits/Shared/CachePathUtils.php | 4 +-- .../traits/Shared/ConditionalUtils.php | 14 +++++----- .../traits/Shared/DomainMappingUtils.php | 6 ++-- src/includes/traits/Shared/FsUtils.php | 6 ++-- src/includes/traits/Shared/HttpUtils.php | 4 +-- src/includes/traits/Shared/IpAddrUtils.php | 4 +-- src/includes/traits/Shared/TokenUtils.php | 10 +++---- 19 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/includes/classes/Actions.php b/src/includes/classes/Actions.php index 440acb4b..524c0ead 100644 --- a/src/includes/classes/Actions.php +++ b/src/includes/classes/Actions.php @@ -250,8 +250,8 @@ protected function ajaxClearCacheUrl($args) } $is_multisite = is_multisite(); $is_home = rtrim($url, '/') === rtrim($home_url, '/'); - $url_host = strtolower(parse_url($url, PHP_URL_HOST)); - $home_host = strtolower(parse_url($home_url, PHP_URL_HOST)); + $url_host = mb_strtolower(parse_url($url, PHP_URL_HOST)); + $home_host = mb_strtolower(parse_url($home_url, PHP_URL_HOST)); $is_offsite_host = !$is_multisite && $url_host !== $home_host; if (!$this->plugin->currentUserCanClearCache()) { diff --git a/src/includes/classes/AdvCacheBackCompat.php b/src/includes/classes/AdvCacheBackCompat.php index 461aaa53..b79a8c52 100644 --- a/src/includes/classes/AdvCacheBackCompat.php +++ b/src/includes/classes/AdvCacheBackCompat.php @@ -44,7 +44,7 @@ public static function zcRequestVars() */ public static function zenCacheConstants() { - $_global_ns = strtoupper(GLOBAL_NS); + $_global_ns = mb_strtoupper(GLOBAL_NS); if (!($constants = get_defined_constants(true)) || empty($constants['user'])) { return; // Nothing to do; i.e. no user-defined constants. diff --git a/src/includes/classes/AutoCache.php b/src/includes/classes/AutoCache.php index 6ce3e47c..d58b72a8 100644 --- a/src/includes/classes/AutoCache.php +++ b/src/includes/classes/AutoCache.php @@ -178,7 +178,7 @@ protected function logAutoCacheUrl($url, $wp_remote_get_response) { $cache_dir = $this->plugin->cacheDir(); $cache_lock = $this->plugin->cacheLock(); - $auto_cache_log_file = $cache_dir.'/'.strtolower(SHORT_NAME).'-auto-cache.log'; + $auto_cache_log_file = $cache_dir.'/'.mb_strtolower(SHORT_NAME).'-auto-cache.log'; if (is_file($auto_cache_log_file) && !is_writable($auto_cache_log_file)) { throw new \Exception(sprintf(__('Auto-cache log file is NOT writable: `%1$s`. Please set permissions to `644` (or higher). `666` might be needed in some cases.', SLUG_TD), $auto_cache_log_file)); @@ -215,7 +215,7 @@ protected function logAutoCacheRun($total_urls, $total_time) { $cache_dir = $this->plugin->cacheDir(); $cache_lock = $this->plugin->cacheLock(); - $auto_cache_log_file = $cache_dir.'/'.strtolower(SHORT_NAME).'-auto-cache.log'; + $auto_cache_log_file = $cache_dir.'/'.mb_strtolower(SHORT_NAME).'-auto-cache.log'; if (is_file($auto_cache_log_file) && !is_writable($auto_cache_log_file)) { throw new \Exception(sprintf(__('Auto-cache log file is NOT writable: `%1$s`. Please set permissions to `644` (or higher). `666` might be needed in some cases.', SLUG_TD), $auto_cache_log_file)); diff --git a/src/includes/classes/CdnFilters.php b/src/includes/classes/CdnFilters.php index f0b460b1..89f890d4 100644 --- a/src/includes/classes/CdnFilters.php +++ b/src/includes/classes/CdnFilters.php @@ -138,9 +138,9 @@ public function __construct() // Host-related properties. - $this->local_host = strtolower($this->plugin->hostToken()); - $this->cdn_host = strtolower($this->plugin->options['cdn_host']); - $this->cdn_hosts = strtolower($this->plugin->options['cdn_hosts']); + $this->local_host = mb_strtolower($this->plugin->hostToken()); + $this->cdn_host = mb_strtolower($this->plugin->options['cdn_host']); + $this->cdn_hosts = mb_strtolower($this->plugin->options['cdn_hosts']); $this->parseCdnHosts(); // Convert CDN hosts to an array. // Configure invalidation-related properties. @@ -158,7 +158,7 @@ public function __construct() if (!($cdn_whitelisted_extensions = trim($this->plugin->options['cdn_whitelisted_extensions']))) { $cdn_whitelisted_extensions = implode('|', static::defaultWhitelistedExtensions()); } - $this->cdn_whitelisted_extensions = trim(strtolower($cdn_whitelisted_extensions), "\r\n\t\0\x0B".' |;,'); + $this->cdn_whitelisted_extensions = trim(mb_strtolower($cdn_whitelisted_extensions), "\r\n\t\0\x0B".' |;,'); $this->cdn_whitelisted_extensions = preg_split('/[|;,\s]+/', $this->cdn_whitelisted_extensions, -1, PREG_SPLIT_NO_EMPTY); $this->cdn_whitelisted_extensions = array_unique($this->cdn_whitelisted_extensions); @@ -166,7 +166,7 @@ public function __construct() $cdn_blacklisted_extensions = $this->plugin->options['cdn_blacklisted_extensions']; - $this->cdn_blacklisted_extensions = trim(strtolower($cdn_blacklisted_extensions), "\r\n\t\0\x0B".' |;,'); + $this->cdn_blacklisted_extensions = trim(mb_strtolower($cdn_blacklisted_extensions), "\r\n\t\0\x0B".' |;,'); $this->cdn_blacklisted_extensions = preg_split('/[|;,\s]+/', $this->cdn_blacklisted_extensions, -1, PREG_SPLIT_NO_EMPTY); $this->cdn_blacklisted_extensions[] = 'php'; // Always exclude. @@ -174,7 +174,7 @@ public function __construct() // Whitelisted URI patterns; if applicable. - $cdn_whitelisted_uri_patterns = trim(strtolower($this->plugin->options['cdn_whitelisted_uri_patterns'])); + $cdn_whitelisted_uri_patterns = trim(mb_strtolower($this->plugin->options['cdn_whitelisted_uri_patterns'])); $cdn_whitelisted_uri_patterns = preg_split('/['."\r\n".']+/', $cdn_whitelisted_uri_patterns, null, PREG_SPLIT_NO_EMPTY); $cdn_whitelisted_uri_patterns = array_unique($cdn_whitelisted_uri_patterns); @@ -185,7 +185,7 @@ public function __construct() } // Blacklisted URI patterns; if applicable. - $cdn_blacklisted_uri_patterns = trim(strtolower($this->plugin->options['cdn_blacklisted_uri_patterns'])); + $cdn_blacklisted_uri_patterns = trim(mb_strtolower($this->plugin->options['cdn_blacklisted_uri_patterns'])); $cdn_blacklisted_uri_patterns = preg_split('/['."\r\n".']+/', $cdn_blacklisted_uri_patterns, null, PREG_SPLIT_NO_EMPTY); $cdn_blacklisted_uri_patterns[] = '*/wp-admin/*'; // Always. @@ -462,7 +462,7 @@ protected function localFile($url_uri_qsl) if (empty($parsed['host']) && empty($this->cdn_hosts[$this->local_host])) { return; // Not on this host name. } - if (!empty($parsed['host']) && empty($this->cdn_hosts[strtolower($parsed['host'])])) { + if (!empty($parsed['host']) && empty($this->cdn_hosts[mb_strtolower($parsed['host'])])) { return; // Not on this host name. } if (!isset($parsed['path'][0]) || $parsed['path'][0] !== '/') { @@ -479,10 +479,10 @@ protected function localFile($url_uri_qsl) $uri = $parsed['path']; // Put URI together. if (!empty($parsed['scheme'])) { - $scheme = strtolower($parsed['scheme']); + $scheme = mb_strtolower($parsed['scheme']); } if (!empty($parsed['host'])) { - $host = strtolower($parsed['host']); + $host = mb_strtolower($parsed['host']); } if (!empty($parsed['query'])) { $uri .= '?'.$parsed['query']; @@ -512,7 +512,7 @@ protected function extension($path) return ''; // No path. } - return strtolower(ltrim((string) strrchr(basename($path), '.'), '.')); + return mb_strtolower(ltrim((string) strrchr(basename($path), '.'), '.')); } /** @@ -526,7 +526,7 @@ protected function parseCdnHosts() $this->cdn_hosts = []; // Initialize. $lines = str_replace(["\r\n", "\r"], "\n", $lines); - $lines = trim(strtolower($lines)); // Force all mappings to lowercase. + $lines = trim(mb_strtolower($lines)); // Force all mappings to lowercase. $lines = preg_split('/['."\r\n".']+/', $lines, null, PREG_SPLIT_NO_EMPTY); foreach ($lines as $_line) { @@ -556,7 +556,7 @@ protected function parseCdnHosts() if (empty($this->cdn_hosts[$this->local_host])) { if ($this->cdn_host && (!is_multisite() || is_main_site())) { - $this->cdn_hosts[strtolower((string) $this->plugin->parseUrl(network_home_url(), PHP_URL_HOST))][] = $this->cdn_host; + $this->cdn_hosts[mb_strtolower((string) $this->plugin->parseUrl(network_home_url(), PHP_URL_HOST))][] = $this->cdn_host; } } } @@ -571,7 +571,7 @@ protected function parseCdnHosts() public static function defaultWhitelistedExtensions() { $extensions = array_keys(wp_get_mime_types()); - $extensions = explode('|', strtolower(implode('|', $extensions))); + $extensions = explode('|', mb_strtolower(implode('|', $extensions))); $extensions = array_merge($extensions, ['eot', 'ttf', 'otf', 'woff']); if (($permalink_structure = get_option('permalink_structure'))) { diff --git a/src/includes/classes/Conflicts.php b/src/includes/classes/Conflicts.php index d2427d39..ab70288d 100644 --- a/src/includes/classes/Conflicts.php +++ b/src/includes/classes/Conflicts.php @@ -77,7 +77,7 @@ protected function maybeEnqueueNotice() return; // Already did this in one plugin or the other. } $construct_name = function ($slug_or_ns) { - $name = trim(strtolower((string) $slug_or_ns)); + $name = trim(mb_strtolower((string) $slug_or_ns)); $name = preg_replace('/[_\-]+(?:lite|pro)$/u', '', $name); $name = preg_replace('/[^a-z0-9]/u', ' ', $name); $name = str_replace('cache', 'Cache', ucwords($name)); diff --git a/src/includes/classes/MenuPageOptions.php b/src/includes/classes/MenuPageOptions.php index 44ece530..018f5783 100644 --- a/src/includes/classes/MenuPageOptions.php +++ b/src/includes/classes/MenuPageOptions.php @@ -160,7 +160,7 @@ public function __construct() if (!empty($_REQUEST[GLOBAL_NS.'_advanced_cache_add_failure'])) { echo '
'."\n"; if ($_REQUEST[GLOBAL_NS.'_advanced_cache_add_failure'] === 'advanced-cache') { - echo ' '.sprintf(__('Failed to update your /wp-content/advanced-cache.php file. Cannot write stat file: %1$s/%2$s-advanced-cache. Please be sure this directory exists (and that it\'s writable): %1$s. Please use directory permissions 755 or higher (perhaps 777). Once you\'ve done this, please try again.', SLUG_TD), esc_html($this->plugin->cacheDir()), esc_html(strtolower(SHORT_NAME)))."\n"; + echo ' '.sprintf(__('Failed to update your /wp-content/advanced-cache.php file. Cannot write stat file: %1$s/%2$s-advanced-cache. Please be sure this directory exists (and that it\'s writable): %1$s. Please use directory permissions 755 or higher (perhaps 777). Once you\'ve done this, please try again.', SLUG_TD), esc_html($this->plugin->cacheDir()), esc_html(mb_strtolower(SHORT_NAME)))."\n"; } else { echo ' '.__('Failed to update your /wp-content/advanced-cache.php file. Most likely a permissions error. Please create an empty file here: /wp-content/advanced-cache.php (just an empty PHP file, with nothing in it); give it permissions 644 or higher (perhaps 666). Once you\'ve done this, please try again.', SLUG_TD)."\n"; } @@ -569,7 +569,7 @@ public function __construct() echo '

'."\n"; echo '

'.__('Tip: Setting this to No is highly recommended when running a membership plugin like s2Member (as one example). In fact, many plugins like s2Member will send nocache_headers() on their own, so your configuration here will likely be overwritten when you run such plugins (which is better anyway). In short, if you run a membership plugin, you should NOT allow a client-side browser cache.', SLUG_TD).'

'."\n"; echo '

'.__('Tip: Setting this to No will NOT impact static content; e.g., CSS, JS, images, or other media. This setting pertains only to dynamic PHP scripts which produce content generated by WordPress.', SLUG_TD).'

'."\n"; - echo '

'.sprintf(__('Advanced Tip: if you have this set to No, but you DO want to allow a few special URLs to be cached by the browser; you can add this parameter to your URL ?%2$sABC=1. This tells %1$s that it\'s OK for the browser to cache that particular URL. In other words, the %2$sABC=1 parameter tells %1$s NOT to send no-cache headers to the browser.', SLUG_TD), esc_html(NAME), esc_html(strtolower(SHORT_NAME))).'

'."\n"; + echo '

'.sprintf(__('Advanced Tip: if you have this set to No, but you DO want to allow a few special URLs to be cached by the browser; you can add this parameter to your URL ?%2$sABC=1. This tells %1$s that it\'s OK for the browser to cache that particular URL. In other words, the %2$sABC=1 parameter tells %1$s NOT to send no-cache headers to the browser.', SLUG_TD), esc_html(NAME), esc_html(mb_strtolower(SHORT_NAME))).'

'."\n"; echo '

'.__('Exclusion Patterns for Client-Side Caching', SLUG_TD).'

'."\n"; echo '

'.__('When you enable Client-Side Caching above, you may want to prevent certain pages on your site from being cached by a client-side browser. This is where you will enter those if you need to (one per line). Searches are performed against the REQUEST_URI; i.e., /path/?query (caSe insensitive). So, don\'t put in full URLs here, just word fragments found in the file path (or query string) is all you need, excluding the http:// and domain name. A wildcard * character can also be used when necessary; e.g., /category/abc-followed-by-* (where * = 0 or more characters that are NOT a slash /). Other special characters include: ** = 0 or more characters of any kind, including / slashes; ^ = beginning of the string; $ = end of the string. To learn more about this syntax, please see this KB article.', SLUG_TD).'

'."\n"; echo '

'."\n"; @@ -636,7 +636,7 @@ public function __construct() echo ' '."\n"; echo '

'."\n"; echo '

'.__('Note: POST requests (i.e., forms with method="post") are always excluded from the cache, which is the way it should be. Any POST/PUT/DELETE request should NEVER (ever) be cached. CLI (and self-serve) requests are also excluded from the cache (always). A CLI request is one that comes from the command line; commonly used by CRON jobs and other automated routines. A self-serve request is an HTTP connection established from your site -› to your site. For instance, a WP Cron job, or any other HTTP request that is spawned not by a user, but by the server itself.', SLUG_TD).'

'."\n"; - echo '

'.sprintf(__('Advanced Tip: If you are NOT caching GET requests (recommended), but you DO want to allow some special URLs that include query string parameters to be cached; you can add this special parameter to any URL ?%2$sAC=1. This tells %1$s that it\'s OK to cache that particular URL, even though it contains query string arguments. If you ARE caching GET requests and you want to force %1$s to NOT cache a specific request, you can add this special parameter to any URL ?%2$sAC=0.', SLUG_TD), esc_html(NAME), esc_html(strtolower(SHORT_NAME))).'

'."\n"; + echo '

'.sprintf(__('Advanced Tip: If you are NOT caching GET requests (recommended), but you DO want to allow some special URLs that include query string parameters to be cached; you can add this special parameter to any URL ?%2$sAC=1. This tells %1$s that it\'s OK to cache that particular URL, even though it contains query string arguments. If you ARE caching GET requests and you want to force %1$s to NOT cache a specific request, you can add this special parameter to any URL ?%2$sAC=0.', SLUG_TD), esc_html(NAME), esc_html(mb_strtolower(SHORT_NAME))).'

'."\n"; echo '
'."\n"; echo ''."\n"; diff --git a/src/includes/stub.php b/src/includes/stub.php index 00965802..a5ddae7c 100644 --- a/src/includes/stub.php +++ b/src/includes/stub.php @@ -16,7 +16,7 @@ ${__FILE__}['plugin'] = dirname(dirname(__DIR__)); ${__FILE__}['plugin'] .= '/'.basename(${__FILE__}['plugin']).'.php'; ${__FILE__}['ns_path'] = str_replace('\\', '/', __NAMESPACE__); // To dir/path. -${__FILE__}['is_pro'] = strtolower(basename(${__FILE__}['ns_path'])) === 'pro'; +${__FILE__}['is_pro'] = mb_strtolower(basename(${__FILE__}['ns_path'])) === 'pro'; define(__NAMESPACE__.'\\SHORT_NAME', 'CC'); define(__NAMESPACE__.'\\NAME', 'Comet Cache'); diff --git a/src/includes/traits/Ac/BrowserUtils.php b/src/includes/traits/Ac/BrowserUtils.php index 2953a96c..1cf59773 100644 --- a/src/includes/traits/Ac/BrowserUtils.php +++ b/src/includes/traits/Ac/BrowserUtils.php @@ -16,8 +16,8 @@ public function maybeStopBrowserCaching() case true: // If global config allows, check exclusions. - if (isset($_GET[strtolower(SHORT_NAME).'ABC'])) { - if (!filter_var($_GET[strtolower(SHORT_NAME).'ABC'], FILTER_VALIDATE_BOOLEAN)) { + if (isset($_GET[mb_strtolower(SHORT_NAME).'ABC'])) { + if (!filter_var($_GET[mb_strtolower(SHORT_NAME).'ABC'], FILTER_VALIDATE_BOOLEAN)) { return $this->sendNoCacheHeaders(); // Disallow. } // Else, allow client-side caching; because `ABC` is a true-ish value. // ↑ Note that exclusion patterns are ignored in this case, in favor of `ABC`. @@ -28,8 +28,8 @@ public function maybeStopBrowserCaching() case false: // Global config disallows; check inclusions. - if (isset($_GET[strtolower(SHORT_NAME).'ABC'])) { - if (filter_var($_GET[strtolower(SHORT_NAME).'ABC'], FILTER_VALIDATE_BOOLEAN)) { + if (isset($_GET[mb_strtolower(SHORT_NAME).'ABC'])) { + if (filter_var($_GET[mb_strtolower(SHORT_NAME).'ABC'], FILTER_VALIDATE_BOOLEAN)) { return; // Allow, because `ABC` is a false-ish value. } // Else, disallow client-side caching; because `ABC` is a true-ish value. // ↑ Note that inclusion patterns are ignored in this case, in favor of `ABC`. diff --git a/src/includes/traits/Ac/NcDebugUtils.php b/src/includes/traits/Ac/NcDebugUtils.php index 592d9a4d..32902747 100644 --- a/src/includes/traits/Ac/NcDebugUtils.php +++ b/src/includes/traits/Ac/NcDebugUtils.php @@ -111,7 +111,7 @@ public function maybeGetNcDebugInfo($reason_code = '', $reason = '') break; // Break switch handler. case $this::NC_DEBUG_AC_GET_VAR: - $reason = sprintf(__('because `$_GET[\'%1$sAC\']` is set to a boolean-ish FALSE value.', SLUG_TD), strtolower(SHORT_NAME)); + $reason = sprintf(__('because `$_GET[\'%1$sAC\']` is set to a boolean-ish FALSE value.', SLUG_TD), mb_strtolower(SHORT_NAME)); break; // Break switch handler. case $this::NC_DEBUG_UNCACHEABLE_REQUEST: diff --git a/src/includes/traits/Ac/ObUtils.php b/src/includes/traits/Ac/ObUtils.php index f0f5538c..ac018dac 100644 --- a/src/includes/traits/Ac/ObUtils.php +++ b/src/includes/traits/Ac/ObUtils.php @@ -126,7 +126,7 @@ public function maybeStartOutputBuffering() if (isset($_SERVER['DONOTCACHEPAGE'])) { return $this->maybeSetDebugInfo($this::NC_DEBUG_DONOTCACHEPAGE_SERVER_VAR); } - if (isset($_GET[strtolower(SHORT_NAME).'AC']) && !filter_var($_GET[strtolower(SHORT_NAME).'AC'], FILTER_VALIDATE_BOOLEAN)) { + if (isset($_GET[mb_strtolower(SHORT_NAME).'AC']) && !filter_var($_GET[mb_strtolower(SHORT_NAME).'AC'], FILTER_VALIDATE_BOOLEAN)) { return $this->maybeSetDebugInfo($this::NC_DEBUG_AC_GET_VAR); } if ($this->isUncacheableRequestMethod()) { diff --git a/src/includes/traits/Plugin/AdminBarUtils.php b/src/includes/traits/Plugin/AdminBarUtils.php index 89540f68..5698e72b 100644 --- a/src/includes/traits/Plugin/AdminBarUtils.php +++ b/src/includes/traits/Plugin/AdminBarUtils.php @@ -17,7 +17,7 @@ trait AdminBarUtils */ public function adminBarShowing($feature = '') { - $feature = trim(strtolower((string) $feature)); + $feature = trim(mb_strtolower((string) $feature)); if (!is_null($showing = &$this->cacheKey('adminBarShowing', $feature))) { return $showing; // Already cached this. } diff --git a/src/includes/traits/Plugin/InstallUtils.php b/src/includes/traits/Plugin/InstallUtils.php index 3297bd7f..6c5efdd9 100644 --- a/src/includes/traits/Plugin/InstallUtils.php +++ b/src/includes/traits/Plugin/InstallUtils.php @@ -246,7 +246,7 @@ public function checkAdvancedCache() } $cache_dir = $this->cacheDir(); $advanced_cache_file = WP_CONTENT_DIR.'/advanced-cache.php'; - $advanced_cache_check_file = $cache_dir.'/'.strtolower(SHORT_NAME).'-advanced-cache'; + $advanced_cache_check_file = $cache_dir.'/'.mb_strtolower(SHORT_NAME).'-advanced-cache'; // Fixes zero-byte advanced-cache.php bug related to migrating from ZenCache // See: @@ -276,7 +276,7 @@ public function addAdvancedCache() } $cache_dir = $this->cacheDir(); $advanced_cache_file = WP_CONTENT_DIR.'/advanced-cache.php'; - $advanced_cache_check_file = $cache_dir.'/'.strtolower(SHORT_NAME).'-advanced-cache'; + $advanced_cache_check_file = $cache_dir.'/'.mb_strtolower(SHORT_NAME).'-advanced-cache'; $advanced_cache_template = dirname(dirname(__DIR__)).'/templates/advanced-cache.txt'; if (is_file($advanced_cache_file) && !is_writable($advanced_cache_file)) { @@ -443,7 +443,7 @@ public function deleteAdvancedCache() { $cache_dir = $this->cacheDir(); $advanced_cache_file = WP_CONTENT_DIR.'/advanced-cache.php'; - $advanced_cache_check_file = $cache_dir.'/'.strtolower(SHORT_NAME).'-advanced-cache'; + $advanced_cache_check_file = $cache_dir.'/'.mb_strtolower(SHORT_NAME).'-advanced-cache'; if (is_file($advanced_cache_file)) { if (!is_writable($advanced_cache_file) || !unlink($advanced_cache_file)) { @@ -489,7 +489,7 @@ public function checkBlogPaths() return; // Skip on plugin actions. } $cache_dir = $this->cacheDir(); - $blog_paths_file = $cache_dir.'/'.strtolower(SHORT_NAME).'-blog-paths'; + $blog_paths_file = $cache_dir.'/'.mb_strtolower(SHORT_NAME).'-blog-paths'; if (!is_file($blog_paths_file)) { $this->updateBlogPaths(); @@ -520,7 +520,7 @@ public function updateBlogPaths($enable_live_network_counts = null) return $value; // N/A. } $cache_dir = $this->cacheDir(); - $blog_paths_file = $cache_dir.'/'.strtolower(SHORT_NAME).'-blog-paths'; + $blog_paths_file = $cache_dir.'/'.mb_strtolower(SHORT_NAME).'-blog-paths'; $cache_lock = $this->cacheLock(); diff --git a/src/includes/traits/Shared/CachePathUtils.php b/src/includes/traits/Shared/CachePathUtils.php index da0cfe8e..7973ba0b 100644 --- a/src/includes/traits/Shared/CachePathUtils.php +++ b/src/includes/traits/Shared/CachePathUtils.php @@ -146,9 +146,9 @@ public function buildCachePath($url, $with_user_token = '', $with_version_salt = } } if ($this->isExtensionLoaded('mbstring') && mb_check_encoding($cache_path, 'UTF-8')) { - $cache_path = mb_strtolower($cache_path, 'UTF-8'); + $cache_path = mb_mb_strtolower($cache_path, 'UTF-8'); } - $cache_path = str_replace('.', '-', strtolower($cache_path)); + $cache_path = str_replace('.', '-', mb_strtolower($cache_path)); if (!($flags & $this::CACHE_PATH_NO_QUV)) { if (!($flags & $this::CACHE_PATH_NO_QUERY)) { diff --git a/src/includes/traits/Shared/ConditionalUtils.php b/src/includes/traits/Shared/ConditionalUtils.php index 95e15cc6..c6c37052 100644 --- a/src/includes/traits/Shared/ConditionalUtils.php +++ b/src/includes/traits/Shared/ConditionalUtils.php @@ -73,7 +73,7 @@ public function isPostPutDeleteRequest() return $is = true; } if (!empty($_SERVER['REQUEST_METHOD']) && is_string($_SERVER['REQUEST_METHOD'])) { - if (in_array(strtoupper($_SERVER['REQUEST_METHOD']), ['POST', 'PUT', 'DELETE'], true)) { + if (in_array(mb_strtoupper($_SERVER['REQUEST_METHOD']), ['POST', 'PUT', 'DELETE'], true)) { return $is = true; } } @@ -96,9 +96,9 @@ public function requestContainsUncacheableQueryVars() } if (!empty($_GET) || !empty($_SERVER['QUERY_STRING'])) { $_get_count = !empty($_GET) ? count($_GET) : 0; - $is_abc_only = $_get_count === 1 && isset($_GET[strtolower(SHORT_NAME).'ABC']); + $is_abc_only = $_get_count === 1 && isset($_GET[mb_strtolower(SHORT_NAME).'ABC']); $is_nginx_q_only = $_get_count === 1 && isset($_GET['q']) && $this->isNginx(); - $is_ac_get_var_true = isset($_GET[strtolower(SHORT_NAME).'AC']) && filter_var($_GET[strtolower(SHORT_NAME).'AC'], FILTER_VALIDATE_BOOLEAN); + $is_ac_get_var_true = isset($_GET[mb_strtolower(SHORT_NAME).'AC']) && filter_var($_GET[mb_strtolower(SHORT_NAME).'AC'], FILTER_VALIDATE_BOOLEAN); if (!$is_abc_only && !$is_nginx_q_only && !$is_ac_get_var_true) { return $is = true; @@ -125,7 +125,7 @@ public function isUncacheableRequestMethod() return $is = true; } if (!empty($_SERVER['REQUEST_METHOD']) && is_string($_SERVER['REQUEST_METHOD'])) { - if (!in_array(strtoupper($_SERVER['REQUEST_METHOD']), ['GET'], true)) { + if (!in_array(mb_strtoupper($_SERVER['REQUEST_METHOD']), ['GET'], true)) { return $is = true; } } @@ -380,10 +380,10 @@ public function functionIsPossible($function) $disabled_functions = []; // Initialize disabled/blacklisted functions. if (($disable_functions = trim(ini_get('disable_functions')))) { - $disabled_functions = array_merge($disabled_functions, preg_split('/[\s;,]+/', strtolower($disable_functions), -1, PREG_SPLIT_NO_EMPTY)); + $disabled_functions = array_merge($disabled_functions, preg_split('/[\s;,]+/', mb_strtolower($disable_functions), -1, PREG_SPLIT_NO_EMPTY)); } if (($blacklist_functions = trim(ini_get('suhosin.executor.func.blacklist')))) { - $disabled_functions = array_merge($disabled_functions, preg_split('/[\s;,]+/', strtolower($blacklist_functions), -1, PREG_SPLIT_NO_EMPTY)); + $disabled_functions = array_merge($disabled_functions, preg_split('/[\s;,]+/', mb_strtolower($blacklist_functions), -1, PREG_SPLIT_NO_EMPTY)); } if (filter_var(ini_get('suhosin.executor.disable_eval'), FILTER_VALIDATE_BOOLEAN)) { $disabled_functions = array_merge($disabled_functions, ['eval']); @@ -394,7 +394,7 @@ public function functionIsPossible($function) return $is = false; // Not possible. } } - if ($disabled_functions && in_array(strtolower($function), $disabled_functions, true)) { + if ($disabled_functions && in_array(mb_strtolower($function), $disabled_functions, true)) { return $is = false; // Not possible. } return $is = true; diff --git a/src/includes/traits/Shared/DomainMappingUtils.php b/src/includes/traits/Shared/DomainMappingUtils.php index 32c52aa1..b7a80d49 100644 --- a/src/includes/traits/Shared/DomainMappingUtils.php +++ b/src/includes/traits/Shared/DomainMappingUtils.php @@ -74,7 +74,7 @@ public function domainMappingUrlFilter($url) if (empty($url_parts['host'])) { return $original_url; // Not possible. } - $blog_domain = strtolower($url_parts['host']); // In the unfiltered URL. + $blog_domain = mb_strtolower($url_parts['host']); // In the unfiltered URL. $blog_path = $this->hostDirToken(false, false, !empty($url_parts['path']) ? $url_parts['path'] : '/'); if (!($blog_id = (integer) get_blog_id_from_url($blog_domain, $blog_path))) { @@ -159,7 +159,7 @@ public function domainMappingBlogId($url = '', $domain = '') if (!$url && !$domain && ($blog_details = $this->blogDetails())) { $domain = $blog_details->domain; } - $domain = strtolower(preg_replace('/^www\./ui', '', $domain)); + $domain = mb_strtolower(preg_replace('/^www\./ui', '', $domain)); if (!$domain || mb_strpos($domain, '.') === false) { return 0; // Not possible. @@ -230,7 +230,7 @@ public function domainMappingBlogDomain($blog_id = 0, $fallback = false) } $wpdb->suppress_errors($suppressing_errors); // Restore. - return $domain = strtolower((string) $domain); + return $domain = mb_strtolower((string) $domain); } /** diff --git a/src/includes/traits/Shared/FsUtils.php b/src/includes/traits/Shared/FsUtils.php index ef810651..8d572349 100644 --- a/src/includes/traits/Shared/FsUtils.php +++ b/src/includes/traits/Shared/FsUtils.php @@ -37,7 +37,7 @@ public function nDirSeps($dir_file, $allow_trailing_slash = false) $dir_file = ($allow_trailing_slash) ? $dir_file : rtrim($dir_file, '/'); // Strip trailing slashes. if (!empty($stream_wrapper[0])) { - $dir_file = strtolower($stream_wrapper[0]).$dir_file; + $dir_file = mb_strtolower($stream_wrapper[0]).$dir_file; } return $dir_file; // Normalized now. } @@ -204,7 +204,7 @@ public function abbrBytes($string) return (float) 0; } $value = (float) $_m['value']; - $modifier = strtolower($_m['modifier']); + $modifier = mb_strtolower($_m['modifier']); unset($_m); // Housekeeping. switch ($modifier) { @@ -268,7 +268,7 @@ public function getDirRegexStats($dir, $regex = '', $include_paths = false, $che if (!$dir || !is_dir($dir)) { return $stats; // Not possible. } - $short_name_lc = strtolower(SHORT_NAME); // Once only. + $short_name_lc = mb_strtolower(SHORT_NAME); // Once only. foreach ($this->dirRegexIteration($dir, $regex) as $_resource) { $_resource_sub_path = $_resource->getSubpathname(); diff --git a/src/includes/traits/Shared/HttpUtils.php b/src/includes/traits/Shared/HttpUtils.php index af505ad7..09e89088 100644 --- a/src/includes/traits/Shared/HttpUtils.php +++ b/src/includes/traits/Shared/HttpUtils.php @@ -18,7 +18,7 @@ public function httpProtocol() return $protocol; // Already cached this. } if (!empty($_SERVER['SERVER_PROTOCOL']) && is_string($_SERVER['SERVER_PROTOCOL'])) { - $protocol = strtoupper($_SERVER['SERVER_PROTOCOL']); + $protocol = mb_strtoupper($_SERVER['SERVER_PROTOCOL']); } if (!$protocol || mb_stripos($protocol, 'HTTP/') !== 0) { $protocol = 'HTTP/1.0'; // Default value. @@ -113,7 +113,7 @@ public function cacheableHeadersList() $cacheable_headers = array_map('strtolower', $cacheable_headers); foreach ($headers as $_key => $_header) { - $_header = strtolower((string) strstr($_header, ':', true)); + $_header = mb_strtolower((string) strstr($_header, ':', true)); if (!$_header || !in_array($_header, $cacheable_headers, true)) { unset($headers[$_key]); } diff --git a/src/includes/traits/Shared/IpAddrUtils.php b/src/includes/traits/Shared/IpAddrUtils.php index 2c79a858..26d5da29 100644 --- a/src/includes/traits/Shared/IpAddrUtils.php +++ b/src/includes/traits/Shared/IpAddrUtils.php @@ -53,7 +53,7 @@ public function currentIp() unset($_key, $_source, $_valid_public_ip); // Housekeeping. } if (!empty($_SERVER['REMOTE_ADDR'])) { - return $ip = strtolower((string) $_SERVER['REMOTE_ADDR']); + return $ip = mb_strtolower((string) $_SERVER['REMOTE_ADDR']); } return $ip = 'unknown'; // Not possible. } @@ -79,7 +79,7 @@ public function validPublicIp($list_of_possible_ips) return ''; // Not possible; i.e., empty string. } foreach (preg_split('/[\s;,]+/', $list_of_possible_ips, -1, PREG_SPLIT_NO_EMPTY) as $_key => $_possible_ip) { - if (($_valid_public_ip = filter_var(strtolower($_possible_ip), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))) { + if (($_valid_public_ip = filter_var(mb_strtolower($_possible_ip), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))) { return $_valid_public_ip; // A valid public IPv4 or IPv6 address. } } diff --git a/src/includes/traits/Shared/TokenUtils.php b/src/includes/traits/Shared/TokenUtils.php index cfae4c82..ba59c4b7 100644 --- a/src/includes/traits/Shared/TokenUtils.php +++ b/src/includes/traits/Shared/TokenUtils.php @@ -53,7 +53,7 @@ public function hostToken($dashify = false, $consider_domain_mapping = false, $c $token = (string) $_SERVER['HTTP_HOST']; } if ($token) { // Have token? - $token = strtolower($token); + $token = mb_strtolower($token); if ($dashify) { // Dashify it? $token = preg_replace('/[^a-z0-9]/ui', '-', $token); $token = trim($token, '-'); @@ -95,7 +95,7 @@ public function hostTokenForBlog($dashify = false, $consider_domain_mapping = fa $token = $blog_details->domain; // Unmapped domain. } if ($token) { // Have token? - $token = strtolower($token); + $token = mb_strtolower($token); if ($dashify) { // Dashify it? $token = preg_replace('/[^a-z0-9]/ui', '-', $token); $token = trim($token, '-'); @@ -191,7 +191,7 @@ public function hostDirToken($dashify = false, $consider_domain_mapping = false, $token = isset($token[0]) ? '/'.$token.'/' : '/'; if ($token !== '/') { // Perhaps NOT the main site? - $blog_paths_file = $this->cacheDir().'/'.strtolower(SHORT_NAME).'-blog-paths'; + $blog_paths_file = $this->cacheDir().'/'.mb_strtolower(SHORT_NAME).'-blog-paths'; if (!is_file($blog_paths_file) || !in_array($token, unserialize(file_get_contents($blog_paths_file)), true)) { $token = '/'; // NOT a real/valid child blog path. } @@ -243,7 +243,7 @@ public function hostDirTokenForBlog($dashify = false, $consider_domain_mapping = $token = isset($token[0]) ? '/'.$token.'/' : '/'; if ($token !== '/') { // Perhaps NOT the main site? - $blog_paths_file = $this->cacheDir().'/'.strtolower(SHORT_NAME).'-blog-paths'; + $blog_paths_file = $this->cacheDir().'/'.mb_strtolower(SHORT_NAME).'-blog-paths'; if (!is_file($blog_paths_file) || !in_array($token, unserialize(file_get_contents($blog_paths_file)), true)) { $token = '/'; // NOT a real/valid child blog path. } @@ -332,7 +332,7 @@ public function userToken() } } if (!empty($_COOKIE['comment_author_email_'.COOKIEHASH])) { - return $token = md5(strtolower(stripslashes((string) $_COOKIE['comment_author_email_'.COOKIEHASH]))); + return $token = md5(mb_strtolower(stripslashes((string) $_COOKIE['comment_author_email_'.COOKIEHASH]))); } elseif (!empty($_COOKIE['wp-postpass_'.COOKIEHASH])) { return $token = md5(stripslashes((string) $_COOKIE['wp-postpass_'.COOKIEHASH])); } elseif (defined('SID') && SID) { From de3bd9204c554e82c7f473b68beeba534f498e40 Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Thu, 3 Mar 2016 21:12:41 -0500 Subject: [PATCH 05/11] Multibyte String Enhancements: Update `strtolower()` and `strtoupper()` See websharks/comet-cache#703 --- src/includes/traits/Shared/DomainMappingUtils.php | 2 +- src/includes/traits/Shared/FsUtils.php | 2 +- src/includes/traits/Shared/HttpUtils.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/includes/traits/Shared/DomainMappingUtils.php b/src/includes/traits/Shared/DomainMappingUtils.php index b7a80d49..bf092c9f 100644 --- a/src/includes/traits/Shared/DomainMappingUtils.php +++ b/src/includes/traits/Shared/DomainMappingUtils.php @@ -272,6 +272,6 @@ public function domainMappingBlogDomains($blog_id = 0) } $wpdb->suppress_errors($suppressing_errors); // Restore. - return $domains = array_unique(array_map('strtolower', (array) $domains)); + return $domains = array_unique(array_map('mb_strtolower', (array) $domains)); } } diff --git a/src/includes/traits/Shared/FsUtils.php b/src/includes/traits/Shared/FsUtils.php index 8d572349..26ae9fdf 100644 --- a/src/includes/traits/Shared/FsUtils.php +++ b/src/includes/traits/Shared/FsUtils.php @@ -30,7 +30,7 @@ public function nDirSeps($dir_file, $allow_trailing_slash = false) } if (mb_strpos($dir_file, ':' !== false)) { if (preg_match('/^(?P[a-zA-Z])\:[\/\\\\]/u', $dir_file)) { - $dir_file = preg_replace_callback('/^(?P[a-zA-Z])\:[\/\\\\]/u', create_function('$m', 'return strtoupper($m[0]);'), $dir_file); + $dir_file = preg_replace_callback('/^(?P[a-zA-Z])\:[\/\\\\]/u', create_function('$m', 'return mb_strtoupper($m[0]);'), $dir_file); } } $dir_file = preg_replace('/\/+/u', '/', str_replace([DIRECTORY_SEPARATOR, '\\', '/'], '/', $dir_file)); diff --git a/src/includes/traits/Shared/HttpUtils.php b/src/includes/traits/Shared/HttpUtils.php index 09e89088..d08b16f6 100644 --- a/src/includes/traits/Shared/HttpUtils.php +++ b/src/includes/traits/Shared/HttpUtils.php @@ -110,7 +110,7 @@ public function cacheableHeadersList() 'X-Powered-By', 'X-UA-Compatible', ]; - $cacheable_headers = array_map('strtolower', $cacheable_headers); + $cacheable_headers = array_map('mb_strtolower', $cacheable_headers); foreach ($headers as $_key => $_header) { $_header = mb_strtolower((string) strstr($_header, ':', true)); From 1914ea3eabf466c9addd8c61e8131ef8fdba50f7 Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Thu, 3 Mar 2016 21:14:59 -0500 Subject: [PATCH 06/11] Multibyte String Enhancements: Update `substr()` See websharks/comet-cache#703 --- src/includes/classes/Actions.php | 2 +- src/includes/classes/AdvCacheBackCompat.php | 2 +- src/includes/classes/AutoCache.php | 4 ++-- src/includes/classes/CdnFilters.php | 6 +++--- src/includes/traits/Plugin/DirUtils.php | 2 +- src/includes/traits/Shared/HookUtils.php | 8 ++++---- src/includes/traits/Shared/StringUtils.php | 8 ++++---- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/includes/classes/Actions.php b/src/includes/classes/Actions.php index 524c0ead..11e6b52e 100644 --- a/src/includes/classes/Actions.php +++ b/src/includes/classes/Actions.php @@ -749,7 +749,7 @@ protected function proUpdate($args) if (!is_object($product_api_response) || !empty($product_api_response->error) || empty($product_api_response->pro_version) || empty($product_api_response->pro_zip)) { if (!empty($product_api_response->error)) { - $error = substr((string) $product_api_response->error, 0, 1000); + $error = mb_substr((string) $product_api_response->error, 0, 1000); } else { $error = __('Unknown error. Please wait 15 minutes and try again.', SLUG_TD); } diff --git a/src/includes/classes/AdvCacheBackCompat.php b/src/includes/classes/AdvCacheBackCompat.php index b79a8c52..7f2e7dda 100644 --- a/src/includes/classes/AdvCacheBackCompat.php +++ b/src/includes/classes/AdvCacheBackCompat.php @@ -53,7 +53,7 @@ public static function zenCacheConstants() if (mb_stripos($_constant, 'ZENCACHE_') !== 0) { continue; // Nothing to do here. } - if (!($_constant_sub_name = substr($_constant, 9))) { + if (!($_constant_sub_name = mb_substr($_constant, 9))) { continue; // Nothing to do here. } if (!defined($_global_ns.'_'.$_constant_sub_name)) { diff --git a/src/includes/classes/AutoCache.php b/src/includes/classes/AutoCache.php index d58b72a8..eb8acb3f 100644 --- a/src/includes/classes/AutoCache.php +++ b/src/includes/classes/AutoCache.php @@ -196,7 +196,7 @@ protected function logAutoCacheUrl($url, $wp_remote_get_response) file_put_contents($auto_cache_log_file, $log_entry, FILE_APPEND); if (filesize($auto_cache_log_file) > 2097152) { - rename($auto_cache_log_file, substr($auto_cache_log_file, 0, -4).'-archived-'.time().'.log'); + rename($auto_cache_log_file, mb_substr($auto_cache_log_file, 0, -4).'-archived-'.time().'.log'); } $this->plugin->cacheUnlock($cache_lock); // Release. } @@ -228,7 +228,7 @@ protected function logAutoCacheRun($total_urls, $total_time) file_put_contents($auto_cache_log_file, $log_entry, FILE_APPEND); if (filesize($auto_cache_log_file) > 2097152) { - rename($auto_cache_log_file, substr($auto_cache_log_file, 0, -4).'-archived-'.time().'.log'); + rename($auto_cache_log_file, mb_substr($auto_cache_log_file, 0, -4).'-archived-'.time().'.log'); } $this->plugin->cacheUnlock($cache_lock); // Release. } diff --git a/src/includes/classes/CdnFilters.php b/src/includes/classes/CdnFilters.php index 89f890d4..41f28049 100644 --- a/src/includes/classes/CdnFilters.php +++ b/src/includes/classes/CdnFilters.php @@ -468,7 +468,7 @@ protected function localFile($url_uri_qsl) if (!isset($parsed['path'][0]) || $parsed['path'][0] !== '/') { return; // Missing or unexpected path. } - if (substr($parsed['path'], -1) === '/') { + if (mb_substr($parsed['path'], -1) === '/') { return; // Directory, not a file. } if (mb_strpos($parsed['path'], '..') !== false || mb_strpos($parsed['path'], './') !== false) { @@ -575,9 +575,9 @@ public static function defaultWhitelistedExtensions() $extensions = array_merge($extensions, ['eot', 'ttf', 'otf', 'woff']); if (($permalink_structure = get_option('permalink_structure'))) { - if (strcasecmp(substr($permalink_structure, -5), '.html') === 0) { + if (strcasecmp(mb_substr($permalink_structure, -5), '.html') === 0) { $extensions = array_diff($extensions, ['html']); - } elseif (strcasecmp(substr($permalink_structure, -4), '.htm') === 0) { + } elseif (strcasecmp(mb_substr($permalink_structure, -4), '.htm') === 0) { $extensions = array_diff($extensions, ['htm']); } } diff --git a/src/includes/traits/Plugin/DirUtils.php b/src/includes/traits/Plugin/DirUtils.php index 9dbef834..f82e3bb4 100644 --- a/src/includes/traits/Plugin/DirUtils.php +++ b/src/includes/traits/Plugin/DirUtils.php @@ -77,7 +77,7 @@ public function wpHomePath() if (!empty($home) && 0 !== strcasecmp($home, $siteurl)) { $wp_path_rel_to_home = str_ireplace($home, '', $siteurl); /* $siteurl - $home */ $pos = strripos(str_replace('\\', '/', $_SERVER['SCRIPT_FILENAME']), trailingslashit($wp_path_rel_to_home)); - $home_path = substr($_SERVER['SCRIPT_FILENAME'], 0, $pos); + $home_path = mb_substr($_SERVER['SCRIPT_FILENAME'], 0, $pos); $home_path = trailingslashit($home_path); } else { $home_path = ABSPATH; diff --git a/src/includes/traits/Shared/HookUtils.php b/src/includes/traits/Shared/HookUtils.php index dfefd520..a406fc99 100644 --- a/src/includes/traits/Shared/HookUtils.php +++ b/src/includes/traits/Shared/HookUtils.php @@ -61,7 +61,7 @@ public function addHook($hook, $function, $priority = 10, $accepted_args = 1) { $hook = (string) $hook; if (mb_stripos($hook, 'zencache') === 0) { - $hook = GLOBAL_NS.substr($hook, strlen('zencache')); + $hook = GLOBAL_NS.mb_substr($hook, strlen('zencache')); } $priority = (integer) $priority; $accepted_args = max(0, (integer) $accepted_args); @@ -129,7 +129,7 @@ public function removeHook($hook, $function, $priority = 10) { $hook = (string) $hook; if (mb_stripos($hook, 'zencache') === 0) { - $hook = GLOBAL_NS.substr($hook, strlen('zencache')); + $hook = GLOBAL_NS.mb_substr($hook, strlen('zencache')); } $priority = (integer) $priority; $hook_id = $this->hookId($function); @@ -245,7 +245,7 @@ public function doWpAction($hook) call_user_func_array('do_action', $args); if (mb_stripos($hook, GLOBAL_NS) === 0) { - $zencache_filter = 'zencache'.substr($hook, strlen(GLOBAL_NS)); + $zencache_filter = 'zencache'.mb_substr($hook, strlen(GLOBAL_NS)); $zencache_args = $args; // Use a copy of the args. $zencache_args[0] = $zencache_filter; call_user_func_array('do_action', $zencache_args); @@ -268,7 +268,7 @@ public function applyWpFilters($hook) $value = call_user_func_array('apply_filters', $args); if (mb_stripos($hook, GLOBAL_NS) === 0) { - $zencache_hook = 'zencache'.substr($hook, strlen(GLOBAL_NS)); + $zencache_hook = 'zencache'.mb_substr($hook, strlen(GLOBAL_NS)); $zencache_args = $args; // Use a copy of the args. $zencache_args[0] = $zencache_hook; $zencache_args[1] = $value; // Filtered value. diff --git a/src/includes/traits/Shared/StringUtils.php b/src/includes/traits/Shared/StringUtils.php index 7a04ebb1..fdd6df17 100644 --- a/src/includes/traits/Shared/StringUtils.php +++ b/src/includes/traits/Shared/StringUtils.php @@ -36,9 +36,9 @@ public function clip($value, $max_length = 80, $force_ellipsis = false) $string = trim($string); // Trim it up now. if (strlen($string) > $max_length) { - $string = (string) substr($string, 0, $max_length - 3).'...'; + $string = (string) mb_substr($string, 0, $max_length - 3).'...'; } elseif ($force_ellipsis && strlen($string) + 3 > $max_length) { - $string = (string) substr($string, 0, $max_length - 3).'...'; + $string = (string) mb_substr($string, 0, $max_length - 3).'...'; } else { $string .= $force_ellipsis ? '...' : ''; } @@ -82,12 +82,12 @@ public function midClip($value, $max_length = 80) $first_clip = $half_max_length - 3; $string = $first_clip >= 1 // Something? - ? substr($full_string, 0, $first_clip).'...' + ? mb_substr($full_string, 0, $first_clip).'...' : '...'; // Ellipsis only. $second_clip = strlen($full_string) - ($max_length - strlen($string)); $string .= $second_clip >= 0 && $second_clip >= $first_clip - ? substr($full_string, $second_clip) : ''; + ? mb_substr($full_string, $second_clip) : ''; return $string; } From c400d172a300895a241460efea3b96b8e0fbdf85 Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Thu, 3 Mar 2016 21:20:55 -0500 Subject: [PATCH 07/11] Multibyte String Enhancements: Update `strlen()` See websharks/comet-cache#703 --- src/includes/traits/Shared/CachePathUtils.php | 2 +- src/includes/traits/Shared/HookUtils.php | 8 ++++---- src/includes/traits/Shared/ReplaceUtils.php | 2 +- src/includes/traits/Shared/StringUtils.php | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/includes/traits/Shared/CachePathUtils.php b/src/includes/traits/Shared/CachePathUtils.php index 7973ba0b..f040004a 100644 --- a/src/includes/traits/Shared/CachePathUtils.php +++ b/src/includes/traits/Shared/CachePathUtils.php @@ -133,7 +133,7 @@ public function buildCachePath($url, $with_user_token = '', $with_version_salt = $url_parts['path'] = '/lp-'.sha1($url_parts['path']).'/'; } } // Now add the path and check for a possible root `index/` suffix. - if (!empty($url_parts['path']) && strlen($url_parts['path'] = trim($url_parts['path'], '\\/'." \t\n\r\0\x0B"))) { + if (!empty($url_parts['path']) && mb_strlen($url_parts['path'] = trim($url_parts['path'], '\\/'." \t\n\r\0\x0B"))) { $cache_path .= $url_parts['path'].'/'; // Add the path as it exists. if (!($flags & $this::CACHE_PATH_NO_PATH_INDEX) && $is_multisite && $is_a_multisite_base_dir_root) { diff --git a/src/includes/traits/Shared/HookUtils.php b/src/includes/traits/Shared/HookUtils.php index a406fc99..779c8f97 100644 --- a/src/includes/traits/Shared/HookUtils.php +++ b/src/includes/traits/Shared/HookUtils.php @@ -61,7 +61,7 @@ public function addHook($hook, $function, $priority = 10, $accepted_args = 1) { $hook = (string) $hook; if (mb_stripos($hook, 'zencache') === 0) { - $hook = GLOBAL_NS.mb_substr($hook, strlen('zencache')); + $hook = GLOBAL_NS.mb_substr($hook, mb_strlen('zencache')); } $priority = (integer) $priority; $accepted_args = max(0, (integer) $accepted_args); @@ -129,7 +129,7 @@ public function removeHook($hook, $function, $priority = 10) { $hook = (string) $hook; if (mb_stripos($hook, 'zencache') === 0) { - $hook = GLOBAL_NS.mb_substr($hook, strlen('zencache')); + $hook = GLOBAL_NS.mb_substr($hook, mb_strlen('zencache')); } $priority = (integer) $priority; $hook_id = $this->hookId($function); @@ -245,7 +245,7 @@ public function doWpAction($hook) call_user_func_array('do_action', $args); if (mb_stripos($hook, GLOBAL_NS) === 0) { - $zencache_filter = 'zencache'.mb_substr($hook, strlen(GLOBAL_NS)); + $zencache_filter = 'zencache'.mb_substr($hook, mb_strlen(GLOBAL_NS)); $zencache_args = $args; // Use a copy of the args. $zencache_args[0] = $zencache_filter; call_user_func_array('do_action', $zencache_args); @@ -268,7 +268,7 @@ public function applyWpFilters($hook) $value = call_user_func_array('apply_filters', $args); if (mb_stripos($hook, GLOBAL_NS) === 0) { - $zencache_hook = 'zencache'.mb_substr($hook, strlen(GLOBAL_NS)); + $zencache_hook = 'zencache'.mb_substr($hook, mb_strlen(GLOBAL_NS)); $zencache_args = $args; // Use a copy of the args. $zencache_args[0] = $zencache_hook; $zencache_args[1] = $value; // Filtered value. diff --git a/src/includes/traits/Shared/ReplaceUtils.php b/src/includes/traits/Shared/ReplaceUtils.php index c6a7b689..0f320a4d 100644 --- a/src/includes/traits/Shared/ReplaceUtils.php +++ b/src/includes/traits/Shared/ReplaceUtils.php @@ -28,7 +28,7 @@ public function strReplaceOnce($needle, $replace, $haystack, $caSe_insensitive = if (($needle_strpos = $caSe_mb_strpos($haystack, $needle)) === false) { return $haystack; // Nothing to replace. } - return (string) substr_replace($haystack, $replace, $needle_strpos, strlen($needle)); + return (string) substr_replace($haystack, $replace, $needle_strpos, mb_strlen($needle)); } /** diff --git a/src/includes/traits/Shared/StringUtils.php b/src/includes/traits/Shared/StringUtils.php index fdd6df17..d676ca13 100644 --- a/src/includes/traits/Shared/StringUtils.php +++ b/src/includes/traits/Shared/StringUtils.php @@ -35,9 +35,9 @@ public function clip($value, $max_length = 80, $force_ellipsis = false) $string = preg_replace('/\s+/u', ' ', strip_tags($string)); $string = trim($string); // Trim it up now. - if (strlen($string) > $max_length) { + if (mb_strlen($string) > $max_length) { $string = (string) mb_substr($string, 0, $max_length - 3).'...'; - } elseif ($force_ellipsis && strlen($string) + 3 > $max_length) { + } elseif ($force_ellipsis && mb_strlen($string) + 3 > $max_length) { $string = (string) mb_substr($string, 0, $max_length - 3).'...'; } else { $string .= $force_ellipsis ? '...' : ''; @@ -74,7 +74,7 @@ public function midClip($value, $max_length = 80) $string = preg_replace('/\s+/u', ' ', strip_tags($string)); $string = trim($string); // Trim it up now. - if (strlen($string) <= $max_length) { + if (mb_strlen($string) <= $max_length) { return $string; // Nothing to do. } $full_string = $string; @@ -85,7 +85,7 @@ public function midClip($value, $max_length = 80) ? mb_substr($full_string, 0, $first_clip).'...' : '...'; // Ellipsis only. - $second_clip = strlen($full_string) - ($max_length - strlen($string)); + $second_clip = mb_strlen($full_string) - ($max_length - mb_strlen($string)); $string .= $second_clip >= 0 && $second_clip >= $first_clip ? mb_substr($full_string, $second_clip) : ''; From 0865b8d9ab8d58c5a50cad42e112fd53bcead7c1 Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Wed, 11 May 2016 14:05:33 -0400 Subject: [PATCH 08/11] Fix misspelled mb_mb_strtolower() See websharks/comet-cache#703 --- src/includes/traits/Shared/CachePathUtils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/includes/traits/Shared/CachePathUtils.php b/src/includes/traits/Shared/CachePathUtils.php index f040004a..25b4d4e0 100644 --- a/src/includes/traits/Shared/CachePathUtils.php +++ b/src/includes/traits/Shared/CachePathUtils.php @@ -146,7 +146,7 @@ public function buildCachePath($url, $with_user_token = '', $with_version_salt = } } if ($this->isExtensionLoaded('mbstring') && mb_check_encoding($cache_path, 'UTF-8')) { - $cache_path = mb_mb_strtolower($cache_path, 'UTF-8'); + $cache_path = mb_strtolower($cache_path, 'UTF-8'); } $cache_path = str_replace('.', '-', mb_strtolower($cache_path)); From b3d2b1032ed449a006d8e48fe9b502c8844b226b Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Wed, 11 May 2016 14:35:11 -0400 Subject: [PATCH 09/11] Add mbstring to extensions required by WP PHP RV See websharks/comet-cache#703 --- plugin.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin.php b/plugin.php index d50cc237..1163a224 100644 --- a/plugin.php +++ b/plugin.php @@ -2,7 +2,8 @@ if (!defined('WPINC')) { exit('Do NOT access this file directly: '.basename(__FILE__)); } -$GLOBALS['wp_php_rv'] = '5.3.2'; //php-required-version// // Leaving this at v5.3.2 so that we can have more control over Dashboard messages below. +$GLOBALS['wp_php_rv']['rv'] = '5.3.2'; //php-required-version// // Leaving this at v5.3.2 so that we can have more control over Dashboard messages below. +$GLOBALS['wp_php_rv']['re'] = array('mbstring'); if (require(__DIR__.'/src/vendor/websharks/wp-php-rv/src/includes/check.php')) { if (!empty($_REQUEST['comet_cache_mbstring_deprecated_warning_bypass']) && is_admin()) { From edadf24ad6d0d30c6cc2ec3c70da8226ed4e3b46 Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Tue, 7 Jun 2016 16:36:46 -0400 Subject: [PATCH 10/11] Multibyte String Enhancements See websharks/comet-cache#703 --- src/includes/classes/MenuPageOptions.php | 4 ++-- src/includes/templates/ac-plugin.txt | 4 ++-- src/includes/traits/Plugin/DirUtils.php | 2 +- src/includes/traits/Plugin/InstallUtils.php | 19 +++++++++---------- src/includes/traits/Shared/CacheDirUtils.php | 10 +++++----- src/includes/traits/Shared/ReplaceUtils.php | 6 ++++++ 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/includes/classes/MenuPageOptions.php b/src/includes/classes/MenuPageOptions.php index 62ebade1..76baa157 100644 --- a/src/includes/classes/MenuPageOptions.php +++ b/src/includes/classes/MenuPageOptions.php @@ -164,7 +164,7 @@ public function __construct() if (!empty($_REQUEST[GLOBAL_NS.'_advanced_cache_add_failure'])) { echo '
'."\n"; if ($_REQUEST[GLOBAL_NS.'_advanced_cache_add_failure'] === 'advanced-cache') { - echo ' '.sprintf(__('Failed to update your /wp-content/advanced-cache.php file. Cannot write file: %1$s/%2$s-advanced-cache. Please be sure this directory exists (and that it\'s writable): %1$s. Please use directory permissions 755 or higher (perhaps 777). Once you\'ve done this, please try again.', SLUG_TD), esc_html($this->plugin->cacheDir()), esc_html(strtolower(SHORT_NAME)))."\n"; + echo ' '.sprintf(__('Failed to update your /wp-content/advanced-cache.php file. Cannot write file: %1$s/%2$s-advanced-cache. Please be sure this directory exists (and that it\'s writable): %1$s. Please use directory permissions 755 or higher (perhaps 777). Once you\'ve done this, please try again.', SLUG_TD), esc_html($this->plugin->cacheDir()), esc_html(mb_strtolower(SHORT_NAME)))."\n"; } else { echo ' '.__('Failed to update your /wp-content/advanced-cache.php file. Most likely a permissions error. Please create an empty file here: /wp-content/advanced-cache.php (just an empty PHP file, with nothing in it); give it permissions 644 or higher (perhaps 666). Once you\'ve done this, please try again.', SLUG_TD)."\n"; } @@ -573,7 +573,7 @@ public function __construct() echo '

'."\n"; echo '

'.__('Tip: Setting this to No is highly recommended when running a membership plugin like s2Member (as one example). In fact, many plugins like s2Member will send nocache_headers() on their own, so your configuration here will likely be overwritten when you run such plugins (which is better anyway). In short, if you run a membership plugin, you should NOT allow a client-side browser cache.', SLUG_TD).'

'."\n"; echo '

'.__('Tip: Setting this to No will NOT impact static content; e.g., CSS, JS, images, or other media. This setting pertains only to dynamic PHP scripts which produce content generated by WordPress.', SLUG_TD).'

'."\n"; - echo '

'.sprintf(__('Advanced Tip: if you have this set to No, but you DO want to allow a few special URLs to be cached by the browser; you can add this parameter to your URL ?%2$sABC=1. This tells %1$s that it\'s OK for the browser to cache that particular URL. In other words, the %2$sABC=1 parameter tells %1$s NOT to send no-cache headers to the browser.', SLUG_TD), esc_html(NAME), esc_html(strtolower(SHORT_NAME))).'

'."\n"; + echo '

'.sprintf(__('Advanced Tip: if you have this set to No, but you DO want to allow a few special URLs to be cached by the browser; you can add this parameter to your URL ?%2$sABC=1. This tells %1$s that it\'s OK for the browser to cache that particular URL. In other words, the %2$sABC=1 parameter tells %1$s NOT to send no-cache headers to the browser.', SLUG_TD), esc_html(NAME), esc_html(mb_strtolower(SHORT_NAME))).'

'."\n"; echo '
'."\n"; echo '
'."\n"; echo '

'.__('Exclusion Patterns for Client-Side Caching', SLUG_TD).'

'."\n"; diff --git a/src/includes/templates/ac-plugin.txt b/src/includes/templates/ac-plugin.txt index fab100b5..9eaa1b4b 100644 --- a/src/includes/templates/ac-plugin.txt +++ b/src/includes/templates/ac-plugin.txt @@ -15,9 +15,9 @@ function my_ac_plugin() // Example plugin. } function my_ac_version_salt_shaker($version_salt) { - if (stripos($_SERVER['HTTP_USER_AGENT'], 'iphone') !== false) { + if (mb_stripos($_SERVER['HTTP_USER_AGENT'], 'iphone') !== false) { $version_salt .= 'iphones'; // Give iPhones their own variation of the cache. - } elseif (stripos($_SERVER['HTTP_USER_AGENT'], 'android') !== false) { + } elseif (mb_stripos($_SERVER['HTTP_USER_AGENT'], 'android') !== false) { $version_salt .= 'androids'; // Androic variation. } else { $version_salt .= 'other'; // A default group. diff --git a/src/includes/traits/Plugin/DirUtils.php b/src/includes/traits/Plugin/DirUtils.php index 0b41a76f..353929ea 100644 --- a/src/includes/traits/Plugin/DirUtils.php +++ b/src/includes/traits/Plugin/DirUtils.php @@ -75,7 +75,7 @@ public function wpHomePath() $home = set_url_scheme(get_option('home'), 'http'); $siteurl = set_url_scheme(get_option('siteurl'), 'http'); if (!empty($home) && 0 !== strcasecmp($home, $siteurl) && !empty($_SERVER['SCRIPT_FILENAME'])) { - $wp_path_rel_to_home = str_ireplace($home, '', $siteurl); /* $siteurl - $home */ + $wp_path_rel_to_home = preg_replace('/'.preg_quote($home, '/').'/ui', '', $siteurl); /* $siteurl - $home */ $pos = strripos(str_replace('\\', '/', $_SERVER['SCRIPT_FILENAME']), trailingslashit($wp_path_rel_to_home)); $home_path = mb_substr($_SERVER['SCRIPT_FILENAME'], 0, $pos); $home_path = trailingslashit($home_path); diff --git a/src/includes/traits/Plugin/InstallUtils.php b/src/includes/traits/Plugin/InstallUtils.php index 2fcb3c39..41960549 100644 --- a/src/includes/traits/Plugin/InstallUtils.php +++ b/src/includes/traits/Plugin/InstallUtils.php @@ -343,15 +343,14 @@ public function addAdvancedCache() $_value = "'".$this->escSq($_value)."'"; break; // Break switch handler. } - $advanced_cache_contents = // Fill replacement codes. - str_ireplace( - [ - "'%%".GLOBAL_NS.'_'.$_option."%%'", - "'%%".GLOBAL_NS.'_'.preg_replace('/^cache_/ui', '', $_option)."%%'", - ], - $_value, - $advanced_cache_contents - ); + $advanced_cache_contents = preg_replace( + [ + '/'.preg_quote("'%%".GLOBAL_NS.'_'.$_option."%%'", '/').'/ui', + '/'.preq_quote("'%%".GLOBAL_NS.'_'.preg_replace('/^cache_/ui', '', $_option)."%%'", '/').'/ui', + ], + $_value, + $advanced_cache_contents + ); } unset($_option, $_value, $_values, $_response); // Housekeeping. @@ -361,7 +360,7 @@ public function addAdvancedCache() $plugin_file = "'".$this->escSq(PLUGIN_FILE)."'"; // Full absolute path. } // Make it possible for the `advanced-cache.php` handler to find the plugin directory reliably. - $advanced_cache_contents = str_ireplace("'%%".GLOBAL_NS."_PLUGIN_FILE%%'", $plugin_file, $advanced_cache_contents); + $advanced_cache_contents = preg_replace('/'.preg_quote("'%%".GLOBAL_NS."_PLUGIN_FILE%%'", '/').'/ui', $plugin_file, $advanced_cache_contents); // Ignore; this is created by Comet Cache; and we don't need to obey in this case. #if(defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) diff --git a/src/includes/traits/Shared/CacheDirUtils.php b/src/includes/traits/Shared/CacheDirUtils.php index d0a98c07..eb95f6d1 100644 --- a/src/includes/traits/Shared/CacheDirUtils.php +++ b/src/includes/traits/Shared/CacheDirUtils.php @@ -142,7 +142,7 @@ public function deleteFilesFromCacheDir($regex, $check_max_age = false) $cache_dir_tmp_regex = $regex; // Initialize host-specific regex pattern for the tmp directory. $cache_dir_tmp_regex = '\\/'.ltrim($cache_dir_tmp_regex, '^\\/'); // Make sure it begins with an escaped `/`. - $cache_dir_tmp_regex = $this->strIreplaceOnce(preg_quote($cache_dir.'/', '/'), '', $cache_dir_tmp_regex); + $cache_dir_tmp_regex = preg_replace('/'.preg_quote(preg_quote($cache_dir.'/', '/'), '/').'/ui', '', $cache_dir_tmp_regex, 1); $cache_dir_tmp_regex = ltrim($cache_dir_tmp_regex, '^\\/'); if (mb_strpos($cache_dir_tmp_regex, '(?:\/') === 0 || mb_strpos($cache_dir_tmp_regex, '(\/') === 0) { @@ -150,7 +150,7 @@ public function deleteFilesFromCacheDir($regex, $check_max_age = false) } else { $cache_dir_tmp_regex = '/^'.preg_quote($cache_dir_tmp.'/', '/').$cache_dir_tmp_regex; } - # if(WP_DEBUG) file_put_contents(WP_CONTENT_DIR.'/'.strtolower(SHORT_NAME).'-debug.log', print_r($regex, TRUE)."\n".print_r($cache_dir_tmp_regex, TRUE)."\n\n", FILE_APPEND); + # if(WP_DEBUG) file_put_contents(WP_CONTENT_DIR.'/'.mb_strtolower(SHORT_NAME).'-debug.log', print_r($regex, TRUE)."\n".print_r($cache_dir_tmp_regex, TRUE)."\n\n", FILE_APPEND); // Uncomment the above line to debug regex pattern matching used by this routine; and others that call upon it. if (!rename($cache_dir, $cache_dir_tmp)) { @@ -307,8 +307,8 @@ public function deleteFilesFromHostCacheDir( $_host_cache_dir_tmp_regex = $regex; // Initialize host-specific regex pattern for the tmp directory. $_host_cache_dir_tmp_regex = '\\/'.ltrim($_host_cache_dir_tmp_regex, '^\\/'); // Make sure it begins with an escaped `/`. - $_host_cache_dir_tmp_regex = $this->strIreplaceOnce(preg_quote($_host_cache_path.'/', '/'), '', $_host_cache_dir_tmp_regex); - $_host_cache_dir_tmp_regex = $this->strIreplaceOnce(preg_quote($_host_cache_dir.'/', '/'), '', $_host_cache_dir_tmp_regex); + $_host_cache_dir_tmp_regex = preg_replace('/'.preg_quote(preg_quote($_host_cache_path.'/', '/'), '/').'/ui', '', $_host_cache_dir_tmp_regex, 1); + $_host_cache_dir_tmp_regex = preg_replace('/'.preg_quote(preg_quote($_host_cache_dir.'/', '/'), '/').'/ui', '', $_host_cache_dir_tmp_regex, 1); $_host_cache_dir_tmp_regex = ltrim($_host_cache_dir_tmp_regex, '^\\/'); if (mb_strpos($_host_cache_dir_tmp_regex, '(?:\/') === 0 || mb_strpos($_host_cache_dir_tmp_regex, '(\/') === 0) { @@ -316,7 +316,7 @@ public function deleteFilesFromHostCacheDir( } else { $_host_cache_dir_tmp_regex = '/^'.preg_quote($_host_cache_dir_tmp.'/', '/').$_host_cache_dir_tmp_regex; } - #if(WP_DEBUG) file_put_contents(WP_CONTENT_DIR.'/'.strtolower(SHORT_NAME).'-debug.log', print_r($regex, TRUE)."\n".print_r($_host_cache_dir_tmp_regex, TRUE)."\n\n", FILE_APPEND); + #if(WP_DEBUG) file_put_contents(WP_CONTENT_DIR.'/'.mb_strtolower(SHORT_NAME).'-debug.log', print_r($regex, TRUE)."\n".print_r($_host_cache_dir_tmp_regex, TRUE)."\n\n", FILE_APPEND); // Uncomment the above line to debug regex pattern matching used by this routine; and others that call upon it. if (!rename($_host_cache_dir, $_host_cache_dir_tmp)) { diff --git a/src/includes/traits/Shared/ReplaceUtils.php b/src/includes/traits/Shared/ReplaceUtils.php index 0f320a4d..33bf315c 100644 --- a/src/includes/traits/Shared/ReplaceUtils.php +++ b/src/includes/traits/Shared/ReplaceUtils.php @@ -8,6 +8,9 @@ trait ReplaceUtils /** * String replace ONE time. * + * @deprecated Deprecated since v16xxxx + * @deprecated Replaced with Multibyte String support; see https://github.com/websharks/comet-cache/issues/703 + * * @since 150422 Rewrite. * * @param string $needle A string to search/replace. @@ -34,6 +37,9 @@ public function strReplaceOnce($needle, $replace, $haystack, $caSe_insensitive = /** * String replace ONE time (caSe-insensitive). * + * @deprecated Deprecated since v16xxxx + * @deprecated Replaced with Multibyte String support; see https://github.com/websharks/comet-cache/issues/703 + * * @since 150422 Rewrite. * * @param string $needle A string to search/replace. From e1f5423ee77d90853f4c8a515babad06feea8b6f Mon Sep 17 00:00:00 2001 From: Raam Dev Date: Tue, 7 Jun 2016 17:13:43 -0400 Subject: [PATCH 11/11] Multibyte String Enhancements See websharks/comet-cache#703 --- src/includes/traits/Plugin/InstallUtils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/includes/traits/Plugin/InstallUtils.php b/src/includes/traits/Plugin/InstallUtils.php index 41960549..d2b79213 100644 --- a/src/includes/traits/Plugin/InstallUtils.php +++ b/src/includes/traits/Plugin/InstallUtils.php @@ -346,7 +346,7 @@ public function addAdvancedCache() $advanced_cache_contents = preg_replace( [ '/'.preg_quote("'%%".GLOBAL_NS.'_'.$_option."%%'", '/').'/ui', - '/'.preq_quote("'%%".GLOBAL_NS.'_'.preg_replace('/^cache_/ui', '', $_option)."%%'", '/').'/ui', + '/'.preg_quote("'%%".GLOBAL_NS.'_'.preg_replace('/^cache_/ui', '', $_option)."%%'", '/').'/ui', ], $_value, $advanced_cache_contents