diff options
Diffstat (limited to 'library/vendor/Zend/Locale')
-rw-r--r-- | library/vendor/Zend/Locale/Data.php | 1609 | ||||
-rw-r--r-- | library/vendor/Zend/Locale/Data/Translation.php | 285 | ||||
-rw-r--r-- | library/vendor/Zend/Locale/Exception.php | 36 | ||||
-rw-r--r-- | library/vendor/Zend/Locale/Format.php | 1321 | ||||
-rw-r--r-- | library/vendor/Zend/Locale/Math.php | 354 | ||||
-rw-r--r-- | library/vendor/Zend/Locale/Math/Exception.php | 52 | ||||
-rw-r--r-- | library/vendor/Zend/Locale/Math/PhpMath.php | 239 |
7 files changed, 3896 insertions, 0 deletions
diff --git a/library/vendor/Zend/Locale/Data.php b/library/vendor/Zend/Locale/Data.php new file mode 100644 index 0000000..a6a435a --- /dev/null +++ b/library/vendor/Zend/Locale/Data.php @@ -0,0 +1,1609 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Locale + * @subpackage Data + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** + * include needed classes + */ + +/** @see Zend_Xml_Security */ + +/** + * Locale data reader, handles the CLDR + * + * @category Zend + * @package Zend_Locale + * @subpackage Data + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Locale_Data +{ + /** + * Locale files + * + * @var array + */ + private static $_ldml = array(); + + /** + * List of values which are collected + * + * @var array + */ + private static $_list = array(); + + /** + * Internal cache for ldml values + * + * @var Zend_Cache_Core + */ + private static $_cache = null; + + /** + * Internal value to remember if cache supports tags + * + * @var boolean + */ + private static $_cacheTags = false; + + /** + * Internal option, cache disabled + * + * @var boolean + */ + private static $_cacheDisabled = false; + + /** + * Read the content from locale + * + * Can be called like: + * <ldml> + * <delimiter>test</delimiter> + * <second type='myone'>content</second> + * <second type='mysecond'>content2</second> + * <third type='mythird' /> + * </ldml> + * + * Case 1: _readFile('ar','/ldml/delimiter') -> returns [] = test + * Case 1: _readFile('ar','/ldml/second[@type=myone]') -> returns [] = content + * Case 2: _readFile('ar','/ldml/second','type') -> returns [myone] = content; [mysecond] = content2 + * Case 3: _readFile('ar','/ldml/delimiter',,'right') -> returns [right] = test + * Case 4: _readFile('ar','/ldml/third','type','myone') -> returns [myone] = mythird + * + * @param string $locale + * @param string $path + * @param string $attribute + * @param string $value + * @access private + * @return array + */ + private static function _readFile($locale, $path, $attribute, $value, $temp) + { + // without attribute - read all values + // with attribute - read only this value + if (!empty(self::$_ldml[(string) $locale])) { + + $result = self::$_ldml[(string) $locale]->xpath($path); + if (!empty($result)) { + foreach ($result as &$found) { + + if (empty($value)) { + + if (empty($attribute)) { + // Case 1 + $temp[] = (string) $found; + } else if (empty($temp[(string) $found[$attribute]])){ + // Case 2 + $temp[(string) $found[$attribute]] = (string) $found; + } + + } else if (empty ($temp[$value])) { + + if (empty($attribute)) { + // Case 3 + $temp[$value] = (string) $found; + } else { + // Case 4 + $temp[$value] = (string) $found[$attribute]; + } + + } + } + } + } + return $temp; + } + + /** + * Find possible routing to other path or locale + * + * @param string $locale + * @param string $path + * @param string $attribute + * @param string $value + * @param array $temp + * @return bool + * @throws Zend_Locale_Exception + */ + private static function _findRoute($locale, $path, $attribute, $value, &$temp) + { + // load locale file if not already in cache + // needed for alias tag when referring to other locale + if (empty(self::$_ldml[(string) $locale])) { + $filename = dirname(__FILE__) . '/Data/' . $locale . '.xml'; + if (!file_exists($filename)) { + throw new Zend_Locale_Exception("Missing locale file '$filename' for '$locale' locale."); + } + + self::$_ldml[(string) $locale] = Zend_Xml_Security::scanFile($filename); + } + + // search for 'alias' tag in the search path for redirection + $search = ''; + $tok = strtok($path, '/'); + + // parse the complete path + if (!empty(self::$_ldml[(string) $locale])) { + while ($tok !== false) { + $search .= '/' . $tok; + if (strpos($search, '[@') !== false) { + while (strrpos($search, '[@') > strrpos($search, ']')) { + $tok = strtok('/'); + if (empty($tok)) { + $search .= '/'; + } + $search = $search . '/' . $tok; + } + } + $result = self::$_ldml[(string) $locale]->xpath($search . '/alias'); + + // alias found + if (!empty($result)) { + + $source = $result[0]['source']; + $newpath = $result[0]['path']; + + // new path - path //ldml is to ignore + if ($newpath != '//ldml') { + // other path - parse to make real path + + while (substr($newpath,0,3) == '../') { + $newpath = substr($newpath, 3); + $search = substr($search, 0, strrpos($search, '/')); + } + + // truncate ../ to realpath otherwise problems with alias + $path = $search . '/' . $newpath; + while (($tok = strtok('/'))!== false) { + $path = $path . '/' . $tok; + } + } + + // reroute to other locale + if ($source != 'locale') { + $locale = $source; + } + + $temp = self::_getFile($locale, $path, $attribute, $value, $temp); + return false; + } + + $tok = strtok('/'); + } + } + return true; + } + + /** + * Read the right LDML file + * + * @param string $locale + * @param string $path + * @param string|bool $attribute + * @param string|bool $value + * @param array $temp + * @return array + * @throws Zend_Locale_Exception + */ + private static function _getFile($locale, $path, $attribute = false, $value = false, $temp = array()) + { + $result = self::_findRoute($locale, $path, $attribute, $value, $temp); + if ($result) { + $temp = self::_readFile($locale, $path, $attribute, $value, $temp); + } + + // parse required locales reversive + // example: when given zh_Hans_CN + // 1. -> zh_Hans_CN + // 2. -> zh_Hans + // 3. -> zh + // 4. -> root + if (($locale != 'root') && ($result)) { + // Search for parent locale + if (false !== strpos($locale, '_')) { + $parentLocale = self::getContent($locale, 'parentlocale'); + if ($parentLocale) { + $temp = self::_getFile($parentLocale, $path, $attribute, $value, $temp); + } + } + + $locale = substr($locale, 0, -strlen(strrchr($locale, '_'))); + if (!empty($locale)) { + $temp = self::_getFile($locale, $path, $attribute, $value, $temp); + } else { + $temp = self::_getFile('root', $path, $attribute, $value, $temp); + } + } + return $temp; + } + + /** + * Find the details for supplemental calendar datas + * + * @param string $locale Locale for Detaildata + * @param array $list List to search + * @return string Key for Detaildata + */ + private static function _calendarDetail($locale, $list) + { + $ret = "001"; + foreach ($list as $key => $value) { + if (strpos($locale, '_') !== false) { + $locale = substr($locale, strpos($locale, '_') + 1); + } + if (strpos($key, $locale) !== false) { + $ret = $key; + break; + } + } + return $ret; + } + + /** + * Internal function for checking the locale + * + * @param string|Zend_Locale $locale Locale to check + * @return string + * @throws Zend_Locale_Exception + */ + private static function _checkLocale($locale) + { + if (empty($locale)) { + $locale = new Zend_Locale(); + } + + if (!(Zend_Locale::isLocale((string) $locale, null, false))) { + throw new Zend_Locale_Exception("Locale (" . (string) $locale . ") is a unknown locale"); + } + + if (Zend_Locale::isAlias($locale)) { + // Return a valid CLDR locale so that the XML file can be loaded. + return Zend_Locale::getAlias($locale); + } + return (string) $locale; + } + + /** + * Read the LDML file, get a array of multipath defined value + * + * @param string $locale + * @param string $path + * @param bool|string $value + * @return array + * @throws Zend_Locale_Exception + */ + public static function getList($locale, $path, $value = false) + { + $locale = self::_checkLocale($locale); + + if (!isset(self::$_cache) && !self::$_cacheDisabled) { + self::$_cache = Zend_Cache::factory( + 'Core', + 'File', + array('automatic_serialization' => true), + array()); + } + + $val = $value; + if (is_array($value)) { + $val = implode('_' , $value); + } + + $val = urlencode($val); + $id = self::_filterCacheId('Zend_LocaleL_' . $locale . '_' . $path . '_' . $val); + if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) { + return unserialize($result); + } + + $temp = array(); + switch(strtolower($path)) { + case 'language': + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language', 'type'); + break; + + case 'script': + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/scripts/script', 'type'); + break; + + case 'territory': + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/territories/territory', 'type'); + if ($value === 1) { + foreach($temp as $key => $value) { + if ((is_numeric($key) === false) and ($key != 'QO') and ($key != 'EU')) { + unset($temp[$key]); + } + } + } else if ($value === 2) { + foreach($temp as $key => $value) { + if (is_numeric($key) or ($key == 'QO') or ($key == 'EU')) { + unset($temp[$key]); + } + } + } + break; + + case 'variant': + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/variants/variant', 'type'); + break; + + case 'key': + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/keys/key', 'type'); + break; + + case 'type': + if (empty($value)) { + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type', 'type'); + } else { + if (($value == 'calendar') or + ($value == 'collation') or + ($value == 'currency')) { + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type[@key=\'' . $value . '\']', 'type'); + } else { + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/types/type[@type=\'' . $value . '\']', 'type'); + } + } + break; + + case 'layout': + $temp = self::_getFile($locale, '/ldml/layout/orientation/characterOrder', '', 'characterOrder'); + $temp += self::_getFile($locale, '/ldml/layout/orientation/lineOrder', '', 'lineOrder'); + break; + + case 'contexttransform': + if (empty($value)) { + $value = 'uiListOrMenu'; + } + $temp = self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'languages\']/contextTransform[@type=\''.$value.'\']', '', 'languages'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'day-format-except-narrow\']/contextTransform[@type=\''.$value.'\']', '', 'day-format-except-narrow'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'day-standalone-except-narrow\']/contextTransform[@type=\''.$value.'\']', '', 'day-standalone-except-narrow'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'day-narrow\']/contextTransform[@type=\''.$value.'\']', '', 'day-narrow'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'month-format-except-narrow\']/contextTransform[@type=\''.$value.'\']', '', 'month-format-except-narrow'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'month-standalone-except-narrow\']/contextTransform[@type=\''.$value.'\']', '', 'month-standalone-except-narrow'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'month-narrow\']/contextTransform[@type=\''.$value.'\']', '', 'month-narrow'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'script\']/contextTransform[@type=\''.$value.'\']', '', 'script'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'territory\']/contextTransform[@type=\''.$value.'\']', '', 'territory'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'variant\']/contextTransform[@type=\''.$value.'\']', '', 'variant'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'key\']/contextTransform[@type=\''.$value.'\']', '', 'key'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'type\']/contextTransform[@type=\''.$value.'\']', '', 'type'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'era-name\']/contextTransform[@type=\''.$value.'\']', '', 'era-name'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'era-abbr\']/contextTransform[@type=\''.$value.'\']', '', 'era-abbr'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'era-narrow\']/contextTransform[@type=\''.$value.'\']', '', 'era-narrow'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'quater-format-wide\']/contextTransform[@type=\''.$value.'\']', '', 'quater-format-wide'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'quater-standalone-wide\']/contextTransform[@type=\''.$value.'\']', '', 'quater-standalone-wide'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'quater-abbreviated\']/contextTransform[@type=\''.$value.'\']', '', 'quater-abbreviated'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'quater-narrow\']/contextTransform[@type=\''.$value.'\']', '', 'quater-narrow'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'calendar-field\']/contextTransform[@type=\''.$value.'\']', '', 'calendar-field'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'symbol\']/contextTransform[@type=\''.$value.'\']', '', 'symbol'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'tense\']/contextTransform[@type=\''.$value.'\']', '', 'tense'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'zone-exemplarCity\']/contextTransform[@type=\''.$value.'\']', '', 'zone-exemplarCity'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'zone-long\']/contextTransform[@type=\''.$value.'\']', '', 'zone-long'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'zone-short\']/contextTransform[@type=\''.$value.'\']', '', 'zone-short'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'metazone-long\']/contextTransform[@type=\''.$value.'\']', '', 'metazone-long'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'metazone-short\']/contextTransform[@type=\''.$value.'\']', '', 'metazone-short'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'displayName-count\']/contextTransform[@type=\''.$value.'\']', '', 'displayName-count'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'displayName\']/contextTransform[@type=\''.$value.'\']', '', 'displayName'); + $temp += self::_getFile($locale, '/ldml/contextTransforms/contextTransformUsage[@type=\'unit-pattern\']/contextTransform[@type=\''.$value.'\']', '', 'unit-pattern'); + break; + + case 'characters': + $temp = self::_getFile($locale, '/ldml/characters/exemplarCharacters', '', 'characters'); + $temp += self::_getFile($locale, '/ldml/characters/exemplarCharacters[@type=\'auxiliary\']', '', 'auxiliary'); + // $temp += self::_getFile($locale, '/ldml/characters/exemplarCharacters[@type=\'currencySymbol\']', '', 'currencySymbol'); + break; + + case 'delimiters': + $temp = self::_getFile($locale, '/ldml/delimiters/quotationStart', '', 'quoteStart'); + $temp += self::_getFile($locale, '/ldml/delimiters/quotationEnd', '', 'quoteEnd'); + $temp += self::_getFile($locale, '/ldml/delimiters/alternateQuotationStart', '', 'quoteStartAlt'); + $temp += self::_getFile($locale, '/ldml/delimiters/alternateQuotationEnd', '', 'quoteEndAlt'); + break; + + case 'measurement': + $temp = self::_getFile('supplementalData', '/supplementalData/measurementData/measurementSystem[@type=\'metric\']', 'territories', 'metric'); + $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/measurementSystem[@type=\'US\']', 'territories', 'US'); + $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/paperSize[@type=\'A4\']', 'territories', 'A4'); + $temp += self::_getFile('supplementalData', '/supplementalData/measurementData/paperSize[@type=\'US-Letter\']', 'territories', 'US-Letter'); + break; + + case 'months': + if (empty($value)) { + $value = "gregorian"; + } + $temp['context'] = "format"; + $temp['default'] = "wide"; + $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'abbreviated\']/month', 'type'); + $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'narrow\']/month', 'type'); + $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/monthWidth[@type=\'wide\']/month', 'type'); + $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'abbreviated\']/month', 'type'); + $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'narrow\']/month', 'type'); + $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'stand-alone\']/monthWidth[@type=\'wide\']/month', 'type'); + break; + + case 'month': + if (empty($value)) { + $value = array("gregorian", "format", "wide"); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/months/monthContext[@type=\'' . $value[1] . '\']/monthWidth[@type=\'' . $value[2] . '\']/month', 'type'); + break; + + case 'days': + if (empty($value)) { + $value = "gregorian"; + } + $temp['context'] = "format"; + $temp['default'] = "wide"; + $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'abbreviated\']/day', 'type'); + $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'narrow\']/day', 'type'); + $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/dayWidth[@type=\'wide\']/day', 'type'); + $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'abbreviated\']/day', 'type'); + $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'narrow\']/day', 'type'); + $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'stand-alone\']/dayWidth[@type=\'wide\']/day', 'type'); + break; + + case 'day': + if (empty($value)) { + $value = array("gregorian", "format", "wide"); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/days/dayContext[@type=\'' . $value[1] . '\']/dayWidth[@type=\'' . $value[2] . '\']/day', 'type'); + break; + + case 'week': + $minDays = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/minDays', 'territories')); + $firstDay = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/firstDay', 'territories')); + $weekStart = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/weekendStart', 'territories')); + $weekEnd = self::_calendarDetail($locale, self::_getFile('supplementalData', '/supplementalData/weekData/weekendEnd', 'territories')); + + $temp = self::_getFile('supplementalData', "/supplementalData/weekData/minDays[@territories='" . $minDays . "']", 'count', 'minDays'); + $temp += self::_getFile('supplementalData', "/supplementalData/weekData/firstDay[@territories='" . $firstDay . "']", 'day', 'firstDay'); + $temp += self::_getFile('supplementalData', "/supplementalData/weekData/weekendStart[@territories='" . $weekStart . "']", 'day', 'weekendStart'); + $temp += self::_getFile('supplementalData', "/supplementalData/weekData/weekendEnd[@territories='" . $weekEnd . "']", 'day', 'weekendEnd'); + break; + + case 'quarters': + if (empty($value)) { + $value = "gregorian"; + } + $temp['format']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'abbreviated\']/quarter', 'type'); + $temp['format']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'narrow\']/quarter', 'type'); + $temp['format']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'format\']/quarterWidth[@type=\'wide\']/quarter', 'type'); + $temp['stand-alone']['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'abbreviated\']/quarter', 'type'); + $temp['stand-alone']['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'narrow\']/quarter', 'type'); + $temp['stand-alone']['wide'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/quarters/quarterContext[@type=\'stand-alone\']/quarterWidth[@type=\'wide\']/quarter', 'type'); + break; + + case 'quarter': + if (empty($value)) { + $value = array("gregorian", "format", "wide"); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/quarters/quarterContext[@type=\'' . $value[1] . '\']/quarterWidth[@type=\'' . $value[2] . '\']/quarter', 'type'); + break; + + case 'eras': + if (empty($value)) { + $value = "gregorian"; + } + $temp['names'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraNames/era', 'type'); + $temp['abbreviated'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraAbbr/era', 'type'); + $temp['narrow'] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/eras/eraNarrow/era', 'type'); + break; + + case 'era': + if (empty($value)) { + $value = array("gregorian", "Abbr"); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/eras/era' . $value[1] . '/era', 'type'); + break; + + case 'date': + if (empty($value)) { + $value = "gregorian"; + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'full\']/dateFormat/pattern', '', 'full'); + $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'long\']/dateFormat/pattern', '', 'long'); + $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'medium\']/dateFormat/pattern', '', 'medium'); + $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'short\']/dateFormat/pattern', '', 'short'); + break; + + case 'time': + if (empty($value)) { + $value = "gregorian"; + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'full\']/timeFormat/pattern', '', 'full'); + $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'long\']/timeFormat/pattern', '', 'long'); + $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'medium\']/timeFormat/pattern', '', 'medium'); + $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'short\']/timeFormat/pattern', '', 'short'); + break; + + case 'datetime': + if (empty($value)) { + $value = "gregorian"; + } + + $timefull = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'full\']/timeFormat/pattern', '', 'full'); + $timelong = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'long\']/timeFormat/pattern', '', 'long'); + $timemedi = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'medium\']/timeFormat/pattern', '', 'medi'); + $timeshor = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/timeFormatLength[@type=\'short\']/timeFormat/pattern', '', 'shor'); + + $datefull = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'full\']/dateFormat/pattern', '', 'full'); + $datelong = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'long\']/dateFormat/pattern', '', 'long'); + $datemedi = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'medium\']/dateFormat/pattern', '', 'medi'); + $dateshor = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/dateFormatLength[@type=\'short\']/dateFormat/pattern', '', 'shor'); + + $full = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'full\']/dateTimeFormat/pattern', '', 'full'); + $long = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'long\']/dateTimeFormat/pattern', '', 'long'); + $medi = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'medium\']/dateTimeFormat/pattern', '', 'medi'); + $shor = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'short\']/dateTimeFormat/pattern', '', 'shor'); + + $temp['full'] = str_replace(array('{0}', '{1}'), array($timefull['full'], $datefull['full']), $full['full']); + $temp['long'] = str_replace(array('{0}', '{1}'), array($timelong['long'], $datelong['long']), $long['long']); + $temp['medium'] = str_replace(array('{0}', '{1}'), array($timemedi['medi'], $datemedi['medi']), $medi['medi']); + $temp['short'] = str_replace(array('{0}', '{1}'), array($timeshor['shor'], $dateshor['shor']), $shor['shor']); + break; + + case 'dateitem': + if (empty($value)) { + $value = "gregorian"; + } + $_temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/availableFormats/dateFormatItem', 'id'); + foreach($_temp as $key => $found) { + $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/availableFormats/dateFormatItem[@id=\'' . $key . '\']', '', $key); + } + break; + + case 'dateinterval': + if (empty($value)) { + $value = "gregorian"; + } + $_temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/intervalFormats/intervalFormatItem', 'id'); + foreach($_temp as $key => $found) { + $temp[$key] = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateTimeFormats/intervalFormats/intervalFormatItem[@id=\'' . $key . '\']/greatestDifference', 'id'); + } + break; + + case 'field': + if (empty($value)) { + $value = "gregorian"; + } + $temp2 = self::_getFile($locale, '/ldml/dates/fields/field', 'type'); + // $temp2 = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/fields/field', 'type'); + foreach ($temp2 as $key => $keyvalue) { + $temp += self::_getFile($locale, '/ldml/dates/fields/field[@type=\'' . $key . '\']/displayName', '', $key); + // $temp += self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/fields/field[@type=\'' . $key . '\']/displayName', '', $key); + } + break; + + case 'relative': + if (empty($value)) { + $value = "day"; + } + $temp = self::_getFile($locale, '/ldml/dates/fields/field[@type=\'' . $value . '\']/relative', 'type'); + break; + + case 'symbols': + $temp = self::_getFile($locale, '/ldml/numbers/symbols/decimal', '', 'decimal'); + $temp += self::_getFile($locale, '/ldml/numbers/symbols/group', '', 'group'); + $temp += self::_getFile($locale, '/ldml/numbers/symbols/list', '', 'list'); + $temp += self::_getFile($locale, '/ldml/numbers/symbols/percentSign', '', 'percent'); + $temp += self::_getFile($locale, '/ldml/numbers/symbols/nativeZeroDigit', '', 'zero'); + $temp += self::_getFile($locale, '/ldml/numbers/symbols/patternDigit', '', 'pattern'); + $temp += self::_getFile($locale, '/ldml/numbers/symbols/plusSign', '', 'plus'); + $temp += self::_getFile($locale, '/ldml/numbers/symbols/minusSign', '', 'minus'); + $temp += self::_getFile($locale, '/ldml/numbers/symbols/exponential', '', 'exponent'); + $temp += self::_getFile($locale, '/ldml/numbers/symbols/perMille', '', 'mille'); + $temp += self::_getFile($locale, '/ldml/numbers/symbols/infinity', '', 'infinity'); + $temp += self::_getFile($locale, '/ldml/numbers/symbols/nan', '', 'nan'); + break; + + case 'nametocurrency': + $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type'); + foreach ($_temp as $key => $found) { + $temp += self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key); + } + break; + + case 'currencytoname': + $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type'); + foreach ($_temp as $key => $keyvalue) { + $val = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key); + if (!isset($val[$key])) { + continue; + } + if (!isset($temp[$val[$key]])) { + $temp[$val[$key]] = $key; + } else { + $temp[$val[$key]] .= " " . $key; + } + } + break; + + case 'currencysymbol': + $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type'); + foreach ($_temp as $key => $found) { + $temp += self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/symbol', '', $key); + } + break; + + case 'question': + $temp = self::_getFile($locale, '/ldml/posix/messages/yesstr', '', 'yes'); + $temp += self::_getFile($locale, '/ldml/posix/messages/nostr', '', 'no'); + break; + + case 'currencyfraction': + $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info', 'iso4217'); + foreach ($_temp as $key => $found) { + $temp += self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $key . '\']', 'digits', $key); + } + break; + + case 'currencyrounding': + $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info', 'iso4217'); + foreach ($_temp as $key => $found) { + $temp += self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $key . '\']', 'rounding', $key); + } + break; + + case 'currencytoregion': + $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166'); + foreach ($_temp as $key => $keyvalue) { + $temp += self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key); + } + break; + + case 'regiontocurrency': + $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166'); + foreach ($_temp as $key => $keyvalue) { + $val = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key); + if (!isset($val[$key])) { + continue; + } + if (!isset($temp[$val[$key]])) { + $temp[$val[$key]] = $key; + } else { + $temp[$val[$key]] .= " " . $key; + } + } + break; + + case 'regiontoterritory': + $_temp = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type'); + foreach ($_temp as $key => $found) { + $temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key); + } + break; + + case 'territorytoregion': + $_temp2 = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type'); + $_temp = array(); + foreach ($_temp2 as $key => $found) { + $_temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key); + } + foreach($_temp as $key => $found) { + $_temp3 = explode(" ", $found); + foreach($_temp3 as $found3) { + if (!isset($temp[$found3])) { + $temp[$found3] = (string) $key; + } else { + $temp[$found3] .= " " . $key; + } + } + } + break; + + case 'scripttolanguage': + $_temp = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type'); + foreach ($_temp as $key => $found) { + $temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key); + if (empty($temp[$key])) { + unset($temp[$key]); + } + } + break; + + case 'languagetoscript': + $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type'); + $_temp = array(); + foreach ($_temp2 as $key => $found) { + $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key); + } + foreach($_temp as $key => $found) { + $_temp3 = explode(" ", $found); + foreach($_temp3 as $found3) { + if (empty($found3)) { + continue; + } + if (!isset($temp[$found3])) { + $temp[$found3] = (string) $key; + } else { + $temp[$found3] .= " " . $key; + } + } + } + break; + + case 'territorytolanguage': + $_temp = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type'); + foreach ($_temp as $key => $found) { + $temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key); + if (empty($temp[$key])) { + unset($temp[$key]); + } + } + break; + + case 'languagetoterritory': + $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type'); + $_temp = array(); + foreach ($_temp2 as $key => $found) { + $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key); + } + foreach($_temp as $key => $found) { + $_temp3 = explode(" ", $found); + foreach($_temp3 as $found3) { + if (empty($found3)) { + continue; + } + if (!isset($temp[$found3])) { + $temp[$found3] = (string) $key; + } else { + $temp[$found3] .= " " . $key; + } + } + } + break; + + case 'timezonetowindows': + $_temp = self::_getFile('windowsZones', '/supplementalData/windowsZones/mapTimezones/mapZone', 'other'); + foreach ($_temp as $key => $found) { + $temp += self::_getFile('windowsZones', '/supplementalData/windowsZones/mapTimezones/mapZone[@other=\'' . $key . '\']', 'type', $key); + } + break; + + case 'windowstotimezone': + $_temp = self::_getFile('windowsZones', '/supplementalData/windowsZones/mapTimezones/mapZone', 'type'); + foreach ($_temp as $key => $found) { + $temp += self::_getFile('windowsZones', '/supplementalData/windowsZones/mapTimezones/mapZone[@type=\'' .$key . '\']', 'other', $key); + } + break; + + case 'territorytotimezone': + $_temp = self::_getFile('metaZones', '/supplementalData/metaZones/mapTimezones/mapZone', 'type'); + foreach ($_temp as $key => $found) { + $temp += self::_getFile('metaZones', '/supplementalData/metaZones/mapTimezones/mapZone[@type=\'' . $key . '\']', 'territory', $key); + } + break; + + case 'timezonetoterritory': + $_temp = self::_getFile('metaZones', '/supplementalData/metaZones/mapTimezones/mapZone', 'territory'); + foreach ($_temp as $key => $found) { + $temp += self::_getFile('metaZones', '/supplementalData/metaZones/mapTimezones/mapZone[@territory=\'' . $key . '\']', 'type', $key); + } + break; + + case 'citytotimezone': + $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type'); + foreach($_temp as $key => $found) { + $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key); + } + break; + + case 'timezonetocity': + $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type'); + $temp = array(); + foreach($_temp as $key => $found) { + $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key); + if (!empty($temp[$key])) { + $temp[$temp[$key]] = $key; + } + unset($temp[$key]); + } + break; + + case 'phonetoterritory': + $_temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory'); + foreach ($_temp as $key => $keyvalue) { + $temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key); + } + break; + + case 'territorytophone': + $_temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory'); + foreach ($_temp as $key => $keyvalue) { + $val = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key); + if (!isset($val[$key])) { + continue; + } + if (!isset($temp[$val[$key]])) { + $temp[$val[$key]] = $key; + } else { + $temp[$val[$key]] .= " " . $key; + } + } + break; + + case 'numerictoterritory': + $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'type'); + foreach ($_temp as $key => $keyvalue) { + $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $key . '\']', 'numeric', $key); + } + break; + + case 'territorytonumeric': + $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'numeric'); + foreach ($_temp as $key => $keyvalue) { + $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\'' . $key . '\']', 'type', $key); + } + break; + + case 'alpha3toterritory': + $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'type'); + foreach ($_temp as $key => $keyvalue) { + $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $key . '\']', 'alpha3', $key); + } + break; + + case 'territorytoalpha3': + $_temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes', 'alpha3'); + foreach ($_temp as $key => $keyvalue) { + $temp += self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\'' . $key . '\']', 'type', $key); + } + break; + + case 'postaltoterritory': + $_temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex', 'territoryId'); + foreach ($_temp as $key => $keyvalue) { + $temp += self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $key . '\']', 'territoryId'); + } + break; + + case 'numberingsystem': + $_temp = self::_getFile('numberingSystems', '/supplementalData/numberingSystems/numberingSystem', 'id'); + foreach ($_temp as $key => $keyvalue) { + $temp += self::_getFile('numberingSystems', '/supplementalData/numberingSystems/numberingSystem[@id=\'' . $key . '\']', 'digits', $key); + if (empty($temp[$key])) { + unset($temp[$key]); + } + } + break; + + case 'chartofallback': + $_temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character', 'value'); + foreach ($_temp as $key => $keyvalue) { + $temp2 = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $key . '\']/substitute', '', $key); + $temp[current($temp2)] = $key; + } + break; + + case 'fallbacktochar': + $_temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character', 'value'); + foreach ($_temp as $key => $keyvalue) { + $temp += self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $key . '\']/substitute', '', $key); + } + break; + + case 'localeupgrade': + $_temp = self::_getFile('likelySubtags', '/supplementalData/likelySubtags/likelySubtag', 'from'); + foreach ($_temp as $key => $keyvalue) { + $temp += self::_getFile('likelySubtags', '/supplementalData/likelySubtags/likelySubtag[@from=\'' . $key . '\']', 'to', $key); + } + break; + + case 'unit': + $_temp = self::_getFile($locale, '/ldml/units/unitLength/unit', 'type'); + foreach($_temp as $key => $keyvalue) { + $_temp2 = self::_getFile($locale, '/ldml/units/unitLength/unit[@type=\'' . $key . '\']/unitPattern', 'count'); + $temp[$key] = $_temp2; + } + break; + + default : + throw new Zend_Locale_Exception("Unknown list ($path) for parsing locale data."); + break; + } + + if (isset(self::$_cache)) { + if (self::$_cacheTags) { + self::$_cache->save( serialize($temp), $id, array('Zend_Locale')); + } else { + self::$_cache->save( serialize($temp), $id); + } + } + + return $temp; + } + + /** + * Read the LDML file, get a single path defined value + * + * @param string $locale + * @param string $path + * @param bool|string $value + * @return string + * @throws Zend_Locale_Exception + */ + public static function getContent($locale, $path, $value = false) + { + $locale = self::_checkLocale($locale); + + if (!isset(self::$_cache) && !self::$_cacheDisabled) { + self::$_cache = Zend_Cache::factory( + 'Core', + 'File', + array('automatic_serialization' => true), + array()); + } + + $val = $value; + if (is_array($value)) { + $val = implode('_' , $value); + } + $val = urlencode($val); + $id = self::_filterCacheId('Zend_LocaleC_' . $locale . '_' . $path . '_' . $val); + if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) { + return unserialize($result); + } + + switch(strtolower($path)) { + case 'language': + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language[@type=\'' . $value . '\']', 'type'); + break; + + case 'script': + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/scripts/script[@type=\'' . $value . '\']', 'type'); + break; + + case 'country': + case 'territory': + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/territories/territory[@type=\'' . $value . '\']', 'type'); + break; + + case 'variant': + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/variants/variant[@type=\'' . $value . '\']', 'type'); + break; + + case 'key': + $temp = self::_getFile($locale, '/ldml/localeDisplayNames/keys/key[@type=\'' . $value . '\']', 'type'); + break; + + case 'defaultcalendar': + $givenLocale = new Zend_Locale($locale); + $territory = $givenLocale->getRegion(); + unset($givenLocale); + $temp = self::_getFile('supplementalData', '/supplementalData/calendarPreferenceData/calendarPreference[contains(@territories,\'' . $territory . '\')]', 'ordering', 'ordering'); + if (isset($temp['ordering'])) { + list($temp) = explode(' ', $temp['ordering']); + } else { + $temp = 'gregorian'; + } + break; + + case 'monthcontext': + /* default context is always 'format' + if (empty ($value)) { + $value = "gregorian"; + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/default', 'choice', 'context'); + */ + $temp = 'format'; + break; + + case 'defaultmonth': + /* default width is always 'wide' + if (empty ($value)) { + $value = "gregorian"; + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/default', 'choice', 'default'); + */ + $temp = 'wide'; + break; + + case 'month': + if (!is_array($value)) { + $temp = $value; + $value = array("gregorian", "format", "wide", $temp); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/months/monthContext[@type=\'' . $value[1] . '\']/monthWidth[@type=\'' . $value[2] . '\']/month[@type=\'' . $value[3] . '\']', 'type'); + break; + + case 'daycontext': + /* default context is always 'format' + if (empty($value)) { + $value = "gregorian"; + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/default', 'choice', 'context'); + */ + $temp = 'format'; + break; + + case 'defaultday': + /* default width is always 'wide' + if (empty($value)) { + $value = "gregorian"; + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/default', 'choice', 'default'); + */ + $temp = 'wide'; + break; + + case 'day': + if (!is_array($value)) { + $temp = $value; + $value = array("gregorian", "format", "wide", $temp); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/days/dayContext[@type=\'' . $value[1] . '\']/dayWidth[@type=\'' . $value[2] . '\']/day[@type=\'' . $value[3] . '\']', 'type'); + break; + + case 'quarter': + if (!is_array($value)) { + $temp = $value; + $value = array("gregorian", "format", "wide", $temp); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/quarters/quarterContext[@type=\'' . $value[1] . '\']/quarterWidth[@type=\'' . $value[2] . '\']/quarter[@type=\'' . $value[3] . '\']', 'type'); + break; + + case 'am': + if (empty($value)) { + $value = array("gregorian", "format", "wide"); + } + if (!is_array($value)) { + $temp = $value; + $value = array($temp, "format", "wide"); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dayPeriods/dayPeriodContext[@type=\'' . $value[1] . '\']/dayPeriodWidth[@type=\'' . $value[2] . '\']/dayPeriod[@type=\'am\']', '', 'dayPeriod'); + break; + + case 'pm': + if (empty($value)) { + $value = array("gregorian", "format", "wide"); + } + if (!is_array($value)) { + $temp = $value; + $value = array($temp, "format", "wide"); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dayPeriods/dayPeriodContext[@type=\'' . $value[1] . '\']/dayPeriodWidth[@type=\'' . $value[2] . '\']/dayPeriod[@type=\'pm\']', '', 'dayPeriod'); + break; + + case 'era': + if (!is_array($value)) { + $temp = $value; + $value = array("gregorian", "Abbr", $temp); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/eras/era' . $value[1] . '/era[@type=\'' . $value[2] . '\']', 'type'); + break; + + case 'defaultdate': + /* default choice is deprecated in CDLR - should be always medium here + if (empty($value)) { + $value = "gregorian"; + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/default', 'choice', 'default'); + */ + $temp = 'medium'; + break; + + case 'date': + if (empty($value)) { + $value = array("gregorian", "medium"); + } + if (!is_array($value)) { + $temp = $value; + $value = array("gregorian", $temp); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateFormats/dateFormatLength[@type=\'' . $value[1] . '\']/dateFormat/pattern', '', 'pattern'); + break; + + case 'defaulttime': + /* default choice is deprecated in CDLR - should be always medium here + if (empty($value)) { + $value = "gregorian"; + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/default', 'choice', 'default'); + */ + $temp = 'medium'; + break; + + case 'time': + if (empty($value)) { + $value = array("gregorian", "medium"); + } + if (!is_array($value)) { + $temp = $value; + $value = array("gregorian", $temp); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/timeFormats/timeFormatLength[@type=\'' . $value[1] . '\']/timeFormat/pattern', '', 'pattern'); + break; + + case 'datetime': + if (empty($value)) { + $value = array("gregorian", "medium"); + } + if (!is_array($value)) { + $temp = $value; + $value = array("gregorian", $temp); + } + + $date = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateFormats/dateFormatLength[@type=\'' . $value[1] . '\']/dateFormat/pattern', '', 'pattern'); + $time = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/timeFormats/timeFormatLength[@type=\'' . $value[1] . '\']/timeFormat/pattern', '', 'pattern'); + $datetime = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'' . $value[1] . '\']/dateTimeFormat/pattern', '', 'pattern'); + $temp = str_replace(array('{0}', '{1}'), array(current($time), current($date)), current($datetime)); + break; + + case 'dateitem': + if (empty($value)) { + $value = array("gregorian", "yyMMdd"); + } + if (!is_array($value)) { + $temp = $value; + $value = array("gregorian", $temp); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateTimeFormats/availableFormats/dateFormatItem[@id=\'' . $value[1] . '\']', ''); + break; + + case 'dateinterval': + if (empty($value)) { + $value = array("gregorian", "yMd", "y"); + } + if (!is_array($value)) { + $temp = $value; + $value = array("gregorian", $temp, $temp[0]); + } + $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateTimeFormats/intervalFormats/intervalFormatItem[@id=\'' . $value[1] . '\']/greatestDifference[@id=\'' . $value[2] . '\']', ''); + break; + + case 'field': + if (!is_array($value)) { + $temp = $value; + $value = array("gregorian", $temp); + } + $temp = self::_getFile($locale, '/ldml/dates/fields/field[@type=\'' . $value[1] . '\']/displayName', '', $value[1]); + break; + + case 'relative': + if (!is_array($value)) { + $temp = $value; + $value = array("gregorian", $temp); + } + $temp = self::_getFile($locale, '/ldml/dates/fields/field[@type=\'day\']/relative[@type=\'' . $value[1] . '\']', '', $value[1]); + // $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/fields/field/relative[@type=\'' . $value[1] . '\']', '', $value[1]); + break; + + case 'defaultnumberingsystem': + $temp = self::_getFile($locale, '/ldml/numbers/defaultNumberingSystem', '', 'default'); + break; + + case 'decimalnumber': + $temp = self::_getFile($locale, '/ldml/numbers/decimalFormats/decimalFormatLength/decimalFormat/pattern', '', 'default'); + break; + + case 'scientificnumber': + $temp = self::_getFile($locale, '/ldml/numbers/scientificFormats/scientificFormatLength/scientificFormat/pattern', '', 'default'); + break; + + case 'percentnumber': + $temp = self::_getFile($locale, '/ldml/numbers/percentFormats/percentFormatLength/percentFormat/pattern', '', 'default'); + break; + + case 'currencynumber': + $temp = self::_getFile($locale, '/ldml/numbers/currencyFormats/currencyFormatLength/currencyFormat/pattern', '', 'default'); + break; + + case 'nametocurrency': + $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value); + break; + + case 'currencytoname': + $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value); + $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type'); + $temp = array(); + foreach ($_temp as $key => $keyvalue) { + $val = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key); + if (!isset($val[$key]) or ($val[$key] != $value)) { + continue; + } + if (!isset($temp[$val[$key]])) { + $temp[$val[$key]] = $key; + } else { + $temp[$val[$key]] .= " " . $key; + } + } + break; + + case 'currencysymbol': + $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/symbol', '', $value); + break; + + case 'question': + $temp = self::_getFile($locale, '/ldml/posix/messages/' . $value . 'str', '', $value); + break; + + case 'currencyfraction': + if (empty($value)) { + $value = "DEFAULT"; + } + $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'digits', 'digits'); + break; + + case 'currencyrounding': + if (empty($value)) { + $value = "DEFAULT"; + } + $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'rounding', 'rounding'); + break; + + case 'currencytoregion': + $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $value . '\']/currency', 'iso4217', $value); + break; + + case 'regiontocurrency': + $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166'); + $temp = array(); + foreach ($_temp as $key => $keyvalue) { + $val = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key); + if (!isset($val[$key]) or ($val[$key] != $value)) { + continue; + } + if (!isset($temp[$val[$key]])) { + $temp[$val[$key]] = $key; + } else { + $temp[$val[$key]] .= " " . $key; + } + } + break; + + case 'regiontoterritory': + $temp = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $value . '\']', 'contains', $value); + break; + + case 'territorytoregion': + $_temp2 = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type'); + $_temp = array(); + foreach ($_temp2 as $key => $found) { + $_temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key); + } + $temp = array(); + foreach($_temp as $key => $found) { + $_temp3 = explode(" ", $found); + foreach($_temp3 as $found3) { + if ($found3 !== $value) { + continue; + } + if (!isset($temp[$found3])) { + $temp[$found3] = (string) $key; + } else { + $temp[$found3] .= " " . $key; + } + } + } + break; + + case 'scripttolanguage': + $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'scripts', $value); + break; + + case 'languagetoscript': + $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type'); + $_temp = array(); + foreach ($_temp2 as $key => $found) { + $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key); + } + $temp = array(); + foreach($_temp as $key => $found) { + $_temp3 = explode(" ", $found); + foreach($_temp3 as $found3) { + if ($found3 !== $value) { + continue; + } + if (!isset($temp[$found3])) { + $temp[$found3] = (string) $key; + } else { + $temp[$found3] .= " " . $key; + } + } + } + break; + + case 'territorytolanguage': + $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'territories', $value); + break; + + case 'languagetoterritory': + $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type'); + $_temp = array(); + foreach ($_temp2 as $key => $found) { + $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key); + } + $temp = array(); + foreach($_temp as $key => $found) { + $_temp3 = explode(" ", $found); + foreach($_temp3 as $found3) { + if ($found3 !== $value) { + continue; + } + if (!isset($temp[$found3])) { + $temp[$found3] = (string) $key; + } else { + $temp[$found3] .= " " . $key; + } + } + } + break; + + case 'timezonetowindows': + $temp = self::_getFile('windowsZones', '/supplementalData/windowsZones/mapTimezones/mapZone[@other=\''.$value.'\']', 'type', $value); + break; + + case 'windowstotimezone': + $temp = self::_getFile('windowsZones', '/supplementalData/windowsZones/mapTimezones/mapZone[@type=\''.$value.'\']', 'other', $value); + break; + + case 'territorytotimezone': + $temp = self::_getFile('metaZones', '/supplementalData/metaZones/mapTimezones/mapZone[@type=\'' . $value . '\']', 'territory', $value); + break; + + case 'timezonetoterritory': + $temp = self::_getFile('metaZones', '/supplementalData/metaZones/mapTimezones/mapZone[@territory=\'' . $value . '\']', 'type', $value); + break; + + case 'citytotimezone': + $temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $value . '\']/exemplarCity', '', $value); + break; + + case 'timezonetocity': + $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type'); + $temp = array(); + foreach($_temp as $key => $found) { + $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key); + if (!empty($temp[$key])) { + if ($temp[$key] == $value) { + $temp[$temp[$key]] = $key; + } + } + unset($temp[$key]); + } + break; + + case 'phonetoterritory': + $temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $value . '\']/telephoneCountryCode', 'code', $value); + break; + + case 'territorytophone': + $_temp2 = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory'); + $_temp = array(); + foreach ($_temp2 as $key => $found) { + $_temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key); + } + $temp = array(); + foreach($_temp as $key => $found) { + $_temp3 = explode(" ", $found); + foreach($_temp3 as $found3) { + if ($found3 !== $value) { + continue; + } + if (!isset($temp[$found3])) { + $temp[$found3] = (string) $key; + } else { + $temp[$found3] .= " " . $key; + } + } + } + break; + + case 'numerictoterritory': + $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\''.$value.'\']', 'numeric', $value); + break; + + case 'territorytonumeric': + $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\''.$value.'\']', 'type', $value); + break; + + case 'alpha3toterritory': + $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\''.$value.'\']', 'alpha3', $value); + break; + + case 'territorytoalpha3': + $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\''.$value.'\']', 'type', $value); + break; + + case 'postaltoterritory': + $temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $value . '\']', 'territoryId'); + break; + + case 'numberingsystem': + $temp = self::_getFile('numberingSystems', '/supplementalData/numberingSystems/numberingSystem[@id=\'' . strtolower($value) . '\']', 'digits', $value); + break; + + case 'chartofallback': + $_temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character', 'value'); + foreach ($_temp as $key => $keyvalue) { + $temp2 = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $key . '\']/substitute', '', $key); + if (current($temp2) == $value) { + $temp = $key; + } + } + break; + + $temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $value . '\']/substitute', '', $value); + break; + + case 'fallbacktochar': + $temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $value . '\']/substitute', ''); + break; + + case 'localeupgrade': + $temp = self::_getFile('likelySubtags', '/supplementalData/likelySubtags/likelySubtag[@from=\'' . $value . '\']', 'to', $value); + break; + + case 'unit': + $temp = self::_getFile($locale, '/ldml/units/unitLength/unit[@type=\'' . $value[0] . '\']/unitPattern[@count=\'' . $value[1] . '\']', ''); + break; + + case 'parentlocale': + if (false === $value) { + $value = $locale; + } + $temp = self::_getFile('supplementalData', "/supplementalData/parentLocales/parentLocale[contains(@locales, '" . $value . "')]", 'parent', 'parent'); + break; + + default : + throw new Zend_Locale_Exception("Unknown detail ($path) for parsing locale data."); + break; + } + + if (is_array($temp)) { + $temp = current($temp); + } + if (isset(self::$_cache)) { + if (self::$_cacheTags) { + self::$_cache->save( serialize($temp), $id, array('Zend_Locale')); + } else { + self::$_cache->save( serialize($temp), $id); + } + } + + return $temp; + } + + /** + * Returns the set cache + * + * @return Zend_Cache_Core The set cache + */ + public static function getCache() + { + return self::$_cache; + } + + /** + * Set a cache for Zend_Locale_Data + * + * @param Zend_Cache_Core $cache A cache frontend + */ + public static function setCache(Zend_Cache_Core $cache) + { + self::$_cache = $cache; + self::_getTagSupportForCache(); + } + + /** + * Returns true when a cache is set + * + * @return boolean + */ + public static function hasCache() + { + if (self::$_cache !== null) { + return true; + } + + return false; + } + + /** + * Removes any set cache + * + * @return void + */ + public static function removeCache() + { + self::$_cache = null; + } + + /** + * Clears all set cache data + * + * @return void + */ + public static function clearCache() + { + if (self::$_cacheTags) { + self::$_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('Zend_Locale')); + } else { + self::$_cache->clean(Zend_Cache::CLEANING_MODE_ALL); + } + } + + /** + * Disables the cache + * + * @param bool $flag + */ + public static function disableCache($flag) + { + self::$_cacheDisabled = (boolean) $flag; + } + + /** + * Internal method to check if the given cache supports tags + * + * @return bool + */ + private static function _getTagSupportForCache() + { + $backend = self::$_cache->getBackend(); + if ($backend instanceof Zend_Cache_Backend_ExtendedInterface) { + $cacheOptions = $backend->getCapabilities(); + self::$_cacheTags = $cacheOptions['tags']; + } else { + self::$_cacheTags = false; + } + + return self::$_cacheTags; + } + + /** + * Filter an ID to only allow valid variable characters + * + * @param string $value + * @return string + */ + protected static function _filterCacheId($value) + { + return strtr( + $value, + array( + '-' => '_', + '%' => '_', + '+' => '_', + '.' => '_', + ) + ); + } +} diff --git a/library/vendor/Zend/Locale/Data/Translation.php b/library/vendor/Zend/Locale/Data/Translation.php new file mode 100644 index 0000000..ceb16a9 --- /dev/null +++ b/library/vendor/Zend/Locale/Data/Translation.php @@ -0,0 +1,285 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Locale + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** + * Definition class for all Windows locales + * + * Based on this two lists: + * @link http://msdn.microsoft.com/en-us/library/39cwe7zf.aspx + * @link http://msdn.microsoft.com/en-us/library/cdax410z.aspx + * @link http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx + * @link http://msdn.microsoft.com/en-us/goglobal/bb895996.aspx + * + * @category Zend + * @package Zend_Locale + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Locale_Data_Translation +{ + /** + * Locale Translation for Full Named Locales + * + * @var array $localeTranslation + */ + public static $languageTranslation = array( + 'Afrikaans' => 'af', + 'Albanian' => 'sq', + 'Amharic' => 'am', + 'Arabic' => 'ar', + 'Armenian' => 'hy', + 'Assamese' => 'as', + 'Azeri' => 'az', + 'Azeri Latin' => 'az_Latn', + 'Azeri Cyrillic' => 'az_Cyrl', + 'Basque' => 'eu', + 'Belarusian' => 'be', + 'Bengali' => 'bn', + 'Bengali Latin' => 'bn_Latn', + 'Bosnian' => 'bs', + 'Bulgarian' => 'bg', + 'Burmese' => 'my', + 'Catalan' => 'ca', + 'Cherokee' => 'chr', + 'Chinese' => 'zh', + 'Croatian' => 'hr', + 'Czech' => 'cs', + 'Danish' => 'da', + 'Divehi' => 'dv', + 'Dutch' => 'nl', + 'English' => 'en', + 'Estonian' => 'et', + 'Faroese' => 'fo', + 'Faeroese' => 'fo', + 'Farsi' => 'fa', + 'Filipino' => 'fil', + 'Finnish' => 'fi', + 'French' => 'fr', + 'Frisian' => 'fy', + 'Gaelic' => 'gd', + 'Galician' => 'gl', + 'Georgian' => 'ka', + 'German' => 'de', + 'Greek' => 'el', + 'Guarani' => 'gn', + 'Gujarati' => 'gu', + 'Hausa' => 'ha', + 'Hawaiian' => 'haw', + 'Hebrew' => 'he', + 'Hindi' => 'hi', + 'Hungarian' => 'hu', + 'Icelandic' => 'is', + 'Igbo' => 'ig', + 'Indonesian' => 'id', + 'Inuktitut' => 'iu', + 'Italian' => 'it', + 'Japanese' => 'ja', + 'Kannada' => 'kn', + 'Kanuri' => 'kr', + 'Kashmiri' => 'ks', + 'Kazakh' => 'kk', + 'Khmer' => 'km', + 'Konkani' => 'kok', + 'Korean' => 'ko', + 'Kyrgyz' => 'ky', + 'Lao' => 'lo', + 'Latin' => 'la', + 'Latvian' => 'lv', + 'Lithuanian' => 'lt', + 'Macedonian' => 'mk', + 'Malay' => 'ms', + 'Malayalam' => 'ml', + 'Maltese' => 'mt', + 'Manipuri' => 'mni', + 'Maori' => 'mi', + 'Marathi' => 'mr', + 'Mongolian' => 'mn', + 'Nepali' => 'ne', + 'Norwegian' => 'no', + 'Norwegian Bokmal' => 'nb', + 'Norwegian Nynorsk' => 'nn', + 'Oriya' => 'or', + 'Oromo' => 'om', + 'Papiamentu' => 'pap', + 'Pashto' => 'ps', + 'Polish' => 'pl', + 'Portuguese' => 'pt', + 'Punjabi' => 'pa', + 'Quecha' => 'qu', + 'Quechua' => 'qu', + 'Rhaeto-Romanic' => 'rm', + 'Romanian' => 'ro', + 'Russian' => 'ru', + 'Sami' => 'smi', + 'Sami Inari' => 'smn', + 'Sami Lule' => 'smj', + 'Sami Northern' => 'se', + 'Sami Skolt' => 'sms', + 'Sami Southern' => 'sma', + 'Sanskrit' => 'sa', + 'Serbian' => 'sr', + 'Serbian Latin' => 'sr_Latn', + 'Serbian Cyrillic' => 'sr_Cyrl', + 'Sindhi' => 'sd', + 'Sinhalese' => 'si', + 'Slovak' => 'sk', + 'Slovenian' => 'sl', + 'Somali' => 'so', + 'Sorbian' => 'wen', + 'Spanish' => 'es', + 'Swahili' => 'sw', + 'Swedish' => 'sv', + 'Syriac' => 'syr', + 'Tajik' => 'tg', + 'Tamazight' => 'tmh', + 'Tamil' => 'ta', + 'Tatar' => 'tt', + 'Telugu' => 'te', + 'Thai' => 'th', + 'Tibetan' => 'bo', + 'Tigrigna' => 'ti', + 'Tsonga' => 'ts', + 'Tswana' => 'tn', + 'Turkish' => 'tr', + 'Turkmen' => 'tk', + 'Uighur' => 'ug', + 'Ukrainian' => 'uk', + 'Urdu' => 'ur', + 'Uzbek' => 'uz', + 'Uzbek Latin' => 'uz_Latn', + 'Uzbek Cyrillic' => 'uz_Cyrl', + 'Venda' => 've', + 'Vietnamese' => 'vi', + 'Welsh' => 'cy', + 'Xhosa' => 'xh', + 'Yiddish' => 'yi', + 'Yoruba' => 'yo', + 'Zulu' => 'zu', + ); + + public static $regionTranslation = array( + 'Albania' => 'AL', + 'Algeria' => 'DZ', + 'Argentina' => 'AR', + 'Armenia' => 'AM', + 'Australia' => 'AU', + 'Austria' => 'AT', + 'Bahrain' => 'BH', + 'Bangladesh' => 'BD', + 'Belgium' => 'BE', + 'Belize' => 'BZ', + 'Bhutan' => 'BT', + 'Bolivia' => 'BO', + 'Bosnia Herzegovina' => 'BA', + 'Brazil' => 'BR', + 'Brazilian' => 'BR', + 'Brunei Darussalam' => 'BN', + 'Cameroon' => 'CM', + 'Canada' => 'CA', + 'Chile' => 'CL', + 'China' => 'CN', + 'Colombia' => 'CO', + 'Costa Rica' => 'CR', + "Cote d'Ivoire" => 'CI', + 'Czech Republic' => 'CZ', + 'Dominican Republic' => 'DO', + 'Denmark' => 'DK', + 'Ecuador' => 'EC', + 'Egypt' => 'EG', + 'El Salvador' => 'SV', + 'Eritrea' => 'ER', + 'Ethiopia' => 'ET', + 'Finland' => 'FI', + 'France' => 'FR', + 'Germany' => 'DE', + 'Greece' => 'GR', + 'Guatemala' => 'GT', + 'Haiti' => 'HT', + 'Honduras' => 'HN', + 'Hong Kong' => 'HK', + 'Hong Kong SAR' => 'HK', + 'Hungary' => 'HU', + 'Iceland' => 'IS', + 'India' => 'IN', + 'Indonesia' => 'ID', + 'Iran' => 'IR', + 'Iraq' => 'IQ', + 'Ireland' => 'IE', + 'Italy' => 'IT', + 'Jamaica' => 'JM', + 'Japan' => 'JP', + 'Jordan' => 'JO', + 'Korea' => 'KR', + 'Kuwait' => 'KW', + 'Lebanon' => 'LB', + 'Libya' => 'LY', + 'Liechtenstein' => 'LI', + 'Luxembourg' => 'LU', + 'Macau' => 'MO', + 'Macao SAR' => 'MO', + 'Malaysia' => 'MY', + 'Mali' => 'ML', + 'Mexico' => 'MX', + 'Moldava' => 'MD', + 'Monaco' => 'MC', + 'Morocco' => 'MA', + 'Netherlands' => 'NL', + 'New Zealand' => 'NZ', + 'Nicaragua' => 'NI', + 'Nigeria' => 'NG', + 'Norway' => 'NO', + 'Oman' => 'OM', + 'Pakistan' => 'PK', + 'Panama' => 'PA', + 'Paraguay' => 'PY', + "People's Republic of China" => 'CN', + 'Peru' => 'PE', + 'Philippines' => 'PH', + 'Poland' => 'PL', + 'Portugal' => 'PT', + 'PRC' => 'CN', + 'Puerto Rico' => 'PR', + 'Qatar' => 'QA', + 'Reunion' => 'RE', + 'Russia' => 'RU', + 'Saudi Arabia' => 'SA', + 'Senegal' => 'SN', + 'Singapore' => 'SG', + 'Slovakia' => 'SK', + 'South Africa' => 'ZA', + 'Spain' => 'ES', + 'Sri Lanka' => 'LK', + 'Sweden' => 'SE', + 'Switzerland' => 'CH', + 'Syria' => 'SY', + 'Taiwan' => 'TW', + 'The Netherlands' => 'NL', + 'Trinidad' => 'TT', + 'Tunisia' => 'TN', + 'UAE' => 'AE', + 'United Kingdom' => 'GB', + 'United States' => 'US', + 'Uruguay' => 'UY', + 'Venezuela' => 'VE', + 'Yemen' => 'YE', + 'Zimbabwe' => 'ZW', + ); +} diff --git a/library/vendor/Zend/Locale/Exception.php b/library/vendor/Zend/Locale/Exception.php new file mode 100644 index 0000000..05c543f --- /dev/null +++ b/library/vendor/Zend/Locale/Exception.php @@ -0,0 +1,36 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Locale + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id$ + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + + +/** + * Zend_Exception + */ + + +/** + * @category Zend + * @package Zend_Locale + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Locale_Exception extends Zend_Exception +{ +} diff --git a/library/vendor/Zend/Locale/Format.php b/library/vendor/Zend/Locale/Format.php new file mode 100644 index 0000000..a1baf6e --- /dev/null +++ b/library/vendor/Zend/Locale/Format.php @@ -0,0 +1,1321 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Locale + * @subpackage Format + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id$ + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * include needed classes + */ + +/** + * @category Zend + * @package Zend_Locale + * @subpackage Format + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Locale_Format +{ + const STANDARD = 'auto'; + + private static $_options = array('date_format' => null, + 'number_format' => null, + 'format_type' => 'iso', + 'fix_date' => false, + 'locale' => null, + 'cache' => null, + 'disableCache' => null, + 'precision' => null); + + /** + * Sets class wide options, if no option was given, the actual set options will be returned + * The 'precision' option of a value is used to truncate or stretch extra digits. -1 means not to touch the extra digits. + * The 'locale' option helps when parsing numbers and dates using separators and month names. + * The date format 'format_type' option selects between CLDR/ISO date format specifier tokens and PHP's date() tokens. + * The 'fix_date' option enables or disables heuristics that attempt to correct invalid dates. + * The 'number_format' option can be used to specify a default number format string + * The 'date_format' option can be used to specify a default date format string, but beware of using getDate(), + * checkDateFormat() and getTime() after using setOptions() with a 'format'. To use these four methods + * with the default date format for a locale, use array('date_format' => null, 'locale' => $locale) for their options. + * + * @param array $options Array of options, keyed by option name: format_type = 'iso' | 'php', fix_date = true | false, + * locale = Zend_Locale | locale string, precision = whole number between -1 and 30 + * @throws Zend_Locale_Exception + * @return array if no option was given + */ + public static function setOptions(array $options = array()) + { + self::$_options = self::_checkOptions($options) + self::$_options; + return self::$_options; + } + + /** + * Internal function for checking the options array of proper input values + * See {@link setOptions()} for details. + * + * @param array $options Array of options, keyed by option name: format_type = 'iso' | 'php', fix_date = true | false, + * locale = Zend_Locale | locale string, precision = whole number between -1 and 30 + * @throws Zend_Locale_Exception + * @return array if no option was given + */ + private static function _checkOptions(array $options = array()) + { + if (count($options) == 0) { + return self::$_options; + } + foreach ($options as $name => $value) { + $name = strtolower($name); + if ($name !== 'locale') { + if (gettype($value) === 'string') { + $value = strtolower($value); + } + } + + switch($name) { + case 'number_format' : + if ($value == Zend_Locale_Format::STANDARD) { + $locale = self::$_options['locale']; + if (isset($options['locale'])) { + $locale = $options['locale']; + } + $options['number_format'] = Zend_Locale_Data::getContent($locale, 'decimalnumber'); + } else if ((gettype($value) !== 'string') and ($value !== NULL)) { + $stringValue = (string)(is_array($value) ? implode(' ', $value) : $value); + throw new Zend_Locale_Exception("Unknown number format type '" . gettype($value) . "'. " + . "Format '$stringValue' must be a valid number format string."); + } + break; + + case 'date_format' : + if ($value == Zend_Locale_Format::STANDARD) { + $locale = self::$_options['locale']; + if (isset($options['locale'])) { + $locale = $options['locale']; + } + $options['date_format'] = Zend_Locale_Format::getDateFormat($locale); + } else if ((gettype($value) !== 'string') and ($value !== NULL)) { + $stringValue = (string)(is_array($value) ? implode(' ', $value) : $value); + throw new Zend_Locale_Exception("Unknown dateformat type '" . gettype($value) . "'. " + . "Format '$stringValue' must be a valid ISO or PHP date format string."); + } else { + if (((isset($options['format_type']) === true) and ($options['format_type'] == 'php')) or + ((isset($options['format_type']) === false) and (self::$_options['format_type'] == 'php'))) { + $options['date_format'] = Zend_Locale_Format::convertPhpToIsoFormat($value); + } + } + break; + + case 'format_type' : + if (($value != 'php') && ($value != 'iso')) { + throw new Zend_Locale_Exception("Unknown date format type '$value'. Only 'iso' and 'php'" + . " are supported."); + } + break; + + case 'fix_date' : + if (($value !== true) && ($value !== false)) { + throw new Zend_Locale_Exception("Enabling correction of dates must be either true or false" + . "(fix_date='$value')."); + } + break; + + case 'locale' : + $options['locale'] = Zend_Locale::findLocale($value); + break; + + case 'cache' : + if ($value instanceof Zend_Cache_Core) { + Zend_Locale_Data::setCache($value); + } + break; + + case 'disablecache' : + if (null !== $value) { + Zend_Locale_Data::disableCache($value); + } + break; + + case 'precision' : + if ($value === NULL) { + $value = -1; + } + + if (($value < -1) || ($value > 30)) { + throw new Zend_Locale_Exception("'$value' precision is not a whole number less than 30."); + } + break; + + default: + throw new Zend_Locale_Exception("Unknown option: '$name' = '$value'"); + break; + + } + } + + return $options; + } + + /** + * Changes the numbers/digits within a given string from one script to another + * 'Decimal' representated the stardard numbers 0-9, if a script does not exist + * an exception will be thrown. + * + * Examples for conversion from Arabic to Latin numerals: + * convertNumerals('١١٠Tests', 'Arab'); -> returns '100 Tests' + * Example for conversion from Latin to Arabic numerals: + * convertNumerals('100 Tests', 'Latn', 'Arab'); -> returns '١١٠Tests' + * + * @param string $input String to convert + * @param string $from Script to parse, see {@link Zend_Locale::getScriptList()} for details. + * @param string $to OPTIONAL Script to convert to + * @return string Returns the converted input + * @throws Zend_Locale_Exception + */ + public static function convertNumerals($input, $from, $to = null) + { + if (!self::_getUniCodeSupport()) { + trigger_error("Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE); + } + + $from = strtolower($from); + $source = Zend_Locale_Data::getContent('en', 'numberingsystem', $from); + if (empty($source)) { + throw new Zend_Locale_Exception("Unknown script '$from'. Use 'Latn' for digits 0,1,2,3,4,5,6,7,8,9."); + } + + if ($to !== null) { + $to = strtolower($to); + $target = Zend_Locale_Data::getContent('en', 'numberingsystem', $to); + if (empty($target)) { + throw new Zend_Locale_Exception("Unknown script '$to'. Use 'Latn' for digits 0,1,2,3,4,5,6,7,8,9."); + } + } else { + $target = '0123456789'; + } + + for ($x = 0; $x < 10; ++$x) { + $asource[$x] = "/" . iconv_substr($source, $x, 1, 'UTF-8') . "/u"; + $atarget[$x] = iconv_substr($target, $x, 1, 'UTF-8'); + } + + return preg_replace($asource, $atarget, $input); + } + + /** + * Returns the normalized number from a localized one + * Parsing depends on given locale (grouping and decimal) + * + * Examples for input: + * '2345.4356,1234' = 23455456.1234 + * '+23,3452.123' = 233452.123 + * '12343 ' = 12343 + * '-9456' = -9456 + * '0' = 0 + * + * @param string $input Input string to parse for numbers + * @param array $options Options: locale, precision. See {@link setOptions()} for details. + * @return string Returns the extracted number + * @throws Zend_Locale_Exception + */ + public static function getNumber($input, array $options = array()) + { + $options = self::_checkOptions($options) + self::$_options; + if (!is_string($input)) { + return $input; + } + + if (!self::isNumber($input, $options)) { + throw new Zend_Locale_Exception('No localized value in ' . $input . ' found, or the given number does not match the localized format'); + } + + // Get correct signs for this locale + $symbols = Zend_Locale_Data::getList($options['locale'],'symbols'); + // Change locale input to be default number + if (($input[0] == $symbols['minus']) && ('-' != $input[0])) { + $input = '-' . substr($input, 1); + } + + $input = str_replace($symbols['group'],'', $input); + if (strpos($input, $symbols['decimal']) !== false) { + if ($symbols['decimal'] != '.') { + $input = str_replace($symbols['decimal'], ".", $input); + } + + $pre = substr($input, strpos($input, '.') + 1); + if ($options['precision'] === null) { + $options['precision'] = strlen($pre); + } + + if (strlen($pre) >= $options['precision']) { + $input = substr($input, 0, strlen($input) - strlen($pre) + $options['precision']); + } + + if (($options['precision'] == 0) && ($input[strlen($input) - 1] == '.')) { + $input = substr($input, 0, -1); + } + } + + return $input; + } + + /** + * Returns a locale formatted number depending on the given options. + * The seperation and fraction sign is used from the set locale. + * ##0.# -> 12345.12345 -> 12345.12345 + * ##0.00 -> 12345.12345 -> 12345.12 + * ##,##0.00 -> 12345.12345 -> 12,345.12 + * + * @param string $value Localized number string + * @param array $options Options: number_format, locale, precision. See {@link setOptions()} for details. + * @return string locale formatted number + * @throws Zend_Locale_Exception + */ + public static function toNumber($value, array $options = array()) + { + // load class within method for speed + + $value = Zend_Locale_Math::floatalize($value); + $value = Zend_Locale_Math::normalize($value); + $options = self::_checkOptions($options) + self::$_options; + $options['locale'] = (string) $options['locale']; + + // Get correct signs for this locale + $symbols = Zend_Locale_Data::getList($options['locale'], 'symbols'); + $oenc = self::_getEncoding(); + self::_setEncoding('UTF-8'); + + // Get format + $format = $options['number_format']; + if ($format === null) { + $format = Zend_Locale_Data::getContent($options['locale'], 'decimalnumber'); + $format = self::_seperateFormat($format, $value, $options['precision']); + + if ($options['precision'] !== null) { + $value = Zend_Locale_Math::normalize(Zend_Locale_Math::round($value, $options['precision'])); + } + } else { + // seperate negative format pattern when available + $format = self::_seperateFormat($format, $value, $options['precision']); + if (strpos($format, '.')) { + if (is_numeric($options['precision'])) { + $value = Zend_Locale_Math::round($value, $options['precision']); + } else { + if (substr($format, iconv_strpos($format, '.') + 1, 3) == '###') { + $options['precision'] = null; + } else { + $options['precision'] = iconv_strlen(iconv_substr($format, iconv_strpos($format, '.') + 1, + iconv_strrpos($format, '0') - iconv_strpos($format, '.'))); + $format = iconv_substr($format, 0, iconv_strpos($format, '.') + 1) . '###' + . iconv_substr($format, iconv_strrpos($format, '0') + 1); + } + } + } else { + $value = Zend_Locale_Math::round($value, 0); + $options['precision'] = 0; + } + $value = Zend_Locale_Math::normalize($value); + } + + if (iconv_strpos($format, '0') === false) { + self::_setEncoding($oenc); + throw new Zend_Locale_Exception('Wrong format... missing 0'); + } + + // get number parts + $pos = iconv_strpos($value, '.'); + if ($pos !== false) { + if ($options['precision'] === null) { + $precstr = iconv_substr($value, $pos + 1); + } else { + $precstr = iconv_substr($value, $pos + 1, $options['precision']); + if (iconv_strlen($precstr) < $options['precision']) { + $precstr = $precstr . str_pad("0", ($options['precision'] - iconv_strlen($precstr)), "0"); + } + } + } else { + if ($options['precision'] > 0) { + $precstr = str_pad("0", ($options['precision']), "0"); + } + } + + if ($options['precision'] === null) { + if (isset($precstr)) { + $options['precision'] = iconv_strlen($precstr); + } else { + $options['precision'] = 0; + } + } + + // get fraction and format lengths + if (strpos($value, '.') !== false) { + $number = substr((string) $value, 0, strpos($value, '.')); + } else { + $number = $value; + } + + $prec = call_user_func(Zend_Locale_Math::$sub, $value, $number, $options['precision']); + $prec = Zend_Locale_Math::floatalize($prec); + $prec = Zend_Locale_Math::normalize($prec); + if (iconv_strpos($prec, '-') !== false) { + $prec = iconv_substr($prec, 1); + } + + if (($prec == 0) and ($options['precision'] > 0)) { + $prec = "0.0"; + } + + if (($options['precision'] + 2) > iconv_strlen($prec)) { + $prec = str_pad((string) $prec, $options['precision'] + 2, "0", STR_PAD_RIGHT); + } + + if (iconv_strpos($number, '-') !== false) { + $number = iconv_substr($number, 1); + } + $group = iconv_strrpos($format, ','); + $group2 = iconv_strpos ($format, ','); + $point = iconv_strpos ($format, '0'); + // Add fraction + $rest = ""; + if (iconv_strpos($format, '.')) { + $rest = iconv_substr($format, iconv_strpos($format, '.') + 1); + $length = iconv_strlen($rest); + for($x = 0; $x < $length; ++$x) { + if (($rest[0] == '0') || ($rest[0] == '#')) { + $rest = iconv_substr($rest, 1); + } + } + $format = iconv_substr($format, 0, iconv_strlen($format) - iconv_strlen($rest)); + } + + if ($options['precision'] == '0') { + if (iconv_strrpos($format, '-') != 0) { + $format = iconv_substr($format, 0, $point) + . iconv_substr($format, iconv_strrpos($format, '#') + 2); + } else { + $format = iconv_substr($format, 0, $point); + } + } else { + $format = iconv_substr($format, 0, $point) . $symbols['decimal'] + . iconv_substr($prec, 2); + } + + $format .= $rest; + // Add seperation + if ($group == 0) { + // no seperation + $format = $number . iconv_substr($format, $point); + } else if ($group == $group2) { + // only 1 seperation + $seperation = ($point - $group); + for ($x = iconv_strlen($number); $x > $seperation; $x -= $seperation) { + if (iconv_substr($number, 0, $x - $seperation) !== "") { + $number = iconv_substr($number, 0, $x - $seperation) . $symbols['group'] + . iconv_substr($number, $x - $seperation); + } + } + $format = iconv_substr($format, 0, iconv_strpos($format, '#')) . $number . iconv_substr($format, $point); + } else { + + // 2 seperations + if (iconv_strlen($number) > ($point - $group)) { + $seperation = ($point - $group); + $number = iconv_substr($number, 0, iconv_strlen($number) - $seperation) . $symbols['group'] + . iconv_substr($number, iconv_strlen($number) - $seperation); + + if ((iconv_strlen($number) - 1) > ($point - $group + 1)) { + $seperation2 = ($group - $group2 - 1); + for ($x = iconv_strlen($number) - $seperation2 - 2; $x > $seperation2; $x -= $seperation2) { + $number = iconv_substr($number, 0, $x - $seperation2) . $symbols['group'] + . iconv_substr($number, $x - $seperation2); + } + } + + } + $format = iconv_substr($format, 0, iconv_strpos($format, '#')) . $number . iconv_substr($format, $point); + } + // set negative sign + if (call_user_func(Zend_Locale_Math::$comp, $value, 0, $options['precision']) < 0) { + if (iconv_strpos($format, '-') === false) { + $format = $symbols['minus'] . $format; + } else { + $format = str_replace('-', $symbols['minus'], $format); + } + } + + self::_setEncoding($oenc); + return (string) $format; + } + + /** + * @param string $format + * @param string $value + * @param int $precision + * @return string + */ + private static function _seperateFormat($format, $value, $precision) + { + if (iconv_strpos($format, ';') !== false) { + if (call_user_func(Zend_Locale_Math::$comp, $value, 0, $precision) < 0) { + $tmpformat = iconv_substr($format, iconv_strpos($format, ';') + 1); + if ($tmpformat[0] == '(') { + $format = iconv_substr($format, 0, iconv_strpos($format, ';')); + } else { + $format = $tmpformat; + } + } else { + $format = iconv_substr($format, 0, iconv_strpos($format, ';')); + } + } + + return $format; + } + + + /** + * Checks if the input contains a normalized or localized number + * + * @param string $input Localized number string + * @param array $options Options: locale. See {@link setOptions()} for details. + * @return boolean Returns true if a number was found + */ + public static function isNumber($input, array $options = array()) + { + if (!self::_getUniCodeSupport()) { + trigger_error("Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE); + } + + $options = self::_checkOptions($options) + self::$_options; + + // Get correct signs for this locale + $symbols = Zend_Locale_Data::getList($options['locale'],'symbols'); + + $regexs = Zend_Locale_Format::_getRegexForType('decimalnumber', $options); + $regexs = array_merge($regexs, Zend_Locale_Format::_getRegexForType('scientificnumber', $options)); + if (!empty($input) && ($input[0] == $symbols['decimal'])) { + $input = 0 . $input; + } + foreach ($regexs as $regex) { + preg_match($regex, $input, $found); + if (isset($found[0])) { + return true; + } + } + + return false; + } + + /** + * Internal method to convert cldr number syntax into regex + * + * @param string $type + * @param array $options Options: locale. See {@link setOptions()} for details. + * @return string + * @throws Zend_Locale_Exception + */ + private static function _getRegexForType($type, $options) + { + $decimal = Zend_Locale_Data::getContent($options['locale'], $type); + $decimal = preg_replace('/[^#0,;\.\-Ee]/u', '',$decimal); + $patterns = explode(';', $decimal); + + if (count($patterns) == 1) { + $patterns[1] = '-' . $patterns[0]; + } + + $symbols = Zend_Locale_Data::getList($options['locale'],'symbols'); + + foreach($patterns as $pkey => $pattern) { + $regex[$pkey] = '/^'; + $rest = 0; + $end = null; + if (strpos($pattern, '.') !== false) { + $end = substr($pattern, strpos($pattern, '.') + 1); + $pattern = substr($pattern, 0, -strlen($end) - 1); + } + + if (strpos($pattern, ',') !== false) { + $parts = explode(',', $pattern); + $count = count($parts); + foreach($parts as $key => $part) { + switch ($part) { + case '#': + case '-#': + if ($part[0] == '-') { + $regex[$pkey] .= '[' . $symbols['minus'] . '-]{0,1}'; + } else { + $regex[$pkey] .= '[' . $symbols['plus'] . '+]{0,1}'; + } + + if (($parts[$key + 1]) == '##0') { + $regex[$pkey] .= '[0-9]{1,3}'; + } else if (($parts[$key + 1]) == '##') { + $regex[$pkey] .= '[0-9]{1,2}'; + } else { + throw new Zend_Locale_Exception('Unsupported token for numberformat (Pos 1):"' . $pattern . '"'); + } + break; + case '##': + if ($parts[$key + 1] == '##0') { + $regex[$pkey] .= '(\\' . $symbols['group'] . '{0,1}[0-9]{2})*'; + } else { + throw new Zend_Locale_Exception('Unsupported token for numberformat (Pos 2):"' . $pattern . '"'); + } + break; + case '##0': + if ($parts[$key - 1] == '##') { + $regex[$pkey] .= '[0-9]'; + } else if (($parts[$key - 1] == '#') || ($parts[$key - 1] == '-#')) { + $regex[$pkey] .= '(\\' . $symbols['group'] . '{0,1}[0-9]{3})*'; + } else { + throw new Zend_Locale_Exception('Unsupported token for numberformat (Pos 3):"' . $pattern . '"'); + } + break; + case '#0': + if ($key == 0) { + $regex[$pkey] .= '[0-9]*'; + } else { + throw new Zend_Locale_Exception('Unsupported token for numberformat (Pos 4):"' . $pattern . '"'); + } + break; + } + } + } + + if (strpos($pattern, 'E') !== false) { + if (($pattern == '#E0') || ($pattern == '#E00')) { + $regex[$pkey] .= '[' . $symbols['plus']. '+]{0,1}[0-9]{1,}(\\' . $symbols['decimal'] . '[0-9]{1,})*[eE][' . $symbols['plus']. '+]{0,1}[0-9]{1,}'; + } else if (($pattern == '-#E0') || ($pattern == '-#E00')) { + $regex[$pkey] .= '[' . $symbols['minus']. '-]{0,1}[0-9]{1,}(\\' . $symbols['decimal'] . '[0-9]{1,})*[eE][' . $symbols['minus']. '-]{0,1}[0-9]{1,}'; + } else { + throw new Zend_Locale_Exception('Unsupported token for numberformat (Pos 5):"' . $pattern . '"'); + } + } + + if (!empty($end)) { + if ($end == '###') { + $regex[$pkey] .= '(\\' . $symbols['decimal'] . '{1}[0-9]{1,}){0,1}'; + } else if ($end == '###-') { + $regex[$pkey] .= '(\\' . $symbols['decimal'] . '{1}[0-9]{1,}){0,1}[' . $symbols['minus']. '-]'; + } else { + throw new Zend_Locale_Exception('Unsupported token for numberformat (Pos 6):"' . $pattern . '"'); + } + } + + $regex[$pkey] .= '$/u'; + } + + return $regex; + } + + /** + * Alias for getNumber + * + * @param string $input Number to localize + * @param array $options Options: locale, precision. See {@link setOptions()} for details. + * @return float + */ + public static function getFloat($input, array $options = array()) + { + return floatval(self::getNumber($input, $options)); + } + + /** + * Returns a locale formatted integer number + * Alias for toNumber() + * + * @param string $value Number to normalize + * @param array $options Options: locale, precision. See {@link setOptions()} for details. + * @return string Locale formatted number + */ + public static function toFloat($value, array $options = array()) + { + $options['number_format'] = Zend_Locale_Format::STANDARD; + return self::toNumber($value, $options); + } + + /** + * Returns if a float was found + * Alias for isNumber() + * + * @param string $value Localized number string + * @param array $options Options: locale. See {@link setOptions()} for details. + * @return boolean Returns true if a number was found + */ + public static function isFloat($value, array $options = array()) + { + return self::isNumber($value, $options); + } + + /** + * Returns the first found integer from an string + * Parsing depends on given locale (grouping and decimal) + * + * Examples for input: + * ' 2345.4356,1234' = 23455456 + * '+23,3452.123' = 233452 + * ' 12343 ' = 12343 + * '-9456km' = -9456 + * '0' = 0 + * '(-){0,1}(\d+(\.){0,1})*(\,){0,1})\d+' + * + * @param string $input Input string to parse for numbers + * @param array $options Options: locale. See {@link setOptions()} for details. + * @return integer Returns the extracted number + */ + public static function getInteger($input, array $options = array()) + { + $options['precision'] = 0; + return intval(self::getFloat($input, $options)); + } + + /** + * Returns a localized number + * + * @param string $value Number to normalize + * @param array $options Options: locale. See {@link setOptions()} for details. + * @return string Locale formatted number + */ + public static function toInteger($value, array $options = array()) + { + $options['precision'] = 0; + $options['number_format'] = Zend_Locale_Format::STANDARD; + return self::toNumber($value, $options); + } + + /** + * Returns if a integer was found + * + * @param string $value Localized number string + * @param array $options Options: locale. See {@link setOptions()} for details. + * @return boolean Returns true if a integer was found + */ + public static function isInteger($value, array $options = array()) + { + if (!self::isNumber($value, $options)) { + return false; + } + + if (self::getInteger($value, $options) == self::getFloat($value, $options)) { + return true; + } + + return false; + } + + /** + * Converts a format string from PHP's date format to ISO format + * Remember that Zend Date always returns localized string, so a month name which returns the english + * month in php's date() will return the translated month name with this function... use 'en' as locale + * if you are in need of the original english names + * + * The conversion has the following restrictions: + * 'a', 'A' - Meridiem is not explicit upper/lowercase, you have to upper/lowercase the translated value yourself + * + * @param string $format Format string in PHP's date format + * @return string Format string in ISO format + */ + public static function convertPhpToIsoFormat($format) + { + if ($format === null) { + return null; + } + + $convert = array( + 'd' => 'dd' , 'D' => 'EE' , 'j' => 'd' , 'l' => 'EEEE', + 'N' => 'eee' , 'S' => 'SS' , 'w' => 'e' , 'z' => 'D' , + 'W' => 'ww' , 'F' => 'MMMM', 'm' => 'MM' , 'M' => 'MMM' , + 'n' => 'M' , 't' => 'ddd' , 'L' => 'l' , 'o' => 'YYYY', + 'Y' => 'yyyy', 'y' => 'yy' , 'a' => 'a' , 'A' => 'a' , + 'B' => 'B' , 'g' => 'h' , 'G' => 'H' , 'h' => 'hh' , + 'H' => 'HH' , 'i' => 'mm' , 's' => 'ss' , 'e' => 'zzzz', + 'I' => 'I' , 'O' => 'Z' , 'P' => 'ZZZZ', 'T' => 'z' , + 'Z' => 'X' , 'c' => 'yyyy-MM-ddTHH:mm:ssZZZZ', 'r' => 'r', + 'U' => 'U', + ); + $escaped = false; + $inEscapedString = false; + $converted = array(); + foreach (str_split($format) as $char) { + if (!$escaped && $char == '\\') { + // Next char will be escaped: let's remember it + $escaped = true; + } elseif ($escaped) { + if (!$inEscapedString) { + // First escaped string: start the quoted chunk + $converted[] = "'"; + $inEscapedString = true; + } + // Since the previous char was a \ and we are in the quoted + // chunk, let's simply add $char as it is + $converted[] = $char; + $escaped = false; + } elseif ($char == "'") { + // Single quotes need to be escaped like this + $converted[] = "''"; + } else { + if ($inEscapedString) { + // Close the single-quoted chunk + $converted[] = "'"; + $inEscapedString = false; + } + // Convert the unescaped char if needed + if (isset($convert[$char])) { + $converted[] = $convert[$char]; + } else { + $converted[] = $char; + } + } + } + + return implode($converted); + } + + /** + * Parse date and split in named array fields + * + * @param string $date Date string to parse + * @param array $options Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details. + * @return array Possible array members: day, month, year, hour, minute, second, fixed, format + * @throws Zend_Locale_Exception + */ + private static function _parseDate($date, $options) + { + if (!self::_getUniCodeSupport()) { + trigger_error("Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE); + } + + $options = self::_checkOptions($options) + self::$_options; + $test = array('h', 'H', 'm', 's', 'y', 'Y', 'M', 'd', 'D', 'E', 'S', 'l', 'B', 'I', + 'X', 'r', 'U', 'G', 'w', 'e', 'a', 'A', 'Z', 'z', 'v'); + + $format = $options['date_format']; + $number = $date; // working copy + $result['date_format'] = $format; // save the format used to normalize $number (convenience) + $result['locale'] = $options['locale']; // save the locale used to normalize $number (convenience) + + $oenc = self::_getEncoding(); + self::_setEncoding('UTF-8'); + $day = iconv_strpos($format, 'd'); + $month = iconv_strpos($format, 'M'); + $year = iconv_strpos($format, 'y'); + $hour = iconv_strpos($format, 'H'); + $min = iconv_strpos($format, 'm'); + $sec = iconv_strpos($format, 's'); + $am = null; + if ($hour === false) { + $hour = iconv_strpos($format, 'h'); + } + if ($year === false) { + $year = iconv_strpos($format, 'Y'); + } + if ($day === false) { + $day = iconv_strpos($format, 'E'); + if ($day === false) { + $day = iconv_strpos($format, 'D'); + } + } + + if ($day !== false) { + $parse[$day] = 'd'; + if (!empty($options['locale']) && ($options['locale'] !== 'root') && + (!is_object($options['locale']) || ((string) $options['locale'] !== 'root'))) { + // erase day string + $daylist = Zend_Locale_Data::getList($options['locale'], 'day'); + foreach($daylist as $key => $name) { + if (iconv_strpos($number, $name) !== false) { + $number = str_replace($name, "EEEE", $number); + break; + } + } + } + } + $position = false; + + if ($month !== false) { + $parse[$month] = 'M'; + if (!empty($options['locale']) && ($options['locale'] !== 'root') && + (!is_object($options['locale']) || ((string) $options['locale'] !== 'root'))) { + // prepare to convert month name to their numeric equivalents, if requested, + // and we have a $options['locale'] + $position = self::_replaceMonth($number, Zend_Locale_Data::getList($options['locale'], + 'month')); + if ($position === false) { + $position = self::_replaceMonth($number, Zend_Locale_Data::getList($options['locale'], + 'month', array('gregorian', 'format', 'abbreviated'))); + } + } + } + if ($year !== false) { + $parse[$year] = 'y'; + } + if ($hour !== false) { + $parse[$hour] = 'H'; + } + if ($min !== false) { + $parse[$min] = 'm'; + } + if ($sec !== false) { + $parse[$sec] = 's'; + } + + if (empty($parse)) { + self::_setEncoding($oenc); + throw new Zend_Locale_Exception("Unknown date format, neither date nor time in '" . $format . "' found"); + } + ksort($parse); + + // get daytime + if (iconv_strpos($format, 'a') !== false) { + if (iconv_strpos(strtoupper($number), strtoupper(Zend_Locale_Data::getContent($options['locale'], 'am'))) !== false) { + $am = true; + } else if (iconv_strpos(strtoupper($number), strtoupper(Zend_Locale_Data::getContent($options['locale'], 'pm'))) !== false) { + $am = false; + } + } + + // split number parts + $split = false; + preg_match_all('/\d+/u', $number, $splitted); + + if (count($splitted[0]) == 0) { + self::_setEncoding($oenc); + throw new Zend_Locale_Exception("No date part in '$date' found."); + } + if (count($splitted[0]) == 1) { + $split = 0; + } + $cnt = 0; + foreach($parse as $key => $value) { + + switch($value) { + case 'd': + if ($split === false) { + if (count($splitted[0]) > $cnt) { + $result['day'] = $splitted[0][$cnt]; + } + } else { + $result['day'] = iconv_substr($splitted[0][0], $split, 2); + $split += 2; + } + ++$cnt; + break; + case 'M': + if ($split === false) { + if (count($splitted[0]) > $cnt) { + $result['month'] = $splitted[0][$cnt]; + } + } else { + $result['month'] = iconv_substr($splitted[0][0], $split, 2); + $split += 2; + } + ++$cnt; + break; + case 'y': + $length = 2; + if ((iconv_substr($format, $year, 4) == 'yyyy') + || (iconv_substr($format, $year, 4) == 'YYYY')) { + $length = 4; + } + + if ($split === false) { + if (count($splitted[0]) > $cnt) { + $result['year'] = $splitted[0][$cnt]; + } + } else { + $result['year'] = iconv_substr($splitted[0][0], $split, $length); + $split += $length; + } + + ++$cnt; + break; + case 'H': + if ($split === false) { + if (count($splitted[0]) > $cnt) { + $result['hour'] = $splitted[0][$cnt]; + } + } else { + $result['hour'] = iconv_substr($splitted[0][0], $split, 2); + $split += 2; + } + ++$cnt; + break; + case 'm': + if ($split === false) { + if (count($splitted[0]) > $cnt) { + $result['minute'] = $splitted[0][$cnt]; + } + } else { + $result['minute'] = iconv_substr($splitted[0][0], $split, 2); + $split += 2; + } + ++$cnt; + break; + case 's': + if ($split === false) { + if (count($splitted[0]) > $cnt) { + $result['second'] = $splitted[0][$cnt]; + } + } else { + $result['second'] = iconv_substr($splitted[0][0], $split, 2); + $split += 2; + } + ++$cnt; + break; + } + } + + // AM/PM correction + if ($hour !== false) { + if (($am === true) and ($result['hour'] == 12)){ + $result['hour'] = 0; + } else if (($am === false) and ($result['hour'] != 12)) { + $result['hour'] += 12; + } + } + + if ($options['fix_date'] === true) { + $result['fixed'] = 0; // nothing has been "fixed" by swapping date parts around (yet) + } + + if ($day !== false) { + // fix false month + if (isset($result['day']) and isset($result['month'])) { + if (($position !== false) and ((iconv_strpos($date, $result['day']) === false) or + (isset($result['year']) and (iconv_strpos($date, $result['year']) === false)))) { + if ($options['fix_date'] !== true) { + self::_setEncoding($oenc); + throw new Zend_Locale_Exception("Unable to parse date '$date' using '" . $format + . "' (false month, $position, $month)"); + } + $temp = $result['day']; + $result['day'] = $result['month']; + $result['month'] = $temp; + $result['fixed'] = 1; + } + } + + // fix switched values d <> y + if (isset($result['day']) and isset($result['year'])) { + if ($result['day'] > 31) { + if ($options['fix_date'] !== true) { + self::_setEncoding($oenc); + throw new Zend_Locale_Exception("Unable to parse date '$date' using '" + . $format . "' (d <> y)"); + } + $temp = $result['year']; + $result['year'] = $result['day']; + $result['day'] = $temp; + $result['fixed'] = 2; + } + } + + // fix switched values M <> y + if (isset($result['month']) and isset($result['year'])) { + if ($result['month'] > 31) { + if ($options['fix_date'] !== true) { + self::_setEncoding($oenc); + throw new Zend_Locale_Exception("Unable to parse date '$date' using '" + . $format . "' (M <> y)"); + } + $temp = $result['year']; + $result['year'] = $result['month']; + $result['month'] = $temp; + $result['fixed'] = 3; + } + } + + // fix switched values M <> d + if (isset($result['month']) and isset($result['day'])) { + if ($result['month'] > 12) { + if ($options['fix_date'] !== true || $result['month'] > 31) { + self::_setEncoding($oenc); + throw new Zend_Locale_Exception("Unable to parse date '$date' using '" + . $format . "' (M <> d)"); + } + $temp = $result['day']; + $result['day'] = $result['month']; + $result['month'] = $temp; + $result['fixed'] = 4; + } + } + } + + if (isset($result['year'])) { + if (((iconv_strlen($result['year']) == 2) && ($result['year'] < 10)) || + (((iconv_strpos($format, 'yy') !== false) && (iconv_strpos($format, 'yyyy') === false)) || + ((iconv_strpos($format, 'YY') !== false) && (iconv_strpos($format, 'YYYY') === false)))) { + if (($result['year'] >= 0) && ($result['year'] < 100)) { + if ($result['year'] < 70) { + $result['year'] = (int) $result['year'] + 100; + } + + $result['year'] = (int) $result['year'] + 1900; + } + } + } + + self::_setEncoding($oenc); + return $result; + } + + /** + * Search $number for a month name found in $monthlist, and replace if found. + * + * @param string $number Date string (modified) + * @param array $monthlist List of month names + * + * @return int|false Position of replaced string (false if nothing replaced) + */ + protected static function _replaceMonth(&$number, $monthlist) + { + // If $locale was invalid, $monthlist will default to a "root" identity + // mapping for each month number from 1 to 12. + // If no $locale was given, or $locale was invalid, do not use this identity mapping to normalize. + // Otherwise, translate locale aware month names in $number to their numeric equivalents. + $position = false; + if ($monthlist && $monthlist[1] != 1) { + foreach($monthlist as $key => $name) { + if (($position = iconv_strpos($number, $name, 0, 'UTF-8')) !== false) { + $number = str_ireplace($name, $key, $number); + return $position; + } + } + } + + return false; + } + + /** + * Returns the default date format for $locale. + * + * @param string|Zend_Locale $locale OPTIONAL Locale of $number, possibly in string form (e.g. 'de_AT') + * @return string format + * @throws Zend_Locale_Exception throws an exception when locale data is broken + */ + public static function getDateFormat($locale = null) + { + $format = Zend_Locale_Data::getContent($locale, 'date'); + if (empty($format)) { + throw new Zend_Locale_Exception("failed to receive data from locale $locale"); + } + + return $format; + } + + /** + * Returns an array with the normalized date from an locale date + * a input of 10.01.2006 without a $locale would return: + * array ('day' => 10, 'month' => 1, 'year' => 2006) + * The 'locale' option is only used to convert human readable day + * and month names to their numeric equivalents. + * The 'format' option allows specification of self-defined date formats, + * when not using the default format for the 'locale'. + * + * @param string $date Date string + * @param array $options Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details. + * @return array Possible array members: day, month, year, hour, minute, second, fixed, format + */ + public static function getDate($date, array $options = array()) + { + $options = self::_checkOptions($options) + self::$_options; + if (empty($options['date_format'])) { + $options['format_type'] = 'iso'; + $options['date_format'] = self::getDateFormat($options['locale']); + } + + return self::_parseDate($date, $options); + } + + /** + * Returns if the given datestring contains all date parts from the given format. + * If no format is given, the default date format from the locale is used + * If you want to check if the date is a proper date you should use Zend_Date::isDate() + * + * @param string $date Date string + * @param array $options Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details. + * @return boolean + */ + public static function checkDateFormat($date, array $options = array()) + { + try { + $date = self::getDate($date, $options); + } catch (Exception $e) { + return false; + } + + if (empty($options['date_format'])) { + $options['format_type'] = 'iso'; + $options['date_format'] = self::getDateFormat(isset($options['locale']) ? $options['locale'] : null); + } + $options = self::_checkOptions($options) + self::$_options; + + // day expected but not parsed + if ((iconv_strpos($options['date_format'], 'd', 0, 'UTF-8') !== false) and (!isset($date['day']) or ($date['day'] === ""))) { + return false; + } + + // month expected but not parsed + if ((iconv_strpos($options['date_format'], 'M', 0, 'UTF-8') !== false) and (!isset($date['month']) or ($date['month'] === ""))) { + return false; + } + + // year expected but not parsed + if (((iconv_strpos($options['date_format'], 'Y', 0, 'UTF-8') !== false) or + (iconv_strpos($options['date_format'], 'y', 0, 'UTF-8') !== false)) and (!isset($date['year']) or ($date['year'] === ""))) { + return false; + } + + // second expected but not parsed + if ((iconv_strpos($options['date_format'], 's', 0, 'UTF-8') !== false) and (!isset($date['second']) or ($date['second'] === ""))) { + return false; + } + + // minute expected but not parsed + if ((iconv_strpos($options['date_format'], 'm', 0, 'UTF-8') !== false) and (!isset($date['minute']) or ($date['minute'] === ""))) { + return false; + } + + // hour expected but not parsed + if (((iconv_strpos($options['date_format'], 'H', 0, 'UTF-8') !== false) or + (iconv_strpos($options['date_format'], 'h', 0, 'UTF-8') !== false)) and (!isset($date['hour']) or ($date['hour'] === ""))) { + return false; + } + + return true; + } + + /** + * Returns the default time format for $locale. + * + * @param string|Zend_Locale $locale OPTIONAL Locale of $number, possibly in string form (e.g. 'de_AT') + * @return string format + * @throws Zend_Locale_Exception + */ + public static function getTimeFormat($locale = null) + { + $format = Zend_Locale_Data::getContent($locale, 'time'); + if (empty($format)) { + throw new Zend_Locale_Exception("failed to receive data from locale $locale"); + } + return $format; + } + + /** + * Returns an array with 'hour', 'minute', and 'second' elements extracted from $time + * according to the order described in $format. For a format of 'H:i:s', and + * an input of 11:20:55, getTime() would return: + * array ('hour' => 11, 'minute' => 20, 'second' => 55) + * The optional $locale parameter may be used to help extract times from strings + * containing both a time and a day or month name. + * + * @param string $time Time string + * @param array $options Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details. + * @return array Possible array members: day, month, year, hour, minute, second, fixed, format + */ + public static function getTime($time, array $options = array()) + { + $options = self::_checkOptions($options) + self::$_options; + if (empty($options['date_format'])) { + $options['format_type'] = 'iso'; + $options['date_format'] = self::getTimeFormat($options['locale']); + } + return self::_parseDate($time, $options); + } + + /** + * Returns the default datetime format for $locale. + * + * @param string|Zend_Locale $locale OPTIONAL Locale of $number, possibly in string form (e.g. 'de_AT') + * @return string format + * @throws Zend_Locale_Exception + */ + public static function getDateTimeFormat($locale = null) + { + $format = Zend_Locale_Data::getContent($locale, 'datetime'); + if (empty($format)) { + throw new Zend_Locale_Exception("failed to receive data from locale $locale"); + } + return $format; + } + + /** + * Returns an array with 'year', 'month', 'day', 'hour', 'minute', and 'second' elements + * extracted from $datetime according to the order described in $format. For a format of 'd.M.y H:i:s', + * and an input of 10.05.1985 11:20:55, getDateTime() would return: + * array ('year' => 1985, 'month' => 5, 'day' => 10, 'hour' => 11, 'minute' => 20, 'second' => 55) + * The optional $locale parameter may be used to help extract times from strings + * containing both a time and a day or month name. + * + * @param string $datetime DateTime string + * @param array $options Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details. + * @return array Possible array members: day, month, year, hour, minute, second, fixed, format + */ + public static function getDateTime($datetime, array $options = array()) + { + $options = self::_checkOptions($options) + self::$_options; + if (empty($options['date_format'])) { + $options['format_type'] = 'iso'; + $options['date_format'] = self::getDateTimeFormat($options['locale']); + } + return self::_parseDate($datetime, $options); + } + + /** + * Internal method to detect of Unicode supports UTF8 + * which should be enabled within vanilla php installations + * + * @return boolean + */ + protected static function _getUniCodeSupport() + { + return (@preg_match('/\pL/u', 'a')) ? true : false; + } + + /** + * Internal method to retrieve the current encoding via the ini setting + * default_charset for PHP >= 5.6 or iconv_get_encoding otherwise. + * + * @return string + */ + protected static function _getEncoding() + { + $oenc = PHP_VERSION_ID < 50600 + ? iconv_get_encoding('internal_encoding') + : ini_get('default_charset'); + + return $oenc; + } + + /** + * Internal method to set the encoding via the ini setting + * default_charset for PHP >= 5.6 or iconv_set_encoding otherwise. + * + * @param string $encoding + * @return void + */ + protected static function _setEncoding($encoding) + { + if (PHP_VERSION_ID < 50600) { + iconv_set_encoding('internal_encoding', $encoding); + } else { + ini_set('default_charset', $encoding); + } + } +} diff --git a/library/vendor/Zend/Locale/Math.php b/library/vendor/Zend/Locale/Math.php new file mode 100644 index 0000000..1b61b07 --- /dev/null +++ b/library/vendor/Zend/Locale/Math.php @@ -0,0 +1,354 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Locale + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + + +/** + * Utility class for proxying math function to bcmath functions, if present, + * otherwise to PHP builtin math operators, with limited detection of overflow conditions. + * Sampling of PHP environments and platforms suggests that at least 80% to 90% support bcmath. + * Thus, this file should be as light as possible. + * + * @category Zend + * @package Zend_Locale + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +class Zend_Locale_Math +{ + // support unit testing without using bcmath functions + public static $_bcmathDisabled = false; + + public static $add = array('Zend_Locale_Math', 'Add'); + public static $sub = array('Zend_Locale_Math', 'Sub'); + public static $pow = array('Zend_Locale_Math', 'Pow'); + public static $mul = array('Zend_Locale_Math', 'Mul'); + public static $div = array('Zend_Locale_Math', 'Div'); + public static $comp = array('Zend_Locale_Math', 'Comp'); + public static $sqrt = array('Zend_Locale_Math', 'Sqrt'); + public static $mod = array('Zend_Locale_Math', 'Mod'); + public static $scale = 'bcscale'; + + public static function isBcmathDisabled() + { + return self::$_bcmathDisabled; + } + + /** + * Surprisingly, the results of this implementation of round() + * prove better than the native PHP round(). For example, try: + * round(639.795, 2); + * round(267.835, 2); + * round(0.302515, 5); + * round(0.36665, 4); + * then try: + * Zend_Locale_Math::round('639.795', 2); + */ + public static function round($op1, $precision = 0) + { + if (self::$_bcmathDisabled) { + $op1 = round($op1, $precision); + if (strpos((string) $op1, 'E') === false) { + return self::normalize(round($op1, $precision)); + } + } + + if (strpos($op1, 'E') !== false) { + $op1 = self::floatalize($op1); + } + + $op1 = trim(self::normalize($op1)); + $length = strlen($op1); + if (($decPos = strpos($op1, '.')) === false) { + $op1 .= '.0'; + $decPos = $length; + $length += 2; + } + if ($precision < 0 && abs($precision) > $decPos) { + return '0'; + } + + $digitsBeforeDot = $length - ($decPos + 1); + if ($precision >= ($length - ($decPos + 1))) { + return $op1; + } + + if ($precision === 0) { + $triggerPos = 1; + $roundPos = -1; + } elseif ($precision > 0) { + $triggerPos = $precision + 1; + $roundPos = $precision; + } else { + $triggerPos = $precision; + $roundPos = $precision -1; + } + + $triggerDigit = $op1[$triggerPos + $decPos]; + if ($precision < 0) { + // zero fill digits to the left of the decimal place + $op1 = substr($op1, 0, $decPos + $precision) . str_pad('', abs($precision), '0'); + } + + if ($triggerDigit >= '5') { + if ($roundPos + $decPos == -1) { + return str_pad('1', $decPos + 1, '0'); + } + + $roundUp = str_pad('', $length, '0'); + $roundUp[$decPos] = '.'; + $roundUp[$roundPos + $decPos] = '1'; + + if ($op1 > 0) { + if (self::$_bcmathDisabled) { + return Zend_Locale_Math_PhpMath::Add($op1, $roundUp, $precision); + } + return self::Add($op1, $roundUp, $precision); + } else { + if (self::$_bcmathDisabled) { + return Zend_Locale_Math_PhpMath::Sub($op1, $roundUp, $precision); + } + return self::Sub($op1, $roundUp, $precision); + } + } elseif ($precision >= 0) { + return substr($op1, 0, $decPos + ($precision ? $precision + 1: 0)); + } + + return (string) $op1; + } + + /** + * Convert a scientific notation to float + * Additionally fixed a problem with PHP <= 5.2.x with big integers + * + * @param string $value + */ + public static function floatalize($value) + { + $value = strtoupper($value); + if (strpos($value, 'E') === false) { + return $value; + } + + $number = substr($value, 0, strpos($value, 'E')); + if (strpos($number, '.') !== false) { + $post = strlen(substr($number, strpos($number, '.') + 1)); + $mantis = substr($value, strpos($value, 'E') + 1); + if ($mantis < 0) { + $post += abs((int) $mantis); + } + + $value = number_format($value, $post, '.', ''); + } else { + $value = number_format($value, 0, '.', ''); + } + + return $value; + } + + /** + * Normalizes an input to standard english notation + * Fixes a problem of BCMath with setLocale which is PHP related + * + * @param integer $value Value to normalize + * @return string Normalized string without BCMath problems + */ + public static function normalize($value) + { + $convert = localeconv(); + $value = str_replace($convert['thousands_sep'], "",(string) $value); + $value = str_replace($convert['positive_sign'], "", $value); + $value = str_replace($convert['decimal_point'], ".",$value); + if (!empty($convert['negative_sign']) and (strpos($value, $convert['negative_sign']))) { + $value = str_replace($convert['negative_sign'], "", $value); + $value = "-" . $value; + } + + return $value; + } + + /** + * Localizes an input from standard english notation + * Fixes a problem of BCMath with setLocale which is PHP related + * + * @param integer $value Value to normalize + * @return string Normalized string without BCMath problems + */ + public static function localize($value) + { + $convert = localeconv(); + $value = str_replace(".", $convert['decimal_point'], (string) $value); + if (!empty($convert['negative_sign']) and (strpos($value, "-"))) { + $value = str_replace("-", $convert['negative_sign'], $value); + } + return $value; + } + + /** + * Changes exponential numbers to plain string numbers + * Fixes a problem of BCMath with numbers containing exponents + * + * @param integer $value Value to erase the exponent + * @param integer $scale (Optional) Scale to use + * @return string + */ + public static function exponent($value, $scale = null) + { + if (!extension_loaded('bcmath')) { + return $value; + } + + $split = explode('e', $value); + if (count($split) == 1) { + $split = explode('E', $value); + } + + if (count($split) > 1) { + $value = bcmul($split[0], bcpow(10, $split[1], $scale), $scale); + } + + return $value; + } + + /** + * BCAdd - fixes a problem of BCMath and exponential numbers + * + * @param string $op1 + * @param string $op2 + * @param integer $scale + * @return string + */ + public static function Add($op1, $op2, $scale = null) + { + $op1 = self::exponent($op1, $scale); + $op2 = self::exponent($op2, $scale); + + return bcadd($op1, $op2, $scale); + } + + /** + * BCSub - fixes a problem of BCMath and exponential numbers + * + * @param string $op1 + * @param string $op2 + * @param integer $scale + * @return string + */ + public static function Sub($op1, $op2, $scale = null) + { + $op1 = self::exponent($op1, $scale); + $op2 = self::exponent($op2, $scale); + return bcsub($op1, $op2, $scale); + } + + /** + * BCPow - fixes a problem of BCMath and exponential numbers + * + * @param string $op1 + * @param string $op2 + * @param integer $scale + * @return string + */ + public static function Pow($op1, $op2, $scale = null) + { + $op1 = self::exponent($op1, $scale); + $op2 = self::exponent($op2, $scale); + return bcpow($op1, $op2, $scale); + } + + /** + * BCMul - fixes a problem of BCMath and exponential numbers + * + * @param string $op1 + * @param string $op2 + * @param integer $scale + * @return string + */ + public static function Mul($op1, $op2, $scale = null) + { + $op1 = self::exponent($op1, $scale); + $op2 = self::exponent($op2, $scale); + return bcmul($op1, $op2, $scale); + } + + /** + * BCDiv - fixes a problem of BCMath and exponential numbers + * + * @param string $op1 + * @param string $op2 + * @param integer $scale + * @return string + */ + public static function Div($op1, $op2, $scale = null) + { + $op1 = self::exponent($op1, $scale); + $op2 = self::exponent($op2, $scale); + return bcdiv($op1, $op2, $scale); + } + + /** + * BCSqrt - fixes a problem of BCMath and exponential numbers + * + * @param string $op1 + * @param integer $scale + * @return string + */ + public static function Sqrt($op1, $scale = null) + { + $op1 = self::exponent($op1, $scale); + return bcsqrt($op1, $scale); + } + + /** + * BCMod - fixes a problem of BCMath and exponential numbers + * + * @param string $op1 + * @param string $op2 + * @return string + */ + public static function Mod($op1, $op2) + { + $op1 = self::exponent($op1); + $op2 = self::exponent($op2); + return bcmod($op1, $op2); + } + + /** + * BCComp - fixes a problem of BCMath and exponential numbers + * + * @param string $op1 + * @param string $op2 + * @param integer $scale + * @return string + */ + public static function Comp($op1, $op2, $scale = null) + { + $op1 = self::exponent($op1, $scale); + $op2 = self::exponent($op2, $scale); + return bccomp($op1, $op2, $scale); + } +} + +if (!extension_loaded('bcmath') + || (defined('TESTS_ZEND_LOCALE_BCMATH_ENABLED') && !TESTS_ZEND_LOCALE_BCMATH_ENABLED) +) { + Zend_Locale_Math_PhpMath::disable(); +} diff --git a/library/vendor/Zend/Locale/Math/Exception.php b/library/vendor/Zend/Locale/Math/Exception.php new file mode 100644 index 0000000..fbf6c55 --- /dev/null +++ b/library/vendor/Zend/Locale/Math/Exception.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Locale + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id$ + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + + +/** + * Zend_Exception + */ + + +/** + * @category Zend + * @package Zend_Locale + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Locale_Math_Exception extends Zend_Locale_Exception +{ + protected $op1 = null; + protected $op2 = null; + protected $result = null; + + public function __construct($message, $op1 = null, $op2 = null, $result = null) + { + $this->op1 = $op1; + $this->op2 = $op2; + $this->result = $result; + parent::__construct($message); + } + + public function getResults() + { + return array($this->op1, $this->op2, $this->result); + } +} diff --git a/library/vendor/Zend/Locale/Math/PhpMath.php b/library/vendor/Zend/Locale/Math/PhpMath.php new file mode 100644 index 0000000..6d774c2 --- /dev/null +++ b/library/vendor/Zend/Locale/Math/PhpMath.php @@ -0,0 +1,239 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Locale + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + + +/** + * Utility class for proxying math function to bcmath functions, if present, + * otherwise to PHP builtin math operators, with limited detection of overflow conditions. + * Sampling of PHP environments and platforms suggests that at least 80% to 90% support bcmath. + * This file should only be loaded for the 10% to 20% lacking access to the bcmath extension. + * + * @category Zend + * @package Zend_Locale + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Locale_Math_PhpMath extends Zend_Locale_Math +{ + public static function disable() + { + self::$_bcmathDisabled = true; + self::$add = array('Zend_Locale_Math_PhpMath', 'Add'); + self::$sub = array('Zend_Locale_Math_PhpMath', 'Sub'); + self::$pow = array('Zend_Locale_Math_PhpMath', 'Pow'); + self::$mul = array('Zend_Locale_Math_PhpMath', 'Mul'); + self::$div = array('Zend_Locale_Math_PhpMath', 'Div'); + self::$comp = array('Zend_Locale_Math_PhpMath', 'Comp'); + self::$sqrt = array('Zend_Locale_Math_PhpMath', 'Sqrt'); + self::$mod = array('Zend_Locale_Math_PhpMath', 'Mod'); + self::$scale = array('Zend_Locale_Math_PhpMath', 'Scale'); + + self::$defaultScale = 0; + self::$defaultPrecision = 1; + } + + public static $defaultScale; + public static $defaultPrecision; + + + public static function Add($op1, $op2, $scale = null) + { + if ($scale === null) { + $scale = Zend_Locale_Math_PhpMath::$defaultScale; + $precision = Zend_Locale_Math_PhpMath::$defaultPrecision; + } else { + $precision = pow(10, -$scale); + } + + if (empty($op1)) { + $op1 = 0; + } + $op1 = self::normalize($op1); + $op2 = self::normalize($op2); + $result = $op1 + $op2; + if (is_infinite($result) or (abs($result - $op2 - $op1) > $precision)) { + throw new Zend_Locale_Math_Exception("addition overflow: $op1 + $op2 != $result", $op1, $op2, $result); + } + + return self::round(self::normalize($result), $scale); + } + + public static function Sub($op1, $op2, $scale = null) + { + if ($scale === null) { + $scale = Zend_Locale_Math_PhpMath::$defaultScale; + $precision = Zend_Locale_Math_PhpMath::$defaultPrecision; + } else { + $precision = pow(10, -$scale); + } + + if (empty($op1)) { + $op1 = 0; + } + $op1 = self::normalize($op1); + $op2 = self::normalize($op2); + $result = $op1 - $op2; + if (is_infinite($result) or (abs($result + $op2 - $op1) > $precision)) { + throw new Zend_Locale_Math_Exception("subtraction overflow: $op1 - $op2 != $result", $op1, $op2, $result); + } + + return self::round(self::normalize($result), $scale); + } + + public static function Pow($op1, $op2, $scale = null) + { + if ($scale === null) { + $scale = Zend_Locale_Math_PhpMath::$defaultScale; + } + + $op1 = self::normalize($op1); + $op2 = self::normalize($op2); + + // BCMath extension doesn't use decimal part of the power + // Provide the same behavior + $op2 = ($op2 > 0) ? floor($op2) : ceil($op2); + + $result = pow($op1, $op2); + if (is_infinite($result) or is_nan($result)) { + throw new Zend_Locale_Math_Exception("power overflow: $op1 ^ $op2", $op1, $op2, $result); + } + + return self::round(self::normalize($result), $scale); + } + + public static function Mul($op1, $op2, $scale = null) + { + if ($scale === null) { + $scale = Zend_Locale_Math_PhpMath::$defaultScale; + } + + if (empty($op1)) { + $op1 = 0; + } + $op1 = self::normalize($op1); + $op2 = self::normalize($op2); + $result = $op1 * $op2; + if (is_infinite($result) or is_nan($result)) { + throw new Zend_Locale_Math_Exception("multiplication overflow: $op1 * $op2 != $result", $op1, $op2, $result); + } + + return self::round(self::normalize($result), $scale); + } + + public static function Div($op1, $op2, $scale = null) + { + if ($scale === null) { + $scale = Zend_Locale_Math_PhpMath::$defaultScale; + } + + if (empty($op2)) { + throw new Zend_Locale_Math_Exception("can not divide by zero", $op1, $op2, null); + } + if (empty($op1)) { + $op1 = 0; + } + $op1 = self::normalize($op1); + $op2 = self::normalize($op2); + $result = $op1 / $op2; + if (is_infinite($result) or is_nan($result)) { + throw new Zend_Locale_Math_Exception("division overflow: $op1 / $op2 != $result", $op1, $op2, $result); + } + + return self::round(self::normalize($result), $scale); + } + + public static function Sqrt($op1, $scale = null) + { + if ($scale === null) { + $scale = Zend_Locale_Math_PhpMath::$defaultScale; + } + + if (empty($op1)) { + $op1 = 0; + } + $op1 = self::normalize($op1); + $result = sqrt($op1); + if (is_nan($result)) { + return NULL; + } + + return self::round(self::normalize($result), $scale); + } + + public static function Mod($op1, $op2) + { + if (empty($op1)) { + $op1 = 0; + } + if (empty($op2)) { + return NULL; + } + $op1 = self::normalize($op1); + $op2 = self::normalize($op2); + if ((int)$op2 == 0) { + return NULL; + } + $result = $op1 % $op2; + if (is_nan($result) or (($op1 - $result) % $op2 != 0)) { + throw new Zend_Locale_Math_Exception("modulus calculation error: $op1 % $op2 != $result", $op1, $op2, $result); + } + + return self::normalize($result); + } + + public static function Comp($op1, $op2, $scale = null) + { + if ($scale === null) { + $scale = Zend_Locale_Math_PhpMath::$defaultScale; + } + + if (empty($op1)) { + $op1 = 0; + } + $op1 = self::normalize($op1); + $op2 = self::normalize($op2); + if ($scale <> 0) { + $op1 = self::round($op1, $scale); + $op2 = self::round($op2, $scale); + } else { + $op1 = ($op1 > 0) ? floor($op1) : ceil($op1); + $op2 = ($op2 > 0) ? floor($op2) : ceil($op2); + } + if ($op1 > $op2) { + return 1; + } else if ($op1 < $op2) { + return -1; + } + return 0; + } + + public static function Scale($scale) + { + if ($scale > 9) { + throw new Zend_Locale_Math_Exception("can not scale to precision $scale", $scale, null, null); + } + self::$defaultScale = $scale; + self::$defaultPrecision = pow(10, -$scale); + return true; + } +} + +Zend_Locale_Math_PhpMath::disable(); // disable use of bcmath functions |