Index: paging.install
===================================================================
RCS file: paging.install
diff -N paging.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ paging.install	18 Apr 2007 03:44:07 -0000
@@ -0,0 +1,49 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_install().
+ */
+function paging_install() {
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqle':
+      db_query('CREATE TABLE {paging} (
+        nid int(10) unsigned NOT NULL default 0,
+        pages int(10) unsigned NOT NULL default 0,
+        PRIMARY KEY (nid),
+      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;');
+      break;
+    case 'pgsql':
+      db_query('CREATE TABLE {paging} (
+        nid int NOT NULL default 0,
+        pages int NOT NULL default 0,
+        PRIMARY KEY (nid),
+      );');
+      break;
+  }
+  if (module_exists('gsitemap')) {
+    $result = db_query("
+      SELECT n.nid, nr.body
+      FROM {node} n
+      INNER JOIN {node_revisions} nr
+      ON n.vid = nr.vid
+      WHERE n.type IN ('%s')
+    ", implode("', '", variable_get('paging_node_types_enabled', array())));
+    while ($node = db_fetch_object($result)) {
+      $page_count = substr_count($node->body, variable_get('paging_separator', '<!--pagebreak-->'));
+      db_query('INSERT INTO {paging} (nid, pages) VALUES (%d, %d)', $node->nid, $page_count);
+    }
+  }
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function paging_uninstall() {
+  db_query('DROP TABLE {paging}');
+  variable_del('paging_separator');
+  variable_del('paging_read_more_enabled');
+  variable_del('paging_node_types_enabled');
+}
+
Index: paging.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/paging/paging.module,v
retrieving revision 1.15.2.1
diff -u -p -r1.15.2.1 paging.module
--- paging.module	12 Dec 2006 02:35:42 -0000	1.15.2.1
+++ paging.module	18 Apr 2007 03:44:07 -0000
@@ -96,6 +96,22 @@ function paging_nodeapi(&$node, $op, $te
  */
 function _paging_nodeapi(&$node, &$nodebody, &$nodeteaser, $op, $teaser, $page) {
   switch ($op) {
+    case 'insert':
+    case 'update':
+      if (module_exists('gsitemap')) {
+        if (in_array($node->type, variable_get('paging_node_types_enabled', array()), TRUE)) {
+          $node->pages_count = substr_count($nodebody, variable_get('paging_separator', '<!--pagebreak-->'));
+          if ($node->pages_count > 1) {
+            if ($op == 'insert') {
+              db_query('INSERT INTO {paging} (nid, pages) VALUES (%d, %d)', $node->nid, $node->pages_count);
+            }
+            if ($op == 'update') {
+              db_query('UPDATE {paging} SET pages = %d WHERE nid = %d)', $node->pages_count, $node->nid);
+            }
+          }
+        }
+      }
+      break;
     case 'load':
       $node->pages = explode(PAGING_SEPARATOR, $nodebody);
       $node->pages_count = count($node->pages);
@@ -179,3 +195,82 @@ function paging_filter_tips($in_delta, $
     return t('Use %separator to create page breaks.', array('%separator' => PAGING_SEPARATOR));
   }
 }
+
+/**
+ * Implementation of hook_gsitemap().
+ *
+ * Add page links to the site map.
+ */
+function paging_gsitemap() {
+  $result = db_query("
+    SELECT n.nid, nr.body
+    FROM {node} n
+    INNER JOIN {node_revisions} nr
+    ON n.vid = nr.vid
+    LEFT JOIN {paging} p
+    ON n.nid = p.nid
+    WHERE p.nid IS NULL
+    AND n.type IN ('%s')
+  ", implode("', '", variable_get('paging_node_types_enabled', array())));
+  while ($node = db_fetch_object($result)) {
+    $page_count = substr_count($node->body, variable_get('paging_separator', '<!--pagebreak-->'));
+    db_query('INSERT INTO {paging} (nid, pages) VALUES (%d, %d)', $node->nid, $page_count);
+  }
+  $additional = array();
+  if (module_exists('comment')) {
+    $maxcomments = db_result(db_query('SELECT MAX(comment_count) FROM {node_comment_statistics}'));
+  }
+  else {
+    $maxcomments = 0;
+  }
+  $result = db_query('
+    SELECT n.nid, n.changed, p.pages, g.previously_changed, g.priority_override
+    FROM {node} n
+    INNER JOIN {paging} p
+    ON n.nid = p.nid
+    LEFT JOIN {gsitemap} g
+    ON n.nid = g.nid
+    WHERE p.pages > 1
+  ');
+  while ($node = db_fetch_object($result)) {
+    $age = time() - $node->changed;
+    $interval = 0;
+    if (max($age, $interval) < 3600) {
+      $frequency = 'always';
+    }
+    elseif (max($age, $interval) < 86400) {
+      $frequency = 'hourly';
+    }
+    elseif (max($age, $interval) < 604800) {
+      $frequency = 'daily';
+    }
+    elseif (max($age, $interval) < 2419200) {
+      $frequency = 'weekly';
+    }
+    elseif (max($age, $interval) < 29030400) {
+      $frequency = 'monthly';
+    }
+    elseif (max($age, $interval) < 100000000) {
+      $frequency = 'yearly';
+    }
+    else {
+      $frequency = 'never';
+    }
+    if (isset($node->previously_changed)) {
+      $interval = $node->changed - $node->previously_changed;
+    }
+    $count = 1;
+    while ($count < $node->pages) {
+      $entry = array(
+        '#loc' => url('node/'. $node->nid, "page=0,$count", NULL, TRUE),
+        '#lastmod' => gmdate('Y-m-d\TH:i:s+00:00', $node->changed),
+        '#changefreq' => $frequency,
+        '#priority' => _gsitemap_calc_priority($node, $maxcomments),
+      );
+      $additional[] = $entry;
+      ++ $count;
+    }
+  }
+  return $additional;
+}
+
