[BUGFIX] Re-apply colorspace to resulting image
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Configuration / TypoScript / ConditionMatching / ConditionMatcher.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Matching TypoScript conditions for frontend disposal.
22 *
23 * Used with the TypoScript parser. Matches browserinfo
24 * and IP numbers for use with templates.
25 */
26 class ConditionMatcher extends AbstractConditionMatcher
27 {
28 /**
29 * Evaluates a TypoScript condition given as input,
30 * eg. "[browser=net][...(other conditions)...]"
31 *
32 * @param string $string The condition to match against its criteria.
33 * @return bool Whether the condition matched
34 * @see \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::parse()
35 * @throws \TYPO3\CMS\Core\Configuration\TypoScript\Exception\InvalidTypoScriptConditionException
36 */
37 protected function evaluateCondition($string)
38 {
39 list($key, $value) = GeneralUtility::trimExplode('=', $string, false, 2);
40 $result = $this->evaluateConditionCommon($key, $value);
41
42 if (is_bool($result)) {
43 return $result;
44 }
45 switch ($key) {
46 case 'usergroup':
47 $groupList = $this->getGroupList();
48 // '0,-1' is the default usergroups when not logged in!
49 if ($groupList !== '0,-1') {
50 $values = GeneralUtility::trimExplode(',', $value, true);
51 foreach ($values as $test) {
52 if ($test === '*' || GeneralUtility::inList($groupList, $test)) {
53 return true;
54 }
55 }
56 }
57 break;
58 case 'treeLevel':
59 $values = GeneralUtility::trimExplode(',', $value, true);
60 $treeLevel = count($this->rootline) - 1;
61 foreach ($values as $test) {
62 if ($test == $treeLevel) {
63 return true;
64 }
65 }
66 break;
67 case 'PIDupinRootline':
68 case 'PIDinRootline':
69 $values = GeneralUtility::trimExplode(',', $value, true);
70 if ($key === 'PIDinRootline' || !in_array($this->pageId, $values)) {
71 foreach ($values as $test) {
72 foreach ($this->rootline as $rlDat) {
73 if ($rlDat['uid'] == $test) {
74 return true;
75 }
76 }
77 }
78 }
79 break;
80 default:
81 $conditionResult = $this->evaluateCustomDefinedCondition($string);
82 if ($conditionResult !== null) {
83 return $conditionResult;
84 }
85 }
86
87 return false;
88 }
89
90 /**
91 * Returns GP / ENV / TSFE vars
92 *
93 * @param string $var Identifier
94 * @return mixed The value of the variable pointed to or NULL if variable did not exist
95 */
96 protected function getVariable($var)
97 {
98 $vars = explode(':', $var, 2);
99 $val = $this->getVariableCommon($vars);
100 if (is_null($val)) {
101 $splitAgain = explode('|', $vars[1], 2);
102 $k = trim($splitAgain[0]);
103 if ($k) {
104 switch ((string)trim($vars[0])) {
105 case 'TSFE':
106 $val = $this->getGlobal('TSFE|' . $vars[1]);
107 break;
108 default:
109 }
110 }
111 }
112 return $val;
113 }
114
115 /**
116 * Get the usergroup list of the current user.
117 *
118 * @return string The usergroup list of the current user
119 */
120 protected function getGroupList()
121 {
122 return $this->getTypoScriptFrontendController()->gr_list;
123 }
124
125 /**
126 * Determines the current page Id.
127 *
128 * @return int The current page Id
129 */
130 protected function determinePageId()
131 {
132 return (int)$this->getTypoScriptFrontendController()->id;
133 }
134
135 /**
136 * Gets the properties for the current page.
137 *
138 * @return array The properties for the current page.
139 */
140 protected function getPage()
141 {
142 return $this->getTypoScriptFrontendController()->page;
143 }
144
145 /**
146 * Determines the rootline for the current page.
147 *
148 * @return array The rootline for the current page.
149 */
150 protected function determineRootline()
151 {
152 return (array)$this->getTypoScriptFrontendController()->tmpl->rootLine;
153 }
154
155 /**
156 * Get the id of the current user.
157 *
158 * @return int The id of the current user
159 */
160 protected function getUserId()
161 {
162 return $this->getTypoScriptFrontendController()->fe_user->user['uid'];
163 }
164
165 /**
166 * Determines if a user is logged in.
167 *
168 * @return bool Determines if a user is logged in
169 */
170 protected function isUserLoggedIn()
171 {
172 return (bool)$this->getTypoScriptFrontendController()->loginUser;
173 }
174
175 /**
176 * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
177 */
178 protected function getTypoScriptFrontendController()
179 {
180 return $GLOBALS['TSFE'];
181 }
182 }