File: class.t3lib_matchcondition.php

package info (click to toggle)
typo3-src 4.0.2%2Bdebian-3
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 29,856 kB
  • ctags: 33,382
  • sloc: php: 134,523; xml: 6,976; sql: 1,084; sh: 168; makefile: 45
file content (707 lines) | stat: -rw-r--r-- 22,273 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
<?php
/***************************************************************
*  Copyright notice
*
*  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Contains class for Matching TypoScript conditions
 *
 * $Id: class.t3lib_matchcondition.php 1674 2006-08-07 10:03:43Z stfl_wolfgang $
 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
 *
 * @author	Kasper Skaarhoj <kasperYYYY@typo3.com>
 */
/**
 * [CLASS/FUNCTION INDEX of SCRIPT]
 *
 *
 *
 *   80: class t3lib_matchCondition
 *   87:     function __construct()
 *  105:     function t3lib_matchCondition()
 *  115:     function match($condition_line)
 *  160:     function evalConditionStr($string)
 *  381:     function testNumber($test,$value)
 *  405:     function matchWild($haystack,$needle)
 *  429:     function whichDevice($useragent)
 *  498:     function browserInfo($useragent)
 *  611:     function browserInfo_version($tmp)
 *  624:     function getGlobal($var, $source=NULL)
 *  658:     function getGP_ENV_TSFE($var)
 *
 * TOTAL FUNCTIONS: 11
 * (This index is automatically created/updated by the extension "extdeveval")
 *
 */












/**
 * Matching TypoScript conditions
 *
 * Used with the TypoScript parser.
 * Matches browserinfo, IPnumbers for use with templates
 *
 * @author	Kasper Skaarhoj <kasperYYYY@typo3.com>
 * @package TYPO3
 * @subpackage t3lib
 * @see t3lib_TStemplate::matching(), t3lib_TStemplate::generateConfig()
 */
class t3lib_matchCondition {
	var $matchAlternative=array();		// If this array has elements, the matching returns true if a whole "matchline" is found in the array!
	var $matchAll=0;					// If set all is matched!

	var $altRootLine=array();
	var $hookObjectsArr = array();

