static function fullGen($str) { static $cache = array(); if (isset($cache[$str])) { return $cache[$str]; } $arr = hq::simpleGen($str); $res = array(); foreach ($arr as $cur) { $t = hq::simpleGen($cur, '{', '}'); $res[$t[0]] = $t; } $cache[$str] = $res; return $res; }
static function findQueryOnce() { //Парcим текущий запрос $ref = false; if (isset($_SERVER['HTTP_REFERER'])) { $ref = $_SERVER['HTTP_REFERER']; if (!$ref || count(explode('/', $ref)) === 1) { $ref = false; } } $base = false; $params = array(); if ($ref) { $arr = explode('?', $ref, 2); if (count($arr) === 2) { $base = $arr[0]; $arr = explode('&', $arr[1]); foreach ($arr as $str) { $str = explode('=', $str, 2); if (isset($str[1])) { $params[$str[0]] = $str[1]; } } //Яндекс $arr = explode('/', $ref); $arr = explode('.', $arr[2]); if (($arr[0] === 'yandex' || $arr[0] === 'ya') && strpos($ref, 'yandsearch') && isset($params['text']) && $params['text']) { return hq::Utf8_To_Cp1251(urldecode($params['text'])); } } else { $ref = false; } } foreach (hq::$queryDetect as $str => $encoding) { $arr = hq::simpleGen($str); foreach ($arr as $str) { if (strpos($str, '://')) { //из реферера if ($ref) { $str = explode('?', $str, 2); if ($base === $str[0] && isset($params[$str[1]]) && $params[$str[1]]) { if (hq::isCp1251($encoding)) { return urldecode($params[$str[1]]); } else { return hq::Utf8_To_Cp1251(urldecode($params[$str[1]])); } } } } else { if (isset($_GET[$str]) && $_GET[$str]) { //из гет параметра if (hq::isCp1251($encoding)) { return $_GET[$str]; } else { return hq::Utf8_To_Cp1251($_GET[$str]); } } } } } }