Index: linkchecker.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/linkchecker/linkchecker.module,v retrieving revision 1.7.2.68 diff -u -r1.7.2.68 linkchecker.module --- linkchecker.module 30 Jun 2009 06:31:37 -0000 1.7.2.68 +++ linkchecker.module 30 Jun 2009 06:32:27 -0000 @@ -9,6 +9,16 @@ */ /** + * Implementation of hook_init(). + */ +function linkchecker_init() { + $path = drupal_get_path('module', 'linkchecker'); + if (module_exists('trigger')) { + include_once $path . '/includes/linkchecker.trigger.inc'; + } +} + +/** * Implementation of hook_perm(). */ function linkchecker_perm() { @@ -20,6 +30,10 @@ */ function linkchecker_help($path, $arg) { switch ($path) { + case 'admin/build/trigger/linkchecker': + $output = '

'. t('Triggers are system events, such as when new content is added or when a user logs in. Trigger module combines these triggers with actions (functional tasks), such as unpublishing content or e-mailing an administrator. The Actions settings page contains a list of existing actions and provides the ability to create and configure additional actions.', array('@url' => url('admin/settings/actions'))) .'

'; + $output .= '

'. t('Below you can assign actions to run when certain link checker-related triggers happen. For example, you could unpublish a node or put it in moderation queue if a link check failed.') .'

'; + return $output; case 'admin/help#linkchecker': return '

' . t('This module provides an aid to finding broken links on your site. It periodically checks contents of all public nodes, tries to find any html links and check for their validity. It reports broken links through the admin interface. For more information about status codes see Status Code Definitions.', array('@rfc' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html')) . '

'; } @@ -427,6 +441,18 @@ //watchdog('linkchecker', 'Unhandled link error %link has been found.', array('%link' => $link->url), WATCHDOG_ERROR, l(t('Broken links'), 'admin/reports/linkchecker')); } } + + if (module_exists('trigger')) { + //Fire Trigger on all nodes, that contain the link. + $res = db_query("SELECT * FROM {linkchecker_nodes} WHERE lid = %d", $link->lid); + $trigger_code = ($response->code >= 200 && $response->code < 600) ? $response->code : 'failed'; + $nid = array(); + while ($row = db_fetch_object($res)) { + $node = node_load(array('nid' => $row->nid)); + module_invoke_all('linkchecker', $trigger_code, $node); + } + } + } function linkchecker_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { Index: includes/linkchecker.trigger.inc =================================================================== RCS file: includes/linkchecker.trigger.inc diff -N includes/linkchecker.trigger.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ includes/linkchecker.trigger.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,48 @@ + t('Content contains links with HTTP status code @code', array('@code' => $code)) + ); + } + $triggers['failed'] = array( + 'runs when' => t('Content contains links without HTTP status codes (failed)'), + ); + + // $triggers will not be set if no workflows have been assigned to node types. + if (isset($triggers)) { + return array( + 'linkchecker' => array( + 'linkchecker' => $triggers, + ), + ); + } +} + +/** + * Implementation of hook_trigger_name(). + */ +function linkchecker_linkchecker($op, $user) { + // We support a subset of operations. + if (!($op == 'failed' || ($op >= 300 && $op < 600) )) { + return; + } + $aids = _trigger_get_hook_aids('linkchecker', $op); + $context = array( + 'hook' => 'linkchecker', + 'op' => $op, + 'user' => $user, + ); + actions_do(array_keys($aids), $user, $context); +}