Fixed bug #17662: Remove deprecated class gzip_encode
[Packages/TYPO3.CMS.git] / t3lib / matchcondition / class.t3lib_matchcondition_frontend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Oliver Hader <oliver@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Matching TypoScript conditions for frontend disposal.
30 *
31 * Used with the TypoScript parser.
32 * Matches browserinfo, IPnumbers for use with templates
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 * @package TYPO3
36 * @subpackage t3lib
37 */
38 class t3lib_matchCondition_frontend extends t3lib_matchCondition_abstract {
39 /**
40 * @var array
41 */
42 protected $deprecatedHooks = array();
43
44 /**
45 * Constructor for this class
46 *
47 * @return void
48 */
49 public function __construct() {
50 $this->initializeDeprecatedHooks();
51 }
52
53 /**
54 * Initializes deprectated hooks that existed in t3lib_matchCondition until TYPO3 4.3.
55 *
56 * @return void
57 */
58 protected function initializeDeprecatedHooks() {
59 // Hook: $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass']:
60 $matchConditionHooks =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'];
61 if (is_array($matchConditionHooks)) {
62 t3lib_div::deprecationLog(
63 'The hook $TYPO3_CONF_VARS[SC_OPTIONS][t3lib/class.t3lib_matchcondition.php][matchConditionClass] ' .
64 'is deprecated since TYPO3 4.3. Use the new hooks getBrowserInfo and getDeviceType in ' .
65 't3lib_utility_Client instead.'
66 );
67
68 foreach ($matchConditionHooks as $hookClass) {
69 $this->deprecatedHooks[] = t3lib_div::getUserObj($hookClass, '');
70 }
71 }
72 }
73
74 /**
75 * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]"
76 *
77 * @param string $string: The condition to match against its criterias.
78 * @return boolean Whether the condition matched
79 * @see t3lib_tsparser::parse()
80 */
81 protected function evaluateCondition($string) {
82 list($key, $value) = t3lib_div::trimExplode('=', $string, FALSE, 2);
83
84 $result = parent::evaluateConditionCommon($key, $value);
85
86 if (is_bool($result)) {
87 return $result;
88 } else {
89 switch ($key) {
90 case 'usergroup':
91 $groupList = $this->getGroupList();
92 if ($groupList != '0,-1') { // '0,-1' is the default usergroups when not logged in!
93 $values = t3lib_div::trimExplode(',', $value, TRUE);
94 foreach ($values as $test) {
95 if ($test == '*' || t3lib_div::inList($groupList, $test)) {
96 return TRUE;
97 }
98 }
99 }
100 break;
101 case 'treeLevel':
102 $values = t3lib_div::trimExplode(',', $value, TRUE);
103 $treeLevel = count($this->rootline) - 1;
104 foreach ($values as $test) {
105 if ($test == $treeLevel) {
106 return TRUE;
107 }
108 }
109 break;
110 case 'PIDupinRootline':
111 case 'PIDinRootline':
112 $values = t3lib_div::trimExplode(',', $value, TRUE);
113 if (($key == 'PIDinRootline') || (!in_array($this->pageId, $values))) {
114 foreach ($values as $test) {
115 foreach ($this->rootline as $rl_dat) {
116 if ($rl_dat['uid'] == $test) {
117 return TRUE;
118 }
119 }
120 }
121 }
122 break;
123 }
124 }
125
126 return FALSE;
127 }
128
129 /**
130 * Generates an array with abstracted browser information
131 *
132 * @param string $userAgent: The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
133 * @return array Contains keys "browser", "version", "system"
134 */
135 protected function getBrowserInfo($userAgent) {
136 // Exceute deprecated hooks:
137 // @deprecated since TYPO3 4.3
138 foreach ($this->deprecatedHooks as $hookObj) {
139 if (method_exists($hookObj, 'browserInfo')) {
140 $result = $hookObj->browserInfo($userAgent);
141 if (strlen($result)) {
142 return $result;
143 }
144 }
145 }
146
147 return parent::getBrowserInfo($userAgent);
148 }
149
150 /**
151 * Gets a code for a browsing device based on the input useragent string.
152 *
153 * @param string $userAgent: The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
154 * @return string Code for the specific device type
155 */
156 protected function getDeviceType($userAgent) {
157 // Exceute deprecated hooks:
158 // @deprecated since TYPO3 4.3
159 foreach ($this->deprecatedHooks as $hookObj) {
160 if (method_exists($hookObj, 'whichDevice')) {
161 $result = $hookObj->whichDevice($userAgent);
162 if (strlen($result)) {
163 return $result;
164 }
165 }
166 }
167
168 // deprecated, see above
169 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'])) {
170 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'] as $_classRef) {
171 $_procObj = t3lib_div::getUserObj($_classRef);
172 return $_procObj->whichDevice_ext($userAgent);
173 }
174 }
175
176 return parent::getDeviceType($userAgent);
177 }
178
179 /**
180 * Returns GP / ENV / TSFE vars
181 *
182 * @param string Identifier
183 * @return mixed The value of the variable pointed to.
184 */
185 protected function getVariable($var) {
186 $vars = explode(':', $var, 2);
187
188 $val = parent::getVariableCommon($vars);
189
190 if (is_null($val)) {
191 $splitAgain = explode('|', $vars[1], 2);
192 $k = trim($splitAgain[0]);
193 if ($k) {
194 switch ((string) trim($vars[0])) {
195 case 'TSFE':
196 $val = $this->getGlobal('TSFE|' . $vars[1]);
197 break;
198 }
199 }
200 }
201
202 return $val;
203 }
204
205 /**
206 * Get the usergroup list of the current user.
207 *
208 * @return string The usergroup list of the current user
209 */
210 protected function getGroupList() {
211 $groupList = $GLOBALS['TSFE']->gr_list;
212 return $groupList;
213 }
214
215 /**
216 * Determines the current page Id.
217 *
218 * @return integer The current page Id
219 */
220 protected function determinePageId() {
221 return (int) $GLOBALS['TSFE']->id;
222 }
223
224 /**
225 * Gets the properties for the current page.
226 *
227 * @return array The properties for the current page.
228 */
229 protected function getPage() {
230 return $GLOBALS['TSFE']->page;
231 }
232
233 /**
234 * Determines the rootline for the current page.
235 *
236 * @return array The rootline for the current page.
237 */
238 protected function determineRootline() {
239 $rootline = (array) $GLOBALS['TSFE']->tmpl->rootLine;
240 return $rootline;
241 }
242
243 /**
244 * Get prefix for user functions (normally 'user_').
245 *
246 * @return string The prefix for user functions (normally 'user_').
247 */
248 protected function getUserFuncClassPrefix() {
249 $userFuncClassPrefix = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['userFuncClassPrefix'];
250 return $userFuncClassPrefix;
251 }
252
253 /**
254 * Get the id of the current user.
255 *
256 * @return integer The id of the current user
257 */
258 protected function getUserId() {
259 $userId = $GLOBALS['TSFE']->fe_user->user['uid'];
260 return $userId;
261 }
262
263 /**
264 * Determines if a user is logged in.
265 *
266 * @return boolean Determines if a user is logged in
267 */
268 protected function isUserLoggedIn() {
269 $userLoggedIn = FALSE;
270 if ($GLOBALS['TSFE']->loginUser) {
271 $userLoggedIn = TRUE;
272 }
273 return $userLoggedIn;
274 }
275
276 /**
277 * Set/write a log message.
278 *
279 * @param string $message: The log message to set/write
280 * @return void
281 */
282 protected function log($message) {
283 if (is_object($GLOBALS['TT'])) {
284 $GLOBALS['TT']->setTSlogMessage($message, 3);
285 }
286 }
287 }
288
289
290 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/matchcondition/class.t3lib_matchcondition_frontend.php'])) {
291 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/matchcondition/class.t3lib_matchcondition_frontend.php']);
292 }
293
294 ?>