Index: prev_next_views.info
===================================================================
--- prev_next_views.info	(revision 0)
+++ prev_next_views.info	(revision 0)
@@ -0,0 +1,7 @@
+; $Id: $
+name = Prev/Next for Views
+description = Provide an API for previous/next nodes for Views results
+package = Views
+core = 6.x
+dependencies[] = views
+dependencies[] = prev_next
Index: prev_next_views.admin.inc
===================================================================
--- prev_next_views.admin.inc	(revision 0)
+++ prev_next_views.admin.inc	(revision 0)
@@ -0,0 +1,18 @@
+<?php
+
+function prev_next_views_settings() {
+  $options = array();
+  foreach (views_get_all_views() as $key => $view) {
+    $options[$key] = $view->name;
+  }
+
+  $form['prev_next_views_enabled'] = array(
+    '#type' => 'select',
+    '#title' => t('Enable the Prev/Next API for the following views'),
+    '#default_value' => variable_get('prev_next_views_enabled', array()),
+    '#options' => $options,
+    '#multiple' => TRUE,
+  );
+
+  return system_settings_form($form);
+}
Index: prev_next_views.module
===================================================================
--- prev_next_views.module	(revision 0)
+++ prev_next_views.module	(revision 0)
@@ -0,0 +1,92 @@
+<?php
+
+function prev_next_views_prev_next_nid($nid, $op = 'next') {
+  if (isset($_SESSION['prev_next_views'])) {
+    $index = array_search($nid, $_SESSION['prev_next_views']);
+    if ($index !== FALSE) {
+      $ret = $index;
+      if ($op == 'prev') {
+        $ret--;
+      }
+      elseif ($op == 'next') {
+        $ret++;
+      }
+
+      if (($ret >= 0) && ($ret < count($_SESSION['prev_next_views']))) {
+        return $_SESSION['prev_next_views'][$ret];
+      }
+      else {
+        return 0;
+      }
+    }
+  }
+  return FALSE;
+}
+
+
+/**
+ * Implementation of hook_perm().
+ */
+function prev_next_views_perm() {
+  return array('administer prev_next_views');
+}
+
+
+/**
+* Implementation of hook_menu().
+*/
+function prev_next_views_menu() {
+  $items = array();
+
+  $items['admin/settings/prev_next/views'] = array(
+    'title' => 'Views',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('prev_next_views_settings'),
+    'access arguments'  => array('administer prev_next_views'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 10,
+    'file' => 'prev_next_views.admin.inc',
+  );
+
+  return $items;
+}
+
+
+/**
+ * Implementation of hook_nodeapi().
+ */
+function prev_next_views_nodeapi(&$node, $op) {
+  if (isset($_SESSION['prev_next_views']) && (array_search($node->nid, $_SESSION['prev_next_views']) === FALSE)) {
+    // The current node is no longer part of the views results, so forget about it
+    unset($_SESSION['prev_next_views']);
+  }
+}
+
+
+/**
+ * Implementation of hook_views_api().
+ */
+function prev_next_views_views_api() {
+  return array(
+    'api' => 2,
+  );
+}
+
+
+/**
+ * Implementation of hook_views_pre_execute().
+ */
+function prev_next_views_views_pre_execute(&$view) {
+  if (in_array($view->name, variable_get('prev_next_views_enabled', array()))) {
+    $query = db_rewrite_sql($view->build_info['query'], $view->base_table, $view->base_field, array('view' => &$view));
+    $args = $view->build_info['query_args'];
+
+    $result = db_query($query, $args);
+    $nids = array();
+    while ($item = db_fetch_array($result)) {
+      $nids[] = $item['nid'];
+    }
+
+    $_SESSION['prev_next_views'] = $nids;
+  }
+}
Index: prev_next.module
===================================================================
--- prev_next.module	(revision 85)
+++ prev_next.module	(working copy)
@@ -15,6 +15,11 @@
     'page arguments'   => array('prev_next_admin'),
     'access arguments' => array('access administration pages'),
   );
+  $items['admin/settings/prev_next/general'] = array(
+    'title' => 'General',
+    'weight' => 0,
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+  );
 
   $items['admin/settings/prev_next/re-index'] = array(
     'type'             => MENU_CALLBACK,
@@ -252,6 +257,15 @@
  * Callable API function to get the next/prev nid of a given nid
  */
 function prev_next_nid($nid, $op = 'next') {
+  foreach (module_implements('prev_next_nid') as $module) {
+    $function = $module . '_prev_next_nid';
+    $ret = $function($nid, $op);
+    if ($ret !== FALSE) {
+      // If the function returns FALSE, keep trying other methods
+      return $ret;
+    }
+  }
+
   if ($op == 'prev') {
     return prev_next_nid_prev($nid);
   }
