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;
}