1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Widget_Model_Widget_Config extends Varien_Object
35: {
36:
37: 38: 39: 40: 41: 42:
43: public function getPluginSettings($config)
44: {
45: $settings = array(
46: 'widget_plugin_src' => Mage::getBaseUrl('js').'mage/adminhtml/wysiwyg/tiny_mce/plugins/magentowidget/editor_plugin.js',
47: 'widget_images_url' => $this->getPlaceholderImagesBaseUrl(),
48: 'widget_placeholders' => $this->getAvailablePlaceholderFilenames(),
49: 'widget_window_url' => $this->getWidgetWindowUrl($config)
50: );
51:
52: return $settings;
53: }
54:
55: 56: 57: 58: 59:
60: public function getPlaceholderImagesBaseUrl()
61: {
62: return Mage::getDesign()->getSkinUrl('images/widget/');
63: }
64:
65: 66: 67: 68: 69:
70: public function getPlaceholderImagesBaseDir()
71: {
72: return Mage::getDesign()->getSkinBaseDir() . DS . 'images' . DS . 'widget';
73: }
74:
75: 76: 77: 78: 79:
80: public function getAvailablePlaceholderFilenames()
81: {
82: $result = array();
83: $targetDir = $this->getPlaceholderImagesBaseDir();
84: if (is_dir($targetDir) && is_readable($targetDir)) {
85: $collection = new Varien_Data_Collection_Filesystem();
86: $collection->addTargetDir($targetDir)
87: ->setCollectDirs(false)
88: ->setCollectFiles(true)
89: ->setCollectRecursively(false);
90: foreach ($collection as $file) {
91: $result[] = $file->getBasename();
92: }
93: }
94:
95: return $result;
96: }
97:
98: 99: 100: 101: 102: 103:
104: public function getWidgetWindowUrl($config)
105: {
106: $params = array();
107:
108: $skipped = is_array($config->getData('skip_widgets')) ? $config->getData('skip_widgets') : array();
109: if ($config->hasData('widget_filters')) {
110: $all = Mage::getModel('widget/widget')->getWidgetsXml();
111: $filtered = Mage::getModel('widget/widget')->getWidgetsXml($config->getData('widget_filters'));
112: $reflection = new ReflectionObject($filtered);
113: foreach ($all as $code => $widget) {
114: if (!$reflection->hasProperty($code)) {
115: $skipped[] = $widget->getAttribute('type');
116: }
117: }
118: }
119:
120: if (count($skipped) > 0) {
121: $params['skip_widgets'] = $this->encodeWidgetsToQuery($skipped);
122: }
123: return Mage::getSingleton('adminhtml/url')->getUrl('*/widget/index', $params);
124: }
125:
126: 127: 128: 129: 130: 131:
132: public function encodeWidgetsToQuery($widgets)
133: {
134: $widgets = is_array($widgets) ? $widgets : array($widgets);
135: $param = implode(',', $widgets);
136: return Mage::helper('core')->urlEncode($param);
137: }
138:
139: 140: 141: 142: 143: 144:
145: public function decodeWidgetsFromQuery($queryParam)
146: {
147: $param = Mage::helper('core')->urlDecode($queryParam);
148: return preg_split('/\s*\,\s*/', $param, 0, PREG_SPLIT_NO_EMPTY);
149: }
150:
151: }
152: