4 はてなダイアリーなどで使用される脚注を作成するプラグイン。
5 本文中に(())で囲まれたフレーズがあると、脚注として表示します。
6 もとのデータ自体は変更せず、パースする際に変換しています。
9 0.3:注釈がない記事にも無駄なコードを追加していたバグ修正。
10 0.2:拡張領域に入力がない場合無駄なコードを追加していたバグ修正。
11 0.1+:本文と拡張文とで注解を分ける指定をオプションに追加。
12 0.1:本文注の部分に入ったAタグのtitle属性から不要な文字を削除するようにした。またこの部分の表示/非表示を切り替えるオプションを追加。
13 0.06:同じ行に(())があると一つの注としてまとめられるバグを修正。注内部での改行をサポート。
14 0.05:拡張領域のみに注がある場合に注が表示されないバグを修正。
15 0.04:拡張領域への注に対応。注がある場合には拡張領域に注を表示するようにした。
19 class NP_FootNote extends NucleusPlugin {
22 return 'Foot Note Plugin.';
24 function getAuthor() {
25 return 'charlie + nakahara21';
29 return 'http://xx.nakahara21.net/';
31 function getVersion() {
34 function getDescription() {
35 return 'はてな、Wikiで使用される脚注を生成するプラグインです。本文中に((と))で囲まれたフレーズがあると、脚注として表示します。';
37 function supportsFeature($what) {
39 case 'SqlTablePrefix':
48 $this->createOption('CreateTitle','本文注のリンクにTitle属性を付加しますか?','yesno','yes');
49 $this->createOption('Split','本文と拡張文で注解を分けますか?(アイテムページは常にまとめて最下部になります)','yesno','no');
52 function getEventList() {
53 return array('PreItem','PreSkinParse');
56 function event_PreSkinParse($data) {
57 $this->type = $data['type'];
60 function event_PreItem($data) {
61 global $i, $id, $notelist;
62 $this->currentItem = &$data["item"];
65 $id = $this->currentItem->itemid;
66 $this->currentItem->body = preg_replace_callback("/\(\((.*)\)\)/Us", array(&$this, 'footnote'), $this->currentItem->body);
67 if($this->getOption('Split') == 'yes' && $this->type != 'item'){
68 if($footnote = @join('',$notelist))
69 $this->currentItem->body .= '<ul class="footnote">' . $footnote . '</ul>';
72 if($this->currentItem->more){
73 $this->currentItem->more = preg_replace_callback("/\(\((.*)\)\)/Us", array(&$this, 'footnote'), $this->currentItem->more);
74 if($footnote = @join('',$notelist))
75 $this->currentItem->more .= '<ul class="footnote">' . $footnote . '</ul>';
76 }elseif($footnote = @join('',$notelist)){
77 $this->currentItem->body .= '<ul class="footnote">' . $footnote . '</ul>';
81 function footnote($matches){
82 global $i, $id, $notelist;
84 if($this->getOption('CreateTitle') == 'yes'){
85 $fnote2 = htmlspecialchars(strip_tags($matches[1]));
86 $fnote2 = preg_replace('/\r\n/s','',$fnote2);
87 $fnote2 = ' title="'.$fnote2.'"';
91 $note = '<span class="footnote"><a href="#'.$id.'-'.$i.'"'.$fnote2.'>*'.$i.'</a><a name="'.$id.'-'.$i.'f"></a></span>';
92 $notelist[] = '<a name="'.$id.'-'.$i.'"></a>'.'<li><a href="#'.$id.'-'.$i.'f">注'.$i.'</a>'.$matches[1].'</li>';