Added feature #13953: Hookrequest - t3lib_page::getRecordOverlay (thanks to Tolleiv...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_matchcondition.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 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 extends t3lib_matchCondition_frontend {
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 * @deprecated since TYPO3 4.3, will be removed in TYPO3 4.5 - The functionality was moved to t3lib_matchCondition_frontend
92 */
93 function __construct() {
94 t3lib_div::logDeprecatedFunction();
95
96 parent::__construct();
97 }
98
99 /**
100 * Matching TS condition
101 *
102 * @param string Line to match
103 * @return boolean True if matched
104 */
105 function match($condition_line) {
106 if ($this->matchAll) {
107 parent::setSimulateMatchResult(true);
108 }
109 if (count($this->matchAlternative)) {
110 parent::setSimulateMatchConditions($this->matchAlternative);
111 }
112
113 return parent::match($condition_line);
114 }
115
116
117 /**
118 * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]"
119 *
120 * @param string The condition to match against its criterias.
121 * @return boolean Returns true or false based on the evaluation.
122 * @see t3lib_tsparser::parse()
123 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=292&cHash=c6c7d43d2f
124 */
125 function evalConditionStr($string) {
126 return parent::evaluateCondition($string);
127 }
128
129 /**
130 * Evaluates a $leftValue based on an operator: "<", ">", "<=", ">=", "!=" or "="
131 *
132 * @param string $test: The value to compare with on the form [operator][number]. Eg. "< 123"
133 * @param integer $leftValue: The value on the left side
134 * @return boolean If $value is "50" and $test is "< 123" then it will return true.
135 */
136 function testNumber($test, $leftValue) {
137 return parent::compareNumber($test, $leftValue);
138 }
139
140 /**
141 * Matching two strings against each other, supporting a "*" wildcard or (if wrapped in "/") PCRE regular expressions
142 *
143 * @param string The string in which to find $needle.
144 * @param string The string to find in $haystack
145 * @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.
146 */
147 function matchWild($haystack, $needle) {
148 return parent::searchStringWildcard($haystack, $needle);
149 }
150
151 /**
152 * Returns a code for a browsing device based on the input useragent string
153 *
154 * @param string User agent string from browser, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
155 * @return string A code. See link.
156 * @access private
157 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=296&cHash=a8ae66c7d6
158 */
159 function whichDevice($useragent) {
160 return parent::getDeviceType($useragent);
161 }
162
163 /**
164 * Generates an array with abstracted browser information
165 * This method is used in the function match() in this class
166 *
167 * @param string The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
168 * @return array Contains keys "browser", "version", "system"
169 * @access private
170 * @see match()
171 */
172 function browserInfo($useragent) {
173 return parent::getBrowserInfo($useragent);
174 }
175
176 /**
177 * 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.
178 *
179 * @param string A string with version number, eg. "/7.32 blablabla"
180 * @return double Returns double value, eg. "7.32"
181 * @deprecated since TYPO3 4.3 - use t3lib_utility_Client::getVersion() instead
182 */
183 function browserInfo_version($tmp) {
184 t3lib_div::logDeprecatedFunction();
185 return t3lib_utility_Client::getVersion($tmp);
186 }
187
188 /**
189 * Return global variable where the input string $var defines array keys separated by "|"
190 * Example: $var = "HTTP_SERVER_VARS | something" will return the value $GLOBALS['HTTP_SERVER_VARS']['something'] value
191 *
192 * @param string Global var key, eg. "HTTP_GET_VAR" or "HTTP_GET_VARS|id" to get the GET parameter "id" back.
193 * @param array Alternative array than $GLOBAL to get variables from.
194 * @return mixed Whatever value. If none, then blank string.
195 * @access private
196 */
197 function getGlobal($var, $source=NULL) {
198 return parent::getGlobal($var, $source);
199 }
200
201 /**
202 * Returns GP / ENV / TSFE vars
203 *
204 * @param string Identifier
205 * @return mixed The value of the variable pointed to.
206 * @access private
207 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=311&cHash=487cbd5cdf
208 */
209 function getGP_ENV_TSFE($var) {
210 return parent::getVariable($var);
211 }
212 }
213
214
215 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php']) {
216 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_matchcondition.php']);
217 }
218
219 ?>