You are here

function linkchecker_nodeapi in Link checker 6.2

Same name and namespace in other branches
  1. 5.2 linkchecker.module \linkchecker_nodeapi()

File

./linkchecker.module, line 759
This module periodically check links in given node types, blocks, cck fields, etc.

Code

function linkchecker_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'insert':

      // The node is going to be published.
      if (_linkchecker_scan_nodetype($node->type) && $node->status) {
        _linkchecker_add_node_links($node);
      }
      break;
    case 'update':

      // The node is going to be published.
      if (_linkchecker_scan_nodetype($node->type) && $node->status) {
        _linkchecker_add_node_links($node);
      }
      else {

        // The node is going to be unpublished.
        _linkchecker_delete_node_links($node->nid);
      }
      break;
    case 'delete':
      _linkchecker_delete_node_links($node->nid);
      break;
    case 'prepare':

      // Node edit tab is viewed.
      if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit' && isset($node->nid)) {

        // Show a message on node edit page if a link check failed once or more.
        $ignore_response_codes = preg_split('/(\\r\\n?|\\n)/', variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403"));
        $links = db_query("SELECT ll.* FROM {linkchecker_nodes} ln INNER JOIN {linkchecker_links} ll ON ln.lid = ll.lid WHERE ln.nid = %d AND ll.fail_count > %d AND ll.status = %d AND ll.code NOT IN (" . db_placeholders($ignore_response_codes, 'int') . ")", array_merge(array(
          $node->nid,
          0,
          1,
        ), $ignore_response_codes));
        while ($link = db_fetch_object($links)) {
          if (_linkchecker_link_access($link)) {
            drupal_set_message(format_plural($link->fail_count, 'Link check of <a href="@url">@url</a> failed once (status code: @code).', 'Link check of <a href="@url">@url</a> failed @count times (status code: @code).', array(
              '@url' => $link->url,
              '@code' => $link->code,
            )), 'warning', FALSE);
          }
        }
      }
      break;
  }
}