|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com) 00006 * (c) 2007-2011 Kraft Bernhard (kraftb@kraftb.at) 00007 * All rights reserved 00008 * 00009 * This script is part of the TYPO3 project. The TYPO3 project is 00010 * free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * The GNU General Public License can be found at 00016 * http://www.gnu.org/copyleft/gpl.html. 00017 * A copy is found in the textfile GPL.txt and important notices to the license 00018 * from the author is found in LICENSE.txt distributed with these scripts. 00019 * 00020 * 00021 * This script is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * This copyright notice MUST APPEAR in all copies of the script! 00027 ***************************************************************/ 00028 /** 00029 * A TS-Config parsing class which performs condition evaluation 00030 * 00031 * $Id: class.t3lib_tsparser_tsconfig.php 10121 2011-01-18 20:15:30Z ohader $ 00032 * 00033 * @author Kraft Bernhard <kraftb@kraftb.at> 00034 */ 00035 /** 00036 * [CLASS/FUNCTION INDEX of SCRIPT] 00037 */ 00038 00039 class t3lib_TSparser_TSconfig extends t3lib_TSparser { 00040 /** 00041 * @var array 00042 */ 00043 protected $rootLine = array(); 00044 00045 /** 00046 * Parses the passed TS-Config using conditions and caching 00047 * 00048 * @param string $TStext: The TSConfig being parsed 00049 * @param string $type: The type of TSConfig (either "userTS" or "PAGES") 00050 * @param integer $id: The uid of the page being handled 00051 * @param array $rootLine: The rootline of the page being handled 00052 * @return array Array containing the parsed TSConfig and a flag wheter the content was retrieved from cache 00053 * @see t3lib_TSparser 00054 */ 00055 public function parseTSconfig($TStext, $type, $id = 0, array $rootLine = array()) { 00056 $this->type = $type; 00057 $this->id = $id; 00058 $this->rootLine = $rootLine; 00059 $hash = md5($type . ':' . $TStext); 00060 $cachedContent = t3lib_BEfunc::getHash($hash, 0); 00061 00062 if ($cachedContent) { 00063 $storedData = unserialize($cachedContent); 00064 $storedMD5 = substr($cachedContent, -strlen($hash)); 00065 $storedData['match'] = array(); 00066 $storedData = $this->matching($storedData); 00067 $checkMD5 = md5(serialize($storedData)); 00068 00069 if ($checkMD5 == $storedMD5) { 00070 $res = array( 00071 'TSconfig' => $storedData['TSconfig'], 00072 'cached' => 1, 00073 ); 00074 } else { 00075 $shash = md5($checkMD5 . $hash); 00076 $cachedSpec = t3lib_BEfunc::getHash($shash, 0); 00077 if ($cachedSpec) { 00078 $storedData = unserialize($cachedSpec); 00079 $res = array( 00080 'TSconfig' => $storedData['TSconfig'], 00081 'cached' => 1, 00082 ); 00083 } else { 00084 $storeData = $this->parseWithConditions($TStext); 00085 $serData = serialize($storeData); 00086 t3lib_BEfunc::storeHash($shash, $serData, $type . '_TSconfig'); 00087 $res = array( 00088 'TSconfig' => $storeData['TSconfig'], 00089 'cached' => 0, 00090 ); 00091 } 00092 } 00093 } else { 00094 $storeData = $this->parseWithConditions($TStext); 00095 $serData = serialize($storeData); 00096 $md5 = md5($serData); 00097 t3lib_BEfunc::storeHash($hash, $serData . $md5, $type . '_TSconfig'); 00098 $res = array( 00099 'TSconfig' => $storeData['TSconfig'], 00100 'cached' => 0, 00101 ); 00102 } 00103 00104 return $res; 00105 } 00106 00107 /** 00108 * Does the actual parsing using the parent objects "parse" method. Creates the match-Object 00109 * 00110 * @param string $TSconfig: The TSConfig being parsed 00111 * @return array Array containing the parsed TSConfig, the encountered sectiosn, the matched sections 00112 */ 00113 protected function parseWithConditions($TSconfig) { 00114 /* @var $matchObj t3lib_matchCondition_backend */ 00115 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_backend'); 00116 $matchObj->setRootline($this->rootLine); 00117 $matchObj->setPageId($this->id); 00118 00119 $this->parse($TSconfig, $matchObj); 00120 00121 $storeData = array( 00122 'TSconfig' => $this->setup, 00123 'sections' => $this->sections, 00124 'match' => $this->sectionsMatch, 00125 ); 00126 00127 return $storeData; 00128 } 00129 00130 00131 /** 00132 * Is just going through an array of conditions to determine which are matching (for getting correct cache entry) 00133 * 00134 * @param array $cc: An array containing the sections to match 00135 * @return array The input array with matching sections filled into the "match" key 00136 */ 00137 protected function matching(array $cc) { 00138 if (is_array($cc['sections'])) { 00139 /* @var $matchObj t3lib_matchCondition_backend */ 00140 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_backend'); 00141 $matchObj->setRootline($this->rootLine); 00142 $matchObj->setPageId($this->id); 00143 00144 foreach ($cc['sections'] as $key => $pre) { 00145 if ($matchObj->match($pre)) { 00146 $cc['match'][$key] = $pre; 00147 } 00148 } 00149 } 00150 00151 return $cc; 00152 } 00153 00154 } 00155 00156 00157 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_tsconfig.php'])) { 00158 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_tsconfig.php']); 00159 } 00160 ?>
1.8.0