Skip to content

Commit

Permalink
Multibyte String Enhancements: Update strtolower() and strtoupper()
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Mar 4, 2016
1 parent ea4d0b3 commit e013ea8
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions src/includes/classes/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
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 @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/includes/classes/AutoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
28 changes: 14 additions & 14 deletions src/includes/classes/CdnFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -158,23 +158,23 @@ 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);

// Blacklisted extensions; if applicable.

$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.

$this->cdn_blacklisted_extensions = array_unique($this->cdn_blacklisted_extensions);

// 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);

Expand All @@ -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.

Expand Down Expand Up @@ -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] !== '/') {
Expand All @@ -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'];
Expand Down Expand Up @@ -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), '.'), '.'));
}

/**
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
}
}
Expand All @@ -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'))) {
Expand Down
2 changes: 1 addition & 1 deletion src/includes/classes/Conflicts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions src/includes/classes/MenuPageOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function __construct()
if (!empty($_REQUEST[GLOBAL_NS.'_advanced_cache_add_failure'])) {
echo '<div class="plugin-menu-page-notice error">'."\n";
if ($_REQUEST[GLOBAL_NS.'_advanced_cache_add_failure'] === 'advanced-cache') {
echo '<i class="si si-thumbs-down"></i> '.sprintf(__('Failed to update your <code>/wp-content/advanced-cache.php</code> file. Cannot write stat file: <code>%1$s/%2$s-advanced-cache</code>. Please be sure this directory exists (and that it\'s writable): <code>%1$s</code>. Please use directory permissions <code>755</code> or higher (perhaps <code>777</code>). Once you\'ve done this, please try again.', SLUG_TD), esc_html($this->plugin->cacheDir()), esc_html(strtolower(SHORT_NAME)))."\n";
echo '<i class="si si-thumbs-down"></i> '.sprintf(__('Failed to update your <code>/wp-content/advanced-cache.php</code> file. Cannot write stat file: <code>%1$s/%2$s-advanced-cache</code>. Please be sure this directory exists (and that it\'s writable): <code>%1$s</code>. Please use directory permissions <code>755</code> or higher (perhaps <code>777</code>). Once you\'ve done this, please try again.', SLUG_TD), esc_html($this->plugin->cacheDir()), esc_html(mb_strtolower(SHORT_NAME)))."\n";
} else {
echo '<i class="si si-thumbs-down"></i> '.__('Failed to update your <code>/wp-content/advanced-cache.php</code> file. Most likely a permissions error. Please create an empty file here: <code>/wp-content/advanced-cache.php</code> (just an empty PHP file, with nothing in it); give it permissions <code>644</code> or higher (perhaps <code>666</code>). Once you\'ve done this, please try again.', SLUG_TD)."\n";
}
Expand Down Expand Up @@ -569,7 +569,7 @@ public function __construct()
echo ' </select></p>'."\n";
echo ' <p class="info">'.__('<strong>Tip:</strong> Setting this to <code>No</code> is highly recommended when running a membership plugin like <a href="http://wordpress.org/plugins/s2member/" target="_blank">s2Member</a> (as one example). In fact, many plugins like s2Member will send <a href="http://codex.wordpress.org/Function_Reference/nocache_headers" target="_blank">nocache_headers()</a> 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).'</p>'."\n";
echo ' <p class="info">'.__('<strong>Tip:</strong> Setting this to <code>No</code> 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).'</p>'."\n";
echo ' <p class="info">'.sprintf(__('<strong>Advanced Tip:</strong> if you have this set to <code>No</code>, but you DO want to allow a few special URLs to be cached by the browser; you can add this parameter to your URL <code>?%2$sABC=1</code>. This tells %1$s that it\'s OK for the browser to cache that particular URL. In other words, the <code>%2$sABC=1</code> parameter tells %1$s NOT to send no-cache headers to the browser.', SLUG_TD), esc_html(NAME), esc_html(strtolower(SHORT_NAME))).'</p>'."\n";
echo ' <p class="info">'.sprintf(__('<strong>Advanced Tip:</strong> if you have this set to <code>No</code>, but you DO want to allow a few special URLs to be cached by the browser; you can add this parameter to your URL <code>?%2$sABC=1</code>. This tells %1$s that it\'s OK for the browser to cache that particular URL. In other words, the <code>%2$sABC=1</code> parameter tells %1$s NOT to send no-cache headers to the browser.', SLUG_TD), esc_html(NAME), esc_html(mb_strtolower(SHORT_NAME))).'</p>'."\n";
echo ' <h3>'.__('Exclusion Patterns for Client-Side Caching', SLUG_TD).'</h3>'."\n";
echo ' <p>'.__('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 <a href="https://gist.github.com/jaswsinc/338b6eb03a36c048c26f" target="_blank" style="text-decoration:none;"><code>REQUEST_URI</code></a>; i.e., <code>/path/?query</code> (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 <code>*</code> character can also be used when necessary; e.g., <code>/category/abc-followed-by-*</code> (where <code>*</code> = 0 or more characters that are NOT a slash <code>/</code>). Other special characters include: <code>**</code> = 0 or more characters of any kind, including <code>/</code> slashes; <code>^</code> = beginning of the string; <code>$</code> = end of the string. To learn more about this syntax, please see <a href ="http://cometcache.com/r/watered-down-regex-syntax/" target="_blank">this KB article</a>.', SLUG_TD).'</p>'."\n";
echo ' <p><textarea name="'.esc_attr(GLOBAL_NS).'[saveOptions][exclude_client_side_uris]" rows="5" spellcheck="false" class="monospace">'.format_to_edit($this->plugin->options['exclude_client_side_uris']).'</textarea></p>'."\n";
Expand Down Expand Up @@ -636,7 +636,7 @@ public function __construct()
echo ' <option value="1"'.selected($this->plugin->options['get_requests'], '1', false).'>'.__('Yes, I would like to cache URLs that contain a query string.', SLUG_TD).'</option>'."\n";
echo ' </select></p>'."\n";
echo ' <p class="info">'.__('<strong>Note:</strong> POST requests (i.e., forms with <code>method=&quot;post&quot;</code>) are always excluded from the cache, which is the way it should be. Any <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html" target="_blank">POST/PUT/DELETE</a> 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).'</p>'."\n";
echo ' <p class="info">'.sprintf(__('<strong>Advanced Tip:</strong> 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 <code>?%2$sAC=1</code>. 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 <code>?%2$sAC=0</code>.', SLUG_TD), esc_html(NAME), esc_html(strtolower(SHORT_NAME))).'</p>'."\n";
echo ' <p class="info">'.sprintf(__('<strong>Advanced Tip:</strong> 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 <code>?%2$sAC=1</code>. 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 <code>?%2$sAC=0</code>.', SLUG_TD), esc_html(NAME), esc_html(mb_strtolower(SHORT_NAME))).'</p>'."\n";
echo ' </div>'."\n";

echo '</div>'."\n";
Expand Down
2 changes: 1 addition & 1 deletion src/includes/stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 4 additions & 4 deletions src/includes/traits/Ac/BrowserUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Ac/NcDebugUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Ac/ObUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/AdminBarUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
Loading

0 comments on commit e013ea8

Please sign in to comment.