Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_views/README.txt,v
retrieving revision 1.5
diff -u -r1.5 README.txt
--- README.txt	6 Jul 2008 21:16:42 -0000	1.5
+++ README.txt	23 Apr 2009 00:35:04 -0000
@@ -27,10 +27,10 @@
 Views to filter content based on the access privlieges set by Domain Access.
 
 This module is most useful for site administrators, who can normally see all
-nodes at all times.  Using the provides filters can alter this behavior.
+nodes at all times.  Using the provided filters can alter this behavior.
 
-This code implements views integration for the Domain Access module by adding
-a views filter and argument handler. This allows you to restrict your view content
+This code implements Views integration for the Domain Access module by adding
+a Views filter and argument handler. This allows you to restrict your view content
 to only show content from a specified domain (or set of domains) either by using
 a predefined filter or by passing arguments to the view e.g. example.com/myview/6
 (where 6 is the id for one one of your domains).
@@ -105,11 +105,4 @@
 When using Views filters, you must select at least one criteria for the filter to
 be applied.
 
-The filters available to Domain Access include all active domains plus:
-
- -- The currently active domain.
- -- Any domain
- 
- If you use the "Any domain" option, the filter must be set to "not one of" in
- order to return all nodes.
-
+The filters available to Domain Access include all active domains plus currently active domain.
\ No newline at end of file
Index: domain_views.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_views/domain_views.module,v
retrieving revision 1.7
diff -u -r1.7 domain_views.module
--- domain_views.module	11 Oct 2008 23:18:00 -0000	1.7
+++ domain_views.module	23 Apr 2009 00:36:08 -0000
@@ -24,6 +24,16 @@
  * Implements hook_views_api().
  */
 function domain_views_views_api() {
-
   return array('api' => 2.0);
 }
+
+/**
+ * Implementation of hook_theme().
+ */
+function domain_views_theme() {
+  return array(
+   'domain_views_view_multiple_field' => array(
+      'arguments' => array('items' => NULL, 'field' => NULL, 'data' => NULL),
+    ),
+  );
+}
Index: domain_views.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_views/domain_views.views.inc,v
retrieving revision 1.6
diff -u -r1.6 domain_views.views.inc
--- domain_views.views.inc	6 Nov 2008 16:32:07 -0000	1.6
+++ domain_views.views.inc	23 Apr 2009 00:35:48 -0000
@@ -48,7 +48,7 @@
     ),
   );
   $data['domain']['subdomain'] = array(
-    'title' => t('Domain'),
+    'title' => t('Subdomain'),
     'help' => t('The URL string that identifies a domain.'),
     'field' => array(
       'click sortable' => TRUE,
@@ -66,6 +66,7 @@
     'title' => t('Site name'),
     'help' => t('The display string that identifies a domain.'),
     'field' => array(
+      'handler' => 'domain_views_handler_field_domain_sitename',
       'click sortable' => TRUE,
     ),
     // Information for accepting a domain_id as a filter
@@ -156,6 +157,10 @@
     'sort' => array(
       'handler' => 'views_handler_sort',
     ),
+    // Information accepting domain_id as an argument
+    'argument' => array(
+      'handler' => 'domain_views_handler_argument_domain_access_gid',
+    ),
   );
   // Define the fields.
   $data['domain_access']['realm'] = array(
@@ -187,12 +192,59 @@
       'label' => t('Available on current domain'),
     ),
   );
+  // Define the {domain_editor} table.
+  $data['domain_editor']['table']['group'] = t('Domain');
+  // Define the joins.
+  $data['domain_editor']['table']['join']['users'] = array(
+    'left_field' => 'uid',
+    'field' => 'uid',
+  );
+  // Define the fields.
+  $data['domain_editor']['uid'] = array(
+    'title' => t('User ID'),
+    'help' => t('The user\'s id.'),
+    'field' => array(
+      'click sortable' => TRUE,
+    ),
+    // Information for accepting a domain_id as a filter
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    // Information for sorting on a domain_id.
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+  );
+  // Define the fields.
+  $data['domain_editor']['domain_id'] = array(
+    'title' => t('Domain ID'),
+    'help' => t('The domain id of the editor record.'),
+    'field' => array(
+      'click sortable' => TRUE,
+    ),
+    // Information for accepting a domain_id as a filter
+    'filter' => array(
+      'handler' => 'domain_views_handler_filter_domain_domain_id',
+    ),
+    // Information for sorting on a domain_id.
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'relationship' => array(
+      'title' => t('Domain editors'),
+      'help' => t("Bring in information about the domain this user is assigned to."),
+      'base' => 'domain',
+      'field' => 'domain_id',
+      'handler' => 'views_handler_relationship',
+      'label' => t('Domain editors'),
+    ),
+  );
   return $data;
 }
 
 /**
- * Implementation of hook_views_handlers() to register all of the basic handlers
- * views uses.
+ * Implementation of hook_views_handlers() to register all of the
+ * basic handlers views uses.
  */
 function domain_views_views_handlers() {
   $handlers = array(
@@ -210,6 +262,14 @@
     'domain_views_handler_filter_domain_domain_id' => array(
       'parent' => 'views_handler_filter_in_operator',
     ),
+    // argument handlers
+    'domain_views_handler_argument_domain_access_gid' => array(
+      'parent' => 'views_handler_argument',
+    ),
+    // field handlers
+    'domain_views_handler_field_domain_sitename' => array(
+      'parent' => 'views_handler_field',
+    ),
   ),
   );
   return $handlers;
