/** * @param $observer */ public function pathTemplateReplaceBeforeToHtml($observer) { if (($block = $observer->getBlock()) instanceof Mage_Core_Block_Template) { if (!Mage::registry('design_path_aitoc')) { $currentViewDirAll = Mage::getBaseDir('design'); Mage::register('design_path_aitoc', $currentViewDirAll); } $currentViewDir = Mage::registry('design_path_aitoc'); $fileName = $block->getTemplateFile(); //save base dir before this block if (Mage::registry('design_path_for_' . get_class($block) . '_' . $block->getId())) { Mage::unregister('design_path_for_' . get_class($block) . '_' . $block->getId()); } Mage::register('design_path_for_' . get_class($block) . '_' . $block->getId(), Mage::getBaseDir('design')); if (false !== strpos($fileName, 'aitcommonfiles')) { if (Mage::getStoreConfigFlag('aitsys/settings/use_dynamic_patches') || !file_exists($currentViewDir . DS . $fileName)) { $newViewDir = Aitoc_Aitsys_Model_Aitpatch::getPatchesCacheDir() . 'design'; if (file_exists($newViewDir . DS . $fileName)) { $currentViewDir = $newViewDir; // replacing view dir } else { // also trying with 'default' folder instead of 'base' (for compatibility with 1.3 and 1.4 in one version) $fileNameDef = str_replace(DS . 'base' . DS, DS . 'default' . DS, $fileName); if (file_exists($newViewDir . DS . $fileNameDef)) { $currentViewDir = $newViewDir; // replacing view dir $fileName = $fileNameDef; // forcing use 'default' instead of 'base' } } } } $block->setTemplateFile($fileName); Mage::getConfig()->getOptions()->setData('design_dir', $currentViewDir); } else { if (Mage::registry('design_path_aitoc') && Mage::registry('design_path_aitoc') != Mage::getBaseDir('design')) { Mage::getConfig()->getOptions()->setData('design_dir', Mage::registry('design_path_aitoc')); } } }
/** * @return string */ public function getDestinationFile() { $destinationFile = str_replace(Mage::getBaseDir('app'), Aitoc_Aitsys_Model_Aitpatch::getPatchesCacheDir(), $this->getSourceFile(true)); $destinationFile = substr($destinationFile, 0, strrpos($destinationFile, DS) + 1); $destinationFile = str_replace(strstr($destinationFile, 'template'), '', $destinationFile); $destinationFile .= 'template' . DS . 'aitcommonfiles' . DS . str_replace('.patch', '', $this->getPatchFile()); $destinationFile = $this->_removeBasedir($destinationFile); return $destinationFile; }
public function fetchView($fileName) { $currentViewDir = $this->_viewDir; if (false !== strpos($fileName, 'aitcommonfiles')) { if (Mage::getStoreConfigFlag('aitsys/settings/use_dynamic_patches') || !file_exists($currentViewDir . DS . $fileName)) { $newViewDir = Aitoc_Aitsys_Model_Aitpatch::getPatchesCacheDir() . 'design'; if (file_exists($newViewDir . DS . $fileName)) { $this->_viewDir = $newViewDir; // replacing view dir } else { // also trying with 'default' folder instead of 'base' (for compatibility with 1.3 and 1.4 in one version) $fileNameDef = str_replace(DS . 'base' . DS, DS . 'default' . DS, $fileName); if (file_exists($newViewDir . DS . $fileNameDef)) { $this->_viewDir = $newViewDir; // replacing view dir $fileName = $fileNameDef; // forcing use 'default' instead of 'base' } } } } Varien_Profiler::start($fileName); extract($this->_viewVars); $do = $this->getDirectOutput(); if (!$do) { ob_start(); } if ($this->getShowTemplateHints()) { echo '<div style="position:relative; border:1px dotted red; margin:6px 2px; padding:18px 2px 2px 2px; zoom:1;"><div style="position:absolute; left:0; top:0; padding:2px 5px; background:red; color:white; font:normal 11px Arial; text-align:left !important; z-index:998;" onmouseover="this.style.zIndex=\'999\'" onmouseout="this.style.zIndex=\'998\'" title="' . $fileName . '">' . $fileName . '</div>'; if (self::$_showTemplateHintsBlocks) { $thisClass = get_class($this); echo '<div style="position:absolute; right:0; top:0; padding:2px 5px; background:red; color:blue; font:normal 11px Arial; text-align:left !important; z-index:998;" onmouseover="this.style.zIndex=\'999\'" onmouseout="this.style.zIndex=\'998\'" title="' . $thisClass . '">' . $thisClass . '</div>'; } } try { $includeFilePath = realpath($this->_viewDir . DS . $fileName); if (strpos($includeFilePath, realpath($this->_viewDir)) === 0 || $this->_checkAllowSymlinks()) { include $includeFilePath; } else { Mage::log('Not valid template file:' . $fileName, Zend_Log::CRIT, null, null, true); } } catch (Exception $e) { ob_get_clean(); Mage::log('Failed to load template:' . $this->_viewDir . DS . $fileName); throw $e; } //include $this->_viewDir.DS.$fileName; if ($this->getShowTemplateHints()) { echo '</div>'; } if (!$do) { $html = ob_get_clean(); } else { $html = ''; } Varien_Profiler::stop($fileName); #$html = parent::fetchView($fileName); $this->_viewDir = $currentViewDir; // returning default dir back return $html; }
/** * @return array */ public function getSubsystemsDirs() { if (empty($this->_subsystemsDirs)) { $this->_subsystemsDirs[] = Aitoc_Aitsys_Model_Rewriter_Abstract::getRewritesCacheDir(); $this->_subsystemsDirs[] = Aitoc_Aitsys_Model_Aitpatch::getPatchesCacheDir(); } return $this->_subsystemsDirs; }
/** * @todo refactoring */ protected function _setFileMergeData($oModuleCustomConfig, $sModuleDir) { if (!$oModuleCustomConfig) { return false; } $oConfig = Mage::getConfig(); $aDestFileHash = array(); if ($oModuleCustomConfig->template and $oModuleCustomConfig->template->children()) { foreach ($oModuleCustomConfig->template->children() as $sAreaName => $aAreaConfig) { if ($aAreaConfig and $aAreaConfig->children()) { foreach ($aAreaConfig->children() as $sNodeKey => $aFileConfig) { if (!$this->validateVersion(Mage::getVersion(), $aFileConfig->attributes())) { continue; } $aFilePathKey = $aFileConfig->attributes()->path; $bOptional = $aFileConfig->attributes()->optional ? (int) $aFileConfig->attributes()->optional : false; $bOptional = $bOptional ? true : false; $sTplKey = $aFilePathKey . '.phtml.patch'; if (isset($this->_aFileMerge[$sTplKey]['optional'])) { if ($this->_aFileMerge[$sTplKey]['optional']) { $this->_aFileMerge[$sTplKey]['optional'] = $bOptional; } } else { $this->_aFileMerge[$sTplKey]['optional'] = $bOptional; } $patchFile = $this->tool()->filesystem()->getPatchFilePath($sTplKey, $sModuleDir . '/data/'); if ($patchFile->getIsError()) { $this->_addError($patchFile->getFilePath(), 'no_module_file'); } $sFileDest = $this->_getDesignFileDestinationPrefix($sAreaName) . 'default/template/aitcommonfiles/' . $aFilePathKey . '.phtml'; $sDestFilePath = Aitoc_Aitsys_Model_Aitpatch::getPatchesCacheDir() . $sFileDest; $aDestFileHash[$sDestFilePath] = 1; if (isset($this->_aFileMerge[$sTplKey])) { $this->_aFileMerge[$sTplKey]['modules'][$sModuleDir] = $sFileDest; } else { $this->_aFileMerge[$sTplKey] = array('modules' => array($sModuleDir => $sFileDest)); } } } } } if ($aDestFileHash) { foreach ($aDestFileHash as $sFile => $sVal) { $this->_checkFileWritePermissions($sFile); } } return true; }