function linkchecker_nodeapi in Link checker 5.2
Same name and namespace in other branches
- 6.2 linkchecker.module \linkchecker_nodeapi()
File
- ./
linkchecker.module, line 904 - 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':
case 'update':
// The node is going to be published.
if ($node->status && _linkchecker_scan_nodetype($node->type)) {
_linkchecker_add_node_links($node);
}
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') {
// Show a message if a link check failed once or more.
$ignore_response_codes = preg_split('/(\\r\\n?|\\n)/', variable_get('linkchecker_ignore_response_codes', "200\n302\n304\n401\n403"));
$placeholders = implode(',', array_fill(0, count($ignore_response_codes), '%d'));
$links = db_query("SELECT url, code, fail_count 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 (" . $placeholders . ")", array_merge(array(
$node->nid,
0,
1,
), $ignore_response_codes));
while ($link = db_fetch_object($links)) {
drupal_set_message(strtr(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' => check_plain($link->url),
'@code' => $link->code,
)), 'warning');
}
}
break;
}
}