Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DKAN link checker #2354

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions drupal-org.make
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ projects:
version: '1.1'
link_iframe_formatter:
version: '1.1'
linkchecker:
download:
type: git
url: 'https://git.drupal.org/project/linkchecker.git'
revision: 623819d04464b26af8e216113a88cd03f4bb4ccc
patch:
965720: https://www.drupal.org/files/issues/linkchecker-views-integration-965720-124.patch
1: patches/dkan_linkchecker_file.patch
manualcrop:
version: '1.6'
markdown:
Expand Down
21 changes: 21 additions & 0 deletions modules/dkan/dkan_linkchecker/css/linkchecker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.view-dkan-linkchecker-reports {
font-family: arial;
font-size: 12px;
font-weight: normal;
}
.view-dkan-linkchecker-reports .views-exposed-form .views-exposed-widget {
padding-top: 0;
}
.view-dkan-linkchecker-reports th.views-field-nothing {
text-align: center;
}
.view-dkan-linkchecker-reports td.views-field-nothing a:hover {
text-decoration: none;
}
.view-dkan-linkchecker-reports td.views-field-nothing a .btn-primary {
margin: 2px;
padding: 4px 8px;
}
.view-dkan-linkchecker-reports .views-field i {
font-size: 1.5em;
}
22 changes: 22 additions & 0 deletions modules/dkan/dkan_linkchecker/dkan_linkchecker.features.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* @file
* dkan_linkchecker.features.inc
*/

/**
* Implements hook_ctools_plugin_api().
*/
function dkan_linkchecker_ctools_plugin_api($module = NULL, $api = NULL) {
if ($module == "strongarm" && $api == "strongarm") {
return array("version" => "1");
}
}

