‪TYPO3CMS  10.4
QueryParser.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
24 {
28  protected ‪$commandKey = '';
29 
33  protected ‪$tableName = '';
34 
38  const ‪COMMAND_KEY_INDICATOR = '#';
39 
43  const ‪COMMAND_SPLIT_INDICATOR = ':';
44 
50  protected function ‪extractKeyFromQuery($query)
51  {
52  [‪$this->commandKey] = explode(':', substr($query, 1));
53  }
54 
61  public function ‪getSearchQueryValue($query)
62  {
63  $this->‪extractKeyFromQuery($query);
64  return str_replace(self::COMMAND_KEY_INDICATOR . $this->commandKey . self::COMMAND_SPLIT_INDICATOR, '', $query);
65  }
66 
73  public function ‪getTableNameFromCommand($query)
74  {
75  ‪$tableName = '';
76  $this->‪extractKeyFromQuery($query);
77  if (array_key_exists($this->commandKey, ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['livesearch'])) {
78  ‪$tableName = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['livesearch'][‪$this->commandKey];
79  }
80  return ‪$tableName;
81  }
82 
89  public function ‪getId($query)
90  {
91  return str_replace(self::COMMAND_KEY_INDICATOR, '', $query);
92  }
93 
100  public function ‪isValidPageJump($query)
101  {
102  $isValid = false;
103  if (preg_match('~^#(\\d)+$~', $query)) {
104  $isValid = true;
105  }
106  return $isValid;
107  }
108 
115  public function ‪isValidCommand($query)
116  {
117  $isValid = false;
118  if (strpos($query, self::COMMAND_KEY_INDICATOR) === 0 && strpos($query, self::COMMAND_SPLIT_INDICATOR) > 1 && $this->‪getTableNameFromCommand($query)) {
119  $isValid = true;
120  }
121  return $isValid;
122  }
123 
130  public function ‪getCommandForTable(‪$tableName)
131  {
132  $commandArray = array_keys(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['livesearch'], ‪$tableName);
133  if (is_array($commandArray)) {
134  $command = $commandArray[0];
135  } else {
136  $command = false;
137  }
138  return $command;
139  }
140 
147  public function ‪getCommandForPageJump($query)
148  {
149  if ($this->‪isValidPageJump($query)) {
150  $command = $this->‪getCommandForTable('pages');
151  $id = $this->‪getId($query);
152  $resultQuery = self::COMMAND_KEY_INDICATOR . $command . self::COMMAND_SPLIT_INDICATOR . $id;
153  } else {
154  $resultQuery = false;
155  }
156  return $resultQuery;
157  }
158 }
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\isValidPageJump
‪bool isValidPageJump($query)
Definition: QueryParser.php:98
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser
Definition: QueryParser.php:24
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\isValidCommand
‪bool isValidCommand($query)
Definition: QueryParser.php:113
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\COMMAND_KEY_INDICATOR
‪const COMMAND_KEY_INDICATOR
Definition: QueryParser.php:36
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\getId
‪int getId($query)
Definition: QueryParser.php:87
‪TYPO3\CMS\Backend\Search\LiveSearch
Definition: LiveSearch.php:16
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\getTableNameFromCommand
‪string getTableNameFromCommand($query)
Definition: QueryParser.php:71
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\COMMAND_SPLIT_INDICATOR
‪const COMMAND_SPLIT_INDICATOR
Definition: QueryParser.php:41
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\extractKeyFromQuery
‪extractKeyFromQuery($query)
Definition: QueryParser.php:48
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\getSearchQueryValue
‪string getSearchQueryValue($query)
Definition: QueryParser.php:59
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\$tableName
‪string $tableName
Definition: QueryParser.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\getCommandForPageJump
‪string getCommandForPageJump($query)
Definition: QueryParser.php:145
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\$commandKey
‪string $commandKey
Definition: QueryParser.php:27
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser\getCommandForTable
‪string getCommandForTable($tableName)
Definition: QueryParser.php:128