Index: views_bookmark.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_bookmark/views_bookmark.module,v
retrieving revision 1.6.2.37
diff -u -F^f -r1.6.2.37 views_bookmark.module
--- views_bookmark.module	14 Jan 2008 05:12:57 -0000	1.6.2.37
+++ views_bookmark.module	18 Jan 2008 10:41:30 -0000
@@ -610,14 +610,13 @@ function views_bookmark_views_tables() {
           'query_handler' => 'views_bookmark_qhandler_ops',
           'vbid' => $bookmark->vbid,
         ),
-        'uid' => array(
-          'name' => t('Bookmark: User for @s', array('@s' => $bookmark->title)),
-          'handler' => 'views_bookmark_field_handler_username',
-          'query_handler' => 'views_bookmark_qhandler_username',
-          'sortable' => true,
-          'help' => t('This will display the author of the node.'),
-          'uid' => 'uid',
-          'vbid' => $bookmark->vbid,
+        'timestamp' => array(
+          'name' => t('Bookmark: @s Marked Time', array('@s' => $bookmark->title)),
+          'sortable' => TRUE,
+          'handler' => views_handler_field_dates(),
+          'option' => 'string',
+          'help' => t('Display the time the node was bookmarked by a user.')
+                  .' '. t('The option field may be used to specify the custom date format as it\'s required by the date() function or if "as time ago" has been chosen to customize the granularity of the time interval.'),
         ),
       ),
       'filters' => array(
@@ -653,6 +652,36 @@ function views_bookmark_views_tables() {
     $tables["views_bookmark_nodes_$bookmark->vbid"] = $table;
 
     $table = array(
+      'name' => 'users',
+      'join' => array(
+        'left' => array(
+          'table' => "views_bookmark_nodes_$bookmark->vbid",
+          'field' => 'uid',
+        ),
+        'right' => array(
+          'field' => 'uid'
+        ),
+      ),
+      'fields' => array(
+        'name' => array(
+          'name' => t('Bookmark: User for @s', array('@s' => $bookmark->title)),
+          'handler' => 'views_handler_field_username',
+          'sortable' => TRUE,
+          'help' => t('This will display the user who bookmarked the node.'),
+          'uid' => 'uid',
+          'addlfields' => array('uid'),
+        ),
+      ),
+      'sorts' => array(
+        'name' => array(
+          'name' => t('Bookmark: User for @s', array('@s' => $bookmark->title)),
+          'help' => t('Sort by the the name of the users who bookmarked the node using the %s mark. This probably makes sense only when the list is filtered for a single node; e.g., on a "Who\'s bookmarked this" tab.', array('%s' => $bookmark->title)),
+        ),
+      ),
+    );
+    $tables["views_bookmark_users_$bookmark->vbid"] = $table;
+
+    $table = array(
       'name' => 'views_bookmarks', 
       'provider' => 'views_bookmark',
       'join' => array(
@@ -775,20 +804,6 @@ function views_bookmark_field_handler_op
   }
 }
 
-function views_bookmark_field_handler_username($fieldinfo, $fielddata, $value, $data) {
-  $obj = new stdClass();
-  $uid_field = $fielddata['tablename'] . "_uid";
-  $name_field = $fielddata['tablename'] . "_name";
-  if (!$data->$name_field && $data->$uid_field) {
-    $obj = user_load(array('uid' => $data->$uid_field));
-  }
-  else {
-    $obj->name = $data->$name_field;
-    $obj->uid = $data->$uid_field;
-  }
-  return theme('username', $obj);
-}
-
 /**
  * handler that makes sure the right fields are available for a bookmark,
  * because the actual link text is completely variable.
@@ -807,22 +822,6 @@ function views_bookmark_qhandler_ops($fi
 }
 
 /**
- * Handler that makes sure the user name field is available for a bookmark.
- */
-function views_bookmark_qhandler_username($field, $fieldinfo, &$query) {
-  $num = $query->add_table('users', false, 1, array(
-    'left' => array(
-      'table' => $field['tablename'],
-      'field' => 'uid',
-    ),
-    'right' => array(
-      'field' => 'uid'
-    ),
-  ));
-  $query->add_field('name', $query->get_table_name('users', $num), $field['tablename'] . '_name');
-}
-
-/**
  * Handler that lets us filter nodes to include only those by a particular user.
  */
 function views_bookmark_filter_handler_uid($op, $filter, $filterinfo, &$query) {
Index: views_bookmark.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views_bookmark/views_bookmark.install,v
retrieving revision 1.2.2.12
diff -u -F^f -r1.2.2.12 views_bookmark.install
--- views_bookmark.install	6 Jan 2008 20:00:14 -0000	1.2.2.12
+++ views_bookmark.install	18 Jan 2008 10:41:44 -0000
@@ -292,7 +292,67 @@ function views_bookmark_update_7() {
   if (function_exists('views_devel_caches')) {
     $caches = views_devel_caches();
     foreach ($caches as $cache_table) {
-      db_query("TRUNCATE {$cache_table}");
+      db_query('TRUNCATE {'. $cache_table .'}');
+    }
+  }
+  return $ret;
+}
+
+/**
+ * Update all views that use the 'views_bookmark_nodes_N.uid' field to use
+ * the 'views_bookmark_users_N.name' one. See http://drupal.org/node/211112
+ */
+function views_bookmark_update_5150() {
+  $ret = array();
+  // Ensure views is available.
+  include_once(drupal_get_path('module', 'views') .'/views.module');
+  // Load the cache to ensure _views_get_default_views() is available.
+  if (function_exists('views_load_cache')) {
+    views_load_cache();
+  }
+
+  // Update database views automatically.
+  $result = db_query("SELECT vid FROM {view_view}");
+
+  while ($view = db_fetch_object($result)) {
+    $view = views_load_view($view->vid);
+    $views[$view->name] = $view;
+    // Check if this view uses a 'views_bookmark_nodes_N.uid' field.
+    foreach ($view->field as $delta => $field) {
+      if (strpos($field['tablename'], 'views_bookmark_nodes_') === 0 && $field['field'] == 'uid') {
+        // If so, change it to use 'views_bookmark_users_N.name' instead.
+        $view->field[$delta]['tablename'] = str_replace('_nodes_', '_users_', $field['tablename']);
+        $view->field[$delta]['field'] = 'name';
+        // Put the updated message in the return array.
+        $ret[] = array('success' => TRUE, 'query' => t('The view %name has been updated to use the <em>views_bookmark_users_N.name</em> field', array('%name' => $view->name)));
+      }
+    }
+    _views_save_view($view);
+  }
+
+  // Because we can't actually update default views, just give the user a warning.
+  $default_views = _views_get_default_views();
+  $default_views_warnings = array();
+  foreach ($default_views as $view) {
+    foreach ($view->field as $delta => $field) {
+      // Check if this view uses a 'views_bookmark_nodes_N.uid' field.
+      if (strpos($field['tablename'], 'views_bookmark_nodes_') === 0 && $field['field'] == 'uid') {
+        $default_views_warnings[] = t('%name needs the %field field updated.', array('%name' => $view->name, '%field' => $field['id']));
+      }
+    }
+  }
+
+  if (!empty($default_views_warnings)) {
+    $message = t('The following views are provided by modules and need to be updated in order to work properly with this version of Views Bookmark.') . theme('item_list', $default_views_warnings);
+    drupal_set_message($message, 'error');
+    watchdog('views_bookmark', $message, WATCHDOG_ERROR);
+  }
+
+  // Clear views caches.
+  if (function_exists('views_devel_caches')) {
+    $caches = views_devel_caches();
+    foreach ($caches as $cache_table) {
+      db_query('TRUNCATE {'. $cache_table .'}');
     }
   }
   return $ret;
