Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage
  • Mage_Adminhtml_Block_Html_Date
  • Mage_Adminhtml_Block_Html_Select
  • Mage_Api_Model_Wsdl_Config_Element
  • Mage_Captcha_Adminhtml_RefreshController
  • Mage_Captcha_RefreshController
  • Mage_Core_AjaxController
  • Mage_Core_Block_Abstract
  • Mage_Core_Block_Flush
  • Mage_Core_Block_Html_Calendar
  • Mage_Core_Block_Html_Date
  • Mage_Core_Block_Html_Link
  • Mage_Core_Block_Html_Select
  • Mage_Core_Block_Messages
  • Mage_Core_Block_Profiler
  • Mage_Core_Block_Store_Switcher
  • Mage_Core_Block_Template
  • Mage_Core_Block_Template_Facade
  • Mage_Core_Block_Template_Smarty
  • Mage_Core_Block_Template_Zend
  • Mage_Core_Block_Text
  • Mage_Core_Block_Text_List
  • Mage_Core_Block_Text_List_Item
  • Mage_Core_Block_Text_List_Link
  • Mage_Core_Block_Text_Tag
  • Mage_Core_Block_Text_Tag_Css
  • Mage_Core_Block_Text_Tag_Css_Admin
  • Mage_Core_Block_Text_Tag_Debug
  • Mage_Core_Block_Text_Tag_Js
  • Mage_Core_Block_Text_Tag_Meta
  • Mage_Core_Controller_Front_Action
  • Mage_Core_Controller_Front_Router
  • Mage_Core_Controller_Request_Http
  • Mage_Core_Controller_Response_Http
  • Mage_Core_Controller_Varien_Action
  • Mage_Core_Controller_Varien_Front
  • Mage_Core_Controller_Varien_Router_Abstract
  • Mage_Core_Controller_Varien_Router_Admin
  • Mage_Core_Controller_Varien_Router_Default
  • Mage_Core_Controller_Varien_Router_Standard
  • Mage_Core_Helper_Abstract
  • Mage_Core_Helper_Cookie
  • Mage_Core_Helper_Data
  • Mage_Core_Helper_File_Storage
  • Mage_Core_Helper_File_Storage_Database
  • Mage_Core_Helper_Hint
  • Mage_Core_Helper_Http
  • Mage_Core_Helper_Js
  • Mage_Core_Helper_String
  • Mage_Core_Helper_Translate
  • Mage_Core_Helper_Url
  • Mage_Core_Helper_Url_Rewrite
  • Mage_Core_IndexController
  • Mage_Core_Model_Abstract
  • Mage_Core_Model_App
  • Mage_Core_Model_App_Area
  • Mage_Core_Model_App_Emulation
  • Mage_Core_Model_Cache
  • Mage_Core_Model_Calculator
  • Mage_Core_Model_Config
  • Mage_Core_Model_Config_Base
  • Mage_Core_Model_Config_Data
  • Mage_Core_Model_Config_Element
  • Mage_Core_Model_Config_Options
  • Mage_Core_Model_Config_System
  • Mage_Core_Model_Cookie
  • Mage_Core_Model_Date
  • Mage_Core_Model_Design
  • Mage_Core_Model_Design_Package
  • Mage_Core_Model_Design_Source_Design
  • Mage_Core_Model_Email
  • Mage_Core_Model_Email_Info
  • Mage_Core_Model_Email_Template
  • Mage_Core_Model_Email_Template_Filter
  • Mage_Core_Model_Email_Template_Mailer
  • Mage_Core_Model_Email_Transport
  • Mage_Core_Model_Encryption
  • Mage_Core_Model_File_Storage
  • Mage_Core_Model_File_Storage_Abstract
  • Mage_Core_Model_File_Storage_Database
  • Mage_Core_Model_File_Storage_Database_Abstract
  • Mage_Core_Model_File_Storage_Directory_Database
  • Mage_Core_Model_File_Storage_File
  • Mage_Core_Model_File_Storage_Flag
  • Mage_Core_Model_File_Uploader
  • Mage_Core_Model_File_Validator_AvailablePath
  • Mage_Core_Model_File_Validator_NotProtectedExtension
  • Mage_Core_Model_Flag
  • Mage_Core_Model_Input_Filter
  • Mage_Core_Model_Input_Filter_MaliciousCode
  • Mage_Core_Model_Language
  • Mage_Core_Model_Layout
  • Mage_Core_Model_Layout_Data
  • Mage_Core_Model_Layout_Element
  • Mage_Core_Model_Layout_Update
  • Mage_Core_Model_Locale
  • Mage_Core_Model_Locale_Config
  • Mage_Core_Model_Log_Adapter
  • Mage_Core_Model_Magento_Api
  • Mage_Core_Model_Magento_Api_V2
  • Mage_Core_Model_Message
  • Mage_Core_Model_Message_Abstract
  • Mage_Core_Model_Message_Collection
  • Mage_Core_Model_Message_Error
  • Mage_Core_Model_Message_Notice
  • Mage_Core_Model_Message_Success
  • Mage_Core_Model_Message_Warning
  • Mage_Core_Model_Mysql4_Abstract
  • Mage_Core_Model_Mysql4_Cache
  • Mage_Core_Model_Mysql4_Collection_Abstract
  • Mage_Core_Model_Mysql4_Config
  • Mage_Core_Model_Mysql4_Config_Data
  • Mage_Core_Model_Mysql4_Config_Data_Collection
  • Mage_Core_Model_Mysql4_Design
  • Mage_Core_Model_Mysql4_Design_Collection
  • Mage_Core_Model_Mysql4_Design_Package_Collection
  • Mage_Core_Model_Mysql4_Design_Theme
  • Mage_Core_Model_Mysql4_Email_Template
  • Mage_Core_Model_Mysql4_Email_Template_Collection
  • Mage_Core_Model_Mysql4_File_Storage_Abstract
  • Mage_Core_Model_Mysql4_File_Storage_Database
  • Mage_Core_Model_Mysql4_File_Storage_Directory_Database
  • Mage_Core_Model_Mysql4_File_Storage_File
  • Mage_Core_Model_Mysql4_Flag
  • Mage_Core_Model_Mysql4_Language
  • Mage_Core_Model_Mysql4_Language_Collection
  • Mage_Core_Model_Mysql4_Layout
  • Mage_Core_Model_Mysql4_Resource
  • Mage_Core_Model_Mysql4_Session
  • Mage_Core_Model_Mysql4_Store
  • Mage_Core_Model_Mysql4_Store_Collection
  • Mage_Core_Model_Mysql4_Store_Group
  • Mage_Core_Model_Mysql4_Store_Group_Collection
  • Mage_Core_Model_Mysql4_Translate
  • Mage_Core_Model_Mysql4_Translate_String
  • Mage_Core_Model_Mysql4_Url_Rewrite
  • Mage_Core_Model_Mysql4_Url_Rewrite_Collection
  • Mage_Core_Model_Mysql4_Variable
  • Mage_Core_Model_Mysql4_Variable_Collection
  • Mage_Core_Model_Mysql4_Website
  • Mage_Core_Model_Mysql4_Website_Collection
  • Mage_Core_Model_Observer
  • Mage_Core_Model_Resource
  • Mage_Core_Model_Resource_Abstract
  • Mage_Core_Model_Resource_Cache
  • Mage_Core_Model_Resource_Config
  • Mage_Core_Model_Resource_Config_Data
  • Mage_Core_Model_Resource_Config_Data_Collection
  • Mage_Core_Model_Resource_Db_Abstract
  • Mage_Core_Model_Resource_Db_Collection_Abstract
  • Mage_Core_Model_Resource_Design
  • Mage_Core_Model_Resource_Design_Collection
  • Mage_Core_Model_Resource_Design_Package_Collection
  • Mage_Core_Model_Resource_Email_Template
  • Mage_Core_Model_Resource_Email_Template_Collection
  • Mage_Core_Model_Resource_Entity_Abstract
  • Mage_Core_Model_Resource_Entity_Table
  • Mage_Core_Model_Resource_File_Storage_Abstract
  • Mage_Core_Model_Resource_File_Storage_Database
  • Mage_Core_Model_Resource_File_Storage_Directory_Database
  • Mage_Core_Model_Resource_File_Storage_File
  • Mage_Core_Model_Resource_Flag
  • Mage_Core_Model_Resource_Helper_Abstract
  • Mage_Core_Model_Resource_Helper_Mysql4
  • Mage_Core_Model_Resource_Iterator
  • Mage_Core_Model_Resource_Language
  • Mage_Core_Model_Resource_Language_Collection
  • Mage_Core_Model_Resource_Layout
  • Mage_Core_Model_Resource_Resource
  • Mage_Core_Model_Resource_Session
  • Mage_Core_Model_Resource_Setup
  • Mage_Core_Model_Resource_Setup_Query_Modifier
  • Mage_Core_Model_Resource_Store
  • Mage_Core_Model_Resource_Store_Collection
  • Mage_Core_Model_Resource_Store_Group
  • Mage_Core_Model_Resource_Store_Group_Collection
  • Mage_Core_Model_Resource_Transaction
  • Mage_Core_Model_Resource_Translate
  • Mage_Core_Model_Resource_Translate_String
  • Mage_Core_Model_Resource_Type_Abstract
  • Mage_Core_Model_Resource_Type_Db
  • Mage_Core_Model_Resource_Type_Db_Mysqli
  • Mage_Core_Model_Resource_Type_Db_Mysqli_Setup
  • Mage_Core_Model_Resource_Type_Db_Pdo_Mysql
  • Mage_Core_Model_Resource_Url_Rewrite
  • Mage_Core_Model_Resource_Url_Rewrite_Collection
  • Mage_Core_Model_Resource_Variable
  • Mage_Core_Model_Resource_Variable_Collection
  • Mage_Core_Model_Resource_Website
  • Mage_Core_Model_Resource_Website_Collection
  • Mage_Core_Model_Session
  • Mage_Core_Model_Session_Abstract
  • Mage_Core_Model_Session_Abstract_Varien
  • Mage_Core_Model_Session_Abstract_Zend
  • Mage_Core_Model_Source_Email_Variables
  • Mage_Core_Model_Store
  • Mage_Core_Model_Store_Api
  • Mage_Core_Model_Store_Api_V2
  • Mage_Core_Model_Store_Group
  • Mage_Core_Model_Template
  • Mage_Core_Model_Translate
  • Mage_Core_Model_Translate_Expr
  • Mage_Core_Model_Translate_Inline
  • Mage_Core_Model_Translate_String
  • Mage_Core_Model_Url
  • Mage_Core_Model_Url_Rewrite
  • Mage_Core_Model_Url_Validator
  • Mage_Core_Model_Variable
  • Mage_Core_Model_Variable_Config
  • Mage_Core_Model_Variable_Observer
  • Mage_Core_Model_Website
  • Mage_Page_Block_Switch
  • Mage_Page_Block_Template_Container
  • Mage_Page_Block_Template_Links
  • Mage_Page_Block_Template_Links_Block
  • Mage_Sales_Model_Quote_Address_Total_Collector

