Index: revisionreference.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/revisionreference/revisionreference.install,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 revisionreference.install
--- revisionreference.install	19 Jun 2008 21:15:26 -0000	1.1.2.1
+++ revisionreference.install	7 Feb 2010 20:49:23 -0000
@@ -5,6 +5,7 @@
  * Implementation of hook_install().
  */
 function revisionreference_install() {
+  drupal_load('module', 'content');
   content_notify('install', 'revisionreference');
 }
 
@@ -12,6 +13,7 @@
  * Implementation of hook_uninstall().
  */
 function revisionreference_uninstall() {
+  drupal_load('module', 'content');
   content_notify('uninstall', 'revisionreference');
 }
 
@@ -21,6 +23,7 @@
  * Notify content module when this module is enabled.
  */
 function revisionreference_enable() {
+  drupal_load('module', 'content');
   content_notify('enable', 'revisionreference');
 }
 
@@ -30,5 +33,6 @@
  * Notify content module when this module is disabled.
  */
 function revisionreference_disable() {
+  drupal_load('module', 'content');
   content_notify('disable', 'revisionreference');
 }
\ No newline at end of file
Index: revisionreference.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/revisionreference/revisionreference.module,v
retrieving revision 1.1.2.4
diff -u -r1.1.2.4 revisionreference.module
--- revisionreference.module	23 Aug 2008 03:30:04 -0000	1.1.2.4
+++ revisionreference.module	7 Feb 2010 20:49:23 -0000
@@ -55,6 +55,15 @@
 }
 
 /**
+ * Implementaion of hook_ctools_plugin_directory().
+ */
+function revisionreference_ctools_plugin_directory($module, $plugin) {
+  if ($module == 'ctools' && $plugin == 'relationships') {
+    return 'panels/' . $plugin;
+  }
+}
+
+/**
  * Implementation of hook_field_info().
  *
  * Here we indicate that the content module will use its default
@@ -90,15 +99,20 @@
         '#title' => t('Content types that can be referenced'),
         '#multiple' => TRUE,
         '#default_value' => is_array($field['referenceable_revision_types']) ? $field['referenceable_revision_types'] : array(),
-        '#options' => node_get_types('names'),
+        '#options' => array_map('check_plain', node_get_types('names')),
       );
       if (module_exists('views')) {
         $views = array('--' => '--');
         $all_views = views_get_all_views();
         foreach ($all_views as $view) {
-          // Only views that have fields will work for our purpose.
-          if (!empty($view->display['default']->display_options['fields'])) {
-            $views[t('Existing Views')][$view->name] = $view->name;
+          // Only 'node' views that have fields will work for our purpose.
+          if ($view->base_table == 'node' && !empty($view->display['default']->display_options['fields'])) {
+            if ($view->type == 'Default') {
+              $views[t('Default Views')][$view->name] = $view->name;
+            }
+            else {
+              $views[t('Existing Views')][$view->name] = $view->name;
+            }
           }
         }
 
@@ -146,14 +160,16 @@
       $db_info = content_database_info($field);
       $table_alias = content_views_tablename($field);
 
-      // Swap the filter handler to the 'in' operator.
+      // Filter: Swap the filter handler to the 'in' operator.
       $data[$table_alias][$field['field_name'] .'_vid']['filter']['handler'] = 'views_handler_filter_many_to_one_content';
 
-      // Add a relationship for related node revision.
+      // Relationship: Add a relationship for related node revision.
       $data[$table_alias][$field['field_name'] .'_vid']['relationship'] = array(
         'base' => 'node_revisions',
         'field' => $db_info['columns']['vid']['column'],
-        'handler' => 'views_handler_relationship',
+        'handler' => 'content_handler_relationship',
+        'label' => t($field['widget']['label']),
+        'content_field_name' => $field['field_name'],
       );
       return $data;
   }
@@ -415,9 +431,9 @@
     $vid = $element['#default_value'][$field_key];
     $args[] = $vid;
     $row = db_fetch_object(db_query(db_rewrite_sql("
-      SELECT r.nid, r.timestamp, r.title, u.name AS user 
-      FROM {node_revisions} r 
-      LEFT JOIN {users} u ON r.uid = u.uid 
+      SELECT r.nid, r.timestamp, r.title, u.name AS user
+      FROM {node_revisions} r
+      LEFT JOIN {users} u ON r.uid = u.uid
       WHERE r.vid = %d", 'node_revisions', 'vid', $args), $args));
 
     $current = revisionreference_vid_is_current($row->vid, $row->nid);
@@ -504,7 +520,7 @@
     $value = $value[$parent];
     if ($parent == $field_key) {
       $element['#parents'] = $new_parents;
-      form_set_value($element, $value, $form_state);    
+      form_set_value($element, $value, $form_state);
       break;
     }
     $new_parents[] = $parent;
@@ -601,17 +617,17 @@
     }
 
     if (isset($string)) {
-      $string_clause = $exact_string ? " AND r.title = '%s'" : " AND r.title LIKE '%%%s%'";  
+      $string_clause = $exact_string ? " AND r.title = '%s'" : " AND r.title LIKE '%%%s%'";
       $related_clause = "(". $related_clause .")". $string_clause;
       $args[] = $string;
     }
 
     $result = db_query(db_rewrite_sql("
-      SELECT r.vid, r.nid, r.timestamp, r.title AS node_title, n.type AS node_type, u.name AS user 
-      FROM {node_revisions} r 
-      LEFT JOIN {node} n ON r.nid = n.nid 
-      LEFT JOIN {users} u ON r.uid = u.uid 
-      WHERE ". $related_clause ." 
+      SELECT r.vid, r.nid, r.timestamp, r.title AS node_title, n.type AS node_type, u.name AS user
+      FROM {node_revisions} r
+      LEFT JOIN {node} n ON r.nid = n.nid
+      LEFT JOIN {users} u ON r.uid = u.uid
+      WHERE ". $related_clause ."
       ORDER BY n.title, n.vid", 'node_revisions', 'vid', $args), $args);
   }
 
@@ -637,7 +653,7 @@
  * re-rendered more than one in a session, as when getting
  * a list of potential references and then running each of
  * them through the theme.
- * 
+ *
  * If $string or $exact_string change, we'll need a new query,
  * so in that case we need to refresh the view.
  */
