Updating version number to 4.2-dev after release of 4.2.0beta2a
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_matchcondition.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2006 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 if ($needle && $haystack) {
416 if (preg_match('/^\/.+\/$/', $needle)) { // Regular expression, only "//" is allowed as delimiter
417 $regex = $needle;
418 } else {
419 $needle = str_replace(array('*','?'), array('###MANY###','###ONE###'), $needle);
420 $regex = '/^'.preg_quote($needle,'/').'$/';
421 $regex = str_replace(array('###MANY###','###ONE###'), array('.*','.'), $regex); // Replace the marker with .* to match anything (wildcard)
422 }
423
424 if (preg_match($regex, $haystack)) return true;
425 }
426
427 return false;
428 }
429
430 /**
431 * Returns a code for a browsing device based on the input useragent string
432 *
433 * @param string User agent string from browser, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
434 * @return string A code. See link.
435 * @access private
436 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=296&cHash=a8ae66c7d6
437 */
438 function whichDevice($useragent) {
439 foreach($this->hookObjectsArr as $hookObj) {
440 if (method_exists($hookObj, 'whichDevice')) {
441 $result = $hookObj->whichDevice($useragent);
442 if (strlen($result)) {
443 return $result;
444 }
445 }
446 }
447
448 // deprecated, see above
449 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'])) {
450 foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'] as $_classRef) {
451 $_procObj = &t3lib_div::getUserObj($_classRef);
452 return $_procObj->whichDevice_ext($useragent);
453 }
454 }
455 //
456
457 $agent=strtolower(trim($useragent));
458 // pda
459 if( strstr($agent, 'avantgo')) {
460 return 'pda';
461 }
462
463 // wap
464 $browser=substr($agent,0,4);
465 $wapviwer=substr(stristr($agent,'wap'),0,3);
466 if( $wapviwer=='wap' ||
467 $browser=='noki' ||
468 $browser== 'eric' ||
469 $browser== 'r380' ||
470 $browser== 'up.b' ||
471 $browser== 'winw' ||
472 $browser== 'wapa') {
473 return 'wap';
474 }
475
476 // grabber
477 if( strstr($agent, 'g.r.a.b.') ||
478 strstr($agent, 'utilmind httpget') ||
479 strstr($agent, 'webcapture') ||
480 strstr($agent, 'teleport') ||
481 strstr($agent, 'webcopier')) {
482 return 'grabber';
483 }
484
485 // robots
486 if( strstr($agent, 'crawler') ||
487 strstr($agent, 'spider') ||
488 strstr($agent, 'googlebot') ||
489 strstr($agent, 'searchbot') ||
490 strstr($agent, 'infoseek') ||
491 strstr($agent, 'altavista') ||
492 strstr($agent, 'diibot')) {
493 return 'robot';
494 }
495
496 }
497
498 /**
499 * Generates an array with abstracted browser information
500 * This method is used in the function match() in this class
501 *
502 * @param string The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
503 * @return array Contains keys "browser", "version", "system"
504 * @access private
505 * @see match()
506 */
507 function browserInfo($useragent) {
508 foreach($this->hookObjectsArr as $hookObj) {
509 if (method_exists($hookObj, 'browserInfo')) {
510 $result = $hookObj->browserInfo($useragent);
511 if (strlen($result)) {
512 return $result;
513 }
514 }
515 }
516
517 $useragent = trim($useragent);
518 $browserInfo=Array();
519 $browserInfo['useragent']=$useragent;
520 if ($useragent) {
521 // browser
522 if (strstr($useragent,'MSIE')) {
523 $browserInfo['browser']='msie';
524 } elseif(strstr($useragent,'Konqueror')) {
525 $browserInfo['browser']='konqueror';
526 } elseif(strstr($useragent,'Opera')) {
527 $browserInfo['browser']='opera';
528 } elseif(strstr($useragent,'Lynx')) {
529 $browserInfo['browser']='lynx';
530 } elseif(strstr($useragent,'PHP')) {
531 $browserInfo['browser']='php';
532 } elseif(strstr($useragent,'AvantGo')) {
533 $browserInfo['browser']='avantgo';
534 } elseif(strstr($useragent,'WebCapture')) {
535 $browserInfo['browser']='acrobat';
536 } elseif(strstr($useragent,'IBrowse')) {
537 $browserInfo['browser']='ibrowse';
538 } elseif(strstr($useragent,'Teleport')) {
539 $browserInfo['browser']='teleport';
540 } elseif(strstr($useragent,'Mozilla')) {
541 $browserInfo['browser']='netscape';
542 } else {
543 $browserInfo['browser']='unknown';
544 }
545 // version
546 switch($browserInfo['browser']) {
547 case 'netscape':
548 $browserInfo['version'] = $this->browserInfo_version(substr($useragent,8));
549 if (strstr($useragent,'Netscape6')) {$browserInfo['version']=6;}
550 break;
551 case 'msie':
552 $tmp = strstr($useragent,'MSIE');
553 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
554 break;
555 case 'opera':
556 $tmp = strstr($useragent,'Opera');
557 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
558 break;
559 case 'lynx':
560 $tmp = strstr($useragent,'Lynx/');
561 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
562 break;
563 case 'php':
564 $tmp = strstr($useragent,'PHP/');
565 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
566 break;
567 case 'avantgo':
568 $tmp = strstr($useragent,'AvantGo');
569 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,7));
570 break;
571 case 'acrobat':
572 $tmp = strstr($useragent,'WebCapture');
573 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
574 break;
575 case 'ibrowse':
576 $tmp = strstr($useragent,'IBrowse/');
577 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,8));
578 break;
579 case 'konqueror':
580 $tmp = strstr($useragent,'Konqueror/');
581 $browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
582 break;
583 }
584 // system
585 $browserInfo['system']='';
586 if (strstr($useragent,'Win')) {
587 // windows
588 if (strstr($useragent,'Win98') || strstr($useragent,'Windows 98')) {
589 $browserInfo['system']='win98';
590 } elseif (strstr($useragent,'Win95') || strstr($useragent,'Windows 95')) {
591 $browserInfo['system']='win95';
592 } elseif (strstr($useragent,'WinNT') || strstr($useragent,'Windows NT')) {
593 $browserInfo['system']='winNT';
594 } elseif (strstr($useragent,'Win16') || strstr($useragent,'Windows 311')) {
595 $browserInfo['system']='win311';
596 }
597 } elseif (strstr($useragent,'Mac')) {
598 $browserInfo['system']='mac';
599 // unixes
600 } elseif (strstr($useragent,'Linux')) {
601 $browserInfo['system']='linux';
602 } elseif (strstr($useragent,'SGI') && strstr($useragent,' IRIX ')) {
603 $browserInfo['system']='unix_sgi';
604 } elseif (strstr($useragent,' SunOS ')) {
605 $browserInfo['system']='unix_sun';
606 } elseif (strstr($useragent,' HP-UX ')) {
607 $browserInfo['system']='unix_hp';
608 }
609 }
610
611 return $browserInfo;
612 }
613
614 /**
615 * 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.
616 *
617 * @param string A string with version number, eg. "/7.32 blablabla"
618 * @return double Returns double value, eg. "7.32"
619 */
620 function browserInfo_version($tmp) {
621 return doubleval(preg_replace('/^[^0-9]*/','',$tmp));
622 }
623
624 /**
625 * Return global variable where the input string $var defines array keys separated by "|"
626 * Example: $var = "HTTP_SERVER_VARS | something" will return the value $GLOBALS['HTTP_SERVER_VARS']['something'] value
627 *
628 * @param string Global var key, eg. "HTTP_GET_VAR" or "HTTP_GET_VARS|id" to get the GET parameter "id" back.
629 * @param array Alternative array than $GLOBAL to get variables from.
630 * @return mixed Whatever value. If none, then blank string.
631 * @access private
632 */
633 function getGlobal($var, $source=NULL) {
634 $vars = explode('|',$var);
635 $c = count($vars);
636 $k = trim($vars[0]);
637 $theVar = isset($source) ? $source[$k] : $GLOBALS[$k];
638
639 for ($a=1;$a<$c;$a++) {
640 if (!isset($theVar)) { break; }
641
642 $key = trim($vars[$a]);
643 if (is_object($theVar)) {
644 $theVar = $theVar->$key;
645 } elseif (is_array($theVar)) {
646 $theVar = $theVar[$key];
647 } else {
648 return '';
649 }
650 }
651
652 if (!is_array($theVar) && !is_object($theVar)) {
653 return $theVar;
654 } else {
655 return '';
656 }
657 }
658
659 /**
660 * Returns GP / ENV / TSFE vars
661 *
662 * @param string Identifier
663 * @return mixed The value of the variable pointed to.
664 * @access private
665 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=311&cHash=487cbd5cdf
666 */
667 function getGP_ENV_TSFE($var) {
668 $vars = explode(':',$var,2);
669 if (count($vars)==1) {
670 $val = $this->getGlobal($var);
671 } else {
672 $splitAgain=explode('|',$vars[1],2);
673 $k=trim($splitAgain[0]);
674 if ($k) {
675 switch((string)trim($vars[0])) {
676 case 'GP':
677 $val = t3lib_div::_GP($k);
678 break;
679 case 'TSFE':
680 $val = $this->getGlobal('TSFE|'.$vars[1]);
681 $splitAgain=0; // getGlobal resolves all parts of the key, so no further splitting is needed
682 break;
683 case 'ENV':
684 $val = getenv($k);
685 break;
686 case 'IENV':
687 $val = t3lib_div::getIndpEnv($k);
688 break;
689 case 'LIT':
690 { return trim($vars[1]); } // return litteral value...
691 break;
692 }
693 // If array:
694 if (count($splitAgain)>1) {
695 if (is_array($val) && trim($splitAgain[1])) {
696 $val=$this->getGlobal($splitAgain[1],$val);
697 } else {
698 $val='';
699 }
700 }
701 }
702 }
703 return $val;
704 }
705 }
706
707
708 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php']) {
709 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php']);
710 }
711 ?>