Beispiel #1
0
 /**
  * Cleverly merge the JS and CSS files for the frontend
  *
  * @param string $area
  * @param string $package
  * @param string $theme
  * @param int $storeId = null
  * @return Mage_Core_Model_Layout_Element
  */
 public function getFileLayoutUpdatesXml($area, $package, $theme, $storeId = null)
 {
     $xml = parent::getFileLayoutUpdatesXml($area, $package, $theme, $storeId);
     $new = array();
     foreach ($this->_methods as $method => $type) {
         $defaults = $this->_getDefaultItems($xml, $method);
         foreach ($xml->children() as $handle => $node) {
             if (in_array($handle, $this->_ignoredHandles)) {
                 continue;
             }
             if ($actions = $node->xpath(".//action[@method='" . $method . "']")) {
                 $remove = array();
                 $add = array();
                 foreach ($actions as $i => $action) {
                     list($attributes, $file) = array_values($action->asArray());
                     if (!in_array($file, $defaults)) {
                         $remove[$file] = sprintf('<action method="removeItem"><type>%s</type><file>%s</file></action>', $type, $file);
                         $add[$file] = sprintf('<action method="%s"><file>%s</file></action>', $method, $file);
                     }
                 }
                 if (count($remove) > 0 && count($add) > 0) {
                     $new[] = sprintf('<%s><reference name="head">%s<block type="opti/page_html_head" name="head.%s">%s</block></reference></%s>', $handle, implode('', $remove), $handle, implode('', $add), $handle);
                 }
             }
         }
     }
     #echo implode('', $new);exit;
     return simplexml_load_string('<layouts>' . $xml->innerXml() . (!$new ? implode('', $new) : '') . '</layouts>', $this->getElementClass());
 }
Beispiel #2
0
 public function templatesDataProvider()
 {
     $templates = array();
     $themes = $this->_getDesignThemes();
     foreach ($themes as $view) {
         list($area, $package, $theme) = explode('/', $view);
         $layoutUpdate = new Mage_Core_Model_Layout_Update(array('area' => $area, 'package' => $package, 'theme' => $theme));
         $layoutTemplates = $this->_getLayoutTemplates($layoutUpdate->getFileLayoutUpdatesXml());
         foreach ($layoutTemplates as $templateData) {
             $templates[] = array_merge(array($area, $package, $theme), $templateData);
         }
     }
     return $templates;
 }
