From 1ae04d082da53eeb60af77885ad09030a5b4f079 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 13 Aug 2013 09:35:59 +0800 Subject: [PATCH] MDL-40877 repository_url: Use textlib functions instead of mb_strlen() --- repository/url/locallib.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/repository/url/locallib.php b/repository/url/locallib.php index 042350b4951..941b07c3b7d 100644 --- a/repository/url/locallib.php +++ b/repository/url/locallib.php @@ -40,6 +40,8 @@ * See: http://www.opensource.org/licenses/bsd-license.php */ +defined('MOODLE_INTERNAL') || die(); + /** * Combine a base URL and a relative URL to produce a new * absolute URL. The base URL is often the URL of a page, @@ -110,15 +112,16 @@ function url_to_absolute( $baseUrl, $relativeUrl ) return join_url( $r ); } - // If relative URL path doesn't start with /, merge with base path - if ( $r['path'][0] != '/' ) - { - $base = mb_strrchr( $b['path'], '/', TRUE, 'UTF-8' ); - if ( $base === FALSE ) $base = ''; + // If relative URL path doesn't start with /, merge with base path. + if ($r['path'][0] != '/') { + $base = textlib::strrchr($b['path'], '/', TRUE); + if ($base === FALSE) { + $base = ''; + } $r['path'] = $base . '/' . $r['path']; } - $r['path'] = url_remove_dot_segments( $r['path'] ); - return join_url( $r ); + $r['path'] = url_remove_dot_segments($r['path']); + return join_url($r); } /** @@ -152,12 +155,15 @@ function url_remove_dot_segments( $path ) array_push( $outSegs, $seg ); } $outPath = implode( '/', $outSegs ); - if ( $path[0] == '/' ) + + if ($path[0] == '/') { $outPath = '/' . $outPath; - // compare last multi-byte character against '/' - if ( $outPath != '/' && - (mb_strlen($path)-1) == mb_strrpos( $path, '/', 'UTF-8' ) ) + } + + // Compare last multi-byte character against '/'. + if ($outPath != '/' && (textlib::strlen($path) - 1) == textlib::strrpos($path, '/', 'UTF-8')) { $outPath .= '/'; + } return $outPath; }