protected function getConfig() { $token = 'config.' . Bootstrap::$main->getConfig('site'); $config = Tools::memcache($token); if ($config && !$this->data('debug')) { return $config; } $config = json_config(__DIR__ . '/../config/merlin.json', false, false); $config['words'] = []; $config['words-with-space'] = []; $extended = ['number']; foreach ($config['dict'] as $field => $fields) { foreach ($fields as $code => $values) { foreach ($values['words'] as $d) { $w = []; if ($field != 'extended') { $w['field'] = $field; } foreach ($extended as $f) { if (isset($values[$f])) { $w[$f] = $values[$f]; } } $value = 'value'; if (isset($values['name'])) { $value = $values['name']; } if (isset($values['evalue'])) { $w[$value] = '~' . $values['evalue']; } elseif (isset($values['value'])) { $w[$value] = $values['value']; } elseif (!in_array($field, $extended)) { $w[$value] = $code; } $config['words'][$d] = $w; } } } unset($config['dict']); //mydie($config['words']); $reg = $this->merlin->getRegions('F', null, $this->data('debug') ? false : true, true); $dest = []; $i = 0; $far = []; foreach ($reg as $r) { if (!isset($r['region'])) { $r['region'] = ''; } if (!isset($r['country'])) { continue; } $country = trim(mb_strtolower($r['country'], 'utf-8')); $region = trim(mb_strtolower($r['region'], 'utf-8')); if ($r['price'] >= Bootstrap::$main->getConfig('merlin.far.price') && !in_array($country, ['bułgaria', 'portugalia', 'hiszpania', 'włochy', 'grecja', 'francja', 'niemcy', 'cypr', 'chorwacja'])) { $far[] = $r['id']; } foreach ($config['dest_shit'] as $shit) { for ($ii = 0; $ii < 2; $ii++) { if (strstr($country, ' ') && strstr($country, $shit)) { $country = trim(str_replace($shit, '', $country)); } if (strstr($region, ' ') && strstr($region, $shit)) { $region = trim(str_replace($shit, '', $region)); } } } $i++; if (strstr($country, ' ') || strstr($region, ' ')) { continue; mydie($r, "{$country}:{$region}:{$i}/" . count($reg)); } foreach ([$country, $region] as $w) { if (!$w) { continue; } if (!isset($dest[$w])) { $dest[$w] = ['field' => 'dest', 'value' => $r['id']]; } else { $dest[$w]['value'] .= ',' . $r['id']; } $w2 = Tools::str_to_url($w); if ($w2 == $w) { continue; } $w = $w2; if (!isset($dest[$w])) { $dest[$w] = ['field' => 'dest', 'value' => $r['id']]; } else { $dest[$w]['value'] .= ',' . $r['id']; } } } foreach (['dest'] as $field) { foreach ($config[$field] as $code => $dep) { foreach ($dep as $d) { if (isset($dest[$d])) { $dest[$d]['value'] .= ',' . $code; } else { $dest[$d] = ['field' => 'dest', 'value' => $code]; } } } } foreach ($dest as $w => $r) { if (!isset($config['words'][$w])) { $config['words'][$w] = $r; } } $config['far'] = $far; if ($this->data('debug') == 1) { $hotels = $this->merlin->getFilters(['ofr_type' => 'F'], 'obj_xCode', $this->data('debug') ? false : true); Tools::log('hotels-' . $token, $hotels); $words = array_keys($config['words']); $hotel_map = []; foreach ($hotels as $hotel) { $hotel = str_replace(['+', ',', ';', '~', '(', ')', '"'], ' ', $hotel); $hotel = str_replace(["'"], '"', $hotel); $hotel = preg_replace('/\\s+/', ' ', trim($hotel)); $hotel = mb_strtolower($hotel, 'utf-8'); foreach (explode(' ', $hotel) as $h) { $h = Tools::str_to_url($h); if (strlen($h) < 4) { continue; } if (isset($config['words'][$h])) { continue; } if (isset($hotel_map[$h])) { continue; } $lev = false; foreach ($words as $w) { if (levenshtein($h, $w) <= 2) { $lev = true; break; } } if ($lev) { continue; } $hotel_map[$h] = ['field' => 'ftsName', 'value' => $h]; } } $config['hotels'] = $hotel_map; } //mydie($config,count($config['words'])); foreach (array_keys($config['words']) as $word) { if (strstr($word, ' ')) { $config['words-with-space'][] = $word; } } Tools::log('get-config', [$token]); return Tools::memcache($token, $config, 4 * 3600); }
<?php $_SERVER['backend_start'] = microtime(true); include __DIR__ . '/backend/include/all.php'; autoload([__DIR__ . '/classes', __DIR__ . '/controllers']); $config = json_config(__DIR__ . '/config/application.json'); $bootstrap = new Bootstrap($config); $root = $bootstrap->getRoot(); $uri = $_SERVER['REQUEST_URI']; if ($pos = strpos($uri, '?')) { $uri = substr($uri, 0, $pos); } $uri = substr($uri, strlen($root)); $q = urldecode(trim(str_replace(['-', '/', "'"], ' ', $uri))); $google_part = ''; $description = $q ? str_replace('{q}', $q, $bootstrap->getConfig('page.description')) : $bootstrap->getConfig('page.description0'); if (isset($_GET['_google']) || isset($_SERVER['HTTP_USER_AGENT']) && strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'google')) { if ($q) { $google_part = '<h1>' . $q . '</h1>' . "\n"; $template = new templateController(); $template->init(); $holidays = new holidaysController(0, ['q' => $q]); $holidays->init(); $tmpl = $template->get(false); $tmpl = preg_replace('~\\[if:[^\\]]+\\]~', '', $tmpl); $tmpl = preg_replace('~\\[endif:[^\\]]+\\]~', '', $tmpl); $tmpl = preg_replace('~\\[loop:[^\\]]+\\]~', '', $tmpl); $tmpl = preg_replace('~\\[endloop:[^\\]]+\\]~', '', $tmpl); $tmpl = str_replace('style="display:none"', '', $tmpl); $result = $holidays->get(10); foreach ($result['data'] as $rec) {