Beispiel #3
0
 /**
  * @magentoConfigFixture current_store advanced/modules_disable_output/Mage_Catalog true
  * @magentoConfigFixture current_store advanced/modules_disable_output/Mage_Page    true
  */
 public function testGetFileLayoutUpdatesXmlDisabledOutput()
 {
     $this->_replaceConfigLayoutUpdates('
         <catalog module="Mage_Catalog">
             <file>layout.xml</file>
         </catalog>
         <core module="Mage_Core">
             <file>layout.xml</file>
         </core>
         <page module="Mage_Page">
             <file>layout.xml</file>
         </page>
     ');
     $expectedXmlStr = $this->_readLayoutFileContents(__DIR__ . '/../_files/design/frontend/test/default/Mage_Core/layout.xml');
     $actualXml = $this->_model->getFileLayoutUpdatesXml('frontend', 'test', 'default');
     $this->assertXmlStringEqualsXmlString($expectedXmlStr, $actualXml->asNiceXml());
 }
 /**
  * Collect and merge layout updates from
  * file based on handle
  *
  * @param string $area
  * @param string $package
  * @param string $theme
  * @param integer|null $storeId
  * @return Mage_Core_Model_Layout_Element
  */
 public function getFileLayoutUpdatesXml($area, $package, $theme, $storeId = null)
 {
     $xml = parent::getFileLayoutUpdatesXml($area, $package, $theme, $storeId);
     $shouldMergeJs = Mage::helper('mergeminify')->isJsMergeEnabled() && Mage::helper('mergeminify')->isJsMergeHandle();
     $shouldMergeCss = Mage::helper('mergeminify')->isCssMergeEnabled() && Mage::helper('mergeminify')->isCssMergeHandle();
     $methods = array();
     if ($shouldMergeJs) {
         $methods[] = 'addJs';
     }
     if ($shouldMergeCss) {
         $methods[] = 'addCss';
     }
     if ($shouldMergeJs || $shouldMergeCss) {
         $methods[] = 'addItem';
     }
     foreach ($methods as $method) {
         foreach ($xml->children() as $handle => $child) {
             $items = $child->xpath('.//action[@method=\'' . $method . '\']');
             foreach ($items as $item) {
                 if ($method == 'addItem' && (!$shouldMergeCss && (string) $item->{'type'} == 'skin_css' || !$shouldMergeJs && (string) $item->{'type'} == 'skin_js')) {
                     continue;
                 }
                 $params = $item->xpath('params');
                 if (count($params)) {
                     foreach ($params as $param) {
                         if (trim($param)) {
                             $param->{0} = (string) $param . ' ' . static::HANDLE_ATTRIBUTE . '="' . $handle . '"';
                         } else {
                             $param->{0} = static::HANDLE_ATTRIBUTE . '="' . $handle . '"';
                         }
                     }
                 } else {
                     $item->addChild('params', static::HANDLE_ATTRIBUTE . '="' . $handle . '"');
                 }
             }
         }
     }
     return $xml;
 }
 /**
  * Collect and merge layout updates from file
  *
  * @param string $area
  * @param string $package
  * @param string $theme
  * @param integer|null $storeId
  * @return Mage_Core_Model_Layout_Element
  */
 public function getFileLayoutUpdatesXml($area, $package, $theme, $storeId = null)
 {
     $xml = parent::getFileLayoutUpdatesXml($area, $package, $theme, $storeId);
     if (Mage::getDesign()->getArea() != 'adminhtml') {
         $shouldMergeJs = Mage::getStoreConfigFlag('dev/js/merge_files') && Mage::getStoreConfigFlag('dev/js/merge_js_by_handle');
         $shouldMergeCss = Mage::getStoreConfigFlag('dev/css/merge_css_files') && Mage::getStoreConfigFlag('dev/css/merge_css_by_handle');
         $methods = array();
         if ($shouldMergeJs) {
             $methods[] = 'addJs';
         }
         if ($shouldMergeCss) {
             $methods[] = 'addCss';
         }
         if ($shouldMergeJs || $shouldMergeCss) {
             $methods[] = 'addItem';
         }
         foreach ($methods as $method) {
             foreach ($xml->children() as $handle => $child) {
                 $items = $child->xpath(".//action[@method='" . $method . "']");
                 foreach ($items as $item) {
                     $params = $item->xpath("params");
                     if (count($params)) {
                         foreach ($params as $param) {
                             if (trim($param)) {
                                 $param->{0} = (string) $param . ' title="' . $handle . '"';
                             } else {
                                 $param->{0} = 'title="' . $handle . '"';
                             }
                         }
                     } else {
                         $item->addChild('params', 'title="' . $handle . '"');
                     }
                 }
             }
         }
     }
     return $xml;
 }
Beispiel #6
0
 /**
  * Collect getSkinUrl() from theme templates
  *
  * @param string    $area
  * @param string    $package
  * @param string    $theme
  * @param array     &$files
  */
 protected function _collectGetSkinUrlInvokes($area, $package, $theme, &$files)
 {
     $searchDir = Mage::getBaseDir('design') . DIRECTORY_SEPARATOR . $area . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR . $theme;
     $dirLength = strlen($searchDir);
     foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($searchDir)) as $fileInfo) {
         // Check that file path is valid
         $relativePath = substr($fileInfo->getPath(), $dirLength);
         if (!$this->_validateTemplatePath($relativePath)) {
             continue;
         }
         // Scan file for references to other files
         foreach ($this->_findReferencesToSkinFile($fileInfo) as $file) {
             $files[$area][$package][$theme][] = $file;
         }
     }
     // Collect "addCss" and "addJs" from theme layout
     $layoutUpdate = new Mage_Core_Model_Layout_Update(array('area' => $area, 'package' => $package, 'theme' => $theme));
     $fileLayoutUpdates = $layoutUpdate->getFileLayoutUpdatesXml();
     $elements = $fileLayoutUpdates->xpath('//action[@method="addCss" or @method="addJs"]/*[1]');
     if ($elements) {
         foreach ($elements as $filenameNode) {
             $skinFile = (string) $filenameNode;
             if ($this->_isFileForDisabledModule($skinFile)) {
                 continue;
             }
             $files[$area][$package][$theme][] = $skinFile;
         }
     }
 }
Beispiel #7
0
 /**
  * Composes full layout xml for designated parameters
  *
  * @param string $area
  * @param string $package
  * @param string $theme
  * @return Mage_Core_Model_Layout_Element
  */
 protected function _composeXml($area, $package, $theme)
 {
     $layoutUpdate = new Mage_Core_Model_Layout_Update(array('area' => $area, 'package' => $package, 'theme' => $theme));
     return $layoutUpdate->getFileLayoutUpdatesXml();
 }