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_XmlConnect_Adminhtml_MobileController
  • Mage_XmlConnect_Block_Adminhtml_History
  • Mage_XmlConnect_Block_Adminhtml_History_Grid
  • Mage_XmlConnect_Block_Adminhtml_Mobile
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Form
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Submission
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Cache
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Content
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Images
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Tabs
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Accordion_Themes
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Preview
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Design_Themes
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Flurryanalytics
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_General
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Notification
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Payment
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Settings
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Social
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Submission_History
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tabs
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Addrow
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Color
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Country
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Datetime
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Font
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Image
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Page
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Tabs
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Theme
  • Mage_Xmlconnect_Block_Adminhtml_Mobile_Grid
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Grid_Renderer_Bool
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Grid_Renderer_Type
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Content
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Preview_Tabitems
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Form
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Androidmarket
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Renderer_Country_Istore
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tab_Container
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tab_Container_Submission
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Submission_Tabs
  • Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
  • Mage_XmlConnect_Block_Adminhtml_Queue
  • Mage_XmlConnect_Block_Adminhtml_Queue_Edit
  • Mage_XmlConnect_Block_Adminhtml_Queue_Edit_Form
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Action
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Application
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Id
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Msgtitle
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Pushtitle
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Status
  • Mage_XmlConnect_Block_Adminhtml_Queue_Grid_Renderer_Template
  • Mage_XmlConnect_Block_Adminhtml_Template
  • Mage_XmlConnect_Block_Adminhtml_Template_Edit
  • Mage_XmlConnect_Block_Adminhtml_Template_Edit_Form
  • Mage_XmlConnect_Block_Adminhtml_Template_Grid
  • Mage_XmlConnect_Block_Adminhtml_Template_Grid_Renderer_Application
  • Mage_XmlConnect_Block_Adminhtml_Template_Grid_Renderer_Name
  • Mage_XmlConnect_Block_Adminhtml_Template_Preview
  • Mage_XmlConnect_Block_Adminhtml_Template_Preview_Form
  • Mage_XmlConnect_Block_Cart
  • Mage_XmlConnect_Block_Cart_Crosssell
  • Mage_XmlConnect_Block_Cart_Info
  • Mage_XmlConnect_Block_Cart_Item_Renderer
  • Mage_XmlConnect_Block_Cart_Item_Renderer_Configurable
  • Mage_XmlConnect_Block_Cart_Item_Renderer_Grouped
  • Mage_XmlConnect_Block_Cart_Paypal_Mecl_Details
  • Mage_XmlConnect_Block_Cart_Paypal_Mecl_Review
  • Mage_XmlConnect_Block_Cart_Paypal_Mecl_Shippingmethods
  • Mage_XmlConnect_Block_Cart_Paypal_Mep_Totals
  • Mage_XmlConnect_Block_Cart_Totals
  • Mage_XmlConnect_Block_Catalog
  • Mage_XmlConnect_Block_Catalog_Category
  • Mage_XmlConnect_Block_Catalog_Category_Info
  • Mage_XmlConnect_Block_Catalog_Filters
  • Mage_XmlConnect_Block_Catalog_Product
  • Mage_XmlConnect_Block_Catalog_Product_Attributes
  • Mage_XmlConnect_Block_Catalog_Product_Gallery
  • Mage_XmlConnect_Block_Catalog_Product_List
  • Mage_XmlConnect_Block_Catalog_Product_Options
  • Mage_XmlConnect_Block_Catalog_Product_Options_Bundle
  • Mage_XmlConnect_Block_Catalog_Product_Options_Configurable
  • Mage_XmlConnect_Block_Catalog_Product_Options_Giftcard
  • Mage_XmlConnect_Block_Catalog_Product_Options_Grouped
  • Mage_XmlConnect_Block_Catalog_Product_Options_Simple
  • Mage_XmlConnect_Block_Catalog_Product_Options_Virtual
  • Mage_XmlConnect_Block_Catalog_Product_Price
  • Mage_XmlConnect_Block_Catalog_Product_Price_Bundle
  • Mage_XmlConnect_Block_Catalog_Product_Price_Default
  • Mage_XmlConnect_Block_Catalog_Product_Price_Giftcard
  • Mage_XmlConnect_Block_Catalog_Product_Related
  • Mage_XmlConnect_Block_Catalog_Product_Review
  • Mage_XmlConnect_Block_Catalog_Product_Review_List
  • Mage_XmlConnect_Block_Catalog_Search
  • Mage_XmlConnect_Block_Catalog_Search_Suggest
  • Mage_XmlConnect_Block_Checkout_Address_Billing
  • Mage_XmlConnect_Block_Checkout_Address_Form
  • Mage_XmlConnect_Block_Checkout_Address_Shipping
  • Mage_XmlConnect_Block_Checkout_Agreements
  • Mage_XmlConnect_Block_Checkout_Order_Review
  • Mage_XmlConnect_Block_Checkout_Order_Review_Info
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Authorizenet
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Ccsave
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Checkmo
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Authorizenet
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Ccsave
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Checkmo
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Free
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Abstract
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Express
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Paypal_Mecl
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Authorizenet
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Paypal_Direct
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Paypaluk_Direct
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Pbridge_Verisign
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Info_Purchaseorder
  • Mage_XmlConnect_Block_Checkout_Payment_Method_List
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Paypal_Direct
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Paypal_Payflow
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Abstract
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Authorizenet
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Paypal
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Paypaluk
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Pbridge_Verisign
  • Mage_XmlConnect_Block_Checkout_Payment_Method_Purchaseorder
  • Mage_XmlConnect_Block_Checkout_Pbridge_Result
  • Mage_XmlConnect_Block_Checkout_Shipping_Method_Available
  • Mage_XmlConnect_Block_Cms_Page
  • Mage_XmlConnect_Block_Configuration
  • Mage_XmlConnect_Block_Customer_Address_Form
  • Mage_XmlConnect_Block_Customer_Address_List
  • Mage_XmlConnect_Block_Customer_Form
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Boolean
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Date
  • Mage_XmlConnect_Block_Customer_Form_Renderer_File
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Image
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Multiline
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Multiselect
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Select
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Text
  • Mage_XmlConnect_Block_Customer_Form_Renderer_Textarea
  • Mage_XmlConnect_Block_Customer_GiftcardCheck
  • Mage_XmlConnect_Block_Customer_Order_Details
  • Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Bundle
  • Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Default
  • Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Downloadable
  • Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Giftcard
  • Mage_XmlConnect_Block_Customer_Order_Item_Renderer_Grouped
  • Mage_XmlConnect_Block_Customer_Order_Items
  • Mage_XmlConnect_Block_Customer_Order_List
  • Mage_XmlConnect_Block_Customer_Order_Totals
  • Mage_XmlConnect_Block_Customer_Order_Totals_Customerbalance
  • Mage_XmlConnect_Block_Customer_Order_Totals_Customerbalance_Refunded
  • Mage_XmlConnect_Block_Customer_Order_Totals_Giftcards
  • Mage_XmlConnect_Block_Customer_Order_Totals_Tax
  • Mage_XmlConnect_Block_Customer_Storecredit
  • Mage_XmlConnect_Block_Home
  • Mage_XmlConnect_Block_Review_Form
  • Mage_XmlConnect_Block_Wishlist
  • Mage_XmlConnect_CartController
  • Mage_XmlConnect_CatalogController
  • Mage_XmlConnect_CheckoutController
  • Mage_XmlConnect_CmsController
  • Mage_XmlConnect_ConfigurationController
  • Mage_XmlConnect_Controller_Action
  • Mage_XmlConnect_CustomerController
  • Mage_XmlConnect_Helper_Android
  • Mage_XmlConnect_Helper_Catalog_Category_Image
  • Mage_XmlConnect_Helper_Customer_Form_Renderer
  • Mage_XmlConnect_Helper_Customer_Order
  • Mage_XmlConnect_Helper_Data
  • Mage_XmlConnect_Helper_Image
  • Mage_XmlConnect_Helper_Ipad
  • Mage_XmlConnect_Helper_Iphone
  • Mage_XmlConnect_Helper_Theme
  • Mage_XmlConnect_IndexController
  • Mage_XmlConnect_Model_Adminhtml_System_Config_Backend_Baseurl
  • Mage_XmlConnect_Model_Adminhtml_System_Config_Backend_Currency_Default
  • Mage_XmlConnect_Model_Application
  • Mage_XmlConnect_Model_Catalog_Category_Image
  • Mage_XmlConnect_Model_ConfigData
  • Mage_XmlConnect_Model_History
  • Mage_XmlConnect_Model_Mysql4_Application
  • Mage_XmlConnect_Model_Mysql4_Application_Collection
  • Mage_XmlConnect_Model_Mysql4_Cms_Page_Collection
  • Mage_XmlConnect_Model_Mysql4_ConfigData
  • Mage_XmlConnect_Model_Mysql4_ConfigData_Collection
  • Mage_XmlConnect_Model_Mysql4_Filter_Collection
  • Mage_XmlConnect_Model_Mysql4_History
  • Mage_XmlConnect_Model_Mysql4_History_Collection
  • Mage_XmlConnect_Model_Mysql4_Queue
  • Mage_XmlConnect_Model_Mysql4_Queue_Collection
  • Mage_XmlConnect_Model_Mysql4_Setup
  • Mage_XmlConnect_Model_Mysql4_Template
  • Mage_XmlConnect_Model_Mysql4_Template_Collection
  • Mage_XmlConnect_Model_Observer
  • Mage_XmlConnect_Model_Payment_Method_Paypal_Config
  • Mage_XmlConnect_Model_Payment_Method_Paypal_Mecl
  • Mage_XmlConnect_Model_Payment_Method_Paypal_Mep
  • Mage_XmlConnect_Model_Paypal_Mecl_Checkout
  • Mage_XmlConnect_Model_Paypal_Mep_Checkout
  • Mage_XmlConnect_Model_Preview_Abstract
  • Mage_XmlConnect_Model_Preview_Android
  • Mage_XmlConnect_Model_Preview_Ipad
  • Mage_XmlConnect_Model_Preview_Iphone
  • Mage_XmlConnect_Model_Queue
  • Mage_XmlConnect_Model_Resource_Application
  • Mage_XmlConnect_Model_Resource_Application_Collection
  • Mage_XmlConnect_Model_Resource_Cms_Page_Collection
  • Mage_XmlConnect_Model_Resource_ConfigData
  • Mage_XmlConnect_Model_Resource_ConfigData_Collection
  • Mage_XmlConnect_Model_Resource_Filter_Collection
  • Mage_XmlConnect_Model_Resource_History
  • Mage_XmlConnect_Model_Resource_History_Collection
  • Mage_XmlConnect_Model_Resource_Queue
  • Mage_XmlConnect_Model_Resource_Queue_Collection
  • Mage_XmlConnect_Model_Resource_Setup
  • Mage_XmlConnect_Model_Resource_Template
  • Mage_XmlConnect_Model_Resource_Template_Collection
  • Mage_XmlConnect_Model_Simplexml_Element
  • Mage_XmlConnect_Model_Simplexml_Form
  • Mage_XmlConnect_Model_Simplexml_Form_Abstract
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Abstract
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Checkbox
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Collection
  • Mage_XmlConnect_Model_Simplexml_Form_Element_CountryListSelect
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Date
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Email
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Fieldset
  • Mage_XmlConnect_Model_Simplexml_Form_Element_File
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Image
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Multiline
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Multiselect
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Select
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Text
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Textarea
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Validator
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Validator_Abstract
  • Mage_XmlConnect_Model_Simplexml_Form_Element_Validator_Rule
  • Mage_XmlConnect_Model_Tabs
  • Mage_XmlConnect_Model_Template
  • Mage_XmlConnect_Model_Theme
  • Mage_XmlConnect_Paypal_MeclController
  • Mage_XmlConnect_Paypal_MepController
  • Mage_XmlConnect_PbridgeController
  • Mage_XmlConnect_ReviewController
  • Mage_XmlConnect_WishlistController

