Public Member Functions | |
| __construct () | |
| getElementClass () | |
| resetUpdates () | |
| addUpdate ($update) | |
| asArray () | |
| asString () | |
| resetHandles () | |
| addHandle ($handle) | |
| removeHandle ($handle) | |
| getHandles () | |
| getCacheId () | |
| setCacheId ($cacheId) | |
| loadCache () | |
| saveCache () | |
| load ($handles=array()) | |
| asSimplexml () | |
| merge ($handle) | |
| fetchFileLayoutUpdates () | |
| fetchPackageLayoutUpdates ($handle) | |
| fetchDbLayoutUpdates ($handle) | |
| fetchRecursiveUpdates ($updateXml) | |
Public Attributes | |
| const | LAYOUT_GENERAL_CACHE_TAG = 'LAYOUT_GENERAL_CACHE_TAG' |
Protected Attributes | |
| $_elementClass | |
| $_packageLayout | |
| $_cacheId | |
| $_cachePrefix | |
| $_updates = array() | |
| $_handles = array() | |
| $_subst = array() | |
Definition at line 28 of file Update.php.
| __construct | ( | ) |
Definition at line 82 of file Update.php.
00083 { 00084 $subst = Mage::getConfig()->getPathVars(); 00085 foreach ($subst as $k=>$v) { 00086 $this->_subst['from'][] = '{{'.$k.'}}'; 00087 $this->_subst['to'][] = $v; 00088 } 00089 }
| addHandle | ( | $ | handle | ) |
Definition at line 127 of file Update.php.
00128 { 00129 if (is_array($handle)) { 00130 foreach ($handle as $h) { 00131 $this->_handles[$h] = 1; 00132 } 00133 } else { 00134 $this->_handles[$handle] = 1; 00135 } 00136 return $this; 00137 }
| addUpdate | ( | $ | update | ) |
| asArray | ( | ) |
| asSimplexml | ( | ) |
Definition at line 231 of file Update.php.
00232 { 00233 $updates = trim($this->asString()); 00234 $updates = '<'.'?xml version="1.0"?'.'><layout>'.$updates.'</layout>'; 00235 return simplexml_load_string($updates, $this->getElementClass()); 00236 }
| asString | ( | ) |
| fetchDbLayoutUpdates | ( | $ | handle | ) |
Definition at line 334 of file Update.php.
00335 { 00336 $_profilerKey = 'layout/db_update: '.$handle; 00337 Varien_Profiler::start($_profilerKey); 00338 00339 try { 00340 $updateStr = Mage::getResourceModel('core/layout')->fetchUpdatesByHandle($handle); 00341 if (!$updateStr) { 00342 return false; 00343 } 00344 $updateStr = str_replace($this->_subst['from'], $this->_subst['to'], $updateStr); 00345 $updateXml = simplexml_load_string($updateStr, $this->getElementClass()); 00346 $this->fetchRecursiveUpdates($updateXml); 00347 00348 $this->addUpdate($update); 00349 } catch (PDOException $e) { 00350 throw $e; 00351 } catch (Exception $e) { 00352 00353 } 00354 00355 Varien_Profiler::stop($_profilerKey); 00356 return true; 00357 }
| fetchFileLayoutUpdates | ( | ) |
Definition at line 253 of file Update.php.
00254 { 00255 $elementClass = $this->getElementClass(); 00256 00257 $design = Mage::getSingleton('core/design_package'); 00258 $area = $design->getArea(); 00259 $storeId = Mage::app()->getStore()->getId(); 00260 $cacheKey = 'LAYOUT_'.$area.'_STORE'.$storeId.'_'.$design->getPackageName().'_'.$design->getTheme('layout'); 00261 #echo "TEST:".$cacheKey; 00262 $cacheTags = array('layout'); 00263 00264 if (Mage::app()->useCache('layout') && ($layoutStr = Mage::app()->loadCache($cacheKey))) { 00265 $this->_packageLayout = simplexml_load_string($layoutStr, $elementClass); 00266 } 00267 00268 if (empty($layoutStr)) { 00269 $updatesRoot = Mage::app()->getConfig()->getNode($area.'/layout/updates'); 00270 Mage::dispatchEvent('core_layout_update_updates_get_after', array('updates' => $updatesRoot)); 00271 $updateFiles = array(); 00272 foreach ($updatesRoot->children() as $updateNode) { 00273 if ($updateNode->file) { 00274 $module = $updateNode->getAttribute('module'); 00275 if ($module && Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $module)) { 00276 continue; 00277 } 00278 $updateFiles[] = (string)$updateNode->file; 00279 } 00280 } 00281 00282 // custom local layout updates file - load always last 00283 $updateFiles[] = 'local.xml'; 00284 00285 $layoutStr = ''; 00286 #$layoutXml = new $elementClass('<layouts/>'); 00287 foreach ($updateFiles as $file) { 00288 $filename = $design->getLayoutFilename($file); 00289 if (!is_readable($filename)) { 00290 continue; 00291 } 00292 $fileStr = file_get_contents($filename); 00293 $fileStr = str_replace($this->_subst['from'], $this->_subst['to'], $fileStr); 00294 $fileXml = simplexml_load_string($fileStr, $elementClass); 00295 if (!$fileXml instanceof SimpleXMLElement) { 00296 continue; 00297 } 00298 $layoutStr .= $fileXml->innerXml(); 00299 00300 #$layoutXml->appendChild($fileXml); 00301 } 00302 $layoutXml = simplexml_load_string('<layouts>'.$layoutStr.'</layouts>', $elementClass); 00303 00304 $this->_packageLayout = $layoutXml; 00305 00306 if (Mage::app()->useCache('layout')) { 00307 Mage::app()->saveCache($this->_packageLayout->asXml(), $cacheKey, $cacheTags, null); 00308 } 00309 } 00310 00311 return $this; 00312 }
| fetchPackageLayoutUpdates | ( | $ | handle | ) |
Definition at line 314 of file Update.php.
00315 { 00316 $_profilerKey = 'layout/package_update: '.$handle; 00317 Varien_Profiler::start($_profilerKey); 00318 00319 if (empty($this->_packageLayout)) { 00320 $this->fetchFileLayoutUpdates(); 00321 } 00322 foreach ($this->_packageLayout->$handle as $updateXml) { 00323 #echo '<textarea style="width:600px; height:400px;">'.$handle.':'.print_r($updateXml,1).'</textarea>'; 00324 $this->fetchRecursiveUpdates($updateXml); 00325 00326 $this->addUpdate($updateXml->innerXml()); 00327 } 00328 00329 Varien_Profiler::stop($_profilerKey); 00330 00331 return true; 00332 }
| fetchRecursiveUpdates | ( | $ | updateXml | ) |
Definition at line 359 of file Update.php.
00360 { 00361 foreach ($updateXml->children() as $child) { 00362 if (strtolower($child->getName())=='update' && isset($child['handle'])) { 00363 $this->merge((string)$child['handle']); 00364 } 00365 } 00366 return $this; 00367 }
| getCacheId | ( | ) |
Get cache id
Definition at line 155 of file Update.php.
00156 { 00157 if (!$this->_cacheId) { 00158 $this->_cacheId = Mage::app()->getStore()->getId().'_'.md5(join('__', $this->getHandles())); 00159 } 00160 return $this->_cacheId; 00161 }
| getElementClass | ( | ) |
Definition at line 91 of file Update.php.
00092 { 00093 if (!$this->_elementClass) { 00094 $this->_elementClass = Mage::getConfig()->getModelClassName('core/layout_element'); 00095 } 00096 return $this->_elementClass; 00097 }
| getHandles | ( | ) |
| load | ( | $ | handles = array() |
) |
Load layout updates by handles
| array|string | $handles |
Definition at line 207 of file Update.php.
00208 { 00209 if (is_string($handles)) { 00210 $handles = array($handles); 00211 } elseif (!is_array($handles)) { 00212 throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid layout update handle')); 00213 } 00214 00215 foreach ($handles as $handle) { 00216 $this->addHandle($handle); 00217 } 00218 00219 if ($this->loadCache()) { 00220 return $this; 00221 } 00222 00223 foreach ($this->getHandles() as $handle) { 00224 $this->merge($handle); 00225 } 00226 00227 $this->saveCache(); 00228 return $this; 00229 }
| loadCache | ( | ) |
Definition at line 175 of file Update.php.
00176 { 00177 if (!Mage::app()->useCache('layout')) { 00178 return false; 00179 } 00180 00181 if (!$result = Mage::app()->loadCache($this->getCacheId())) { 00182 return false; 00183 } 00184 00185 $this->addUpdate($result); 00186 00187 return true; 00188 }
| merge | ( | $ | handle | ) |
Merge layout update by handle
| string | $handle |
Definition at line 244 of file Update.php.
00245 { 00246 if (!$this->fetchPackageLayoutUpdates($handle) 00247 && !$this->fetchDbLayoutUpdates($handle)) { 00248 #$this->removeHandle($handle); 00249 } 00250 return $this; 00251 }
| removeHandle | ( | $ | handle | ) |
| resetHandles | ( | ) |
Definition at line 121 of file Update.php.
00122 { 00123 $this->_handles = array(); 00124 return $this; 00125 }
| resetUpdates | ( | ) |
Definition at line 99 of file Update.php.
00100 { 00101 $this->_updates = array(); 00102 return $this; 00103 }
| saveCache | ( | ) |
Definition at line 190 of file Update.php.
00191 { 00192 if (!Mage::app()->useCache('layout')) { 00193 return false; 00194 } 00195 $str = $this->asString(); 00196 $tags = $this->getHandles(); 00197 $tags[] = self::LAYOUT_GENERAL_CACHE_TAG; 00198 return Mage::app()->saveCache($str, $this->getCacheId(), $tags, null); 00199 }
| setCacheId | ( | $ | cacheId | ) |
Set cache id
| string | $cacheId |
Definition at line 169 of file Update.php.
$_cacheId [protected] |
Definition at line 52 of file Update.php.
$_cachePrefix [protected] |
Definition at line 59 of file Update.php.
$_elementClass [protected] |
Definition at line 40 of file Update.php.
$_handles = array() [protected] |
Definition at line 73 of file Update.php.
$_packageLayout [protected] |
Definition at line 45 of file Update.php.
$_subst = array() [protected] |
Definition at line 80 of file Update.php.
$_updates = array() [protected] |
Definition at line 66 of file Update.php.
Additional tag for cleaning layout cache convenience
Definition at line 33 of file Update.php.
1.5.8