Further modules included.
[yaffs-website] / web / modules / contrib / linkchecker / linkchecker.redirect.inc
1 <?php
2
3 /**
4  * @file
5  * Redirect interface to linkchecker functionalities.
6  */
7
8 /**
9  * Implements hook_redirect_insert().
10  */
11 function linkchecker_redirect_insert($redirect) {
12   linkchecker_redirect_update($redirect);
13 }
14
15 /**
16  * Implements hook_redirect_update().
17  */
18 function linkchecker_redirect_update($redirect) {
19   // It's unknown if this is a redirect for HTTP/HTTPS or the encoded urls.
20   $url_http = url($redirect->source, array('absolute' => TRUE, $redirect->source_options));
21   $url_https = url($redirect->source, array('absolute' => TRUE, 'https' => TRUE, $redirect->source_options));
22
23   $urls = array(
24     $url_http,
25     $url_https,
26     rawurldecode($url_http),
27     rawurldecode($url_https),
28   );
29
30   _linkchecker_redirect_reset($urls);
31 }
32
33 /**
34  * Reset last_checked status.
35  *
36  * @param array $urls
37  *   An array of urls that should be checked on next cron run.
38  */
39 function _linkchecker_redirect_reset($urls = array()) {
40   $urls = array_unique($urls);
41
42   $num_updated = db_update('linkchecker_link')
43     ->condition('urlhash', array_map('drupal_hash_base64', $urls))
44     ->condition('fail_count', 0, '>')
45     ->condition('status', 1)
46     ->fields(array('last_checked' => 0))
47     ->execute();
48
49   if ($num_updated) {
50     drupal_set_message(t('The link %url will be checked again on the next cron run.', array('%url' => $urls[0])));
51   }
52 }