You are here

function expire_rules_action_flush_url in Cache Expiration 6

Same name and namespace in other branches
  1. 7.2 expire.rules.inc \expire_rules_action_flush_url()
  2. 7 expire.rules.inc \expire_rules_action_flush_url()

Expire a URL from the page cache.

File

./expire.rules.inc, line 28
Integration with the rules module

Code

function expire_rules_action_flush_url($urls, $settings) {
  global $base_root, $base_path;
  $urls = preg_replace("/\r\n/", "\n", $urls);
  $urls = explode("\n", $urls);
  $urls = array_map('trim', $urls);
  $urls = array_filter($urls);
  $urls_parsed = array_map('parse_url', $urls);

  // Figure out what kind of URL's these are and act accordingly.
  $full_urls = array();
  $bad_paths = array();
  $internal = array();
  foreach ($urls_parsed as $key => $parts) {
    if (!empty($parts['host'])) {
      $full_urls[] = $urls[$key];
    }
    elseif (!empty($parts['path'])) {

      // Strip base path from path.
      $parts['path'] = preg_replace('/^' . preg_quote($base_path, '/') . '/i', '', $parts['path']);
      if (empty($parts['path']) || $parts['path'] == '<front>') {
        $internal[$key] = variable_get('site_frontpage', 'node');
      }
      else {
        $normal = expire_normal_path_check($parts['path']);
        if (is_array($normal)) {
          $internal[$key] = $urls[$key];
        }
        else {
          $normal = drupal_get_normal_path($parts['path']);
          if ($normal == $parts['path']) {

            // Bad path given
            $bad_paths[$key] = $urls[$key];
          }
          else {
            $internal[$key] = $normal;
          }
        }
      }
    }
  }
  if (!empty($bad_paths)) {
    watchdog('expire', 'Bad URL(s) given. !url do not match any given paths or aliases', array(
      '!url' => expire_print_r($bad_paths),
    ));
  }

  // Process internal paths
  foreach ($internal as $key => $path) {
    $arg = arg(NULL, $path);
    if ($arg[0] == 'node' && !empty($arg[1]) && is_numeric($arg[1])) {
      $node = node_load($arg[1]);
      expire_node($node);
      unset($internal[$key]);
    }
  }
  if (!empty($internal)) {
    $flushed = expire_cache_derivative($internal);
  }

  // Process Full URLs
  // hook_expire_cache
  $modules = module_implements('expire_cache');
  foreach ($modules as $module) {
    module_invoke($module, 'expire_cache', $full_urls);
  }
  watchdog('expire', 'Output: !urls <br /> Modules Using hook_expire_cache(): !modules', array(
    '!urls' => expire_print_r($full_urls),
    '!modules' => expire_print_r($modules),
  ));
}