TYPO3 CMS  TYPO3_7-6
QueryParser.php
Go to the documentation of this file.
1 <?php
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 
22 {
26  protected $commandKey = '';
27 
31  protected $tableName = '';
32 
36  const COMMAND_KEY_INDICATOR = '#';
37 
42 
49  protected function extractKeyFromQuery($query)
50  {
51  list($this->commandKey) = explode(':', substr($query, 1));
52  }
53 
60  public function getSearchQueryValue($query)
61  {
62  $this->extractKeyFromQuery($query);
63  return str_replace(self::COMMAND_KEY_INDICATOR . $this->commandKey . self::COMMAND_SPLIT_INDICATOR, '', $query);
64  }
65 
72  public function getTableNameFromCommand($query)
73  {
74  $tableName = '';
75  $this->extractKeyFromQuery($query);
76  if (array_key_exists($this->commandKey, $GLOBALS['TYPO3_CONF_VARS']['SYS']['livesearch'])) {
77  $tableName = $GLOBALS['TYPO3_CONF_VARS']['SYS']['livesearch'][$this->commandKey];
78  }
79  return $tableName;
80  }
81 
88  public function getId($query)
89  {
90  return str_replace(self::COMMAND_KEY_INDICATOR, '', $query);
91  }
92 
99  public function isValidPageJump($query)
100  {
101  $isValid = false;
102  if (preg_match('~^#(\\d)+$~', $query)) {
103  $isValid = true;
104  }
105  return $isValid;
106  }
107 
114  public function isValidCommand($query)
115  {
116  $isValid = false;
117  if (strpos($query, self::COMMAND_KEY_INDICATOR) === 0 && strpos($query, self::COMMAND_SPLIT_INDICATOR) > 1 && $this->getTableNameFromCommand($query)) {
118  $isValid = true;
119  }
120  return $isValid;
121  }
122 
130  {
131  $commandArray = array_keys($GLOBALS['TYPO3_CONF_VARS']['SYS']['livesearch'], $tableName);
132  if (is_array($commandArray)) {
133  $command = $commandArray[0];
134  } else {
135  $command = false;
136  }
137  return $command;
138  }
139 
146  public function getCommandForPageJump($query)
147  {
148  if ($this->isValidPageJump($query)) {
149  $command = $this->getCommandForTable('pages');
150  $id = $this->getId($query);
151  $resultQuery = self::COMMAND_KEY_INDICATOR . $command . self::COMMAND_SPLIT_INDICATOR . $id;
152  } else {
153  $resultQuery = false;
154  }
155  return $resultQuery;
156  }
157 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']