	/**
	 * Constructor for this class
	 *
	 * @return	void
	 */
	function __construct()	{
		global $TYPO3_CONF_VARS;

		// Usage (ext_localconf.php):
		// $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'][] =
		// 'EXT:my_ext/class.browserinfo.php:MyBrowserInfoClass';
		if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'])) {
			foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'] as $classRef) {
				$this->hookObjectsArr[] = &t3lib_div::getUserObj($classRef, '');
			}
		}
	}

	/**
	 * Constructor for this class
	 *
	 * @return	void
	 */
	function t3lib_matchCondition() {
		$this->__construct();
	}

	/**
	 * Matching TS condition
	 *
	 * @param	string		Line to match
	 * @return	boolean		True if matched
	 */
	function match($condition_line) {
		if ($this->matchAll) {
			return true;
		}
		if (count($this->matchAlternative))	{
			return in_array($condition_line, $this->matchAlternative);
		}

			// Getting the value from inside of the wrapping square brackets of the condition line:
		$insideSqrBrackets = substr(trim($condition_line), 1, strlen($condition_line) - 2);
		$insideSqrBrackets = preg_replace('/\]\s*OR\s*\[/i', ']||[', $insideSqrBrackets);
		$insideSqrBrackets = preg_replace('/\]\s*AND\s*\[/i', ']&&[', $insideSqrBrackets);

			// The "weak" operator "||" (OR) takes precedence: backwards compatible, [XYZ][ZYX] does still work as OR
		$orParts = preg_split('/\]\s*(\|\|){0,1}\s*\[/',$insideSqrBrackets);

		foreach ($orParts as $partString)	{
			$matches = false;

				// Splits by the "&&" (AND) operator:
			$andParts = preg_split('/\]\s*&&\s*\[/',$partString);
			foreach ($andParts as $condStr)	{
				$matches = $this->evalConditionStr($condStr);
				if ($matches===false)	{
					break;		// only true AND true = true, so we have to break here
				}
			}

			if ($matches===true)	{
				break;		// true OR false = true, so we break if we have a positive result
			}
		}

		return $matches;
	}


	/**
	 * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]"
	 *
	 * @param	string		The condition to match against its criterias.
	 * @return	boolean		Returns true or false based on the evaluation.
	 * @see t3lib_tsparser::parse()
	 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=292&cHash=c6c7d43d2f
	 */
	function evalConditionStr($string)	{
		if (!is_array($this->altRootLine)) {
			$this->altRootLine = array();
		}
		list($key, $value) = explode('=', $string, 2);
		$key = trim($key);
		if (stristr(',browser,version,system,useragent,', ",$key,")) {
			$browserInfo = $this->browserInfo(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
		}
		$value = trim($value);
		switch ($key) {
			case 'browser':
				$values = explode(',',$value);
				while(list(,$test)=each($values))	{
					if (strstr($browserInfo['browser'].$browserInfo['version'],trim($test)))	{
						return true;
					}
				}
			break;
			case 'version':
				$values = explode(',',$value);
				while(list(,$test)=each($values))	{
					$test = trim($test);
					if (strlen($test)) {
						if (strcspn($test,'=<>')==0)	{
							switch(substr($test,0,1))	{
								case '=':
									if (doubleval(substr($test,1))==$browserInfo['version']) return true;
								break;
								case '<':
									if (doubleval(substr($test,1))>$browserInfo['version'])	return true;
								break;
								case '>':
									if (doubleval(substr($test,1))<$browserInfo['version'])	return true;
								break;
							}
						} else {
							if (strpos(' '.$browserInfo['version'],$test)==1)	{return true;}
						}
					}
				}
			break;
			case 'system':
				$values = explode(',',$value);
				while(list(,$test)=each($values))	{
					$test = trim($test);
					if (strlen($test)) {
						if (strpos(' '.$browserInfo['system'],$test)==1)	{return true;}
					}
				}
			break;
			case 'device':
				$values = explode(',',$value);
				if (!isset($this->deviceInfo))	{
					$this->deviceInfo = $this->whichDevice(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
				}
				while(list(,$test)=each($values))	{
					$test = trim($test);
					if (strlen($test)) {
						if ($this->deviceInfo==$test)	{return true;}
					}
				}
			break;
			case 'useragent':
				$test = trim($value);
				if (strlen($test)) {
					return $this->matchWild($browserInfo['useragent'],$test);
				}
			break;
			case 'language':
				$values = explode(',',$value);
				while(list(,$test)=each($values))	{
					$test = trim($test);
					if (strlen($test)) {
						if (preg_match('/^\*.+\*$/',$test))	{
							$allLanguages = split('[,;]',t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE'));
							if (in_array(substr($test,1,-1), $allLanguages))	{return true;}
						} else {
							if (t3lib_div::getIndpEnv('HTTP_ACCEPT_LANGUAGE') == $test)	{return true;}
						}
					}
				}
			break;
			case 'IP':
				if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $value))	{return true;}
			break;
			case 'hostname':
				if (t3lib_div::cmpFQDN(t3lib_div::getIndpEnv('REMOTE_ADDR'), $value))  {return true;}
			break;
				// hour, minute, dayofweek, dayofmonth, month
			case 'hour':
			case 'minute':
			case 'dayofweek':
			case 'dayofmonth':
			case 'month':
				$theEvalTime = $GLOBALS['SIM_EXEC_TIME'];	// In order to simulate time properly in templates.
				switch($key) {
					case 'hour':		$theTestValue = date('H',$theEvalTime);	break;
					case 'minute':		$theTestValue = date('i',$theEvalTime);	break;
					case 'dayofweek':	$theTestValue = date('w',$theEvalTime);	break;
					case 'dayofmonth':	$theTestValue = date('d',$theEvalTime);	break;
					case 'month':		$theTestValue = date('m',$theEvalTime);	break;
				}
				$theTestValue = intval($theTestValue);
					// comp
				$values = explode(',',$value);
				reset($values);
				while(list(,$test)=each($values))	{
					$test = trim($test);
					if (t3lib_div::testInt($test))	{$test='='.$test;}
					if (strlen($test)) {
						if ($this->testNumber($test,$theTestValue)) {return true;}
					}
				}
			break;
			case 'usergroup':
				if ($GLOBALS['TSFE']->gr_list!='0,-1')	{		// '0,-1' is the default usergroups when not logged in!
					$values = explode(',',$value);
					while(list(,$test)=each($values))	{
						$test = trim($test);
						if (strlen($test)) {
							if ($test=='*' || t3lib_div::inList($GLOBALS['TSFE']->gr_list,$test))	{return true;}
						}
					}
				}
			break;
			case 'loginUser':
				if ($GLOBALS['TSFE']->loginUser)	{
					$values = explode(',',$value);
					while(list(,$test)=each($values))	{
						$test = trim($test);
						if (strlen($test)) {
							if ($test=='*' || !strcmp($GLOBALS['TSFE']->fe_user->user['uid'],$test))	{return true;}
						}
					}
				}
			break;
			case 'globalVar':
				$values = explode(',',$value);
				while(list(,$test)=each($values))	{
					$test = trim($test);
					if (strlen($test)) {
						$point = strcspn($test,'=<>');
						$theVarName = substr($test,0,$point);
						$nv = $this->getGP_ENV_TSFE(trim($theVarName));
						$testValue = substr($test,$point);

						if ($this->testNumber($testValue,$nv)) {return true;}
					}
				}
			break;
			case 'globalString':
				$values = explode(',',$value);
				while(list(,$test)=each($values))	{
					$test = trim($test);
					if (strlen($test)) {
						$point = strcspn($test,'=');
						$theVarName = substr($test,0,$point);
						$nv = $this->getGP_ENV_TSFE(trim($theVarName));
						$testValue = substr($test,$point+1);

						if ($this->matchWild($nv,trim($testValue))) {return true;}
					}
				}
			break;
			case 'treeLevel':
				$values = explode(',',$value);
				$theRootLine = is_array($GLOBALS['TSFE']->tmpl->rootLine) ? $GLOBALS['TSFE']->tmpl->rootLine : $this->altRootLine;
				$theRLC = count($theRootLine)-1;
				while(list(,$test)=each($values))	{
					$test = trim($test);
					if ($test==$theRLC)	{	return true;	}
				}
			break;
			case 'PIDupinRootline':
			case 'PIDinRootline':
				$values = explode(',',$value);
				if (($key=='PIDinRootline') || (!in_array($GLOBALS['TSFE']->id,$values))) {
					$theRootLine = is_array($GLOBALS['TSFE']->tmpl->rootLine) ? $GLOBALS['TSFE']->tmpl->rootLine : $this->altRootLine;
					reset($values);
					while(list(,$test)=each($values))	{
						$test = trim($test);
						reset($theRootLine);
						while(list($rl_key,$rl_dat)=each($theRootLine))	{
							if ($rl_dat['uid']==$test)	{	return true;	}
						}
					}
				}
			break;
			case 'compatVersion':
				{ return t3lib_div::compat_version($value); }
			break;
			case 'userFunc':
				$values = split('\(|\)',$value);
				$funcName=trim($values[0]);
				$funcValue = t3lib_div::trimExplode(',',$values[1]);
				$pre = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['userFuncClassPrefix'];
				if ($pre &&
					!t3lib_div::isFirstPartOfStr(trim($funcName),$pre) &&
					!t3lib_div::isFirstPartOfStr(trim($funcName),'tx_')
				)	{
					if (is_object($GLOBALS['TT']))	$GLOBALS['TT']->setTSlogMessage('Match condition: Function "'.$funcName.'" was not prepended with "'.$pre.'"',3);
					return false;
				}
				if (function_exists($funcName) && call_user_func($funcName, $funcValue[0]))	{
					return true;
				}
			break;
		}


		return false;
	}

	/**
	 * Will evaluate a $value based on an operator: "<", ">" or "=" (default)
	 *
	 * @param	string		The value to compare with on the form [operator][number]. Eg. "< 123"
	 * @param	integer		The number
	 * @return	boolean		If $value is "50" and $test is "< 123" then it will return true.
	 */
	function testNumber($test,$value) {
		$test = trim($test);
		switch(substr($test,0,1))	{
			case '<':
				if (doubleval(substr($test,1))>$value)	return true;
			break;
			case '>':
				if (doubleval(substr($test,1))<$value)	return true;
			break;
			default:
				if (trim(substr($test,1))==$value)	return true;
			break;
		}

		return false;
	}

	/**
	 * Matching two strings against each other, supporting a "*" wildcard or (if wrapped in "/") PCRE regular expressions
	 *
	 * @param	string		The string in which to find $needle.
	 * @param	string		The string to find in $haystack
	 * @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.
	 */
	function matchWild($haystack,$needle)	{
		if ($needle && $haystack)	{
			if (preg_match('/^\/.+\/$/', $needle))	{	// Looks like a regular expression
				$regex = $needle;
			} else {
				$needle = str_replace(array('*','?'), array('###MANY###','###ONE###'), $needle);
				$regex = '/^'.preg_quote($needle,'/').'$/';
				$regex = str_replace(array('###MANY###','###ONE###'), array('.*','.'), $regex);	// Replace the marker with .* to match anything (wildcard)
			}

			if (preg_match($regex, $haystack)) return true;
		}

		return false;
	}

	/**
	 * Returns a code for a browsing device based on the input useragent string
	 *
	 * @param	string		User agent string from browser, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
	 * @return	string		A code. See link.
	 * @access private
	 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=296&cHash=a8ae66c7d6
	 */
	function whichDevice($useragent)	{
		foreach($this->hookObjectsArr as $hookObj)	{
			if (method_exists($hookObj, 'whichDevice')) {
				$result = $hookObj->whichDevice($useragent);
				if (strlen($result)) {
					return $result;
				}
			}
		}

		// deprecated, see above
		if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class']))	{
			foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'] as $_classRef)	{
				$_procObj = &t3lib_div::getUserObj($_classRef);
				return $_procObj->whichDevice_ext($useragent);
			}
		}
		//

		$agent=strtolower(trim($useragent));
			// pda
		if(	strstr($agent, 'avantgo'))	{
			return 'pda';
		}

			// wap
		$browser=substr($agent,0,4);
		$wapviwer=substr(stristr($agent,'wap'),0,3);
		if(	$wapviwer=='wap' ||
			$browser=='noki' ||
			$browser== 'eric' ||
			$browser== 'r380' ||
			$browser== 'up.b' ||
			$browser== 'winw' ||
			$browser== 'wapa')	{
				return 'wap';
		}

			// grabber
		if(	strstr($agent, 'g.r.a.b.') ||
			strstr($agent, 'utilmind httpget') ||
			strstr($agent, 'webcapture') ||
			strstr($agent, 'teleport') ||
			strstr($agent, 'webcopier'))	{
			return 'grabber';
		}

			// robots
		if(	strstr($agent, 'crawler') ||
			strstr($agent, 'spider') ||
			strstr($agent, 'googlebot') ||
			strstr($agent, 'searchbot') ||
			strstr($agent, 'infoseek') ||
			strstr($agent, 'altavista') ||
			strstr($agent, 'diibot'))	{
			return 'robot';
		}

	}

	/**
	 * Generates an array with abstracted browser information
	 * This method is used in the function match() in this class
	 *
	 * @param	string		The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
	 * @return	array		Contains keys "browser", "version", "system"
	 * @access private
	 * @see match()
	 */
	function browserInfo($useragent)	{
		foreach($this->hookObjectsArr as $hookObj)	{
			if (method_exists($hookObj, 'browserInfo')) {
				$result = $hookObj->browserInfo($useragent);
				if (strlen($result)) {
					return $result;
				}
			}
		}

		$useragent = trim($useragent);
		$browserInfo=Array();
		$browserInfo['useragent']=$useragent;
		if ($useragent)	{
			// browser
			if (strstr($useragent,'MSIE'))	{
				$browserInfo['browser']='msie';
			} elseif(strstr($useragent,'Konqueror'))	{
				$browserInfo['browser']='konqueror';
			} elseif(strstr($useragent,'Opera'))	{
				$browserInfo['browser']='opera';
			} elseif(strstr($useragent,'Lynx'))	{
				$browserInfo['browser']='lynx';
			} elseif(strstr($useragent,'PHP'))	{
				$browserInfo['browser']='php';
			} elseif(strstr($useragent,'AvantGo'))	{
				$browserInfo['browser']='avantgo';
			} elseif(strstr($useragent,'WebCapture'))	{
				$browserInfo['browser']='acrobat';
			} elseif(strstr($useragent,'IBrowse'))	{
				$browserInfo['browser']='ibrowse';
			} elseif(strstr($useragent,'Teleport'))	{
				$browserInfo['browser']='teleport';
			} elseif(strstr($useragent,'Mozilla'))	{
				$browserInfo['browser']='netscape';
			} else {
				$browserInfo['browser']='unknown';
			}
			// version
			switch($browserInfo['browser'])	{
				case 'netscape':
					$browserInfo['version'] = $this->browserInfo_version(substr($useragent,8));
					if (strstr($useragent,'Netscape6')) {$browserInfo['version']=6;}
				break;
				case 'msie':
					$tmp = strstr($useragent,'MSIE');
					$browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
				break;
				case 'opera':
					$tmp = strstr($useragent,'Opera');
					$browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
				break;
				case 'lynx':
					$tmp = strstr($useragent,'Lynx/');
					$browserInfo['version'] = $this->browserInfo_version(substr($tmp,5));
				break;
				case 'php':
					$tmp = strstr($useragent,'PHP/');
					$browserInfo['version'] = $this->browserInfo_version(substr($tmp,4));
				break;
				case 'avantgo':
					$tmp = strstr($useragent,'AvantGo');
					$browserInfo['version'] = $this->browserInfo_version(substr($tmp,7));
				break;
				case 'acrobat':
					$tmp = strstr($useragent,'WebCapture');
					$browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
				break;
				case 'ibrowse':
					$tmp = strstr($useragent,'IBrowse/');
					$browserInfo['version'] = $this->browserInfo_version(substr($tmp,8));
				break;
				case 'konqueror':
					$tmp = strstr($useragent,'Konqueror/');
					$browserInfo['version'] = $this->browserInfo_version(substr($tmp,10));
				break;
			}
			// system
			$browserInfo['system']='';
			if (strstr($useragent,'Win'))	{
				// windows
				if (strstr($useragent,'Win98') || strstr($useragent,'Windows 98'))	{
					$browserInfo['system']='win98';
				} elseif (strstr($useragent,'Win95') || strstr($useragent,'Windows 95'))	{
					$browserInfo['system']='win95';
				} elseif (strstr($useragent,'WinNT') || strstr($useragent,'Windows NT'))	{
					$browserInfo['system']='winNT';
				} elseif (strstr($useragent,'Win16') || strstr($useragent,'Windows 311'))	{
					$browserInfo['system']='win311';
				}
			} elseif (strstr($useragent,'Mac'))	{
				$browserInfo['system']='mac';
				// unixes
			} elseif (strstr($useragent,'Linux'))	{
				$browserInfo['system']='linux';
			} elseif (strstr($useragent,'SGI') && strstr($useragent,' IRIX '))	{
				$browserInfo['system']='unix_sgi';
			} elseif (strstr($useragent,' SunOS '))	{
				$browserInfo['system']='unix_sun';
			} elseif (strstr($useragent,' HP-UX '))	{
				$browserInfo['system']='unix_hp';
			}
		}

		return $browserInfo;
	}

	/**
	 * 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.
	 *
	 * @param	string		A string with version number, eg. "/7.32 blablabla"
	 * @return	double		Returns double value, eg. "7.32"
	 */
	function browserInfo_version($tmp)	{
		return doubleval(preg_replace('/^[^0-9]*/','',$tmp));
	}

	/**
	 * Return global variable where the input string $var defines array keys separated by "|"
	 * Example: $var = "HTTP_SERVER_VARS | something" will return the value $GLOBALS['HTTP_SERVER_VARS']['something'] value
	 *
	 * @param	string		Global var key, eg. "HTTP_GET_VAR" or "HTTP_GET_VARS|id" to get the GET parameter "id" back.
	 * @param	array		Alternative array than $GLOBAL to get variables from.
	 * @return	mixed		Whatever value. If none, then blank string.
	 * @access private
	 */
	function getGlobal($var, $source=NULL)	{
		$vars = explode('|',$var);
		$c = count($vars);
		$k = trim($vars[0]);
		$theVar = isset($source) ? $source[$k] : $GLOBALS[$k];

		for ($a=1;$a<$c;$a++)	{
			if (!isset($theVar))	{ break; }

			$key = trim($vars[$a]);
			if (is_object($theVar))	{
				$theVar = $theVar->$key;
			} elseif (is_array($theVar))	{
				$theVar = $theVar[$key];
			} else {
				return '';
			}
		}

		if (!is_array($theVar) && !is_object($theVar))	{
			return $theVar;
		} else {
			return '';
		}
	}

	/**
	 * Returns GP / ENV / TSFE vars
	 *
	 * @param	string		Identifier
	 * @return	mixed		The value of the variable pointed to.
	 * @access private
	 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=311&cHash=487cbd5cdf
	 */
	function getGP_ENV_TSFE($var) {
		$vars = explode(':',$var,2);
		if (count($vars)==1)	{
			$val = $this->getGlobal($var);
		} else {
			$splitAgain=explode('|',$vars[1],2);
			$k=trim($splitAgain[0]);
			if ($k)	{
				switch((string)trim($vars[0]))	{
					case 'GP':
						$val = t3lib_div::_GP($k);
					break;
					case 'TSFE':
						$val = $this->getGlobal('TSFE|'.$vars[1]);
						$splitAgain=0;	// getGlobal resolves all parts of the key, so no further splitting is needed
					break;
					case 'ENV':
						$val = getenv($k);
					break;
					case 'IENV':
						$val = t3lib_div::getIndpEnv($k);
					break;
					case 'LIT':
						{ return trim($vars[1]); }	// return litteral value...
					break;
				}
					// If array:
				if (count($splitAgain)>1)	{
					if (is_array($val) && trim($splitAgain[1]))	{
						$val=$this->getGlobal($splitAgain[1],$val);
					} else {
						$val='';
					}
				}
			}
		}
		return $val;
	}
}


if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php']);
}
?>