Index: paging.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/paging/paging.module,v
retrieving revision 1.15.2.3
diff -u -r1.15.2.3 paging.module
--- paging.module	23 Apr 2007 08:41:40 -0000	1.15.2.3
+++ paging.module	23 Apr 2007 10:23:22 -0000
@@ -46,7 +46,8 @@
  */
 function paging_settings() {
   $form = array();
-
+  $node_types = node_get_types('names');
+  $node_types_enabled = variable_get('paging_node_types_enabled', array());
   $form['paging_config'] = array(
     '#type' => 'fieldset',
     '#title' => t('Paging settings'),
@@ -57,7 +58,7 @@
     '#size' => 20,
     '#maxlength' => 255,
     '#default_value' => PAGING_SEPARATOR,
-    '#description' => t('Page separator string. You should use an HTML tag that will render reasonably when paging is not enabled, such as <em>&lt;!--pagebreak--&gt;</em> or <em>&lt;HR /&gt;</em>.'),
+    '#description' => t('Page separator string. You should use an HTML tag that will render reasonably when paging is not enabled, such as:<br /><em>&lt;!--pagebreak--&gt;</em> or <em>&lt;HR /&gt;</em>.'),
   );
   $form['paging_config']['paging_read_more_enabled'] = array(
     '#type' => 'checkbox',
@@ -69,9 +70,44 @@
     '#type' => 'checkboxes',
     '#title' => t('Node types'),
     '#description' => t('Select the node types you want to enable paging for.'),
-    '#default_value' => variable_get('paging_node_types_enabled', array()),
-    '#options' => node_get_types('names'),
+    '#default_value' => $node_types_enabled,
+    '#options' => $node_types,
+  );
+  $form['paging_automatic'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Automatic Paging settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => false,
   );
+  $form['paging_automatic']['paging_automatic_on'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Automatic Paging'),
+    '#description' => t('Enabling Automatic Paging will automatically set the page separator string at the consecutive configured number of words for the chosen node type. Content with manually inserted page separator string will not be treated.'),
+    '#default_value' => variable_get('paging_automatic_on', 0),
+  );
+  $form['paging_automatic']['paging_automatic_words'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Number of Words'),
+    '#size' => 5,
+    '#maxlength' => 5,
+    '#description' => t('Set the number of words that should be displayed per page. Will be ignored if Automatic Paging is not on.'),
+    '#default_value' => variable_get('paging_automatic_words', 700),
+   );
+  if (count($node_types_enabled) > 0) {
+    foreach (array_keys($node_types_enabled, '0') as $unset) {
+      unset($node_types_enabled[$unset]);
+    }
+    foreach ($node_types_enabled as $key => $nodetype) {
+      $node_types_enabled[$key] = $node_types[$key];
+    }
+    $form['paging_automatic']['paging_node_types_auto_enabled'] = array(
+      '#type' => 'checkboxes',
+      '#title' => t('Node types'),
+      '#description' => t('Select the node types you want to enable automatic paging for. Only node types, for which Paging is enabled, are shown.'),
+      '#default_value' => variable_get('paging_node_types_auto_enabled', array()),
+      '#options' => $node_types_enabled,
+    );
+  }
 
   return system_settings_form($form);
 }
@@ -103,12 +139,28 @@
 function _paging_nodeapi(&$node, &$nodebody, &$nodeteaser, $op, $teaser, $page) {
   switch ($op) {
     case 'load':
-      $node->pages = explode(PAGING_SEPARATOR, $nodebody);
+      $custom_body = $nodebody;
+      if (variable_get('paging_automatic_on', 0) && in_array($node->type, variable_get('paging_node_types_auto_enabled', array()), TRUE) && strpos($nodebody, PAGING_SEPARATOR) === false) {
+        //$nodebody = str_replace(PAGING_SEPARATOR, '', $nodebody); //Delete any previous paginations if using automatic paging.
+        $paging_number = variable_get('paging_automatic_words', 700);
+        $body = explode(' ', $nodebody);
+        $words = count($body);
+        if ($words > $paging_number) {
+          $breaks = $words / $paging_number;
+          for ($i = 1; $i <= $breaks; $i++) {
+            $index = $i * $paging_number;
+            $para_pos = strpos($index, 'a', 1);
+            $body[$index] .= PAGING_SEPARATOR;
+          }
+        }
+        $custom_body = implode(' ', $body);
+      }
+      $node->pages = explode(PAGING_SEPARATOR, $custom_body);
       $node->pages_count = count($node->pages);
       break;
 
     case 'view':
-    $node_type = in_array($node->type, variable_get('paging_node_types_enabled', array()), TRUE);
+      $node_type = in_array($node->type, variable_get('paging_node_types_enabled', array()), TRUE);
       if (!$node->in_preview && $node_type && ereg('<!--paging_filter-->', $teaser ? $nodeteaser : $nodebody)) {
         $element = 1;
         if (!$teaser && $node->pages_count > 1 && arg(2) != 'print' && arg(2) != 'full') {

