Index: core/kernel/db/cat_event_handler.php
===================================================================
--- core/kernel/db/cat_event_handler.php
+++ core/kernel/db/cat_event_handler.php
@@ -1105,26 +1105,13 @@
$keywords = $this->Application->unescapeRequestVariable(trim($this->Application->GetVar('keywords')));
- $query_object = $this->Application->recallObject('HTTPQuery');
- /* @var $query_object kHTTPQuery */
-
- $sql = 'SHOW TABLES LIKE "'.$search_table.'"';
+ $search_helper = $this->Application->recallObject('SearchHelper');
+ /** @var kSearchHelper $search_helper */
- if(!isset($query_object->Get['keywords']) &&
- !isset($query_object->Post['keywords']) &&
- $this->Conn->Query($sql))
- {
- return; // used when navigating by pages or changing sorting in search results
- }
- if(!$keywords || strlen($keywords) < $this->Application->ConfigValue('Search_MinKeyword_Length'))
- {
- $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table);
- $this->Application->SetVar('keywords_too_short', 1);
- return; // if no or too short keyword entered, doing nothing
+ if ( !$search_helper->needNewSearch($search_table, $keywords) ) {
+ return;
}
- $this->Application->StoreVar('keywords', $keywords);
-
$this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search
$event->setPseudoClass('_List');
@@ -1236,9 +1223,6 @@
}
// keyword string processing
- $search_helper = $this->Application->recallObject('SearchHelper');
- /* @var $search_helper kSearchHelper */
-
$where_clause = Array ();
foreach ($field_list as $field) {
if (preg_match('/^' . preg_quote($items_table, '/') . '\.(.*)/', $field, $regs)) {
Index: core/kernel/db/db_event_handler.php
===================================================================
--- core/kernel/db/db_event_handler.php
+++ core/kernel/db/db_event_handler.php
@@ -829,7 +829,7 @@
*/
protected function _passListParams($event, $skip_var)
{
- $param_names = array_diff(Array ('page', 'per_page', 'sort_by'), Array ($skip_var));
+ $param_names = array_diff(array('page', 'per_page', 'sort_by', 'keywords'), array($skip_var));
$list_helper = $this->Application->recallObject('ListHelper');
/* @var $list_helper ListHelper */
@@ -861,6 +861,13 @@
$event->SetRedirectParam('sort_by', $value);
}
break;
+
+ case 'keywords':
+ if ( $value ) {
+ $value = $this->Application->unescapeRequestVariable($value);
+ $event->SetRedirectParam('keywords', kUtil::escape($value, kUtil::ESCAPE_URL));
+ }
+ break;
}
}
}
Index: core/kernel/db/db_tag_processor.php
===================================================================
--- core/kernel/db/db_tag_processor.php
+++ core/kernel/db/db_tag_processor.php
@@ -681,7 +681,8 @@
}
if ( $has_next_page ) {
- $block_params = Array ('name' => $this->SelectParam($params, 'render_as,block'));
+ $block_params = $this->prepareTagParams($params);
+ $block_params['name'] = $this->SelectParam($params, 'render_as,block');
return $this->Application->ParseBlock($block_params);
}
@@ -754,6 +755,16 @@
unset($params['per_page']);
}
+ // Process keywords.
+ $keywords = $this->Application->GetVar('keywords');
+
+ if ( $keywords ) {
+ $params['keywords'] = kUtil::escape(
+ $this->Application->unescapeRequestVariable($keywords),
+ kUtil::ESCAPE_URL
+ );
+ }
+
if (!array_key_exists('pass', $params)) {
$params['pass'] = 'm,' . $prefix_special;
}
Index: core/kernel/processors/main_processor.php
===================================================================
--- core/kernel/processors/main_processor.php
+++ core/kernel/processors/main_processor.php
@@ -1223,7 +1223,7 @@
function GetUrlHiddenFileds($params)
{
- $vars = Array ('page', 'per_page', 'sort_by');
+ $vars = array('page', 'per_page', 'sort_by', 'keywords');
$ret = '';
if (array_key_exists('skip', $params)) {
@@ -1283,4 +1283,22 @@
{
return $this->Application->Parser->blockFound($params['name']);
}
+
+ /**
+ * Search link.
+ *
+ * @param array $params Tag params.
+ *
+ * @return string
+ */
+ protected function SearchLink(array $params)
+ {
+ $params['keywords'] = kUtil::escape(
+ kUtil::unescape($this->Application->GetVar('keywords'), kUtil::ESCAPE_HTML),
+ kUtil::ESCAPE_URL
+ );
+
+ return $this->Application->ProcessParsedTag('m', 'Link', $params);
+ }
+
}
Index: core/units/categories/categories_event_handler.php
===================================================================
--- core/units/categories/categories_event_handler.php
+++ core/units/categories/categories_event_handler.php
@@ -2454,25 +2454,13 @@
$keywords = $this->Application->unescapeRequestVariable(trim($this->Application->GetVar('keywords')));
- $query_object = $this->Application->recallObject('HTTPQuery');
- /* @var $query_object kHTTPQuery */
-
- $sql = 'SHOW TABLES LIKE "'.$search_table.'"';
+ $search_helper = $this->Application->recallObject('SearchHelper');
+ /** @var kSearchHelper $search_helper */
- if ( !isset($query_object->Get['keywords']) && !isset($query_object->Post['keywords']) && $this->Conn->Query($sql) ) {
- // used when navigating by pages or changing sorting in search results
+ if ( !$search_helper->needNewSearch($search_table, $keywords) ) {
return;
}
- if(!$keywords || strlen($keywords) < $this->Application->ConfigValue('Search_MinKeyword_Length'))
- {
- $this->Conn->Query('DROP TABLE IF EXISTS '.$search_table);
- $this->Application->SetVar('keywords_too_short', 1);
- return; // if no or too short keyword entered, doing nothing
- }
-
- $this->Application->StoreVar('keywords', $keywords);
-
$this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search
$keywords = strtr($keywords, Array('%' => '\\%', '_' => '\\_'));
@@ -2586,9 +2574,6 @@
}
// keyword string processing
- $search_helper = $this->Application->recallObject('SearchHelper');
- /* @var $search_helper kSearchHelper */
-
$where_clause = Array ();
foreach ($field_list as $field) {
if (preg_match('/^' . preg_quote($items_table, '/') . '\.(.*)/', $field, $regs)) {
Index: core/units/helpers/search_helper.php
===================================================================
--- core/units/helpers/search_helper.php
+++ core/units/helpers/search_helper.php
@@ -802,4 +802,49 @@
$object->addFilter('includes_filter_h', $includes_or_filter_h, kDBList::HAVING_FILTER);
$object->addFilter('excepts_filter_h', $excepts_and_filter_h, kDBList::HAVING_FILTER);
}
- }
\ No newline at end of file
+
+ /**
+ * Determines if new search required.
+ *
+ * @param string $search_table Search table.
+ * @param string $keywords Keywords.
+ *
+ * @return boolean
+ */
+ public function needNewSearch($search_table, $keywords)
+ {
+ if ( $this->Application->GetVar('session_keywords') === false ) {
+ $this->Application->SetVar('session_keywords', $this->Application->RecallVar('keywords', ''));
+ }
+
+ $sql = 'SHOW TABLES LIKE "' . $search_table . '"';
+ $request_keywords = $this->Application->GetVarDirect('keywords', 'Get');
+
+ if ( !$request_keywords ) {
+ $request_keywords = $this->Application->GetVarDirect('keywords', 'Post');
+ }
+
+ $request_keywords_compare = $this->Application->unescapeRequestVariable(trim($request_keywords));
+ $session_keywords = $this->Application->GetVar('session_keywords');
+
+ if ( (!$request_keywords || $request_keywords_compare == $session_keywords)
+ && $this->Conn->Query($sql)
+ ) {
+ return false; // Used when navigating by pages or changing sorting in search results.
+ }
+
+ $this->Application->StoreVar('keywords', $request_keywords);
+
+ if ( !$keywords || strlen($keywords) < $this->Application->ConfigValue('Search_MinKeyword_Length') ) {
+ $this->Conn->Query('DROP TABLE IF EXISTS ' . $search_table);
+ $this->Application->SetVar('keywords_too_short', 1);
+
+ return false; // If no or too short keyword entered, doing nothing.
+ }
+
+ $this->Application->StoreVar('keywords', $keywords);
+
+ return true;
+ }
+
+ }
Index: themes/advanced/in-bulletin/elements/content_boxes/search_results.elm.tpl
===================================================================
--- themes/advanced/in-bulletin/elements/content_boxes/search_results.elm.tpl
+++ themes/advanced/in-bulletin/elements/content_boxes/search_results.elm.tpl
@@ -2,7 +2,7 @@
- ">
- + |