You are here

public function Pagination::getToc in Pagination (Node) 7

Same name and namespace in other branches
  1. 6 pagination.module \Pagination::getToc()

Return a themed table of contents.

Parameters

$nid: The nid of the node.

$ignore_title: Boolean value to indicate whether "Table of Contents" string should not be rendered.

Return value

HTML corresponding to a themed ToC.

File

includes/Pagination.inc, line 200

Class

Pagination
Handles all the pagination logic

Code

public function getToc($nid, $ignore_title = FALSE) {
  if (!$nid) {
    return;
  }
  drupal_add_css(drupal_get_path('module', 'pagination') . '/css/pagination.css');
  $toc = array();
  $headers = $this
    ->getHeaders($nid);
  $headers[0] = menu_get_active_title();
  foreach ($headers as $key => $header) {
    $page = $key + 1;
    $header = str_replace(array(
      '<br />',
      '<br>',
    ), '', $header);
    $options = array(
      'attributes' => array(
        'title' => t('Go to page !page', array(
          '!page' => $page,
        )),
      ),
      'query' => array(
        'page' => $page,
      ),
    );
    $toc[] = array(
      'data' => $this
        ->getPageVar() == $key ? check_plain($header) : l($header, $_GET['q'], $options),
      'class' => array(
        $this
          ->getPageVar() == $key ? 'pagination-toc-item current' : 'pagination-toc-item',
      ),
    );
  }
  $items = theme('item_list', array(
    'items' => $toc,
    'type' => variable_get('pagination_list_type', 'ul'),
    'attributes' => array(
      'class' => array(
        'pagination-toc-list',
      ),
    ),
  ));

  // Avoid problems with special chars displaying, likely not an exhaustive regex
  $items = preg_replace('#&amp;(\\S{2,7}[^;];)#e', "'&\$1'", $items);
  $toc = theme('pagination_toc', array(
    'toc' => $ignore_title ? NULL : t('Table of Contents:'),
    'title' => drupal_get_title(),
    'pages' => $items,
  ));
  return $toc;
}