[TASK] Remove initialization for fileFactory in AbstractContentObject
[Packages/TYPO3.CMS.git] / typo3 / sysext / compatibility6 / Classes / ContentObject / SearchResultContentObject.php
1 <?php
2 namespace TYPO3\CMS\Compatibility6\ContentObject;
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
17 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
18
19 /**
20 * Search class used for the content object SEARCHRESULT
21 * and searching in database tables, typ. "pages" and "tt_content"
22 * Used to generate search queries for TypoScript.
23 * The class is included from "TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer"
24 * based on whether there has been detected content in the GPvar "sword"
25 */
26 class SearchResultContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractContentObject {
27
28 /**
29 * @var array
30 */
31 public $tables = array();
32
33 /**
34 * Alternatively 'PRIMARY_KEY'; sorting by primary key
35 *
36 * @var string
37 */
38 public $group_by = 'PRIMARY_KEY';
39
40 /**
41 * Standard SQL-operator between words
42 *
43 * @var string
44 */
45 public $default_operator = 'AND';
46
47 /**
48 * @var bool
49 */
50 public $operator_translate_table_caseinsensitive = TRUE;
51
52 /**
53 * case-sensitive. Defines the words, which will be operators between words
54 *
55 * @var array
56 */
57 public $operator_translate_table = array(
58 array('+', 'AND'),
59 array('|', 'AND'),
60 array('-', 'AND NOT'),
61 // english
62 array('and', 'AND'),
63 array('or', 'OR'),
64 array('not', 'AND NOT')
65 );
66
67 /**
68 * Contains the search-words and operators
69 *
70 * @var array
71 */
72 public $sword_array;
73
74 /**
75 * Contains the query parts after processing.
76 *
77 * @var array
78 */
79 public $queryParts;
80
81 /**
82 * This is set with the foreign table that 'pages' are connected to.
83 *
84 * @var string
85 */
86 public $fTable;
87
88 /**
89 * How many rows to offset from the beginning
90 *
91 * @var int
92 */
93 public $res_offset = 0;
94
95 /**
96 * How many results to show (0 = no limit)
97 *
98 * @var int
99 */
100 public $res_shows = 20;
101
102 /**
103 * Intern: How many results, there was last time (with the exact same searchstring.
104 *
105 * @var int
106 */
107 public $res_count;
108
109 /**
110 * List of pageIds.
111 *
112 * @var string
113 */
114 public $pageIdList = '';
115
116 /**
117 * @var string
118 */
119 public $listOfSearchFields = '';
120
121 /**
122 * Override default constructor to make it possible to instantiate this
123 * class for indexed_search
124 *
125 * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj
126 */
127 public function __construct(ContentObjectRenderer $cObj = NULL) {
128 if (!is_null($cObj)) {
129 $this->cObj = $cObj;
130 }
131 }
132
133 /**
134 * Rendering the cObject, SEARCHRESULT
135 *
136 * @param array $conf Array of TypoScript properties
137 * @return string Output
138 */
139 public function render($conf = array()) {
140 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('sword') && \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('scols')) {
141 $this->register_and_explode_search_string(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('sword'));
142 $this->register_tables_and_columns(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('scols'), $conf['allowedCols']);
143 // Depth
144 $depth = 100;
145 // The startId is found
146 $theStartId = 0;
147 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('stype'))) {
148 $temp_theStartId = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('stype');
149 $rootLine = $GLOBALS['TSFE']->sys_page->getRootLine($temp_theStartId);
150 // The page MUST have a rootline with the Level0-page of the current site inside!!
151 foreach ($rootLine as $val) {
152 if ($val['uid'] == $GLOBALS['TSFE']->tmpl->rootLine[0]['uid']) {
153 $theStartId = $temp_theStartId;
154 }
155 }
156 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('stype')) {
157 if (substr(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('stype'), 0, 1) == 'L') {
158 $pointer = (int)substr(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('stype'), 1);
159 $theRootLine = $GLOBALS['TSFE']->tmpl->rootLine;
160 // location Data:
161 $locDat_arr = explode(':', \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('locationData'));
162 $pId = (int)$locDat_arr[0];
163 if ($pId) {
164 $altRootLine = $GLOBALS['TSFE']->sys_page->getRootLine($pId);
165 ksort($altRootLine);
166 if (count($altRootLine)) {
167 // Check if the rootline has the real Level0 in it!!
168 $hitRoot = 0;
169 $theNewRoot = array();
170 foreach ($altRootLine as $val) {
171 if ($hitRoot || $val['uid'] == $GLOBALS['TSFE']->tmpl->rootLine[0]['uid']) {
172 $hitRoot = 1;
173 $theNewRoot[] = $val;
174 }
175 }
176 if ($hitRoot) {
177 // Override the real rootline if any thing
178 $theRootLine = $theNewRoot;
179 }
180 }
181 }
182 $key = $this->cObj->getKey($pointer, $theRootLine);
183 $theStartId = $theRootLine[$key]['uid'];
184 }
185 }
186 if (!$theStartId) {
187 // If not set, we use current page
188 $theStartId = $GLOBALS['TSFE']->id;
189 }
190 // Generate page-tree
191 $this->pageIdList .= $this->cObj->getTreeList(-1 * $theStartId, $depth);
192 $endClause = 'pages.uid IN (' . $this->pageIdList . ')
193 AND pages.doktype in (' . $GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'] . ($conf['addExtUrlsAndShortCuts'] ? ',3,4' : '') . ')
194 AND pages.no_search=0' . $this->cObj->enableFields($this->fTable) . $this->cObj->enableFields('pages');
195 if ($conf['languageField.'][$this->fTable]) {
196 // (using sys_language_uid which is the ACTUAL language of the page.
197 // sys_language_content is only for selecting DISPLAY content!)
198 $endClause .= ' AND ' . $this->fTable . '.' . $conf['languageField.'][$this->fTable] . ' = ' . (int)$GLOBALS['TSFE']->sys_language_uid;
199 }
200 // Build query
201 $this->build_search_query($endClause);
202 // Count...
203 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('scount'))) {
204 $this->res_count = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('scount');
205 } else {
206 $this->count_query();
207 }
208 // Range
209 $spointer = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('spointer');
210 $range = isset($conf['range.']) ? $this->cObj->stdWrap($conf['range'], $conf['range.']) : $conf['range'];
211 if ($range) {
212 $theRange = (int)$range;
213 } else {
214 $theRange = 20;
215 }
216 // Order By:
217 $noOrderBy = isset($conf['noOrderBy.']) ? $this->cObj->stdWrap($conf['noOrderBy'], $conf['noOrderBy.']) : $conf['noOrderBy'];
218 if (!$noOrderBy) {
219 $this->queryParts['ORDERBY'] = 'pages.lastUpdated, pages.tstamp';
220 }
221 $this->queryParts['LIMIT'] = $spointer . ',' . $theRange;
222 // Search...
223 $this->execute_query();
224 if ($GLOBALS['TYPO3_DB']->sql_num_rows($this->result)) {
225 $GLOBALS['TSFE']->register['SWORD_PARAMS'] = $this->get_searchwords();
226 $total = $this->res_count;
227 $rangeLow = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($spointer + 1, 1, $total);
228 $rangeHigh = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($spointer + $theRange, 1, $total);
229 // prev/next url:
230 $target = isset($conf['target.']) ? $this->cObj->stdWrap($conf['target'], $conf['target.']) : $conf['target'];
231 $LD = $GLOBALS['TSFE']->tmpl->linkData($GLOBALS['TSFE']->page, $target, 1, '', '', $this->cObj->getClosestMPvalueForPage($GLOBALS['TSFE']->page['uid']));
232 $targetPart = $LD['target'] ? ' target="' . htmlspecialchars($LD['target']) . '"' : '';
233 $urlParams = $this->cObj->URLqMark($LD['totalURL'], '&sword=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('sword')) . '&scols=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('scols')) . '&stype=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('stype')) . '&scount=' . $total);
234 // substitution:
235 $result = str_replace(
236 array(
237 '###RANGELOW###',
238 '###RANGEHIGH###',
239 '###TOTAL###'
240 ),
241 array(
242 $rangeLow,
243 $rangeHigh,
244 $total
245 ),
246 $this->cObj->cObjGetSingle($conf['layout'], $conf['layout.'], 'layout')
247 );
248 if ($rangeHigh < $total) {
249 $next = $this->cObj->cObjGetSingle($conf['next'], $conf['next.'], 'next');
250 $next = '<a href="' . htmlspecialchars(($urlParams . '&spointer=' . ($spointer + $theRange))) . '"' . $targetPart . $GLOBALS['TSFE']->ATagParams . '>' . $next . '</a>';
251 } else {
252 $next = '';
253 }
254 $result = str_replace('###NEXT###', $next, $result);
255 if ($rangeLow > 1) {
256 $prev = $this->cObj->cObjGetSingle($conf['prev'], $conf['prev.'], 'prev');
257 $prev = '<a href="' . htmlspecialchars(($urlParams . '&spointer=' . ($spointer - $theRange))) . '"' . $targetPart . $GLOBALS['TSFE']->ATagParams . '>' . $prev . '</a>';
258 } else {
259 $prev = '';
260 }
261 $result = str_replace('###PREV###', $prev, $result);
262 // Searching result
263 $theValue = $this->cObj->cObjGetSingle($conf['resultObj'], $conf['resultObj.'], 'resultObj');
264 /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */
265 $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
266 $cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
267 $renderCode = '';
268 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($this->result)) {
269 // versionOL() here? This is search result displays, is that possible to preview anyway?
270 // Or are records selected here already future versions?
271 $cObj->start($row);
272 $renderCode .= $cObj->cObjGetSingle($conf['renderObj'], $conf['renderObj.'], 'renderObj');
273 }
274 $renderWrap = isset($conf['renderWrap.']) ? $this->cObj->stdWrap($conf['renderWrap'], $conf['renderWrap.']) : $conf['renderWrap'];
275 $theValue .= $this->cObj->wrap($renderCode, $renderWrap);
276 $theValue = str_replace('###RESULT###', $theValue, $result);
277 } else {
278 $theValue = $this->cObj->cObjGetSingle($conf['noResultObj'], $conf['noResultObj.'], 'noResultObj');
279 }
280 $GLOBALS['TT']->setTSlogMessage('Search in fields: ' . $this->listOfSearchFields);
281 // Wrapping
282 $content = $theValue;
283 $wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
284 if ($wrap) {
285 $content = $this->cObj->wrap($content, $wrap);
286 }
287 if (isset($conf['stdWrap.'])) {
288 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
289 }
290 // Returning, do not cache the result of the search
291 $GLOBALS['TSFE']->set_no_cache('Search result page');
292 return $content;
293 }
294 return '';
295 }
296
297 /**
298 * Creates the $this->tables-array.
299 * The 'pages'-table is ALWAYS included as the search is page-based. Apart from this there may be one and only one table, joined with the pages-table. This table is the first table mentioned in the requested-list. If any more tables are set here, they are ignored.
300 *
301 * @param string $requestedCols is a list (-) of columns that we want to search. This could be input from the search-form (see TypoScript documentation)
302 * @param string $allowedCols $allowedCols: is the list of columns, that MAY be searched. All allowed cols are set as result-fields. All requested cols MUST be in the allowed-fields list.
303 * @return void
304 */
305 public function register_tables_and_columns($requestedCols, $allowedCols) {
306 $rCols = $this->explodeCols($requestedCols);
307 $aCols = $this->explodeCols($allowedCols);
308 foreach ($rCols as $k => $v) {
309 $rCols[$k] = trim($v);
310 if (in_array($rCols[$k], $aCols)) {
311 $parts = explode('.', $rCols[$k]);
312 $this->tables[$parts[0]]['searchfields'][] = $parts[1];
313 }
314 }
315 $this->tables['pages']['primary_key'] = 'uid';
316 $this->tables['pages']['resultfields'][] = 'uid';
317 unset($this->tables['pages']['fkey']);
318 foreach ($aCols as $k => $v) {
319 $aCols[$k] = trim($v);
320 $parts = explode('.', $aCols[$k]);
321 $this->tables[$parts[0]]['resultfields'][] = $parts[1] . ' AS ' . str_replace('.', '_', $aCols[$k]);
322 $this->tables[$parts[0]]['fkey'] = 'pid';
323 }
324 $this->fTable = '';
325 foreach ($this->tables as $t => $v) {
326 if ($t != 'pages') {
327 if (!$this->fTable) {
328 $this->fTable = $t;
329 } else {
330 unset($this->tables[$t]);
331 }
332 }
333 }
334 }
335
336 /**
337 * Function that can convert the syntax for entering which tables/fields the search should be conducted in.
338 *
339 * @param string $in This is the code-line defining the tables/fields to search. Syntax: '[table1].[field1]-[field2]-[field3] : [table2].[field1]-[field2]'
340 * @return array An array where the values is "[table].[field]" strings to search
341 * @see register_tables_and_columns()
342 */
343 public function explodeCols($in) {
344 $theArray = explode(':', $in);
345 $out = array();
346 foreach ($theArray as $val) {
347 $val = trim($val);
348 $parts = explode('.', $val);
349 if ($parts[0] && $parts[1]) {
350 $subparts = explode('-', $parts[1]);
351 foreach ($subparts as $piece) {
352 $piece = trim($piece);
353 if ($piece) {
354 $out[] = $parts[0] . '.' . $piece;
355 }
356 }
357 }
358 }
359 return $out;
360 }
361
362 /**
363 * Takes a search-string (WITHOUT SLASHES or else it'll be a little sppooky , NOW REMEMBER to unslash!!)
364 * Sets up $this->sword_array op with operators.
365 * This function uses $this->operator_translate_table as well as $this->default_operator
366 *
367 * @param string $sword The input search-word string.
368 * @return void
369 */
370 public function register_and_explode_search_string($sword) {
371 $sword = trim($sword);
372 if ($sword) {
373 $components = $this->split($sword);
374 // the searchword is stored here during the loop
375 $s_sword = '';
376 if (is_array($components)) {
377 $i = 0;
378 $lastoper = '';
379 foreach ($components as $key => $val) {
380 $operator = $this->get_operator($val);
381 if ($operator) {
382 $lastoper = $operator;
383 } elseif (strlen($val) > 1) {
384 // A searchword MUST be at least two characters long!
385 $this->sword_array[$i]['sword'] = $val;
386 $this->sword_array[$i]['oper'] = $lastoper ?: $this->default_operator;
387 $lastoper = '';
388 $i++;
389 }
390 }
391 }
392 }
393 }
394
395 /**
396 * Used to split a search-word line up into elements to search for. This function will detect boolean words like AND and OR, + and -, and even find sentences encapsulated in ""
397 * This function could be re-written to be more clean and effective - yet it's not that important.
398 *
399 * @param string $origSword The raw sword string from outside
400 * @param string $specchars Special chars which are used as operators (+- is default)
401 * @param string $delchars Special chars which are deleted if the append the searchword (+-., is default)
402 * @return mixed Returns an ARRAY if there were search words, otherwise the return value may be unset.
403 */
404 public function split($origSword, $specchars = '+-', $delchars = '+.,-') {
405 $sword = $origSword;
406 $specs = '[' . preg_quote($specchars, '/') . ']';
407 // As long as $sword is TRUE (that means $sword MUST be reduced little by little until its empty inside the loop!)
408 while ($sword) {
409 // There was a double-quote and we will then look for the ending quote.
410 if (preg_match('/^"/', $sword)) {
411 // Removes first double-quote
412 $sword = preg_replace('/^"/', '', $sword);
413 // Removes everything till next double-quote
414 preg_match('/^[^"]*/', $sword, $reg);
415 // reg[0] is the value, should not be trimmed
416 $value[] = $reg[0];
417 $sword = preg_replace('/^' . preg_quote($reg[0], '/') . '/', '', $sword);
418 // Removes last double-quote
419 $sword = trim(preg_replace('/^"/', '', $sword));
420 } elseif (preg_match('/^' . $specs . '/', $sword, $reg)) {
421 $value[] = $reg[0];
422 // Removes = sign
423 $sword = trim(preg_replace('/^' . $specs . '/', '', $sword));
424 } elseif (preg_match('/[\\+\\-]/', $sword)) {
425 // Check if $sword contains + or -
426 // + and - shall only be interpreted as $specchars when there's whitespace before it
427 // otherwise it's included in the searchword (e.g. "know-how")
428 // explode $sword to single words
429 $a_sword = explode(' ', $sword);
430 // get first word
431 $word = array_shift($a_sword);
432 // Delete $delchars at end of string
433 $word = rtrim($word, $delchars);
434 // add searchword to values
435 $value[] = $word;
436 // re-build $sword
437 $sword = implode(' ', $a_sword);
438 } else {
439 // There are no double-quotes around the value. Looking for next (space) or special char.
440 preg_match('/^[^ ' . preg_quote($specchars, '/') . ']*/', $sword, $reg);
441 // Delete $delchars at end of string
442 $word = rtrim(trim($reg[0]), $delchars);
443 $value[] = $word;
444 $sword = trim(preg_replace('/^' . preg_quote($reg[0], '/') . '/', '', $sword));
445 }
446 }
447 return $value;
448 }
449
450 /**
451 * This creates the search-query.
452 * In TypoScript this is used for searching only records not hidden, start/endtimed and fe_grouped! (enable-fields, see tt_content)
453 * Sets $this->queryParts
454 *
455 * @param string $endClause Some extra conditions that the search must match.
456 * @return bool Returns TRUE no matter what - sweet isn't it!
457 * @access private
458 * @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::SEARCHRESULT()
459 */
460 public function build_search_query($endClause) {
461 if (is_array($this->tables)) {
462 $tables = $this->tables;
463 $primary_table = '';
464 // Primary key table is found.
465 foreach ($tables as $key => $val) {
466 if ($tables[$key]['primary_key']) {
467 $primary_table = $key;
468 }
469 }
470 if ($primary_table) {
471 // Initialize query parts:
472 $this->queryParts = array(
473 'SELECT' => '',
474 'FROM' => '',
475 'WHERE' => '',
476 'GROUPBY' => '',
477 'ORDERBY' => '',
478 'LIMIT' => ''
479 );
480 // Find tables / field names to select:
481 $fieldArray = array();
482 $tableArray = array();
483 foreach ($tables as $key => $val) {
484 $tableArray[] = $key;
485 $resultfields = $tables[$key]['resultfields'];
486 if (is_array($resultfields)) {
487 foreach ($resultfields as $key2 => $val2) {
488 $fieldArray[] = $key . '.' . $val2;
489 }
490 }
491 }
492 $this->queryParts['SELECT'] = implode(',', $fieldArray);
493 $this->queryParts['FROM'] = implode(',', $tableArray);
494 // Set join WHERE parts:
495 $whereArray = array();
496 $primary_table_and_key = $primary_table . '.' . $tables[$primary_table]['primary_key'];
497 $primKeys = array();
498 foreach ($tables as $key => $val) {
499 $fkey = $tables[$key]['fkey'];
500 if ($fkey) {
501 $primKeys[] = $key . '.' . $fkey . '=' . $primary_table_and_key;
502 }
503 }
504 if (count($primKeys)) {
505 $whereArray[] = '(' . implode(' OR ', $primKeys) . ')';
506 }
507 // Additional where clause:
508 if (trim($endClause)) {
509 $whereArray[] = trim($endClause);
510 }
511 // Add search word where clause:
512 $query_part = $this->build_search_query_for_searchwords();
513 if (!$query_part) {
514 $query_part = '(0!=0)';
515 }
516 $whereArray[] = '(' . $query_part . ')';
517 // Implode where clauses:
518 $this->queryParts['WHERE'] = implode(' AND ', $whereArray);
519 // Group by settings:
520 if ($this->group_by) {
521 if ($this->group_by == 'PRIMARY_KEY') {
522 $this->queryParts['GROUPBY'] = $primary_table_and_key;
523 } else {
524 $this->queryParts['GROUPBY'] = $this->group_by;
525 }
526 }
527 }
528 }
529 }
530
531 /**
532 * Creates the part of the SQL-sentence, that searches for the search-words ($this->sword_array)
533 *
534 * @return string Part of where class limiting result to the those having the search word.
535 * @access private
536 */
537 public function build_search_query_for_searchwords() {
538 if (is_array($this->sword_array)) {
539 $main_query_part = array();
540 foreach ($this->sword_array as $key => $val) {
541 $s_sword = $this->sword_array[$key]['sword'];
542 // Get subQueryPart
543 $sub_query_part = array();
544 $this->listOfSearchFields = '';
545 foreach ($this->tables as $key3 => $val3) {
546 $searchfields = $this->tables[$key3]['searchfields'];
547 if (is_array($searchfields)) {
548 foreach ($searchfields as $key2 => $val2) {
549 $this->listOfSearchFields .= $key3 . '.' . $val2 . ',';
550 $sub_query_part[] = $key3 . '.' . $val2 . ' LIKE \'%' . $GLOBALS['TYPO3_DB']->quoteStr($s_sword, $key3) . '%\'';
551 }
552 }
553 }
554 if (count($sub_query_part)) {
555 $main_query_part[] = $this->sword_array[$key]['oper'];
556 $main_query_part[] = '(' . implode(' OR ', $sub_query_part) . ')';
557 }
558 }
559 if (count($main_query_part)) {
560 // Remove first part anyways.
561 unset($main_query_part[0]);
562 return implode(' ', $main_query_part);
563 }
564 }
565 }
566
567 /**
568 * This returns an SQL search-operator (eg. AND, OR, NOT) translated from the current localized set of operators (eg. in danish OG, ELLER, IKKE).
569 *
570 * @param string $operator The possible operator to find in the internal operator array.
571 * @return string If found, the SQL operator for the localized input operator.
572 * @access private
573 */
574 public function get_operator($operator) {
575 $operator = trim($operator);
576 $op_array = $this->operator_translate_table;
577 if ($this->operator_translate_table_caseinsensitive) {
578 // case-conversion is charset insensitive, but it doesn't spoil
579 // anything if input string AND operator table is already converted
580 $operator = strtolower($operator);
581 }
582 foreach ($op_array as $key => $val) {
583 $item = $op_array[$key][0];
584 if ($this->operator_translate_table_caseinsensitive) {
585 // See note above.
586 $item = strtolower($item);
587 }
588 if ($operator == $item) {
589 return $op_array[$key][1];
590 }
591 }
592 }
593
594 /**
595 * Counts the results and sets the result in $this->res_count
596 *
597 * @return bool TRUE, if $this->query was found
598 */
599 public function count_query() {
600 if (is_array($this->queryParts)) {
601 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($this->queryParts['SELECT'], $this->queryParts['FROM'], $this->queryParts['WHERE'], $this->queryParts['GROUPBY']);
602 $this->res_count = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
603 return TRUE;
604 }
605 }
606
607 /**
608 * Executes the search, sets result pointer in $this->result
609 *
610 * @return bool TRUE, if $this->query was set and query performed
611 */
612 public function execute_query() {
613 if (is_array($this->queryParts)) {
614 $this->result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($this->queryParts);
615 return TRUE;
616 }
617 }
618
619 /**
620 * Returns URL-parameters with the current search words.
621 * Used when linking to result pages so that search words can be highlighted.
622 *
623 * @return string URL-parameters with the searchwords
624 */
625 public function get_searchwords() {
626 $SWORD_PARAMS = '';
627 if (is_array($this->sword_array)) {
628 foreach ($this->sword_array as $key => $val) {
629 $SWORD_PARAMS .= '&sword_list[]=' . rawurlencode($val['sword']);
630 }
631 }
632 return $SWORD_PARAMS;
633 }
634
635 /**
636 * Returns an array with the search words in
637 *
638 * @return array IF the internal sword_array contained search words it will return these, otherwise "void
639 */
640 public function get_searchwordsArray() {
641 if (is_array($this->sword_array)) {
642 foreach ($this->sword_array as $key => $val) {
643 $swords[] = $val['sword'];
644 }
645 }
646 return $swords;
647 }
648
649 }