public function get($limit = 0) { $opt = $this->nav_array($limit ?: Bootstrap::$main->getConfig('merlin.search.limit')); $opt['totalPrice'] = Bootstrap::$main->session('total'); $site = Bootstrap::$main->getConfig('site'); $config = $this->getConfig(); Bootstrap::$main->system('cfg'); $cond = $this->data('q') ? $this->q2cond($this->data('q')) : []; Bootstrap::$main->system('q2c'); Bootstrap::$main->session('q', $this->data('q')); $social_url = 'http://' . $_SERVER['HTTP_HOST'] . '/'; $social_text = ''; $social_words = []; if (count($cond)) { if (isset($cond[1])) { foreach ($cond[1] as $arr) { foreach ($arr as $ar) { if (isset($social_words[$ar])) { continue; } $social_words[$ar] = true; $social_url .= str_replace(' ', '-', $ar) . '/'; $social_text .= $ar . ' '; } } } if (!isset($cond[0]['type'])) { $cond[0]['type'] = 'F'; } if (!isset($cond[0]['adt'])) { $cond[0]['adt'] = 2; } $cond[0]['total'] = $opt['totalPrice'] ? true : false; $rowattr = []; $rowattr['total'] = $opt['totalPrice']; $results = $this->results($cond, $opt['limit'], $opt['offset'], $config, $rowattr); $offers = $results['offers']; $result = $results['result']; $offers2 = $offers; $opt['next_offset'] = $opt['offset'] + $opt['limit']; $limit = $opt['limit']; $security = 20; while (count($offers2['result']) == $limit && count($result) < $opt['limit']) { $offset = $opt['next_offset']; $limit = $opt['limit'] - count($result); $opt['next_offset'] += $limit; $results = $this->results($cond, $limit, $offset, $config, $rowattr); if (count($results['result'])) { $result = array_merge($result, $results['result']); } $offers2 = $results['offers']; if (!$security--) { break; } } if (!isset($cond['memcache']) && !$this->data('debug')) { @Tools::log('query-' . $site, ['q' => $this->data('q'), 'count' => $offers['count'], 'cond' => $cond]); if (isset($cond[2]) && is_array($cond[2]) && count($cond[2])) { foreach ($cond[2] as $w) { $query = new queryModel(); $query->datetime = date('c'); $query->q = $this->data('q'); $query->site = Bootstrap::$main->getConfig('site'); $query->word = $w; $query->ip = Bootstrap::$main->ip; $query->save(); } } } } else { $offers = ['result' => [], 'count' => 0]; $result = []; $opt['next_offset'] = $opt['offset']; } Bootstrap::$main->system('mds'); $social_subject = trim(str_replace('{q}', trim($social_text), Bootstrap::$main->getConfig('mail.subject'))); $opt['f'] = 'https://www.facebook.com/sharer/sharer.php?t=' . urlencode($social_subject) . '&u=' . urlencode($social_url); $opt['m'] = 'mailto:?subject=' . urlencode($social_subject) . '&body=' . urlencode($social_url); $opt['results'] = 'Wyniki: '; if (isset($offers['count'])) { if ($offers['count'] >= 1000) { $opt['results'] .= 'ponad 1000'; } else { $opt['results'] .= $offers['count']; } } $opt['change'] = isset($cond[3]) && strlen($cond[3]) ? $cond[3] : ''; if (isset($cond[2]) && is_array($cond[2])) { foreach ($cond[2] as $unknown) { if (strstr($opt['change'], $unknown)) { $opt['change'] = str_replace($unknown, "<i>{$unknown}</i>", $opt['change']); } else { if (strlen($opt['change'])) { $opt['change'] .= ' '; } $opt['change'] .= "<i>{$unknown}</i>"; } } } if ($this->data('debug')) { $ret = ['conditions' => $cond, 'result' => $result]; if ($this->data('debug') == 2) { $ret['merlin'] = $this->merlin->debug; } mydie($ret); } return array('status' => true, 'options' => $opt, 'data' => $result); }