[FEATURE] Add support for native date/time fields
[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 /**
30 * A TS-Config parsing class which performs condition evaluation
31 *
32 * @author Kraft Bernhard <kraftb@kraftb.at>
33 * @package TYPO3
34 * @subpackage t3lib
35 */
36 class t3lib_TSparser_TSconfig extends t3lib_TSparser {
37 /**
38 * @var array
39 */
40 protected $rootLine = array();
41
42 /**
43 * Parses the passed TS-Config using conditions and caching
44 *
45 * @param string $TStext The TSConfig being parsed
46 * @param string $type The type of TSConfig (either "userTS" or "PAGES")
47 * @param integer $id The uid of the page being handled
48 * @param array $rootLine The rootline of the page being handled
49 * @return array Array containing the parsed TSConfig and a flag whether the content was retrieved from cache
50 * @see t3lib_TSparser
51 */
52 public function parseTSconfig($TStext, $type, $id = 0, array $rootLine = array()) {
53 $this->type = $type;
54 $this->id = $id;
55 $this->rootLine = $rootLine;
56 $hash = md5($type . ':' . $TStext);
57 $cachedContent = t3lib_BEfunc::getHash($hash, 0);
58
59 if ($cachedContent) {
60 $storedData = unserialize($cachedContent);
61 $storedMD5 = substr($cachedContent, -strlen($hash));
62 $storedData['match'] = array();
63 $storedData = $this->matching($storedData);
64 $checkMD5 = md5(serialize($storedData));
65
66 if ($checkMD5 == $storedMD5) {
67 $res = array(
68 'TSconfig' => $storedData['TSconfig'],
69 'cached' => 1,
70 );
71 } else {
72 $shash = md5($checkMD5 . $hash);
73 $cachedSpec = t3lib_BEfunc::getHash($shash, 0);
74 if ($cachedSpec) {
75 $storedData = unserialize($cachedSpec);
76 $res = array(
77 'TSconfig' => $storedData['TSconfig'],
78 'cached' => 1,
79 );
80 } else {
81 $storeData = $this->parseWithConditions($TStext);
82 $serData = serialize($storeData);
83 t3lib_BEfunc::storeHash($shash, $serData, $type . '_TSconfig');
84 $res = array(
85 'TSconfig' => $storeData['TSconfig'],
86 'cached' => 0,
87 );
88 }
89 }
90 } else {
91 $storeData = $this->parseWithConditions($TStext);
92 $serData = serialize($storeData);
93 $md5 = md5($serData);
94 t3lib_BEfunc::storeHash($hash, $serData . $md5, $type . '_TSconfig');
95 $res = array(
96 'TSconfig' => $storeData['TSconfig'],
97 'cached' => 0,
98 );
99 }
100
101 return $res;
102 }
103
104 /**
105 * Does the actual parsing using the parent objects "parse" method. Creates the match-Object
106 *
107 * @param string $TSconfig The TSConfig being parsed
108 * @return array Array containing the parsed TSConfig, the encountered sectiosn, the matched sections
109 */
110 protected function parseWithConditions($TSconfig) {
111 /** @var $matchObj t3lib_matchCondition_backend */
112 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_backend');
113 $matchObj->setRootline($this->rootLine);
114 $matchObj->setPageId($this->id);
115
116 $this->parse($TSconfig, $matchObj);
117
118 $storeData = array(
119 'TSconfig' => $this->setup,
120 'sections' => $this->sections,
121 'match' => $this->sectionsMatch,
122 );
123
124 return $storeData;
125 }
126
127
128 /**
129 * Is just going through an array of conditions to determine which are matching (for getting correct cache entry)
130 *
131 * @param array $cc An array containing the sections to match
132 * @return array The input array with matching sections filled into the "match" key
133 */
134 protected function matching(array $cc) {
135 if (is_array($cc['sections'])) {
136 /** @var $matchObj t3lib_matchCondition_backend */
137 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition_backend');
138 $matchObj->setRootline($this->rootLine);
139 $matchObj->setPageId($this->id);
140
141 foreach ($cc['sections'] as $key => $pre) {
142 if ($matchObj->match($pre)) {
143 $cc['match'][$key] = $pre;
144 }
145 }
146 }
147
148 return $cc;
149 }
150 }
151 ?>