Habari\Comments::search_to_get PHP Метод

search_to_get() публичный статический Метод

Parses a search string for status, type, author, and tag keywords. Returns an associative array which can be passed to Comments::get(). If multiple authors, statuses, or types are specified, we assume an implicit OR such that (e.g.) any author that matches would be returned.
public static search_to_get ( string $search_string ) : array
$search_string string The search string
Результат array An associative array which can be passed to Comments::get()
    public static function search_to_get($search_string)
    {
        $statuses = array_flip(Comment::list_comment_statuses());
        $types = array_flip(Comment::list_comment_types());
        $arguments = array('name' => array(), 'status' => array(), 'type' => array());
        $criteria = '';
        $tokens = explode(' ', $search_string);
        foreach ($tokens as $token) {
            // check for a keyword:value pair
            if (preg_match('/^\\w+:\\S+$/u', $token)) {
                list($keyword, $value) = explode(':', $token);
                $keyword = strtolower($keyword);
                $value = MultiByte::strtolower($value);
                switch ($keyword) {
                    case 'author':
                        $arguments['name'][] = $value;
                        break;
                    case 'status':
                        if (isset($statuses[$value])) {
                            $arguments['status'][] = (int) $statuses[$value];
                        }
                        break;
                    case 'type':
                        if (isset($types[$value])) {
                            $arguments['type'][] = (int) $types[$value];
                        }
                        break;
                }
            } else {
                $criteria .= $token . ' ';
            }
        }
        // flatten keys that have single-element or no-element arrays
        foreach ($arguments as $key => $arg) {
            switch (count($arg)) {
                case 0:
                    unset($arguments[$key]);
                    break;
                case 1:
                    $arguments[$key] = $arg[0];
                    break;
            }
        }
        if ($criteria != '') {
            $arguments['criteria'] = $criteria;
        }
        return $arguments;
    }