public static function postRaw($strKey) { $strCacheKey = 'postRaw'; if (!isset(static::$arrCache[$strCacheKey][$strKey])) { $varValue = static::findPost($strKey); if ($varValue === null) { return $varValue; } $varValue = static::preserveBasicEntities($varValue); $varValue = static::xssClean($varValue); if (TL_MODE != 'BE') { $varValue = static::encodeInsertTags($varValue); } static::$arrCache[$strCacheKey][$strKey] = $varValue; } return static::$arrCache[$strCacheKey][$strKey]; }
/** * Return a search form that allows to search results using regular expressions * * @return string */ protected function searchMenu() { $searchFields = array(); /** @var AttributeBagInterface $objSessionBag */ $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend'); $session = $objSessionBag->all(); // Get search fields foreach ($GLOBALS['TL_DCA'][$this->strTable]['fields'] as $k => $v) { if ($v['search']) { $searchFields[] = $k; } } // Return if there are no search fields if (empty($searchFields)) { return ''; } // Store search value in the current session if (\Input::post('FORM_SUBMIT') == 'tl_filters') { $strField = \Input::post('tl_field', true); $strKeyword = ltrim(\Input::postRaw('tl_value'), '*'); // Make sure the regular expression is valid if ($strKeyword != '') { try { $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE " . $strField . " REGEXP ?")->limit(1)->execute($strKeyword); } catch (\Exception $e) { $strKeyword = ''; } } $session['search'][$this->strTable]['field'] = $strField; $session['search'][$this->strTable]['value'] = $strKeyword; $objSessionBag->replace($session); } elseif ($session['search'][$this->strTable]['value'] != '') { $strPattern = "CAST(%s AS CHAR) REGEXP ?"; if (substr(\Config::get('dbCollation'), -3) == '_ci') { $strPattern = "LOWER(CAST(%s AS CHAR)) REGEXP LOWER(?)"; } $fld = $session['search'][$this->strTable]['field']; if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey'])) { list($t, $f) = explode('.', $GLOBALS['TL_DCA'][$this->strTable]['fields'][$fld]['foreignKey']); $this->procedure[] = "(" . sprintf($strPattern, $fld) . " OR " . sprintf($strPattern, "(SELECT {$f} FROM {$t} WHERE {$t}.id={$this->strTable}.{$fld})") . ")"; $this->values[] = $session['search'][$this->strTable]['value']; } else { $this->procedure[] = sprintf($strPattern, $fld); } $this->values[] = $session['search'][$this->strTable]['value']; } $options_sorter = array(); foreach ($searchFields as $field) { $option_label = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['label'][0] ?: (is_array($GLOBALS['TL_LANG']['MSC'][$field]) ? $GLOBALS['TL_LANG']['MSC'][$field][0] : $GLOBALS['TL_LANG']['MSC'][$field]); $options_sorter[Utf8::toAscii($option_label) . '_' . $field] = ' <option value="' . specialchars($field) . '"' . ($field == $session['search'][$this->strTable]['field'] ? ' selected="selected"' : '') . '>' . $option_label . '</option>'; } // Sort by option values $options_sorter = natcaseksort($options_sorter); $active = $session['search'][$this->strTable]['value'] != '' ? true : false; return ' <div class="tl_search tl_subpanel"> <strong>' . $GLOBALS['TL_LANG']['MSC']['search'] . ':</strong> <select name="tl_field" class="tl_select' . ($active ? ' active' : '') . '"> ' . implode("\n", $options_sorter) . ' </select> <span> = </span> <input type="search" name="tl_value" class="tl_text' . ($active ? ' active' : '') . '" value="' . specialchars($session['search'][$this->strTable]['value']) . '"> </div>'; }