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