You are here

function _paging_nodeapi in Paging 5

Same name and namespace in other branches
  1. 6 paging.module \_paging_nodeapi()

Helper function for paging_nodeapi().

1 call to _paging_nodeapi()
paging_nodeapi in ./paging.module
Implementation of hook_nodeapi().

File

./paging.module, line 177

Code

function _paging_nodeapi(&$node, &$node_body, &$node_teaser, $op, $teaser, $page) {
  switch ($op) {
    case 'load':
      if (strpos($teaser ? $node_teaser : $node_body, PAGING_SEPARATOR) !== FALSE) {
        $pages = explode(PAGING_SEPARATOR, $node_body);
      }
      else {
        $body_parts = $node_body;
        if (($max_chars = variable_get('paging_automatic_chars', 0)) != 0) {
          $total_chars = strlen($node_body);
          $body = $node_body;
          if ($total_chars > $max_chars) {
            $breaks = (int) ($total_chars / $max_chars);
            $bodypart = array();
            for ($i = 0; $i <= $breaks; $i++) {
              $bodypart[$i] = paging_paragraph_split(trim($body), NULL, $max_chars);
              $bodycount = strlen($bodypart[$i]);
              $body = substr($body, $bodycount);
            }
            $body_parts = implode(PAGING_SEPARATOR, $bodypart);
          }
        }
        elseif (($max_words = variable_get('paging_automatic_words', 0)) != 0) {
          $words = explode(' ', $node_body);
          $total_words = count($words);
          if ($total_words > $max_words) {
            $breaks = (int) ($total_words / $max_words);
            for ($i = 1; $i < $breaks; $i++) {
              $index = $i * $max_words;
              $words[$index] .= PAGING_SEPARATOR;
            }
          }
          $body_parts = implode(' ', $words);
        }
        $pages = explode(PAGING_SEPARATOR, $body_parts);
      }
      foreach ($pages as $key => $page) {
        if (is_null($page) || $page == "") {
          unset($pages[$key]);
        }
      }
      $node->pages = array_values($pages);
      $node->page_count = count($node->pages);
      break;
    case 'view':
      if ($teaser && !$node->in_preview && strpos($node_teaser, '<!--paging_filter-->') !== FALSE) {

        // Check to see if the teaser is longer than our first page.
        if ($node->page_count > 1 && strlen($node->teaser) > strlen($node->pages[0])) {
          $node->content['body']['#value'] = check_markup($node->pages[0], $node->format, false);
          $node->pagemore = true;
        }
      }
      break;
    case 'alter':
      if (!$node->in_preview && strpos($teaser ? $node_teaser : $node_body, '<!--paging_filter-->') !== FALSE) {
        $element = 1;
        $page = isset($_GET['page']) ? $_GET['page'] : '';

        // Remove internal <!--paging_filter--> tag from final output.
        $node->teaser = str_replace('<!--paging_filter-->', '', $node_teaser);
        if (!$teaser && $node->page_count > 1 && arg(2) != 'print' && arg(2) != 'full' && $page != 'full' && arg(0) != 'book' && arg(1) != 'export') {
          global $pager_page_array, $pager_total;
          $pager_page_array = explode(',', $page);
          $pager_total[$element] = $node->page_count;
          $page = isset($pager_page_array[$element]) ? $pager_page_array[$element] : 0;
          $node->body = check_markup($node->pages[$page], $node->format, false);
          $position = variable_get('paging_pager_widget_position', 'below');
          $node->paging = theme('pager', NULL, 1, $element);
          if ($position == 'above' || $position == 'both') {
            $node->body = $node->paging . $node->body;
          }
          if ($position == 'below' || $position == 'both') {
            $node->body .= $node->paging;
          }

          // Remove internal <!--paging_filter--> tag from final output.
          $node->body = str_replace('<!--paging_filter-->', '', $node->body);
          $node->content['body']['#value'] = $node->body;
        }
      }
      break;
  }
}