バージョン | 全部 |
---|---|
投稿者 | pooh |
状態 | 提案 |
投稿日 | 2008-10-09 (木) 19:09:34 |
見出し番号を下記、
1 1.1 1.1.1 1.2 1.1.2 1.1.3
のように表示できるプラグインがほしいです。 「number プラグイン」で箇条書き「-,--」には対応していますが、見出し「*,**」に対応されていません。
<?php define(PLUGIN_CHAPTER_MAX_DEPTH,10); define(PLUGIN_CHAPTER_SEPARATOR,'.'); function plugin_chapter_inline() { static $counter = array(); global $vars; foreach(debug_backtrace() as $r) if($r["function"] == "make_heading") return false; $args = func_get_args(); array_pop($args); $div = (is_null($args[1])) ? '' : $args[1]; $depth = (is_null($args[0]) || $args[0] == "") ? 1 : intval($args[0]); if(is_null($counter[$vars['page']][$div])){ $counter[$vars['page']][$div]['count'] = array_fill(1, PLUGIN_CHAPTER_MAX_DEPTH, 0); $counter[$vars['page']][$div]['last_depth'] = 1; } if($depth <= 0 || $depth > PLUGIN_CHAPTER_MAX_DEPTH) return '<strong>(chapter: "<em>'. htmlspecialchars($args[0]) .'</em>" wrong parameter)</strong>'; if($depth < $counter[$vars['page']][$div]['last_depth']) for($i=$depth+1;$i<=PLUGIN_CHAPTER_MAX_DEPTH;$i++) $counter[$vars['page']][$div]['count'][$i] = 0; $counter[$vars['page']][$div]['count'][$depth]++; $numstr = implode(PLUGIN_CHAPTER_SEPARATOR,array_slice($counter[$vars['page']][$div]['count'], 0, $depth)); $counter[$vars['page']][$div]['last_depth'] = $depth; return $numstr; } ?>上記ソースをchapter.inc.phpという名前でpluginフォルダに保存・アップロードし、&chapter([depth,[division]]);みたいな感じで使ってください。(number.inc.phpとはパラメータの順番が逆になっています)
--- chapter.inc.php-orig 2009-02-07 01:26:59.000000000 +0900 +++ chapter.inc.php 2009-02-07 01:59:53.000000000 +0900 @@ -7,14 +7,16 @@ static $counter = array(); global $vars; - foreach(debug_backtrace() as $r) if($r["function"] == "make_heading") return false; - + $make_heading = false; + foreach(debug_backtrace() as $r) if($r["function"] == "make_heading") $make_heading = true; + $args = func_get_args(); array_pop($args); $div = (is_null($args[1])) ? '' : $args[1]; $depth = ($args[0] == "" || is_null($args[0])) ? 1 : intval($args[0]); if(is_null($counter[$vars['page']][$div])){ $counter[$vars['page']][$div]['count'] = array_fill(1, PLUGIN_CHAPTER_MAX_DEPTH, 0); + $counter[$vars['page']][$div]['mh'] = array_fill(1, PLUGIN_CHAPTER_MAX_DEPTH, false); $counter[$vars['page']][$div]['last_depth'] = 1; } if($depth <= 0 || $depth > PLUGIN_CHAPTER_MAX_DEPTH) @@ -22,7 +24,9 @@ if($depth < $counter[$vars['page']][$div]['last_depth']) for($i=$depth+1;$i<=PLUGIN_CHAPTER_MAX_DEPTH;$i++) $counter[$vars['page']][$div]['count'][$i] = 0; - $counter[$vars['page']][$div]['count'][$depth]++; + if (!$counter[$vars['page']][$div]['mh'][$depth]) + $counter[$vars['page']][$div]['count'][$depth]++; + $counter[$vars['page']][$div]['mh'][$depth] = $make_heading; $numstr = implode(PLUGIN_CHAPTER_SEPARATOR,array_slice($counter[$vars['page']][$div]['count'], 0, $depth)); $counter[$vars['page']][$div]['last_depth'] = $depth;あまりテストしてませんが、大丈夫ではないかと。。。