Skip to content

Commit

Permalink
Multibyte String Enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Jun 7, 2016
1 parent 2d2a5e5 commit edadf24
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/includes/classes/MenuPageOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,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 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 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 @@ -573,7 +573,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 ' <hr />'."\n";
echo ' <div class="plugin-menu-page-panel-if-enabled -client-side-cache-options">'."\n";
echo ' <h3>'.__('Exclusion Patterns for Client-Side Caching', SLUG_TD).'</h3>'."\n";
Expand Down
4 changes: 2 additions & 2 deletions src/includes/templates/ac-plugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/DirUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 9 additions & 10 deletions src/includes/traits/Plugin/InstallUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/includes/traits/Shared/CacheDirUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ 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) {
$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;
}
# 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)) {
Expand Down Expand Up @@ -307,16 +307,16 @@ 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) {
$_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;
}
#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)) {
Expand Down
6 changes: 6 additions & 0 deletions src/includes/traits/Shared/ReplaceUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit edadf24

Please # to comment.