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: /**
  29:  * Custom Zend_Controller_Action class (formally)
  30:  *
  31:  * Allows dispatching before and after events for each controller action
  32:  *
  33:  * @category   Mage
  34:  * @package    Mage_Core
  35:  * @author     Magento Core Team <core@magentocommerce.com>
  36:  */
  37: abstract class Mage_Core_Controller_Varien_Action
  38: {
  39:     const FLAG_NO_CHECK_INSTALLATION    = 'no-install-check';
  40:     const FLAG_NO_DISPATCH              = 'no-dispatch';
  41:     const FLAG_NO_PRE_DISPATCH          = 'no-preDispatch';
  42:     const FLAG_NO_POST_DISPATCH         = 'no-postDispatch';
  43:     const FLAG_NO_START_SESSION         = 'no-startSession';
  44:     const FLAG_NO_DISPATCH_BLOCK_EVENT  = 'no-beforeGenerateLayoutBlocksDispatch';
  45:     const FLAG_NO_COOKIES_REDIRECT      = 'no-cookies-redirect';
  46: 
  47:     const PARAM_NAME_SUCCESS_URL        = 'success_url';
  48:     const PARAM_NAME_ERROR_URL          = 'error_url';
  49:     const PARAM_NAME_REFERER_URL        = 'referer_url';
  50:     const PARAM_NAME_BASE64_URL         = 'r64';
  51:     const PARAM_NAME_URL_ENCODED        = 'uenc';
  52: 
  53:     const PROFILER_KEY                  = 'mage::dispatch::controller::action';
  54: 
  55:     /**
  56:      * Request object
  57:      *
  58:      * @var Zend_Controller_Request_Abstract
  59:      */
  60:     protected $_request;
  61: 
  62:     /**
  63:      * Response object
  64:      *
  65:      * @var Zend_Controller_Response_Abstract
  66:      */
  67:     protected $_response;
  68: 
  69:     /**
  70:      * Real module name (like 'Mage_Module')
  71:      *
  72:      * @var string
  73:      */
  74:     protected $_realModuleName;
  75: 
  76:     /**
  77:      * Action flags
  78:      *
  79:      * for example used to disable rendering default layout
  80:      *
  81:      * @var array
  82:      */
  83:     protected $_flags = array();
  84: 
  85:     /**
  86:      * Action list where need check enabled cookie
  87:      *
  88:      * @var array
  89:      */
  90:     protected $_cookieCheckActions = array();
  91: 
  92:     /**
  93:      * Currently used area
  94:      *
  95:      * @var string
  96:      */
  97:     protected $_currentArea;
  98: 
  99:     /**
 100:      * Namespace for session.
 101:      * Should be defined for proper working session.
 102:      *
 103:      * @var string
 104:      */
 105:     protected $_sessionNamespace;
 106: 
 107:     /**
 108:      * Whether layout is loaded
 109:      *
 110:      * @see self::loadLayout()
 111:      * @var bool
 112:      */
 113:     protected $_isLayoutLoaded = false;
 114: 
 115:     /**
 116:      * Title parts to be rendered in the page head title
 117:      *
 118:      * @see self::_title()
 119:      * @var array
 120:      */
 121:     protected $_titles = array();
 122: 
 123:     /**
 124:      * Whether the default title should be removed
 125:      *
 126:      * @see self::_title()
 127:      * @var bool
 128:      */
 129:     protected $_removeDefaultTitle = false;
 130: 
 131:     /**
 132:      * Constructor
 133:      *
 134:      * @param Zend_Controller_Request_Abstract $request
 135:      * @param Zend_Controller_Response_Abstract $response
 136:      * @param array $invokeArgs
 137:      */
 138:     public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
 139:     {
 140:         $this->_request = $request;
 141:         $this->_response= $response;
 142: 
 143:         Mage::app()->getFrontController()->setAction($this);
 144: 
 145:         $this->_construct();
 146:     }
 147: 
 148:     protected function _construct()
 149:     {
 150:     }
 151: 
 152:     public function hasAction($action)
 153:     {
 154:         return is_callable(array($this, $this->getActionMethodName($action)));
 155:     }
 156: 
 157:     /**
 158:      * Retrieve request object
 159:      *
 160:      * @return Mage_Core_Controller_Request_Http
 161:      */
 162:     public function getRequest()
 163:     {
 164:         return $this->_request;
 165:     }
 166: 
 167:     /**
 168:      * Retrieve response object
 169:      *
 170:      * @return Mage_Core_Controller_Response_Http
 171:      */
 172:     public function getResponse()
 173:     {
 174:         return $this->_response;
 175:     }
 176: 
 177:     /**
 178:      * Retrieve flag value
 179:      *
 180:      * @param   string $action
 181:      * @param   string $flag
 182:      * @return  bool
 183:      */
 184:     public function getFlag($action, $flag='')
 185:     {
 186:         if (''===$action) {
 187:             $action = $this->getRequest()->getActionName();
 188:         }
 189:         if (''===$flag) {
 190:             return $this->_flags;
 191:         }
 192:         elseif (isset($this->_flags[$action][$flag])) {
 193:             return $this->_flags[$action][$flag];
 194:         }
 195:         else {
 196:             return false;
 197:         }
 198:     }
 199: 
 200:     /**
 201:      * Setting flag value
 202:      *
 203:      * @param   string $action
 204:      * @param   string $flag
 205:      * @param   string $value
 206:      * @return  Mage_Core_Controller_Varien_Action
 207:      */
 208:     public function setFlag($action, $flag, $value)
 209:     {
 210:         if (''===$action) {
 211:             $action = $this->getRequest()->getActionName();
 212:         }
 213:         $this->_flags[$action][$flag] = $value;
 214:         return $this;
 215:     }
 216: 
 217:     /**
 218:      * Retrieve full bane of current action current controller and
 219:      * current module
 220:      *
 221:      * @param   string $delimiter
 222:      * @return  string
 223:      */
 224:     public function getFullActionName($delimiter='_')
 225:     {
 226:         return $this->getRequest()->getRequestedRouteName().$delimiter.
 227:             $this->getRequest()->getRequestedControllerName().$delimiter.
 228:             $this->getRequest()->getRequestedActionName();
 229:     }
 230: 
 231:     /**
 232:      * Retrieve current layout object
 233:      *
 234:      * @return Mage_Core_Model_Layout
 235:      */
 236:     public function getLayout()
 237:     {
 238:         return Mage::getSingleton('core/layout');
 239:     }
 240: 
 241:     /**
 242:      * Load layout by handles(s)
 243:      *
 244:      * @param   string|null|bool $handles
 245:      * @param   bool $generateBlocks
 246:      * @param   bool $generateXml
 247:      * @return  Mage_Core_Controller_Varien_Action
 248:      */
 249:     public function loadLayout($handles = null, $generateBlocks = true, $generateXml = true)
 250:     {
 251:         // if handles were specified in arguments load them first
 252:         if (false!==$handles && ''!==$handles) {
 253:             $this->getLayout()->getUpdate()->addHandle($handles ? $handles : 'default');
 254:         }
 255: 
 256:         // add default layout handles for this action
 257:         $this->addActionLayoutHandles();
 258: 
 259:         $this->loadLayoutUpdates();
 260: 
 261:         if (!$generateXml) {
 262:             return $this;
 263:         }
 264:         $this->generateLayoutXml();
 265: 
 266:         if (!$generateBlocks) {
 267:             return $this;
 268:         }
 269:         $this->generateLayoutBlocks();
 270:         $this->_isLayoutLoaded = true;
 271: 
 272:         return $this;
 273:     }
 274: 
 275:     public function addActionLayoutHandles()
 276:     {
 277:         $update = $this->getLayout()->getUpdate();
 278: 
 279:         // load store handle
 280:         $update->addHandle('STORE_'.Mage::app()->getStore()->getCode());
 281: 
 282:         // load theme handle
 283:         $package = Mage::getSingleton('core/design_package');
 284:         $update->addHandle(
 285:             'THEME_'.$package->getArea().'_'.$package->getPackageName().'_'.$package->getTheme('layout')
 286:         );
 287: 
 288:         // load action handle
 289:         $update->addHandle(strtolower($this->getFullActionName()));
 290: 
 291:         return $this;
 292:     }
 293: 
 294:     public function loadLayoutUpdates()
 295:     {
 296:         $_profilerKey = self::PROFILER_KEY . '::' .$this->getFullActionName();
 297: 
 298:         // dispatch event for adding handles to layout update
 299:         Mage::dispatchEvent(
 300:             'controller_action_layout_load_before',
 301:             array('action'=>$this, 'layout'=>$this->getLayout())
 302:         );
 303: 
 304:         // load layout updates by specified handles
 305:         Varien_Profiler::start("$_profilerKey::layout_load");
 306:         $this->getLayout()->getUpdate()->load();
 307:         Varien_Profiler::stop("$_profilerKey::layout_load");
 308: 
 309:         return $this;
 310:     }
 311: 
 312:     public function generateLayoutXml()
 313:     {
 314:         $_profilerKey = self::PROFILER_KEY . '::' . $this->getFullActionName();
 315:         // dispatch event for adding text layouts
 316:         if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) {
 317:             Mage::dispatchEvent(
 318:                 'controller_action_layout_generate_xml_before',
 319:                 array('action'=>$this, 'layout'=>$this->getLayout())
 320:             );
 321:         }
 322: 
 323:         // generate xml from collected text updates
 324:         Varien_Profiler::start("$_profilerKey::layout_generate_xml");
 325:         $this->getLayout()->generateXml();
 326:         Varien_Profiler::stop("$_profilerKey::layout_generate_xml");
 327: 
 328:         return $this;
 329:     }
 330: 
 331:     public function generateLayoutBlocks()
 332:     {
 333:         $_profilerKey = self::PROFILER_KEY . '::' . $this->getFullActionName();
 334:         // dispatch event for adding xml layout elements
 335:         if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) {
 336:             Mage::dispatchEvent(
 337:                 'controller_action_layout_generate_blocks_before',
 338:                 array('action'=>$this, 'layout'=>$this->getLayout())
 339:             );
 340:         }
 341: 
 342:         // generate blocks from xml layout
 343:         Varien_Profiler::start("$_profilerKey::layout_generate_blocks");
 344:         $this->getLayout()->generateBlocks();
 345:         Varien_Profiler::stop("$_profilerKey::layout_generate_blocks");
 346: 
 347:         if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) {
 348:             Mage::dispatchEvent(
 349:                 'controller_action_layout_generate_blocks_after',
 350:                 array('action'=>$this, 'layout'=>$this->getLayout())
 351:             );
 352:         }
 353: 
 354:         return $this;
 355:     }
 356: 
 357:     /**
 358:      * Rendering layout
 359:      *
 360:      * @param   string $output
 361:      * @return  Mage_Core_Controller_Varien_Action
 362:      */
 363:     public function renderLayout($output='')
 364:     {
 365:         $_profilerKey = self::PROFILER_KEY . '::' . $this->getFullActionName();
 366: 
 367:         if ($this->getFlag('', 'no-renderLayout')) {
 368:             return;
 369:         }
 370: 
 371:         if (Mage::app()->getFrontController()->getNoRender()) {
 372:             return;
 373:         }
 374: 
 375:         $this->_renderTitles();
 376: 
 377:         Varien_Profiler::start("$_profilerKey::layout_render");
 378: 
 379: 
 380:         if (''!==$output) {
 381:             $this->getLayout()->addOutputBlock($output);
 382:         }
 383: 
 384:         Mage::dispatchEvent('controller_action_layout_render_before');
 385:         Mage::dispatchEvent('controller_action_layout_render_before_'.$this->getFullActionName());
 386: 
 387:         #ob_implicit_flush();
 388:         $this->getLayout()->setDirectOutput(false);
 389: 
 390:         $output = $this->getLayout()->getOutput();
 391:         Mage::getSingleton('core/translate_inline')->processResponseBody($output);
 392:         $this->getResponse()->appendBody($output);
 393:         Varien_Profiler::stop("$_profilerKey::layout_render");
 394: 
 395:         return $this;
 396:     }
 397: 
 398:     public function dispatch($action)
 399:     {
 400:         try {
 401:             $actionMethodName = $this->getActionMethodName($action);
 402: 
 403:             if (!is_callable(array($this, $actionMethodName))) {
 404:                 $actionMethodName = 'norouteAction';
 405:             }
 406: 
 407:             Varien_Profiler::start(self::PROFILER_KEY.'::predispatch');
 408:             $this->preDispatch();
 409:             Varien_Profiler::stop(self::PROFILER_KEY.'::predispatch');
 410: 
 411:             if ($this->getRequest()->isDispatched()) {
 412:                 /**
 413:                  * preDispatch() didn't change the action, so we can continue
 414:                  */
 415:                 if (!$this->getFlag('', self::FLAG_NO_DISPATCH)) {
 416:                     $_profilerKey = self::PROFILER_KEY.'::'.$this->getFullActionName();
 417: 
 418:                     Varien_Profiler::start($_profilerKey);
 419:                     $this->$actionMethodName();
 420:                     Varien_Profiler::stop($_profilerKey);
 421: 
 422:                     Varien_Profiler::start(self::PROFILER_KEY.'::postdispatch');
 423:                     $this->postDispatch();
 424:                     Varien_Profiler::stop(self::PROFILER_KEY.'::postdispatch');
 425:                 }
 426:             }
 427:         }
 428:         catch (Mage_Core_Controller_Varien_Exception $e) {
 429:             // set prepared flags
 430:             foreach ($e->getResultFlags() as $flagData) {
 431:                 list($action, $flag, $value) = $flagData;
 432:                 $this->setFlag($action, $flag, $value);
 433:             }
 434:             // call forward, redirect or an action
 435:             list($method, $parameters) = $e->getResultCallback();
 436:             switch ($method) {
 437:                 case Mage_Core_Controller_Varien_Exception::RESULT_REDIRECT:
 438:                     list($path, $arguments) = $parameters;
 439:                     $this->_redirect($path, $arguments);
 440:                     break;
 441:                 case Mage_Core_Controller_Varien_Exception::RESULT_FORWARD:
 442:                     list($action, $controller, $module, $params) = $parameters;
 443:                     $this->_forward($action, $controller, $module, $params);
 444:                     break;
 445:                 default:
 446:                     $actionMethodName = $this->getActionMethodName($method);
 447:                     $this->getRequest()->setActionName($method);
 448:                     $this->$actionMethodName($method);
 449:                     break;
 450:             }
 451:         }
 452:     }
 453: 
 454:     /**
 455:      * Retrieve action method name
 456:      *
 457:      * @param string $action
 458:      * @return string
 459:      */
 460:     public function getActionMethodName($action)
 461:     {
 462:         return $action . 'Action';
 463:     }
 464: 
 465:     /**
 466:      * Dispatch event before action
 467:      *
 468:      * @return void
 469:      */
 470:     public function preDispatch()
 471:     {
 472:         if (!$this->getFlag('', self::FLAG_NO_CHECK_INSTALLATION)) {
 473:             if (!Mage::isInstalled()) {
 474:                 $this->setFlag('', self::FLAG_NO_DISPATCH, true);
 475:                 $this->_redirect('install');
 476:                 return;
 477:             }
 478:         }
 479: 
 480:         // Prohibit disabled store actions
 481:         if (Mage::isInstalled() && !Mage::app()->getStore()->getIsActive()) {
 482:             Mage::app()->throwStoreException();
 483:         }
 484: 
 485:         if ($this->_rewrite()) {
 486:             return;
 487:         }
 488: 
 489:         if (!$this->getFlag('', self::FLAG_NO_START_SESSION)) {
 490:             $checkCookie = in_array($this->getRequest()->getActionName(), $this->_cookieCheckActions)
 491:                 && !$this->getRequest()->getParam('nocookie', false);
 492:             $cookies = Mage::getSingleton('core/cookie')->get();
 493:             /** @var $session Mage_Core_Model_Session */
 494:             $session = Mage::getSingleton('core/session', array('name' => $this->_sessionNamespace))->start();
 495: 
 496:             if (empty($cookies)) {
 497:                 if ($session->getCookieShouldBeReceived()) {
 498:                     $this->setFlag('', self::FLAG_NO_COOKIES_REDIRECT, true);
 499:                     $session->unsCookieShouldBeReceived();
 500:                     $session->setSkipSessionIdFlag(true);
 501:                 } elseif ($checkCookie) {
 502:                     if (isset($_GET[$session->getSessionIdQueryParam()]) && Mage::app()->getUseSessionInUrl()
 503:                         && $this->_sessionNamespace != Mage_Adminhtml_Controller_Action::SESSION_NAMESPACE
 504:                     ) {
 505:                         $session->setCookieShouldBeReceived(true);
 506:                     } else {
 507:                         $this->setFlag('', self::FLAG_NO_COOKIES_REDIRECT, true);
 508:                     }
 509:                 }
 510:             }
 511:         }
 512: 
 513:         Mage::app()->loadArea($this->getLayout()->getArea());
 514: 
 515:         if ($this->getFlag('', self::FLAG_NO_COOKIES_REDIRECT)
 516:             && Mage::getStoreConfig('web/browser_capabilities/cookies')
 517:         ) {
 518:             $this->_forward('noCookies', 'index', 'core');
 519:             return;
 520:         }
 521: 
 522:         if ($this->getFlag('', self::FLAG_NO_PRE_DISPATCH)) {
 523:             return;
 524:         }
 525: 
 526:         Varien_Autoload::registerScope($this->getRequest()->getRouteName());
 527: 
 528:         Mage::dispatchEvent('controller_action_predispatch', array('controller_action' => $this));
 529:         Mage::dispatchEvent('controller_action_predispatch_' . $this->getRequest()->getRouteName(),
 530:             array('controller_action' => $this));
 531:         Mage::dispatchEvent('controller_action_predispatch_' . $this->getFullActionName(),
 532:             array('controller_action' => $this));
 533:     }
 534: 
 535:     /**
 536:      * Dispatches event after action
 537:      */
 538:     public function postDispatch()
 539:     {
 540:         if ($this->getFlag('', self::FLAG_NO_POST_DISPATCH)) {
 541:             return;
 542:         }
 543: 
 544:         Mage::dispatchEvent(
 545:             'controller_action_postdispatch_'.$this->getFullActionName(),
 546:             array('controller_action'=>$this)
 547:         );
 548:         Mage::dispatchEvent(
 549:             'controller_action_postdispatch_'.$this->getRequest()->getRouteName(),
 550:             array('controller_action'=>$this)
 551:         );
 552:         Mage::dispatchEvent('controller_action_postdispatch', array('controller_action'=>$this));
 553:     }
 554: 
 555:     public function norouteAction($coreRoute = null)
 556:     {
 557:         $status = ( $this->getRequest()->getParam('__status__') )
 558:             ? $this->getRequest()->getParam('__status__')
 559:             : new Varien_Object();
 560: 
 561:         Mage::dispatchEvent('controller_action_noroute', array('action'=>$this, 'status'=>$status));
 562:         if ($status->getLoaded() !== true
 563:             || $status->getForwarded() === true
 564:             || !is_null($coreRoute) ) {
 565:             $this->loadLayout(array('default', 'noRoute'));
 566:             $this->renderLayout();
 567:         } else {
 568:             $status->setForwarded(true);
 569:             $this->_forward(
 570:                 $status->getForwardAction(),
 571:                 $status->getForwardController(),
 572:                 $status->getForwardModule(),
 573:                 array('__status__' => $status));
 574:         }
 575:     }
 576: 
 577:     public function noCookiesAction()
 578:     {
 579:         $redirect = new Varien_Object();
 580:         Mage::dispatchEvent('controller_action_nocookies', array(
 581:             'action'    => $this,
 582:             'redirect'  => $redirect
 583:         ));
 584: 
 585:         if ($url = $redirect->getRedirectUrl()) {
 586:             $this->_redirectUrl($url);
 587:         }
 588:         elseif ($redirect->getRedirect()) {
 589:             $this->_redirect($redirect->getPath(), $redirect->getArguments());
 590:         }
 591:         else {
 592:             $this->loadLayout(array('default', 'noCookie'));
 593:             $this->renderLayout();
 594:         }
 595: 
 596:         $this->getRequest()->setDispatched(true);
 597:     }
 598: 
 599:     /**
 600:      * Throw control to different action (control and module if was specified).
 601:      *
 602:      * @param string $action
 603:      * @param string|null $controller
 604:      * @param string|null $module
 605:      * @param array|null $params
 606:      */
 607:     protected function _forward($action, $controller = null, $module = null, array $params = null)
 608:     {
 609:         $request = $this->getRequest();
 610: 
 611:         $request->initForward();
 612: 
 613:         if (isset($params)) {
 614:             $request->setParams($params);
 615:         }
 616: 
 617:         if (isset($controller)) {
 618:             $request->setControllerName($controller);
 619: 
 620:             // Module should only be reset if controller has been specified
 621:             if (isset($module)) {
 622:                 $request->setModuleName($module);
 623:             }
 624:         }
 625: 
 626:         $request->setActionName($action)
 627:             ->setDispatched(false);
 628:     }
 629: 
 630:     /**
 631:      * Initializing layout messages by message storage(s), loading and adding messages to layout messages block
 632:      *
 633:      * @param string|array $messagesStorage
 634:      * @return Mage_Core_Controller_Varien_Action
 635:      */
 636:     protected function _initLayoutMessages($messagesStorage)
 637:     {
 638:         if (!is_array($messagesStorage)) {
 639:             $messagesStorage = array($messagesStorage);
 640:         }
 641:         foreach ($messagesStorage as $storageName) {
 642:             $storage = Mage::getSingleton($storageName);
 643:             if ($storage) {
 644:                 $block = $this->getLayout()->getMessagesBlock();
 645:                 $block->addMessages($storage->getMessages(true));
 646:                 $block->setEscapeMessageFlag($storage->getEscapeMessages(true));
 647:                 $block->addStorageType($storageName);
 648:             }
 649:             else {
 650:                 Mage::throwException(
 651:                      Mage::helper('core')->__('Invalid messages storage "%s" for layout messages initialization', (string) $storageName)
 652:                 );
 653:             }
 654:         }
 655:         return $this;
 656:     }
 657: 
 658:     /**
 659:      * Initializing layout messages by message storage(s), loading and adding messages to layout messages block
 660:      *
 661:      * @param string|array $messagesStorage
 662:      * @return Mage_Core_Controller_Varien_Action
 663:      */
 664:     public function initLayoutMessages($messagesStorage)
 665:     {
 666:         return $this->_initLayoutMessages($messagesStorage);
 667:     }
 668: 
 669:     /**
 670:      * Set redirect url into response
 671:      *
 672:      * @param   string $url
 673:      * @return  Mage_Core_Controller_Varien_Action
 674:      */
 675:     protected function _redirectUrl($url)
 676:     {
 677:         $this->getResponse()->setRedirect($url);
 678:         return $this;
 679:     }
 680: 
 681:     /**
 682:      * Set redirect into response
 683:      *
 684:      * @param   string $path
 685:      * @param   array $arguments
 686:      * @return  Mage_Core_Controller_Varien_Action
 687:      */
 688:     protected function _redirect($path, $arguments = array())
 689:     {
 690:         return $this->setRedirectWithCookieCheck($path, $arguments);
 691:     }
 692: 
 693:     /**
 694:      * Set redirect into response with session id in URL if it is enabled.
 695:      * It allows to distinguish primordial request from browser with cookies disabled.
 696:      *
 697:      * @param   string $path
 698:      * @param   array $arguments
 699:      * @return  Mage_Core_Controller_Varien_Action
 700:      */
 701:     public function setRedirectWithCookieCheck($path, array $arguments = array())
 702:     {
 703:         /** @var $session Mage_Core_Model_Session */
 704:         $session = Mage::getSingleton('core/session', array('name' => $this->_sessionNamespace));
 705:         if ($session->getCookieShouldBeReceived() && Mage::app()->getUseSessionInUrl()
 706:             && $this->_sessionNamespace != Mage_Adminhtml_Controller_Action::SESSION_NAMESPACE
 707:         ) {
 708:             $arguments += array('_query' => array(
 709:                 $session->getSessionIdQueryParam() => $session->getSessionId()
 710:             ));
 711:         }
 712:         $this->getResponse()->setRedirect(Mage::getUrl($path, $arguments));
 713:         return $this;
 714:     }
 715: 
 716: 
 717:     /**
 718:      * Redirect to success page
 719:      *
 720:      * @param string $defaultUrl
 721:      * @return Mage_Core_Controller_Varien_Action
 722:      */
 723:     protected function _redirectSuccess($defaultUrl)
 724:     {
 725:         $successUrl = $this->getRequest()->getParam(self::PARAM_NAME_SUCCESS_URL);
 726:         if (empty($successUrl)) {
 727:             $successUrl = $defaultUrl;
 728:         }
 729:         if (!$this->_isUrlInternal($successUrl)) {
 730:             $successUrl = Mage::app()->getStore()->getBaseUrl();
 731:         }
 732:         $this->getResponse()->setRedirect($successUrl);
 733:         return $this;
 734:     }
 735: 
 736:     /**
 737:      * Redirect to error page
 738:      *
 739:      * @param string $defaultUrl
 740:      * @return  Mage_Core_Controller_Varien_Action
 741:      */
 742:     protected function _redirectError($defaultUrl)
 743:     {
 744:         $errorUrl = $this->getRequest()->getParam(self::PARAM_NAME_ERROR_URL);
 745:         if (empty($errorUrl)) {
 746:             $errorUrl = $defaultUrl;
 747:         }
 748:         if (!$this->_isUrlInternal($errorUrl)) {
 749:             $errorUrl = Mage::app()->getStore()->getBaseUrl();
 750:         }
 751:         $this->getResponse()->setRedirect($errorUrl);
 752:         return $this;
 753:     }
 754: 
 755:     /**
 756:      * Set referer url for redirect in response
 757:      *
 758:      * @param   string $defaultUrl
 759:      * @return  Mage_Core_Controller_Varien_Action
 760:      */
 761:     protected function _redirectReferer($defaultUrl=null)
 762:     {
 763: 
 764:         $refererUrl = $this->_getRefererUrl();
 765:         if (empty($refererUrl)) {
 766:             $refererUrl = empty($defaultUrl) ? Mage::getBaseUrl() : $defaultUrl;
 767:         }
 768: 
 769:         $this->getResponse()->setRedirect($refererUrl);
 770:         return $this;
 771:     }
 772: 
 773:     /**
 774:      * Identify referer url via all accepted methods (HTTP_REFERER, regular or base64-encoded request param)
 775:      *
 776:      * @return string
 777:      */
 778:     protected function _getRefererUrl()
 779:     {
 780:         $refererUrl = $this->getRequest()->getServer('HTTP_REFERER');
 781:         if ($url = $this->getRequest()->getParam(self::PARAM_NAME_REFERER_URL)) {
 782:             $refererUrl = $url;
 783:         }
 784:         if ($url = $this->getRequest()->getParam(self::PARAM_NAME_BASE64_URL)) {
 785:             $refererUrl = Mage::helper('core')->urlDecode($url);
 786:         }
 787:         if ($url = $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED)) {
 788:             $refererUrl = Mage::helper('core')->urlDecode($url);
 789:         }
 790: 
 791:         $refererUrl = Mage::helper('core')->escapeUrl($refererUrl);
 792: 
 793:         if (!$this->_isUrlInternal($refererUrl)) {
 794:             $refererUrl = Mage::app()->getStore()->getBaseUrl();
 795:         }
 796:         return $refererUrl;
 797:     }
 798: 
 799:     /**
 800:      * Check url to be used as internal
 801:      *
 802:      * @param   string $url
 803:      * @return  bool
 804:      */
 805:     protected function _isUrlInternal($url)
 806:     {
 807:         if (strpos($url, 'http') !== false) {
 808:             /**
 809:              * Url must start from base secure or base unsecure url
 810:              */
 811:             if ((strpos($url, Mage::app()->getStore()->getBaseUrl()) === 0)
 812:                 || (strpos($url, Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true)) === 0)
 813:             ) {
 814:                 return true;
 815:             }
 816:         }
 817:         return false;
 818:     }
 819: 
 820:     /**
 821:      * Get real module name (like 'Mage_Module')
 822:      *
 823:      * @return  string
 824:      */
 825:     protected function _getRealModuleName()
 826:     {
 827:         if (empty($this->_realModuleName)) {
 828:             $class = get_class($this);
 829:             $this->_realModuleName = substr(
 830:                 $class,
 831:                 0,
 832:                 strpos(strtolower($class), '_' . strtolower($this->getRequest()->getControllerName() . 'Controller'))
 833:             );
 834:         }
 835:         return $this->_realModuleName;
 836:     }
 837: 
 838:     /**
 839:      * Support for controllers rewrites
 840:      *
 841:      * Example of configuration:
 842:      * <global>
 843:      *   <routers>
 844:      *     <core_module>
 845:      *       <rewrite>
 846:      *         <core_controller>
 847:      *           <to>new_route/new_controller</to>
 848:      *           <override_actions>true</override_actions>
 849:      *           <actions>
 850:      *             <core_action><to>new_module/new_controller/new_action</core_action>
 851:      *           </actions>
 852:      *         <core_controller>
 853:      *       </rewrite>
 854:      *     </core_module>
 855:      *   </routers>
 856:      * </global>
 857:      *
 858:      * This will override:
 859:      * 1. core_module/core_controller/core_action to new_module/new_controller/new_action
 860:      * 2. all other actions of core_module/core_controller to new_module/new_controller
 861:      *
 862:      * @return boolean true if rewrite happened
 863:      */
 864:     protected function _rewrite()
 865:     {
 866:         $route = $this->getRequest()->getRouteName();
 867:         $controller = $this->getRequest()->getControllerName();
 868:         $action = $this->getRequest()->getActionName();
 869: 
 870:         $rewrite = Mage::getConfig()->getNode('global/routers/'.$route.'/rewrite/'.$controller);
 871:         if (!$rewrite) {
 872:             return false;
 873:         }
 874: 
 875:         if (!($rewrite->actions && $rewrite->actions->$action) || $rewrite->is('override_actions')) {
 876:             $t = explode('/', (string)$rewrite->to);
 877:             if (sizeof($t)!==2 || empty($t[0]) || empty($t[1])) {
 878:                 return false;
 879:             }
 880:             $t[2] = $action;
 881:         } else {
 882:             $t = explode('/', (string)$rewrite->actions->$action->to);
 883:             if (sizeof($t)!==3 || empty($t[0]) || empty($t[1]) || empty($t[2])) {
 884:                 return false;
 885:             }
 886:         }
 887: 
 888:         $this->_forward(
 889:             $t[2]==='*' ? $action : $t[2],
 890:             $t[1]==='*' ? $controller : $t[1],
 891:             $t[0]==='*' ? $route : $t[0]
 892:         );
 893: 
 894:         return true;
 895:     }
 896: 
 897:     /**
 898:      * Validate Form Key
 899:      *
 900:      * @return bool
 901:      */
 902:     protected function _validateFormKey()
 903:     {
 904:         if (!($formKey = $this->getRequest()->getParam('form_key', null))
 905:             || $formKey != Mage::getSingleton('core/session')->getFormKey()) {
 906:             return false;
 907:         }
 908:         return true;
 909:     }
 910: 
 911:     /**
 912:      * Add an extra title to the end or one from the end, or remove all
 913:      *
 914:      * Usage examples:
 915:      * $this->_title('foo')->_title('bar');
 916:      * => bar / foo / <default title>
 917:      *
 918:      * $this->_title()->_title('foo')->_title('bar');
 919:      * => bar / foo
 920:      *
 921:      * $this->_title('foo')->_title(false)->_title('bar');
 922:      * bar / <default title>
 923:      *
 924:      * @see self::_renderTitles()
 925:      * @param string|false|-1|null $text
 926:      * @param bool $resetIfExists
 927:      * @return Mage_Core_Controller_Varien_Action
 928:      */
 929:     protected function _title($text = null, $resetIfExists = true)
 930:     {
 931:         if (is_string($text)) {
 932:             $this->_titles[] = $text;
 933:         } elseif (-1 === $text) {
 934:             if (empty($this->_titles)) {
 935:                 $this->_removeDefaultTitle = true;
 936:             } else {
 937:                 array_pop($this->_titles);
 938:             }
 939:         } elseif (empty($this->_titles) || $resetIfExists) {
 940:             if (false === $text) {
 941:                 $this->_removeDefaultTitle = false;
 942:                 $this->_titles = array();
 943:             } elseif (null === $text) {
 944:                 $this->_removeDefaultTitle = true;
 945:                 $this->_titles = array();
 946:             }
 947:         }
 948:         return $this;
 949:     }
 950: 
 951:     /**
 952:      * Prepare titles in the 'head' layout block
 953:      * Supposed to work only in actions where layout is rendered
 954:      * Falls back to the default logic if there are no titles eventually
 955:      *
 956:      * @see self::loadLayout()
 957:      * @see self::renderLayout()
 958:      */
 959:     protected function _renderTitles()
 960:     {
 961:         if ($this->_isLayoutLoaded && $this->_titles) {
 962:             $titleBlock = $this->getLayout()->getBlock('head');
 963:             if ($titleBlock) {
 964:                 if (!$this->_removeDefaultTitle) {
 965:                     $title = trim($titleBlock->getTitle());
 966:                     if ($title) {
 967:                         array_unshift($this->_titles, $title);
 968:                     }
 969:                 }
 970:                 $titleBlock->setTitle(implode(' / ', array_reverse($this->_titles)));
 971:             }
 972:         }
 973:     }
 974: 
 975:     /**
 976:      * Convert dates in array from localized to internal format
 977:      *
 978:      * @param   array $array
 979:      * @param   array $dateFields
 980:      * @return  array
 981:      */
 982:     protected function _filterDates($array, $dateFields)
 983:     {
 984:         if (empty($dateFields)) {
 985:             return $array;
 986:         }
 987:         $filterInput = new Zend_Filter_LocalizedToNormalized(array(
 988:             'date_format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
 989:         ));
 990:         $filterInternal = new Zend_Filter_NormalizedToLocalized(array(
 991:             'date_format' => Varien_Date::DATE_INTERNAL_FORMAT
 992:         ));
 993: 
 994:         foreach ($dateFields as $dateField) {
 995:             if (array_key_exists($dateField, $array) && !empty($dateField)) {
 996:                 $array[$dateField] = $filterInput->filter($array[$dateField]);
 997:                 $array[$dateField] = $filterInternal->filter($array[$dateField]);
 998:             }
 999:         }
1000:         return $array;
1001:     }
1002: 
1003:     /**
1004:      * Convert dates with time in array from localized to internal format
1005:      *
1006:      * @param   array $array
1007:      * @param   array $dateFields
1008:      * @return  array
1009:      */
1010:     protected function _filterDateTime($array, $dateFields)
1011:     {
1012:         if (empty($dateFields)) {
1013:             return $array;
1014:         }
1015:         $filterInput = new Zend_Filter_LocalizedToNormalized(array(
1016:             'date_format' => Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
1017:         ));
1018:         $filterInternal = new Zend_Filter_NormalizedToLocalized(array(
1019:             'date_format' => Varien_Date::DATETIME_INTERNAL_FORMAT
1020:         ));
1021: 
1022:         foreach ($dateFields as $dateField) {
1023:             if (array_key_exists($dateField, $array) && !empty($dateField)) {
1024:                 $array[$dateField] = $filterInput->filter($array[$dateField]);
1025:                 $array[$dateField] = $filterInternal->filter($array[$dateField]);
1026:             }
1027:         }
1028:         return $array;
1029:     }
1030: 
1031:     /**
1032:      * Declare headers and content file in response for file download
1033:      *
1034:      * @param string $fileName
1035:      * @param string|array $content set to null to avoid starting output, $contentLength should be set explicitly in
1036:      *                              that case
1037:      * @param string $contentType
1038:      * @param int $contentLength    explicit content length, if strlen($content) isn't applicable
1039:      * @return Mage_Core_Controller_Varien_Action
1040:      */
1041:     protected function _prepareDownloadResponse(
1042:         $fileName,
1043:         $content,
1044:         $contentType = 'application/octet-stream',
1045:         $contentLength = null)
1046:     {
1047:         $session = Mage::getSingleton('admin/session');
1048:         if ($session->isFirstPageAfterLogin()) {
1049:             $this->_redirect($session->getUser()->getStartupPageUrl());
1050:             return $this;
1051:         }
1052: 
1053:         $isFile = false;
1054:         $file   = null;
1055:         if (is_array($content)) {
1056:             if (!isset($content['type']) || !isset($content['value'])) {
1057:                 return $this;
1058:             }
1059:             if ($content['type'] == 'filename') {
1060:                 $isFile         = true;
1061:                 $file           = $content['value'];
1062:                 $contentLength  = filesize($file);
1063:             }
1064:         }
1065: 
1066:         $this->getResponse()
1067:             ->setHttpResponseCode(200)
1068:             ->setHeader('Pragma', 'public', true)
1069:             ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
1070:             ->setHeader('Content-type', $contentType, true)
1071:             ->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true)
1072:             ->setHeader('Content-Disposition', 'attachment; filename="'.$fileName.'"', true)
1073:             ->setHeader('Last-Modified', date('r'), true);
1074: 
1075:         if (!is_null($content)) {
1076:             if ($isFile) {
1077:                 $this->getResponse()->clearBody();
1078:                 $this->getResponse()->sendHeaders();
1079: 
1080:                 $ioAdapter = new Varien_Io_File();
1081:                 $ioAdapter->open(array('path' => $ioAdapter->dirname($file)));
1082:                 $ioAdapter->streamOpen($file, 'r');
1083:                 while ($buffer = $ioAdapter->streamRead()) {
1084:                     print $buffer;
1085:                 }
1086:                 $ioAdapter->streamClose();
1087:                 if (!empty($content['rm'])) {
1088:                     $ioAdapter->rm($file);
1089:                 }
1090: 
1091:                 exit(0);
1092:             } else {
1093:                 $this->getResponse()->setBody($content);
1094:             }
1095:         }
1096:         return $this;
1097:     }
1098: }
1099: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0