PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/t3lib/matchcondition/class.t3lib_matchcondition_frontend.php

https://bitbucket.org/linxpinx/mercurial
PHP | 285 lines | 143 code | 27 blank | 115 comment | 26 complexity | 7cb0364a09934d7c6fa822c37a8035dd MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2009-2010 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. * Matching TypoScript conditions for frontend disposal.
  29. *
  30. * Used with the TypoScript parser.
  31. * Matches browserinfo, IPnumbers for use with templates
  32. *
  33. * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
  34. * @package TYPO3
  35. * @subpackage t3lib
  36. */
  37. class t3lib_matchCondition_frontend extends t3lib_matchCondition_abstract {
  38. /**
  39. * @var array
  40. */
  41. protected $deprecatedHooks = array();
  42. /**
  43. * Constructor for this class
  44. *
  45. * @return void
  46. */
  47. public function __construct() {
  48. $this->initializeDeprecatedHooks();
  49. }
  50. /**
  51. * Initializes deprectated hooks that existed in t3lib_matchCondition until TYPO3 4.3.
  52. *
  53. * @return void
  54. */
  55. protected function initializeDeprecatedHooks() {
  56. // Hook: $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass']:
  57. $matchConditionHooks =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'];
  58. if (is_array($matchConditionHooks)) {
  59. t3lib_div::deprecationLog(
  60. 'The hook $TYPO3_CONF_VARS[SC_OPTIONS][t3lib/class.t3lib_matchcondition.php][matchConditionClass] ' .
  61. 'is deprecated since TYPO3 4.3. Use the new hooks getBrowserInfo and getDeviceType in ' .
  62. 't3lib_utility_Client instead.'
  63. );
  64. foreach ($matchConditionHooks as $hookClass) {
  65. $this->deprecatedHooks[] = t3lib_div::getUserObj($hookClass, '');
  66. }
  67. }
  68. }
  69. /**
  70. * Evaluates a TypoScript condition given as input, eg. "[browser=net][...(other conditions)...]"
  71. *
  72. * @param string $string: The condition to match against its criterias.
  73. * @return boolean Whether the condition matched
  74. * @see t3lib_tsparser::parse()
  75. */
  76. protected function evaluateCondition($string) {
  77. list($key, $value) = t3lib_div::trimExplode('=', $string, false, 2);
  78. $result = parent::evaluateConditionCommon($key, $value);
  79. if (is_bool($result)) {
  80. return $result;
  81. } else {
  82. switch ($key) {
  83. case 'usergroup':
  84. $groupList = $this->getGroupList();
  85. if ($groupList != '0,-1') { // '0,-1' is the default usergroups when not logged in!
  86. $values = t3lib_div::trimExplode(',', $value, true);
  87. foreach ($values as $test) {
  88. if ($test == '*' || t3lib_div::inList($groupList, $test)) {
  89. return true;
  90. }
  91. }
  92. }
  93. break;
  94. case 'treeLevel':
  95. $values = t3lib_div::trimExplode(',', $value, true);
  96. $treeLevel = count($this->rootline) - 1;
  97. foreach ($values as $test) {
  98. if ($test == $treeLevel) {
  99. return true;
  100. }
  101. }
  102. break;
  103. case 'PIDupinRootline':
  104. case 'PIDinRootline':
  105. $values = t3lib_div::trimExplode(',', $value, true);
  106. if (($key=='PIDinRootline') || (!in_array($this->pageId, $values))) {
  107. foreach ($values as $test) {
  108. foreach ($this->rootline as $rl_dat) {
  109. if ($rl_dat['uid'] == $test) {
  110. return true;
  111. }
  112. }
  113. }
  114. }
  115. break;
  116. }
  117. }
  118. return false;
  119. }
  120. /**
  121. * Generates an array with abstracted browser information
  122. *
  123. * @param string $userAgent: The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
  124. * @return array Contains keys "browser", "version", "system"
  125. */
  126. protected function getBrowserInfo($userAgent) {
  127. // Exceute deprecated hooks:
  128. // @deprecated since TYPO3 4.3
  129. foreach($this->deprecatedHooks as $hookObj) {
  130. if (method_exists($hookObj, 'browserInfo')) {
  131. $result = $hookObj->browserInfo($userAgent);
  132. if (strlen($result)) {
  133. return $result;
  134. }
  135. }
  136. }
  137. return parent::getBrowserInfo($userAgent);
  138. }
  139. /**
  140. * Gets a code for a browsing device based on the input useragent string.
  141. *
  142. * @param string $userAgent: The useragent string, t3lib_div::getIndpEnv('HTTP_USER_AGENT')
  143. * @return string Code for the specific device type
  144. */
  145. protected function getDeviceType($userAgent) {
  146. // Exceute deprecated hooks:
  147. // @deprecated since TYPO3 4.3
  148. foreach($this->deprecatedHooks as $hookObj) {
  149. if (method_exists($hookObj, 'whichDevice')) {
  150. $result = $hookObj->whichDevice($userAgent);
  151. if (strlen($result)) {
  152. return $result;
  153. }
  154. }
  155. }
  156. // deprecated, see above
  157. if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'])) {
  158. foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['devices_class'] as $_classRef) {
  159. $_procObj = t3lib_div::getUserObj($_classRef);
  160. return $_procObj->whichDevice_ext($useragent);
  161. }
  162. }
  163. return parent::getDeviceType($userAgent);
  164. }
  165. /**
  166. * Returns GP / ENV / TSFE vars
  167. *
  168. * @param string Identifier
  169. * @return mixed The value of the variable pointed to.
  170. */
  171. protected function getVariable($var) {
  172. $vars = explode(':', $var, 2);
  173. $val = parent::getVariableCommon($vars);
  174. if (is_null($val)) {
  175. $splitAgain=explode('|', $vars[1], 2);
  176. $k = trim($splitAgain[0]);
  177. if ($k) {
  178. switch((string)trim($vars[0])) {
  179. case 'TSFE':
  180. $val = $this->getGlobal('TSFE|' . $vars[1]);
  181. break;
  182. }
  183. }
  184. }
  185. return $val;
  186. }
  187. /**
  188. * Get the usergroup list of the current user.
  189. *
  190. * @return string The usergroup list of the current user
  191. */
  192. protected function getGroupList() {
  193. $groupList = $GLOBALS['TSFE']->gr_list;
  194. return $groupList;
  195. }
  196. /**
  197. * Determines the current page Id.
  198. *
  199. * @return integer The current page Id
  200. */
  201. protected function determinePageId() {
  202. return (int)$GLOBALS['TSFE']->id;
  203. }
  204. /**
  205. * Determines the rootline for the current page.
  206. *
  207. * @return array The rootline for the current page.
  208. */
  209. protected function determineRootline() {
  210. $rootline = (array)$GLOBALS['TSFE']->tmpl->rootLine;
  211. return $rootline;
  212. }
  213. /**
  214. * Get prefix for user functions (normally 'user_').
  215. *
  216. * @return string The prefix for user functions (normally 'user_').
  217. */
  218. protected function getUserFuncClassPrefix() {
  219. $userFuncClassPrefix = $GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['userFuncClassPrefix'];
  220. return $userFuncClassPrefix;
  221. }
  222. /**
  223. * Get the id of the current user.
  224. *
  225. * @return integer The id of the current user
  226. */
  227. protected function getUserId() {
  228. $userId = $GLOBALS['TSFE']->fe_user->user['uid'];
  229. return $userId;
  230. }
  231. /**
  232. * Determines if a user is logged in.
  233. *
  234. * @return boolean Determines if a user is logged in
  235. */
  236. protected function isUserLoggedIn() {
  237. $userLoggedIn = false;
  238. if ($GLOBALS['TSFE']->loginUser) {
  239. $userLoggedIn = true;
  240. }
  241. return $userLoggedIn;
  242. }
  243. /**
  244. * Set/write a log message.
  245. *
  246. * @param string $message: The log message to set/write
  247. * @return void
  248. */
  249. protected function log($message) {
  250. if (is_object($GLOBALS['TT'])) {
  251. $GLOBALS['TT']->setTSlogMessage($message,3);
  252. }
  253. }
  254. }
  255. if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/matchcondition/class.t3lib_matchcondition_frontend.php']) {
  256. include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/matchcondition/class.t3lib_matchcondition_frontend.php']);
  257. }
  258. ?>