You are here

function _patterns_scan_action in Patterns 7

Same name and namespace in other branches
  1. 7.2 includes/parser/scan.inc \_patterns_scan_action()

Helper function for scanning patterns.

Scans an action and add the result of the scan to the $result array.

Parameters

array $action The action to scan:

array $result (optional) The array in which inserting: the scan results.

integer $level (optional) : The level of of the analysis. Defaults PATTERNS_VALIDATE_ALL

Return value

array $result The results of the scan.

See also

patterns_scan_pattern()

_patterns_scan_analyze_patternscan()

1 call to _patterns_scan_action()
patterns_scan_pattern in includes/parser/scan.inc
Scans a pattern and returns a brief summary of its properties.

File

includes/parser/scan.inc, line 327
Helping functions for the parser.

Code

function _patterns_scan_action($action, $result = array(), $level = PATTERNS_VALIDATE_ALL) {
  $key = key($action);
  $action = current($action);
  $valid_actions = patterns_actions();
  if (!array_key_exists($key, $valid_actions)) {
    $result['invalid_actions'][] = array(
      'actionid' => $action,
      'key' => $key,
      'value' => $action,
    );
    return $result;
  }
  if (empty($action)) {
    $result['empties'][] = $key;
    return $result;
  }
  if (!is_array($action)) {
    $result['generic_errors'][] = $key . ': ' . $action;
    return $result;
  }

  // Make sure there is only one valid action in each array element.
  // NOTE: Having additional valid actions will work, but is discouraged,
  // and therefore undocumented.
  $found = FALSE;

  // Report additional valid actions.
  if ($found) {
    $result['extra_actions'][] = array(
      'actionid' => $action,
      'key' => $key,
      'value' => $action,
    );
  }
  if ($level <= PATTERNS_VALIDATE_SYNTAX) {
    return $result;
  }

  // Do action specific checkings

  ////////////////////////////////
  if ($key === PATTERNS_INCLUDE) {
    $result['contain_includes'] = TRUE;
    if (!isset($action['pattern'])) {
      $result['missing_tag'][] = array(
        'actionid' => $action,
        'key' => $key,
        'value' => $action,
      );
      return $result;
    }

    // only if the pattern is hard-coded, then scan it
    if (is_array($action['pattern'])) {
      $result['include_scans'][] = patterns_scan_pattern($action['pattern'], TRUE);
    }
    return $result;
  }

  // Check if 'tag' is present.
  if (!isset($action['tag']) || !is_string($action['tag'])) {
    $result['missing_tag'][] = array(
      'actionid' => $action,
      'key' => $key,
      'value' => $action,
    );
  }
  else {
    if ($level >= PATTERNS_VALIDATE_TAG_EXISTS) {
      $tag = $action['tag'];

      // We force to rebuild the index and reload the components
      // because this method may be invoked as a service
      $tag_modules = patterns_tagmodules_get_index($action, true, true);
      if (!isset($tag_modules[$tag])) {
        $result['unknown_tag'][] = $tag;
      }
      else {
        if ($level >= PATTERNS_VALIDATE_ALL) {
          patterns_invoke('prepare', $key, $action);
          $validation = patterns_invoke('validate', $key, $action);
          if ($validation['status'] == PATTERNS_ERR) {
            $result['tag_errors'][] = array(
              'action' => $key,
              'tag' => $tag,
              'msg' => $validation['msg'],
            );
          }
        }
      }
    }
  }

  //else {

  //  $newactions[] = array('action' => $key, 'data' => $action);

  //}
  $found = TRUE;
  return $result;
}