You are here

function pagination_node_view in Pagination (Node) 7

Implementation of hook_node_view()

File

./pagination.module, line 232

Code

function pagination_node_view($node, $view_mode, $langcode) {
  $pg = Pagination::instance();
  $page = $pg
    ->getPageVar();
  $paging = $pg
    ->getValue($node->type);
  $style = $pg
    ->getStyle($node->type);
  $ignore = array_map('trim', explode(',', variable_get('pagination_ignore', '')));
  if ($paging && $view_mode == 'full' && $page !== 'show' && empty($node->in_preview) && !in_array($node->nid, $ignore, TRUE)) {
    $pg
      ->paginate($node->content['body'][0]['#markup'], $paging);
    $node->content['body'][0]['#markup'] = $pg
      ->getPage($page);
    if ($style < PAGINATION_TOC) {
      $node->content['pagination_pager'] = array(
        '#weight' => 50,
        '#markup' => $pg
          ->getPager(),
      );
    }
    if ($style > PAGINATION_DEFAULT && $pg
      ->getPageCount() > 1) {
      $node->content['pagination_toc'] = array(
        '#weight' => -50,
        '#markup' => $pg
          ->getToc($node->nid),
      );
    }
  }
  if ($paging) {
    $node->content['body'][0]['#markup'] = preg_replace($pg->re_custom, '', $node->content['body'][0]['#markup']);
  }
  $count = $pg
    ->getPageCount();
  $showfull = variable_get('pagination_showall', 1);
  if ($paging && $view_mode == 'full' && $showfull && ($count > 1 || $page === 'show')) {
    $query = $page !== 'show' ? array(
      'page' => 'show',
    ) : array();
    $title = $page !== 'show' ? t('Show full page') : t('Show paged');
    $class = $page !== 'show' ? array(
      'pagination-show-full-page',
    ) : array(
      'pagination-show-paged',
    );
    $node->content['links']['node']['#links']['pagination-showall'] = array(
      'title' => $title,
      'href' => drupal_get_path_alias('node/' . $node->nid),
      'query' => $query,
      'attributes' => array(
        'title' => $title,
        'class' => $class,
      ),
    );
  }
}