*/ class Mage_XmlConnect_Block_Configuration extends Mage_Core_Block_Abstract { /** * XmlConnect application model * * @var Mage_XmlConnect_Model_Application */ protected $_connectApp; /** * Retrieve initialized instance of XmlConnect application model * * @return Mage_XmlConnect_Model_Application */ protected function _getConnectApp() { if (!$this->_connectApp) { $this->_connectApp = Mage::helper('xmlconnect')->getApplication(); if (!$this->_connectApp) { $this->_connectApp = Mage::getModel('xmlconnect/application'); $this->_connectApp->loadDefaultConfiguration(); } } return $this->_connectApp; } /** * Recursively build XML configuration tree * * @param Mage_XmlConnect_Model_Simplexml_Element $section * @param array $subTree * @return Mage_XmlConnect_Block_Configuration */ protected function _buildRecursive($section, $subTree) { Mage::helper('xmlconnect')->getDeviceHelper()->checkRequiredConfigFields($subTree); foreach ($subTree as $key => $value) { if (is_array($value)) { if ($key == 'fonts') { $subSection = $section->addChild('fonts'); foreach ($value as $label => $val) { if (empty($val['name']) || empty($val['size']) || empty($val['color'])) { continue; } $font = $subSection->addChild('font'); $font->addAttribute('label', $label); $font->addAttribute('name', $val['name']); $font->addAttribute('size', $val['size']); $font->addAttribute('color', $val['color']); } } elseif ($key == 'pages') { $subSection = $section->addChild('content'); foreach ($value as $page) { $this->_buildRecursive($subSection->addChild('page'), $page); } } else { $subSection = $section->addChild($key); $this->_buildRecursive($subSection, $value); } } elseif ($value instanceof Mage_XmlConnect_Model_Tabs) { foreach ($value->getRenderTabs() as $tab) { $subSection = $section->addChild('tab'); $this->_buildRecursive($subSection, $tab); } } else { $value = (string)$value; if ($value != '') { $section->addChild($key, Mage::helper('core')->escapeHtml($value)); } } } return $this; } /** * Render block * * @return string */ protected function _toHtml() { /** @var $xml Mage_XmlConnect_Model_Simplexml_Element */ $xml = Mage::getModel('xmlconnect/simplexml_element', ''); $conf = $this->_getConnectApp()->getRenderConf(); $this->_buildRecursive($xml, Mage::helper('xmlconnect')->excludeXmlConfigKeys($conf)) ->_addLocalization($xml); return $xml->asNiceXml(); } /** * Add localization data to xml object * * @param Mage_XmlConnect_Model_Simplexml_Element $xml * @return Mage_XmlConnect_Block_Configuration */ protected function _addLocalization(Mage_XmlConnect_Model_Simplexml_Element $xml) { /** @var $translateHelper Mage_XmlConnect_Helper_Translate */ $translateHelper = Mage::helper('xmlconnect/translate'); $xml->addCustomChild('localization', Mage::helper('xmlconnect')->getActionUrl('xmlconnect/localization'), array( 'hash' => $translateHelper->getHash() )); return $this; } }