26a06aa3c5c3abf6fa728fc2545126b3cbb5a493
[Packages/TYPO3.CMS.git] / t3lib / matchcondition / class.t3lib_matchcondition_frontend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Oliver Hader <oliver@typo3.org>
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 /**
29 * Matching TypoScript conditions for frontend disposal.
30 *
31 * Used with the TypoScript parser.
32 * Matches browserinfo, IPnumbers for use with templates
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 * @package TYPO3
36 * @subpackage t3lib
37 */
38 class t3lib_matchCondition_frontend extends t3lib_matchCondition_abstract {
39
40 /**
41 * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]"
42 *
43 * @param string $string: The condition to match against its criterias.
44 * @return boolean Whether the condition matched
45 * @see t3lib_tsparser::parse()
46 */
47 protected function evaluateCondition($string) {
48 list($key, $value) = t3lib_div::trimExplode('=', $string, FALSE, 2);
49
50 $result = parent::evaluateConditionCommon($key, $value);
51
52 if (is_bool($result)) {
53 return $result;
54 } else {
55 switch ($key) {
56 case 'usergroup':
57 $groupList = $this->getGroupList();
58 if ($groupList != '0,-1') { // '0,-1' is the default usergroups when not logged in!
59 $values = t3lib_div::trimExplode(',', $value, TRUE);
60 foreach ($values as $test) {
61 if ($test == '*' || t3lib_div::inList($groupList, $test)) {
62 return TRUE;
63 }
64 }
65 }
66 break;
67 case 'treeLevel':
68 $values = t3lib_div::trimExplode(',', $value, TRUE);
69 $treeLevel = count($this->rootline) - 1;
70 foreach ($values as $test) {
71 if ($test == $treeLevel) {
72 return TRUE;
73 }
74 }
75 break;
76 case 'PIDupinRootline':
77 case 'PIDinRootline':
78 $values = t3lib_div::trimExplode(',', $value, TRUE);
79 if (($key == 'PIDinRootline') || (!in_array($this->pageId, $values))) {
80 foreach ($values as $test) {
81 foreach ($this->rootline as $rl_dat) {
82 if ($rl_dat['uid'] == $test) {
83 return TRUE;
84 }
85 }
86 }
87 }
88 break;
89 }
90 }
91
92 return FALSE;
93 }
94
95 /**
96 * Returns GP / ENV / TSFE vars
97 *
98 * @param string Identifier
99 * @return mixed The value of the variable pointed to.
100 */
101 protected function getVariable($var) {
102 $vars = explode(':', $var, 2);
103
104 $val = parent::getVariableCommon($vars);
105
106 if (is_null($val)) {
107 $splitAgain = explode('|', $vars[1], 2);
108 $k = trim($splitAgain[0]);
109 if ($k) {
110 switch ((string) trim($vars[0])) {
111 case 'TSFE':
112 $val = $this->getGlobal('TSFE|' . $vars[1]);
113 break;
114 }
115 }
116 }
117
118 return $val;
119 }
120
121 /**
122 * Get the usergroup list of the current user.
123 *
124 * @return string The usergroup list of the current user
125 */
126 protected function getGroupList() {
127 $groupList = $GLOBALS['TSFE']->gr_list;
128 return $groupList;
129 }
130
131 /**
132 * Determines the current page Id.
133 *
134 * @return integer The current page Id
135 */
136 protected function determinePageId() {
137 return (int) $GLOBALS['TSFE']->id;
138 }
139
140 /**
141 * Gets the properties for the current page.
142 *
143 * @return array The properties for the current page.
144 */
145 protected function getPage() {
146 return $GLOBALS['TSFE']->page;
147 }
148
149 /**
150 * Determines the rootline for the current page.
151 *
152 * @return array The rootline for the current page.
153 */
154 protected function determineRootline() {
155 $rootline = (array) $GLOBALS['TSFE']->tmpl->rootLine;
156 return $rootline;
157 }
158
159 /**
160 * Get prefix for user functions (normally 'user_').
161 *
162 * @return string The prefix for user functions (normally 'user_').
163 */
164 protected function getUserFuncClassPrefix() {
165 $userFuncClassPrefix = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['userFuncClassPrefix'];
166 return $userFuncClassPrefix;
167 }
168
169 /**
170 * Get the id of the current user.
171 *
172 * @return integer The id of the current user
173 */
174 protected function getUserId() {
175 $userId = $GLOBALS['TSFE']->fe_user->user['uid'];
176 return $userId;
177 }
178
179 /**
180 * Determines if a user is logged in.
181 *
182 * @return boolean Determines if a user is logged in
183 */
184 protected function isUserLoggedIn() {
185 $userLoggedIn = FALSE;
186 if ($GLOBALS['TSFE']->loginUser) {
187 $userLoggedIn = TRUE;
188 }
189 return $userLoggedIn;
190 }
191
192 /**
193 * Set/write a log message.
194 *
195 * @param string $message: The log message to set/write
196 * @return void
197 */
198 protected function log($message) {
199 if (is_object($GLOBALS['TT'])) {
200 $GLOBALS['TT']->setTSlogMessage($message, 3);
201 }
202 }
203 }
204
205
206 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/matchcondition/class.t3lib_matchcondition_frontend.php'])) {
207 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/matchcondition/class.t3lib_matchcondition_frontend.php']);
208 }
209
210 ?>