Skip to content

Commit

Permalink
Multibyte String Enhancements: Update strlen()
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Mar 4, 2016
1 parent 1914ea3 commit c400d17
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/includes/traits/Shared/CachePathUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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.mb_substr($hook, strlen('zencache'));
$hook = GLOBAL_NS.mb_substr($hook, mb_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.mb_substr($hook, strlen('zencache'));
$hook = GLOBAL_NS.mb_substr($hook, mb_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'.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);
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'.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.
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Shared/ReplaceUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
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 @@ -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 ? '...' : '';
Expand Down Expand Up @@ -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;
Expand All @@ -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) : '';

Expand Down

0 comments on commit c400d17

Please sign in to comment.