function toc_node_links in TOC Node 7
Create the TOC links, including numbering of content items.
Parameters
$dom_document:
$links_data:
$style:
Return value
array
1 call to toc_node_links()
- toc_node_generate in ./
toc_node.module - Generate the TOC.
File
- ./
toc_node.module, line 424
Code
function toc_node_links($dom_document, $links_data, $style) {
$path = drupal_get_path_alias($_GET['q']);
$toc_number = array();
$toc_tags = $dom_document
->getElementsByTagName('toc');
foreach ($toc_tags as $toc_tag) {
$toc_id = $toc_tag->attributes
->getNamedItem('class')->value;
$link = $links_data[$toc_id];
// TOC always starts at H2, so we need to adjust level here.
$toc_level = $link['level'] - 1;
$toc_level_count = count($toc_number);
for ($i = $link['level']; $i <= $toc_level_count; $i++) {
unset($toc_number[$i]);
}
if (empty($toc_number[$toc_level])) {
$toc_number[$toc_level] = 1;
}
else {
$toc_number[$toc_level] = $toc_number[$toc_level] + 1;
}
$link_number = implode('.', $toc_number);
$data = '';
if ($style == 'numbers') {
$data .= '<span class="toc-number">' . $link_number . '</span> ';
}
$data .= '<span class="toc-text">' . $link['label'] . '</span>';
$links[] = array(
'data' => l($data, $path, array(
'fragment' => $toc_id,
'html' => TRUE,
)),
'class' => array(
'toc-node-level-' . $toc_level,
),
);
}
if (empty($links)) {
return '';
}
$item_list = theme('item_list', array(
'items' => $links,
'type' => 'ul',
'attributes' => array(
'class' => 'toc-node-' . $style,
),
));
return theme('toc_node_links', array(
'links' => $item_list,
));
}