You are here

function _tableofcontents_headers in Table of Contents 6.3

Same name and namespace in other branches
  1. 7.2 tableofcontents.inc \_tableofcontents_headers()
  2. 7 tableofcontents.pages.inc \_tableofcontents_headers()

This function goes through all the headers found in the text.

@bug The pattern used assumes that you have at most ONE header per line AND that the whole header is defined on ONE line.

@param[in,out] $toc The table of content object @param[in] $format The format being worked on @param[in] $text The text to be parsed

Return value

The text with headers transformed to include an identifier

1 call to _tableofcontents_headers()
_tableofcontents_replace_toc in ./tableofcontents.pages.inc
This function reokaces the table of contents.

File

./tableofcontents.pages.inc, line 274
Applies the filter functions.

Code

function _tableofcontents_headers(&$toc, $format, $text) {

  // initialize header variables
  $toc->headers = array();
  $toc->header_id = 1;
  $toc->header_min = 0;
  $toc->header_max = 0;
  $toc->allowed_tags = variable_get('tableofcontents_allowed_tags_' . $format, TABLEOFCONTENTS_ALLOWED_TAGS);
  $toc->id_stripping = variable_get('tableofcontents_id_stripping_' . $format, array());
  $toc->identifier_introducer = variable_get('tableofcontents_identifier_introducer_' . $format, 'header');
  $toc->id_separator = variable_get('tableofcontents_id_separator_' . $format, '-');
  $toc->id_generator = variable_get('tableofcontents_id_generator_' . $format, 'title');
  $toc->back_to_top = check_plain(variable_get('tableofcontents_back_to_top_' . $format, ''));
  $toc->back_to_top_location = check_plain(variable_get('tableofcontents_back_to_top_location_' . $format, 'bottom'));
  $toc->back_to_top_anchor = check_plain(variable_get('tableofcontents_back_to_top_anchor_' . $format, 'toc'));
  $toc->scroll_back_to_top = check_plain(variable_get('tableofcontents_scroll_back_to_top_' . $format, FALSE));
  $toc->back_to_top_minlevel = variable_get('tableofcontents_back_to_top_minlevel_' . $format, 2);
  $toc->back_to_top_maxlevel = variable_get('tableofcontents_back_to_top_maxlevel_' . $format, 4);
  $toc->first_header = TRUE;
  $toc->numbering = variable_get('tableofcontents_numbering_' . $format, 0);
  $toc->number_mode = variable_get('tableofcontents_number_mode_' . $format, 0);
  $toc->number_start_letter = check_plain(variable_get('tableofcontents_number_start_letter_' . $format, ''));
  $toc->number_separator = check_plain(variable_get('tableofcontents_number_separator_' . $format, '.'));
  $toc->number_end_letter = check_plain(variable_get('tableofcontents_number_end_letter_' . $format, '.'));
  $toc->number_headers = variable_get('tableofcontents_number_headers_' . $format, FALSE);
  $toc->level_from = 6;
  $toc->level_to = 6;
  $toc->counters = array(
    0,
    0,
    0,
    0,
    0,
    0,
    0,
  );

  // used to generate a toc with advanced counters
  if (isset($toc->on_print_pages)) {
    $toc->back_to_top_link = '';
  }
  else {
    $toc->back_to_top_link = theme('tableofcontents_back_to_top', $toc);
  }

  // note that the pattern below assumes that the headers
  // are properly defined in your HTML (i.e. a header cannot
  // include another)
  //
  // Note: we support having a [collapse] tag just before a header
  //       and even possibly a [/collapse] just before that!
  $result = preg_replace_callback('%((?:(?:<p(?:\\s[^>]*)?' . '>\\s*)?\\[/collapse\\](?:</p\\s*>\\s*)?)?' . '(?:<p(?:\\s[^>]*)?' . '>\\s*)?\\[collapse[^]]*?\\](?:</p\\s*>\\s*)?)?' . '<h([1-6])(\\s+[^>]*?)?' . '>(.*?)</h[1-6]\\s*>%si', '_tableofcontents_replace_headers', $text);
  return $result;
}