Group URLs by schema.

@param \eZ\Publish\API\Repository\Values\URL\SearchResult $urls
@return array
519538
private function groupByScheme(SearchResult $urls)
    {
        $grouped = [];

        foreach ($urls as $url) {
            $scheme = parse_url($url->url, PHP_URL_SCHEME);
            if (!$scheme) {
                continue;
            }

            if (!isset($grouped[$scheme])) {
                $grouped[$scheme] = [];
            }

            $grouped[$scheme][] = $url;
        }

        return $grouped;
    }
950991
public function lookup($url)
  {
    $result = array();
    // get url's to check
    $canon_url = GoogleSafeBrowsing_Lookup_URL::googleCanonicalize($url);
    if(is_null($canon_url)){
      // unable to canonicalize, nothing we can do
      $this->debugLog('lookup('.$url.'): cannot canonicalize url, skipping');
      return $result;
    }
    $lookup_urls = GoogleSafeBrowsing_Lookup_URL::googleGetLookupExpressions($canon_url);
    
    $lookup_hashes = array();
    foreach($lookup_urls as $lookup_url){
      $lookup_hashes[]=GoogleSafeBrowsing_Lookup_URL::hash($lookup_url);
      //$this->debugLog(bin2hex($lookup_hashes[count($lookup_hashes)-1])." $lookup_url");
    }
    
    $found_hashes=$this->storage->hasPrefix($lookup_hashes);
    
    $matched_lists=array();
    // full hash lookups
    foreach($found_hashes as $found_hash){
      $this->debugLog('lookup('.$url.'): found hash prefix for '.bin2hex($found_hash));
      $lookup_result=$this->storage->isListedInCache($found_hash);
      if(is_null($lookup_result)){
        $lookup_result=array();
        // not cached, query google
        $collection=$this->api->getHash(substr($found_hash,0,4),$this->storage->getLists());
        if(count($collection->list_hashes)==0){
          // no hashes found, can happen, so insert dummy record for this prefix
          // so we can use the cached result (empty)
          $this->storage->addHashInCache($found_hash,$lookup_result,null,(int)$collection->cache);
        }else{
          // full length hashes found
          foreach($collection->list_hashes as $list_hash){
            $this->debugLog('lookup('.$url.'): remote lookup found full length hashes in list '.$list_hash->list_name);
            foreach($list_hash->hashes as $hash){
              $this->debugLog('lookup('.$url.'):   hash '.bin2hex($hash->hash));
              // cache in db
              $cache_seconds=(int)$collection->cache;
              if(isset($hash->cache) && $hash->cache){
                $cache_seconds=(int)$hash->cache;
              }
              $this->storage->addHashInCache($hash->hash,array($list_hash->list_name),$hash->raw_meta,$cache_seconds);
              if($hash->hash==$found_hash){
                // full length hash match
                if(!in_array($list_hash->list_name, $lookup_result)){
                  $lookup_result[]=$list_hash->list_name;
                }
              }
            }
          }
        }
      }// end cached if/else
      // $lookup_result is array of listnames (can be empty if not listed)
      foreach($lookup_result as $matched_list){
        $matched_lists[$matched_list]=true;
      }
    }
    if(count($matched_lists)>0){
      $this->debugLog('lookup('.$url.'): listed in '.implode(', ',array_keys($matched_lists)));
    }
    return array_keys($matched_lists);
  }
360230
protected function separateUrlParams($url, $params)
    {
        $a = parse_url($url);

        if (!empty($a['query'])) {
            parse_str($a['query'], $qparts);
            $cleanParams = array();
            foreach ($qparts as $k => $v) {
                $cleanParams[$k] = $v ? $v : '';
            }
            $params   = array_merge($params, $cleanParams);
            $urlParts = explode('?', $url, 2);
            $url      = $urlParts[0];
        }

        return array($url, $params);
    }
1219614
private function generateQueryUrlParameters(
        Result $result,
        string $filterName = null
    ): array {
        $query = $result->getQuery();
        $queryFilters = $query->getFilters();
        $urlParameters = [];
        foreach ($queryFilters as $currentFilterName => $filter) {
            /*
             * Special case for elements with LEVEL.
             */
            $urlParameters[$currentFilterName] = (
                !is_null($filterName) &&
                $currentFilterName === $filterName &&
                Filter::MUST_ALL_WITH_LEVELS === $filter->getApplicationType()
            )
                ? []
                : $filter->getValues();
        }

        unset($urlParameters['_query']);

        $queryFilter = $query->getFilter('_query');
        $queryString = $queryFilter instanceof Filter
            ? $queryFilter->getValues()[0]
            : '';

        if (!empty($queryString)) {
            $urlParameters['q'] = $queryString;
        }

        $sort = $query->getSortBy();
        if (SortBy::SCORE !== $sort) {
            $urlParameters['sort_by'] = $sort;
        }

        return $urlParameters;
    }
1080136
public function indexSearch($searchText, $maxResults)
    {
        // split the phrase into words
        $words = SearchAnalyser::analyse($searchText);
        if (!$words) {
            return [];
        }

        $query = $this->_em->createQueryBuilder()
            ->select('o')
            ->from($this->_entityName, 'o')
            ->setMaxResults($maxResults);

        $parameters = [];
        foreach ($words as $k => $word) {
            $subquery = $this->_em->createQueryBuilder()
                ->select("i$k.keyword")
                ->from($this->getSearchIndexClass(), "i$k")
                ->where("i$k.object = o")
                ->andWhere("i$k.keyword ILIKE :search$k");
            $query->andWhere($query->expr()->exists($subquery->getDql()));
            $parameters["search$k"] = '%' . $word . '%';
        }
        $query->setParameters($parameters);

        $results = $query->getQuery()->execute();

        return $results;
    }
83791
public function extractUrlWildcardsFromRows(array $rows)
    {
        $urlWildcards = array();

        foreach ($rows as $row) {
            $urlWildcards[] = $this->extractUrlWildcardFromRow($row);
        }

        return $urlWildcards;
    }
109561
protected function parseQueryParams($url)
    {
        $queries = [];

        $querySegment = \parse_url($url, PHP_URL_QUERY);
        \parse_str($querySegment, $queries);

        return $queries;
    }
1115038
protected function _urlMatch($patterns)
    {
        if (empty($patterns)) {
            return false;
        }

        $url = urldecode($this->_View->request->url);
        $path = str_starts_with($url, '/') ? str_replace_once('/', '', $url) : $url;

        if (option('url_locale_prefix')) {
            $patterns = explode("\n", $patterns);
            $locales = array_keys(quickapps('languages'));
            $localesPattern = '(' . implode('|', array_map('preg_quote', $locales)) . ')';

            foreach ($patterns as &$p) {
                if (!preg_match("/^{$localesPattern}\//", $p)) {
                    $p = I18n::locale() . '/' . $p;
                    $p = str_replace('//', '/', $p);
                }
            }

            $patterns = implode("\n", $patterns);
        }

        // Convert path settings to a regular expression.
        // Therefore replace newlines with a logical or, /* with asterisks and  "/" with the front page.
        $toReplace = [
            '/(\r\n?|\n)/', // newlines
            '/\\\\\*/', // asterisks
            '/(^|\|)\/($|\|)/' // front '/'
        ];

        $replacements = [
            '|',
            '.*',
            '\1' . preg_quote($this->_View->Url->build('/'), '/') . '\2'
        ];

        $patternsQuoted = preg_quote($patterns, '/');
        $patterns = '/^(' . preg_replace($toReplace, $replacements, $patternsQuoted) . ')$/';

        return (bool)preg_match($patterns, $path);
    }
509639
private function getSearchResults($parameters)
    {
        $searchRequest  = $this->requestBuilder->getSearchRequest($parameters);
        $searchResponse = $this->searchEngine->search($searchRequest);

        return $searchResponse;
    }
92911
public function serializeFilterGroups(array $filterGroups = array())
    {
        $return = [];
        foreach ($filterGroups as $filterGroup) {
            $filters = [];
            foreach ($filterGroup->getFilters() as $filter) {
                $filters[$filter->getName()] = $filter->getParameter();
            }
            $return[] = $filters;
        }

        return $return;
    }
456331
private function searchRouter($routes) 
    {
        foreach ($routes as $route) {
            if (!preg_match_all('#^' . $route['request'] . '$#', $this->request, $matches, PREG_OFFSET_CAPTURE))
                continue;
            // Rework matches to only contain the matches, not the orig string
            $matches = array_slice($matches, 1);

            // Extract the matched URL parameters (and only the parameters)
            $params = array_map(function ($match, $index) use ($matches) {

                // We have a following parameter: take the substring from the current param position until the next one's position (thank you PREG_OFFSET_CAPTURE)
                if (isset($matches[$index + 1]) && isset($matches[$index + 1][0]) && is_array($matches[$index + 1][0])) {
                    return trim(substr($match[0][0], 0, $matches[$index + 1][0][1] - $match[0][1]), '/');
                } // We have no following parameters: return the whole lot
                else {
                    return (isset($match[0][0]) ? trim($match[0][0], '/') : null);
                }
            }, $matches, array_keys($matches));

            $route['params'] = $params;
            return $route;
        }
        //not exists ...
        return false;
    }
