function plugin_ls2_get_headings($page, &$params, $level, $include = FALSE) { static $_ls2_anchor = 0; // ページが未表示のとき $is_done = isset($params["page_{$page}"]) && $params["page_{$page}"] > 0; if (!$is_done) { $params["page_{$page}"] = ++$_ls2_anchor; } $s_page = Utility::htmlsc($page); $wiki = Factory::Wiki($page); $title = $s_page . ' ' . $wiki->passage(false, true); $href = $wiki->uri(); plugin_ls2_list_push($params, $level); $ret = $include ? '<li>include ' : '<li>'; if ($params['title'] && $is_done) { $ret .= '<a href="' . $href . '" title="' . $title . '">' . $s_page . '</a> '; $ret .= '<a href="#list_' . $params["page_{$page}"] . '"><sup>↑</sup></a>'; array_push($params['result'], $ret); return; } $ret .= '<a id="list_' . $params["page_{$page}"] . '" href="' . $href . '" title="' . $title . '">' . $s_page . '</a>'; array_push($params['result'], $ret); $anchor = PLUGIN_LS2_ANCHOR_ORIGIN; $matches = array(); foreach ($wiki->get() as $line) { if ($params['title'] && preg_match('/^(\\*{1,3})/', $line, $matches)) { list($heading, $id) = Rules::getHeading($line); $level = strlen($matches[1]); plugin_ls2_list_push($params, $level + strlen($level)); array_push($params['result'], '<li><a href="' . $href . '#' . $id . '">' . $heading . '</a>'); } else { if ($params['include'] && preg_match('/^#include\\((.+)\\)/', $line, $matches) && is_page($matches[1])) { plugin_ls2_get_headings($matches[1], $params, $level + 1, TRUE); } } } }
function plugin_ls2_get_headings($page, &$params, $level, $include = FALSE) { global $script; static $_ls2_anchor = 0; // ページが未表示のとき $is_done = isset($params["page_{$page}"]) && $params["page_{$page}"] > 0; if (!$is_done) { $params["page_{$page}"] = ++$_ls2_anchor; } $r_page = rawurlencode($page); $s_page = htmlsc($page); $title = $s_page . ' ' . get_pg_passage($page, FALSE); $href = $script . '?cmd=read&page=' . $r_page; plugin_ls2_list_push($params, $level); $ret = $include ? '<li>include ' : '<li>'; if ($params['title'] && $is_done) { $ret .= '<a href="' . $href . '" title="' . $title . '">' . $s_page . '</a> '; $ret .= '<a href="#list_' . $params["page_{$page}"] . '"><sup>↑</sup></a>'; array_push($params['result'], $ret); return; } $ret .= '<a id="list_' . $params["page_{$page}"] . '" href="' . $href . '" title="' . $title . '">' . $s_page . '</a>'; array_push($params['result'], $ret); $anchor = PLUGIN_LS2_ANCHOR_ORIGIN; $matches = array(); foreach (get_source($page) as $line) { if ($params['title'] && preg_match('/^(\\*{1,3})/', $line, $matches)) { $id = make_heading($line); $level = strlen($matches[1]); $id = PLUGIN_LS2_ANCHOR_PREFIX . $anchor++; plugin_ls2_list_push($params, $level + strlen($level)); array_push($params['result'], '<li><a href="' . $href . $id . '">' . $line . '</a>'); } else { if ($params['include'] && preg_match('/^#include\\((.+)\\)/', $line, $matches) && is_page($matches[1])) { plugin_ls2_get_headings($matches[1], $params, $level + 1, TRUE); } } } }