You are here

function _collapse_text_find_levels in Collapse Text 7.2

Same name and namespace in other branches
  1. 6.2 collapse_text.module \_collapse_text_find_levels()

using the locations of the tags, determine what the nesting structure is.

1 call to _collapse_text_find_levels()
_collapse_text_filter_process in ./collapse_text.module
Implements hook_filter_FILTER_process().

File

./collapse_text.module, line 304
collapse_text is an input filter that allows text to be collapsible

Code

function _collapse_text_find_levels($tags, $options) {
  $levels = array();
  $curr_level = 0;
  foreach ($tags as $item) {

    // determine whether this is an open or close tag
    $type = 'unknown';
    if (substr($item[0], 0, 9) == '[collapse') {
      $type = 'start';
    }
    elseif (substr($item[0], 0, 10) == '[/collapse') {
      $type = 'end';
    }

    // the level of an open tag is incremented before we save its
    // information, while the level of a close tag is decremented after
    if ($type == 'start') {
      $curr_level++;
    }
    $levels[] = array(
      'type' => $type,
      'tag' => $item[0],
      'start' => $item[1],
      'end' => $item[1] + strlen($item[0]),
      'level' => $curr_level,
    );
    if ($type == 'end') {
      $curr_level--;
    }
  }
  return $levels;
}