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 Config for Editor HTML Element
29: *
30: * @category Mage
31: * @package Mage_Cms
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Cms_Model_Wysiwyg_Config extends Varien_Object
35: {
36: /**
37: * Wysiwyg behaviour
38: */
39: const WYSIWYG_ENABLED = 'enabled';
40: const WYSIWYG_HIDDEN = 'hidden';
41: const WYSIWYG_DISABLED = 'disabled';
42: const IMAGE_DIRECTORY = 'wysiwyg';
43:
44: /**
45: * Return Wysiwyg config as Varien_Object
46: *
47: * Config options description:
48: *
49: * enabled: Enabled Visual Editor or not
50: * hidden: Show Visual Editor on page load or not
51: * use_container: Wrap Editor contents into div or not
52: * no_display: Hide Editor container or not (related to use_container)
53: * translator: Helper to translate phrases in lib
54: * files_browser_*: Files Browser (media, images) settings
55: * encode_directives: Encode template directives with JS or not
56: *
57: * @param $data Varien_Object constructor params to override default config values
58: * @return Varien_Object
59: */
60: public function getConfig($data = array())
61: {
62: $config = new Varien_Object();
63:
64: $config->setData(array(
65: 'enabled' => $this->isEnabled(),
66: 'hidden' => $this->isHidden(),
67: 'use_container' => false,
68: 'add_variables' => true,
69: 'add_widgets' => true,
70: 'no_display' => false,
71: 'translator' => Mage::helper('cms'),
72: 'encode_directives' => true,
73: 'directives_url' => Mage::getSingleton('adminhtml/url')->getUrl('*/cms_wysiwyg/directive'),
74: 'popup_css' =>
75: Mage::getBaseUrl('js').'mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css',
76: 'content_css' =>
77: Mage::getBaseUrl('js').'mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css',
78: 'width' => '100%',
79: 'plugins' => array()
80: ));
81:
82: $config->setData('directives_url_quoted', preg_quote($config->getData('directives_url')));
83:
84: if (Mage::getSingleton('admin/session')->isAllowed('cms/media_gallery')) {
85: $config->addData(array(
86: 'add_images' => true,
87: 'files_browser_window_url' => Mage::getSingleton('adminhtml/url')->getUrl('*/cms_wysiwyg_images/index'),
88: 'files_browser_window_width' => (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_width'),
89: 'files_browser_window_height'=> (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_height'),
90: ));
91: }
92:
93: if (is_array($data)) {
94: $config->addData($data);
95: }
96:
97: Mage::dispatchEvent('cms_wysiwyg_config_prepare', array('config' => $config));
98:
99: return $config;
100: }
101:
102: /**
103: * Return URL for skin images placeholder
104: *
105: * @return string
106: */
107: public function getSkinImagePlaceholderUrl()
108: {
109: return Mage::getDesign()->getSkinUrl('images/wysiwyg/skin_image.png');
110: }
111:
112: /**
113: * Check whether Wysiwyg is enabled or not
114: *
115: * @return bool
116: */
117: public function isEnabled()
118: {
119: $storeId = $this->getStoreId();
120: if (!is_null($storeId)) {
121: $wysiwygState = Mage::getStoreConfig('cms/wysiwyg/enabled', $storeId);
122: } else {
123: $wysiwygState = Mage::getStoreConfig('cms/wysiwyg/enabled');
124: }
125: return in_array($wysiwygState, array(self::WYSIWYG_ENABLED, self::WYSIWYG_HIDDEN));
126: }
127:
128: /**
129: * Check whether Wysiwyg is loaded on demand or not
130: *
131: * @return bool
132: */
133: public function isHidden()
134: {
135: return Mage::getStoreConfig('cms/wysiwyg/enabled') == self::WYSIWYG_HIDDEN;
136: }
137: }
138: