2 /***************************************************************
5 * (c) 2009 Oliver Hader <oliver@typo3.org>
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * Matching TypoScript conditions for frontend disposal.
31 * Used with the TypoScript parser.
32 * Matches browserinfo, IPnumbers for use with templates
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
38 class t3lib_matchCondition_frontend
extends t3lib_matchCondition_abstract
{
42 protected $deprecatedHooks = array();
45 * Constructor for this class
49 public function __construct() {
50 $this->initializeDeprecatedHooks();
54 * Initializes deprectated hooks that existed in t3lib_matchCondition until TYPO3 4.3.
58 protected function initializeDeprecatedHooks() {
59 // Hook: $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass']:
60 $matchConditionHooks =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'];
61 if (is_array($matchConditionHooks)) {
62 t3lib_div
::deprecationLog(
63 'The hook $TYPO3_CONF_VARS[SC_OPTIONS][t3lib/class.t3lib_matchcondition.php][matchConditionClass] ' .
64 'is deprecated since TYPO3 4.3. Use the new hooks getBrowserInfo and getDeviceType in ' .
65 't3lib_utility_Client instead.'
68 foreach ($matchConditionHooks as $hookClass) {
69 $this->deprecatedHooks
[] = t3lib_div
::getUserObj($hookClass, '');
75 * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]"
77 * @param string $string: The condition to match against its criterias.
78 * @return boolean Whether the condition matched
79 * @see t3lib_tsparser::parse()
81 protected function evaluateCondition($string) {
82 list($key, $value) = t3lib_div
::trimExplode('=', $string, false, 2);
84 $result = parent
::evaluateConditionCommon($key, $value);
86 if (is_bool($result)) {
91 $groupList = $this->getGroupList();
92 if ($groupList != '0,-1') { // '0,-1' is the default usergroups when not logged in!
93 $values = t3lib_div
::trimExplode(',', $value, true);
94 foreach ($values as $test) {
95 if ($test == '*' || t3lib_div
::inList($groupList, $test)) {
102 $values = t3lib_div
::trimExplode(',', $value, true);
103 $treeLevel = count($this->rootline
) - 1;
104 foreach ($values as $test) {
105 if ($test == $treeLevel) {
110 case 'PIDupinRootline':
111 case 'PIDinRootline':
112 $values = t3lib_div
::trimExplode(',', $value, true);
113 if (($key=='PIDinRootline') ||
(!in_array($this->pageId
, $values))) {
114 foreach ($values as $test) {
115 foreach ($this->rootline
as $rl_dat) {
116 if ($rl_dat['uid'] == $test) {
130 * Generates an array with abstracted browser information
132 * @param string $userAgent: The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
133 * @return array Contains keys "browser", "version", "system"
135 protected function getBrowserInfo($userAgent) {
136 // Exceute deprecated hooks:
137 // @deprecated since TYPO3 4.3
138 foreach($this->deprecatedHooks
as $hookObj) {
139 if (method_exists($hookObj, 'browserInfo')) {
140 $result = $hookObj->browserInfo($userAgent);
141 if (strlen($result)) {
147 return parent
::getBrowserInfo($userAgent);
151 * Gets a code for a browsing device based on the input useragent string.
153 * @param string $userAgent: The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
154 * @return string Code for the specific device type
156 protected function getDeviceType($userAgent) {
157 // Exceute deprecated hooks:
158 // @deprecated since TYPO3 4.3
159 foreach($this->deprecatedHooks
as $hookObj) {
160 if (method_exists($hookObj, 'whichDevice')) {
161 $result = $hookObj->whichDevice($userAgent);
162 if (strlen($result)) {
168 // deprecated, see above
169 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'])) {
170 foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'] as $_classRef) {
171 $_procObj = t3lib_div
::getUserObj($_classRef);
172 return $_procObj->whichDevice_ext($useragent);
176 return parent
::getDeviceType($userAgent);
180 * Returns GP / ENV / TSFE vars
182 * @param string Identifier
183 * @return mixed The value of the variable pointed to.
185 protected function getVariable($var) {
186 $vars = explode(':', $var, 2);
188 $val = parent
::getVariableCommon($vars);
191 $splitAgain=explode('|', $vars[1], 2);
192 $k = trim($splitAgain[0]);
194 switch((string)trim($vars[0])) {
196 $val = $this->getGlobal('TSFE|' . $vars[1]);
206 * Get the usergroup list of the current user.
208 * @return string The usergroup list of the current user
210 protected function getGroupList() {
211 $groupList = $GLOBALS['TSFE']->gr_list
;
216 * Determines the current page Id.
218 * @return integer The current page Id
220 protected function determinePageId() {
221 return (int)$GLOBALS['TSFE']->id
;
225 * Determines the rootline for the current page.
227 * @return array The rootline for the current page.
229 protected function determineRootline() {
230 $rootline = (array)$GLOBALS['TSFE']->tmpl
->rootLine
;
235 * Get prefix for user functions (normally 'user_').
237 * @return string The prefix for user functions (normally 'user_').
239 protected function getUserFuncClassPrefix() {
240 $userFuncClassPrefix = $GLOBALS['TSFE']->TYPO3_CONF_VARS
['FE']['userFuncClassPrefix'];
241 return $userFuncClassPrefix;
245 * Get the id of the current user.
247 * @return integer The id of the current user
249 protected function getUserId() {
250 $userId = $GLOBALS['TSFE']->fe_user
->user
['uid'];
255 * Determines if a user is logged in.
257 * @return boolean Determines if a user is logged in
259 protected function isUserLoggedIn() {
260 $userLoggedIn = false;
261 if ($GLOBALS['TSFE']->loginUser
) {
262 $userLoggedIn = true;
264 return $userLoggedIn;
268 * Set/write a log message.
270 * @param string $message: The log message to set/write
273 protected function log($message) {
274 if (is_object($GLOBALS['TT'])) {
275 $GLOBALS['TT']->setTSlogMessage($message,3);
281 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/matchcondition/class.t3lib_matchcondition_frontend.php']) {
282 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/matchcondition/class.t3lib_matchcondition_frontend.php']);