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_Widget
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: * Widgets management controller
29: *
30: * @category Mage
31: * @package Mage_Widget
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Widget_Adminhtml_WidgetController extends Mage_Adminhtml_Controller_Action
35: {
36: /**
37: * Wisywyg widget plugin main page
38: */
39: public function indexAction()
40: {
41: // save extra params for widgets insertion form
42: $skipped = $this->getRequest()->getParam('skip_widgets');
43: $skipped = Mage::getSingleton('widget/widget_config')->decodeWidgetsFromQuery($skipped);
44:
45: Mage::register('skip_widgets', $skipped);
46:
47: $this->loadLayout('empty')->renderLayout();
48: }
49:
50: /**
51: * Ajax responder for loading plugin options form
52: */
53: public function loadOptionsAction()
54: {
55: try {
56: $this->loadLayout('empty');
57: if ($paramsJson = $this->getRequest()->getParam('widget')) {
58: $request = Mage::helper('core')->jsonDecode($paramsJson);
59: if (is_array($request)) {
60: $optionsBlock = $this->getLayout()->getBlock('wysiwyg_widget.options');
61: if (isset($request['widget_type'])) {
62: $optionsBlock->setWidgetType($request['widget_type']);
63: }
64: if (isset($request['values'])) {
65: $optionsBlock->setWidgetValues($request['values']);
66: }
67: }
68: $this->renderLayout();
69: }
70: } catch (Mage_Core_Exception $e) {
71: $result = array('error' => true, 'message' => $e->getMessage());
72: $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
73: }
74: }
75:
76: /**
77: * Format widget pseudo-code for inserting into wysiwyg editor
78: */
79: public function buildWidgetAction()
80: {
81: $type = $this->getRequest()->getPost('widget_type');
82: $params = $this->getRequest()->getPost('parameters', array());
83: $asIs = $this->getRequest()->getPost('as_is');
84: $html = Mage::getSingleton('widget/widget')->getWidgetDeclaration($type, $params, $asIs);
85: $this->getResponse()->setBody($html);
86: }
87: }
88: