Index: privatemsg.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsg.module,v
retrieving revision 1.105
diff -u -p -r1.105 privatemsg.module
--- privatemsg.module	18 Dec 2008 16:26:33 -0000	1.105
+++ privatemsg.module	26 Jun 2009 05:06:31 -0000
@@ -1001,3 +1001,13 @@ function privatemsg_privatemsg_pm_contro
   return l(t('Delete message'), 'messages/delete/'. $pmid);
 }
 
+/**
+ * Implementation of hook_views_api.
+ */
+function privatemsg_views_api() {
+  return array(
+    'api' => 2,
+    'path' => drupal_get_path('module', 'privatemsg') . '/views',
+  );
+}
+
Index: privatemsg.views.inc
===================================================================
RCS file: privatemsg.views.inc
diff -N privatemsg.views.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ views/privatemsg.views.inc	26 Jun 2009 05:06:31 -0000
@@ -0,0 +1,247 @@
+<?php
+// $Id$
+/**
+ * @file
+ * Provide views data and handlers for privatemsg.module
+ */
+
+/**
+ * Implementation of hook_views_data()
+ */
+function privatemsg_views_data() {
+  // ----------------------------------------------------------------
+  // privatemsg table -- basic table information.
+
+  // Define the base group of this table. Fields that don't
+  // have a group defined will go into this field by default.
+  $data['pm_message']['table']['group']  = t('Private message');
+
+  // Advertise this table as a possible base table
+  $data['pm_message']['table']['base'] = array(
+    'field' => 'mid',
+    'title' => t('Private message'),
+    'help' => t("Private messages sent between users."),
+    'weight' => 10,
+  );
+
+  // For other base tables, explain how we join
+  $data['pm_message']['table']['join'] = array(
+    // Join with the user table
+    'user' => array(
+      'left_field' => 'uid',
+      'field' => 'author',
+    ),
+  );
+  
+  // ----------------------------------------------------------------
+  // pm_message table -- fields
+
+  // mid
+  $data['pm_message']['mid'] = array(
+    'title' => t('Mesage Id'),
+    'help' => t('The ID of the private message.'), // The help that appears on the UI,
+    // Information for displaying the nid
+    'field' => array(
+      'handler' => 'views_handler_field_privatemsg',
+      'click sortable' => TRUE,
+    ),
+    // Information for accepting a mid as an argument
+    'argument' => array(
+      'handler' => 'views_handler_argument_numeric',
+      //'parent' => 'views_handler_argument_numeric', // make sure parent is included
+      'name field' => 'subject', // the field to display in the summary.
+      'numeric' => TRUE,
+      'validate type' => 'numeric',
+    ),
+    // Information for accepting a mid as a filter
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    // Information for sorting on a mid.
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+  );
+
+  // title
+  // This definition has more items in it than it needs to as an example.
+  $data['pm_message']['subject'] = array(
+    'title' => t('Subject'), // The item it appears as on the UI,
+    'help' => t('The subject of the message.'), // The help that appears on the UI,
+     // Information for displaying a title as a field
+    'field' => array(
+      'handler' => 'views_handler_field_privatemsg',
+      'click sortable' => TRUE,
+     ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    // Information for accepting a title as a filter
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
+
+  // Body field
+  $data['pm_message']['body'] = array(
+    'title' => t('Body'), // The item it appears as on the UI,
+    'help' => t('The body of the message.'), // The help that appears on the UI,
+     // Information for displaying a title as a field
+    'field' => array(
+      'handler' => 'views_handler_field_markup',
+      'format' => variable_get('filter_default_format', 1), // The name of the format field or an integer
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+  );
+
+  // uid field
+  $data['pm_message']['author'] = array(
+    'title' => t('Author'),
+    'help' => t('Author of the message.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'base' => 'users',
+      'field' => 'uid',
+      'label' => t('Author'),
+    ),
+  );
+
+  // created field
+  $data['pm_message']['timestamp'] = array(
+    'title' => t('Sent date'), // The item it appears as on the UI,
+    'help' => t('The date and time when the message was sent.'), // The help that appears on the UI,
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_date',
+    ),
+  );
+
+  // ----------------------------------------------------------------------
+  // privatemsg message instance table
+
+  // Define the base group of this table. Fields that don't
+  // have a group defined will go into this field by default.
+  $data['pm_index']['table']['group']  = t('Private message');
+
+  // For other base tables, explain how we join
+  $data['pm_index']['table']['join'] = array(
+    // Directly links to privatemsg table.
+    'pm_message' => array(
+      'left_field' => 'mid',
+      'field' => 'mid',
+      'type' => 'INNER',
+  ),
+    // Join with the user table
+    'user' => array(
+      'left_field' => 'uid',
+      'field' => 'uid',
+    ),
+  );
+
+  // mid
+  $data['pm_index']['thread_id'] = array(
+    'title' => t('Message thread'),
+    'help' => t('Messages thread ID.'), // The help that appears on the UI,
+    // Information for displaying the nid
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+      'click sortable' => TRUE,
+    ),
+    // Information for accepting a mid as an argument
+    'argument' => array(
+      'handler' => 'views_handler_argument_numeric',
+      //'parent' => 'views_handler_argument_numeric', // make sure parent is included
+      'name field' => 'subject', // the field to display in the summary.
+      'numeric' => TRUE,
+      'validate type' => 'numeric',
+    ),
+    // Information for accepting a mid as a filter
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    // Information for sorting on a mid.
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+  );
+
+  // uid field
+  $data['pm_index']['uid'] = array(
+    'title' => t('Recipient'),
+    'help' => t('Relate a message to the user who received it.'),
+    'relationship' => array(
+      'handler' => 'views_handler_relationship',
+      'base' => 'users',
+      'field' => 'uid',
+      'label' => t('Recipient'),
+    ),
+  );
+
+  $data['pm_index']['is_new'] = array(
+    'title' => t('New?'), // The item it appears as on the UI,
+    'help' => t('Whether the user has read this message.'), // The help that appears on the UI,
+    'field' => array(
+      'handler' => 'views_handler_field_boolean',
+      'click sortable' => TRUE,
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_boolean_operator',
+      'label' => t('New?'),
+      'type' => 'yes-no',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+  );
+
+  $data['pm_index']['deleted'] = array(
+    'title' => t('Deleted?'), // The item it appears as on the UI,
+    'help' => t('Whether the user has deleted this message.'), // The help that appears on the UI,
+    'field' => array(
+      'handler' => 'views_handler_field_boolean',
+      'click sortable' => TRUE,
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_boolean_operator',
+      'label' => t('Deleted?'),
+      'type' => 'yes-no',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+  );
+
+  return $data;
+}
+
+/**
+ * Implementation of hook_views_handlers() to register all of the basic handlers
+ * views uses.
+ */
+function privatemsg_views_handlers() {
+  return array(
+    'info' => array(
+      'path' => drupal_get_path('module', 'privatemsg') . '/views',
+    ),
+    'handlers' => array(
+      // field handlers
+      'views_handler_field_privatemsg' => array(
+        'parent' => 'views_handler_field',
+      ),
+    ),
+  );
+}
+
+
+
Index: privatemsg.views_default.inc
===================================================================
RCS file: privatemsg.views_default.inc
diff -N privatemsg.views_default.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ views/privatemsg.views_default.inc	26 Jun 2009 05:06:31 -0000
@@ -0,0 +1,213 @@
+<?php
+// $Id$
+
+/**
+ * Provide default views for the privatemsg module.
+ */
+
+/**
+ * Implementation of hook_views_default_views().
+ */
+function privatemsg_views_default_views() {
+  $view = new view;
+  $view->name = 'privatemsg';
+  $view->description = '';
+  $view->tag = '';
+  $view->view_php = '';
+  $view->base_table = 'pm_message';
+  $view->is_cacheable = FALSE;
+  $view->api_version = 2;
+  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
+  $handler = $view->new_display('default', 'Defaults', 'default');
+  $handler->override_option('relationships', array(
+    'uid' => array(
+      'label' => 'Recipient',
+      'required' => 1,
+      'id' => 'uid',
+      'table' => 'pm_index',
+      'field' => 'uid',
+      'override' => array(
+        'button' => 'Override',
+      ),
+      'relationship' => 'none',
+    ),
+    'author' => array(
+      'label' => 'Author',
+      'required' => 1,
+      'id' => 'author',
+      'table' => 'pm_message',
+      'field' => 'author',
+      'override' => array(
+        'button' => 'Override',
+      ),
+      'relationship' => 'none',
+    ),
+  ));
+  $handler->override_option('fields', array(
+    'name_1' => array(
+      'label' => 'From',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'link_to_user' => 1,
+      'overwrite_anonymous' => 0,
+      'anonymous_text' => '',
+      'exclude' => 0,
+      'id' => 'name_1',
+      'table' => 'users',
+      'field' => 'name',
+      'relationship' => 'author',
+      'override' => array(
+        'button' => 'Override',
+      ),
+    ),
+    'subject' => array(
+      'label' => 'Subject',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'link_to_msg' => 1,
+      'exclude' => 0,
+      'id' => 'subject',
+      'table' => 'pm_message',
+      'field' => 'subject',
+      'relationship' => 'none',
+    ),
+    'timestamp' => array(
+      'label' => 'Sent date',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'date_format' => 'small',
+      'custom_date_format' => '',
+      'exclude' => 0,
+      'id' => 'timestamp',
+      'table' => 'pm_message',
+      'field' => 'timestamp',
+      'relationship' => 'none',
+    ),
+  ));
+  $handler->override_option('sorts', array(
+    'timestamp' => array(
+      'order' => 'DESC',
+      'granularity' => 'second',
+      'id' => 'timestamp',
+      'table' => 'pm_message',
+      'field' => 'timestamp',
+      'override' => array(
+        'button' => 'Override',
+      ),
+      'relationship' => 'none',
+    ),
+  ));
+  $handler->override_option('filters', array(
+    'uid_current' => array(
+      'operator' => '=',
+      'value' => '1',
+      'group' => '0',
+      'exposed' => FALSE,
+      'expose' => array(
+        'operator' => FALSE,
+        'label' => '',
+      ),
+      'id' => 'uid_current',
+      'table' => 'users',
+      'field' => 'uid_current',
+      'relationship' => 'uid',
+      'override' => array(
+        'button' => 'Override',
+      ),
+    ),
+  ));
+  $handler->override_option('access', array(
+    'type' => 'none',
+  ));
+  $handler->override_option('cache', array(
+    'type' => 'none',
+  ));
+  $handler->override_option('title', 'Messages');
+  $handler->override_option('items_per_page', 25);
+  $handler->override_option('use_pager', 'mini');
+  $handler->override_option('style_plugin', 'table');
+  $handler->override_option('style_options', array(
+    'grouping' => '',
+    'override' => 1,
+    'sticky' => 0,
+    'order' => 'asc',
+    'columns' => array(
+      'subject' => 'subject',
+      'timestamp' => 'timestamp',
+    ),
+    'info' => array(
+      'subject' => array(
+        'sortable' => 0,
+        'separator' => '',
+      ),
+      'timestamp' => array(
+        'sortable' => 0,
+        'separator' => '',
+      ),
+    ),
+    'default' => '-1',
+  ));
+  $handler = $view->new_display('page', 'Inbox', 'page_1');
+  $handler->override_option('path', 'privatemsg');
+  $handler->override_option('menu', array(
+    'type' => 'normal',
+    'title' => 'Private Messages',
+    'description' => '',
+    'weight' => '0',
+    'name' => 'navigation',
+  ));
+  $handler->override_option('tab_options', array(
+    'type' => 'none',
+    'title' => '',
+    'description' => '',
+    'weight' => 0,
+  ));
+
+  $views[$view->name] = $view;
+  return $views;
+}
\ No newline at end of file
Index: views_handler_field_privatemsg.inc
===================================================================
RCS file: views_handler_field_privatemsg.inc
diff -N views_handler_field_privatemsg.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ views/views_handler_field_privatemsg.inc	26 Jun 2009 05:06:31 -0000
@@ -0,0 +1,55 @@
+<?php
+// $Id$
+/**
+ * @file
+ * Contains the basic 'private message' field handler.
+ */
+
+/**
+ * Field handler to provide simple renderer that allows linking to a private message.
+ */
+class views_handler_field_privatemsg extends views_handler_field {
+  /**
+   * Constructor to provide additional field to add.
+   */
+  function construct() {
+    parent::construct();
+    $this->additional_fields['mid'] = 'mid';
+  }
+
+  function option_definition() {
+    $options = parent::option_definition();
+    $options['link_to_msg'] = array('default' => FALSE);
+    return $options;
+  }
+
+  /**
+   * Provide link to node option
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['link_to_msg'] = array(
+      '#title' => t('Link this field to its message'),
+      '#description' => t('This will override any other link you have set.'),
+      '#type' => 'checkbox',
+      '#default_value' => !empty($this->options['link_to_msg']),
+    );
+  }
+
+  /**
+   * Render whatever the data is as a link to the node.
+   *
+   * Data should be made XSS safe prior to calling this function.
+   */
+  function render_link($data, $values) {
+    if (!empty($this->options['link_to_msg']) && $data !== NULL && $data !== '') {
+      $this->options['alter']['make_link'] = TRUE;
+      $this->options['alter']['path'] = "messages/view/" . $values->{$this->aliases['mid']};
+    }
+    return $data;
+  }
+
+  function render($values) {
+    return $this->render_link(check_plain($values->{$this->field_alias}), $values);
+  }
+}
