You are here

function _linkchecker_report_page in Link checker 6.2

Same name and namespace in other branches
  1. 7 linkchecker.pages.inc \_linkchecker_report_page()
2 calls to _linkchecker_report_page()
linkchecker_admin_report_page in includes/linkchecker.pages.inc
Menu callback for general reporting.
linkchecker_user_report_page in includes/linkchecker.pages.inc
Menu callback for author specific reporting.

File

includes/linkchecker.pages.inc, line 90
User page callbacks for the linkchecker module.

Code

function _linkchecker_report_page($links_report_sql, $links_report_parameters = NULL, $account = NULL) {
  $links_unchecked = db_result(db_query('SELECT COUNT(1) FROM {linkchecker_links} WHERE last_checked = %d AND status = %d', 0, 1));
  if ($links_unchecked > 0) {
    $links_all = db_result(db_query('SELECT COUNT(1) FROM {linkchecker_links} WHERE status = %d', 1));
    drupal_set_message(format_plural($links_unchecked, 'There is 1 unchecked link of about @links_all links in the database. Please be patient until all links have been checked via cron.', 'There are @count unchecked links of about @links_all links in the database. Please be patient until all links have been checked via cron.', array(
      '@links_all' => $links_all,
    )), 'warning');
  }
  $header = array(
    array(
      'data' => t('URL'),
      'field' => 'url',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Response'),
      'field' => 'code',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Error'),
      'field' => 'error',
    ),
    array(
      'data' => t('Operations'),
    ),
  );
  $result = pager_query($links_report_sql . tablesort_sql($header), 50, 0, NULL, $links_report_parameters);

  // Evaluate permission once for performance reasons.
  $access_edit_link_settings = user_access('edit link settings');
  $access_administer_blocks = user_access('administer blocks');
  $access_administer_redirects = user_access('administer redirects');
  $rows = array();
  while ($link = db_fetch_object($result)) {

    // Get the node, block and comment IDs that refer to this broken link and
    // that the current user has access to.
    $nids = _linkchecker_link_node_ids($link, $account);
    $cids = _linkchecker_link_comment_ids($link, $account);
    $bids = _linkchecker_link_block_ids($link);

    // If the user does not have access to see this link anywhere, do not
    // display it, for reasons explained in _linkchecker_link_access(). We
    // still need to fill the table row, though, so as not to throw off the
    // number of items in the pager.
    if (empty($nids) && empty($cids) && empty($bids)) {
      $rows[] = array(
        array(
          'data' => t('Permission restrictions deny you access to this broken link.'),
          'colspan' => count($header),
        ),
      );
      continue;
    }
    $links = array();

    // Show links to link settings.
    if ($access_edit_link_settings) {
      $links[] = l(t('Edit link settings'), 'linkchecker/' . $link->lid . '/edit', array(
        'query' => drupal_get_destination(),
      ));
    }

    // Show link to nodes having this broken link.
    foreach ($nids as $nid) {
      $links[] = l(t('Edit node @node', array(
        '@node' => $nid,
      )), 'node/' . $nid . '/edit', array(
        'query' => drupal_get_destination(),
      ));
    }

    // Show link to comments having this broken link.
    if (module_exists('comment') && variable_get('linkchecker_scan_comments', 0)) {
      foreach ($cids as $cid) {
        $links[] = l(t('Edit comment @comment', array(
          '@comment' => $cid,
        )), 'comment/edit/' . $cid, array(
          'query' => drupal_get_destination(),
        ));
      }
    }

    // Show link to blocks having this broken link.
    if ($access_administer_blocks) {
      foreach ($bids as $bid) {
        $links[] = l(t('Edit block @block', array(
          '@block' => $bid,
        )), 'admin/build/block/configure/block/' . $bid, array(
          'query' => drupal_get_destination(),
        ));
      }
    }

    // Show link to redirect this broken internal link.
    if (module_exists('path_redirect') && $access_administer_redirects && _linkchecker_is_internal_url($link)) {
      $links[] = l(t('Create redirection'), 'admin/build/path-redirect/add', array(
        'query' => array(
          'source' => $link->internal,
        ),
      ));
    }

    // Create table data for output. Use inline styles to prevent extra CSS file.
    $rows[] = array(
      l(_filter_url_trim($link->url, 40), $link->url),
      $link->code,
      check_plain($link->error),
      theme('item_list', $links),
    );
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No broken links have been found.'),
        'colspan' => count($header),
      ),
    );
  }
  $output = theme('table', $header, $rows);
  $output .= theme('pager', NULL, 3000, 0);
  return $output;
}