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_Adminhtml_Cms_PageController
  • Mage_Adminhtml_Model_System_Config_Source_Cms_Wysiwyg_Enabled
  • Mage_Cms_Block_Block
  • Mage_Cms_Block_Page
  • Mage_Cms_Block_Widget_Block
  • Mage_Cms_Block_Widget_Page_Link
  • Mage_Cms_Controller_Router
  • Mage_Cms_Helper_Data
  • Mage_Cms_Helper_Page
  • Mage_Cms_Helper_Wysiwyg_Images
  • Mage_Cms_IndexController
  • Mage_Cms_Model_Block
  • Mage_Cms_Model_Mysql4_Block
  • Mage_Cms_Model_Mysql4_Block_Collection
  • Mage_Cms_Model_Mysql4_Page
  • Mage_Cms_Model_Mysql4_Page_Collection
  • Mage_Cms_Model_Mysql4_Page_Service
  • Mage_Cms_Model_Observer
  • Mage_Cms_Model_Page
  • Mage_Cms_Model_Resource_Block
  • Mage_Cms_Model_Resource_Block_Collection
  • Mage_Cms_Model_Resource_Page
  • Mage_Cms_Model_Resource_Page_Collection
  • Mage_Cms_Model_Resource_Page_Service
  • Mage_Cms_Model_Template_Filter
  • Mage_Cms_Model_Wysiwyg_Config
  • Mage_Cms_Model_Wysiwyg_Images_Storage
  • Mage_Cms_Model_Wysiwyg_Images_Storage_Collection
  • Mage_Cms_PageController
  • 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_Cms
 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:  * Wysiwyg Images Helper
 29:  */
 30: class Mage_Cms_Helper_Wysiwyg_Images extends Mage_Core_Helper_Abstract
 31: {
 32: 
 33:     /**
 34:      * Current directory path
 35:      * @var string
 36:      */
 37:     protected $_currentPath;
 38: 
 39:     /**
 40:      * Current directory URL
 41:      * @var string
 42:      */
 43:     protected $_currentUrl;
 44: 
 45:     /**
 46:      * Currenty selected store ID if applicable
 47:      *
 48:      * @var int
 49:      */
 50:     protected $_storeId = null;
 51: 
 52: 
 53:     /**
 54:      * Set a specified store ID value
 55:      *
 56:      * @param <type> $store
 57:      */
 58:     public function setStoreId($store)
 59:     {
 60:         $this->_storeId = $store;
 61:         return $this;
 62:     }
 63: 
 64:     /**
 65:      * Images Storage root directory
 66:      *
 67:      * @return string
 68:      */
 69:     public function getStorageRoot()
 70:     {
 71:         return Mage::getConfig()->getOptions()->getMediaDir() . DS . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY
 72:             . DS;
 73:     }
 74: 
 75:     /**
 76:      * Images Storage base URL
 77:      *
 78:      * @return string
 79:      */
 80:     public function getBaseUrl()
 81:     {
 82:         return Mage::getBaseUrl('media') . '/';
 83:     }
 84: 
 85:     /**
 86:      * Ext Tree node key name
 87:      *
 88:      * @return string
 89:      */
 90:     public function getTreeNodeName()
 91:     {
 92:         return 'node';
 93:     }
 94: 
 95:     /**
 96:      * Encode path to HTML element id
 97:      *
 98:      * @param string $path Path to file/directory
 99:      * @return string
100:      */
101:     public function convertPathToId($path)
102:     {
103:         $path = str_replace($this->getStorageRoot(), '', $path);
104:         return $this->idEncode($path);
105:     }
106: 
107:     /**
108:      * Decode HTML element id
109:      *
110:      * @param string $id
111:      * @return string
112:      */
113:     public function convertIdToPath($id)
114:     {
115:         $path = $this->idDecode($id);
116:         if (!strstr($path, $this->getStorageRoot())) {
117:             $path = $this->getStorageRoot() . $path;
118:         }
119:         return $path;
120:     }
121: 
122:     /**
123:      * File system path correction
124:      *
125:      * @param string $path Original path
126:      * @param boolean $trim Trim slashes or not
127:      * @return string
128:      */
129:     public function correctPath($path, $trim = true)
130:     {
131:         $path = strtr($path, "\\\/", DS . DS);
132:         if ($trim) {
133:             $path = trim($path, DS);
134:         }
135:         return $path;
136:     }
137: 
138:     /**
139:      * Return file system path as Url string
140:      *
141:      * @param string $path
142:      * @return string
143:      */
144:     public function convertPathToUrl($path)
145:     {
146:         return str_replace(DS, '/', $path);
147:     }
148: 
149:     /**
150:      * Check whether using static URLs is allowed
151:      *
152:      * @return boolean
153:      */
154:     public function isUsingStaticUrlsAllowed()
155:     {
156:         $checkResult = new StdClass;
157:         $checkResult->isAllowed = false;
158:         Mage::dispatchEvent('cms_wysiwyg_images_static_urls_allowed', array(
159:             'result'   => $checkResult,
160:             'store_id' => $this->_storeId
161:         ));
162:         return $checkResult->isAllowed;
163:     }
164: 
165:     /**
166:      * Prepare Image insertion declaration for Wysiwyg or textarea(as_is mode)
167:      *
168:      * @param string $filename Filename transferred via Ajax
169:      * @param bool $renderAsTag Leave image HTML as is or transform it to controller directive
170:      * @return string
171:      */
172:     public function getImageHtmlDeclaration($filename, $renderAsTag = false)
173:     {
174:         $fileurl = $this->getCurrentUrl() . $filename;
175:         $mediaPath = str_replace(Mage::getBaseUrl('media'), '', $fileurl);
176:         $directive = sprintf('{{media url="%s"}}', $mediaPath);
177:         if ($renderAsTag) {
178:             $html = sprintf('<img src="%s" alt="" />', $this->isUsingStaticUrlsAllowed() ? $fileurl : $directive);
179:         } else {
180:             if ($this->isUsingStaticUrlsAllowed()) {
181:                 $html = $fileurl; // $mediaPath;
182:             } else {
183:                 $directive = Mage::helper('core')->urlEncode($directive);
184:                 $html = Mage::helper('adminhtml')->getUrl('*/cms_wysiwyg/directive', array('___directive' => $directive));
185:             }
186:         }
187:         return $html;
188:     }
189: 
190:     /**
191:      * Return path of the current selected directory or root directory for startup
192:      * Try to create target directory if it doesn't exist
193:      *
194:      * @throws Mage_Core_Exception
195:      * @return string
196:      */
197:     public function getCurrentPath()
198:     {
199:         if (!$this->_currentPath) {
200:             $currentPath = $this->getStorageRoot();
201:             $path = $this->_getRequest()->getParam($this->getTreeNodeName());
202:             if ($path) {
203:                 $path = $this->convertIdToPath($path);
204:                 if (is_dir($path)) {
205:                     $currentPath = $path;
206:                 }
207:             }
208:             $io = new Varien_Io_File();
209:             if (!$io->isWriteable($currentPath) && !$io->mkdir($currentPath)) {
210:                 $message = Mage::helper('cms')->__('The directory %s is not writable by server.',$currentPath);
211:                 Mage::throwException($message);
212:             }
213:             $this->_currentPath = $currentPath;
214:         }
215:         return $this->_currentPath;
216:     }
217: 
218:     /**
219:      * Return URL based on current selected directory or root directory for startup
220:      *
221:      * @return string
222:      */
223:     public function getCurrentUrl()
224:     {
225:         if (!$this->_currentUrl) {
226:             $path = str_replace(Mage::getConfig()->getOptions()->getMediaDir(), '', $this->getCurrentPath());
227:             $path = trim($path, DS);
228:             $this->_currentUrl = Mage::app()->getStore($this->_storeId)->getBaseUrl('media') .
229:                                  $this->convertPathToUrl($path) . '/';
230:         }
231:         return $this->_currentUrl;
232:     }
233: 
234:     /**
235:      * Storage model singleton
236:      *
237:      * @return Mage_Cms_Model_Page_Wysiwyg_Images_Storage
238:      */
239:     public function getStorage()
240:     {
241:         return Mage::getSingleton('cms/wysiwyg_images_storage');
242:     }
243: 
244:     /**
245:      * Encode string to valid HTML id element, based on base64 encoding
246:      *
247:      * @param string $string
248:      * @return string
249:      */
250:     public function idEncode($string)
251:     {
252:         return strtr(base64_encode($string), '+/=', ':_-');
253:     }
254: 
255:     /**
256:      * Revert opration to idEncode
257:      *
258:      * @param string $string
259:      * @return string
260:      */
261:     public function idDecode($string)
262:     {
263:         $string = strtr($string, ':_-', '+/=');
264:         return base64_decode($string);
265:     }
266: 
267:     /**
268:      * Reduce filename by replacing some characters with dots
269:      *
270:      * @param string $filename
271:      * @param int $maxLength Maximum filename
272:      * @return string Truncated filename
273:      */
274:     public function getShortFilename($filename, $maxLength = 20)
275:     {
276:         if (strlen($filename) <= $maxLength) {
277:             return $filename;
278:         }
279:         return substr($filename, 0, $maxLength) . '...';
280:     }
281: }
282: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0