diff --git a/linkchecker.module b/linkchecker.module index 311a0a0..1a00df3 100644 --- a/linkchecker.module +++ b/linkchecker.module @@ -133,6 +133,15 @@ function linkchecker_menu() { } /** + * Implements hook_views_api(). + */ +function linkchecker_views_api() { + return array( + 'api' => 3, + ); +} + +/** * Implements hook_cron(). */ function linkchecker_cron() { diff --git a/linkchecker.views.inc b/linkchecker.views.inc new file mod 100644 index 0000000..06d2837 --- /dev/null +++ b/linkchecker.views.inc @@ -0,0 +1,519 @@ + array( + 'group' => t('Broken Links'), + 'join' => array( + 'node' => array( + 'left_table' => 'node', + 'left_field' => 'nid', + 'field' => 'nid', + ), + ), + ), + + + ); + $data['linkchecker_link'] = array( + 'table' => array( + 'group' => t('Broken Links'), + 'join' => array( + 'node' => array( + 'left_table' => 'linkchecker_node', + 'left_field' => 'lid', + 'field' => 'lid', + ), + ), + ), + // Describe table fields to views + 'lid' => array( + 'title' => t('Link ID'), + 'help' => t("The Linkchecker module-assigned link ID"), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + ), + 'url' => array( + 'title' => t('URL'), + 'help' => t('The URL of a link in a Broken Links report'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ), + // HTTP Status code + 'code' => array( + 'title' => t('HTTP Status Code'), + 'help' => t('The status code returned by HTTP requests to the link'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + ), + // Error Message + 'error' => array( + 'title' => t('Error Message'), + 'help' => t('The error message returned by the Broken Links module to explain failure'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ), + // Fail Count + 'fail_count' => array( + 'title' => t('Fail Count'), + 'help' => t('The number of times requests for the URL have failed'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + ), + // Last checked + 'last_checked' => array( + 'title' => t('Last Checked'), + 'help' => t('The time the link was last checked on a cron run'), + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ), + // Status (true or false - failed or not) + 'status' => array( + 'title' => t('Status'), + 'help' => t('Whether or not the link was valid when last checked'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('Broken?'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ), + ); + + return $data; +} + +function linkchecker_views_default_views(){ + $views = array(); + + $view = new view; + $view->name = 'broken_links'; + $view->description = ''; + $view->tag = ''; + $view->view_php = ''; + $view->base_table = 'node'; + $view->is_cacheable = FALSE; + $view->api_version = '3.0-alpha1'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + $handler = $view->new_display('default', 'Defaults', 'default'); + $handler->override_option('fields', array( + 'url' => array( + 'label' => 'URL', + 'alter' => array( + 'alter_text' => 0, + 'text' => '', + 'make_link' => 1, + 'path' => '[url]', + 'link_class' => '', + 'alt' => 'External link', + 'prefix' => '', + 'suffix' => '', + 'target' => '_blank', + 'help' => '', + 'trim' => 0, + 'max_length' => '', + 'word_boundary' => 1, + 'ellipsis' => 1, + 'html' => 0, + 'strip_tags' => 0, + ), + 'empty' => '', + 'hide_empty' => 0, + 'empty_zero' => 0, + 'exclude' => 0, + 'id' => 'url', + 'table' => 'linkchecker_link', + 'field' => 'url', + 'relationship' => 'none', + ), + 'code' => array( + 'label' => 'Response', + 'alter' => array( + 'alter_text' => 0, + 'text' => '', + 'make_link' => 0, + 'path' => '', + 'link_class' => '', + 'alt' => '', + 'prefix' => '', + 'suffix' => '', + 'target' => '', + 'help' => '', + 'trim' => 0, + 'max_length' => '', + 'word_boundary' => 1, + 'ellipsis' => 1, + 'html' => 0, + 'strip_tags' => 0, + ), + 'empty' => '', + 'hide_empty' => 0, + 'empty_zero' => 0, + 'set_precision' => FALSE, + 'precision' => 0, + 'decimal' => '.', + 'separator' => ',', + 'prefix' => '', + 'suffix' => '', + 'exclude' => 0, + 'id' => 'code', + 'table' => 'linkchecker_link', + 'field' => 'code', + 'relationship' => 'none', + ), + 'error' => array( + 'label' => 'Error', + 'alter' => array( + 'alter_text' => 0, + 'text' => '', + 'make_link' => 0, + 'path' => '', + 'link_class' => '', + 'alt' => '', + 'prefix' => '', + 'suffix' => '', + 'target' => '', + 'help' => '', + 'trim' => 0, + 'max_length' => '', + 'word_boundary' => 1, + 'ellipsis' => 1, + 'html' => 0, + 'strip_tags' => 0, + ), + 'empty' => '', + 'hide_empty' => 0, + 'empty_zero' => 0, + 'exclude' => 0, + 'id' => 'error', + 'table' => 'linkchecker_link', + 'field' => 'error', + 'relationship' => 'none', + ), + 'nid' => array( + 'label' => '', + 'alter' => array( + 'alter_text' => 1, + 'text' => 'Edit node [nid]', + 'make_link' => 1, + 'path' => 'node/[nid]/edit?destination=broken_links', + 'link_class' => '', + 'alt' => '', + 'prefix' => '', + 'suffix' => '', + 'target' => '', + 'help' => '', + 'trim' => 0, + 'max_length' => '', + 'word_boundary' => 1, + 'ellipsis' => 1, + 'html' => 0, + 'strip_tags' => 0, + ), + 'empty' => '', + 'hide_empty' => 0, + 'empty_zero' => 0, + 'link_to_node' => 0, + 'exclude' => 1, + 'id' => 'nid', + 'table' => 'node', + 'field' => 'nid', + 'relationship' => 'none', + ), + 'lid' => array( + 'label' => '', + 'alter' => array( + 'alter_text' => 1, + 'text' => 'Edit Link Settings', + 'make_link' => 1, + 'path' => 'linkchecker/[lid]/edit?destination=broken_links', + 'link_class' => '', + 'alt' => 'Edit Linkchecker settings for this link', + 'prefix' => '', + 'suffix' => '', + 'target' => '', + 'help' => '', + 'trim' => 0, + 'max_length' => '', + 'word_boundary' => 1, + 'ellipsis' => 1, + 'html' => 0, + 'strip_tags' => 0, + ), + 'empty' => '', + 'hide_empty' => 0, + 'empty_zero' => 0, + 'set_precision' => FALSE, + 'precision' => 0, + 'decimal' => '.', + 'separator' => ',', + 'prefix' => '', + 'suffix' => '', + 'exclude' => 1, + 'id' => 'lid', + 'table' => 'linkchecker_link', + 'field' => 'lid', + 'relationship' => 'none', + ), + 'nothing' => array( + 'label' => 'Operations', + 'alter' => array( + 'text' => '', + 'make_link' => 0, + 'path' => '', + 'link_class' => '', + 'alt' => '', + 'prefix' => '', + 'suffix' => '', + 'target' => '', + 'help' => '', + 'trim' => 0, + 'max_length' => '', + 'word_boundary' => 1, + 'ellipsis' => 1, + 'html' => 0, + 'strip_tags' => 0, + ), + 'empty' => '', + 'hide_empty' => 0, + 'empty_zero' => 0, + 'exclude' => 0, + 'id' => 'nothing', + 'table' => 'views', + 'field' => 'nothing', + 'relationship' => 'none', + ), + )); + $handler->override_option('sorts', array( + 'last_checked' => array( + 'order' => 'DESC', + 'granularity' => 'second', + 'id' => 'last_checked', + 'table' => 'linkchecker_link', + 'field' => 'last_checked', + 'relationship' => 'none', + ), + )); + $handler->override_option('filters', array( + 'code_1' => array( + 'operator' => '!=', + 'value' => array( + 'value' => '200', + 'min' => '', + 'max' => '', + ), + 'group' => '0', + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'id' => 'code_1', + 'table' => 'linkchecker_link', + 'field' => 'code', + 'relationship' => 'none', + ), + 'code_2' => array( + 'operator' => '!=', + 'value' => array( + 'value' => '302', + 'min' => '', + 'max' => '', + ), + 'group' => '0', + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'id' => 'code_2', + 'table' => 'linkchecker_link', + 'field' => 'code', + 'relationship' => 'none', + ), + 'code_3' => array( + 'operator' => '!=', + 'value' => array( + 'value' => '304', + 'min' => '', + 'max' => '', + ), + 'group' => '0', + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'id' => 'code_3', + 'table' => 'linkchecker_link', + 'field' => 'code', + 'relationship' => 'none', + ), + 'code_4' => array( + 'operator' => '!=', + 'value' => array( + 'value' => '401', + 'min' => '', + 'max' => '', + ), + 'group' => '0', + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'id' => 'code_4', + 'table' => 'linkchecker_link', + 'field' => 'code', + 'relationship' => 'none', + ), + 'code_5' => array( + 'operator' => '!=', + 'value' => array( + 'value' => '403', + 'min' => '', + 'max' => '', + ), + 'group' => '0', + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'id' => 'code_5', + 'table' => 'linkchecker_link', + 'field' => 'code', + 'relationship' => 'none', + ), + )); + $handler->override_option('access', array( + 'type' => 'none', + )); + $handler->override_option('cache', array( + 'type' => 'none', + )); + $handler->override_option('title', 'Broken Links'); + $handler->override_option('items_per_page', 0); + $handler->override_option('style_plugin', 'table'); + $handler->override_option('style_options', array( + 'grouping' => '', + 'override' => 1, + 'sticky' => 0, + 'order' => 'desc', + 'columns' => array( + 'url' => 'url', + 'code' => 'code', + 'error' => 'error', + 'nid' => 'nid', + 'lid' => 'lid', + 'nothing' => 'nothing', + ), + 'info' => array( + 'url' => array( + 'sortable' => 1, + 'separator' => '', + ), + 'code' => array( + 'sortable' => 1, + 'separator' => '', + ), + 'error' => array( + 'sortable' => 1, + 'separator' => '', + ), + 'nid' => array( + 'sortable' => 0, + 'separator' => '', + ), + 'lid' => array( + 'sortable' => 0, + 'separator' => '', + ), + 'nothing' => array( + 'separator' => '', + ), + ), + 'default' => 'code', + )); + $handler = $view->new_display('page', 'Page', 'page_1'); + $handler->override_option('path', 'broken_links'); + $handler->override_option('menu', array( + 'type' => 'none', + 'title' => '', + 'description' => '', + 'weight' => 0, + 'name' => 'navigation', + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'description' => '', + 'weight' => 0, + 'name' => 'navigation', + )); + + $views[$view->name] = $view; + return $views; + +} +