/** * Get CSS files of a given theme * * Returned array has a structure * array( * 'Mage_Catalog::widgets.css' => 'http://mage2.com/pub/media/theme/frontend/_theme15/en_US/Mage_Cms/widgets.css' * ) * * @param Mage_Core_Model_Theme $theme * @return array */ public function getCssFiles($theme) { $arguments = array('area' => $theme->getArea(), 'theme' => $theme->getId()); /** @var $layoutMerge Mage_Core_Model_Layout_Merge */ $layoutMerge = Mage::getModel('Mage_Core_Model_Layout_Merge', array('arguments' => $arguments)); $layoutElement = $layoutMerge->getFileLayoutUpdatesXml(); $xpathRefs = '//reference[@name="head"]/action[@method="addCss" or @method="addCssIe"]/*[1]'; $xpathBlocks = '//block[@type="Mage_Page_Block_Html_Head"]/action[@method="addCss" or @method="addCssIe"]/*[1]'; $files = array_merge($layoutElement->xpath($xpathRefs), $layoutElement->xpath($xpathBlocks)); $design = Mage::getDesign(); $params = array('area' => $theme->getArea(), 'themeModel' => $theme, 'skipProxy' => true); $urls = array(); foreach ($files as $file) { $urls[(string) $file] = $design->getViewFile($file, $params); } return $urls; }
/** * Collect getViewUrl() from theme templates * * @param Mage_Core_Model_Theme $theme * @param array &$files */ protected function _collectGetViewUrlInvokes($theme, &$files) { $themePath = str_replace(Mage_Core_Model_Theme::PATH_SEPARATOR, DIRECTORY_SEPARATOR, $theme->getThemePath()); $searchDir = Mage::getBaseDir('design') . DIRECTORY_SEPARATOR . $theme->getArea() . DIRECTORY_SEPARATOR . $themePath; $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->_findReferencesToViewFile($fileInfo) as $file) { $files[$theme->getArea()][$theme->getId()][] = $file; } } // Collect "addCss" and "addJs" from theme layout $layoutUpdate = Mage::getModel('Mage_Core_Model_Layout_Merge', array('arguments' => array('area' => $theme->getArea(), 'theme' => $theme->getId()))); $fileLayoutUpdates = $layoutUpdate->getFileLayoutUpdatesXml(); $elements = $fileLayoutUpdates->xpath('//action[@method="addCss" or @method="addJs"]/*[1]'); if ($elements) { foreach ($elements as $filenameNode) { $viewFile = (string) $filenameNode; if ($this->_isFileForDisabledModule($viewFile)) { continue; } $files[$theme->getArea()][$theme->getId()][] = $viewFile; } } }