OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@843 1ca29b6e-896d...
[nucleus-jp/nucleus-plugins.git] / NP_FootNote / NP_FootNote.php
1 <?php 
2 /**
3   *
4   * FOOT NOTE PLUG-IN FOR NucleusCMS
5   * PHP versions 4 and 5
6   *
7   * This program is free software; you can redistribute it and/or
8   * modify it under the terms of the GNU General Public License
9   * as published by the Free Software Foundation; either version 2
10   * of the License, or (at your option) any later version.
11   * (see nucleus/documentation/index.html#license for more info)
12   *
13   * @author     Original Author nakahara21
14   * @copyright  2005-2006 nakahara21
15   * @license    http://www.gnu.org/licenses/gpl.txt
16   *             GNU GENERAL PUBLIC LICENSE Version 2, June 1991
17   * @version    0.32
18   * @link               http://nakahara21.com
19   *
20   **/
21 class NP_FootNote extends NucleusPlugin
22 {
23
24     function getName()
25     {
26         return 'Foot Note Plugin.';
27     }
28
29     function getAuthor()
30     {
31         $author = 'charlie, '
32                         . 'nakahara21, '
33                         . 'shizuki';
34         return $author;
35     }
36
37     function getURL()
38     {
39         $original = 'http://nakahara21.com/';
40         $wikiPage = 'http://japan.nucleuscms.org/wiki/plugins:footnote';
41         return $wikiPage;
42     }
43
44     function getVersion()
45     {
46         return '0.32';
47     }
48
49     function getDescription()
50     {
51         $description = _FNOTE_DESC;
52         return $description;
53     }
54
55         function supportsFeature($what)
56         {
57                 switch ($what) {
58                         case 'SqlTablePrefix':
59                                 return 1;
60                         default:
61                                 return 0;
62                 }
63         }
64
65
66         function install()
67         {
68                 $this->createOption('CreateTitle', _CLT_TITLE, 'yesno', 'yes');
69                 $this->createOption('Split',       _NOTE_SPLT, 'yesno', 'no');
70         }
71
72         function getEventList()
73         {
74                 $events = array (
75                                                  'PreItem',
76                                                  'PreSkinParse'
77                                                 );
78                 return $events;
79         }
80
81         function init()
82         {
83                 $language = ereg_replace( '[\\|/]', '', getLanguageName());
84                 if (file_exists($this->getDirectory()  . $language . '.php')) {
85                         include_once($this->getDirectory() . $language . '.php');
86                 }else {
87                         include_once($this->getDirectory() . 'english.php');
88                 }
89         }
90
91         function event_PreSkinParse($data)
92         {
93                 $this->skinType = $data['type'];
94         }
95
96         function event_PreItem($data)
97         {
98                 $skinType       =  $this->skinType;
99                 $this->nodeId   =  0;
100                 $this->noteList =  array();
101                 $this->itemId   =  $data['item']->itemid;
102                 $cData          =  array(
103                                                              &$this,
104                                                              'footnote'
105                                                             );
106                 $iBody          =& $data['item']->body;
107                 $iMore          =& $data['item']->more;
108                 $iBody          =  preg_replace_callback("/\(\((.*)\)\)/Us",
109                                                                                                  $cData,
110                                                                                                  $iBody);
111                 $nsplit         =  $this->getOption('Split');
112                 if ($nsplit == 'yes' && $skinType != 'item') {
113                         if ($footNote = implode('', $this->noteList)) {
114                                 $iBody .= '<ul class="footnote">' . $footNote . '</ul>';
115                         }
116                         $this->noteList = array();
117                 }
118                 if ($iMore) {
119                         $iMore = preg_replace_callback("/\(\((.*)\)\)/Us",
120                                                                                    $cData,
121                                                                                    $iMore);
122                         if ($footNote = implode('', $this->noteList)) {
123                                 $iMore .= '<ul class="footnote">' . $footNote . '</ul>';
124                         }
125                 } elseif ($footNote = implode('', $this->noteList)) {
126                         $iBody .= '<ul class="footnote">' . $footNote . '</ul>';
127                 }
128         }
129
130         function footnote($matches){
131                 global $manager;
132                 $this->nodeId++;
133                 $iid    =  intval($this->itemId);
134                 $bid    =  getBlogIDFromItemID($iid);
135                 $b      =& $manager->getBlog($bid);
136                 $bsname =  $b->getShortName();
137                 if ($this->getOption('CreateTitle') == 'yes') {
138                         $fNote = htmlspecialchars(strip_tags($matches[1]));
139                         $fNote = preg_replace('/\r\n/s', '', $fNote);
140                         $fNote = ' title="' . $fNote . '"';
141                 }else{
142                         $fNote = '';
143                 }
144                 $footNoteID       = $bsname . $iid . '-' . $this->nodeId;
145                 $note             = '<span class="footnote">'
146                                               . '<a'
147                                               . ' href="#' . $footNoteID . '"'
148                                               . $fNote
149                                               . ' name="' . $footNoteID . 'f"'
150                                               . ' id="'   . $footNoteID . 'f"'
151                                               . '>'
152                                               . '*' . $this->nodeid
153                                               . '</a>'
154                                               . '</span>';
155                 $this->noteList[] = '<li>'
156                                               . '<a'
157                                               . ' href="#' . $footNoteID . 'f"'
158                                               . ' name="' . $footNoteID . '"'
159                                               . ' id="'   . $footNoteID . '"'
160                                               . '>'
161                                               . _NOTE_WORD . $this->nodeId
162                                               . '</a>'
163                                               . $matches[1]
164                                               . '</li>';
165                 return $note;
166         }
167 }