26 #require_once 'Zend/Locale/Data.php'; 39 private static $_options = array(
'date_format' =>
null,
40 'number_format' =>
null,
41 'format_type' =>
'iso',
45 'disableCache' =>
null,
66 self::$_options = self::_checkOptions(
$options) + self::$_options;
67 return self::$_options;
79 private static function _checkOptions(array
$options = array())
82 return self::$_options;
86 if (
$name !==
'locale') {
87 if (gettype(
$value) ===
'string') {
93 case 'number_format' :
95 $locale = self::$_options[
'locale'];
100 }
else if ((gettype(
$value) !==
'string') and (
$value !== NULL)) {
101 #require_once 'Zend/Locale/Exception.php'; 104 .
"Format '$stringValue' must be a valid number format string.");
110 $locale = self::$_options[
'locale'];
115 }
else if ((gettype(
$value) !==
'string') and (
$value !== NULL)) {
116 #require_once 'Zend/Locale/Exception.php'; 119 .
"Format '$stringValue' must be a valid ISO or PHP date format string.");
121 if (((isset(
$options[
'format_type']) ===
true) and (
$options[
'format_type'] ==
'php')) or
122 ((isset(
$options[
'format_type']) ===
false) and (self::$_options[
'format_type'] ==
'php'))) {
130 #require_once 'Zend/Locale/Exception.php'; 132 .
" are supported.");
138 #require_once 'Zend/Locale/Exception.php'; 140 .
"(fix_date='$value').");
154 case 'disablecache' :
166 #require_once 'Zend/Locale/Exception.php'; 172 #require_once 'Zend/Locale/Exception.php'; 200 if (!self::_getUniCodeSupport()) {
201 trigger_error(
"Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE);
204 $from = strtolower($from);
207 #require_once 'Zend/Locale/Exception.php'; 208 throw new Zend_Locale_Exception(
"Unknown script '$from'. Use 'Latn' for digits 0,1,2,3,4,5,6,7,8,9.");
212 $to = strtolower($to);
215 #require_once 'Zend/Locale/Exception.php'; 222 for ($x = 0; $x < 10; ++$x) {
223 $asource[$x] =
"/" . iconv_substr(
$source, $x, 1,
'UTF-8') .
"/u";
224 $atarget[$x] = iconv_substr(
$target, $x, 1,
'UTF-8');
227 return preg_replace($asource, $atarget, $input);
249 if (!is_string($input)) {
253 if (!self::isNumber($input,
$options)) {
254 #require_once 'Zend/Locale/Exception.php'; 255 throw new Zend_Locale_Exception(
'No localized value in ' . $input .
' found, or the given number does not match the localized format');
261 if (($input[0] == $symbols[
'minus']) && (
'-' != $input[0])) {
262 $input =
'-' . substr($input, 1);
265 $input = str_replace($symbols[
'group'],
'', $input);
266 if (strpos($input, $symbols[
'decimal']) !==
false) {
267 if ($symbols[
'decimal'] !=
'.') {
268 $input = str_replace($symbols[
'decimal'],
".", $input);
271 $pre = substr($input, strpos($input,
'.') + 1);
272 if (
$options[
'precision'] ===
null) {
273 $options[
'precision'] = strlen($pre);
276 if (strlen($pre) >=
$options[
'precision']) {
277 $input = substr($input, 0, strlen($input) - strlen($pre) +
$options[
'precision']);
280 if ((
$options[
'precision'] == 0) && ($input[strlen($input) - 1] ==
'.')) {
281 $input = substr($input, 0, -1);
303 #require_once 'Zend/Locale/Math.php'; 321 if (
$options[
'precision'] !==
null) {
328 if (is_numeric(
$options[
'precision'])) {
331 if (substr(
$format, iconv_strpos(
$format,
'.') + 1, 3) ==
'###') {
347 if (iconv_strpos(
$format,
'0') ===
false) {
349 #require_once 'Zend/Locale/Exception.php'; 355 if (
$pos !==
false) {
356 if (
$options[
'precision'] ===
null) {
360 if (iconv_strlen($precstr) <
$options[
'precision']) {
361 $precstr = $precstr . str_pad(
"0", (
$options[
'precision'] - iconv_strlen($precstr)),
"0");
366 $precstr = str_pad(
"0", (
$options[
'precision']),
"0");
370 if (
$options[
'precision'] ===
null) {
371 if (isset($precstr)) {
372 $options[
'precision'] = iconv_strlen($precstr);
379 if (strpos(
$value,
'.') !==
false) {
388 if (iconv_strpos($prec,
'-') !==
false) {
389 $prec = iconv_substr($prec, 1);
392 if (($prec == 0) and (
$options[
'precision'] > 0)) {
396 if ((
$options[
'precision'] + 2) > iconv_strlen($prec)) {
397 $prec = str_pad((
string) $prec,
$options[
'precision'] + 2,
"0", STR_PAD_RIGHT);
400 if (iconv_strpos(
$number,
'-') !==
false) {
404 $group2 = iconv_strpos (
$format,
',');
405 $point = iconv_strpos (
$format,
'0');
408 if (iconv_strpos(
$format,
'.')) {
410 $length = iconv_strlen($rest);
411 for($x = 0; $x < $length; ++$x) {
412 if (($rest[0] ==
'0') || ($rest[0] ==
'#')) {
413 $rest = iconv_substr($rest, 1);
420 if (iconv_strrpos(
$format,
'-') != 0) {
428 . iconv_substr($prec, 2);
436 }
else if (
$group == $group2) {
438 $seperation = ($point -
$group);
439 for ($x = iconv_strlen(
$number); $x > $seperation; $x -= $seperation) {
440 if (iconv_substr(
$number, 0, $x - $seperation) !==
"") {
441 $number = iconv_substr(
$number, 0, $x - $seperation) . $symbols[
'group']
442 . iconv_substr(
$number, $x - $seperation);
450 $seperation = ($point -
$group);
455 $seperation2 = (
$group - $group2 - 1);
456 for ($x = iconv_strlen(
$number) - $seperation2 - 2; $x > $seperation2; $x -= $seperation2) {
457 $number = iconv_substr(
$number, 0, $x - $seperation2) . $symbols[
'group']
458 . iconv_substr(
$number, $x - $seperation2);
467 if (iconv_strpos(
$format,
'-') ===
false) {
484 private static function _seperateFormat(
$format,
$value, $precision)
486 if (iconv_strpos(
$format,
';') !==
false) {
488 $tmpformat = iconv_substr(
$format, iconv_strpos(
$format,
';') + 1);
489 if ($tmpformat[0] ==
'(') {
512 if (!self::_getUniCodeSupport()) {
513 trigger_error(
"Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE);
521 $regexs = Zend_Locale_Format::_getRegexForType(
'decimalnumber',
$options);
522 $regexs = array_merge($regexs, Zend_Locale_Format::_getRegexForType(
'scientificnumber',
$options));
523 if (!empty($input) && ($input[0] == $symbols[
'decimal'])) {
526 foreach ($regexs as $regex) {
527 preg_match($regex, $input, $found);
528 if (isset($found[0])) {
547 $decimal = preg_replace(
'/[^#0,;\.\-Ee]/u',
'',$decimal);
548 $patterns = explode(
';', $decimal);
550 if (count($patterns) == 1) {
551 $patterns[1] =
'-' . $patterns[0];
556 foreach($patterns as $pkey =>
$pattern) {
557 $regex[$pkey] =
'/^';
560 if (strpos(
$pattern,
'.') !==
false) {
565 if (strpos(
$pattern,
',') !==
false) {
568 foreach($parts as $key => $part) {
572 if ($part[0] ==
'-') {
573 $regex[$pkey] .=
'[' . preg_quote($symbols[
'minus']) .
'-]{0,1}';
575 $regex[$pkey] .=
'[' . $symbols[
'plus'] .
'+]{0,1}';
578 if (($parts[$key + 1]) ==
'##0') {
579 $regex[$pkey] .=
'[0-9]{1,3}';
580 }
else if (($parts[$key + 1]) ==
'##') {
581 $regex[$pkey] .=
'[0-9]{1,2}';
587 if ($parts[$key + 1] ==
'##0') {
588 $regex[$pkey] .=
'(\\' . $symbols[
'group'] .
'{0,1}[0-9]{2})*';
594 if ($parts[$key - 1] ==
'##') {
595 $regex[$pkey] .=
'[0-9]';
596 }
else if (($parts[$key - 1] ==
'#') || ($parts[$key - 1] ==
'-#')) {
597 $regex[$pkey] .=
'(\\' . $symbols[
'group'] .
'{0,1}[0-9]{3})*';
604 $regex[$pkey] .=
'[0-9]*';
613 if (strpos(
$pattern,
'E') !==
false) {
615 $regex[$pkey] .=
'[' . $symbols[
'plus'].
'+]{0,1}[0-9]{1,}(\\' . $symbols[
'decimal'] .
'[0-9]{1,})*[eE][' . $symbols[
'plus'].
'+]{0,1}[0-9]{1,}';
617 $regex[$pkey] .=
'[' . preg_quote($symbols[
'minus']) .
'-]{0,1}[0-9]{1,}(\\' . $symbols[
'decimal'] .
'[0-9]{1,})*[eE][' . preg_quote($symbols[
'minus']) .
'-]{0,1}[0-9]{1,}';
625 $regex[$pkey] .=
'(\\' . $symbols[
'decimal'] .
'{1}[0-9]{1,}){0,1}';
626 }
else if ($end ==
'###-') {
627 $regex[$pkey] .=
'(\\' . $symbols[
'decimal'] .
'{1}[0-9]{1,}){0,1}[' . preg_quote($symbols[
'minus']) .
'-]';
633 $regex[$pkey] .=
'$/u';
648 return floatval(self::getNumber($input,
$options));
697 return intval(self::getFloat($input,
$options));
753 'd' =>
'dd' ,
'D' =>
'EE' ,
'j' =>
'd' ,
'l' =>
'EEEE',
754 'N' =>
'eee' ,
'S' =>
'SS' ,
'w' =>
'e' ,
'z' =>
'D' ,
755 'W' =>
'ww' ,
'F' =>
'MMMM',
'm' =>
'MM' ,
'M' =>
'MMM' ,
756 'n' =>
'M' ,
't' =>
'ddd' ,
'L' =>
'l' ,
'o' =>
'YYYY',
757 'Y' =>
'yyyy',
'y' =>
'yy' ,
'a' =>
'a' ,
'A' =>
'a' ,
758 'B' =>
'B' ,
'g' =>
'h' ,
'G' =>
'H' ,
'h' =>
'hh' ,
759 'H' =>
'HH' ,
'i' =>
'mm' ,
's' =>
'ss' ,
'e' =>
'zzzz',
760 'I' =>
'I' ,
'O' =>
'Z' ,
'P' =>
'ZZZZ',
'T' =>
'z' ,
761 'Z' =>
'X' ,
'c' =>
'yyyy-MM-ddTHH:mm:ssZZZZ',
'r' =>
'r',
765 $inEscapedString =
false;
766 $converted = array();
767 foreach (str_split(
$format) as $char) {
768 if (!$escaped && $char ==
'\\') {
772 if (!$inEscapedString) {
775 $inEscapedString =
true;
779 $converted[] = $char;
785 if ($inEscapedString) {
788 $inEscapedString =
false;
791 if (isset($convert[$char])) {
792 $converted[] = $convert[$char];
794 $converted[] = $char;
799 return implode($converted);
810 private static function _parseDate($date,
$options)
812 if (!self::_getUniCodeSupport()) {
813 trigger_error(
"Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE);
817 $test = array(
'h',
'H',
'm',
's',
'y',
'Y',
'M',
'd',
'D',
'E',
'S',
'l',
'B',
'I',
818 'X',
'r',
'U',
'G',
'w',
'e',
'a',
'A',
'Z',
'z',
'v');
827 $day = iconv_strpos(
$format,
'd');
828 $month = iconv_strpos(
$format,
'M');
829 $year = iconv_strpos(
$format,
'y');
830 $hour = iconv_strpos(
$format,
'H');
831 $min = iconv_strpos(
$format,
'm');
832 $sec = iconv_strpos(
$format,
's');
834 if ($hour ===
false) {
835 $hour = iconv_strpos(
$format,
'h');
837 if ($year ===
false) {
838 $year = iconv_strpos(
$format,
'Y');
840 if ($day ===
false) {
841 $day = iconv_strpos(
$format,
'E');
842 if ($day ===
false) {
843 $day = iconv_strpos(
$format,
'D');
847 if ($day !==
false) {
850 (!is_object(
$options[
'locale']) || ((
string)
$options[
'locale'] !==
'root'))) {
853 foreach($daylist as $key =>
$name) {
863 if ($month !==
false) {
864 $parse[$month] =
'M';
866 (!is_object(
$options[
'locale']) || ((
string)
$options[
'locale'] !==
'root'))) {
871 if ($position ===
false) {
873 'month', array(
'gregorian',
'format',
'abbreviated')));
877 if ($year !==
false) {
880 if ($hour !==
false) {
883 if ($min !==
false) {
886 if ($sec !==
false) {
892 #require_once 'Zend/Locale/Exception.php'; 898 if (iconv_strpos(
$format,
'a') !==
false) {
908 preg_match_all(
'/\d+/u',
$number, $splitted);
910 if (count($splitted[0]) == 0) {
912 #require_once 'Zend/Locale/Exception.php'; 915 if (count($splitted[0]) == 1) {
919 foreach($parse as $key =>
$value) {
923 if ($split ===
false) {
924 if (count($splitted[0]) > $cnt) {
925 $result[
'day'] = $splitted[0][$cnt];
928 $result[
'day'] = iconv_substr($splitted[0][0], $split, 2);
934 if ($split ===
false) {
935 if (count($splitted[0]) > $cnt) {
936 $result[
'month'] = $splitted[0][$cnt];
939 $result[
'month'] = iconv_substr($splitted[0][0], $split, 2);
946 if ((iconv_substr(
$format, $year, 4) ==
'yyyy')
947 || (iconv_substr(
$format, $year, 4) ==
'YYYY')) {
951 if ($split ===
false) {
952 if (count($splitted[0]) > $cnt) {
953 $result[
'year'] = $splitted[0][$cnt];
956 $result[
'year'] = iconv_substr($splitted[0][0], $split, $length);
963 if ($split ===
false) {
964 if (count($splitted[0]) > $cnt) {
965 $result[
'hour'] = $splitted[0][$cnt];
968 $result[
'hour'] = iconv_substr($splitted[0][0], $split, 2);
974 if ($split ===
false) {
975 if (count($splitted[0]) > $cnt) {
976 $result[
'minute'] = $splitted[0][$cnt];
979 $result[
'minute'] = iconv_substr($splitted[0][0], $split, 2);
985 if ($split ===
false) {
986 if (count($splitted[0]) > $cnt) {
987 $result[
'second'] = $splitted[0][$cnt];
990 $result[
'second'] = iconv_substr($splitted[0][0], $split, 2);
999 if ($hour !==
false) {
1000 if (($am ===
true) and (
$result[
'hour'] == 12)){
1002 }
else if (($am ===
false) and (
$result[
'hour'] != 12)) {
1007 if (
$options[
'fix_date'] ===
true) {
1011 if ($day !==
false) {
1014 if (($position !==
false) and ((iconv_strpos($date,
$result[
'day']) ===
false) or
1015 (isset(
$result[
'year']) and (iconv_strpos($date,
$result[
'year']) ===
false)))) {
1016 if (
$options[
'fix_date'] !==
true) {
1018 #require_once 'Zend/Locale/Exception.php'; 1020 .
"' (false month, $position, $month)");
1032 if (
$options[
'fix_date'] !==
true) {
1034 #require_once 'Zend/Locale/Exception.php'; 1048 if (
$options[
'fix_date'] !==
true) {
1050 #require_once 'Zend/Locale/Exception.php'; 1066 #require_once 'Zend/Locale/Exception.php'; 1079 if (((iconv_strlen(
$result[
'year']) == 2) && (
$result[
'year'] < 10)) ||
1080 (((iconv_strpos(
$format,
'yy') !==
false) && (iconv_strpos(
$format,
'yyyy') ===
false)) ||
1081 ((iconv_strpos(
$format,
'YY') !==
false) && (iconv_strpos(
$format,
'YYYY') ===
false)))) {
1111 if ($monthlist && $monthlist[1] != 1) {
1112 foreach($monthlist as $key =>
$name) {
1113 if (($position = iconv_strpos(
$number,
$name, 0,
'UTF-8')) !==
false) {
1134 #require_once 'Zend/Locale/Exception.php'; 1157 if (empty(
$options[
'date_format'])) {
1162 return self::_parseDate($date,
$options);
1178 }
catch (Exception $e) {
1182 if (empty(
$options[
'date_format'])) {
1189 if ((iconv_strpos(
$options[
'date_format'],
'd', 0,
'UTF-8') !==
false) and (!isset($date[
'day']) or ($date[
'day'] ===
""))) {
1194 if ((iconv_strpos(
$options[
'date_format'],
'M', 0,
'UTF-8') !==
false) and (!isset($date[
'month']) or ($date[
'month'] ===
""))) {
1199 if (((iconv_strpos(
$options[
'date_format'],
'Y', 0,
'UTF-8') !==
false) or
1200 (iconv_strpos(
$options[
'date_format'],
'y', 0,
'UTF-8') !==
false)) and (!isset($date[
'year']) or ($date[
'year'] ===
""))) {
1205 if ((iconv_strpos(
$options[
'date_format'],
's', 0,
'UTF-8') !==
false) and (!isset($date[
'second']) or ($date[
'second'] ===
""))) {
1210 if ((iconv_strpos(
$options[
'date_format'],
'm', 0,
'UTF-8') !==
false) and (!isset($date[
'minute']) or ($date[
'minute'] ===
""))) {
1215 if (((iconv_strpos(
$options[
'date_format'],
'H', 0,
'UTF-8') !==
false) or
1216 (iconv_strpos(
$options[
'date_format'],
'h', 0,
'UTF-8') !==
false)) and (!isset($date[
'hour']) or ($date[
'hour'] ===
""))) {
1234 #require_once 'Zend/Locale/Exception.php'; 1255 if (empty(
$options[
'date_format'])) {
1259 return self::_parseDate($time,
$options);
1273 #require_once 'Zend/Locale/Exception.php'; 1294 if (empty(
$options[
'date_format'])) {
1298 return self::_parseDate($datetime,
$options);
1309 return (@preg_match(
'/\pL/u',
'a')) ? true :
false;
1320 $oenc = PHP_VERSION_ID < 50600
1321 ? iconv_get_encoding(
'internal_encoding')
1336 if (PHP_VERSION_ID < 50600) {
1337 iconv_set_encoding(
'internal_encoding', $encoding);
1339 ini_set(
'default_charset', $encoding);
static getList($locale, $path, $value=false)
ini_set($varName, $newValue)
elseif(isset( $params[ 'redirect_parent']))
static floatalize($value)
call_user_func($callable, $param)
static getContent($locale, $path, $value=false)
static findLocale($locale=null)
static disableCache($flag)
static setCache(Zend_Cache_Core $cache)
static round($op1, $precision=0)
if(!isset($_GET['name'])) $name