Fixed bug #8491: Template Analyzer Module inconsistencies (thanks to Steffen Kamper).
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_matchcondition.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
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 * Contains class for Matching TypoScript conditions
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 80: class t3lib_matchCondition
41 * 87: function __construct()
42 * 105: function t3lib_matchCondition()
43 * 115: function match($condition_line)
44 * 160: function evalConditionStr($string)
45 * 381: function testNumber($test,$value)
46 * 405: function matchWild($haystack,$needle)
47 * 429: function whichDevice($useragent)
48 * 498: function browserInfo($useragent)
49 * 611: function browserInfo_version($tmp)
50 * 624: function getGlobal($var, $source=NULL)
51 * 658: function getGP_ENV_TSFE($var)
52 *
53 * TOTAL FUNCTIONS: 11
54 * (This index is automatically created/updated by the extension "extdeveval")
55 *
56 */
57
58
59
60
61
62
63
64
65
66
67
68
69 /**
70 * Matching TypoScript conditions
71 *
72 * Used with the TypoScript parser.
73 * Matches browserinfo, IPnumbers for use with templates
74 *
75 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
76 * @package TYPO3
77 * @subpackage t3lib
78 * @see t3lib_TStemplate::matching(), t3lib_TStemplate::generateConfig()
79 */
80 class t3lib_matchCondition {
81 var $matchAlternative=array(); // If this array has elements, the matching returns true if a whole "matchline" is found in the array!
82 var $matchAll=0; // If set all is matched!
83
84 var $altRootLine=array();
85 var $hookObjectsArr = array();
86
87 /**
88 * Constructor for this class
89 *
90 * @return void
91 */
92 function __construct() {
93 global $TYPO3_CONF_VARS;
94
95 // Usage (ext_localconf.php):
96 // $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'][] =
97 // 'EXT:my_ext/class.browserinfo.php:MyBrowserInfoClass';
98 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'])) {
99 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'] as $classRef) {
100 $this->hookObjectsArr[] = &t3lib_div::getUserObj($classRef, '');
101 }
102 }
103 }
104
105 /**
106 * Constructor for this class
107 *
108 * @return void
109 */
110 function t3lib_matchCondition() {
111 $this->__construct();
112 }
113
114 /**
115 * Matching TS condition
116 *
117 * @param string Line to match
118 * @return boolean True if matched
119 */
120 function match($condition_line) {
121 if ($this->matchAll) {
122 return true;
123 }
124 if (count($this->matchAlternative)) {
125 return in_array($condition_line, $this->matchAlternative);
126 }
127
128 // Getting the value from inside of the wrapping square brackets of the condition line:
129 $insideSqrBrackets = substr(trim($condition_line), 1, strlen($condition_line) - 2);
130 $insideSqrBrackets = preg_replace('/\]\s*OR\s*\[/i', ']||[', $insideSqrBrackets);
131 $insideSqrBrackets = preg_replace('/\]\s*AND\s*\[/i', ']&&[', $insideSqrBrackets);
132
133 // The "weak" operator "||" (OR) takes precedence: backwards compatible, [XYZ][ZYX] does still work as OR
134 $orParts = preg_split('/\]\s*(\|\|){0,1}\s*\[/',$insideSqrBrackets);
135
136 foreach ($orParts as $partString) {
137 $matches = false;
138
139 // Splits by the "&&" (AND) operator:
140 $andParts = preg_split('/\]\s*&&\s*\[/',$partString);
141 foreach ($andParts as $condStr) {
142 $matches = $this->evalConditionStr($condStr);
143 if ($matches===false) {
144 break; // only true AND true = true, so we have to break here
145 }
146 }
147
148 if ($matches===true) {
149 break; // true OR false = true, so we break if we have a positive result
150 }
151 }
152
153 return $matches;
154 }
155
156
157 /**
158 * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]"
159 *
160 * @param string The condition to match against its criterias.
161 * @return boolean Returns true or false based on the evaluation.
162 * @see t3lib_tsparser::parse()
163 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=292&cHash=c6c7d43d2f
164 */
165 function evalConditionStr($string) {
166 if (!is_array($this->altRootLine)) {
167 $this->altRootLine = array();
168 }
169 list($key, $value) = explode('=', $string, 2);
170 $key = trim($key);
171 if (stristr(',browser,version,system,useragent,', ",$key,")) {
172 $browserInfo = $this->browserInfo(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
173 }
174 $value = trim($value);
175 switch ($key) {
176 case 'browser':
177 $values = explode(',',$value);
178 while(list(,$test)=each($values)) {
179 if (strstr($browserInfo['browser'].$browserInfo['version'],trim($test))) {
180 return true;
181 }
182 }
183 break;
184 case 'version':
185 $values = explode(',',$value);
186 while(list(,$test)=each($values)) {
187 $test = trim($test);
188 if (strlen($test)) {
189 if (strcspn($test,'=<>')==0) {
190 switch(substr($test,0,1)) {
191 case '=':
192 if (doubleval(substr($test,1))==$browserInfo['version']) return true;
193 break;
194 case '<':
195 if (doubleval(substr($test,1))>$browserInfo['version']) return true;
196 break;
197 case '>':
198 if (doubleval(substr($test,1))<$browserInfo['version']) return true;
199 break;
200 }
201 } else {
202 if (strpos(' '.$browserInfo['version'],$test)==1) {return true;}
203 }
204 }
205 }
206 break;
207 case 'system':
208 $values = explode(',',$value);
209 while(list(,$test)=each($values)) {
210 $test = trim($test);
211 if (strlen($test)) {
212 if (strpos(' '.$browserInfo['system'],$test)==1) {return true;}
213 }
214 }
215 break;
216 case 'device':
217 $values = explode(',',$value);
218 if (!isset($this->deviceInfo)) {
219 $this->deviceInfo = $this->whichDevice(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
220 }
221 while(list(,$test)=each($values)) {
222 $test = trim($test);
223 if (strlen($test)) {
224 if ($this->deviceInfo==$test) {return true;}
225 }
226 }
227 break;
228 case 'useragent':
229 $test = trim($value);
230 if (strlen($test)) {
231 return $this->matchWild($browserInfo['useragent'],$test);
232 }
233 break;
234 case 'language':
235 $values = explode(',',$value);
236 while(list(,$test)=each($values)) {
237 $test = trim($test);
238 if (strlen($test)) {
239 if (preg_match('/^\*.+\*$/',$test)) {
240 $allLanguages = split('[,;]',t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE'));
241 if (in_array(substr($test,1,-1), $allLanguages)) {return true;}
242 } else {
243 if (t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE') == $test) {return true;}
244 }
245 }
246 }
247 break;
248 case 'IP':
249 if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $value)) {return true;}
250 break;
251 case 'hostname':
252 if (t3lib_div::cmpFQDN(t3lib_div::getIndpEnv('REMOTE_ADDR'), $value)) {return true;}
253 break;
254 // hour, minute, dayofweek, dayofmonth, month, year, julianday
255 case 'hour':
256 case 'minute':
257 case 'month':
258 case 'year':
259 case 'dayofweek':
260 case 'dayofmonth':
261 case 'dayofyear':
262 $theEvalTime = $GLOBALS['SIM_EXEC_TIME']; // In order to simulate time properly in templates.
263 switch($key) {
264 case 'hour': $theTestValue = date('H',$theEvalTime); break;
265 case 'minute': $theTestValue = date('i',$theEvalTime); break;
266 case 'month': $theTestValue = date('m',$theEvalTime); break;
267 case 'year': $theTestValue = date('Y',$theEvalTime); break;
268 case 'dayofweek': $theTestValue = date('w',$theEvalTime); break;
269 case 'dayofmonth': $theTestValue = date('d',$theEvalTime); break;
270 case 'dayofyear': $theTestValue = date('z',$theEvalTime); break;
271 }
272 $theTestValue = intval($theTestValue);
273 // comp
274 $values = explode(',',$value);
275 reset($values);
276 while(list(,$test)=each($values)) {
277 $test = trim($test);
278 if (t3lib_div::testInt($test)) {$test='='.$test;}
279 if (strlen($test)) {
280 if ($this->testNumber($test,$theTestValue)) {return true;}
281 }
282 }
283 break;
284 case 'usergroup':
285 if ($GLOBALS['TSFE']->gr_list!='0,-1') { // '0,-1' is the default usergroups when not logged in!
286 $values = explode(',',$value);
287 while(list(,$test)=each($values)) {
288 $test = trim($test);
289 if (strlen($test)) {
290 if ($test=='*' || t3lib_div::inList($GLOBALS['TSFE']->gr_list,$test)) {return true;}
291 }
292 }
293 }
294 break;
295 case 'loginUser':
296 if ($GLOBALS['TSFE']->loginUser) {
297 $values = explode(',',$value);
298 while(list(,$test)=each($values)) {
299 $test = trim($test);
300 if (strlen($test)) {
301 if ($test=='*' || !strcmp($GLOBALS['TSFE']->fe_user->user['uid'],$test)) {return true;}
302 }
303 }
304 }
305 break;
306 case 'globalVar':
307 $values = explode(',',$value);
308 while(list(,$test)=each($values)) {
309 $test = trim($test);
310 if (strlen($test)) {
311 $point = strcspn($test,'=<>');
312 $theVarName = substr($test,0,$point);
313 $nv = $this->getGP_ENV_TSFE(trim($theVarName));
314 $testValue = substr($test,$point);
315
316 if ($this->testNumber($testValue,$nv)) {return true;}
317 }
318 }
319 break;
320 case 'globalString':
321 $values = explode(',',$value);
322 while(list(,$test)=each($values)) {
323 $test = trim($test);
324 if (strlen($test)) {
325 $point = strcspn($test,'=');
326 $theVarName = substr($test,0,$point);
327 $nv = $this->getGP_ENV_TSFE(trim($theVarName));
328 $testValue = substr($test,$point+1);
329
330 if ($this->matchWild($nv,trim($testValue))) {return true;}
331 }
332 }
333 break;
334 case 'treeLevel':
335 $values = explode(',',$value);
336 $theRootLine = is_array($GLOBALS['TSFE']->tmpl->rootLine) ? $GLOBALS['TSFE']->tmpl->rootLine : $this->altRootLine;
337 $theRLC = count($theRootLine)-1;
338 while(list(,$test)=each($values)) {
339 $test = trim($test);
340 if ($test==$theRLC) { return true; }
341 }
342 break;
343 case 'PIDupinRootline':
344 case 'PIDinRootline':
345 $values = explode(',',$value);
346 if (($key=='PIDinRootline') || (!in_array($GLOBALS['TSFE']->id,$values))) {
347 $theRootLine = is_array($GLOBALS['TSFE']->tmpl->rootLine) ? $GLOBALS['TSFE']->tmpl->rootLine : $this->altRootLine;
348 reset($values);
349 while(list(,$test)=each($values)) {
350 $test = trim($test);
351 reset($theRootLine);
352 while(list($rl_key,$rl_dat)=each($theRootLine)) {
353 if ($rl_dat['uid']==$test) { return true; }
354 }
355 }
356 }
357 break;
358 case 'compatVersion':
359 { return t3lib_div::compat_version($value); }
360 break;
361 case 'userFunc':
362 $values = split('\(|\)',$value);
363 $funcName=trim($values[0]);
364 $funcValue = t3lib_div::trimExplode(',',$values[1]);
365 $pre = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['userFuncClassPrefix'];
366 if ($pre &&
367 !t3lib_div::isFirstPartOfStr(trim($funcName),$pre) &&
368 !t3lib_div::isFirstPartOfStr(trim($funcName),'tx_')
369 ) {
370 if (is_object($GLOBALS['TT'])) $GLOBALS['TT']->setTSlogMessage('Match condition: Function "'.$funcName.'" was not prepended with "'.$pre.'"',3);
371 return false;
372 }
373 if (function_exists($funcName) && call_user_func($funcName, $funcValue[0])) {
374 return true;
375 }
376 break;
377 }
378
379
380 return false;
381 }
382
383 /**
384 * Will evaluate a $value based on an operator: "<", ">" or "=" (default)
385 *
386 * @param string The value to compare with on the form [operator][number]. Eg. "< 123"
387 * @param integer The number
388 * @return boolean If $value is "50" and $test is "< 123" then it will return true.
389 */
390 function testNumber($test,$value) {
391 $test = trim($test);
392 switch(substr($test,0,1)) {
393 case '<':
394 if (doubleval(substr($test,1))>$value) return true;
395 break;
396 case '>':
397 if (doubleval(substr($test,1))<$value) return true;
398 break;
399 default:
400 if (trim(substr($test,1))==$value) return true;
401 break;
402 }
403
404 return false;
405 }
406
407 /**
408 * Matching two strings against each other, supporting a "*" wildcard or (if wrapped in "/") PCRE regular expressions
409 *
410 * @param string The string in which to find $needle.
411 * @param string The string to find in $haystack
412 * @return boolean Returns true if $needle matches or is found in (according to wildcards) in $haystack. Eg. if $haystack is "Netscape 6.5" and $needle is "Net*" or "Net*ape" then it returns true.
413 */
414 function matchWild($haystack, $needle) {
415 $result = false;
416
417 if ($needle) {
418 if (preg_match('/^\/.+\/$/', $needle)) {
419 // Regular expression, only "//" is allowed as delimiter
420 $regex = $needle;
421 } else {
422 $needle = str_replace(array('*', '?'), array('###MANY###', '###ONE###'), $needle);
423 $regex = '/^' . preg_quote($needle, '/') . '$/';
424 // Replace the marker with .* to match anything (wildcard)
425 $regex = str_replace(array('###MANY###', '###ONE###'), array('.*' , '.'), $regex);
426 }
427
428 $result = (boolean)preg_match($regex, (string)$haystack);
429 }
430
431 return $result;
432 }
433
434 /**
435 * Returns a code for a browsing device based on the input useragent string
436 *
437 * @param string User agent string from browser, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
438 * @return string A code. See link.
439 * @access private
440 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=296&cHash=a8ae66c7d6
441 */
442 function whichDevice($useragent) {
443 foreach($this->hookObjectsArr as $hookObj) {
444 if (method_exists($hookObj, 'whichDevice')) {
445 $result = $hookObj->whichDevice($useragent);
446 if (strlen($result)) {
447 return $result;
448 }
449 }
450 }
451
452 // deprecated, see above
453 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'])) {
454 foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'] as $_classRef) {
455 $_procObj = &t3lib_div::getUserObj($_classRef);
456 return $_procObj->whichDevice_ext($useragent);
457 }
458 }
459 //
460
461 $agent=strtolower(trim($useragent));
462 // pda
463 if( strstr($agent, 'avantgo')) {
464 return 'pda';
465 }
466
467 // wap
468 $browser=substr($agent,0,4);
469 $wapviwer=substr(stristr($agent,'wap'),0,3);
470 if( $wapviwer=='wap' ||
471 $browser=='noki' ||
472 $browser== 'eric' ||
473 $browser== 'r380' ||
474 $browser== 'up.b' ||
475 $browser== 'winw' ||
476 $browser== 'wapa') {
477 return 'wap';
478 }
479
480 // grabber
481 if( strstr($agent, 'g.r.a.b.') ||
482 strstr($agent, 'utilmind httpget') ||
483 strstr($agent, 'webcapture') ||
484 strstr($agent, 'teleport') ||
485 strstr($agent, 'webcopier')) {
486 return 'grabber';
487 }
488
489 // robots
490 if( strstr($agent, 'crawler') ||
491 strstr($agent, 'spider') ||
492 strstr($agent, 'googlebot') ||
493 strstr($agent, 'searchbot') ||
494 strstr($agent, 'infoseek') ||
495 strstr($agent, 'altavista') ||
496 strstr($agent, 'diibot')) {
497 return 'robot';
498 }
499
500 }
501
502 /**
503 * Generates an array with abstracted browser information
504 * This method is used in the function match() in this class
505 *
506 * @param string The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
507 * @return array Contains keys "browser", "version", "system"
508 * @access private
509 * @see match()
510 */
511 function browserInfo($useragent) {
512 foreach($this->hookObjectsArr as $hookObj) {
513 if (method_exists($hookObj, 'browserInfo')) {
514 $result = $hookObj->browserInfo($useragent);
515 if (strlen($result)) {
516 return $result;
517 }
518 }
519 }
520
521 $useragent = trim($useragent);
522 $browserInfo=Array();
523 $browserInfo['useragent']=$useragent;
524 if ($useragent) {
525 // browser
526 if (strstr($useragent,'MSIE')) {
527 $browserInfo['browser']='msie';
528 } elseif(strstr($useragent,'Konqueror')) {
529 $browserInfo['browser']='konqueror';
530 } elseif(strstr($useragent,'Opera')) {
531 $browserInfo['browser']='opera';
532 } elseif(strstr($useragent,'Lynx')) {
533 $browserInfo['browser']='lynx';
534 } elseif(strstr($useragent,'PHP')) {
535 $browserInfo['browser']='php';
536 } elseif(strstr($useragent,'AvantGo')) {
537 $browserInfo['browser']='avantgo';
538 } elseif(strstr($useragent,'WebCapture')) {
539 $browserInfo['browser']='acrobat';
540 } elseif(strstr($useragent,'IBrowse')) {
541 $browserInfo['browser']='ibrowse';
542 } elseif(strstr($useragent,'Teleport')) {
543 $browserInfo['browser']='teleport';
544 } elseif(strstr($useragent,'Mozilla')) {
545 $browserInfo['browser']='netscape';
546 } else {
547 $browserInfo['browser']='unknown';
548 }
549 // version
550 switch($browserInfo['browser']) {
551 case 'netscape':
552 $browserInfo['version'] = $this->browserInfo_version(substr($useragent,8));
553 if (strstr($useragent,'Netscape6')) {$browserInfo['version']=6;}
554 break;
555 case 'msie':
556 $tmp = strstr($useragent,'MSIE');
557 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
558 break;
559 case 'opera':
560 $tmp = strstr($useragent,'Opera');
561 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
562 break;
563 case 'lynx':
564 $tmp = strstr($useragent,'Lynx/');
565 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
566 break;
567 case 'php':
568 $tmp = strstr($useragent,'PHP/');
569 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
570 break;
571 case 'avantgo':
572 $tmp = strstr($useragent,'AvantGo');
573 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,7));
574 break;
575 case 'acrobat':
576 $tmp = strstr($useragent,'WebCapture');
577 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
578 break;
579 case 'ibrowse':
580 $tmp = strstr($useragent,'IBrowse/');
581 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,8));
582 break;
583 case 'konqueror':
584 $tmp = strstr($useragent,'Konqueror/');
585 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
586 break;
587 }
588 // system
589 $browserInfo['system']='';
590 if (strstr($useragent,'Win')) {
591 // windows
592 if (strstr($useragent,'Win98') || strstr($useragent,'Windows 98')) {
593 $browserInfo['system']='win98';
594 } elseif (strstr($useragent,'Win95') || strstr($useragent,'Windows 95')) {
595 $browserInfo['system']='win95';
596 } elseif (strstr($useragent,'WinNT') || strstr($useragent,'Windows NT')) {
597 $browserInfo['system']='winNT';
598 } elseif (strstr($useragent,'Win16') || strstr($useragent,'Windows 311')) {
599 $browserInfo['system']='win311';
600 }
601 } elseif (strstr($useragent,'Mac')) {
602 $browserInfo['system']='mac';
603 // unixes
604 } elseif (strstr($useragent,'Linux')) {
605 $browserInfo['system']='linux';
606 } elseif (strstr($useragent,'SGI') && strstr($useragent,' IRIX ')) {
607 $browserInfo['system']='unix_sgi';
608 } elseif (strstr($useragent,' SunOS ')) {
609 $browserInfo['system']='unix_sun';
610 } elseif (strstr($useragent,' HP-UX ')) {
611 $browserInfo['system']='unix_hp';
612 }
613 }
614
615 return $browserInfo;
616 }
617
618 /**
619 * Returns the version of a browser; Basically getting doubleval() of the input string, stripping of any non-numeric values in the beginning of the string first.
620 *
621 * @param string A string with version number, eg. "/7.32 blablabla"
622 * @return double Returns double value, eg. "7.32"
623 */
624 function browserInfo_version($tmp) {
625 return doubleval(preg_replace('/^[^0-9]*/','',$tmp));
626 }
627
628 /**
629 * Return global variable where the input string $var defines array keys separated by "|"
630 * Example: $var = "HTTP_SERVER_VARS | something" will return the value $GLOBALS['HTTP_SERVER_VARS']['something'] value
631 *
632 * @param string Global var key, eg. "HTTP_GET_VAR" or "HTTP_GET_VARS|id" to get the GET parameter "id" back.
633 * @param array Alternative array than $GLOBAL to get variables from.
634 * @return mixed Whatever value. If none, then blank string.
635 * @access private
636 */
637 function getGlobal($var, $source=NULL) {
638 $vars = explode('|',$var);
639 $c = count($vars);
640 $k = trim($vars[0]);
641 $theVar = isset($source) ? $source[$k] : $GLOBALS[$k];
642
643 for ($a=1;$a<$c;$a++) {
644 if (!isset($theVar)) { break; }
645
646 $key = trim($vars[$a]);
647 if (is_object($theVar)) {
648 $theVar = $theVar->$key;
649 } elseif (is_array($theVar)) {
650 $theVar = $theVar[$key];
651 } else {
652 return '';
653 }
654 }
655
656 if (!is_array($theVar) && !is_object($theVar)) {
657 return $theVar;
658 } else {
659 return '';
660 }
661 }
662
663 /**
664 * Returns GP / ENV / TSFE vars
665 *
666 * @param string Identifier
667 * @return mixed The value of the variable pointed to.
668 * @access private
669 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=311&cHash=487cbd5cdf
670 */
671 function getGP_ENV_TSFE($var) {
672 $vars = explode(':',$var,2);
673 if (count($vars)==1) {
674 $val = $this->getGlobal($var);
675 } else {
676 $splitAgain=explode('|',$vars[1],2);
677 $k=trim($splitAgain[0]);
678 if ($k) {
679 switch((string)trim($vars[0])) {
680 case 'GP':
681 $val = t3lib_div::_GP($k);
682 break;
683 case 'TSFE':
684 $val = $this->getGlobal('TSFE|'.$vars[1]);
685 $splitAgain=0; // getGlobal resolves all parts of the key, so no further splitting is needed
686 break;
687 case 'ENV':
688 $val = getenv($k);
689 break;
690 case 'IENV':
691 $val = t3lib_div::getIndpEnv($k);
692 break;
693 case 'LIT':
694 { return trim($vars[1]); } // return litteral value...
695 break;
696 }
697 // If array:
698 if (count($splitAgain)>1) {
699 if (is_array($val) && trim($splitAgain[1])) {
700 $val=$this->getGlobal($splitAgain[1],$val);
701 } else {
702 $val='';
703 }
704 }
705 }
706 }
707 return $val;
708 }
709 }
710
711
712 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php']) {
713 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php']);
714 }
715 ?>