You are here

function linkchecker_form_alter in Link checker 6.2

Same name and namespace in other branches
  1. 5.2 linkchecker.module \linkchecker_form_alter()
  2. 7 linkchecker.module \linkchecker_form_alter()

File

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

Code

function linkchecker_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {

    // Catch the block add/configure form and add custom submit handler.
    case 'block_add_block_form':

      // Add custom submit handler to block add form.
      $form['#submit'][] = 'linkchecker_block_add_form_submit';
      break;
    case 'block_admin_configure':

      // When displaying the form, show the broken links warning.
      if (empty($form_state['post']) && is_numeric(arg(5))) {

        // Show a message on block 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_boxes} lb INNER JOIN {linkchecker_links} ll ON lb.lid = ll.lid WHERE lb.bid = %d AND ll.fail_count > %d AND ll.status = %d AND ll.code NOT IN (" . db_placeholders($ignore_response_codes, 'int') . ")", array_merge(array(
          arg(5),
          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);
          }
        }
      }

      // Add custom submit handler to block configuration form.
      $form['#submit'][] = 'linkchecker_block_configure_form_submit';
      break;
    case 'block_box_delete':
      $form['#submit'][] = 'linkchecker_block_box_delete_form_submit';
      break;
    case 'comment_form':

      // When displaying the form as 'view' or 'preview', show the broken links warning.
      if ((empty($form_state['post']) || isset($form_state['post']['op']) && $form_state['post']['op'] == t('Preview')) && arg(0) == 'comment' && arg(1) == 'edit' && is_numeric(arg(2))) {

        // Show a message on comment 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_comments} lc INNER JOIN {linkchecker_links} ll ON lc.lid = ll.lid WHERE lc.cid = %d AND ll.fail_count > %d AND ll.status = %d AND ll.code NOT IN (" . db_placeholders($ignore_response_codes, 'int') . ")", array_merge(array(
          arg(2),
          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;
  }
}