TYPO3 CMS  TYPO3_7-6
IndexedSearchUtility.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 {
31  public static function isTableUsed($tableName)
32  {
33  $tableList = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['use_tables'];
34  return \TYPO3\CMS\Core\Utility\GeneralUtility::inList($tableList, $tableName);
35  }
36 
44  public static function md5inthash($stringToHash)
45  {
46  return hexdec(substr(md5($stringToHash), 0, 7));
47  }
48 
58  public static function getExplodedSearchString($sword, $defaultOperator, $operatorTranslateTable)
59  {
60  $swordArray = [];
61  $sword = trim($sword);
62  if ($sword) {
63  $components = self::split($sword);
64  if (is_array($components)) {
65  $i = 0;
66  $lastoper = '';
67  foreach ($components as $key => $val) {
68  $operator = self::getOperator($val, $operatorTranslateTable);
69  if ($operator) {
70  $lastoper = $operator;
71  } elseif (strlen($val) > 1) {
72  // A searchword MUST be at least two characters long!
73  $swordArray[$i]['sword'] = $val;
74  $swordArray[$i]['oper'] = $lastoper ?: $defaultOperator;
75  $lastoper = '';
76  $i++;
77  }
78  }
79  }
80  }
81  return $swordArray;
82  }
83 
93  protected static function split($origSword, $specchars = '+-', $delchars = '+.,-')
94  {
95  $value = null;
96  $sword = $origSword;
97  $specs = '[' . preg_quote($specchars, '/') . ']';
98  // As long as $sword is TRUE (that means $sword MUST be reduced little by little until its empty inside the loop!)
99  while ($sword) {
100  // There was a double-quote and we will then look for the ending quote.
101  if (preg_match('/^"/', $sword)) {
102  // Removes first double-quote
103  $sword = preg_replace('/^"/', '', $sword);
104  // Removes everything till next double-quote
105  preg_match('/^[^"]*/', $sword, $reg);
106  // reg[0] is the value, should not be trimmed
107  $value[] = $reg[0];
108  $sword = preg_replace('/^' . preg_quote($reg[0], '/') . '/', '', $sword);
109  // Removes last double-quote
110  $sword = trim(preg_replace('/^"/', '', $sword));
111  } elseif (preg_match('/^' . $specs . '/', $sword, $reg)) {
112  $value[] = $reg[0];
113  // Removes = sign
114  $sword = trim(preg_replace('/^' . $specs . '/', '', $sword));
115  } elseif (preg_match('/[\\+\\-]/', $sword)) {
116  // Check if $sword contains + or -
117  // + and - shall only be interpreted as $specchars when there's whitespace before it
118  // otherwise it's included in the searchword (e.g. "know-how")
119  // explode $sword to single words
120  $a_sword = explode(' ', $sword);
121  // get first word
122  $word = array_shift($a_sword);
123  // Delete $delchars at end of string
124  $word = rtrim($word, $delchars);
125  // add searchword to values
126  $value[] = $word;
127  // re-build $sword
128  $sword = implode(' ', $a_sword);
129  } else {
130  // There are no double-quotes around the value. Looking for next (space) or special char.
131  preg_match('/^[^ ' . preg_quote($specchars, '/') . ']*/', $sword, $reg);
132  // Delete $delchars at end of string
133  $word = rtrim(trim($reg[0]), $delchars);
134  $value[] = $word;
135  $sword = trim(preg_replace('/^' . preg_quote($reg[0], '/') . '/', '', $sword));
136  }
137  }
138  return $value;
139  }
140 
148  protected static function getOperator($operator, $operatorTranslateTable)
149  {
150  $operator = trim($operator);
151  // case-conversion is charset insensitive, but it doesn't spoil
152  // anything if input string AND operator table is already converted
153  $operator = strtolower($operator);
154  foreach ($operatorTranslateTable as $key => $val) {
155  $item = $operatorTranslateTable[$key][0];
156  // See note above.
157  $item = strtolower($item);
158  if ($operator == $item) {
159  return $operatorTranslateTable[$key][1];
160  }
161  }
162  }
163 }
static split($origSword, $specchars='+-', $delchars='+.,-')
static getExplodedSearchString($sword, $defaultOperator, $operatorTranslateTable)
static getOperator($operator, $operatorTranslateTable)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']