@@ -222,3 +282,13 @@
   return array('***CURRENT_DOMAIN***' => $GLOBALS['_domain']['domain_id']);
 }
 
+/**
+ * Theme multiple field output
+ */
+function theme_domain_views_view_multiple_field($items, $field, $values) {
+  $output = '';
+  foreach ($items as $item) {
+    $output .= '<div class="field-item">'. $item .'</div>';
+  }
+  return $output;
+}
\ No newline at end of file
Index: includes/domain_views_handler_filter_domain_access_current_all.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_views/includes/domain_views_handler_filter_domain_access_current_all.inc,v
retrieving revision 1.2
diff -u -r1.2 domain_views_handler_filter_domain_access_current_all.inc
--- includes/domain_views_handler_filter_domain_access_current_all.inc	25 Mar 2009 13:54:55 -0000	1.2
+++ includes/domain_views_handler_filter_domain_access_current_all.inc	23 Apr 2009 00:33:03 -0000
@@ -4,6 +4,8 @@
 /**
  * @file
  * Interface between domain_views.module and views.module.
+ *
+ * @ingroup domain_views
  */
 
 /**
Index: includes/domain_views_handler_filter_domain_access_gid.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_views/includes/domain_views_handler_filter_domain_access_gid.inc,v
retrieving revision 1.1
diff -u -r1.1 domain_views_handler_filter_domain_access_gid.inc
--- includes/domain_views_handler_filter_domain_access_gid.inc	6 Nov 2008 16:32:07 -0000	1.1
+++ includes/domain_views_handler_filter_domain_access_gid.inc	23 Apr 2009 00:32:29 -0000
@@ -3,6 +3,8 @@
 /**
  * @file
  * Interface between domain_views.module and views.module.
+ *
+ * @ingroup domain_views
  */
 
 /**
Index: includes/domain_views_handler_filter_domain_domain_id.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain_views/includes/domain_views_handler_filter_domain_domain_id.inc,v
retrieving revision 1.1
diff -u -r1.1 domain_views_handler_filter_domain_domain_id.inc
--- includes/domain_views_handler_filter_domain_domain_id.inc	6 Nov 2008 16:32:07 -0000	1.1
+++ includes/domain_views_handler_filter_domain_domain_id.inc	23 Apr 2009 00:33:36 -0000
@@ -4,6 +4,8 @@
 /**
  * @file
  * Interface between domain_views.module and views.module.
+ *
+ * @ingroup domain_views
  */
 
 /**
--- domain_views_handler_argument_domain_access_gid.inc
+++ domain_views_handler_argument_domain_access_gid.inc
@@ -0,0 +1,42 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Interface between domain_views.module and views.module.
+ *
+ * @ingroup domain_views
+ */
+
+/**
+ * Argument for domain ids stored in the database currently active domain and any domain.
+ */
+class domain_views_handler_argument_domain_access_gid extends views_handler_argument  {
+ // If you pass "current" as the argument, it filters according to the domain the page is being viewed from
+  function set_argument($arg) {
+    if ($arg == 'current') {
+      $arg = $GLOBALS['_domain']['domain_id'];
+    }
+    return parent::set_argument($arg);
+  }
+
+  function title() {
+    return $this->domain_id($this->argument);
+  }
+
+  function summary_name($data) {
+    return $this->domain_id($data->{$this->name_alias});
+  }
+
+  function summary_argument($data) {
+    return $this->domain_id($data->{$this->name_alias});
+  }
+
+  function domain_id($domain_id) {
+    $domains = domain_domains();
+    foreach ($domains as $domain) {
+      $domain_options[$domain['domain_id']] = $domain['sitename'];
+    }
+    return isset($domain_options[$domain_id]) ? $domain_options[$domain_id] : t('Unknown domain');
+  }
+}