Exceptions

  • Mage_Core_Controller_Varien_Exception
  • Mage_Core_Exception
  • Mage_Core_Model_Session_Exception
  • Mage_Core_Model_Store_Exception

Functions

  • destruct
  • is_dir_writeable
  • is_empty_date
  • mageCoreErrorHandler
  • mageDebugBacktrace
  • mageDelTree
  • mageFindClassFile
  • mageParseCsv
  • mageSendErrorFooter
  • mageSendErrorHeader
  • mageUndoMagicQuotes
  • now
  • sys_get_temp_dir
  • uc_words
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Core
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Locale model
 29:  *
 30:  * @author      Magento Core Team <core@magentocommerce.com>
 31:  */
 32: class Mage_Core_Model_Locale
 33: {
 34:     /**
 35:      * Default locale name
 36:      */
 37:     const DEFAULT_LOCALE    = 'en_US';
 38:     const DEFAULT_TIMEZONE  = 'UTC';
 39:     const DEFAULT_CURRENCY  = 'USD';
 40: 
 41:     /**
 42:      * XML path constants
 43:      */
 44:     const XML_PATH_DEFAULT_LOCALE   = 'general/locale/code';
 45:     const XML_PATH_DEFAULT_TIMEZONE = 'general/locale/timezone';
 46:     /**
 47:      * @deprecated since 1.4.1.0
 48:      */
 49:     const XML_PATH_DEFAULT_COUNTRY  = 'general/country/default';
 50:     const XML_PATH_ALLOW_CODES      = 'global/locale/allow/codes';
 51:     const XML_PATH_ALLOW_CURRENCIES = 'global/locale/allow/currencies';
 52:     const XML_PATH_ALLOW_CURRENCIES_INSTALLED = 'system/currency/installed';
 53: 
 54:     /**
 55:      * Date and time format codes
 56:      */
 57:     const FORMAT_TYPE_FULL  = 'full';
 58:     const FORMAT_TYPE_LONG  = 'long';
 59:     const FORMAT_TYPE_MEDIUM= 'medium';
 60:     const FORMAT_TYPE_SHORT = 'short';
 61: 
 62:     /**
 63:      * Default locale code
 64:      *
 65:      * @var string
 66:      */
 67:     protected $_defaultLocale;
 68: 
 69:     /**
 70:      * Locale object
 71:      *
 72:      * @var Zend_Locale
 73:      */
 74:     protected $_locale;
 75: 
 76:     /**
 77:      * Locale code
 78:      *
 79:      * @var string
 80:      */
 81:     protected $_localeCode;
 82: 
 83:     /**
 84:      * Emulated locales stack
 85:      *
 86:      * @var array
 87:      */
 88:     protected $_emulatedLocales = array();
 89: 
 90:     protected static $_currencyCache = array();
 91: 
 92:     public function __construct($locale = null)
 93:     {
 94:         $this->setLocale($locale);
 95:     }
 96: 
 97:     /**
 98:      * Set default locale code
 99:      *
100:      * @param   string $locale
101:      * @return  Mage_Core_Model_Locale
102:      */
103:     public function setDefaultLocale($locale)
104:     {
105:         $this->_defaultLocale = $locale;
106:         return $this;
107:     }
108: 
109:     /**
110:      * REtrieve default locale code
111:      *
112:      * @return string
113:      */
114:     public function getDefaultLocale()
115:     {
116:         if (!$this->_defaultLocale) {
117:             $locale = Mage::getStoreConfig(self::XML_PATH_DEFAULT_LOCALE);
118:             if (!$locale) {
119:                 $locale = self::DEFAULT_LOCALE;
120:             }
121:             $this->_defaultLocale = $locale;
122:         }
123:         return $this->_defaultLocale;
124:     }
125: 
126:     /**
127:      * Set locale
128:      *
129:      * @param   string $locale
130:      * @return  Mage_Core_Model_Locale
131:      */
132:     public function setLocale($locale = null)
133:     {
134:         if (($locale !== null) && is_string($locale)) {
135:             $this->_localeCode = $locale;
136:         } else {
137:             $this->_localeCode = $this->getDefaultLocale();
138:         }
139:         Mage::dispatchEvent('core_locale_set_locale', array('locale'=>$this));
140:         return $this;
141:     }
142: 
143:     /**
144:      * Retrieve timezone code
145:      *
146:      * @return string
147:      */
148:     public function getTimezone()
149:     {
150:         return self::DEFAULT_TIMEZONE;
151:     }
152: 
153:     /**
154:      * Retrieve currency code
155:      *
156:      * @return string
157:      */
158:     public function getCurrency()
159:     {
160:         return self::DEFAULT_CURRENCY;
161:     }
162: 
163:     /**
164:      * Retrieve locale object
165:      *
166:      * @return Zend_Locale
167:      */
168:     public function getLocale()
169:     {
170:         if (!$this->_locale) {
171:             Zend_Locale_Data::setCache(Mage::app()->getCache());
172:             $this->_locale = new Zend_Locale($this->getLocaleCode());
173:         } elseif ($this->_locale->__toString() != $this->_localeCode) {
174:             $this->setLocale($this->_localeCode);
175:         }
176: 
177:         return $this->_locale;
178:     }
179: 
180:     /**
181:      * Retrieve locale code
182:      *
183:      * @return string
184:      */
185:     public function getLocaleCode()
186:     {
187:         if ($this->_localeCode === null) {
188:             $this->setLocale();
189:         }
190:         return $this->_localeCode;
191:     }
192: 
193:     /**
194:      * Specify current locale code
195:      *
196:      * @param   string $code
197:      * @return  Mage_Core_Model_Locale
198:      */
199:     public function setLocaleCode($code)
200:     {
201:         $this->_localeCode = $code;
202:         $this->_locale = null;
203:         return $this;
204:     }
205: 
206:     /**
207:      * Get options array for locale dropdown in currunt locale
208:      *
209:      * @return array
210:      */
211:     public function getOptionLocales()
212:     {
213:         return $this->_getOptionLocales();
214:     }
215: 
216:     /**
217:      * Get translated to original locale options array for locale dropdown
218:      *
219:      * @return array
220:      */
221:     public function getTranslatedOptionLocales()
222:     {
223:         return $this->_getOptionLocales(true);
224:     }
225: 
226:     /**
227:      * Get options array for locale dropdown
228:      *
229:      * @param   bool $translatedName translation flag
230:      * @return  array
231:      */
232:     protected function _getOptionLocales($translatedName=false)
233:     {
234:         $options    = array();
235:         $locales    = $this->getLocale()->getLocaleList();
236:         $languages  = $this->getLocale()->getTranslationList('language', $this->getLocale());
237:         $countries  = $this->getCountryTranslationList();
238: 
239:         $allowed    = $this->getAllowLocales();
240:         foreach ($locales as $code=>$active) {
241:             if (strstr($code, '_')) {
242:                 if (!in_array($code, $allowed)) {
243:                     continue;
244:                 }
245:                 $data = explode('_', $code);
246:                 if (!isset($languages[$data[0]]) || !isset($countries[$data[1]])) {
247:                     continue;
248:                 }
249:                 if ($translatedName) {
250:                     $label = ucwords($this->getLocale()->getTranslation($data[0], 'language', $code))
251:                         . ' (' . $this->getLocale()->getTranslation($data[1], 'country', $code) . ') / '
252:                         . $languages[$data[0]] . ' (' . $countries[$data[1]] . ')';
253:                 } else {
254:                     $label = $languages[$data[0]] . ' (' . $countries[$data[1]] . ')';
255:                 }
256:                 $options[] = array(
257:                     'value' => $code,
258:                     'label' => $label
259:                 );
260:             }
261:         }
262:         return $this->_sortOptionArray($options);
263:     }
264: 
265:     /**
266:      * Retrieve timezone option list
267:      *
268:      * @return array
269:      */
270:     public function getOptionTimezones()
271:     {
272:         $options= array();
273:         $zones  = $this->getTranslationList('windowstotimezone');
274:         ksort($zones);
275:         foreach ($zones as $code=>$name) {
276:             $name = trim($name);
277:             $options[] = array(
278:                'label' => empty($name) ? $code : $name . ' (' . $code . ')',
279:                'value' => $code,
280:             );
281:         }
282:         return $this->_sortOptionArray($options);
283:     }
284: 
285:     /**
286:      * Retrieve days of week option list
287:      *
288:      * @return array
289:      */
290:     public function getOptionWeekdays()
291:     {
292:         $options= array();
293:         $days = $this->getTranslationList('days');
294:         foreach (array_values($days['format']['wide']) as $code => $name) {
295:             $options[] = array(
296:                'label' => $name,
297:                'value' => $code,
298:             );
299:         }
300:         return $options;
301:     }
302: 
303:     /**
304:      * Retrieve country option list
305:      *
306:      * @return array
307:      */
308:     public function getOptionCountries()
309:     {
310:         $options    = array();
311:         $countries  = $this->getCountryTranslationList();
312: 
313:         foreach ($countries as $code=>$name) {
314:             $options[] = array(
315:                'label' => $name,
316:                'value' => $code,
317:             );
318:         }
319:         return $this->_sortOptionArray($options);
320:     }
321: 
322:     /**
323:      * Retrieve currency option list
324:      *
325:      * @return unknown
326:      */
327:     public function getOptionCurrencies()
328:     {
329:         $currencies = $this->getTranslationList('currencytoname');
330:         $options = array();
331:         $allowed = $this->getAllowCurrencies();
332: 
333:         foreach ($currencies as $name=>$code) {
334:             if (!in_array($code, $allowed)) {
335:                 continue;
336:             }
337: 
338:             $options[] = array(
339:                'label' => $name,
340:                'value' => $code,
341:             );
342:         }
343:         return $this->_sortOptionArray($options);
344:     }
345: 
346:     /**
347:      * Retrieve all currency option list
348:      *
349:      * @return unknown
350:      */
351:     public function getOptionAllCurrencies()
352:     {
353:         $currencies = $this->getTranslationList('currencytoname');
354:         $options = array();
355:         foreach ($currencies as $name=>$code) {
356:             $options[] = array(
357:                'label' => $name,
358:                'value' => $code,
359:             );
360:         }
361:         return $this->_sortOptionArray($options);
362:     }
363: 
364:     protected function _sortOptionArray($option)
365:     {
366:         $data = array();
367:         foreach ($option as $item) {
368:             $data[$item['value']] = $item['label'];
369:         }
370:         asort($data);
371:         $option = array();
372:         foreach ($data as $key => $label) {
373:             $option[] = array(
374:                'value' => $key,
375:                'label' => $label
376:             );
377:         }
378:         return $option;
379:     }
380: 
381:     /**
382:      * Retrieve array of allowed locales
383:      *
384:      * @return array
385:      */
386:     public function getAllowLocales()
387:     {
388:         return Mage::getSingleton('core/locale_config')->getAllowedLocales();
389:     }
390: 
391:     /**
392:      * Retrieve array of allowed currencies
393:      *
394:      * @return unknown
395:      */
396:     public function getAllowCurrencies()
397:     {
398:         $data = array();
399:         if (Mage::isInstalled()) {
400:             $data = Mage::app()->getStore()->getConfig(self::XML_PATH_ALLOW_CURRENCIES_INSTALLED);
401:             return explode(',', $data);
402:         } else {
403:             $data = Mage::getSingleton('core/locale_config')->getAllowedCurrencies();
404:         }
405:         return $data;
406:     }
407: 
408:     /**
409:      * Retrieve ISO date format
410:      *
411:      * @param   string $type
412:      * @return  string
413:      */
414:     public function getDateFormat($type=null)
415:     {
416:         return $this->getTranslation($type, 'date');
417:     }
418: 
419:     /**
420:      * Retrieve short date format with 4-digit year
421:      *
422:      * @return  string
423:      */
424:     public function getDateFormatWithLongYear()
425:     {
426:         return preg_replace('/(?<!y)yy(?!y)/', 'yyyy',
427:             $this->getTranslation(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, 'date'));
428:     }
429: 
430: 
431:     /**
432:      * Retrieve ISO time format
433:      *
434:      * @param   string $type
435:      * @return  string
436:      */
437:     public function getTimeFormat($type=null)
438:     {
439:         return $this->getTranslation($type, 'time');
440:     }
441: 
442:     /**
443:      * Retrieve ISO datetime format
444:      *
445:      * @param   string $type
446:      * @return  string
447:      */
448:     public function getDateTimeFormat($type)
449:     {
450:         return $this->getDateFormat($type) . ' ' . $this->getTimeFormat($type);
451:     }
452: 
453:     /**
454:      * Retrieve date format by strftime function
455:      *
456:      * @param   string $type
457:      * @return  string
458:      */
459:     public function getDateStrFormat($type)
460:     {
461:         return Varien_Date::convertZendToStrftime($this->getDateFormat($type), true, false);
462:     }
463: 
464:     /**
465:      * Retrieve time format by strftime function
466:      *
467:      * @param   string $type
468:      * @return  string
469:      */
470:     public function getTimeStrFormat($type)
471:     {
472:         return Varien_Date::convertZendToStrftime($this->getTimeFormat($type), false, true);
473:     }
474: 
475:     /**
476:      * Create Zend_Date object for current locale
477:      *
478:      * @param mixed              $date
479:      * @param string             $part
480:      * @param string|Zend_Locale $locale
481:      * @param bool               $useTimezone
482:      * @return Zend_Date
483:      */
484:     public function date($date = null, $part = null, $locale = null, $useTimezone = true)
485:     {
486:         if (is_null($locale)) {
487:             $locale = $this->getLocale();
488:         }
489: 
490:         if (empty($date)) {
491:             // $date may be false, but Zend_Date uses strict compare
492:             $date = null;
493:         }
494:         $date = new Zend_Date($date, $part, $locale);
495:         if ($useTimezone) {
496:             if ($timezone = Mage::app()->getStore()->getConfig(self::XML_PATH_DEFAULT_TIMEZONE)) {
497:                 $date->setTimezone($timezone);
498:             }
499:         }
500: 
501:         return $date;
502:     }
503: 
504:     /**
505:      * Create Zend_Date object with date converted to store timezone and store Locale
506:      *
507:      * @param   mixed $store Information about store
508:      * @param   string|integer|Zend_Date|array|null $date date in UTC
509:      * @param   boolean $includeTime flag for including time to date
510:      * @return  Zend_Date
511:      */
512:     public function storeDate($store=null, $date=null, $includeTime=false)
513:     {
514:         $timezone = Mage::app()->getStore($store)->getConfig(self::XML_PATH_DEFAULT_TIMEZONE);
515:         $date = new Zend_Date($date, null, $this->getLocale());
516:         $date->setTimezone($timezone);
517:         if (!$includeTime) {
518:             $date->setHour(0)
519:                 ->setMinute(0)
520:                 ->setSecond(0);
521:         }
522:         return $date;
523:     }
524: 
525:     /**
526:      * Create Zend_Date object with date converted from store's timezone
527:      * to UTC time zone. Date can be passed in format of store's locale
528:      * or in format which was passed as parameter.
529:      *
530:      * @param mixed $store Information about store
531:      * @param string|integer|Zend_Date|array|null $date date in store's timezone
532:      * @param boolean $includeTime flag for including time to date
533:      * @param null|string $format
534:      * @return Zend_Date
535:      */
536:     public function utcDate($store=null, $date, $includeTime = false, $format = null)
537:     {
538:         $dateObj = $this->storeDate($store, $date, $includeTime);
539:         $dateObj->set($date, $format);
540:         $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
541:         return $dateObj;
542:     }
543: 
544:     /**
545:      * Get store timestamp
546:      * Timstamp will be builded with store timezone settings
547:      *
548:      * @param   mixed $store
549:      * @return  int
550:      */
551:     public function storeTimeStamp($store=null)
552:     {
553:         $timezone = Mage::app()->getStore($store)->getConfig(self::XML_PATH_DEFAULT_TIMEZONE);
554:         $currentTimezone = @date_default_timezone_get();
555:         @date_default_timezone_set($timezone);
556:         $date = date('Y-m-d H:i:s');
557:         @date_default_timezone_set($currentTimezone);
558:         return strtotime($date);
559:     }
560: 
561:     /**
562:      * Create Zend_Currency object for current locale
563:      *
564:      * @param   string $currency
565:      * @return  Zend_Currency
566:      */
567:     public function currency($currency)
568:     {
569:         Varien_Profiler::start('locale/currency');
570:         if (!isset(self::$_currencyCache[$this->getLocaleCode()][$currency])) {
571:             $options = array();
572:             try {
573:                 $currencyObject = new Zend_Currency($currency, $this->getLocale());
574:             } catch (Exception $e) {
575:                 $currencyObject = new Zend_Currency($this->getCurrency(), $this->getLocale());
576:                 $options['name'] = $currency;
577:                 $options['currency'] = $currency;
578:                 $options['symbol'] = $currency;
579:             }
580: 
581:             $options = new Varien_Object($options);
582:             Mage::dispatchEvent('currency_display_options_forming', array(
583:                 'currency_options' => $options,
584:                 'base_code' => $currency
585:             ));
586: 
587:             $currencyObject->setFormat($options->toArray());
588:             self::$_currencyCache[$this->getLocaleCode()][$currency] = $currencyObject;
589:         }
590:         Varien_Profiler::stop('locale/currency');
591:         return self::$_currencyCache[$this->getLocaleCode()][$currency];
592:     }
593: 
594:     /**
595:      * Returns the first found number from an string
596:      * Parsing depends on given locale (grouping and decimal)
597:      *
598:      * Examples for input:
599:      * '  2345.4356,1234' = 23455456.1234
600:      * '+23,3452.123' = 233452.123
601:      * ' 12343 ' = 12343
602:      * '-9456km' = -9456
603:      * '0' = 0
604:      * '2 054,10' = 2054.1
605:      * '2'054.52' = 2054.52
606:      * '2,46 GB' = 2.46
607:      *
608:      * @param string|float|int $value
609:      * @return float|null
610:      */
611:     public function getNumber($value)
612:     {
613:         if (is_null($value)) {
614:             return null;
615:         }
616: 
617:         if (!is_string($value)) {
618:             return floatval($value);
619:         }
620: 
621:         //trim spaces and apostrophes
622:         $value = str_replace(array('\'', ' '), '', $value);
623: 
624:         $separatorComa = strpos($value, ',');
625:         $separatorDot  = strpos($value, '.');
626: 
627:         if ($separatorComa !== false && $separatorDot !== false) {
628:             if ($separatorComa > $separatorDot) {
629:                 $value = str_replace('.', '', $value);
630:                 $value = str_replace(',', '.', $value);
631:             }
632:             else {
633:                 $value = str_replace(',', '', $value);
634:             }
635:         }
636:         elseif ($separatorComa !== false) {
637:             $value = str_replace(',', '.', $value);
638:         }
639: 
640:         return floatval($value);
641:     }
642: 
643:     /**
644:      * Functions returns array with price formatting info for js function
645:      * formatCurrency in js/varien/js.js
646:      *
647:      * @return array
648:      */
649:     public function getJsPriceFormat()
650:     {
651:         $format = Zend_Locale_Data::getContent($this->getLocaleCode(), 'currencynumber');
652:         $symbols = Zend_Locale_Data::getList($this->getLocaleCode(), 'symbols');
653: 
654:         $pos = strpos($format, ';');
655:         if ($pos !== false){
656:             $format = substr($format, 0, $pos);
657:         }
658:         $format = preg_replace("/[^0\#\.,]/", "", $format);
659:         $totalPrecision = 0;
660:         $decimalPoint = strpos($format, '.');
661:         if ($decimalPoint !== false) {
662:             $totalPrecision = (strlen($format) - (strrpos($format, '.')+1));
663:         } else {
664:             $decimalPoint = strlen($format);
665:         }
666:         $requiredPrecision = $totalPrecision;
667:         $t = substr($format, $decimalPoint);
668:         $pos = strpos($t, '#');
669:         if ($pos !== false){
670:             $requiredPrecision = strlen($t) - $pos - $totalPrecision;
671:         }
672:         $group = 0;
673:         if (strrpos($format, ',') !== false) {
674:             $group = ($decimalPoint - strrpos($format, ',') - 1);
675:         } else {
676:             $group = strrpos($format, '.');
677:         }
678:         $integerRequired = (strpos($format, '.') - strpos($format, '0'));
679: 
680:         $result = array(
681:             'pattern' => Mage::app()->getStore()->getCurrentCurrency()->getOutputFormat(),
682:             'precision' => $totalPrecision,
683:             'requiredPrecision' => $requiredPrecision,
684:             'decimalSymbol' => $symbols['decimal'],
685:             'groupSymbol' => $symbols['group'],
686:             'groupLength' => $group,
687:             'integerRequired' => $integerRequired
688:         );
689: 
690:         return $result;
691:     }
692: 
693:     /**
694:      * Push current locale to stack and replace with locale from specified store
695:      * Event is not dispatched.
696:      *
697:      * @param int $storeId
698:      */
699:     public function emulate($storeId)
700:     {
701:         if ($storeId) {
702:             $this->_emulatedLocales[] = clone $this->getLocale();
703:             $this->_locale = new Zend_Locale(Mage::getStoreConfig(self::XML_PATH_DEFAULT_LOCALE, $storeId));
704:             $this->_localeCode = $this->_locale->toString();
705:             Mage::getSingleton('core/translate')->setLocale($this->_locale)->init('frontend', true);
706:         }
707:         else {
708:             $this->_emulatedLocales[] = false;
709:         }
710:     }
711: 
712:     /**
713:      * Get last locale, used before last emulation
714:      *
715:      */
716:     public function revert()
717:     {
718:         if ($locale = array_pop($this->_emulatedLocales)) {
719:             $this->_locale = $locale;
720:             $this->_localeCode = $this->_locale->toString();
721:             Mage::getSingleton('core/translate')->setLocale($this->_locale)->init('adminhtml', true);
722:         }
723:     }
724: 
725:     /**
726:      * Returns localized informations as array, supported are several
727:      * types of informations.
728:      * For detailed information about the types look into the documentation
729:      *
730:      * @param  string             $path   (Optional) Type of information to return
731:      * @param  string             $value  (Optional) Value for detail list
732:      * @return array Array with the wished information in the given language
733:      */
734:     public function getTranslationList($path = null, $value = null)
735:     {
736:         return $this->getLocale()->getTranslationList($path, $this->getLocale(), $value);
737:     }
738: 
739:     /**
740:      * Returns a localized information string, supported are several types of informations.
741:      * For detailed information about the types look into the documentation
742:      *
743:      * @param  string             $value  Name to get detailed information about
744:      * @param  string             $path   (Optional) Type of information to return
745:      * @return string|false The wished information in the given language
746:      */
747:     public function getTranslation($value = null, $path = null)
748:     {
749:         return $this->getLocale()->getTranslation($value, $path, $this->getLocale());
750:     }
751: 
752: /**
753:      * Returns the localized country name
754:      *
755:      * @param  string             $value  Name to get detailed information about
756:      * @return array
757:      */
758:     public function getCountryTranslation($value)
759:     {
760:         return $this->getLocale()->getTranslation($value, 'country', $this->getLocale());
761:     }
762: 
763:     /**
764:      * Returns an array with the name of all countries translated to the given language
765:      *
766:      * @return array
767:      */
768:     public function getCountryTranslationList()
769:     {
770:         return $this->getLocale()->getTranslationList('territory', $this->getLocale(), 2);
771:     }
772: 
773:     /**
774:      * Checks if current date of the given store (in the store timezone) is within the range
775:      *
776:      * @param int|string|Mage_Core_Model_Store $store
777:      * @param string|null $dateFrom
778:      * @param string|null $dateTo
779:      * @return bool
780:      */
781:     public function isStoreDateInInterval($store, $dateFrom = null, $dateTo = null)
782:     {
783:         if (!$store instanceof Mage_Core_Model_Store) {
784:             $store = Mage::app()->getStore($store);
785:         }
786: 
787:         $storeTimeStamp = $this->storeTimeStamp($store);
788:         $fromTimeStamp  = strtotime($dateFrom);
789:         $toTimeStamp    = strtotime($dateTo);
790:         if ($dateTo) {
791:             // fix date YYYY-MM-DD 00:00:00 to YYYY-MM-DD 23:59:59
792:             $toTimeStamp += 86400;
793:         }
794: 
795:         $result = false;
796:         if (!is_empty_date($dateFrom) && $storeTimeStamp < $fromTimeStamp) {
797:         }
798:         elseif (!is_empty_date($dateTo) && $storeTimeStamp > $toTimeStamp) {
799:         }
800:         else {
801:             $result = true;
802:         }
803: 
804:         return $result;
805:     }
806: }
807: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0