/** * Constructor. * Following entries in $params are required: 'area', 'package', 'theme', 'locale', 'canSaveMap', * 'mapDir', 'baseDir'. * * @param Magento_Filesystem $filesystem * @param array $data */ public function __construct(Magento_Filesystem $filesystem, array $data = array()) { $this->_filesystem = $filesystem; $this->_area = $data['area']; $this->_theme = $data['themeModel']; $this->_locale = $data['locale']; $this->_canSaveMap = $data['canSaveMap']; $this->_mapDir = $data['mapDir']; $this->_basePath = $data['baseDir'] ? $data['baseDir'] . DIRECTORY_SEPARATOR : ''; $this->_mapFile = "{$this->_mapDir}/{$this->_area}_{$this->_theme->getId()}_{$this->_locale}.ser"; $this->_map = $this->_filesystem->isFile($this->_mapFile) ? unserialize($this->_filesystem->read($this->_mapFile)) : array(); }
/** * 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; }
public function testGetCacheKeyInfo() { $block = Mage::app()->getLayout()->createBlock('Mage_Page_Block_Html_Footer'); $storeId = Mage::app()->getStore()->getId(); $this->assertEquals(array('PAGE_FOOTER', $storeId, 0, $this->_theme->getId(), null), $block->getCacheKeyInfo()); }
/** * 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; } } }
/** * Register theme and recursively all its ascendants * Second param is optional and is used to prevent circular references in inheritance chain * * @param Mage_Core_Model_Theme $theme * @param array $inheritanceChain * @return Mage_Core_Model_Theme_Collection * @throws Mage_Core_Exception */ protected function _registerThemeRecursively(&$theme, $inheritanceChain = array()) { if ($theme->getId()) { return $this; } $themeModel = $this->getThemeFromDb($theme->getFullPath()); if ($themeModel->getId()) { $theme = $themeModel; return $this; } $tempId = $theme->getFullPath(); if (in_array($tempId, $inheritanceChain)) { Mage::throwException(Mage::helper('Mage_Core_Helper_Data')->__('Circular-reference in theme inheritance detected for "%s"', $tempId)); } array_push($inheritanceChain, $tempId); $parentTheme = $theme->getParentTheme(); if ($parentTheme) { $this->_registerThemeRecursively($parentTheme, $inheritanceChain); $theme->setParentId($parentTheme->getId()); } $theme->savePreviewImage()->save(); return $this; }
/** * Create theme customization * * @param Mage_Core_Model_Theme $theme * @return Mage_Core_Model_Theme */ public function createThemeCustomization($theme) { $themeCopyCount = $this->_getThemeCustomizations()->addFilter('parent_id', $theme->getId())->count(); $themeData = $theme->getData(); $themeData['parent_id'] = $theme->getId(); $themeData['theme_id'] = null; $themeData['theme_path'] = null; $themeData['theme_title'] = $theme->getThemeTitle() . ' - ' . $this->_helper->__('Copy') . ' #' . ($themeCopyCount + 1); /** @var $themeCustomization Mage_Core_Model_Theme */ $themeCustomization = $this->_themeFactory->create()->setData($themeData); $themeCustomization->createPreviewImageCopy()->save(); return $themeCustomization; }