Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / linkchecker / linkchecker.pages.inc
index b04349b241037c17f3181ea3f69846d3c92be1ae..f43252e45201cfe781c1994d807882ac53722cb4 100644 (file)
@@ -5,6 +5,8 @@
  * User page callbacks for the linkchecker module.
  */
 
+use Drupal\Component\Utility\Html;
+
 /**
  * Menu callback for general reporting.
  *
  */
 function linkchecker_admin_report_page() {
 
-  $ignore_response_codes = preg_split('/(\r\n?|\n)/', variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403"));
+  $ignore_response_codes = preg_split('/(\r\n?|\n)/', \Drupal::config('linkchecker.settings')->get('linkchecker_ignore_response_codes'));
 
   // Search for broken links in nodes and comments and blocks of all users.
   // @todo Try to make UNION'ed subselect resultset smaller.
   $subquery4 = db_select('linkchecker_node', 'ln')
     ->distinct()
-    ->fields('ln', array('lid'));
+    ->fields('ln', ['lid']);
 
   $subquery3 = db_select('linkchecker_comment', 'lc')
     ->distinct()
-    ->fields('lc', array('lid'));
+    ->fields('lc', ['lid']);
 
   $subquery2 = db_select('linkchecker_block_custom', 'lb')
     ->distinct()
-    ->fields('lb', array('lid'));
+    ->fields('lb', ['lid']);
 
   // UNION all linkchecker type tables.
-  $subquery1 = db_select($subquery2->union($subquery3)->union($subquery4), 'q1')->fields('q1', array('lid'));
+  $subquery1 = db_select($subquery2->union($subquery3)->union($subquery4), 'q1')->fields('q1', ['lid']);
 
   // Build pager query.
   $query = db_select('linkchecker_link', 'll')->extend('PagerDefault')->extend('TableSort');
@@ -55,7 +57,7 @@ function linkchecker_admin_report_page() {
 function linkchecker_user_report_page($account) {
   drupal_set_title($account->name);
 
-  $ignore_response_codes = preg_split('/(\r\n?|\n)/', variable_get('linkchecker_ignore_response_codes', "200\n206\n302\n304\n401\n403"));
+  $ignore_response_codes = preg_split('/(\r\n?|\n)/', \Drupal::config('linkchecker.settings')->get('linkchecker_ignore_response_codes'));
 
   // Build query for broken links in nodes of the current user.
   $subquery2 = db_select('node', 'n');
@@ -70,7 +72,7 @@ function linkchecker_user_report_page($account) {
     ->condition('r.uid', $account->uid)
   );
   $subquery2->distinct();
-  $subquery2->fields('ll', array('lid'));
+  $subquery2->fields('ll', ['lid']);
 
   $comment_types = linkchecker_scan_comment_types();
   if (!empty($comment_types)) {
@@ -83,14 +85,14 @@ function linkchecker_user_report_page($account) {
     $subquery3->condition('ll.code', $ignore_response_codes, 'NOT IN');
     $subquery3->condition('c.uid', $account->uid);
     $subquery3->distinct();
-    $subquery3->fields('ll', array('lid'));
+    $subquery3->fields('ll', ['lid']);
 
     // UNION the linkchecker_node and linkchecker_comment tables.
-    $subquery1 = db_select($subquery2->union($subquery3), 'q1')->fields('q1', array('lid'));
+    $subquery1 = db_select($subquery2->union($subquery3), 'q1')->fields('q1', ['lid']);
   }
   else {
     // Build query for broken links in nodes of the current user.
-    $subquery1 = db_select($subquery2, 'q1')->fields('q1', array('lid'));
+    $subquery1 = db_select($subquery2, 'q1')->fields('q1', ['lid']);
   }
 
   // Build pager query.
@@ -117,21 +119,21 @@ function linkchecker_user_report_page($account) {
  */
 function _linkchecker_report_page($query, $account = NULL) {
 
-  $links_unchecked = db_query('SELECT COUNT(1) FROM {linkchecker_link} WHERE last_checked = :last_checked AND status = :status', array(':last_checked' => 0, ':status' => 1))->fetchField();
+  $links_unchecked = db_query('SELECT COUNT(1) FROM {linkchecker_link} WHERE last_checked = :last_checked AND status = :status', [':last_checked' => 0, ':status' => 1])->fetchField();
   if ($links_unchecked > 0) {
-    $links_all = db_query('SELECT COUNT(1) FROM {linkchecker_link} WHERE status = :status', array(':status' => 1))->fetchField();
-    drupal_set_message(format_plural($links_unchecked,
+    $links_all = db_query('SELECT COUNT(1) FROM {linkchecker_link} WHERE status = :status', [':status' => 1])->fetchField();
+    drupal_set_message(\Drupal::translation()->formatPlural($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');
+      ['@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')),
-  );
+  $header = [
+    ['data' => t('URL'), 'field' => 'url', 'sort' => 'desc'],
+    ['data' => t('Response'), 'field' => 'code', 'sort' => 'desc'],
+    ['data' => t('Error'), 'field' => 'error'],
+    ['data' => t('Operations')],
+  ];
 
   $result = $query
     ->limit(50)
@@ -139,11 +141,11 @@ function _linkchecker_report_page($query, $account = NULL) {
     ->execute();
 
   // 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');
+  $access_edit_link_settings = \Drupal::currentUser()->hasPermission('edit link settings');
+  $access_administer_blocks = \Drupal::currentUser()->hasPermission('administer blocks');
+  $access_administer_redirects = \Drupal::currentUser()->hasPermission('administer redirects');
 
-  $rows = array();
+  $rows = [];
   foreach ($result as $link) {
     // Get the node, block and comment IDs that refer to this broken link and
     // that the current user has access to.
@@ -156,60 +158,60 @@ function _linkchecker_report_page($query, $account = NULL) {
     // 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)));
+      $rows[] = [['data' => t('Permission restrictions deny you access to this broken link.'), 'colspan' => count($header)]];
       continue;
     }
 
-    $links = array();
+    $links = [];
 
     // 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()));
+      $links[] = l(t('Edit link settings'), 'linkchecker/' . $link->lid . '/edit', ['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()));
+      $links[] = l(t('Edit node @node', ['@node' => $nid]), 'node/' . $nid . '/edit', ['query' => drupal_get_destination()]);
     }
 
     // Show link to comments having this broken link.
     $comment_types = linkchecker_scan_comment_types();
-    if (module_exists('comment') && !empty($comment_types)) {
+    if (\Drupal::moduleHandler()->moduleExists('comment') && !empty($comment_types)) {
       foreach ($cids as $cid) {
-        $links[] = l(t('Edit comment @comment', array('@comment' => $cid)), 'comment/' . $cid . '/edit', array('query' => drupal_get_destination()));
+        $links[] = l(t('Edit comment @comment', ['@comment' => $cid]), 'comment/' . $cid . '/edit', ['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/structure/block/manage/block/' . $bid . '/configure', array('query' => drupal_get_destination()));
+        $links[] = l(t('Edit block @block', ['@block' => $bid]), 'admin/structure/block/manage/block/' . $bid . '/configure', ['query' => drupal_get_destination()]);
       }
     }
 
     // Show link to redirect this broken internal link.
-    if (module_exists('redirect') && $access_administer_redirects && _linkchecker_is_internal_url($link)) {
-      $links[] = l(t('Create redirection'), 'admin/config/search/redirect/add', array('query' => array('source' => $link->internal, drupal_get_destination())));
+    if (\Drupal::moduleHandler()->moduleExists('redirect') && $access_administer_redirects && _linkchecker_is_internal_url($link)) {
+      $links[] = l(t('Create redirection'), 'admin/config/search/redirect/add', ['query' => ['source' => $link->internal, drupal_get_destination()]]);
     }
 
     // Create table data for output.
-    $rows[] = array(
-      'data' => array(
+    $rows[] = [
+      'data' => [
         l(_filter_url_trim($link->url, 40), $link->url),
         $link->code,
-        check_plain($link->error),
-        theme('item_list', array('items' => $links)),
-      ),
-    );
+        Html::escape($link->error),
+        theme('item_list', ['items' => $links]),
+      ],
+    ];
   }
 
-  $build['linkchecker_table'] = array(
+  $build['linkchecker_table'] = [
     '#theme' => 'table',
     '#header' => $header,
     '#rows' => $rows,
     '#empty' => t('No broken links have been found.'),
-  );
-  $build['linkchecker_pager'] = array('#theme' => 'pager');
+  ];
+  $build['linkchecker_pager'] = ['#theme' => 'pager'];
 
   return $build;
 }