| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plain-PHP fallbacks for mb_* functions when mbstring extension is missing. |
| 5 |
* |
| 6 |
* These handle ASCII correctly, which is sufficient for the framework's |
| 7 |
* internal use (route matching, snake/camel case, validator attribute parsing). |
| 8 |
* |
| 9 |
* WordPress already polyfills mb_strlen and mb_substr via wp-includes/compat.php. |
| 10 |
* This file covers the remaining functions the framework and plugin use. |
| 11 |
* |
| 12 |
* When mbstring IS loaded, this file does nothing. |
| 13 |
*/ |
| 14 |
|
| 15 |
if (extension_loaded('mbstring')) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
if (!defined('MB_CASE_UPPER')) { |
| 20 |
define('MB_CASE_UPPER', 0); |
| 21 |
} |
| 22 |
|
| 23 |
if (!defined('MB_CASE_LOWER')) { |
| 24 |
define('MB_CASE_LOWER', 1); |
| 25 |
} |
| 26 |
|
| 27 |
if (!defined('MB_CASE_TITLE')) { |
| 28 |
define('MB_CASE_TITLE', 2); |
| 29 |
} |
| 30 |
|
| 31 |
if (!function_exists('mb_strlen')) { |
| 32 |
function mb_strlen($string, $encoding = null) |
| 33 |
{ |
| 34 |
return strlen($string); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
if (!function_exists('mb_substr')) { |
| 39 |
function mb_substr($string, $start, $length = null, $encoding = null) |
| 40 |
{ |
| 41 |
return $length === null ? substr($string, $start) : substr($string, $start, $length); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
if (!function_exists('mb_strtolower')) { |
| 46 |
function mb_strtolower($string, $encoding = null) |
| 47 |
{ |
| 48 |
return strtolower($string); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
if (!function_exists('mb_strtoupper')) { |
| 53 |
function mb_strtoupper($string, $encoding = null) |
| 54 |
{ |
| 55 |
return strtoupper($string); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
if (!function_exists('mb_strpos')) { |
| 60 |
function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) |
| 61 |
{ |
| 62 |
return strpos($haystack, $needle, $offset); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
if (!function_exists('mb_strrpos')) { |
| 67 |
function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) |
| 68 |
{ |
| 69 |
return strrpos($haystack, $needle, $offset); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
if (!function_exists('mb_strwidth')) { |
| 74 |
function mb_strwidth($string, $encoding = null) |
| 75 |
{ |
| 76 |
return strlen($string); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
if (!function_exists('mb_strimwidth')) { |
| 81 |
function mb_strimwidth($string, $start, $width, $trimmarker = '', $encoding = null) |
| 82 |
{ |
| 83 |
$string = substr($string, $start); |
| 84 |
|
| 85 |
if (strlen($string) <= $width) { |
| 86 |
return $string; |
| 87 |
} |
| 88 |
|
| 89 |
$markerLen = strlen($trimmarker); |
| 90 |
|
| 91 |
return substr($string, 0, $width - $markerLen) . $trimmarker; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
if (!function_exists('mb_convert_case')) { |
| 96 |
function mb_convert_case($string, $mode, $encoding = null) |
| 97 |
{ |
| 98 |
switch ($mode) { |
| 99 |
case MB_CASE_UPPER: |
| 100 |
return strtoupper($string); |
| 101 |
case MB_CASE_LOWER: |
| 102 |
return strtolower($string); |
| 103 |
case MB_CASE_TITLE: |
| 104 |
return ucwords(strtolower($string)); |
| 105 |
default: |
| 106 |
return $string; |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
if (!function_exists('mb_str_split')) { |
| 112 |
function mb_str_split($string, $length = 1, $encoding = null) |
| 113 |
{ |
| 114 |
return str_split($string, $length); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
if (!function_exists('mb_split')) { |
| 119 |
function mb_split($pattern, $string, $limit = -1) |
| 120 |
{ |
| 121 |
return preg_split('/' . $pattern . '/u', $string, $limit); |
| 122 |
} |
| 123 |
} |
| 124 |
|