Fixed bug #14050: CleanUp - CGL format of t3lib files - t3lib_positionmap
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsparser_tsconfig.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * (c) 2007-2010 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 * $Id$
32 *
33 * @author Kraft Bernhard <kraftb@kraftb.at>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 */
38
39 class t3lib_TSparser_TSconfig extends t3lib_TSparser {
40 /**
41 * @var array
42 */
43 protected $rootLine = array();
44
45 /**
46 * Parses the passed TS-Config using conditions and caching
47 *
48 * @param string $TStext: The TSConfig being parsed
49 * @param string $type: The type of TSConfig (either "userTS" or "PAGES")
50 * @param integer $id: The uid of the page being handled
51 * @param array $rootLine: The rootline of the page being handled
52 * @return array Array containing the parsed TSConfig and a flag wheter the content was retrieved from cache
53 * @see t3lib_TSparser
54 */
55 public function parseTSconfig($TStext, $type, $id = 0, array $rootLine = array()) {
56 $this->type = $type;
57 $this->id = $id;
58 $this->rootLine = $rootLine;
59 $hash = md5($type.':'.$TStext);
60 $cachedContent = t3lib_BEfunc::getHash($hash, 0);
61
62 if ($cachedContent) {
63 $storedData = unserialize($cachedContent);
64 $storedMD5 = substr($cachedContent, -strlen($hash));
65 $storedData['match'] = array();
66 $storedData = $this->matching($storedData);
67 $checkMD5 = md5(serialize($storedData));
68
69 if ($checkMD5 == $storedMD5) {
70 $res = array(
71 'TSconfig' => $storedData['TSconfig'],
72 'cached' => 1,
73 );
74 } else {
75 $shash = md5($checkMD5.$hash);
76 $cachedSpec = t3lib_BEfunc::getHash($shash, 0);
77 if ($cachedSpec) {
78 $storedData = unserialize($cachedSpec);
79 $res = array(
80 'TSconfig' => $storedData['TSconfig'],
81 'cached' => 1,
82 );
83 } else {
84 $storeData = $this->parseWithConditions($TStext);
85 $serData = serialize($storeData);
86 t3lib_BEfunc::storeHash($shash, $serData, $type.'_TSconfig');
87 $res = array(
88 'TSconfig' => $storeData['TSconfig'],
89 'cached' => 0,
90 );
91 }
92 }
93 } else {
94 $storeData = $this->parseWithConditions($TStext);
95 $serData = serialize($storeData);
96 $md5 = md5($serData);
97 t3lib_BEfunc::storeHash($hash, $serData.$md5, $type.'_TSconfig');
98 $res = array(
99 'TSconfig' => $storeData['TSconfig'],
100 'cached' => 0,
101 );
102 }
103
104 return $res;
105 }
106
107 /**
108 * Does the actual parsing using the parent objects "parse" method. Creates the match-Object
109 *
110 * @param string $TSconfig: The TSConfig being parsed
111 * @return array Array containing the parsed TSConfig, the encountered sectiosn, the matched sections
112 */
113 protected function parseWithConditions($TSconfig) {
114 /* @var $matchObj t3lib_matchCondition_backend */
115 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_backend');
116 $matchObj->setRootline($this->rootLine);
117 $matchObj->setPageId($this->id);
118
119 $this->parse($TSconfig, $matchObj);
120
121 $storeData = array(
122 'TSconfig' => $this->setup,
123 'sections' => $this->sections,
124 'match' => $this->sectionsMatch,
125 );
126
127 return $storeData;
128 }
129
130
131 /**
132 * Is just going through an array of conditions to determine which are matching (for getting correct cache entry)
133 *
134 * @param array $cc: An array containing the sections to match
135 * @return array The input array with matching sections filled into the "match" key
136 */
137 protected function matching(array $cc) {
138 if (is_array($cc['sections'])) {
139 /* @var $matchObj t3lib_matchCondition_backend */
140 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_backend');
141 $matchObj->setRootline($this->rootLine);
142 $matchObj->setPageId($this->id);
143
144 foreach ($cc['sections'] as $key => $pre) {
145 if ($matchObj->match($pre)) {
146 $cc['match'][$key] = $pre;
147 }
148 }
149 }
150
151 return $cc;
152 }
153
154 }
155
156
157 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_tsconfig.php']) {
158 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_tsconfig.php']);
159 }
160 ?>