function run() { $q = $this->get_param('query'); if (empty($q)) { $q = functions::request_var('keyword'); } if (loader::in_ajax()) { $keyword = trim($q); } else { $keyword = trim(urldecode($q)); } $this->renderer->set_return('keyword', $keyword); $this->renderer->set_main_title('search'); if (empty($q)) { return; } if (strings::strlen($keyword) < 3) { $this->renderer->set_message('sat.search_too_short', array('result' => false)); $this->renderer->set_ajax_message('sat.search_too_short'); return false; } // make search and redirect to it $id = $this->make_search($keyword); // redirect to search results $url = $this->_controller->get_context()->get_router()->make_url('/search/' . $id . '/'); if (loader::in_ajax()) { $this->_controller->set_null_template(); $this->renderer->set_ajax_message($this->_found ? sprintf('По вашему запросу найдено %d записей', $this->_found) : 'Подходящих записей не найдено')->set_ajax_result($this->_found)->set_ajax_redirect($url); } else { functions::redirect($url); core::get_instance()->halt(); } }
function run() { $q = trim(urldecode($this->request->get('q'))); $q = core::lib('db')->escape($q); if (strings::strlen($q) < 2) { $this->renderer->set_ajax_result(false)->set_ajax_message('Короткое сообщение')->ajax_flush(false); return; } $pmod = $this->_controller->get_context(); $ph = $pmod->get_search_handle()->set_working_fields('keyword')->set_limit(10); if (!empty($q)) { $ph->set_where("keyword like '%{$q}%' AND c_count > 0"); } $sugg = $ph->load()->render(); core::get_instance()->ajax_answer($sugg); }
/** * Check route matched to uri * Extract params (only for regex <?Pname> routes) */ private function _is_route_matched($route, &$params) { $match = isset($route['match']) ? $route['match'] : false; $uri = $this->_uri; // wildcard: /url/blabla/* if ($match) { if ($match == '*') { $match = ''; $uri = ''; } else { if (strings::strpos($match, '*') !== false) { $match = strings::substr($match, 0, strings::strpos($match, '*')); $uri = strings::substr($uri, 0, strings::strlen($match)); } } } return isset($route['regex']) && preg_match($route['regex'], $this->_uri, $params) && array_shift($params) || $match !== false && $uri == $match; }