function RulesURIInputEvaluator::evaluate

Overrides RulesDataInputEvaluator::evaluate().

Parameters

string $text: The text to evaluate.

array $options: A keyed array of settings and flags to control the processing. Supported options are:

  • language: A language object to be used when processing.
  • callback: A callback function that will be used to post-process replacements that might be incorporated, so they can be cleaned in a certain way.
  • sanitize: A boolean flag indicating whether incorporated replacements should be sanitized.

RulesState $state: The rules evaluation state.

Return value

The evaluated text.

Overrides RulesDataInputEvaluator::evaluate

File

modules/rules_core.eval.inc, line 126

Class

RulesURIInputEvaluator
A class implementing a rules input evaluator processing URI inputs.

Code

public function evaluate($uri, $options, RulesState $state) {
  if (!url_is_external($uri)) {
    // Extract the path and build the URL using the url() function, so URL
    // aliases are applied and query parameters and fragments get handled.
    $url = drupal_parse_url($uri);
    $url_options = array(
      'absolute' => TRUE,
    );
    $url_options['query'] = $url['query'];
    $url_options['fragment'] = $url['fragment'];
    return url($url['path'], $url_options);
  }
  elseif (valid_url($uri)) {
    return $uri;
  }
  throw new RulesEvaluationException('Input evaluation generated an invalid URI.', array(), NULL, RulesLog::WARN);
}