You are here

function ctools_break_phrase in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 ctools.module \ctools_break_phrase()
2 calls to ctools_break_phrase()
ctools_terms_context in plugins/arguments/terms.inc
Discover if this argument gives us the term we crave.
ctools_terms_from_node_context in plugins/relationships/terms_from_node.inc
Return a new context based on an existing context.

File

./ctools.module, line 249
CTools primary module file.

Code

function ctools_break_phrase($str) {
  $object = new stdClass();
  if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str)) {

    // The '+' character in a query string may be parsed as ' '.
    $object->operator = 'or';
    $object->value = preg_split('/[+ ]/', $str);
  }
  else {
    if (preg_match('/^([0-9]+,)*[0-9]+$/', $str)) {
      $object->operator = 'and';
      $object->value = explode(',', $str);
    }
  }

  // Keep an 'error' value if invalid strings were given.
  if (!empty($str) && (empty($object->value) || !is_array($object->value))) {
    $object->value = array(
      -1,
    );
    $object->invalid_input = TRUE;
    return $object;
  }
  if (empty($object->value)) {
    $object->value = array();
  }

  // Doubly ensure that all values are numeric only.
  foreach ($object->value as $id => $value) {
    $object->value[$id] = intval($value);
  }
  return $object;
}