Skip to content

Commit

Permalink
Multibyte String Enhancements: Update strpos() and stripos()
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Mar 4, 2016
1 parent e6aa315 commit ea4d0b3
Show file tree
Hide file tree
Showing 27 changed files with 63 additions and 63 deletions.
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/includes/classes/AdvCacheBackCompat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down
2 changes: 1 addition & 1 deletion src/includes/classes/AutoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/includes/classes/CdnFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions src/includes/classes/FeedUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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), '/').')';
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/includes/classes/MenuPageOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,9 @@ public function __construct()
echo ' <p style="'.($_sys_getloadavg_unavailable ? 'opacity: 0.5;' : '').'">'.sprintf(__('If you have high traffic at certain times of the day, %1$s can be told to check the current load average via <a href="http://cometcache.com/r/system-load-average-via-php/" target="_blank"><code>sys_getloadavg()</code></a>. 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)).'</p>'."\n";
echo ' <p style="'.($_sys_getloadavg_unavailable ? 'opacity: 0.5;' : '').'">'.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 <code>top</code> 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., <code>1.05</code> might be a high load average for a server with one CPU. See also: <a href="http://cometcache.com/r/understanding-load-average/" target="_blank">Understanding Load Average</a>', SLUG_TD), esc_html(NAME)).'</p>'."\n";
echo ' <p><input '.($_sys_getloadavg_unavailable ? 'disabled' : '').' type="text" name="'.esc_attr(GLOBAL_NS).'[saveOptions][cache_max_age_disable_if_load_average_is_gte]" value="'.esc_attr($this->plugin->options['cache_max_age_disable_if_load_average_is_gte']).'" /></p>'."\n";
if ($_sys_getloadavg_unavailable && stripos(PHP_OS, 'win') === 0) { // See: <http://jas.xyz/1HZsZ9v>
if ($_sys_getloadavg_unavailable && mb_stripos(PHP_OS, 'win') === 0) { // See: <http://jas.xyz/1HZsZ9v>
echo ' <p class="warning">'.__('<strong>Note:</strong> It appears that your server is running Windows. The <code>sys_getloadavg()</code> function has not been implemented in PHP for Windows servers yet.', SLUG_TD).'</p>'."\n";
} elseif ($_sys_getloadavg_unavailable && stripos(PHP_OS, 'win') !== 0) {
} elseif ($_sys_getloadavg_unavailable && mb_stripos(PHP_OS, 'win') !== 0) {
echo ' <p class="warning">'.__('<strong>Note:</strong> <code>sys_getloadavg()</code> has been disabled by your web hosting company or is not available on your server.', SLUG_TD).'</p>'."\n";
}
echo ' </div>'."\n";
Expand Down
12 changes: 6 additions & 6 deletions src/includes/classes/VsUpgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
4 changes: 2 additions & 2 deletions src/includes/traits/Ac/ObUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
Expand Down Expand Up @@ -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, '<body id="error-page">') !== false) {
if (mb_stripos($cache, '<body id="error-page">') !== false) {
return (boolean) $this->maybeSetDebugInfo($this::NC_DEBUG_WP_ERROR_PAGE);
}
if (!$this->hasACacheableContentType()) {
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Ac/PostloadUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/includes/traits/Plugin/AutoCacheUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= '<br /><em>'.__('Note: Most timeout errors are resolved by refreshing the page and trying again. If timeout errors persist, please see <a href="http://cometcache.com/r/kb-article-why-am-i-seeing-a-timeout-error/" target="_blank">this article</a>.', SLUG_TD).'</em>';
}
} elseif (empty($head['response']['code']) || (int) $head['response']['code'] >= 400) {
$failure = sprintf(__('HEAD response code (<code>%1$s</code>) 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 (<code>%1$s</code>) indicates an error.', SLUG_TD), esc_html((string) @$head['headers']['content-type']));
}
if ($failure) { // Failure encountered above?
Expand Down
4 changes: 2 additions & 2 deletions src/includes/traits/Plugin/HtaccessUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/includes/traits/Plugin/InstallUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/includes/traits/Plugin/MenuPageUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/OptionUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/WcpPostUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/WcpTermUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/WcpUrlUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit ea4d0b3

Please sign in to comment.