<?php
// PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: ls2.inc.php,v 1.30 2011/01/25 15:01:01 henoheno Exp $
-// Copyright (C)
-// 2002-2004, 2006-2007 PukiWiki Developers Team
+// ls2.inc.php
+// Copyright
+// 2002-2017 PukiWiki Development Team
// 2002 panda http://home.arino.jp/?ls2.inc.php
// 2002 Y.MASUI GPL2 http://masui.net/pukiwiki/ masui@masui.net (ls.inc.php)
// License: GPL version 2
// List plugin 2
/*
- * ÇÛ²¼¤Î¥Ú¡¼¥¸¤ä¡¢¤½¤Î¸«½Ð¤·(*,**,***)¤Î°ìÍ÷¤òɽ¼¨¤¹¤ë
+ * 配下のページや、その見出し(*,**,***)の一覧を表示する
* Usage
* #ls2(pattern[,title|include|link|reverse|compact, ...],heading title)
*
- * pattern : ¾Êά¤¹¤ë¤È¤¤â¥«¥ó¥Þ¤¬É¬Í×
- * 'title' : ¸«½Ð¤·¤Î°ìÍ÷¤òɽ¼¨¤¹¤ë
- * 'include': ¥¤¥ó¥¯¥ë¡¼¥É¤·¤Æ¤¤¤ë¥Ú¡¼¥¸¤Î¸«½Ð¤·¤òºÆµ¢Åª¤ËÎóµó¤¹¤ë
- * 'link ': action¥×¥é¥°¥¤¥ó¤ò¸Æ¤Ó½Ð¤¹¥ê¥ó¥¯¤òɽ¼¨
- * 'reverse': ¥Ú¡¼¥¸¤Îʤӽç¤òȿž¤·¡¢¹ß½ç¤Ë¤¹¤ë
- * 'compact': ¸«½Ð¤·¥ì¥Ù¥ë¤òÄ´À°¤¹¤ë
- * PLUGIN_LS2_LIST_COMPACT¤¬TRUE¤Î»þ¤Ï̵¸ú(ÊѲ½¤·¤Ê¤¤)
- * heading title: ¸«½Ð¤·¤Î¥¿¥¤¥È¥ë¤ò»ØÄꤹ¤ë (link¤ò»ØÄꤷ¤¿»þ¤Î¤ß)
+ * pattern : 省略するときもカンマが必要
+ * 'title' : 見出しの一覧を表示する
+ * 'include': インクルードしているページの見出しを再帰的に列挙する
+ * 'link ': actionプラグインを呼び出すリンクを表示
+ * 'reverse': ページの並び順を反転し、降順にする
+ * 'compact': 見出しレベルを調整する
+ * PLUGIN_LS2_LIST_COMPACTがTRUEの時は無効(変化しない)
+ * heading title: 見出しのタイトルを指定する (linkを指定した時のみ)
*/
-// ¸«½Ð¤·¥¢¥ó¥«¡¼¤Î½ñ¼°
+// 見出しアンカーの書式
define('PLUGIN_LS2_ANCHOR_PREFIX', '#content_1_');
-// ¸«½Ð¤·¥¢¥ó¥«¡¼¤Î³«»ÏÈÖ¹æ
+// 見出しアンカーの開始番号
define('PLUGIN_LS2_ANCHOR_ORIGIN', 0);
-// ¸«½Ð¤·¥ì¥Ù¥ë¤òÄ´À°¤¹¤ë(¥Ç¥Õ¥©¥ë¥ÈÃÍ)
+// 見出しレベルを調整する(デフォルト値)
define('PLUGIN_LS2_LIST_COMPACT', FALSE);
function plugin_ls2_action()
global $vars, $_ls2_msg_title;
$params = array();
- foreach (array('title', 'include', 'reverse') as $key)
+ $keys = array('title', 'include', 'reverse');
+ foreach ($keys as $key)
$params[$key] = isset($vars[$key]);
$prefix = isset($vars['prefix']) ? $vars['prefix'] : '';
function plugin_ls2_convert()
{
- global $script, $vars, $_ls2_msg_title;
+ global $vars, $_ls2_msg_title;
$params = array(
'link' => FALSE,
}
if ($prefix == '') $prefix = strip_bracket($vars['page']) . '/';
- foreach ($args as $key => $arg)
- plugin_ls2_check_arg($arg, $key, $params);
+ foreach ($args as $arg)
+ plugin_ls2_check_arg($arg, $params);
$title = (! empty($params['_args'])) ? join(',', $params['_args']) : // Manual
str_replace('$1', htmlsc($prefix), $_ls2_msg_title); // Auto
if (isset($params['title'])) $tmp[] = 'title=1';
if (isset($params['include'])) $tmp[] = 'include=1';
- return '<p><a href="' . $script . '?' . join('&', $tmp) . '">' .
+ return '<p><a href="' . get_base_uri() . '?' . join('&', $tmp) . '">' .
$title . '</a></p>' . "\n";
}
natcasesort($pages);
if ($params['reverse']) $pages = array_reverse($pages);
- foreach ($pages as $page) $params["page_$page"] = 0;
+ foreach ($pages as $page) $params['page_ ' . $page] = 0;
if (empty($pages)) {
return str_replace('$1', htmlsc($prefix), $_ls2_err_nopages);
} else {
$params['result'] = $params['saved'] = array();
- foreach ($pages as $page)
- plugin_ls2_get_headings($page, $params, 1);
+ foreach ($pages as $page) {
+ $read_pages = array(); // read pages per page
+ plugin_ls2_get_headings($page, $params, 1, false, $read_pages);
+ }
return join("\n", $params['result']) . join("\n", $params['saved']);
}
}
-function plugin_ls2_get_headings($page, & $params, $level, $include = FALSE)
+function plugin_ls2_get_headings($page, & $params, $level, $include = FALSE,
+ &$read_pages)
{
- global $script;
static $_ls2_anchor = 0;
- // ¥Ú¡¼¥¸¤¬Ì¤É½¼¨¤Î¤È¤
- $is_done = (isset($params["page_$page"]) && $params["page_$page"] > 0);
+ if (is_null($read_pages)) {
+ $read_pages = array();
+ }
+ // ページが未表示のとき
+ $is_done = isset($read_pages[$page]);
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;
+ $attrs = get_page_link_a_attrs($page);
+ $href = get_page_uri($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> ';
+ if ($is_done) {
+ $ret .= '<a href="' . $href . '" class="' .
+ $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] .
+ '">' . $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>';
+ '" class="' . $attrs['class'] . '" data-mtime="' .
+ $attrs['data_mtime'] . '">' . $s_page . '</a>';
array_push($params['result'], $ret);
$anchor = PLUGIN_LS2_ANCHOR_ORIGIN;
$matches = array();
+ $is_title = $params['title'];
+ $is_include = $params['include'];
+ if (!$is_title && !$is_include) {
+ return;
+ }
foreach (get_source($page) as $line) {
- if ($params['title'] && preg_match('/^(\*{1,3})/', $line, $matches)) {
+ if ($is_title && preg_match('/^(\*{1,3})/', $line, $matches)) {
$id = make_heading($line);
- $level = strlen($matches[1]);
+ $heading_level = strlen($matches[1]);
$id = PLUGIN_LS2_ANCHOR_PREFIX . $anchor++;
- plugin_ls2_list_push($params, $level + strlen($level));
+ plugin_ls2_list_push($params, $level + $heading_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);
+ } else if ($is_include &&
+ preg_match('/^#include\((.+)\)/', $line, $matches)) {
+ $include_args = $matches[1];
+ $page2 = $include_args;
+ $m2 = null;
+ if (preg_match('#^(("([^"]+)")|([^",]+))#', $include_args, $m2)) {
+ if ($m2[3]) {
+ $page2 = $m2[3];
+ } else if ($m2[4]) {
+ $page2 = $m2[4];
+ }
+ }
+ $sub_page = get_fullname($page2, $page);
+ if (is_page($sub_page)) {
+ $read_pages[$page] = 1;
+ if (!isset($read_pages[$sub_page])) {
+ plugin_ls2_get_headings($sub_page, $params,
+ $level + 1, TRUE, $read_pages);
+ }
+ }
}
}
}
-//¥ê¥¹¥È¹½Â¤¤ò¹½ÃÛ¤¹¤ë
+//リスト構造を構築する
function plugin_ls2_list_push(& $params, $level)
{
- global $_ul_left_margin, $_ul_margin, $_list_pad_str;
-
$result = & $params['result'];
$saved = & $params['saved'];
$cont = TRUE;
$margin = $level - count($saved);
- // count($saved)¤òÁý¤ä¤¹
+ // count($saved)を増やす
while (count($saved) < ($level - 1)) array_unshift($saved, '');
if (count($saved) < $level) {
$cont = FALSE;
array_unshift($saved, $close);
- $left = ($level == $margin) ? $_ul_left_margin : 0;
+ $left = 0;
if ($params['compact']) {
- $left += $_ul_margin; // ¥Þ¡¼¥¸¥ó¤ò¸ÇÄê
- $level -= ($margin - 1); // ¥ì¥Ù¥ë¤ò½¤Àµ
+ $left = 1; // マージンを固定
+ $level -= ($margin - 1); // レベルを修正
} else {
- $left += $margin * $_ul_margin;
+ $left = $margin;
}
- $str = sprintf($_list_pad_str, $level, $left, $left);
+ $str = sprintf(pkwk_list_attrs_template(), $level, $left);
array_push($result, sprintf($open, $str));
}
if ($cont) array_push($result, '</li>');
}
-// ¥ª¥×¥·¥ç¥ó¤ò²òÀϤ¹¤ë
-function plugin_ls2_check_arg($value, $key, & $params)
+// オプションを解析する
+function plugin_ls2_check_arg($value, & $params)
{
if ($value == '') {
$params['_done'] = TRUE;
$params['_args'][] = htmlsc($value); // Link title
}
-?>