Beispiel #1
0
 /**
  * @return Mage_Core_Model_Resource_Theme_Collection
  */
 protected function _getCollection()
 {
     if (!$this->_themesCollection) {
         $this->_themesCollection = $this->_theme->getCollection()->load();
     }
     return $this->_themesCollection;
 }
Beispiel #2
0
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * Get image preview url
  *
  * @return string
  */
 protected function _getUrl()
 {
     $url = false;
     if ($this->getValue()) {
         $url = Mage_Core_Model_Theme::getPreviewImageDirectoryUrl() . $this->getValue();
     }
     return $url;
 }
Beispiel #4
0
 /**
  * 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();
 }
Beispiel #5
0
 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());
 }
Beispiel #6
0
 /**
  * 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;
         }
     }
 }
Beispiel #7
0
 /**
  * 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;
 }
Beispiel #8
0
 /**
  * Add theme fieldset
  *
  * @param Varien_Data_Form $form
  * @param array $formData
  * @return Mage_Theme_Block_Adminhtml_System_Design_Theme_Edit_Tab_General
  */
 protected function _addThemeFieldset($form, $formData)
 {
     $themeFieldset = $form->addFieldset('theme', array('legend' => $this->__('Theme Settings')));
     $this->_addElementTypes($themeFieldset);
     if (isset($formData['theme_id'])) {
         $themeFieldset->addField('theme_id', 'hidden', array('name' => 'theme_id'));
     }
     /** @var $themesCollections Mage_Core_Model_Theme_Collection */
     $themesCollections = Mage::getResourceModel('Mage_Core_Model_Theme_Collection');
     /** @var $helper Mage_Core_Helper_Data */
     $helper = Mage::helper('Mage_Core_Helper_Data');
     $onChangeScript = sprintf('parentThemeOnChange(this.value, %s)', str_replace('"', '\'', $helper->jsonEncode($this->_getDefaultsInherited($themesCollections->addDefaultPattern()))));
     /** @var $parentTheme Mage_Core_Model_Theme */
     $parentTheme = Mage::getModel('Mage_Core_Model_Theme');
     if (!empty($formData['parent_id'])) {
         $parentTheme->load($formData['parent_id']);
     }
     if ($this->_isThemeEditable) {
         $themeFieldset->addField('parent_id', 'select', array('label' => $this->__('Parent theme'), 'title' => $this->__('Parent theme'), 'name' => 'parent_id', 'values' => $themesCollections->toOptionArray(!$parentTheme->getId()), 'required' => true, 'class' => 'no-changes', 'onchange' => $onChangeScript));
     } else {
         if (!empty($formData['parent_id'])) {
             $themeFieldset->addField('parent_title', 'note', array('label' => $this->__('Parent theme'), 'title' => $this->__('Parent theme'), 'name' => 'parent_title', 'text' => $parentTheme->getId() ? $parentTheme->getThemeTitle() : ''));
         }
     }
     if (!empty($formData['theme_path'])) {
         $themeFieldset->addField('theme_path', 'label', array('label' => $this->__('Theme Path'), 'title' => $this->__('Theme Path'), 'name' => 'theme_code'));
     }
     $themeFieldset->addField('theme_version', $this->_getFieldTextType(), array('label' => $this->__('Theme Version'), 'title' => $this->__('Theme Version'), 'name' => 'theme_version', 'required' => $this->_getFieldAttrRequired(), 'note' => $this->_filterFieldNote($this->__('Example: 0.0.0.1 or 123.1.0.25-alpha1'))));
     $themeFieldset->addField('theme_title', $this->_getFieldTextType(), array('label' => $this->__('Theme Title'), 'title' => $this->__('Theme Title'), 'name' => 'theme_title', 'required' => $this->_getFieldAttrRequired()));
     if ($this->_isThemeEditable) {
         $maxImageSize = Mage::helper('Mage_Core_Helper_File_Storage')->getMaxFileSizeInMb();
         if ($maxImageSize) {
             $previewImageNote = $this->__('Max image size %sM', $maxImageSize);
         } else {
             $previewImageNote = $this->__('System doesn\'t allow to get file upload settings');
         }
         $themeFieldset->addField('preview_image', 'image', array('label' => $this->__('Theme Preview Image'), 'title' => $this->__('Theme Preview Image'), 'name' => 'preview_image', 'required' => false, 'note' => $previewImageNote));
     } else {
         if (!empty($formData['preview_image'])) {
             $themeFieldset->addField('preview_image', 'note', array('label' => $this->__('Theme Preview Image'), 'title' => $this->__('Theme Preview Image'), 'name' => 'preview_image', 'after_element_html' => '<img width="50" src="' . Mage_Core_Model_Theme::getPreviewImageDirectoryUrl() . $formData['preview_image'] . '" />'));
         }
     }
     return $this;
 }
Beispiel #9
0
 /**
  * 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;
 }
Beispiel #10
0
 /**
  * Get the name of the inherited theme
  *
  * If the specified theme inherits other theme the result is the name of inherited theme.
  * If the specified theme does not inherit other theme the result is null.
  *
  * @param Mage_Core_Model_Theme $themeModel
  * @return string|null
  */
 protected function _getInheritedTheme($themeModel)
 {
     $themePath = $themeModel->getThemePath();
     return $themePath ? explode('/', $themePath) : null;
 }