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: * Application configuration renderer
29: *
30: * @category Mage
31: * @package Mage_XmlConnect
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_XmlConnect_Block_Configuration extends Mage_Core_Block_Template
35: {
36: /**
37: * Current application model
38: *
39: * @var Mage_XmlConnect_Model_Application
40: */
41: protected $_app;
42:
43: /**
44: * Init current application
45: *
46: * @return Mage_XmlConnect_Block_Configuration
47: */
48: protected function _beforeToHtml()
49: {
50: $app = Mage::helper('xmlconnect')->getApplication();
51: if ($app) {
52: $this->_app = $app;
53: } else {
54: $this->_app = Mage::getModel('xmlconnect/application');
55: $this->_app->loadDefaultConfiguration();
56: }
57: return $this;
58: }
59:
60: /**
61: * Recursively build XML configuration tree
62: *
63: * @param Mage_XmlConnect_Model_Simplexml_Element $section
64: * @param array $subtree
65: * @return Mage_XmlConnect_Model_Simplexml_Element
66: */
67: protected function _buildRecursive($section, $subtree)
68: {
69: Mage::helper('xmlconnect')->getDeviceHelper()->checkRequiredConfigFields($subtree);
70:
71: foreach ($subtree as $key => $value) {
72: if (is_array($value)) {
73: if ($key == 'fonts') {
74: $subsection = $section->addChild('fonts');
75: foreach ($value as $label=>$v) {
76: if (empty($v['name']) || empty($v['size']) || empty($v['color'])) {
77: continue;
78: }
79: $font = $subsection->addChild('font');
80: $font->addAttribute('label', $label);
81: $font->addAttribute('name', $v['name']);
82: $font->addAttribute('size', $v['size']);
83: $font->addAttribute('color', $v['color']);
84: }
85: } elseif ($key == 'pages') {
86: $subsection = $section->addChild('content');
87: foreach ($value as $page) {
88: $this->_buildRecursive($subsection->addChild('page'), $page);
89: }
90: } else {
91: $subsection = $section->addChild($key);
92: $this->_buildRecursive($subsection, $value);
93: }
94: } elseif ($value instanceof Mage_XmlConnect_Model_Tabs) {
95: foreach ($value->getRenderTabs() as $tab) {
96: $subsection = $section->addChild('tab');
97: $this->_buildRecursive($subsection, $tab);
98: }
99: } else {
100: $value = (string)$value;
101: if ($value != '') {
102: $section->addChild($key, Mage::helper('core')->escapeHtml($value));
103: }
104: }
105: }
106: }
107:
108: /**
109: * Render block
110: *
111: * @return string
112: */
113: protected function _toHtml()
114: {
115: $xml = Mage::getModel('xmlconnect/simplexml_element', '<configuration></configuration>');
116: $this->_buildRecursive($xml, Mage::helper('xmlconnect')->excludeXmlConfigKeys($this->_app->getRenderConf()));
117: return $xml->asNiceXml();
118: }
119: }
120: