Bolt\Legacy\Storage::parseTextQuery PHP Method

parseTextQuery() private method

This is tightly coupled to $this->getContent()
private parseTextQuery ( $textquery, array &$decoded, array &$metaParameters, array &$ctypeParameters )
$textquery
$decoded array a pre-set decoded array to fill
$metaParameters array meta parameters
$ctypeParameters array contenttype parameters
    private function parseTextQuery($textquery, array &$decoded, array &$metaParameters, array &$ctypeParameters)
    {
        // Our default callback
        $decoded['queries_callback'] = [$this, 'executeGetContentQueries'];
        // Some special cases, like 'entry/1' or 'page/about' need to be caught before further processing.
        if (preg_match('#^/?([a-z0-9_-]+)/([0-9]+)$#i', $textquery, $match)) {
            // like 'entry/12' or '/page/12345'
            $decoded['contenttypes'] = $this->decodeContentTypesFromText($match[1]);
            $decoded['return_single'] = true;
            // if allow_numeric_slug option is set on contenttype, interpret number as slug instead of id
            $contenttype = $this->getContentType($decoded['contenttypes'][0]);
            $field = $contenttype['allow_numeric_slugs'] === true ? 'slug' : 'id';
            $ctypeParameters[$field] = $match[2];
        } elseif (preg_match('#^/?([a-z0-9_(\\),-]+)/search(/([0-9]+))?$#i', $textquery, $match)) {
            // like 'page/search or '(entry,page)/search'
            $decoded['contenttypes'] = $this->decodeContentTypesFromText($match[1]);
            $metaParameters['order'] = [$this, 'compareSearchWeights'];
            if (count($match) >= 3) {
                $metaParameters['limit'] = $match[3];
            }
            $decoded['queries_callback'] = [$this, 'executeGetContentSearch'];
        } elseif (preg_match('#^/?([a-z0-9_-]+)/([a-z0-9_-]+)$#i', $textquery, $match)) {
            // like 'page/lorem-ipsum-dolor' or '/page/home'
            $decoded['contenttypes'] = $this->decodeContentTypesFromText($match[1]);
            $decoded['return_single'] = true;
            $ctypeParameters['slug'] = $match[2];
        } elseif (preg_match('#^/?([a-z0-9_-]+)/(latest|first)/([0-9]+)$#i', $textquery, $match)) {
            // like 'page/latest/5'
            $decoded['contenttypes'] = $this->decodeContentTypesFromText($match[1]);
            if (!isset($metaParameters['order']) || $metaParameters['order'] === false) {
                $metaParameters['order'] = 'datepublish ' . ($match[2] == 'latest' ? 'DESC' : 'ASC');
            }
            if (!isset($metaParameters['limit'])) {
                $metaParameters['limit'] = $match[3];
            }
        } elseif (preg_match('#^/?([a-z0-9_-]+)/random/([0-9]+)$#i', $textquery, $match)) {
            // like 'page/random/4'
            $decoded['contenttypes'] = $this->decodeContentTypesFromText($match[1]);
            $dboptions = $this->app['config']->get('general/database');
            $metaParameters['order'] = $dboptions['randomfunction'];
            // 'RAND()' or 'RANDOM()'
            if (!isset($metaParameters['limit'])) {
                $metaParameters['limit'] = $match[2];
            }
        } else {
            $decoded['contenttypes'] = $this->decodeContentTypesFromText($textquery);
            if (isset($ctypeParameters['id']) && is_numeric($ctypeParameters['id'])) {
                $decoded['return_single'] = true;
            }
        }
        // When using from the frontend, we assume (by default) that we only want published items,
        // unless something else is specified explicitly
        $request = $this->app['request_stack']->getCurrentRequest();
        $isFrontend = $request ? Zone::isFrontend($request) : true;
        if ($isFrontend && empty($ctypeParameters['status'])) {
            $ctypeParameters['status'] = 'published';
        }
        if (isset($metaParameters['returnsingle'])) {
            $decoded['return_single'] = $metaParameters['returnsingle'];
            unset($metaParameters['returnsingle']);
        }
    }