‪TYPO3CMS  10.4
IndexedSearchUtility.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 
19 
26 {
35  public static function ‪isTableUsed($tableName)
36  {
37  $tableList = ‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['use_tables'];
38  return GeneralUtility::inList($tableList, $tableName);
39  }
40 
48  public static function ‪md5inthash($stringToHash)
49  {
50  return hexdec(substr(md5($stringToHash), 0, 7));
51  }
52 
62  public static function ‪getExplodedSearchString($sword, $defaultOperator, $operatorTranslateTable)
63  {
64  $swordArray = [];
65  $sword = trim($sword);
66  if ($sword) {
67  $components = ‪self::split($sword);
68  if (is_array($components)) {
69  $i = 0;
70  $lastoper = '';
71  foreach ($components as $key => $val) {
72  $operator = ‪self::getOperator($val, $operatorTranslateTable);
73  if ($operator) {
74  $lastoper = $operator;
75  } elseif (strlen($val) > 1) {
76  // A searchword MUST be at least two characters long!
77  $swordArray[$i]['sword'] = $val;
78  $swordArray[$i]['oper'] = $lastoper ?: $defaultOperator;
79  $lastoper = '';
80  $i++;
81  }
82  }
83  }
84  }
85  return $swordArray;
86  }
87 
97  protected static function ‪split($origSword, $specchars = '+-', $delchars = '+.,-')
98  {
99  $value = null;
100  $sword = $origSword;
101  $specs = '[' . preg_quote($specchars, '/') . ']';
102  // As long as $sword is TRUE (that means $sword MUST be reduced little by little until its empty inside the loop!)
103  while ($sword) {
104  // There was a double-quote and we will then look for the ending quote.
105  if (preg_match('/^"/', $sword)) {
106  // Removes first double-quote
107  $sword = (string)preg_replace('/^"/', '', $sword);
108  // Removes everything till next double-quote
109  preg_match('/^[^"]*/', $sword, $reg);
110  // reg[0] is the value, should not be trimmed
111  $value[] = $reg[0];
112  $sword = (string)preg_replace('/^' . preg_quote($reg[0], '/') . '/', '', $sword);
113  // Removes last double-quote
114  $sword = trim((string)preg_replace('/^"/', '', $sword));
115  } elseif (preg_match('/^' . $specs . '/', $sword, $reg)) {
116  $value[] = $reg[0];
117  // Removes = sign
118  $sword = trim((string)preg_replace('/^' . $specs . '/', '', $sword));
119  } elseif (preg_match('/[\\+\\-]/', $sword)) {
120  // Check if $sword contains + or -
121  // + and - shall only be interpreted as $specchars when there's whitespace before it
122  // otherwise it's included in the searchword (e.g. "know-how")
123  // explode $sword to single words
124  $a_sword = explode(' ', $sword);
125  // get first word
126  $word = (string)array_shift($a_sword);
127  // Delete $delchars at end of string
128  $word = rtrim($word, $delchars);
129  // add searchword to values
130  $value[] = $word;
131  // re-build $sword
132  $sword = implode(' ', $a_sword);
133  } else {
134  // There are no double-quotes around the value. Looking for next (space) or special char.
135  preg_match('/^[^ ' . preg_quote($specchars, '/') . ']*/', $sword, $reg);
136  // Delete $delchars at end of string
137  $word = rtrim(trim($reg[0]), $delchars);
138  $value[] = $word;
139  $sword = trim((string)preg_replace('/^' . preg_quote($reg[0], '/') . '/', '', $sword));
140  }
141  }
142  return $value;
143  }
144 
152  protected static function ‪getOperator($operator, $operatorTranslateTable)
153  {
154  $operator = trim($operator);
155  // case-conversion is charset insensitive, but it doesn't spoil
156  // anything if input string AND operator table is already converted
157  $operator = strtolower($operator);
158  foreach ($operatorTranslateTable as $key => $val) {
159  $item = $operatorTranslateTable[$key][0];
160  // See note above.
161  $item = strtolower($item);
162  if ($operator == $item) {
163  return $operatorTranslateTable[$key][1];
164  }
165  }
166 
167  return null;
168  }
169 
175  public static function ‪milliseconds()
176  {
177  return round(microtime(true) * 1000);
178  }
179 }
‪TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility\md5inthash
‪static int md5inthash($stringToHash)
Definition: IndexedSearchUtility.php:48
‪TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility\getOperator
‪static string null getOperator($operator, $operatorTranslateTable)
Definition: IndexedSearchUtility.php:152
‪TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility\isTableUsed
‪static bool isTableUsed($tableName)
Definition: IndexedSearchUtility.php:35
‪TYPO3\CMS\IndexedSearch\Utility
Definition: DoubleMetaPhoneUtility.php:16
‪TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility\split
‪static mixed split($origSword, $specchars='+-', $delchars='+.,-')
Definition: IndexedSearchUtility.php:97
‪TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility\milliseconds
‪static int milliseconds()
Definition: IndexedSearchUtility.php:175
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility
Definition: IndexedSearchUtility.php:26
‪TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility\getExplodedSearchString
‪static array getExplodedSearchString($sword, $defaultOperator, $operatorTranslateTable)
Definition: IndexedSearchUtility.php:62