Revert "[RELEASE] Release of TYPO3 4.6.0alpha1"
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsparser_tsconfig.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * (c) 2007-2011 Kraft Bernhard (kraftb@kraftb.at)
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28 /**
29 * A TS-Config parsing class which performs condition evaluation
30 *
31 * @author Kraft Bernhard <kraftb@kraftb.at>
32 */
33 /**
34 * [CLASS/FUNCTION INDEX of SCRIPT]
35 */
36
37 class t3lib_TSparser_TSconfig extends t3lib_TSparser {
38 /**
39 * @var array
40 */
41 protected $rootLine = array();
42
43 /**
44 * Parses the passed TS-Config using conditions and caching
45 *
46 * @param string $TStext: The TSConfig being parsed
47 * @param string $type: The type of TSConfig (either "userTS" or "PAGES")
48 * @param integer $id: The uid of the page being handled
49 * @param array $rootLine: The rootline of the page being handled
50 * @return array Array containing the parsed TSConfig and a flag wheter the content was retrieved from cache
51 * @see t3lib_TSparser
52 */
53 public function parseTSconfig($TStext, $type, $id = 0, array $rootLine = array()) {
54 $this->type = $type;
55 $this->id = $id;
56 $this->rootLine = $rootLine;
57 $hash = md5($type . ':' . $TStext);
58 $cachedContent = t3lib_BEfunc::getHash($hash, 0);
59
60 if ($cachedContent) {
61 $storedData = unserialize($cachedContent);
62 $storedMD5 = substr($cachedContent, -strlen($hash));
63 $storedData['match'] = array();
64 $storedData = $this->matching($storedData);
65 $checkMD5 = md5(serialize($storedData));
66
67 if ($checkMD5 == $storedMD5) {
68 $res = array(
69 'TSconfig' => $storedData['TSconfig'],
70 'cached' => 1,
71 );
72 } else {
73 $shash = md5($checkMD5 . $hash);
74 $cachedSpec = t3lib_BEfunc::getHash($shash, 0);
75 if ($cachedSpec) {
76 $storedData = unserialize($cachedSpec);
77 $res = array(
78 'TSconfig' => $storedData['TSconfig'],
79 'cached' => 1,
80 );
81 } else {
82 $storeData = $this->parseWithConditions($TStext);
83 $serData = serialize($storeData);
84 t3lib_BEfunc::storeHash($shash, $serData, $type . '_TSconfig');
85 $res = array(
86 'TSconfig' => $storeData['TSconfig'],
87 'cached' => 0,
88 );
89 }
90 }
91 } else {
92 $storeData = $this->parseWithConditions($TStext);
93 $serData = serialize($storeData);
94 $md5 = md5($serData);
95 t3lib_BEfunc::storeHash($hash, $serData . $md5, $type . '_TSconfig');
96 $res = array(
97 'TSconfig' => $storeData['TSconfig'],
98 'cached' => 0,
99 );
100 }
101
102 return $res;
103 }
104
105 /**
106 * Does the actual parsing using the parent objects "parse" method. Creates the match-Object
107 *
108 * @param string $TSconfig: The TSConfig being parsed
109 * @return array Array containing the parsed TSConfig, the encountered sectiosn, the matched sections
110 */
111 protected function parseWithConditions($TSconfig) {
112 /* @var $matchObj t3lib_matchCondition_backend */
113 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_backend');
114 $matchObj->setRootline($this->rootLine);
115 $matchObj->setPageId($this->id);
116
117 $this->parse($TSconfig, $matchObj);
118
119 $storeData = array(
120 'TSconfig' => $this->setup,
121 'sections' => $this->sections,
122 'match' => $this->sectionsMatch,
123 );
124
125 return $storeData;
126 }
127
128
129 /**
130 * Is just going through an array of conditions to determine which are matching (for getting correct cache entry)
131 *
132 * @param array $cc: An array containing the sections to match
133 * @return array The input array with matching sections filled into the "match" key
134 */
135 protected function matching(array $cc) {
136 if (is_array($cc['sections'])) {
137 /* @var $matchObj t3lib_matchCondition_backend */
138 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_backend');
139 $matchObj->setRootline($this->rootLine);
140 $matchObj->setPageId($this->id);
141
142 foreach ($cc['sections'] as $key => $pre) {
143 if ($matchObj->match($pre)) {
144 $cc['match'][$key] = $pre;
145 }
146 }
147 }
148
149 return $cc;
150 }
151
152 }
153
154
155 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_tsconfig.php'])) {
156 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_tsconfig.php']);
157 }
158 ?>