Example #1
0
 public function actionShow()
 {
     $element = new Search($this->di->db);
     $out = $element->find(['id' => $this->di->router->get('id')]);
     if ($out) {
         $values = explode("\t", htmlspecialchars_decode($out['elements'], ENT_QUOTES));
         $this->set('title', 'Найденные значения');
         $this->render('show', ['page_title' => $this->get('title'), 'url' => $out['url'], 'count' => $out['count'], 'values' => $values]);
     } else {
         $this->returnError();
     }
 }
Example #2
0
 public function getSearchResult($db, $types)
 {
     $record = new Search($db);
     $link = $this->post->get('link');
     $type = (int) $this->post->get('type');
     $text = $this->post->get('text');
     if (strpos($link, 'http') === false) {
         $link = 'http://' . $link;
     }
     $regexp = [];
     foreach ($types as $t) {
         $regexp[$t['id']] = is_callable($t['regexp']) ? $t['regexp']($text) : $t['regexp'];
     }
     /* 			1 => '/(<a.*?\/a>)/',
     			2 => '/(<img.*?>)/',
     			3 => '/'.preg_quote($text, '/').'/', */
     if ($element = $record->find(['type' => $type, 'url' => $link])) {
         return [1, "На этой странице уже производился поиск: <a href=\"/elements/show/" . $element['id'] . "/\">перейти</a>"];
     }
     if (!isset($regexp[$type])) {
         return [-1, 'Недействительный тип поиска'];
     }
     if (!($siteSrc = $this->getSearchData($link))) {
         return [-1, 'Неверный адрес сайта'];
     }
     preg_match_all($regexp[$type], $siteSrc, $match);
     if (0 == count($match[0])) {
         return [-1, 'Не было найдено ни одного совпадения'];
     }
     $record->set('url', $link);
     $record->set('type', $type);
     $record->set('elements', join("\t", $match[0]));
     $record->set('count', count($match[0]));
     if ($id = $record->save()) {
         return [1, "Было найдено совпадений: " . count($match[0]) . " (<a href=\"/elements/show/" . $id . "/\">перейти</a>)"];
     }
     return [0, 'Произошла ошибка'];
 }
Example #3
0
 public function doAjaxSearch()
 {
     $result = \models\Search::searchFor(CW::$app->request->get('term'), CW::$app->request->get('page'));
     return json_encode($result);
 }
Example #4
0
 protected function search($arg = null)
 {
     $http = new Http();
     $search = $http->get('search');
     $search_m = new Search($search);
     $pag = new Pagination(2, $search_m->getNumberoOfMached());
     $products = $search_m->getProducts(2, $pag->page($arg[1]));
     $next = $pag->next();
     $prev = $pag->prev();
     $this->render('search', array('categories' => $this->categories, 'products' => $products, 'ids' => $this->category_ids, 'slider' => $this->slider, 'd_product' => $this->d_product, 'next' => $next, 'prev' => $prev, 'action' => $this->action, 'page' => $arg[1], 'tab' => $arg[0], 'search' => $search));
 }