diff --git a/path_redirect.module b/path_redirect.module index 9ce4b13..14dc3cf 100644 --- a/path_redirect.module +++ b/path_redirect.module @@ -662,3 +662,13 @@ function path_redirect_variables() { 'path_redirect_nodeapi_enabled' => NULL, ); } + +/** + * Implements hook_views_api(). + */ +function path_redirect_views_api() { + return array( + 'api' => 2, + 'path' => drupal_get_path('module', 'path_redirect'), + ); +} diff --git a/path_redirect.views.inc b/path_redirect.views.inc new file mode 100644 index 0000000..71f6aed --- /dev/null +++ b/path_redirect.views.inc @@ -0,0 +1,218 @@ + 'rid', + 'title' => t('URL redirect'), + 'help' => t('Redirects from one path to another path or an external URL.'), + ); + + // "Physical" fields. + $data['path_redirect']['rid'] = array( + 'title' => t('Rid'), + 'help' => t('Unique path redirect ID.'), + 'field' => array( + 'handler' => 'views_handler_field_path_redirect', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + $data['path_redirect']['source'] = array( + 'title' => t('Source'), + 'help' => t('The source path redirected from.'), + 'field' => array( + 'handler' => 'views_handler_field_path_redirect', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + $data['path_redirect']['redirect'] = array( + 'title' => t('Redirect path'), + 'help' => t('The destination path redirected to.'), + 'field' => array( + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + $data['path_redirect']['query'] = array( + 'title' => t('Query'), + 'help' => t('The query string sent to the destination.'), + 'field' => array( + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + $data['path_redirect']['fragment'] = array( + 'title' => t('Fragment'), + 'help' => t('An internal page anchor appended to the destination.'), + 'field' => array( + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + $data['path_redirect']['language'] = array( + 'title' => t('Language'), + 'help' => t('The language the redirect is for.'), + 'field' => array( + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + $data['path_redirect']['count'] = array( + 'title' => t('Hits'), + 'help' => t('The number of hits the redirect has accumulated.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + $data['path_redirect']['type'] = array( + 'title' => t('Type'), + 'help' => t('The HTTP status code used for the redirect.'), + 'field' => array( + 'handler' => 'views_handler_field_path_redirect_type', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + $data['path_redirect']['created'] = array( + 'title' => t('Created'), + 'help' => t('The timestamp of when the redirect was created.'), + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + ); + $data['path_redirect']['last_used'] = array( + 'title' => t('Last used'), + 'help' => t('The timestamp of when the redirect was last used.'), + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + ); + // "Virtual" fields. + $data['path_redirect']['redirect_url'] = array( + 'title' => t('Redirect URL'), + 'help' => t('The complete destination URL redirected to.'), + 'field' => array( + 'handler' => 'views_handler_field_path_redirect_url', + ), + ); + $data['path_redirect']['view_redirect'] = array( + 'title' => t('Link'), + 'help' => t('A simple link to the redirect.'), + 'field' => array( + 'handler' => 'views_handler_field_path_redirect_link', + ), + ); + $data['path_redirect']['edit_redirect'] = array( + 'title' => t('Edit link'), + 'help' => t('A simple link to edit the redirect.'), + 'field' => array( + 'handler' => 'views_handler_field_path_redirect_link_edit', + ), + ); + $data['path_redirect']['delete_redirect'] = array( + 'title' => t('Delete link'), + 'help' => t('A simple link to delete the redirect.'), + 'field' => array( + 'handler' => 'views_handler_field_path_redirect_link_delete', + ), + ); + return $data; +} + +/** + * Implements hook_views_handlers(). + */ +function path_redirect_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'path_redirect') . '/views', + ), + 'handlers' => array( + 'views_handler_field_path_redirect' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_path_redirect_link' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_path_redirect_link_delete' => array( + 'parent' => 'views_handler_field_path_redirect_link', + ), + 'views_handler_field_path_redirect_link_edit' => array( + 'parent' => 'views_handler_field_path_redirect_link', + ), + 'views_handler_field_path_redirect_type' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_path_redirect_url' => array( + 'parent' => 'views_handler_field_url', + ), + ), + ); +} diff --git a/views/views_handler_field_path_redirect.inc b/views/views_handler_field_path_redirect.inc new file mode 100644 index 0000000..6951be6 --- /dev/null +++ b/views/views_handler_field_path_redirect.inc @@ -0,0 +1,43 @@ + isset($this->definition['link_to_redirect default']) ? $this->definition['link_to_redirect default'] : FALSE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_redirect'] = array( + '#title' => t('Link this field to its redirect'), + '#description' => t('This will override any other link you have set.'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_redirect']), + ); + } + + function render($values) { + $text = check_plain($values->{$this->field_alias}); + if (!empty($this->options['link_to_redirect'])) { + if ($text !== NULL && $text !== '') { + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = $values->path_redirect_source; + } + else { + $this->options['alter']['make_link'] = FALSE; + } + } + return $text; + } + +} diff --git a/views/views_handler_field_path_redirect_link.inc b/views/views_handler_field_path_redirect_link.inc new file mode 100644 index 0000000..81d83ef --- /dev/null +++ b/views/views_handler_field_path_redirect_link.inc @@ -0,0 +1,33 @@ + '', 'translatable' => TRUE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['text'] = array( + '#type' => 'textfield', + '#title' => t('Text to display'), + '#default_value' => $this->options['text'], + ); + } + + function query() { + $this->add_additional_fields(); + } + + function render($values) { + $text = !empty($this->options['text']) ? $this->options['text'] : t('visit'); + $path = $values->path_redirect_source; + return l($text, $path); + } + +} diff --git a/views/views_handler_field_path_redirect_link_delete.inc b/views/views_handler_field_path_redirect_link_delete.inc new file mode 100644 index 0000000..f425340 --- /dev/null +++ b/views/views_handler_field_path_redirect_link_delete.inc @@ -0,0 +1,19 @@ +options['text']) ? $this->options['text'] : t('delete'); + $path = "admin/build/path-redirect/delete/{$values->rid}"; + $options = array('query' => drupal_get_destination()); + return l($text, $path, $options); + } + +} diff --git a/views/views_handler_field_path_redirect_link_edit.inc b/views/views_handler_field_path_redirect_link_edit.inc new file mode 100644 index 0000000..e93274c --- /dev/null +++ b/views/views_handler_field_path_redirect_link_edit.inc @@ -0,0 +1,19 @@ +options['text']) ? $this->options['text'] : t('edit'); + $path = "admin/build/path-redirect/edit/{$values->rid}"; + $options = array('query' => drupal_get_destination()); + return l($text, $path, $options); + } + +} diff --git a/views/views_handler_field_path_redirect_type.inc b/views/views_handler_field_path_redirect_type.inc new file mode 100644 index 0000000..2400ddd --- /dev/null +++ b/views/views_handler_field_path_redirect_type.inc @@ -0,0 +1,36 @@ + '', 'translatable' => TRUE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['include_description'] = array( + '#title' => t('Include description'), + '#description' => t('Example: 301 Moved Permanently.'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['include_description']), + ); + } + + function render($values) { + $code = check_plain($values->{$this->field_alias}); + if (!empty($this->options['include_description'])) { + module_load_include('inc', 'path_redirect', 'path_redirect.admin'); + $options = path_redirect_status_code_options(); + return $options[$code]; + } + else { + return $code; + } + } + +} diff --git a/views/views_handler_field_path_redirect_url.inc b/views/views_handler_field_path_redirect_url.inc new file mode 100644 index 0000000..d9ec223 --- /dev/null +++ b/views/views_handler_field_path_redirect_url.inc @@ -0,0 +1,18 @@ +field_alias = 'redirect_url'; + $this->add_additional_fields(); + } + + function render($values) { + $values->{$this->field_alias} = path_redirect_build_url($values->path_redirect_redirect, $values->path_redirect_query, $values->path_redirect_fragment); + return parent::render($values); + } + +}