Skip to content

Commit

Permalink
Multibyte String Enhancements: Update substr()
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Mar 4, 2016
1 parent de3bd92 commit 1914ea3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/includes/classes/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
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 @@ -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)) {
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 @@ -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.
}
Expand Down Expand Up @@ -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.
}
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 @@ -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) {
Expand Down Expand Up @@ -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']);
}
}
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 @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/includes/traits/Shared/HookUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/includes/traits/Shared/StringUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? '...' : '';
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 1914ea3

Please sign in to comment.