diff --git a/prev_next.info b/prev_next.info
index d1ac06d..2456bbc 100644
--- a/prev_next.info
+++ b/prev_next.info
@@ -1,3 +1,5 @@
 name = Prev/Next
 description = Provide a high performance API for previous/next nodes for a given node
-core = 6.x
+core = 7.x
+
+configure = admin/config/system/prev_next
diff --git a/prev_next.install b/prev_next.install
index 0349140..1286ae6 100644
--- a/prev_next.install
+++ b/prev_next.install
@@ -8,31 +8,56 @@
  * @ingroup prev_next
  */
 
-function prev_next_install() {
-  drupal_install_schema('prev_next');
-}
-
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function prev_next_uninstall() {
-  drupal_uninstall_schema('prev_next');
-  db_query("DELETE FROM {variable} WHERE name LIKE '%s%%'", 'prev_next');
+  db_delete('variable')
+  ->condition('name', 'prev_next%%', 'LIKE')
+  ->execute();
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function prev_next_enable() {
-  $max_nid = db_result(db_query('SELECT MAX(nid) FROM {node}'));
+  $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
   variable_set('prev_next_index_nid', $max_nid);
   if ($max_nid) {
     drupal_set_message(t('Prev/Next will index from node %nid downward.', array('%nid' => $max_nid)));
   }
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function prev_next_schema() {
   $schema['prev_next_node'] = array(
     'description' => 'Prev/Next node',
     'fields' => array(
-      'nid'      => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,),
-      'prev_nid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,),
-      'next_nid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,),
-      'changed'  => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE,),
+      'nid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'prev_nid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'next_nid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'changed' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
     ),
     'primary key' => array('nid'),
     'indexes' => array(
diff --git a/prev_next.module b/prev_next.module
index 4745661..610d285 100644
--- a/prev_next.module
+++ b/prev_next.module
@@ -5,31 +5,26 @@ define('PREV_NEXT_INDEXING_CRITERIA_DEFAULT', 'nid');
 define('PREV_NEXT_NODE_TYPE', 'prev_next_node_type_');
 define('PREV_NEXT_NUM_BLOCKS_DEFAULT', 1);
 define('PREV_NEXT_DISPLAY_DEFAULT', 1);
-define('PREV_NEXT_DISPLAY_TEXT_PREV_DEFAULT', '[title] »');
-define('PREV_NEXT_DISPLAY_TEXT_NEXT_DEFAULT', '« [title]');
+define('PREV_NEXT_DISPLAY_TEXT_PREV_DEFAULT', '[node:title] »');
+define('PREV_NEXT_DISPLAY_TEXT_NEXT_DEFAULT', '« [node:title]');
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function prev_next_menu() {
-  $items['admin/settings/prev_next'] = array(
-    'title'            => 'Prev/Next',
-    'description'      => 'Prev/Next API for nodes',
-    'page callback'    => 'drupal_get_form',
-    'page arguments'   => array('prev_next_admin'),
+  $items['admin/config/system/prev_next'] = array(
+    'title' => 'Prev/Next',
+    'description' => 'Prev/Next API for nodes',
+    'page callback' => 'drupal_get_form',
+    '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,
-    'title'            => 'Prev/Next reset',
-    'page callback'    => 'drupal_get_form',
-    'page arguments'   => array('prev_next_reindex_confirm'),
+  $items['admin/config/system/prev_next/re-index'] = array(
+    'type' => MENU_CALLBACK,
+    'title' => 'Prev/Next reset',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('prev_next_reindex_confirm'),
     'access arguments' => array('access administration pages'),
   );
 
@@ -39,107 +34,105 @@ function prev_next_menu() {
 /**
  * Menu callback argument. Creates the prev_next administration form.
  */
-function prev_next_admin() {
+function prev_next_admin($form, &$form_state) {
   $form['status'] = array(
-    '#type'   => 'fieldset',
-    '#title'  => t('Indexing status'),
+    '#type' => 'fieldset',
+    '#title' => t('Indexing status'),
   );
 
   $max_nid = variable_get('prev_next_index_nid', 0);
   $cond =  _prev_next_node_types_sql();
 
-  $total = db_result(db_query("SELECT COUNT(nid) FROM {node} WHERE status = 1 $cond"));
-  $completed = db_result(db_query("SELECT COUNT(nid) FROM {prev_next_node}"));
+  $total = db_query("SELECT COUNT(nid) FROM {node} WHERE status = 1 $cond")->fetchField();
+  $completed = db_query("SELECT COUNT(nid) FROM {prev_next_node}")->fetchField();
   $remaining = max(0, $total - $completed);
 
-  $percentage = ((int)min(100, 100 * ($total - $remaining) / max(1, $total))) .'%';
+  $percentage = ((int) min(100, 100 * ($total - $remaining) / max(1, $total))) . '%';
   $status = t('<p>%percentage of nodes have been indexed. There are %remaining items left to index, out of a total of %total.</p>',
     array(
-      '%percentage' => $percentage,
-      '%remaining'  => $remaining,
-      '%total'      => $total,
-    ));
+    '%percentage' => $percentage,
+    '%remaining' => $remaining,
+    '%total' => $total,
+  ));
   $status .= ($max_nid) ? t('<p>Max node ID for indexing on the next cron run: @max.</p>', array('@max' => $max_nid)) : t('<p>Existing nodes have finished prev/next indexing.</p>');
 
-  $form['status']['status'] = array(
-    '#value' => $status,
-  );
+  $form['status']['#description'] = $status;
 
   $form['status']['reindex'] = array(
-    '#type'  => 'submit',
+    '#type' => 'submit',
     '#value' => t('Re-index'),
   );
 
   $form['prev_next_batch_size'] = array(
-    '#title'         => t('Batch size'),
-    '#description'   => t('Number of nodes to index during each cron run.'),
-    '#type'          => 'textfield',
-    '#size'          => 6,
-    '#maxlength'     => 7,
+    '#title' => t('Batch size'),
+    '#description' => t('Number of nodes to index during each cron run.'),
+    '#type' => 'textfield',
+    '#size' => 6,
+    '#maxlength' => 7,
     '#default_value' => variable_get('prev_next_batch_size', PREV_NEXT_BATCH_SIZE_DEFAULT),
-    '#required'      => TRUE,
+    '#required' => TRUE,
   );
 
   $form['prev_next_num_blocks'] = array(
-    '#title'         => t('Blocks'),
-    '#description'   => t('Number of blocks available.'),
-    '#type'          => 'textfield',
-    '#size'          => 2,
-    '#maxlength'     => 3,
+    '#title' => t('Blocks'),
+    '#description' => t('Number of blocks available.'),
+    '#type' => 'textfield',
+    '#size' => 2,
+    '#maxlength' => 3,
     '#default_value' => variable_get('prev_next_num_blocks', PREV_NEXT_NUM_BLOCKS_DEFAULT),
-    '#required'      => TRUE,
+    '#required' => TRUE,
   );
 
   $form['node_types'] = array(
-    '#type'        => 'fieldset',
-    '#title'       => t('Content types'),
+    '#type' => 'fieldset',
+    '#title' => t('Content types'),
     '#description' => t('Define settings for each content type. If none of them is included, then all of them will be.'),
   );
 
-  foreach (node_get_types() as $type => $name) {
+  foreach (node_type_get_types() as $type => $name) {
 
     $form['node_types'][$type] = array(
-      '#type'         => 'fieldset',
-      '#description'  => t('Note: changing one of these values will reset the entire Prev/Next index.'),
-      '#title'        => node_get_types('name', $type),
-      '#collapsible'  => TRUE,
-      '#collapsed'    => !variable_get(PREV_NEXT_NODE_TYPE . $type, 0)
+      '#type' => 'fieldset',
+      '#description' => t('Note: changing one of these values will reset the entire Prev/Next index.'),
+      '#title' => node_type_get_name($type),
+      '#collapsible' => TRUE,
+      '#collapsed' => !variable_get(PREV_NEXT_NODE_TYPE . $type, 0),
     );
 
     $form['node_types'][$type][PREV_NEXT_NODE_TYPE . $type] = array(
-      '#type'          => 'checkbox',
-      '#title'         => t('Include'),
+      '#type' => 'checkbox',
+      '#title' => t('Include'),
       '#default_value' => variable_get(PREV_NEXT_NODE_TYPE . $type, 0),
     );
     $form['node_types'][$type][PREV_NEXT_NODE_TYPE . $type . '_current'] = array(
-      '#type'          => 'hidden',
-      '#default_value' => variable_get(PREV_NEXT_NODE_TYPE . $type, 0)
+      '#type' => 'hidden',
+      '#default_value' => variable_get(PREV_NEXT_NODE_TYPE . $type, 0),
     );
 
     $form['node_types'][$type][PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria'] = array(
-      '#title'          => t('Indexing criteria'),
-      '#type'           => 'select',
-      '#options'        => array(
-        'nid'     => t('Node ID'),
+      '#title' => t('Indexing criteria'),
+      '#type' => 'select',
+      '#options' => array(
+        'nid' => t('Node ID'),
         'created' => t('Post date'),
         'changed' => t('Updated date'),
-        'title'   => t('Title')
+        'title' => t('Title'),
       ),
-      '#default_value'  => variable_get(PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria', PREV_NEXT_INDEXING_CRITERIA_DEFAULT)
+      '#default_value' => variable_get(PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria', PREV_NEXT_INDEXING_CRITERIA_DEFAULT),
     );
     $form['node_types'][$type][PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria_current'] = array(
-      '#type'   => 'hidden',
-      '#value'  => variable_get(PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria', PREV_NEXT_INDEXING_CRITERIA_DEFAULT)
+      '#type' => 'hidden',
+      '#value' => variable_get(PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria', PREV_NEXT_INDEXING_CRITERIA_DEFAULT),
     );
 
     $form['node_types'][$type][PREV_NEXT_NODE_TYPE . $type . '_same_type'] = array(
-      '#type'          => 'checkbox',
-      '#title'         => t('Only nodes with same content type'),
+      '#type' => 'checkbox',
+      '#title' => t('Only nodes with same content type'),
       '#default_value' => variable_get(PREV_NEXT_NODE_TYPE . $type . '_same_type', 0),
     );
     $form['node_types'][$type][PREV_NEXT_NODE_TYPE . $type . '_same_type_current'] = array(
-      '#type'          => 'hidden',
-      '#default_value' => variable_get(PREV_NEXT_NODE_TYPE . $type . '_same_type', 0)
+      '#type' => 'hidden',
+      '#default_value' => variable_get(PREV_NEXT_NODE_TYPE . $type . '_same_type', 0),
     );
 
   }
@@ -154,7 +147,7 @@ function prev_next_admin() {
  */
 function prev_next_admin_validate($form, &$form_state) {
   if ($form_state['values']['op'] == t('Re-index')) {
-    drupal_goto('admin/settings/prev_next/re-index');
+    drupal_goto('admin/config/system/prev_next/re-index');
   }
 
   // Max_nid is just a markup field and should not cause a variable to be set.
@@ -173,12 +166,11 @@ function prev_next_admin_submit($form, &$form_state) {
   $rebuild = FALSE;
 
   // Test sensitive values.
-  foreach (node_get_types() as $type => $name) {
-    if ($form_state['values'][PREV_NEXT_NODE_TYPE . $type . '_current'] != $form_state['values'][PREV_NEXT_NODE_TYPE . $type]
-      || $form_state['values'][PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria_current'] != $form_state['values'][PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria']
-      || $form_state['values'][PREV_NEXT_NODE_TYPE . $type . '_same_type_current'] != $form_state['values'][PREV_NEXT_NODE_TYPE . $type . '_same_type']
-    )
+  foreach (node_type_get_types() as $type => $name) {
+    if ($form_state['values'][PREV_NEXT_NODE_TYPE . $type . '_current'] != $form_state['values'][PREV_NEXT_NODE_TYPE . $type] || $form_state['values'][PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria_current'] != $form_state['values'][PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria'] || $form_state['values'][PREV_NEXT_NODE_TYPE . $type . '_same_type_current'] != $form_state['values'][PREV_NEXT_NODE_TYPE . $type . '_same_type']
+    ) {
       $rebuild = TRUE;
+    }
   }
 
   // If the search criterias has been changed, re-index.
@@ -186,27 +178,39 @@ function prev_next_admin_submit($form, &$form_state) {
     prev_next_reindex();
     drupal_set_message(t('The Prev/Next index will be rebuilt.'));
   }
-  $form_state['redirect'] = 'admin/settings/prev_next';
+  $form_state['redirect'] = 'admin/config/system/prev_next';
 }
 
-function prev_next_reindex_confirm() {
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
+function prev_next_reindex_confirm($form, &$form_state) {
   return confirm_form(array(), t('Are you sure you want to re-index Prev/Next?'),
-    'admin/settings/prev_next', t('The entire Prev/Next index will be reset and rebuilt incrementally as cron runs. action cannot be undone.'), t('Re-index'), t('Cancel'));
+    'admin/config/system/prev_next', t('The entire Prev/Next index will be reset and rebuilt incrementally as cron runs. action cannot be undone.'), t('Re-index'), t('Cancel'));
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function prev_next_reindex_confirm_submit(&$form, &$form_state) {
   if ($form['confirm']) {
     prev_next_reindex();
     drupal_set_message(t('The Prev/Next index will be rebuilt.'));
-    $form_state['redirect'] = 'admin/settings/prev_next';
+    $form_state['redirect'] = 'admin/config/system/prev_next';
   }
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function prev_next_reindex() {
   // Wipe the table clean
   db_query('TRUNCATE {prev_next_node}');
   // Get the highest nid
-  $max_nid = db_result(db_query('SELECT MAX(nid) FROM {node}'));
+  $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
   // Set the variable to that
   variable_set('prev_next_index_nid', $max_nid);
   if ($max_nid) {
@@ -215,7 +219,7 @@ function prev_next_reindex() {
 }
 
 /**
- * Implementation of hook_cron().
+ * Implements hook_cron().
  */
 function prev_next_cron() {
   $max_nid = variable_get('prev_next_index_nid', 0);
@@ -225,12 +229,14 @@ function prev_next_cron() {
     $cond = _prev_next_node_types_sql();
 
     timer_start('prev_next_cron');
-    $result = db_query("SELECT nid FROM {node} WHERE nid <= %d AND status = 1 $cond ORDER BY nid DESC LIMIT %d", $max_nid, $batch_size);
+    $result = db_query_range("SELECT nid FROM {node} WHERE nid <= :nid AND status = 1 $cond ORDER BY nid DESC", 0, $batch_size, array(':nid' => $max_nid));
     $count = 0;
 
-    while ($row = db_fetch_object($result)) {
+    foreach ($result as $row) {
       // Remove existing data for this node.
-      db_query("DELETE FROM {prev_next_node} WHERE nid = %d", $row->nid);
+      db_delete('prev_next_node')
+        ->condition('nid', $row->nid)
+        ->execute();
 
       _prev_next_add($row->nid);
       // Note that we have indexed at least one node.
@@ -249,201 +255,225 @@ function prev_next_cron() {
       // If all nodes have been indexed, set to zero to skip future cron runs.
       variable_set('prev_next_index_nid', 0);
     }
-    watchdog('prev_next', 'Indexed %count nodes in %time milliseconds.', array('%count' => $count, '%time' => $time));
+    if ($count) watchdog('prev_next', 'Indexed %count nodes in %time milliseconds.', array('%count' => $count, '%time' => $time));
 
-    $total = db_result(db_query("SELECT COUNT(nid) FROM {node} WHERE status = 1 $cond"));
-    $completed = db_result(db_query("SELECT COUNT(nid) FROM {prev_next_node}"));
+    $total = db_query("SELECT COUNT(nid) FROM {node} WHERE status = 1 $cond")->fetchField();
+    $completed = db_query("SELECT COUNT(nid) FROM {prev_next_node}")->fetchField();
     $remaining = max(0, $total - $completed);
     drupal_set_message(t('Indexed %count nodes for the Prev/Next index. There are %remaining items left to index.', array(
       '%count' => $count,
-      '%remaining'  => $remaining
+      '%remaining' => $remaining,
     )));
 
   }
 }
 
 /**
- * Implementation of hook_block().
+ * Implements hook_block_info().
  */
-function prev_next_block($op = 'list', $delta = 0, $edit = array()) {
-  switch ($op) {
-
-    case 'list':
-      $num_blocks = variable_get('prev_next_num_blocks', PREV_NEXT_NUM_BLOCKS_DEFAULT);
-      for ($b = 0; $b < $num_blocks ; $b++) {
-        $blocks[$b] = array(
-          'info'    => t('Prev/Next links !blocknum', array('!blocknum' => 1+$b)),
-          'status'  => 0,
-          'cache'   => BLOCK_CACHE_PER_PAGE
-        );
-      }
-      return $blocks;
-      break;
+function prev_next_block_info() {
+  $num_blocks = variable_get('prev_next_num_blocks', PREV_NEXT_NUM_BLOCKS_DEFAULT);
+  for ($b = 0; $b < $num_blocks; $b++) {
+    $blocks[$b] = array(
+      'info' => t('Prev/Next links !blocknum', array('!blocknum' => 1 + $b)),
+      'status' => 0,
+      'cache' => DRUPAL_CACHE_PER_PAGE,
+    );
+  }
+  return $blocks;
+}
 
-    case 'configure':
-      $description = (module_exists('token')) ? 'Use the available tokens (see below) to customize the link text.' : 'The [title] token will be replaced by the actual node title.';
+/**
+ * Implements hook_block_configure().
+ */
+function prev_next_block_configure($delta) {
+  $description = 'Use the available tokens ' . (module_exists('token') ? '(see below)' : '') . ' to customize the link text.';
 
-      $form['previous'] = array(
-        '#type'         => 'fieldset',
-        '#title'        => t('Previous Node'),
-        '#collapsible'  => TRUE,
-      );
-      $form['previous']['prev_next_display_prev' . $delta] = array(
-        '#type'           => 'checkbox',
-        '#title'          => t('Display'),
-        '#default_value'  => variable_get('prev_next_display_prev' . $delta, PREV_NEXT_DISPLAY_DEFAULT),
-      );
-      $form['previous']['prev_next_display_text_prev' . $delta] = array(
-        '#type'           => 'textfield',
-        '#title'          => t('Link text'),
-        '#description'    => $description,
-        '#default_value'  => variable_get('prev_next_display_text_prev' . $delta, PREV_NEXT_DISPLAY_TEXT_PREV_DEFAULT),
-      );
-      if (module_exists('token')) {
-        $form['previous']['token_help'] = array(
-          '#title' => t('Replacement patterns'),
-          '#type' => 'fieldset',
-          '#collapsible' => TRUE,
-          '#collapsed' => TRUE,
-        );
-        $form['previous']['token_help']['help'] = array(
-          '#value' => theme('token_help', 'node'),
-        );
-      }
+  $form['previous'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Previous Node'),
+    '#collapsible' => TRUE,
+  );
+  $form['previous']['prev_next_display_prev' . $delta] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Display'),
+    '#default_value' => variable_get('prev_next_display_prev' . $delta, PREV_NEXT_DISPLAY_DEFAULT),
+  );
+  $form['previous']['prev_next_display_text_prev' . $delta] = array(
+    '#type' => 'textfield',
+    '#title' => t('Link text'),
+    '#description' => $description,
+    '#default_value' => variable_get('prev_next_display_text_prev' . $delta, PREV_NEXT_DISPLAY_TEXT_PREV_DEFAULT),
+  );
+  if (module_exists('token')) {
+    $form['previous']['tokens'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Replacement patterns'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+    );
+    $form['previous']['tokens']['tokens'] = array(
+      '#theme' => 'token_tree',
+      '#token_types' => array('node'),
+    );
+  }
 
-      $form['next'] = array(
-        '#type'         => 'fieldset',
-        '#title'        => t('Next Node'),
-        '#collapsible'  => TRUE,
-      );
-      $form['next']['prev_next_display_next' . $delta] = array(
-        '#type'           => 'checkbox',
-        '#title'          => t('Display'),
-        '#default_value'  => variable_get('prev_next_display_next' . $delta, PREV_NEXT_DISPLAY_DEFAULT),
-      );
-      $form['next']['prev_next_display_text_next' . $delta] = array(
-        '#type'           => 'textfield',
-        '#title'          => t('Link text'),
-        '#description'    => $description,
-        '#default_value'  => variable_get('prev_next_display_text_next' . $delta, PREV_NEXT_DISPLAY_TEXT_NEXT_DEFAULT),
-      );
-      if (module_exists('token')) {
-        $form['next']['token_help'] = array(
-          '#title' => t('Replacement patterns'),
-          '#type' => 'fieldset',
-          '#collapsible' => TRUE,
-          '#collapsed' => TRUE,
-        );
-        $form['next']['token_help']['help'] = array(
-          '#value' => theme('token_help', 'node'),
-        );
+  $form['next'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Next Node'),
+    '#collapsible' => TRUE,
+  );
+  $form['next']['prev_next_display_next' . $delta] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Display'),
+    '#default_value' => variable_get('prev_next_display_next' . $delta, PREV_NEXT_DISPLAY_DEFAULT),
+  );
+  $form['next']['prev_next_display_text_next' . $delta] = array(
+    '#type' => 'textfield',
+    '#title' => t('Link text'),
+    '#description' => $description,
+    '#default_value' => variable_get('prev_next_display_text_next' . $delta, PREV_NEXT_DISPLAY_TEXT_NEXT_DEFAULT),
+  );
+  if (module_exists('token')) {
+    $form['next']['tokens'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Replacement patterns'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+    );
+    $form['next']['tokens']['tokens'] = array(
+      '#theme' => 'token_tree',
+      '#token_types' => array('node'),
+    );
+  }
+  return $form;
+}
+
+/**
+ * Implements hook_block_save().
+ */
+function prev_next_block_save($delta, $edit) {
+  variable_set('prev_next_display_prev' . $delta, $edit['prev_next_display_prev' . $delta]);
+  variable_set('prev_next_display_next' . $delta, $edit['prev_next_display_next' . $delta]);
+  variable_set('prev_next_display_text_prev' . $delta, $edit['prev_next_display_text_prev' . $delta]);
+  variable_set('prev_next_display_text_next' . $delta, $edit['prev_next_display_text_next' . $delta]);
+}
+
+/**
+ * Implements hook_block_view().
+ */
+function prev_next_block_view($delta) {
+  $content = '';
+  $block = array();
+  $next_display = variable_get('prev_next_display_next' . $delta, PREV_NEXT_DISPLAY_DEFAULT);
+  $next_text = variable_get('prev_next_display_text_next' . $delta, PREV_NEXT_DISPLAY_TEXT_NEXT_DEFAULT);
+  $prev_display = variable_get('prev_next_display_prev' . $delta, PREV_NEXT_DISPLAY_DEFAULT);
+  $prev_text = variable_get('prev_next_display_text_prev' . $delta, PREV_NEXT_DISPLAY_TEXT_PREV_DEFAULT);
+
+  if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2) ) {
+    $node = node_load(arg(1));
+    $n_nid = prev_next_nid($node->nid, 'next');
+    $p_nid = prev_next_nid($node->nid, 'prev');
+
+    if ($n_nid || $p_nid) {
+
+      if ($p_nid && $prev_display && $prev_text != '') {
+        $p_node = node_load($p_nid);
+        $link = token_replace($prev_text, array('node' => $p_node));
+        $options = array('html' => TRUE);
+        $content .= '<li class="prev-next-link-prev">' . l($link, "node/$p_nid", $options) . '</li>';
       }
-    return $form;
-    break;
-
-    case 'save':
-      variable_set('prev_next_display_prev' . $delta, $edit['prev_next_display_prev' . $delta]);
-      variable_set('prev_next_display_next' . $delta, $edit['prev_next_display_next' . $delta]);
-      variable_set('prev_next_display_text_prev' . $delta, $edit['prev_next_display_text_prev' . $delta]);
-      variable_set('prev_next_display_text_next' . $delta, $edit['prev_next_display_text_next' . $delta]);
-      break;
-
-    case 'view':
-      $content = '';
-      $next_display = variable_get('prev_next_display_next' . $delta, PREV_NEXT_DISPLAY_DEFAULT);
-      $next_text = variable_get('prev_next_display_text_next' . $delta, PREV_NEXT_DISPLAY_TEXT_NEXT_DEFAULT);
-      $prev_display = variable_get('prev_next_display_prev' . $delta, PREV_NEXT_DISPLAY_DEFAULT);
-      $prev_text = variable_get('prev_next_display_text_prev' . $delta, PREV_NEXT_DISPLAY_TEXT_PREV_DEFAULT);
-
-      if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2) ) {
-        $node = node_load(arg(1));
-        $n_nid = prev_next_nid($node->nid, 'next');
-        $p_nid = prev_next_nid($node->nid, 'prev');
-
-        if ($n_nid || $p_nid) {
-
-          if ($p_nid && $prev_display && $prev_text != '') {
-            $p_node = node_load($p_nid);
-            if (module_exists('token')) {
-              $link = token_replace($prev_text, 'node', $p_node);
-            }
-            else {
-              $link = str_replace('[title]', $p_node->title, $prev_text);
-            }
-            $options = array('html' => TRUE);
-            $content .= '<li class="prev-next-link-prev">' . l($link, "node/$p_nid", $options) . '</li>';
-          }
-
-          if ($n_nid && $next_display && $next_text != '') {
-            $n_node = node_load($n_nid);
-            if (module_exists('token')) {
-              $link = token_replace($next_text, 'node', $n_node);
-            }
-            else {
-              $link = str_replace('[title]', $n_node->title, $next_text);
-            }
-            $options = array('html' => TRUE);
-            $content .= '<li class="prev-next-link-next">' . l($link, "node/$n_nid", $options) . '</li>';
-          }
-
-          $block = array(
-            'subject' => t('Prev/Next links'),
-            'content' => '<ul class="prev-next-links">' . $content . '</ul>'
-          );
-
-        }
 
+      if ($n_nid && $next_display && $next_text != '') {
+        $n_node = node_load($n_nid);
+        $link = token_replace($next_text,  array('node' => $n_node));
+        $options = array('html' => TRUE);
+        $content .= '<li class="prev-next-link-next">' . l($link, "node/$n_nid", $options) . '</li>';
       }
 
-    return $block;
+      $block = array(
+        'subject' => t('Prev/Next links'),
+        'content' => '<ul class="prev-next-links">' . $content . '</ul>',
+      );
+
+    }
 
   }
 
+  return $block;
 }
 
 /**
  * Create or update the prev_next records.
  */
 function _prev_next_add($nid) {
-  $node_type = db_result(db_query("SELECT type FROM {node} WHERE nid = %d LIMIT 1", $nid));
+  $node_type = db_query_range("SELECT type FROM {node} WHERE nid = :nid", 0, 1, array(':nid' => $nid))->fetchField();
   $search_criteria = variable_get(PREV_NEXT_NODE_TYPE . $node_type . '_indexing_criteria', PREV_NEXT_INDEXING_CRITERIA_DEFAULT);
-
-  $criteria_value = db_result(db_query("SELECT %s FROM {node} WHERE nid = %d LIMIT 1", $search_criteria, $nid));
-
   $cond = _prev_next_node_types_sql($node_type);
 
-  $next_nid = db_result(db_query("SELECT nid FROM {node} WHERE %s > '%s' AND status = 1 $cond ORDER BY %s ASC LIMIT 1",
-    $search_criteria, $criteria_value, $search_criteria));
-
-  $prev_nid = db_result(db_query("SELECT nid FROM {node} WHERE %s < '%s' AND status = 1 $cond ORDER BY %s DESC LIMIT 1",
-    $search_criteria, $criteria_value, $search_criteria));
-
+  if ($search_criteria != 'nid') {
+    $criteria_value = db_query_range("SELECT $search_criteria FROM {node} WHERE nid = :nid", 0, 1, array(':nid' => $nid))->fetchField();
+    $next_nid = db_query_range("SELECT nid FROM {node} WHERE (($search_criteria = :value AND nid > :nid) OR $search_criteria > :value) AND status = 1 $cond ORDER BY $search_criteria ASC,nid ASC", 0, 1, array(':value' => $criteria_value, ':nid' => $nid))->fetchField();
+    $prev_nid = db_query_range("SELECT nid FROM {node} WHERE (($search_criteria = :value AND nid < :nid) OR $search_criteria < :value) AND status = 1 $cond ORDER BY $search_criteria DESC,nid DESC", 0, 1, array(':value' => $criteria_value, ':nid' => $nid))->fetchField();
+  }
+  else {
+    $next_nid = db_query_range("SELECT nid FROM {node} WHERE nid > :nid AND status = 1 $cond ORDER BY nid ASC", 0, 1, array(':nid' => $nid))->fetchField();
+    $prev_nid = db_query_range("SELECT nid FROM {node} WHERE nid < :nid AND status = 1 $cond ORDER BY nid DESC", 0, 1, array(':nid' => $nid))->fetchField();
+  }
   // Update the node-level data
-  $exists = db_result(db_query('SELECT COUNT(*) FROM {prev_next_node} WHERE nid = %d', $nid));
+  $exists = (bool) db_query_range('SELECT 1 FROM {prev_next_node} WHERE nid = :nid', 0, 1, array(':nid' => $nid))->fetchField();
   if ($exists) {
-    db_query('UPDATE {prev_next_node} SET prev_nid = %d, next_nid = %d, changed = %d WHERE nid = %d',
-      $prev_nid, $next_nid, time(), $nid);
+    db_update('prev_next_node')
+      ->fields(array(
+        'prev_nid' => ($prev_nid) ? $prev_nid : 0,
+        'next_nid' => ($next_nid) ? $next_nid : 0,
+        'changed' => REQUEST_TIME,
+      ))
+      ->condition('nid', $nid)
+      ->execute();
   }
   else {
-    db_query('INSERT INTO {prev_next_node} (prev_nid, next_nid, changed, nid) VALUES (%d, %d, %d, %d)',
-      $prev_nid, $next_nid, time(), $nid);
+    $id = db_insert('prev_next_node')
+      ->fields(array(
+        'prev_nid' => ($prev_nid) ? $prev_nid : 0,
+        'next_nid' => ($next_nid) ? $next_nid : 0,
+        'changed' => REQUEST_TIME,
+        'nid' => $nid,
+      ))
+      ->execute();
   }
 
   // Update the other nodes pointing to this node
-  foreach (node_get_types() as $type => $name) {
+  foreach (node_type_get_types() as $type => $name) {
     if (variable_get(PREV_NEXT_NODE_TYPE . $type, 0)) {
       $search_criteria = variable_get(PREV_NEXT_NODE_TYPE . $type . '_indexing_criteria', PREV_NEXT_INDEXING_CRITERIA_DEFAULT);
-      $criteria_value = db_result(db_query("SELECT %s FROM {node} WHERE nid = %d LIMIT 1", $search_criteria, $nid));
       $cond = _prev_next_node_types_sql($node_type);
-      $next_nid = db_result(db_query("SELECT nid FROM {node} WHERE %s < '%s' AND status = 1 $cond ORDER BY %s DESC LIMIT 1",
-        $search_criteria, $criteria_value, $search_criteria));
+
+      if ($search_criteria != 'nid') {
+        $criteria_value = db_query_range("SELECT $search_criteria FROM {node} WHERE nid = :nid", 0, 1, array(':nid' => $nid))->fetchField();
+        $prev_nid = db_query_range("SELECT nid FROM {node} WHERE (($search_criteria = :value AND nid > :nid) OR $search_criteria > :value) AND status = 1 $cond ORDER BY $search_criteria ASC,nid ASC", 0, 1, array(':value' => $criteria_value, ':nid' => $nid))->fetchField();
+        $next_nid = db_query_range("SELECT nid FROM {node} WHERE (($search_criteria = :value AND nid < :nid) OR $search_criteria < :value) AND status = 1 $cond ORDER BY $search_criteria DESC,nid DESC", 0, 1, array(':value' => $criteria_value, ':nid' => $nid))->fetchField();
+      }
+      else {
+        $prev_nid = db_query_range("SELECT nid FROM {node} WHERE nid > :nid AND status = 1 $cond ORDER BY nid ASC", 0, 1, array(':nid' => $nid))->fetchField();
+        $next_nid = db_query_range("SELECT nid FROM {node} WHERE nid < :nid AND status = 1 $cond ORDER BY nid DESC", 0, 1, array(':nid' => $nid))->fetchField();
+      }
+
       if ($next_nid) {
-        db_query("UPDATE {prev_next_node} SET next_nid = %d WHERE nid = %d", $nid, $next_nid);
+        db_update('prev_next_node')
+          ->fields(array(
+            'next_nid' => $nid,
+          ))
+          ->condition('nid', $next_nid)
+          ->execute();
       }
-      $prev_nid = db_result(db_query("SELECT nid FROM {node} WHERE %s > '%s' AND status = 1 $cond ORDER BY %s ASC LIMIT 1",
-        $search_criteria, $criteria_value, $search_criteria));
       if ($prev_nid) {
-        db_query("UPDATE {prev_next_node} SET prev_nid = %d WHERE nid = %d", $nid, $prev_nid);
+        db_update('prev_next_node')
+          ->fields(array(
+            'prev_nid' => $nid,
+          ))
+          ->condition('nid', $prev_nid)
+          ->execute();
       }
     }
   }
@@ -464,12 +494,11 @@ function _prev_next_modify($nid) {
  * Delete from the prev_next records.
  */
 function _prev_next_remove($nid) {
-  // Find if there is an entry for this node
-  $node = db_fetch_object(db_query("SELECT nid, prev_nid, next_nid, changed FROM {prev_next_node} WHERE nid = %d", $nid));
-  if ($node) {
-    // Delete the data for this node
-    db_query("DELETE FROM {prev_next_node} WHERE nid = %d", $nid);
-  }
+  // Delete the data for this node
+  db_delete('prev_next_node')
+    ->condition('nid', $nid)
+    ->execute();
+
   // Find out if any other nodes point to this node and update them
   _prev_next_modify_pointing_nodes($nid);
 }
@@ -479,47 +508,44 @@ function _prev_next_remove($nid) {
  */
 function _prev_next_modify_pointing_nodes($nid) {
   // First for previous
-  $result = db_query("SELECT nid FROM {prev_next_node} WHERE prev_nid = %d", $nid);
-  while ($prev_row = db_fetch_object($result)) _prev_next_add($prev_row->nid);
+  $prev = db_query("SELECT nid FROM {prev_next_node} WHERE prev_nid = :prev_nid", array(':prev_nid' => $nid))->fetchField();
+  if ($prev) _prev_next_add($prev);
 
   // Then for next
-  $result = db_query("SELECT nid FROM {prev_next_node} WHERE next_nid = %d", $nid);
-  while ($next_row = db_fetch_object($result)) _prev_next_add($next_row->nid);
+  $next = db_query("SELECT nid FROM {prev_next_node} WHERE next_nid = :next_nid", array(':next_nid' => $nid))->fetchField();
+  if ($next) _prev_next_add($next);
 }
 
 /**
- * Implementation of hook_nodeapi().
+ * Implements hook_node_insert().
  */
-function prev_next_nodeapi(&$node, $op) {
-  $found = FALSE;
-  foreach (_prev_next_node_types() as $type) {
-    if ($node->type == $type) {
-      $found = TRUE;
-      break;
-    }
-  }
-  if (!$found) {
-    return;
-  }
-
-  switch ($op) {
-    case 'insert':
-      _prev_next_add($node->nid);
-      break;
+function prev_next_node_insert($node) {
+  $types = _prev_next_node_types();
+  if (in_array($node->type, $types)) _prev_next_add($node->nid);
+}
 
-    case 'update':
-      _prev_next_modify($node->nid);
-      break;
+/**
+ * Implements hook_node_update().
+ */
+function prev_next_node_update($node) {
+  $types = _prev_next_node_types();
+  if (in_array($node->type, $types)) _prev_next_modify($node->nid);
+}
 
-    case 'delete':
-      _prev_next_remove($node->nid);
-      break;
-  }
+/**
+ * Implements hook_node_delete().
+ */
+function prev_next_node_delete($node) {
+  _prev_next_remove($node->nid);
 }
 
 /*
  * Callable API function to get the next/prev nid of a given nid
  */
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function prev_next_nid($nid, $op = 'next') {
   foreach (module_implements('prev_next_nid') as $module) {
     $function = $module . '_prev_next_nid';
@@ -541,12 +567,20 @@ function prev_next_nid($nid, $op = 'next') {
   }
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function prev_next_nid_next($nid) {
-  return db_result(db_query("SELECT next_nid FROM {prev_next_node} WHERE nid = %d", $nid));
+  return db_query("SELECT next_nid FROM {prev_next_node} WHERE nid = :nid", array(':nid' => $nid))->fetchField();
 }
 
+/**
+ * @todo Please document this function.
+ * @see http://drupal.org/node/1354
+ */
 function prev_next_nid_prev($nid) {
-  return db_result(db_query("SELECT prev_nid FROM {prev_next_node} WHERE nid = %d", $nid));
+  return db_query("SELECT prev_nid FROM {prev_next_node} WHERE nid = :nid", array(':nid' => $nid))->fetchField();
 }
 
 /*
@@ -554,9 +588,9 @@ function prev_next_nid_prev($nid) {
  */
 function _prev_next_node_types() {
   $types = array();
-  foreach (node_get_types() as $type => $name) {
+  foreach (node_type_get_types() as $type => $name) {
     if (variable_get(PREV_NEXT_NODE_TYPE . $type, 0)) {
-      $types[] = $type ;
+      $types[] = $type;
     }
   }
 
@@ -584,7 +618,9 @@ function _prev_next_node_types_sql($node_type = '') {
     }
 
   }
-  else $cond = " AND type = '" . $node_type . "'";
+  else {
+    $cond = " AND type = '" . $node_type . "'";
+  }
 
   return $cond;
 }
diff --git a/prev_next_views.info b/prev_next_views.info
index 7801144..4eec1b7 100644
--- a/prev_next_views.info
+++ b/prev_next_views.info
@@ -1,6 +1,6 @@
 name = Prev/Next for Views
 description = Provide an API for previous/next nodes for Views results
 package = Views
-core = 6.x
+core = 7.x
 dependencies[] = views
-dependencies[] = prev_next
+dependencies[] = prev_next
\ No newline at end of file
diff --git a/prev_next_views.module b/prev_next_views.module
index 5f1af97..8104741 100644
--- a/prev_next_views.module
+++ b/prev_next_views.module
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * Implementation of hook_prev_next_nid().
+ * Implements hook_prev_next_nid().
  */
 function prev_next_views_prev_next_nid($nid, $op = 'next') {
   if (isset($_SESSION['prev_next_views'])) {
@@ -31,7 +31,7 @@ function prev_next_views_prev_next_nid($nid, $op = 'next') {
 
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_perm().
  */
 function prev_next_views_perm() {
   return array('administer prev_next_views');
@@ -39,16 +39,16 @@ function prev_next_views_perm() {
 
 
 /**
-* Implementation of hook_menu().
-*/
+ * Implements hook_menu().
+ */
 function prev_next_views_menu() {
   $items = array();
 
-  $items['admin/settings/prev_next/views'] = array(
+  $items['admin/config/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'),
+    'access arguments' => array('administer prev_next_views'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 10,
     'file' => 'prev_next_views.admin.inc',
@@ -59,7 +59,7 @@ function prev_next_views_menu() {
 
 
 /**
- * Implementation of hook_nodeapi().
+ * Implements hook_nodeapi().
  */
 function prev_next_views_nodeapi(&$node, $op) {
   if (isset($_SESSION['prev_next_views']) && (array_search($node->nid, $_SESSION['prev_next_views']) === FALSE)) {
@@ -70,7 +70,7 @@ function prev_next_views_nodeapi(&$node, $op) {
 
 
 /**
- * Implementation of hook_views_api().
+ * Implements hook_views_api().
  */
 function prev_next_views_views_api() {
   return array(
@@ -80,13 +80,14 @@ function prev_next_views_views_api() {
 
 
 /**
- * Implementation of hook_views_pre_execute().
+ * Implements 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'];
 
+    // TODO Please convert this statement to the D7 database API syntax.
     $result = db_query($query, $args);
     $nids = array();
     while ($item = db_fetch_array($result)) {
