| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: |
|
| 23: | function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = false)
|
| 24: | {
|
| 25: | if (Smarty::$_MBSTRING) {
|
| 26: | if ($lc_rest) {
|
| 27: |
|
| 28: | $upper_string = mb_convert_case($string, MB_CASE_TITLE, Smarty::$_CHARSET);
|
| 29: | } else {
|
| 30: |
|
| 31: | $upper_string = preg_replace_callback(
|
| 32: | "!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
|
| 33: | 'smarty_mod_cap_mbconvert_cb',
|
| 34: | $string
|
| 35: | );
|
| 36: | }
|
| 37: |
|
| 38: | if (!$uc_digits) {
|
| 39: | if (preg_match_all(
|
| 40: | "!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER,
|
| 41: | $string,
|
| 42: | $matches,
|
| 43: | PREG_OFFSET_CAPTURE
|
| 44: | )
|
| 45: | ) {
|
| 46: | foreach ($matches[ 1 ] as $match) {
|
| 47: | $upper_string =
|
| 48: | substr_replace(
|
| 49: | $upper_string,
|
| 50: | mb_strtolower($match[ 0 ], Smarty::$_CHARSET),
|
| 51: | $match[ 1 ],
|
| 52: | strlen($match[ 0 ])
|
| 53: | );
|
| 54: | }
|
| 55: | }
|
| 56: | }
|
| 57: | $upper_string =
|
| 58: | preg_replace_callback(
|
| 59: | "!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER,
|
| 60: | 'smarty_mod_cap_mbconvert2_cb',
|
| 61: | $upper_string
|
| 62: | );
|
| 63: | return $upper_string;
|
| 64: | }
|
| 65: |
|
| 66: | if ($lc_rest) {
|
| 67: | $string = strtolower($string);
|
| 68: | }
|
| 69: |
|
| 70: | $upper_string =
|
| 71: | preg_replace_callback(
|
| 72: | "!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
|
| 73: | 'smarty_mod_cap_ucfirst_cb',
|
| 74: | $string
|
| 75: | );
|
| 76: |
|
| 77: | if (!$uc_digits) {
|
| 78: | if (preg_match_all(
|
| 79: | "!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER,
|
| 80: | $string,
|
| 81: | $matches,
|
| 82: | PREG_OFFSET_CAPTURE
|
| 83: | )
|
| 84: | ) {
|
| 85: | foreach ($matches[ 1 ] as $match) {
|
| 86: | $upper_string =
|
| 87: | substr_replace($upper_string, strtolower($match[ 0 ]), $match[ 1 ], strlen($match[ 0 ]));
|
| 88: | }
|
| 89: | }
|
| 90: | }
|
| 91: | $upper_string = preg_replace_callback(
|
| 92: | "!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER,
|
| 93: | 'smarty_mod_cap_ucfirst2_cb',
|
| 94: | $upper_string
|
| 95: | );
|
| 96: | return $upper_string;
|
| 97: | }
|
| 98: |
|
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | |
| 106: |
|
| 107: | |
| 108: | |
| 109: | |
| 110: | |
| 111: |
|
| 112: | function smarty_mod_cap_mbconvert_cb($matches)
|
| 113: | {
|
| 114: | return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 2 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
|
| 115: | }
|
| 116: |
|
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: |
|
| 122: | function smarty_mod_cap_mbconvert2_cb($matches)
|
| 123: | {
|
| 124: | return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 3 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
|
| 125: | }
|
| 126: |
|
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: |
|
| 132: | function smarty_mod_cap_ucfirst_cb($matches)
|
| 133: | {
|
| 134: | return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 2 ]));
|
| 135: | }
|
| 136: |
|
| 137: | |
| 138: | |
| 139: | |
| 140: | |
| 141: |
|
| 142: | function smarty_mod_cap_ucfirst2_cb($matches)
|
| 143: | {
|
| 144: | return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 3 ]));
|
| 145: | }
|
| 146: | |