Index: link.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/link/views/link.views.inc,v
retrieving revision 1.1.4.2
diff -u -r1.1.4.2 link.views.inc
--- link.views.inc	4 Jul 2009 19:07:42 -0000	1.1.4.2
+++ link.views.inc	20 Feb 2010 17:31:01 -0000
@@ -17,10 +17,37 @@
       'link_views_handler_argument_target' => array(
         'parent' => 'views_handler_argument',
       ),
+      'link_views_handler_argument_url' => array(
+        'parent' => 'views_handler_argument',
+      ),
       'link_views_handler_filter_protocol' => array(
         'parent' => 'views_handler_filter_string',
+      )
+    )
+  );
+}
+
+/**
+ * Implementation of hook_views_plugins().
+ */
+function link_views_plugins() {
+  $path = drupal_get_path('module', 'link');
+  $views_path = drupal_get_path('module', 'views');
+  return array(
+    'module' => 'link',
+    'argument validator' => array(
+      'parent' => array(
+        'no ui' => TRUE,
+        'handler' => 'views_plugin_argument_validate',
+        'path' => "$views_path/plugins",
+        'parent' => ''
       ),
-    ),
+      'url' => array(
+        'title' => t('URL type'),
+        'handler' => 'link_views_plugin_argument_validate_url',
+        'path' => "$path/views"
+      )
+    )
   );
 }
 
@@ -73,6 +100,22 @@
       'allow_empty' => TRUE,
     ),
   );
+  
+  // Build out additional views data for the link "url" field.
+  $data[$table_alias][$field['field_name'] .'_url'] = array(
+    'group' => t('Content'),
+    'title' => t('@label URL', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
+    'help' =>  $data[$table_alias][$field['field_name'] .'_url']['help'],
+    'argument' => array(
+      'field' => $db_info['columns']['url']['column'],
+      'title' => t('@label URL', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
+      'tablename' => $db_info['table'],
+      'handler' => 'link_views_handler_argument_url',
+      'additional fields' => array(),
+      'content_field_name' => $field['field_name'],
+      'allow_empty' => TRUE,
+    )
+  );
 
   // Build out additional Views filter for the link "protocol" pseudo field.
   // TODO: Add a protocol argument.
--- link_views_handler_argument_url.inc
+++ link_views_handler_argument_url.inc
@@ -0,0 +1,60 @@
+<?php
+// $Id: link_views_handler_argument_target.inc,v 1.1.4.2 2009/07/04 19:07:42 jcfiala Exp $
+
+/**
+ * @file
+ * Argument handler to filter results by target.
+ */
+
+/**
+ * Argument handler to filter results by target.
+ */
+class link_views_handler_argument_url extends views_handler_argument {
+
+  /**
+   * Provide defaults for the argument when a new one is created.
+   */
+  function options(&$options) {
+    parent::options($options);
+  }
+
+  /**
+   * Provide a default options form for the argument.
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+  }
+
+  /**
+   * Provide a basic argument validation.
+   */
+  function validate_argument_basic($arg) {
+    if (!parent::validate_argument_basic($arg) || !link_validate_url($arg)) return FALSE;
+    return TRUE;
+  }
+
+  /**
+   * Set the input for this argument.
+   * Since URLs contain slashes which are interpreted as argument separators in views,
+   * URLs must be urlencoded when provided as argument.
+   * Before execution, we decode it here.
+   *
+   * @return TRUE if it successfully validates; FALSE if it does not.
+   */
+  function set_argument($arg) {
+    $this->argument = urldecode($arg);
+    return $this->validate_arg($this->argument);
+  }
+  
+  
+  /**
+   * Set up the query for this argument.
+   *
+   * The argument sent may be found at $this->argument.
+   */
+  function query() {
+    $this->ensure_my_table();
+    // We use LIKE for the sake of simplicity for now
+    $this->query->add_where(0, $this->table_alias .'.'. $this->real_field ." LIKE '%%%s%'", $this->argument);
+  }
+}

--- link_views_plugin_argument_validate_url.inc
+++ link_views_plugin_argument_validate_url.inc
@@ -0,0 +1,48 @@
+<?php
+/**
+ * @file
+ * Contains the Link URL argument validator plugin.
+ */
+
+/**
+ * Validate whether an argument is a URL or not.
+ *
+ * @ingroup views_argument_validate_plugins
+ */
+class link_views_plugin_argument_validate_url extends views_plugin_argument_validate {
+  var $option_name = 'validate_argument_url_type';
+  
+  function validate_form(&$form, &$form_state) {
+
+    $options[LINK_FRONT] = t('Front');
+    $options[LINK_EMAIL] = t('Email');
+    $options[LINK_INTERNAL] = t('Internal');
+    $options[LINK_EXTERNAL] = t('External');
+    
+    $arg = $this->get_argument();
+    if (empty($arg)) {
+      $arg = array();
+    }
+
+    $form[$this->option_name] = array(
+      '#type' => 'checkboxes',
+      '#prefix' => '<div id="edit-options-validate-argument-url-type-wrapper">',
+      '#suffix' => '</div>',
+      '#title' => t('URL type'),
+      '#options' => $options,
+      '#default_value' => $arg,
+      '#description' => t('If you wish to validate for specific URL types, check them; if none are checked, all URLs will pass.'),
+      '#process' => array('expand_checkboxes', 'views_process_dependency'),
+      '#dependency' => array('edit-options-validate-type' => array($this->id)),
+    );
+  }
+  
+  function validate_argument($argument) {
+    $types = array_filter($this->argument->options[$this->option_name]);
+    $result = link_validate_url($argument);
+    if(!empty($types)) return array_key_exists($result, $types);
+    else return $result;
+  }
+  
+}
+


