Пример #1
0
 protected function detectSiteSearchFromUrl($website, $parsedUrl)
 {
     $doRemoveSearchParametersFromUrl = true;
     $separator = '&';
     $count = $actionName = $categoryName = false;
     $keywordParameters = isset($website['sitesearch_keyword_parameters']) ? $website['sitesearch_keyword_parameters'] : array();
     $queryString = (!empty($parsedUrl['query']) ? $parsedUrl['query'] : '') . (!empty($parsedUrl['fragment']) ? $separator . $parsedUrl['fragment'] : '');
     $parametersRaw = UrlHelper::getArrayFromQueryString($queryString);
     // strtolower the parameter names for smooth site search detection
     $parameters = array();
     foreach ($parametersRaw as $k => $v) {
         $parameters[Common::mb_strtolower($k)] = $v;
     }
     // decode values if they were sent from a client using another charset
     $pageEncoding = $this->request->getParam('cs');
     PageUrl::reencodeParameters($parameters, $pageEncoding);
     // Detect Site Search keyword
     foreach ($keywordParameters as $keywordParameterRaw) {
         $keywordParameter = Common::mb_strtolower($keywordParameterRaw);
         if (!empty($parameters[$keywordParameter])) {
             $actionName = $parameters[$keywordParameter];
             break;
         }
     }
     if (empty($actionName)) {
         return false;
     }
     $categoryParameters = isset($website['sitesearch_category_parameters']) ? $website['sitesearch_category_parameters'] : array();
     foreach ($categoryParameters as $categoryParameterRaw) {
         $categoryParameter = Common::mb_strtolower($categoryParameterRaw);
         if (!empty($parameters[$categoryParameter])) {
             $categoryName = $parameters[$categoryParameter];
             break;
         }
     }
     if (isset($parameters['search_count']) && $this->isValidSearchCount($parameters['search_count'])) {
         $count = $parameters['search_count'];
     }
     // Remove search kwd from URL
     if ($doRemoveSearchParametersFromUrl) {
         // @see excludeQueryParametersFromUrl()
         // Excluded the detected parameters from the URL
         $parametersToExclude = array($categoryParameterRaw, $keywordParameterRaw);
         if (isset($parsedUrl['query'])) {
             $parsedUrl['query'] = UrlHelper::getQueryStringWithExcludedParameters(UrlHelper::getArrayFromQueryString($parsedUrl['query']), $parametersToExclude);
         }
         if (isset($parsedUrl['fragment'])) {
             $parsedUrl['fragment'] = UrlHelper::getQueryStringWithExcludedParameters(UrlHelper::getArrayFromQueryString($parsedUrl['fragment']), $parametersToExclude);
         }
     }
     $url = UrlHelper::getParseUrlReverse($parsedUrl);
     if (is_array($actionName)) {
         $actionName = reset($actionName);
     }
     $actionName = trim(urldecode($actionName));
     if (empty($actionName)) {
         return false;
     }
     if (is_array($categoryName)) {
         $categoryName = reset($categoryName);
     }
     $categoryName = trim(urldecode($categoryName));
     return array($url, $actionName, $categoryName, $count);
 }