Interfaces

  • Mage_XmlConnect_Model_Simplexml_Form_Element_Renderer_Interface
  • 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_XmlConnect
 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:  * XmlConnect image helper
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_XmlConnect
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_XmlConnect_Helper_Image extends Mage_Core_Helper_Abstract
 35: {
 36:     /**
 37:      * Xml connect glue
 38:      */
 39:     const XMLCONNECT_GLUE = '_';
 40: 
 41:     /**
 42:      * Image limits for content
 43:      *
 44:      * @var array|null
 45:      */
 46:     protected $_content = null;
 47: 
 48:     /**
 49:      * Image limits for interface
 50:      *
 51:      * @var array|null
 52:      */
 53:     protected $_interface = null;
 54: 
 55:     /**
 56:      * Array of interface image paths in xmlConfig
 57:      *
 58:      * @var array
 59:      */
 60:     protected $_interfacePath = array();
 61: 
 62:     /**
 63:      * Image limits array
 64:      *
 65:      * @var array
 66:      */
 67:     protected $_imageLimits = array();
 68: 
 69:     /**
 70:      * Images paths in the config
 71:      *
 72:      * @var array|null
 73:      */
 74:     protected $_confPaths = null;
 75: 
 76:     /**
 77:      * Process uploaded file
 78:      * setup file names to the configuration
 79:      *
 80:      * @param string $field
 81:      * @retun string
 82:      */
 83:     public function handleUpload($field)
 84:     {
 85:         $uploadedFilename = '';
 86:         $uploadDir = $this->getOriginalSizeUploadDir();
 87: 
 88:         try {
 89:             $this->_forcedConvertPng($field);
 90: 
 91:             /** @var $uploader Mage_Core_Model_File_Uploader */
 92:             $uploader = Mage::getModel('core/file_uploader', $field);
 93:             $uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
 94:             $uploader->setAllowRenameFiles(true);
 95:             $uploader->save($uploadDir);
 96:             $uploadedFilename = $uploader->getUploadedFileName();
 97:             $uploadedFilename = $this->_getResizedFilename($field, $uploadedFilename, true);
 98:         } catch (Exception $e) {
 99:             /**
100:              * Hard coded exception catch
101:              */
102:             if (!strlen($_FILES[$field]['tmp_name'])) {
103:                 Mage::throwException(Mage::helper('xmlconnect')->__('File can\'t be uploaded.'));
104:             } elseif ($e->getMessage() == 'Disallowed file type.') {
105:                 $filename = $_FILES[$field]['name'];
106:                 Mage::throwException(
107:                     Mage::helper('xmlconnect')->__('Error while uploading file "%s". Disallowed file type. Only "jpg", "jpeg", "gif", "png" are allowed.', $filename)
108:                 );
109:             } else {
110:                 Mage::logException($e);
111:             }
112:         }
113:         return basename($uploadedFilename);
114:     }
115: 
116:     /**
117:      * Return current screen_size parameter
118:      *
119:      * @return string
120:      */
121:     protected function _getScreenSize()
122:     {
123:         return Mage::helper('xmlconnect')->getApplication()->getScreenSize();
124:     }
125: 
126:     /**
127:      * Return correct system filename for current screenSize
128:      *
129:      * @throws Mage_Core_Exception
130:      * @param string $fieldPath
131:      * @param string $fileName
132:      * @param bool $default
133:      * @return string
134:      */
135:     protected function _getResizedFilename($fieldPath, $fileName, $default = false)
136:     {
137:         $fileName = basename($fileName);
138:         if ($default) {
139:             $dir = $this->getDefaultSizeUploadDir();
140:         } else {
141:             $dir = $this->getCustomSizeUploadDir($this->_getScreenSize());
142:         }
143:         $customSizeFileName =  $dir . DS . $fileName;
144:         $originalSizeFileName = $this->getOriginalSizeUploadDir(). DS . $fileName;
145: 
146:         /**
147:          * Compatibility with old versions of XmlConnect
148:          */
149:         if (!file_exists($originalSizeFileName)) {
150:             $oldFileName = $this->getOldUploadDir() . DS . $fileName;
151:             if (file_exists($oldFileName)) {
152:                 if (!(copy($oldFileName, $originalSizeFileName)
153:                     && (is_readable($customSizeFileName) || chmod($customSizeFileName, 0644))
154:                 )) {
155:                     Mage::throwException(
156:                         Mage::helper('xmlconnect')->__('Error while processing file "%s".', $fileName)
157:                     );
158:                 }
159:             } else {
160:                 Mage::throwException(Mage::helper('xmlconnect')->__('No such file "%s".', $fileName));
161:             }
162:         }
163: 
164:         $isCopied = copy($originalSizeFileName, $customSizeFileName);
165:         clearstatcache();
166:         if ($isCopied && (is_readable($customSizeFileName) || chmod($customSizeFileName, 0644))) {
167:             $this->_handleResize($fieldPath, $customSizeFileName);
168:         } else {
169:             $fileName = '';
170:             if (isset($_FILES[$fieldPath]) && is_array($_FILES[$fieldPath]) && isset($_FILES[$fieldPath]['name'])) {
171:                 $fileName = $_FILES[$fieldPath]['name'];
172:             }
173:             Mage::throwException(Mage::helper('xmlconnect')->__('Error while uploading file "%s".', $fileName));
174:         }
175:         return $customSizeFileName;
176:     }
177: 
178:     /**
179:      * Resize uploaded file
180:      *
181:      * @param string $fieldPath
182:      * @param string $file
183:      * @return null
184:      */
185:     protected function _handleResize($fieldPath, $file)
186:     {
187:         $nameParts = explode('/', $fieldPath);
188:         array_shift($nameParts);
189:         $conf = $this->getInterfaceImageLimits();
190:         while (count($nameParts)) {
191:             $next = array_shift($nameParts);
192:             if (isset($conf[$next])) {
193:                 $conf = $conf[$next];
194:             } else {
195:                 /**
196:                  * No config data - nothing to resize
197:                  */
198:                 return;
199:             }
200:         }
201: 
202:         $image = new Varien_Image($file);
203:         $width = $image->getOriginalWidth();
204:         $height = $image->getOriginalHeight();
205: 
206:         if (isset($conf['widthMax']) && ($conf['widthMax'] < $width)) {
207:             $width = $conf['widthMax'];
208:         } elseif (isset($conf['width'])) {
209:             $width = $conf['width'];
210:         }
211: 
212:         if (isset($conf['heightMax']) && ($conf['heightMax'] < $height)) {
213:             $height = $conf['heightMax'];
214:         } elseif (isset($conf['height'])) {
215:             $height = $conf['height'];
216:         }
217: 
218:         if (($width != $image->getOriginalWidth()) || ($height != $image->getOriginalHeight())) {
219:             $image->keepTransparency(true);
220:             $image->keepFrame(true);
221:             $image->keepAspectRatio(true);
222:             $image->backgroundColor(array(255, 255, 255));
223:             $image->resize($width, $height);
224:             $image->save(null, basename($file));
225:         }
226:     }
227: 
228:     /**
229:      * Convert uploaded file to PNG
230:      *
231:      * @param string $field
232:      */
233:     protected function _forcedConvertPng($field)
234:     {
235:         $file =& $_FILES[$field];
236: 
237:         $dotPosition = strrpos($file['name'], '.');
238:         if ($dotPosition !== false) {
239:             $file['name'] = substr($file['name'], 0 , $dotPosition);
240:         }
241:         $file['name'] .= '.png';
242: 
243: //      We can't use exif extension, because magento doesn't require it.
244: //      $fileType = exif_imagetype($file['tmp_name']);
245:         list($unnecessaryVar, $unnecessaryVar, $fileType) = getimagesize($file['tmp_name']);
246:         unset($unnecessaryVar);
247: 
248:         if ($fileType != IMAGETYPE_PNG) {
249:             switch ($fileType) {
250:                 case IMAGETYPE_GIF:
251:                     $img = imagecreatefromgif($file['tmp_name']);
252:                     imagealphablending($img, false);
253:                     imagesavealpha($img, true);
254:                     break;
255:                 case IMAGETYPE_JPEG:
256:                     $img = imagecreatefromjpeg($file['tmp_name']);
257:                     break;
258:                 case IMAGETYPE_WBMP:
259:                     $img = imagecreatefromwbmp($file['tmp_name']);
260:                     break;
261:                 case IMAGETYPE_XBM:
262:                     $img = imagecreatefromxbm($file['tmp_name']);
263:                     break;
264:                 default:
265:                     return;
266:             }
267:             imagepng($img, $file['tmp_name']);
268:             imagedestroy($img);
269:         }
270:     }
271: 
272:     /**
273:      * Retrieve xmlconnect images skin url
274:      *
275:      * @param string $name
276:      * @return string
277:      */
278:     public function getSkinImagesUrl($name = null)
279:     {
280:         return Mage::getDesign()->getSkinUrl('images/xmlconnect/' . $name);
281:     }
282: 
283:     /**
284:      * Return CustomSizeDirPrefix
285:      *
286:      * @return string
287:      */
288:     public function getCustomSizeDirPrefix()
289:     {
290:         return $this->_getScreenSize() . DS . 'custom';
291:     }
292: 
293:     /**
294:      * Return FileDefaultSizeSuffixAsUrl
295:      *
296:      * @param string $fileName
297:      * @return string
298:      */
299:     public function getFileDefaultSizeSuffixAsUrl($fileName)
300:     {
301:         return 'custom' . '/' . $this->_getScreenSize() . '/' . basename($fileName);
302:     }
303: 
304:     /**
305:      * Return getFileCustomDirSuffixAsUrl
306:      *
307:      * @param string $confPath
308:      * @param string $fileName
309:      * @return string
310:      */
311:     public function getFileCustomDirSuffixAsUrl($confPath, $fileName)
312:     {
313:         return 'custom'
314:             . '/'
315:             . $this->_getScreenSize()
316:             . '/'
317:             . basename($this->_getResizedFilename($confPath, $fileName));
318:     }
319: 
320:     /**
321:      * Return correct size for given $imageName and device screen_size
322:      *
323:      * @param string $imageName
324:      * @return int
325:      */
326:     public function getImageSizeForContent($imageName)
327:     {
328:         if (!isset($this->_content)) {
329:             $imageLimits = $this->getImageLimits($this->_getScreenSize());
330:             if (($imageLimits['content']) && is_array($imageLimits['content'])) {
331:                 $this->_content = $imageLimits['content'];
332:             } else {
333:                 $this->_content = array();
334:             }
335:         }
336:         $size = isset($this->_content[$imageName]) ? (int) $this->_content[$imageName] : 0;
337:         return $size;
338:     }
339: 
340:     /**
341:      * Return setting for interface images (image size limits)
342:      *
343:      * @return array
344:      */
345:     public function getInterfaceImageLimits()
346:     {
347:         if (!isset($this->_interface)) {
348:             $imageLimits = $this->getImageLimits($this->_getScreenSize());
349:             $this->_interface = $imageLimits['interface'];
350:         }
351:         return $this->_interface;
352:     }
353: 
354:     /**
355:      * Return correct size for given $imageName and device screen_size
356:      *
357:      * @param string $imagePath
358:      * @return int
359:      */
360:     public function getImageSizeForInterface($imagePath)
361:     {
362:         if (!isset($this->_interfacePath[$imagePath])) {
363:             /** @var $app Mage_XmlConnect_Model_Application */
364:             $app = Mage::helper('xmlconnect')->getApplication();
365:             if (!$app) {
366:                 return 0;
367:             } else {
368:                 $imageLimits = $this->getImageLimits($this->_getScreenSize());
369:                 $size = $this->findPath($imageLimits, $imagePath);
370:                 $this->_interfacePath[$imagePath] = $size;
371:             }
372:         }
373:         $size = isset($this->_interfacePath[$imagePath]) ? (int) $this->_interfacePath[$imagePath] : 0;
374:         return $size;
375:     }
376: 
377:     /**
378:      * Return the filesystem path to XmlConnect media files
379:      *
380:      * @param string $path Right part of the path
381:      * @return string
382:      */
383:     public function getMediaPath($path = '')
384:     {
385:         $path = trim($path);
386:         $result = Mage::getBaseDir('media') . DS . 'xmlconnect';
387: 
388:         if (!empty($path)) {
389:             if (strpos($path, DS) === 0) {
390:                 $path = substr($path, 1);
391:             }
392:             $result .= DS . $path;
393:         }
394:         return $result;
395:     }
396: 
397:     /**
398:      * Return Url for media image
399:      *
400:      * @param string $image
401:      * @return string
402:      */
403:     public function getMediaUrl($image = '')
404:     {
405:         $image = trim($image);
406:         $result = Mage::getBaseUrl('media') . 'xmlconnect';
407: 
408:         if (!empty($image)) {
409:             if (strpos($image, '/') === 0) {
410:                 $image = substr($image, 1);
411:             }
412:             $result .= '/' . $image;
413:         }
414:         return $result;
415:     }
416: 
417:     /**
418:      * Return URL for default design image
419:      *
420:      * @param string $image
421:      * @return string
422:      */
423:     public function getDefaultDesignUrl($image = '')
424:     {
425:         return $this->getSkinImagesUrl($this->getDefaultDesignSuffixAsUrl($image));
426:     }
427: 
428:     /**
429:      * Return suffix as URL for default design image
430:      *
431:      * @param string $image
432:      * @return string
433:      */
434:     public function getDefaultDesignSuffixAsUrl($image = '')
435:     {
436:         return 'design_default/' . trim(ltrim($image, '/'));
437:     }
438: 
439:     /**
440:      * Retrieve thumbnail image url
441:      *
442:      * @param string $imageUrl
443:      * @param int $width
444:      * @param int $height
445:      * @return string|null
446:      */
447:     public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100)
448:     {
449:         $screenSize = $width . 'x' . $height;
450:         $customDir = $this->getMediaPath('custom' . DS . $screenSize);
451:         $this->_verifyDirExist($customDir);
452:         $imageUrl = explode('/', $imageUrl);
453:         $file = $imageUrl[count($imageUrl)-1];
454:         $filePath = $this->getDefaultSizeUploadDir() . DS . $file;
455:         if (!file_exists($customDir . DS . $file)) {
456:             $image = new Varien_Image($filePath);
457:             $widthOriginal = $image->getOriginalWidth();
458:             $heightOriginal = $image->getOriginalHeight();
459: 
460:             if ($width != $widthOriginal) {
461:                 $widthOriginal = $width;
462:             }
463: 
464:             if ($height != $heightOriginal) {
465:                 $heightOriginal = $height;
466:             }
467: 
468:             if (($widthOriginal != $image->getOriginalWidth()) ||
469:                 ($heightOriginal != $image->getOriginalHeight()) ) {
470:                 $image->keepTransparency(true);
471:                 $image->keepFrame(true);
472:                 $image->keepAspectRatio(true);
473:                 $image->backgroundColor(array(255, 255, 255));
474:                 $image->resize($widthOriginal, $heightOriginal);
475:                 $image->save($customDir, basename($file));
476:             }
477:         }
478:         return $this->getMediaUrl("custom/{$screenSize}/" . basename($file));
479:     }
480: 
481:     /**
482:      * Ensure correct $screenSize value
483:      *
484:      * @param string $screenSize
485:      * @return string
486:      */
487:     public function filterScreenSize($screenSize)
488:     {
489:         $screenSize = preg_replace('/[^0-9A-z_]/', '', $screenSize);
490:         if (isset($this->_imageLimits[$screenSize])) {
491:             return $screenSize;
492:         }
493:         $screenSizeExplodeArray = explode(self::XMLCONNECT_GLUE, $screenSize);
494:         $version = '';
495:         switch (count($screenSizeExplodeArray)) {
496:             case 2:
497:                 $version = $screenSizeExplodeArray[1];
498:             case 1:
499:                 $resolution = $screenSizeExplodeArray[0];
500:                 break;
501:             default:
502:                 $resolution = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT;
503:                 break;
504:         }
505: 
506:         $sourcePath = empty($version) ? Mage_XmlConnect_Model_Application::APP_SCREEN_SOURCE_DEFAULT : $version;
507:         $xmlPath = 'screen_size/' . self::XMLCONNECT_GLUE . $resolution . '/' . $sourcePath . '/source';
508: 
509:         $source = Mage::getStoreConfig($xmlPath);
510:         if (!empty($source)) {
511:             $screenSize = $resolution . (empty($version) ? '' : self::XMLCONNECT_GLUE . $version);
512:         } else {
513:             $screenSize = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT;
514:         }
515:         return $screenSize;
516:     }
517: 
518:     /**
519:      * Return correct size array for given device screen_size(320x480/640x960_a)
520:      *
521:      * @param string $screenSize
522:      * @return array
523:      */
524:     public function getImageLimits($screenSize = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT)
525:     {
526:         $defaultScreenSize = Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT;
527:         $defaultScreenSource = Mage_XmlConnect_Model_Application::APP_SCREEN_SOURCE_DEFAULT;
528: 
529:         $screenSize = preg_replace('/[^0-9A-z_]/', '', $screenSize);
530:         if (isset($this->_imageLimits[$screenSize])) {
531:             return $this->_imageLimits[$screenSize];
532:         }
533: 
534:         $screenSizeExplodeArray = explode(self::XMLCONNECT_GLUE, $screenSize);
535:         $version = '';
536:         switch (count($screenSizeExplodeArray)) {
537:             case 2:
538:                 $version = $screenSizeExplodeArray[1];
539:             case 1:
540:                 $resolution = $screenSizeExplodeArray[0];
541:                 break;
542:             default:
543:                 $resolution = $defaultScreenSize;
544:                 break;
545:         }
546: 
547:         $sourcePath = empty($version) ? $defaultScreenSource : $version;
548:         $xmlPath = 'screen_size/' . self::XMLCONNECT_GLUE . $resolution . '/' . $sourcePath;
549: 
550:         $root = Mage::getStoreConfig($xmlPath);
551:         $updates = array();
552: 
553:         if (!empty($root)) {
554:             $screenSize = $resolution . (empty($version) ? '' : self::XMLCONNECT_GLUE . $version);
555:             $source = !empty($root['source']) ? $root['source'] : $defaultScreenSource;
556:             $updates = isset($root['updates']) && is_array($root['updates']) ? $root['updates'] : array();
557:         } else {
558:             $screenSize = $defaultScreenSize;
559:             $source = $defaultScreenSource;
560:         }
561: 
562:         $imageLimits = Mage::getStoreConfig('screen_size/' . $source);
563:         if (!is_array($imageLimits)) {
564:             $imageLimits = Mage::getStoreConfig('screen_size/default');
565:         }
566: 
567:         foreach ($updates as $update) {
568:             $path = $update['path'];
569:             $function = $update['function'];
570:             switch ($function) {
571:                 case 'zoom':
572:                     $data = $update['data'];
573:                     $target =& $this->findPath($imageLimits, $path);
574:                     if (is_array($target)) {
575:                         array_walk_recursive($target, array($this, '_zoom'), $data);
576:                     } else {
577:                         $this->_zoom($target, null, $data);
578:                     }
579:                     break;
580:                 case 'update':
581:                     $data = $update['data'];
582:                     $target =& $this->findPath($imageLimits, $path);
583:                     $target = $data;
584:                     break;
585:                 case 'insert':
586:                     $data = $update['data'];
587:                     $target =& $this->findPath($imageLimits, $path);
588:                     if (($target !== null) && (is_array($target)) && (is_array($data))) {
589:                         foreach ($data as $key => $val) {
590:                             $target[$key] = $val;
591:                         }
592:                     }
593:                     break;
594:                 case 'delete':
595:                     $data = $update['data'];
596:                     $target =& $this->findPath($imageLimits, $path);
597:                     if (isset($target[$data])) {
598:                         unset($target[$data]);
599:                     }
600:                     break;
601:                 default:
602:                     break;
603:             }
604: 
605:         }
606:         if (!is_array($imageLimits)) {
607:             $imageLimits = array();
608:         }
609: 
610:         $this->_imageLimits[$screenSize] = $imageLimits;
611:         return $imageLimits;
612:     }
613: 
614:     /**
615:      * Return reference to the $path in $array
616:      *
617:      * @param array &$array
618:      * @param string $path
619:      * @return mixed reference
620:      */
621:     public function &findPath(&$array, $path)
622:     {
623:         $target =& $array;
624:         if ($path !== '/') {
625:             $pathArray = explode('/', $path);
626:             foreach ($pathArray as $node) {
627:                 if (is_array($target) && isset($target[$node])) {
628:                     $target =& $target[$node];
629:                 } else {
630:                     $targetNull = null;
631:                     return $targetNull;
632:                 }
633:             }
634:         }
635:         return $target;
636:     }
637: 
638:     /**
639:      * Multiply given $item by $value if non array
640:      *
641:      * @param mixed $item (argument to change)
642:      * @param mixed $key (used with array_walk_recursive function as a key of given array)
643:      * @param string $value (contains float)
644:      * @return null
645:      */
646:     protected function _zoom(&$item, $key, $value)
647:     {
648:         if (is_string($item)) {
649:             $item = (int) round($item * $value);
650:         }
651:     }
652: 
653:     /**
654:      * Ensure $dir exists (if not then create one)
655:      *
656:      * @param string $dir
657:      * @throw Mage_Core_Exception
658:      */
659:     protected function _verifyDirExist($dir)
660:     {
661:         try {
662:             $ioFile = new Varien_Io_File();
663:             $ioFile->checkAndCreateFolder($dir);
664:         } catch (Exception $e) {
665:             Mage::throwException($e->getMessage());
666:         }
667:     }
668: 
669:     /**
670:      * Return customSizeUploadDir path
671:      *
672:      * @param string $screenSize
673:      * @return string
674:      */
675:     public function getCustomSizeUploadDir($screenSize)
676:     {
677:         $screenSize = $this->filterScreenSize($screenSize);
678:         $customDir = $this->getMediaPath('custom' . DS . $screenSize);
679:         $this->_verifyDirExist($customDir);
680:         return $customDir;
681:     }
682: 
683:     /**
684:      * Return originalSizeUploadDir path
685:      *
686:      * @return string
687:      */
688:     public function getOriginalSizeUploadDir()
689:     {
690:         $dir = $this->getMediaPath('original');
691:         $this->_verifyDirExist($dir);
692:         return $dir;
693:     }
694: 
695:     /**
696:      * Return oldUpload dir path  (media/xmlconnect)
697:      *
698:      * @return string
699:      */
700:     public function getOldUploadDir()
701:     {
702:         $dir = $this->getMediaPath();
703:         $this->_verifyDirExist($dir);
704:         return $dir;
705:     }
706: 
707:     /**
708:      * Return default size upload dir path
709:      *
710:      * @return string
711:      */
712:     public function getDefaultSizeUploadDir()
713:     {
714:         return $this->getCustomSizeUploadDir(Mage_XmlConnect_Model_Application::APP_SCREEN_SIZE_DEFAULT);
715:     }
716: 
717:     /**
718:      * Return array for interface images paths in the config
719:      *
720:      * @return array
721:      */
722:     public function getInterfaceImagesPathsConf()
723:     {
724:         if (!isset($this->_confPaths)) {
725:             $this->_confPaths = array();
726:             $paths = $this->getInterfaceImagesPaths();
727:             if (is_array($paths)) {
728:                 $len = strlen('conf/native/');
729:                 while (list($path,) = each($paths)) {
730:                     $this->_confPaths[$path] = substr($path, $len);
731:                 }
732:             }
733:         }
734:         return $this->_confPaths;
735:     }
736: 
737:     /**
738:      * Return
739:      * - default interface image path for specified $imagePath
740:      * - array of image paths
741:      *
742:      * @param string $imagePath
743:      * @return array|string
744:      */
745:     public function getInterfaceImagesPaths($imagePath = null)
746:     {
747:         $paths = array (
748:             'conf/native/navigationBar/icon' => 'smallIcon_1_6.png',
749:             'conf/native/body/bannerImage' => 'banner_1_2.png',
750:             'conf/native/body/bannerIpadLandscapeImage' => 'banner_ipad_l.png',
751:             'conf/native/body/bannerIpadImage' => 'banner_ipad.png',
752:             'conf/native/body/bannerAndroidImage' => 'banner_android.png',
753:             'conf/native/body/backgroundImage' => 'accordion_open.png',
754:             'conf/native/body/backgroundIpadLandscapeImage' => 'accordion_open_ipad_l.png',
755:             'conf/native/body/backgroundIpadPortraitImage' => 'accordion_open_ipad_p.png',
756:             'conf/native/body/backgroundAndroidLandscapeImage' => 'accordion_open_android_l.png',
757:             'conf/native/body/backgroundAndroidPortraitImage' => 'accordion_open_android_p.png',
758:         );
759:         if ($imagePath == null) {
760:             return $paths;
761:         } else if (isset($paths[$imagePath])) {
762:             return $paths[$imagePath];
763:         } else {
764:             return null;
765:         }
766:     }
767: 
768:     /**
769:      * Check image and get full file path
770:      *
771:      * @param string &$icon
772:      * @return bool
773:      */
774:     public function checkAndGetImagePath(&$icon)
775:     {
776:         $icon = basename($icon);
777:         if (is_file($this->getDefaultSizeUploadDir() . DS . $icon)) {
778:             $icon = $this->getDefaultSizeUploadDir() . DS . $icon;
779:             return true;
780:         }
781:         return false;
782:     }
783: }
784: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0