/**
* Implements hook_views_api().
*/
function dkan_linkchecker_views_api($module = NULL, $api = NULL) {
return array("api" => "3.0");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @file
* dkan_linkchecker.features.user_permission.inc
*/

/**
* Implements hook_user_default_permissions().
*/
function dkan_linkchecker_user_default_permissions() {
$permissions = array();

// Exported permission: 'access broken links report'.
$permissions['access broken links report'] = array(
'name' => 'access broken links report',
'roles' => array(
'site manager' => 'site manager',
),
'module' => 'linkchecker',
);

// Exported permission: 'access own broken links report'.
$permissions['access own broken links report'] = array(
'name' => 'access own broken links report',
'roles' => array(
'site manager' => 'site manager',
),
'module' => 'linkchecker',
);

// Exported permission: 'administer linkchecker'.
$permissions['administer linkchecker'] = array(
'name' => 'administer linkchecker',
'roles' => array(
'site manager' => 'site manager',
),
'module' => 'linkchecker',
);

// Exported permission: 'edit link settings'.
$permissions['edit link settings'] = array(
'name' => 'edit link settings',
'roles' => array(
'site manager' => 'site manager',
),
'module' => 'linkchecker',
);

return $permissions;
}
24 changes: 24 additions & 0 deletions modules/dkan/dkan_linkchecker/dkan_linkchecker.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name = DKAN Link Checker
description = Checks for broken links in datasets, resources, and harvest sources.
core = 7.x
package = DKAN
dependencies[] = dkan_sitewide_menu
dependencies[] = features
dependencies[] = linkchecker
dependencies[] = menu
dependencies[] = strongarm
dependencies[] = views
features[ctools][] = strongarm:strongarm:1
features[ctools][] = views:views_default:3.0
features[features_api][] = api:2
features[user_permission][] = access broken links report
features[user_permission][] = access own broken links report
features[user_permission][] = administer linkchecker
features[user_permission][] = edit link settings
features[variable][] = linkchecker_check_links_types
features[variable][] = linkchecker_scan_node_dataset
features[variable][] = linkchecker_scan_node_harvest_source
features[variable][] = linkchecker_scan_node_resource
features[views_view][] = dkan_linkchecker_reports
features_exclude[dependencies][ctools] = ctools
project path = profiles/dkan/modules/dkan
17 changes: 17 additions & 0 deletions modules/dkan/dkan_linkchecker/dkan_linkchecker.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* @file
* Additional setup tasks for DKAN Link Checker.
*/

/**
* Implements hook_enable().
*/
function dkan_linkchecker_enable() {
// Disable the standard linkchecker_reports view to avoid confusion.
$list = variable_get('views_defaults');
$n = array('linkchecker_reports' => TRUE);
$disabled = array_merge($list, $n);
variable_set('views_defaults', $disabled);
}
159 changes: 159 additions & 0 deletions modules/dkan/dkan_linkchecker/dkan_linkchecker.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?php

/**
* @file
* Code for the DKAN Link Checker feature.
*/

include_once 'dkan_linkchecker.features.inc';

/**
* Implements hook_preprocess_page().
*/
function dkan_linkchecker_preprocess_page(&$vars) {
if (arg(2) == 'dkan-linkchecker-report' || arg(4) == 'dkan_linkchecker_reports') {
drupal_add_css(drupal_get_path('module', 'dkan_linkchecker') . '/css/linkchecker.css');
}
}

/**
* Implements hook_menu().
*/
function dkan_linkchecker_menu() {
$items = array();
// Add links to command center menu for site manager access.
$items['admin/dkan/dkan-linkchecker-report'] = array(
'menu_name' => 'menu-command-center-menu',
'title' => 'Broken Links Report',
'page callback' => '_dkan_linkchecker_report',
'access arguments' => array('access broken links report'),
'weight' => 11,
'type' => MENU_NORMAL_ITEM,
);

$items['admin/config/link-checker-settings'] = array(
'menu_name' => 'menu-command-center-menu',
'title' => 'Link Checker Settings',
'page callback' => '_dkan_linkchecker_form',
'access arguments' => array('administer linkchecker'),
'weight' => 10,
'type' => MENU_NORMAL_ITEM,
);

return $items;
}

/**
* Redirect to link checker report.
*/
function _dkan_linkchecker_report() {
drupal_goto('admin/reports/dkan-linkchecker-report');
}

/**
* Redirect to link checker form.
*/
function _dkan_linkchecker_form() {
drupal_goto('admin/config/content/linkchecker');
}

/**
* Implements hook_menu_alter().
*/
function dkan_linkchecker_menu_alter(&$items) {
// Remove normal linkchecker report link.
$items['admin/reports/linkchecker']['access callback'] = FALSE;
}

/**
* Implements hook_views_pre_render().
*/
function dkan_linkchecker_views_pre_render(&$view) {
if ($view->name == 'dkan_linkchecker_reports') {
// Re-write the output of the contact email.
foreach ($view->result as $key => $result) {
$email = '';
// Dataset results.
if (isset($result->field_field_contact_email[0]['raw']['value'])) {
$email = '<a href="mailto:' . $result->field_field_contact_email[0]['raw']['value'] . '"><i class="fa fa-envelope-square"></i></a> ';
}
if (isset($result->field_field_contact_name[0]['rendered']['#markup'])) {
$result->field_field_contact_name[0]['rendered']['#markup'] = $email . $result->field_field_contact_name[0]['raw']['safe_value'];
}
// Resource results.
if (isset($result->field_field_contact_email_1[0]['raw']['value'])) {
$email = '<a href="mailto:' . $result->field_field_contact_email_1[0]['raw']['value'] . '"><i class="fa fa-envelope-square"></i></a> ';
}
if (isset($result->field_field_contact_name_1[0]['rendered']['#markup'])) {
$result->field_field_contact_name_1[0]['rendered']['#markup'] = $email . $result->field_field_contact_name_1[0]['raw']['safe_value'];
}
}
}
}

/**
* Implements hook_views_query_alter().
*/
function dkan_linkchecker_views_query_alter(&$view, &$query) {
if ($view->name == 'dkan_linkchecker_reports') {
switch ($view->exposed_raw_input['field_public_access_level_value']) {
case 'public':
_access_level_query($view, $query, 'public');
break;

case 'private':
_access_level_query($view, $query, 'private');
break;

case 'restricted':
_access_level_query($view, $query, 'restricted');
break;

default:
break;
}
}
}

/**
* Create filter for public access level that includes resources.
*/
function _access_level_query(&$view, &$query, $level) {
// Get the public access level value from the dataset reference field.
$join = new views_join();
$join->table = 'field_data_field_public_access_level';
$join->field = 'entity_id';
$join->left_table = 'node_linkchecker_node__field_data_field_dataset_ref';
$join->left_field = 'field_dataset_ref_target_id';
$join->type = 'LEFT';

// Do the actual join.
$query->table_queue['public_access_level'] = array(
'alias' => 'public_access_level',
'table' => 'field_data_field_public_access_level',
'relationship' => 'node_linkchecker_node__field_data_field_dataset_ref',
'join' => $join,
);

// This gathers the dataset results.
$query->where[1] = array(
'conditions' => array(
array(
'field' => 'public_access_level.field_public_access_level_value',
'value' => $level,
'operator' => '=',
),
),
'type' => 'OR',
);

$query->table_queue['node_linkchecker_node__field_data_field_public_access_level']['join']->type = 'LEFT';
// This gathers the resource results.
$query->add_where(1, db_or()->condition(
'node_linkchecker_node__field_data_field_public_access_level.field_public_access_level_value', $level));
// Add default filters back in.
$ignore = array(200, 301, 302);
$query->add_where(2, db_and()->condition('linkchecker_link.last_checked', 0, '!=')->condition('linkchecker_link.status', '0', '<>')->condition('linkchecker_link.code', $ignore, 'NOT IN'));

return $query;
}
43 changes: 43 additions & 0 deletions modules/dkan/dkan_linkchecker/dkan_linkchecker.strongarm.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* @file
* dkan_linkchecker.strongarm.inc
*/

/**
* Implements hook_strongarm().
*/
function dkan_linkchecker_strongarm() {
$export = array();

$strongarm = new stdClass();
$strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
$strongarm->api_version = 1;
$strongarm->name = 'linkchecker_check_links_types';
$strongarm->value = '0';
$export['linkchecker_check_links_types'] = $strongarm;

$strongarm = new stdClass();
$strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
$strongarm->api_version = 1;
$strongarm->name = 'linkchecker_scan_node_dataset';
$strongarm->value = 1;
$export['linkchecker_scan_node_dataset'] = $strongarm;

$strongarm = new stdClass();
$strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
$strongarm->api_version = 1;
$strongarm->name = 'linkchecker_scan_node_harvest_source';
$strongarm->value = 1;
$export['linkchecker_scan_node_harvest_source'] = $strongarm;

$strongarm = new stdClass();
$strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */
$strongarm->api_version = 1;
$strongarm->name = 'linkchecker_scan_node_resource';
$strongarm->value = 1;
$export['linkchecker_scan_node_resource'] = $strongarm;

return $export;
}
Loading