211557
public function filterByKeywords($keywords)
    {
        $expressions = [
            $this->query->expr()->like('psi.cName', ':keywords'),
            $this->query->expr()->like('psi.cDescription', ':keywords'),
            $this->query->expr()->like('psi.content', ':keywords'),
        ];

        $keys = \CollectionAttributeKey::getSearchableIndexedList();
        foreach ($keys as $ak) {
            $cnt = $ak->getController();
            $expressions[] = $cnt->searchKeywords($keywords, $this->query);
        }
        $expr = $this->query->expr();
        $this->query->andWhere(call_user_func_array([$expr, 'orX'], $expressions));
        $this->query->setParameter('keywords', '%' . $keywords . '%');
    }
1166090
public static function parseUrlQuery($query)
    {
        $result = [];
        $pairs = explode('&', $query);
        foreach ($pairs as $pair) {
            $parts = explode('=', $pair);
            $rawKey = $parts[0];
            $rawValue = isset($parts[1]) ? $parts[1] : '';
            $value = urldecode($rawValue);
            $key = strtr(urldecode($rawKey), ['[' => '.', ']' => '']);
            Arr::set($result, $key, $value);
        }
        return $result;
    }
138118
function list_groups($search = null, $mode = 0)
    {
        if (!$this->groups) {
            return array();
        }

        $group_cache = $this->_fetch_groups($search, $mode);
        $groups      = array();

        if ($search) {
            foreach ($group_cache as $group) {
                if ($this->compare_search_value('name', $group['name'], mb_strtolower($search), $mode)) {
                    $groups[] = $group;
                }
            }
        }
        else {
            $groups = $group_cache;
        }

        return array_values($groups);
    }
608037
private function createUrlByUrlParameters(
        Result $result,
        array $urlParameters
    ): array {
        foreach ($this->routesDictionary as $field => $route) {
            if (
                !isset($urlParameters[$field]) ||
                (
                    is_array($urlParameters[$field]) &&
                    1 !== count($urlParameters[$field])
                )
            ) {
                continue;
            }

            $value = is_array($urlParameters[$field])
                ? reset($urlParameters[$field])
                : $urlParameters[$field];

            if (!$result
                ->getAggregation($field)
                ->getAllElements()[$value] instanceof Counter) {
                continue;
            }

            unset($urlParameters[$field]);
            $path = $this
                ->router
                ->getRouteCollection()
                ->get($route)
                ->getPath();
            preg_match_all(
                '~\{(.+?)\}~',
                $path,
                $matches
            );

            return [
                'route' => urldecode($this
                    ->router
                    ->generate(
                        $route,
                        array_merge(
                            array_intersect_key(
                                $result
                                    ->getAggregation($field)
                                    ->getAllElements()[$value]
                                    ->getValues(),
                                array_flip($matches[1])
                            ),
                            $urlParameters
                        ),
                        UrlGeneratorInterface::ABSOLUTE_URL
                    )),
                'url_parameters' => $urlParameters,
                'template_path' => $path,
                'field' => $field,
            ];
        }

        return [
            'route' => urldecode($this
                ->router
                ->generate(
                    $this->routesDictionary['main'],
                    $urlParameters,
                    UrlGeneratorInterface::ABSOLUTE_URL
                )),
            'url_parameters' => $urlParameters,
            'template_path' => urldecode($this
                ->router
                ->generate(
                    $this->routesDictionary['main'],
                    [],
                    UrlGeneratorInterface::ABSOLUTE_URL
                )
            ),
            'field' => false,
        ];
    }
1090709
public function search($parameters)
    {
        $this->result = null;
        $result = $this->request('POST', $this->getCore().'/select', [], $parameters, 'form_params');
        $this->result = new SolrSearchResult($result, $this);

        return $this->result;
    }
412533
public static function _parse_url_query($url)
    {
        $queryString = parse_url($url, PHP_URL_QUERY);

        $params = array();

        parse_str($queryString, $params);

        if (count($params) === 0) {
            return $params;
        }

        return array_filter($params);
    }