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:  * Core data helper
 29:  *
 30:  * @author      Magento Core Team <core@magentocommerce.com>
 31:  */
 32: class Mage_Core_Helper_Data extends Mage_Core_Helper_Abstract
 33: {
 34:     const XML_PATH_DEFAULT_COUNTRY              = 'general/country/default';
 35:     const XML_PATH_PROTECTED_FILE_EXTENSIONS    = 'general/file/protected_extensions';
 36:     const XML_PATH_PUBLIC_FILES_VALID_PATHS     = 'general/file/public_files_valid_paths';
 37:     const XML_PATH_ENCRYPTION_MODEL             = 'global/helpers/core/encryption_model';
 38:     const XML_PATH_DEV_ALLOW_IPS                = 'dev/restrict/allow_ips';
 39:     const XML_PATH_CACHE_BETA_TYPES             = 'global/cache/betatypes';
 40:     const XML_PATH_CONNECTION_TYPE              = 'global/resources/default_setup/connection/type';
 41: 
 42:     const CHARS_LOWERS                          = 'abcdefghijklmnopqrstuvwxyz';
 43:     const CHARS_UPPERS                          = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
 44:     const CHARS_DIGITS                          = '0123456789';
 45:     const CHARS_SPECIALS                        = '!$*+-.=?@^_|~';
 46:     const CHARS_PASSWORD_LOWERS                 = 'abcdefghjkmnpqrstuvwxyz';
 47:     const CHARS_PASSWORD_UPPERS                 = 'ABCDEFGHJKLMNPQRSTUVWXYZ';
 48:     const CHARS_PASSWORD_DIGITS                 = '23456789';
 49:     const CHARS_PASSWORD_SPECIALS               = '!$*-.=?@_';
 50: 
 51:     /**
 52:      * Config pathes to merchant country code and merchant VAT number
 53:      */
 54:     const XML_PATH_MERCHANT_COUNTRY_CODE = 'general/store_information/merchant_country';
 55:     const XML_PATH_MERCHANT_VAT_NUMBER = 'general/store_information/merchant_vat_number';
 56:     const XML_PATH_EU_COUNTRIES_LIST = 'general/country/eu_countries';
 57: 
 58:     /**
 59:      * Const for correct dividing decimal values
 60:      */
 61:     const DIVIDE_EPSILON = 10000;
 62: 
 63:     /**
 64:      * @var Mage_Core_Model_Encryption
 65:      */
 66:     protected $_encryptor = null;
 67: 
 68:     protected $_allowedFormats = array(
 69:         Mage_Core_Model_Locale::FORMAT_TYPE_FULL,
 70:         Mage_Core_Model_Locale::FORMAT_TYPE_LONG,
 71:         Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM,
 72:         Mage_Core_Model_Locale::FORMAT_TYPE_SHORT
 73:     );
 74: 
 75: 
 76:     /**
 77:      * @return Mage_Core_Model_Encryption
 78:      */
 79:     public function getEncryptor()
 80:     {
 81:         if ($this->_encryptor === null) {
 82:             $encryptionModel = (string)Mage::getConfig()->getNode(self::XML_PATH_ENCRYPTION_MODEL);
 83:             if ($encryptionModel) {
 84:                 $this->_encryptor = new $encryptionModel;
 85:             } else {
 86:                 $this->_encryptor = Mage::getModel('core/encryption');
 87:             }
 88: 
 89:             $this->_encryptor->setHelper($this);
 90:         }
 91:         return $this->_encryptor;
 92:     }
 93: 
 94:     /**
 95:      * Convert and format price value for current application store
 96:      *
 97:      * @param   float $value
 98:      * @param   bool $format
 99:      * @param   bool $includeContainer
100:      * @return  mixed
101:      */
102:     public static function currency($value, $format = true, $includeContainer = true)
103:     {
104:         return self::currencyByStore($value, null, $format, $includeContainer);
105:     }
106: 
107:     /**
108:      * Convert and format price value for specified store
109:      *
110:      * @param   float $value
111:      * @param   int|Mage_Core_Model_Store $store
112:      * @param   bool $format
113:      * @param   bool $includeContainer
114:      * @return  mixed
115:      */
116:     public static function currencyByStore($value, $store = null, $format = true, $includeContainer = true)
117:     {
118:         try {
119:             if (!($store instanceof Mage_Core_Model_Store)) {
120:                 $store = Mage::app()->getStore($store);
121:             }
122: 
123:             $value = $store->convertPrice($value, $format, $includeContainer);
124:         }
125:         catch (Exception $e){
126:             $value = $e->getMessage();
127:         }
128: 
129:         return $value;
130:     }
131: 
132:     /**
133:      * Format and convert currency using current store option
134:      *
135:      * @param   float $value
136:      * @param   bool $includeContainer
137:      * @return  string
138:      */
139:     public function formatCurrency($value, $includeContainer = true)
140:     {
141:         return $this->currency($value, true, $includeContainer);
142:     }
143: 
144:     /**
145:      * Formats price
146:      *
147:      * @param float $price
148:      * @param bool $includeContainer
149:      * @return string
150:      */
151:     public function formatPrice($price, $includeContainer = true)
152:     {
153:         return Mage::app()->getStore()->formatPrice($price, $includeContainer);
154:     }
155: 
156:     /**
157:      * Format date using current locale options and time zone.
158:      *
159:      * @param   date|Zend_Date|null $date
160:      * @param   string              $format   See Mage_Core_Model_Locale::FORMAT_TYPE_* constants
161:      * @param   bool                $showTime Whether to include time
162:      * @return  string
163:      */
164:     public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false)
165:     {
166:         if (!in_array($format, $this->_allowedFormats, true)) {
167:             return $date;
168:         }
169:         if (!($date instanceof Zend_Date) && $date && !strtotime($date)) {
170:             return '';
171:         }
172:         if (is_null($date)) {
173:             $date = Mage::app()->getLocale()->date(Mage::getSingleton('core/date')->gmtTimestamp(), null, null);
174:         } else if (!$date instanceof Zend_Date) {
175:             $date = Mage::app()->getLocale()->date(strtotime($date), null, null);
176:         }
177: 
178:         if ($showTime) {
179:             $format = Mage::app()->getLocale()->getDateTimeFormat($format);
180:         } else {
181:             $format = Mage::app()->getLocale()->getDateFormat($format);
182:         }
183: 
184:         return $date->toString($format);
185:     }
186: 
187:     /**
188:      * Format time using current locale options
189:      *
190:      * @param   date|Zend_Date|null $time
191:      * @param   string              $format
192:      * @param   bool                $showDate
193:      * @return  string
194:      */
195:     public function formatTime($time = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showDate = false)
196:     {
197:         if (!in_array($format, $this->_allowedFormats, true)) {
198:             return $time;
199:         }
200: 
201:         if (is_null($time)) {
202:             $date = Mage::app()->getLocale()->date(time());
203:         } else if ($time instanceof Zend_Date) {
204:             $date = $time;
205:         } else {
206:             $date = Mage::app()->getLocale()->date(strtotime($time));
207:         }
208: 
209:         if ($showDate) {
210:             $format = Mage::app()->getLocale()->getDateTimeFormat($format);
211:         } else {
212:             $format = Mage::app()->getLocale()->getTimeFormat($format);
213:         }
214: 
215:         return $date->toString($format);
216:     }
217: 
218:     /**
219:      * Encrypt data using application key
220:      *
221:      * @param   string $data
222:      * @return  string
223:      */
224:     public function encrypt($data)
225:     {
226:         if (!Mage::isInstalled()) {
227:             return $data;
228:         }
229:         return $this->getEncryptor()->encrypt($data);
230:     }
231: 
232:     /**
233:      * Decrypt data using application key
234:      *
235:      * @param   string $data
236:      * @return  string
237:      */
238:     public function decrypt($data)
239:     {
240:         if (!Mage::isInstalled()) {
241:             return $data;
242:         }
243:         return $this->getEncryptor()->decrypt($data);
244:     }
245: 
246:     public function validateKey($key)
247:     {
248:         return $this->getEncryptor()->validateKey($key);
249:     }
250: 
251:     public function getRandomString($len, $chars = null)
252:     {
253:         if (is_null($chars)) {
254:             $chars = self::CHARS_LOWERS . self::CHARS_UPPERS . self::CHARS_DIGITS;
255:         }
256:         mt_srand(10000000*(double)microtime());
257:         for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++) {
258:             $str .= $chars[mt_rand(0, $lc)];
259:         }
260:         return $str;
261:     }
262: 
263:     /**
264:      * Generate salted hash from password
265:      *
266:      * @param string $password
267:      * @param string|integer|boolean $salt
268:      */
269:     public function getHash($password, $salt = false)
270:     {
271:         return $this->getEncryptor()->getHash($password, $salt);
272:     }
273: 
274:     public function validateHash($password, $hash)
275:     {
276:         return $this->getEncryptor()->validateHash($password, $hash);
277:     }
278: 
279:     /**
280:      * Retrieve store identifier
281:      *
282:      * @param   mixed $store
283:      * @return  int
284:      */
285:     public function getStoreId($store=null)
286:     {
287:         return Mage::app()->getStore($store)->getId();
288:     }
289: 
290:     public function removeAccents($string, $german=false)
291:     {
292:         static $replacements;
293: 
294:         if (empty($replacements[$german])) {
295:             $subst = array(
296:                 // single ISO-8859-1 letters
297:                 192=>'A', 193=>'A', 194=>'A', 195=>'A', 196=>'A', 197=>'A', 199=>'C',
298:                 208=>'D', 200=>'E', 201=>'E', 202=>'E', 203=>'E', 204=>'I', 205=>'I',
299:                 206=>'I', 207=>'I', 209=>'N', 210=>'O', 211=>'O', 212=>'O', 213=>'O',
300:                 214=>'O', 216=>'O', 138=>'S', 217=>'U', 218=>'U', 219=>'U', 220=>'U',
301:                 221=>'Y', 142=>'Z', 224=>'a', 225=>'a', 226=>'a', 227=>'a', 228=>'a',
302:                 229=>'a', 231=>'c', 232=>'e', 233=>'e', 234=>'e', 235=>'e', 236=>'i',
303:                 237=>'i', 238=>'i', 239=>'i', 241=>'n', 240=>'o', 242=>'o', 243=>'o',
304:                 244=>'o', 245=>'o', 246=>'o', 248=>'o', 154=>'s', 249=>'u', 250=>'u',
305:                 251=>'u', 252=>'u', 253=>'y', 255=>'y', 158=>'z',
306:                 // HTML entities
307:                 258=>'A', 260=>'A', 262=>'C', 268=>'C', 270=>'D', 272=>'D', 280=>'E',
308:                 282=>'E', 286=>'G', 304=>'I', 313=>'L', 317=>'L', 321=>'L', 323=>'N',
309:                 327=>'N', 336=>'O', 340=>'R', 344=>'R', 346=>'S', 350=>'S', 354=>'T',
310:                 356=>'T', 366=>'U', 368=>'U', 377=>'Z', 379=>'Z', 259=>'a', 261=>'a',
311:                 263=>'c', 269=>'c', 271=>'d', 273=>'d', 281=>'e', 283=>'e', 287=>'g',
312:                 305=>'i', 322=>'l', 314=>'l', 318=>'l', 324=>'n', 328=>'n', 337=>'o',
313:                 341=>'r', 345=>'r', 347=>'s', 351=>'s', 357=>'t', 355=>'t', 367=>'u',
314:                 369=>'u', 378=>'z', 380=>'z',
315:                 // ligatures
316:                 198=>'Ae', 230=>'ae', 140=>'Oe', 156=>'oe', 223=>'ss',
317:             );
318: 
319:             if ($german) {
320:                 // umlauts
321:                 $subst = array_merge($subst, array(
322:                     196=>'Ae', 228=>'ae', 214=>'Oe', 246=>'oe', 220=>'Ue', 252=>'ue'
323:                 ));
324:             }
325: 
326:             $replacements[$german] = array();
327:             foreach ($subst as $k=>$v) {
328:                 $replacements[$german][$k<256 ? chr($k) : '&#'.$k.';'] = $v;
329:             }
330:         }
331: 
332:         // convert string from default database format (UTF-8)
333:         // to encoding which replacement arrays made with (ISO-8859-1)
334:         if ($s = @iconv('UTF-8', 'ISO-8859-1', $string)) {
335:             $string = $s;
336:         }
337: 
338:         // Replace
339:         $string = strtr($string, $replacements[$german]);
340: 
341:         return $string;
342:     }
343: 
344:     public function isDevAllowed($storeId=null)
345:     {
346:         $allow = true;
347: 
348:         $allowedIps = Mage::getStoreConfig(self::XML_PATH_DEV_ALLOW_IPS, $storeId);
349:         $remoteAddr = Mage::helper('core/http')->getRemoteAddr();
350:         if (!empty($allowedIps) && !empty($remoteAddr)) {
351:             $allowedIps = preg_split('#\s*,\s*#', $allowedIps, null, PREG_SPLIT_NO_EMPTY);
352:             if (array_search($remoteAddr, $allowedIps) === false
353:                 && array_search(Mage::helper('core/http')->getHttpHost(), $allowedIps) === false) {
354:                 $allow = false;
355:             }
356:         }
357: 
358:         return $allow;
359:     }
360: 
361:     /**
362:      * Get information about available cache types
363:      *
364:      * @return array
365:      */
366:     public function getCacheTypes()
367:     {
368:         $types = array();
369:         $config = Mage::getConfig()->getNode(Mage_Core_Model_Cache::XML_PATH_TYPES);
370:         foreach ($config->children() as $type=>$node) {
371:             $types[$type] = (string)$node->label;
372:         }
373:         return $types;
374:     }
375: 
376:     /**
377:      * Get information about available cache beta types
378:      *
379:      * @return array
380:      */
381:     public function getCacheBetaTypes()
382:     {
383:         $types = array();
384:         $config = Mage::getConfig()->getNode(self::XML_PATH_CACHE_BETA_TYPES);
385:         if ($config) {
386:             foreach ($config->children() as $type=>$node) {
387:                 $types[$type] = (string)$node->label;
388:             }
389:         }
390:         return $types;
391:     }
392: 
393:     /**
394:      * Copy data from object|array to object|array containing fields
395:      * from fieldset matching an aspect.
396:      *
397:      * Contents of $aspect are a field name in target object or array.
398:      * If '*' - will be used the same name as in the source object or array.
399:      *
400:      * @param string $fieldset
401:      * @param string $aspect
402:      * @param array|Varien_Object $source
403:      * @param array|Varien_Object $target
404:      * @param string $root
405:      * @return boolean
406:      */
407:     public function copyFieldset($fieldset, $aspect, $source, $target, $root='global')
408:     {
409:         if (!(is_array($source) || $source instanceof Varien_Object)
410:             || !(is_array($target) || $target instanceof Varien_Object)) {
411: 
412:             return false;
413:         }
414:         $fields = Mage::getConfig()->getFieldset($fieldset, $root);
415:         if (!$fields) {
416:             return false;
417:         }
418: 
419:         $sourceIsArray = is_array($source);
420:         $targetIsArray = is_array($target);
421: 
422:         $result = false;
423:         foreach ($fields as $code=>$node) {
424:             if (empty($node->$aspect)) {
425:                 continue;
426:             }
427: 
428:             if ($sourceIsArray) {
429:                 $value = isset($source[$code]) ? $source[$code] : null;
430:             } else {
431:                 $value = $source->getDataUsingMethod($code);
432:             }
433: 
434:             $targetCode = (string)$node->$aspect;
435:             $targetCode = $targetCode == '*' ? $code : $targetCode;
436: 
437:             if ($targetIsArray) {
438:                 $target[$targetCode] = $value;
439:             } else {
440:                 $target->setDataUsingMethod($targetCode, $value);
441:             }
442: 
443:             $result = true;
444:         }
445: 
446:         $eventName = sprintf('core_copy_fieldset_%s_%s', $fieldset, $aspect);
447:         Mage::dispatchEvent($eventName, array(
448:             'target' => $target,
449:             'source' => $source,
450:             'root'   => $root
451:         ));
452: 
453:         return $result;
454:     }
455: 
456:     /**
457:      * Decorate a plain array of arrays or objects
458:      * The array actually can be an object with Iterator interface
459:      *
460:      * Keys with prefix_* will be set:
461:      * *_is_first - if the element is first
462:      * *_is_odd / *_is_even - for odd/even elements
463:      * *_is_last - if the element is last
464:      *
465:      * The respective key/attribute will be set to element, depending on object it is or array.
466:      * Varien_Object is supported.
467:      *
468:      * $forceSetAll true will cause to set all possible values for all elements.
469:      * When false (default), only non-empty values will be set.
470:      *
471:      * @param mixed $array
472:      * @param string $prefix
473:      * @param bool $forceSetAll
474:      * @return mixed
475:      */
476:     public function decorateArray($array, $prefix = 'decorated_', $forceSetAll = false)
477:     {
478:         // check if array or an object to be iterated given
479:         if (!(is_array($array) || is_object($array))) {
480:             return $array;
481:         }
482: 
483:         $keyIsFirst = "{$prefix}is_first";
484:         $keyIsOdd   = "{$prefix}is_odd";
485:         $keyIsEven  = "{$prefix}is_even";
486:         $keyIsLast  = "{$prefix}is_last";
487: 
488:         $count  = count($array); // this will force Iterator to load
489:         $i      = 0;
490:         $isEven = false;
491:         foreach ($array as $key => $element) {
492:             if (is_object($element)) {
493:                 $this->_decorateArrayObject($element, $keyIsFirst, (0 === $i), $forceSetAll || (0 === $i));
494:                 $this->_decorateArrayObject($element, $keyIsOdd, !$isEven, $forceSetAll || !$isEven);
495:                 $this->_decorateArrayObject($element, $keyIsEven, $isEven, $forceSetAll || $isEven);
496:                 $isEven = !$isEven;
497:                 $i++;
498:                 $this->_decorateArrayObject($element, $keyIsLast, ($i === $count), $forceSetAll || ($i === $count));
499:             }
500:             elseif (is_array($element)) {
501:                 if ($forceSetAll || (0 === $i)) {
502:                     $array[$key][$keyIsFirst] = (0 === $i);
503:                 }
504:                 if ($forceSetAll || !$isEven) {
505:                     $array[$key][$keyIsOdd] = !$isEven;
506:                 }
507:                 if ($forceSetAll || $isEven) {
508:                     $array[$key][$keyIsEven] = $isEven;
509:                 }
510:                 $isEven = !$isEven;
511:                 $i++;
512:                 if ($forceSetAll || ($i === $count)) {
513:                     $array[$key][$keyIsLast] = ($i === $count);
514:                 }
515:             }
516:         }
517: 
518:         return $array;
519:     }
520: 
521:     private function _decorateArrayObject($element, $key, $value, $dontSkip) {
522:         if ($dontSkip) {
523:             if ($element instanceof Varien_Object) {
524:                 $element->setData($key, $value);
525:             }
526:             else {
527:                 $element->$key = $value;
528:             }
529:         }
530:     }
531: 
532:     /**
533:      * Transform an assoc array to SimpleXMLElement object
534:      * Array has some limitations. Appropriate exceptions will be thrown
535:      *
536:      * @param array $array
537:      * @param string $rootName
538:      * @return SimpleXMLElement
539:      * @throws Exception
540:      */
541:     public function assocToXml(array $array, $rootName = '_')
542:     {
543:         if (empty($rootName) || is_numeric($rootName)) {
544:             throw new Exception('Root element must not be empty or numeric');
545:         }
546: 
547:         $xmlstr = <<<XML
548: <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
549: <$rootName></$rootName>
550: XML;
551:         $xml = new SimpleXMLElement($xmlstr);
552:         foreach ($array as $key => $value) {
553:             if (is_numeric($key)) {
554:                 throw new Exception('Array root keys must not be numeric.');
555:             }
556:         }
557:         return self::_assocToXml($array, $rootName, $xml);
558:     }
559: 
560:     /**
561:      * Function, that actually recursively transforms array to xml
562:      *
563:      * @param array $array
564:      * @param string $rootName
565:      * @param SimpleXMLElement $xml
566:      * @return SimpleXMLElement
567:      * @throws Exception
568:      */
569:     private function _assocToXml(array $array, $rootName, SimpleXMLElement &$xml)
570:     {
571:         $hasNumericKey = false;
572:         $hasStringKey  = false;
573:         foreach ($array as $key => $value) {
574:             if (!is_array($value)) {
575:                 if (is_string($key)) {
576:                     if ($key === $rootName) {
577:                         throw new Exception('Associative key must not be the same as its parent associative key.');
578:                     }
579:                     $hasStringKey = true;
580:                     $xml->$key = $value;
581:                 }
582:                 elseif (is_int($key)) {
583:                     $hasNumericKey = true;
584:                     $xml->{$rootName}[$key] = $value;
585:                 }
586:             }
587:             else {
588:                 self::_assocToXml($value, $key, $xml->$key);
589:             }
590:         }
591:         if ($hasNumericKey && $hasStringKey) {
592:             throw new Exception('Associative and numeric keys must not be mixed at one level.');
593:         }
594:         return $xml;
595:     }
596: 
597:     /**
598:      * Transform SimpleXMLElement to associative array
599:      * SimpleXMLElement must be conform structure, generated by assocToXml()
600:      *
601:      * @param SimpleXMLElement $xml
602:      * @return array
603:      */
604:     public function xmlToAssoc(SimpleXMLElement $xml)
605:     {
606:         $array = array();
607:         foreach ($xml as $key => $value) {
608:             if (isset($value->$key)) {
609:                 $i = 0;
610:                 foreach ($value->$key as $v) {
611:                     $array[$key][$i++] = (string)$v;
612:                 }
613:             }
614:             else {
615:                 // try to transform it into string value, trimming spaces between elements
616:                 $array[$key] = trim((string)$value);
617:                 if (empty($array[$key]) && !empty($value)) {
618:                     $array[$key] = self::xmlToAssoc($value);
619:                 }
620:                 // untrim strings values
621:                 else {
622:                     $array[$key] = (string)$value;
623:                 }
624:             }
625:         }
626:         return $array;
627:     }
628: 
629:     /**
630:      * Encode the mixed $valueToEncode into the JSON format
631:      *
632:      * @param mixed $valueToEncode
633:      * @param  boolean $cycleCheck Optional; whether or not to check for object recursion; off by default
634:      * @param  array $options Additional options used during encoding
635:      * @return string
636:      */
637:     public function jsonEncode($valueToEncode, $cycleCheck = false, $options = array())
638:     {
639:         $json = Zend_Json::encode($valueToEncode, $cycleCheck, $options);
640:         /* @var $inline Mage_Core_Model_Translate_Inline */
641:         $inline = Mage::getSingleton('core/translate_inline');
642:         if ($inline->isAllowed()) {
643:             $inline->setIsJson(true);
644:             $inline->processResponseBody($json);
645:             $inline->setIsJson(false);
646:         }
647: 
648:         return $json;
649:     }
650: 
651:     /**
652:      * Decodes the given $encodedValue string which is
653:      * encoded in the JSON format
654:      *
655:      * @param string $encodedValue
656:      * @return mixed
657:      */
658:     public function jsonDecode($encodedValue, $objectDecodeType = Zend_Json::TYPE_ARRAY)
659:     {
660:         return Zend_Json::decode($encodedValue, $objectDecodeType);
661:     }
662: 
663:     /**
664:      * Generate a hash from unique ID
665:      * @param $prefix
666:      * @return string
667:      */
668:     public function uniqHash($prefix = '')
669:     {
670:         return $prefix . md5(uniqid(microtime().mt_rand(), true));
671:     }
672: 
673:     /**
674:      * Merge specified files into one
675:      *
676:      * By default will not merge, if there is already merged file exists and it
677:      * was modified after its components
678:      * If target file is specified, will attempt to write merged contents into it,
679:      * otherwise will return merged content
680:      * May apply callback to each file contents. Callback gets parameters:
681:      * (<existing system filename>, <file contents>)
682:      * May filter files by specified extension(s)
683:      * Returns false on error
684:      *
685:      * @param array $srcFiles
686:      * @param string|false $targetFile - file path to be written
687:      * @param bool $mustMerge
688:      * @param callback $beforeMergeCallback
689:      * @param array|string $extensionsFilter
690:      * @return bool|string
691:      */
692:     public function mergeFiles(array $srcFiles, $targetFile = false, $mustMerge = false,
693:         $beforeMergeCallback = null, $extensionsFilter = array())
694:     {
695:         try {
696:             // check whether merger is required
697:             $shouldMerge = $mustMerge || !$targetFile;
698:             if (!$shouldMerge) {
699:                 if (!file_exists($targetFile)) {
700:                     $shouldMerge = true;
701:                 } else {
702:                     $targetMtime = filemtime($targetFile);
703:                     foreach ($srcFiles as $file) {
704:                         if (!file_exists($file) || @filemtime($file) > $targetMtime) {
705:                             $shouldMerge = true;
706:                             break;
707:                         }
708:                     }
709:                 }
710:             }
711: 
712:             // merge contents into the file
713:             if ($shouldMerge) {
714:                 if ($targetFile && !is_writeable(dirname($targetFile))) {
715:                     // no translation intentionally
716:                     throw new Exception(sprintf('Path %s is not writeable.', dirname($targetFile)));
717:                 }
718: 
719:                 // filter by extensions
720:                 if ($extensionsFilter) {
721:                     if (!is_array($extensionsFilter)) {
722:                         $extensionsFilter = array($extensionsFilter);
723:                     }
724:                     if (!empty($srcFiles)){
725:                         foreach ($srcFiles as $key => $file) {
726:                             $fileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION));
727:                             if (!in_array($fileExt, $extensionsFilter)) {
728:                                 unset($srcFiles[$key]);
729:                             }
730:                         }
731:                     }
732:                 }
733:                 if (empty($srcFiles)) {
734:                     // no translation intentionally
735:                     throw new Exception('No files to compile.');
736:                 }
737: 
738:                 $data = '';
739:                 foreach ($srcFiles as $file) {
740:                     if (!file_exists($file)) {
741:                         continue;
742:                     }
743:                     $contents = file_get_contents($file) . "\n";
744:                     if ($beforeMergeCallback && is_callable($beforeMergeCallback)) {
745:                         $contents = call_user_func($beforeMergeCallback, $file, $contents);
746:                     }
747:                     $data .= $contents;
748:                 }
749:                 if (!$data) {
750:                     // no translation intentionally
751:                     throw new Exception(sprintf("No content found in files:\n%s", implode("\n", $srcFiles)));
752:                 }
753:                 if ($targetFile) {
754:                     file_put_contents($targetFile, $data, LOCK_EX);
755:                 } else {
756:                     return $data; // no need to write to file, just return data
757:                 }
758:             }
759: 
760:             return true; // no need in merger or merged into file successfully
761:         } catch (Exception $e) {
762:             Mage::logException($e);
763:         }
764:         return false;
765:     }
766: 
767:     /**
768:      * Return default country code
769:      *
770:      * @param Mage_Core_Model_Store|string|int $store
771:      * @return string
772:      */
773:     public function getDefaultCountry($store = null)
774:     {
775:         return Mage::getStoreConfig(self::XML_PATH_DEFAULT_COUNTRY, $store);
776:     }
777: 
778:     /**
779:      * Return list with protected file extensions
780:      *
781:      * @param Mage_Core_Model_Store|string|int $store
782:      * @return array
783:      */
784:     public function getProtectedFileExtensions($store = null)
785:     {
786:         return Mage::getStoreConfig(self::XML_PATH_PROTECTED_FILE_EXTENSIONS, $store);
787:     }
788: 
789:     /**
790:      * Return list with public files valid paths
791:      *
792:      * @return array
793:      */
794:     public function getPublicFilesValidPath()
795:     {
796:         return Mage::getStoreConfig(self::XML_PATH_PUBLIC_FILES_VALID_PATHS);
797:     }
798: 
799:     /**
800:      * Check LFI protection
801:      *
802:      * @throws Mage_Core_Exception
803:      * @param string $name
804:      * @return bool
805:      */
806:     public function checkLfiProtection($name)
807:     {
808:         if (preg_match('#\.\.[\\\/]#', $name)) {
809:             throw new Mage_Core_Exception($this->__('Requested file may not include parent directory traversal ("../", "..\\" notation)'));
810:         }
811:         return true;
812:     }
813: 
814:     /**
815:      * Check whether database compatible mode is used (configs enable it for MySQL by default).
816:      *
817:      * @return bool
818:      */
819:     public function useDbCompatibleMode()
820:     {
821:         $connType = (string) Mage::getConfig()->getNode(self::XML_PATH_CONNECTION_TYPE);
822:         $path = 'global/resource/connection/types/' . $connType . '/compatibleMode';
823:         $value = (string) Mage::getConfig()->getNode($path);
824:         return (bool) $value;
825:     }
826: 
827:     /**
828:      * Retrieve merchant country code
829:      *
830:      * @param Mage_Core_Model_Store|string|int|null $store
831:      * @return string
832:      */
833:     public function getMerchantCountryCode($store = null)
834:     {
835:         return (string) Mage::getStoreConfig(self::XML_PATH_MERCHANT_COUNTRY_CODE, $store);
836:     }
837: 
838:     /**
839:      * Retrieve merchant VAT number
840:      *
841:      * @param Mage_Core_Model_Store|string|int|null $store
842:      * @return string
843:      */
844:     public function getMerchantVatNumber($store = null)
845:     {
846:         return (string) Mage::getStoreConfig(self::XML_PATH_MERCHANT_VAT_NUMBER, $store);
847:     }
848: 
849:     /**
850:      * Check whether specified country is in EU countries list
851:      *
852:      * @param string $countryCode
853:      * @param null|int $storeId
854:      * @return bool
855:      */
856:     public function isCountryInEU($countryCode, $storeId = null)
857:     {
858:         $euCountries = explode(',', Mage::getStoreConfig(self::XML_PATH_EU_COUNTRIES_LIST, $storeId));
859:         return in_array($countryCode, $euCountries);
860:     }
861: 
862:     /**
863:      * Returns the floating point remainder (modulo) of the division of the arguments
864:      *
865:      * @param float|int $dividend
866:      * @param float|int $divisor
867:      * @return float|int
868:      */
869:     public function getExactDivision($dividend, $divisor)
870:     {
871:         $epsilon = $divisor / self::DIVIDE_EPSILON;
872: 
873:         $remainder = fmod($dividend, $divisor);
874:         if (abs($remainder - $divisor) < $epsilon || abs($remainder) < $epsilon) {
875:             $remainder = 0;
876:         }
877: 
878:         return $remainder;
879:     }
880: }
881: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0