--- domain_views_handler_field_domain_sitename.inc
+++ domain_views_handler_field_domain_sitename.inc
@@ -0,0 +1,147 @@
+<?php
+// $Id$
+/**
+ * @file
+ * Interface between domain_views.module and views.module.
+ *
+ * @ingroup domain_views
+ */
+
+/**
+ * Field handler to provide simple renderer that allows linking to a domain.
+ *
+ * @ingroup domain_views
+ */
+class domain_views_handler_field_domain_sitename extends views_handler_field {
+  /**
+   * Constructor to provide additional field to add.
+   */
+  function construct() {
+    parent::construct();
+    $this->additional_fields['domain_id'] = 'domain_id';
+    $this->additional_fields['nid'] = array('table' => 'node', 'field' => 'nid');
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['link_to_default_domain'] = array('default' => FALSE);
+    $options['link_to_original_domain'] = array('default' => FALSE);
+    $options['list_all_domains'] = array('default' => FALSE);
+    return $options;
+  }
+
+  /**
+   * Provide link to default domain option
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['link_to_default_domain'] = array(
+      '#title' => t('Link this field to default domain'),
+      '#description' => t('This will override any other link you have set.'),
+      '#type' => 'checkbox',
+      '#default_value' => !empty($this->options['link_to_default_domain']),
+      );
+    $form['link_to_original_domain'] = array(
+      '#title' => t('Link this field to the domain it originates from'),
+      '#description' => t('This will override any other link you have set.'),
+      '#type' => 'checkbox',
+      '#default_value' => !empty($this->options['link_to_original_domain']),
+    );
+    $form['list_all_domains'] = array(
+      '#title' => t('List all domains this node is published to'),
+      '#description' => t('This will override the default setting to show only one domain.'),
+      '#type' => 'checkbox',
+      '#default_value' => !empty($this->options['list_all_domains']),
+    );
+  }
+
+
+  function pre_render($values) {
+    // If there are no values to render (displaying a summary, or query returned no results)
+    // do nothing specific.
+    if (isset($this->view->build_info['summary']) || empty($values)) {
+      return parent::pre_render($values);
+    }
+    $options = $this->options;
+    // Only alter output if requested
+    if (!empty($options['list_all_domains'])) {
+      // Build a list of nids
+      $nids = array();
+      foreach ($values as $value) {
+        $nids[] = $value->nid;
+      }
+      $this->field_values = array();
+      $query = "SELECT node.nid AS nid, domain.sitename AS domain_sitename, domain.domain_id AS domain_domain_id
+      FROM node node  LEFT JOIN domain_access domain_access ON node.nid = domain_access.nid
+      INNER JOIN domain domain ON domain_access.gid = domain.domain_id AND (domain_access.realm = 'domain_id')
+      WHERE node.nid  IN (". implode(',', $nids) .")";
+      $result = db_query($query);
+      while ($item = db_fetch_array($result)) {
+        $this->field_values[$item['nid']][$item['domain_domain_id']] = $item['domain_sitename'];
+      }
+    }
+  }
+
+
+  /**
+   * Render sitename is as a link to the domain.
+   *
+   * Data should be made XSS safe prior to calling this function.
+   */
+  function render_link($data, $values) {
+    if (!empty($this->options['link_to_default_domain']) && $data !== NULL && $data !== '') {
+      $this->options['alter']['make_link'] = TRUE;
+      $domain = domain_lookup(0);
+      $node_path = drupal_get_path_alias('node/'. $values->{$this->aliases['nid']});
+      $this->options['alter']['path'] = $domain['scheme'] .'://'. $domain['subdomain'] .'/'. $node_path;
+    }
+    if (!empty($this->options['link_to_original_domain']) && $data !== NULL && $data !== '') {
+      $this->options['alter']['make_link'] = TRUE;
+      $domain_id = $values->{$this->aliases['domain_id']};
+      $domain = domain_lookup($domain_id);
+      $this->aliases['nid'] = 'nid';
+      $node_path = drupal_get_path_alias('node/'. $values->{$this->aliases['nid']});
+      $this->options['alter']['path'] = $domain['scheme'] .'://'. $domain['subdomain'] .'/'. $node_path;
+    }
+    return $data;
+  }
+
+  function render($values) {
+    // Special case handling when returning multiple sitenames per record.
+    // This only happens when list all domains is selected in options
+    if (is_array($this->field_values[$values->nid])) {
+      $field = $this->content_field;
+      $options = $this->options;
+      $items = array();
+      foreach ($this->field_values[$values->nid] as $key => $item) {
+        if (!empty($item)) {
+          $link = $item;
+          if (!empty($options['link_to_original_domain'])) {
+            $domain_id = $key;
+            $domain = domain_lookup($domain_id);
+            $node_path = drupal_get_path_alias('node/'. $values->{$this->aliases['nid']});
+            $link = l($item, $domain['scheme'] .'://'. $domain['subdomain'] .'/'. $node_path);
+          }
+          if (!empty($options['link_to_default_domain'])) {
+            $domain = domain_lookup(0);
+            $node_path = drupal_get_path_alias('node/'. $values->{$this->aliases['nid']});
+            $link = l($item, $domain['scheme'] .'://'. $domain['subdomain'] .'/'. $node_path);
+          }
+          $items[] = $link;
+        }
+      }
+      if (count($items) > 1) {
+        return theme('domain_views_view_multiple_field', $items, $field, $values);
+      }
+      elseif (count($items) == 1) {
+        return $items[0];
+      }
+      else {
+        return '';
+      }
+    }
+    else {
+      return $this->render_link(check_plain($values->{$this->field_alias}), $values);
+    }
+  }
+}