@@ -665,7 +681,7 @@
     $view->display[$display]->row_plugin = 'fields';
     $view->display_handler->set_option('use_pager', FALSE);
     $view->display_handler->set_option('items_per_page', 0);
-        
+
     // Get arguments for the view.
     if (isset($field['advanced_revision_view_args'])) {
       // TODO: Support Tokens using token.module ?
@@ -695,7 +711,7 @@
     $view->execute_display($display, $view_args);
   }
   return $view;
-  
+
 }
 
 /**
@@ -705,7 +721,7 @@
   $fields = content_fields();
   $field = $fields[$field_name];
   $matches = array();
-  
+
   $references = _revisionreference_potential_references($field, TRUE, $string);
   foreach ($references as $row) {
     $current = revisionreference_vid_is_current($row->vid, $row->nid);
Index: revisionreference.rules.inc
===================================================================
RCS file: revisionreference.rules.inc
diff -N revisionreference.rules.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ revisionreference.rules.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,52 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Provides additional rules support for revisionreference fields.
+ */
+
+/**
+ * Implementation of hook_rules_action_info().
+ */
+function revisionreference_rules_action_info() {
+  $info = array();
+  $info['revisionreference_rules_action_load'] = array(
+    'label' => t('Load a referenced node revision'),
+    'arguments' => array(
+      'node' => array(
+        'type' => 'node',
+        'label' => t('Content containing the revisionreference field'),
+      ),
+    ),
+    'new variables' => array(
+      'referenced_node' => array(
+        'type' => 'node',
+        'label' => t('Referenced revision'),
+      ),
+    ),
+    'module' => 'CCK',
+    'help' => t('Note that if the field has multiple values, only the first content node will be loaded.'),
+  );
+  return $info;
+}
+
+function revisionreference_rules_action_load($node, $settings) {
+  if ($vid = $node->{$settings['field']}[0]['vid']) {
+    return array('referenced_node' => node_load(array('vid' => $vid), $vid));
+  }
+}
+
+function revisionreference_rules_action_load_form($settings, &$form) {
+  $settings += array('field' => '');
+  $options = content_rules_get_field_names_by_type('revisionreference');
+  $form['settings']['field'] = array(
+    '#type' => 'select',
+    '#title' => t('Field'),
+    '#default_value' => $settings['field'],
+    '#options' => $options,
+    '#required' => TRUE,
+    '#disabled' => empty($options),
+    '#description' => empty($options) ? t('There are no revisionreference fields defined.') : '',
+  );
+}
Index: panels/relationships/node_from_revisionref.inc
===================================================================
RCS file: panels/relationships/node_from_revisionref.inc
diff -N panels/relationships/node_from_revisionref.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ panels/relationships/node_from_revisionref.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,76 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Implements the revision reference relationship for Panels.
+ */
+
+/**
+ * Implementation of hook_ctools_relationships().
+ */
+function revisionreference_node_from_revisionref_ctools_relationships() {
+  return array(
+    'title' => t('Node from revisionreference'),
+    'keyword' => 'revisionreference',
+    'description' => t('Adds a node from a revisionreference in a node context; if multiple revisions are referenced, this will get the node of the first referenced revision only.'),
+    'required context' => new ctools_context_required(t('Node'), 'node'),
+    'context' => 'revisionreference_node_from_revisionref_context',
+    'settings form' => 'revisionreference_node_from_revisionref_settings_form',
+    'settings form validate' => 'revisionreference_node_from_revisionref_settings_form_validate',
+  );
+}
+
+/**
+ * Return a new ctools context based on an existing context.
+ */
+function revisionreference_node_from_revisionref_context($context, $conf) {
+  $field = content_fields($conf['field_name']);
+
+  // If unset it wants a generic, unfilled context, which is just NULL.
+  if (empty($context->data)) {
+    $new_context = ctools_context_create_empty('node', NULL);
+  }
+  else if (isset($context->data->{$conf['field_name']}[0]['vid']) && ($vid = $context->data->{$conf['field_name']}[0]['vid'])) {
+    if ($node = node_load(array('status' => 1), $vid)) {
+      $new_context = ctools_context_create('node', $node);
+    }
+  }
+
+  if (!empty($new_context)) {
+    // Have revisionreference relationships limit CCK field availability as well.
+    $restrictions = array_keys(array_filter($field['referenceable_revision_types']));
+    if ($restrictions) {
+      if (isset($new_context->restrictions['type'])) {
+        $new_context->restrictions['type'] = array_unique(array_merge($new_context->restrictions['type'], $restrictions));
+      }
+      else {
+        $new_context->restrictions['type'] = $restrictions;
+      }
+    }
+
+    return $new_context;
+  }
+}
+
+/**
+ * Settings form for the ctools relationship.
+ */
+function revisionreference_node_from_revisionref_settings_form($conf) {
+  $options = array();
+  foreach (content_fields() as $field) {
+    if ($field['type'] == 'revisionreference') {
+      $options[$field['field_name']] = t($field['widget']['label']);
+    }
+  }
+  $form['field_name'] = array(
+    '#title' => t('Node Revision reference field'),
+    '#type' => 'select',
+    '#options' => $options,
+    '#default_value' => isset($conf['field_name']) ? $conf['field_name'] : '',
+    '#prefix' => '<div class="clear-block">',
+    '#suffix' => '</div>',
+  );
+
+  return $form;
+}
