Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの
Revision | eb5ab4511684a39a46c7a32f81e8c91c2eb76118 (tree) |
---|---|
Time | 2006-10-02 22:14:13 |
Author | shizuki <shizuki@1ca2...> |
Commiter | shizuki |
temp
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@398 1ca29b6e-896d-4ea0-84a5-967f57386b96
@@ -1,30 +1,37 @@ | ||
1 | 1 | <?php |
2 | 2 | // plugin needs to work on Nucleus versions <=2.0 as well |
3 | -if (!function_exists('removeBreaks')){ | |
4 | - function removeBreaks($var) { return preg_replace("/<br \/>([\r\n])/","$1",$var); } | |
3 | +if (!function_exists('removeBreaks')) { | |
4 | + function removeBreaks($var) | |
5 | + { | |
6 | + return preg_replace("/<br \/>([\r\n])/", "$1", $var); | |
7 | + } | |
5 | 8 | } |
6 | 9 | |
7 | 10 | |
8 | 11 | class NP_Wikistyle extends NucleusPlugin { |
9 | 12 | |
10 | - function getName() { // name of plugin | |
13 | + function getName() | |
14 | + { | |
11 | 15 | return 'Wikistyle'; |
12 | 16 | } |
13 | 17 | |
14 | - function getAuthor() { // author of plugin | |
15 | - return 'nakahara21'; | |
18 | + function getAuthor() | |
19 | + { | |
20 | + return 'nakahara21'; | |
16 | 21 | } |
17 | 22 | |
18 | - function getURL() { // an URL to the plugin website | |
19 | - return 'http://xx.nakahara21.net/'; | |
23 | + function getURL() | |
24 | + { | |
25 | + return 'http://nakahara21.com'; | |
20 | 26 | } |
21 | 27 | |
22 | - function getVersion() { // version of the plugin | |
23 | - return '0.5'; | |
28 | + function getVersion() | |
29 | + { | |
30 | + return '0.51'; | |
24 | 31 | } |
25 | 32 | |
26 | - // a description to be shown on the installed plugins listing | |
27 | - function getDescription() { | |
33 | + function getDescription() | |
34 | + { | |
28 | 35 | return 'convert WikiTag'; |
29 | 36 | } |
30 | 37 |
@@ -37,16 +44,24 @@ class NP_Wikistyle extends NucleusPlugin { | ||
37 | 44 | } |
38 | 45 | } |
39 | 46 | |
40 | - function getEventList() { return array('PreItem'); } | |
47 | + function getEventList() | |
48 | + { | |
49 | + return array( | |
50 | + 'PreItem' | |
51 | + ); | |
52 | + } | |
41 | 53 | |
42 | - function event_PreItem(&$data) { | |
43 | - $this->currentItem = &$data["item"]; | |
44 | - $this->convert_wikitag($this->currentItem->body); | |
45 | - if($this->currentItem->more) | |
46 | - $this->convert_wikitag($this->currentItem->more); | |
54 | + function event_PreItem(&$data) | |
55 | + { | |
56 | + $this->currentItem =& $data["item"]; | |
57 | + $this->convert_wikitag($this->currentItem->body); | |
58 | + if ($this->currentItem->more) { | |
59 | + $this->convert_wikitag($this->currentItem->more); | |
60 | + } | |
47 | 61 | } |
48 | 62 | |
49 | - function convert_wikitag(&$text) { | |
63 | + function convert_wikitag(&$text) | |
64 | + { | |
50 | 65 | $text = removeBreaks($text); |
51 | 66 | $tmp_lines = explode("\n", $text); |
52 | 67 | $tmp_lines[] = " "; |
@@ -55,7 +70,7 @@ class NP_Wikistyle extends NucleusPlugin { | ||
55 | 70 | $templevel = array(); |
56 | 71 | |
57 | 72 | $endline = count($tmp_lines) - 1; |
58 | - for($i=0;$i<=$endline;$i++){ | |
73 | + for ($i=0;$i<=$endline;$i++) { | |
59 | 74 | // $tmp_lines[$i] = trim($tmp_lines[$i]); |
60 | 75 | $level = ''; |
61 | 76 | //__________ |
@@ -72,97 +87,109 @@ class NP_Wikistyle extends NucleusPlugin { | ||
72 | 87 | '$this->createLinkCodeWiki("\\1", "\\3","mailto")' |
73 | 88 | ); |
74 | 89 | |
75 | - if ($level[p] = preg_match('/^(https:\/\/|http:\/\/|www\.|ftp:\/\/|ftp\.|mailto:)/ie',$tmp_lines[$i]) ){ | |
90 | + if ($level[p] = preg_match('/^(https:\/\/|http:\/\/|www\.|ftp:\/\/|ftp\.|mailto:)/ie', $tmp_lines[$i])) { | |
76 | 91 | $tmp_lines[$i] = preg_replace($replaceFrom, $replaceTo, $tmp_lines[$i]); |
77 | - $text .= $tmp_lines[$i]."<br />"; | |
92 | + $text .= $tmp_lines[$i] . '<br />'; | |
78 | 93 | } |
79 | 94 | //__________ |
80 | - if (($level[h] = strspn($tmp_lines[$i],'*')) > 6) { | |
95 | + if (($level[h] = strspn($tmp_lines[$i], '*')) > 6) { | |
81 | 96 | $level[h] = 6; // limitation ;( |
82 | 97 | } |
83 | - if($level[h]){ | |
84 | - $tmp_lines[$i] = ltrim(substr($tmp_lines[$i],$level[h])); | |
85 | - $text .= '<h'.$level[h].' class="wiki">'.$tmp_lines[$i].'</h'.$level[h].'>'; | |
98 | + if ($level[h]) { | |
99 | + $tmp_lines[$i] = ltrim(substr($tmp_lines[$i], $level[h])); | |
100 | + $text .= '<h' . intval($level[h]) . ' class="wiki">' . $tmp_lines[$i] . '</h' . intval($level[h]) . '>'; | |
86 | 101 | } |
87 | 102 | //__________ |
88 | - if (($level[u] = strspn($tmp_lines[$i],'-')) > 3){ | |
103 | + if (($level[u] = strspn($tmp_lines[$i], '-')) > 3) { | |
89 | 104 | $level[r] = 4; |
90 | 105 | $level[u] = 3; // limitation ;( |
91 | 106 | } |
92 | - if($level[u] && !$level[r]){ | |
93 | - $tmp_lines[$i] = ltrim(substr($tmp_lines[$i],$level[u])); | |
94 | -// $tmp_lines[$i] = '<li>'.$tmp_lines[$i].'</li>'; | |
107 | + if ($level[u] && !$level[r]) { | |
108 | + $tmp_lines[$i] = ltrim(substr($tmp_lines[$i], $level[u])); | |
109 | +// $tmp_lines[$i] = '<li>' . $tmp_lines[$i] . '</li>'; | |
95 | 110 | //_------------- |
96 | - if($temptoplevel == 'u' && $templevel[o]){ | |
97 | - $tmp_lines[$i] = str_repeat("</ol>\n",$templevel[o])."\n".'<li>'.$tmp_lines[$i].'</li>'; | |
111 | + if ($temptoplevel == 'u' && $templevel[o]) { | |
112 | + $tmp_lines[$i] = str_repeat("</ol>\n",$templevel[o]) . "\n" . '<li>' . $tmp_lines[$i] . '</li>'; | |
98 | 113 | $templevel[o] = 0; |
99 | 114 | }else{ |
100 | - $tmp_lines[$i] = '<li>'.$tmp_lines[$i].'</li>'; | |
115 | + $tmp_lines[$i] = '<li>' . $tmp_lines[$i] . '</li>'; | |
101 | 116 | } |
102 | 117 | //_------------- |
103 | 118 | |
104 | 119 | $difflevel = $level[u] - $templevel[u]; |
105 | - if($difflevel < 0) | |
106 | - $text .= str_repeat("</ul>\n",0-$difflevel); | |
107 | - if( $difflevel > 0) | |
108 | - $text .= str_repeat("<ul>\n",$difflevel); | |
120 | + if ($difflevel < 0) { | |
121 | + $text .= str_repeat("</ul>\n", 0 - $difflevel); | |
122 | + } | |
123 | + if ( $difflevel > 0) { | |
124 | + $text .= str_repeat("<ul>\n", $difflevel); | |
125 | + } | |
109 | 126 | |
110 | 127 | $text .= $tmp_lines[$i]; |
111 | - if(!array_sum($templevel)) | |
128 | + if (!array_sum($templevel)) { | |
112 | 129 | $temptoplevel = 'u'; |
130 | + } | |
113 | 131 | $templevel[u] = $level[u]; |
114 | 132 | } |
115 | 133 | //__________ |
116 | - if($level[r]){ | |
117 | - $tmp_lines[$i] = ltrim(substr($tmp_lines[$i],$level[r])); | |
134 | + if ($level[r]) { | |
135 | + $tmp_lines[$i] = ltrim(substr($tmp_lines[$i], $level[r])); | |
118 | 136 | $text .= '<div class="hr"><hr /></div>'; |
119 | 137 | } |
120 | 138 | //__________ |
121 | - if (($level[o] = strspn($tmp_lines[$i],'+')) > 3) | |
139 | + if (($level[o] = strspn($tmp_lines[$i],'+')) > 3) { | |
122 | 140 | $level[o] = 3; // limitation ;( |
123 | - if($level[o]){ | |
124 | - $tmp_lines[$i] = ltrim(substr($tmp_lines[$i],$level[o])); | |
141 | + } | |
142 | + if ($level[o]) { | |
143 | + $tmp_lines[$i] = ltrim(substr($tmp_lines[$i], $level[o])); | |
125 | 144 | |
126 | -// $tmp_lines[$i] = '<li>'.$tmp_lines[$i].'</li>'; | |
145 | +// $tmp_lines[$i] = '<li>' . $tmp_lines[$i] . '</li>'; | |
127 | 146 | //_------------- |
128 | - if($temptoplevel == 'o' && $templevel[u]){ | |
129 | - $tmp_lines[$i] = str_repeat("</ul>\n",$templevel[u])."\n".'<li>'.$tmp_lines[$i].'</li>'; | |
147 | + if ($temptoplevel == 'o' && $templevel[u]) { | |
148 | + $tmp_lines[$i] = str_repeat("</ul>\n", $templevel[u]) . "\n" . '<li>' . $tmp_lines[$i] . '</li>'; | |
130 | 149 | $templevel[u] = 0; |
131 | - }else{ | |
132 | - $tmp_lines[$i] = '<li>'.$tmp_lines[$i].'</li>'; | |
150 | + } else { | |
151 | + $tmp_lines[$i] = '<li>' . $tmp_lines[$i] . '</li>'; | |
133 | 152 | } |
134 | 153 | //_------------- |
135 | 154 | |
136 | 155 | $difflevel = $level[o] - $templevel[o]; |
137 | - if($difflevel < 0) | |
138 | - $text .= str_repeat("</ol>\n",0-$difflevel); | |
139 | - if( $difflevel > 0) | |
140 | - $text .= str_repeat("<ol>\n",$difflevel); | |
156 | + if ($difflevel < 0) { | |
157 | + $text .= str_repeat("</ol>\n", 0 - $difflevel); | |
158 | + } | |
159 | + if ( $difflevel > 0) { | |
160 | + $text .= str_repeat("<ol>\n", $difflevel); | |
161 | + } | |
141 | 162 | |
142 | 163 | $text .= $tmp_lines[$i]; |
143 | - if(!array_sum($templevel)) | |
164 | + if (!array_sum($templevel)) { | |
144 | 165 | $temptoplevel = 'o'; |
166 | + } | |
145 | 167 | $templevel[o] = $level[o]; |
146 | 168 | } |
147 | 169 | //__________ |
148 | - if(array_sum($level) == 0){ | |
149 | - if(array_sum($templevel)){ | |
150 | - if($templevel[u]) | |
151 | - $text .= str_repeat("</ul>\n",$templevel[u]); | |
152 | - if($templevel[o]) | |
153 | - $text .= str_repeat("</ol>\n",$templevel[o]); | |
170 | + if (array_sum($level) == 0) { | |
171 | + if (array_sum($templevel)) { | |
172 | + if ($templevel[u]) { | |
173 | + $text .= str_repeat("</ul>\n", $templevel[u]); | |
174 | + } | |
175 | + if ($templevel[o]) { | |
176 | + $text .= str_repeat("</ol>\n", $templevel[o]); | |
177 | + } | |
154 | 178 | $templevel = array(); |
155 | 179 | $temptoplevel = ''; |
156 | 180 | } |
157 | - if($tmp_lines[$i] && $i != $endline) | |
181 | + if ($tmp_lines[$i] && $i != $endline) { | |
158 | 182 | $text .= $tmp_lines[$i]."<br />"; |
183 | + } | |
159 | 184 | } |
160 | - if($tmp_lines[$i] && $i != $endline) | |
185 | + if ($tmp_lines[$i] && $i != $endline) { | |
161 | 186 | $text .= "\n"; |
187 | + } | |
162 | 188 | } |
163 | 189 | } |
164 | 190 | |
165 | - function createLinkCodeWiki($pre, $url, $protocol = 'http') { | |
191 | + function createLinkCodeWiki($pre, $url, $protocol = 'http') | |
192 | + { | |
166 | 193 | $post = ''; |
167 | 194 | |
168 | 195 | // it's possible that $url ends with an entities |
@@ -172,17 +199,19 @@ class NP_Wikistyle extends NucleusPlugin { | ||
172 | 199 | $url = substr($url, 0, strlen($url) - strlen($post)); |
173 | 200 | } |
174 | 201 | |
175 | - if (!ereg('^'.$protocol.'://',$url)) | |
202 | + if (!ereg('^'.$protocol.'://',$url)) { | |
176 | 203 | $linkedUrl = $protocol . (($protocol == 'mailto') ? ':' : '://') . $url; |
177 | - else | |
204 | + } else { | |
178 | 205 | $linkedUrl = $url; |
206 | + } | |
179 | 207 | |
180 | 208 | |
181 | - if ($protocol != 'mailto') | |
209 | + if ($protocol != 'mailto') { | |
182 | 210 | $displayedUrl = $linkedUrl; |
183 | - else | |
211 | + } else { | |
184 | 212 | $displayedUrl = $url; |
185 | - return $pre . '<a href="'.$linkedUrl.'" target="_blank">'.$displayedUrl.'</a>' . $post; | |
213 | + } | |
214 | + return $pre . '<a href="' . htmlspecialchars($linkedUrl) . '" target="_blank">' . htmlspecialchars($displayedUrl) . '</a>' . $post; | |
186 | 215 | } |
187 | 216 | |
188 | 217 |
@@ -2,24 +2,28 @@ | ||
2 | 2 | |
3 | 3 | class NP_Wtable extends NucleusPlugin { |
4 | 4 | |
5 | - function getName() { // name of plugin | |
6 | - return 'Convert table'; | |
5 | + function getName() | |
6 | + { | |
7 | + return 'Convert table'; | |
7 | 8 | } |
8 | - | |
9 | - function getAuthor() { // author of plugin | |
10 | - return 'nakahara21'; | |
9 | + | |
10 | + function getAuthor() | |
11 | + { | |
12 | + return 'nakahara21'; | |
11 | 13 | } |
12 | - | |
13 | - function getURL() { // an URL to the plugin website | |
14 | - return 'http://xx.nakahara21.net/'; | |
14 | + | |
15 | + function getURL() | |
16 | + { | |
17 | + return 'http://nakahara21.com'; | |
15 | 18 | } |
16 | 19 | |
17 | - function getVersion() { // version of the plugin | |
18 | - return '0.2'; //tate array | |
20 | + function getVersion() | |
21 | + { | |
22 | + return '0.21'; | |
19 | 23 | } |
20 | - | |
21 | - // a description to be shown on the installed plugins listing | |
22 | - function getDescription() { | |
24 | + | |
25 | + function getDescription() | |
26 | + { | |
23 | 27 | return 'Convert table'; |
24 | 28 | } |
25 | 29 |
@@ -32,13 +36,19 @@ class NP_Wtable extends NucleusPlugin { | ||
32 | 36 | } |
33 | 37 | } |
34 | 38 | |
35 | - function getEventList() { return array('PreItem'); } | |
39 | + function getEventList() | |
40 | + { | |
41 | + return array( | |
42 | + 'PreItem' | |
43 | + ); | |
44 | + } | |
36 | 45 | |
37 | - function event_PreItem(&$data) { | |
38 | - $this->currentItem = &$data["item"]; | |
46 | + function event_PreItem(&$data) | |
47 | + { | |
48 | + $this->currentItem =& $data["item"]; | |
39 | 49 | |
40 | 50 | $this->currentItem->body = removeBreaks($this->currentItem->body); |
41 | -// $this->currentItem->body = str_replace("\r\n","\n",$this->currentItem->body); | |
51 | +// $this->currentItem->body = str_replace("\r\n", "\n", $this->currentItem->body); | |
42 | 52 | $this->currentItem->body = preg_replace_callback("#\|(.*)\|\r\n#", array(&$this, 'list_table'), $this->currentItem->body); |
43 | 53 | $this->currentItem->body = preg_replace_callback("#\!(.*)\!#", array(&$this, 'convert_table'), $this->currentItem->body); |
44 | 54 | $this->currentItem->body = addBreaks($this->currentItem->body); |
@@ -46,53 +56,55 @@ class NP_Wtable extends NucleusPlugin { | ||
46 | 56 | $this->currentItem->more = preg_replace_callback("#\|(.*?)\|#", array(&$this, 'convert_table'), $this->currentItem->more); |
47 | 57 | } |
48 | 58 | |
49 | - function list_table($text) { | |
50 | - return "!".$text[1]."!"; | |
59 | + function list_table($text) | |
60 | + { | |
61 | + return "!" . $text[1] . "!"; | |
51 | 62 | } |
52 | 63 | |
53 | - function convert_table($text) { | |
54 | - $rows = explode('!!',$text[1]); | |
55 | - for($r =0; $r < count($rows); $r++){ | |
56 | - $cell = explode('|',$rows["$r"]); | |
57 | - for($c = 0; $c < count($cell); $c++){ | |
64 | + function convert_table($text) | |
65 | + { | |
66 | + $rows = explode('!!', $text[1]); | |
67 | + for ($r =0; $r < count($rows); $r++) { | |
68 | + $cell = explode('|', $rows["$r"]); | |
69 | + for ($c = 0; $c < count($cell); $c++) { | |
58 | 70 | $cols["$c"]["$r"] = $cell["$c"]; |
59 | 71 | } |
60 | 72 | } |
61 | 73 | |
62 | - for($c = 0; $c < count($cols); $c++){ | |
74 | + for ($c = 0; $c < count($cols); $c++) { | |
63 | 75 | $cols["$c"] = array_reverse ($cols["$c"], TRUE); |
64 | 76 | $rowspan = 1; |
65 | 77 | // print_r($cols["$c"]); |
66 | - foreach($cols["$c"] as $key => $val){ | |
67 | - if($val == '~'){ | |
78 | + foreach($cols["$c"] as $key => $val) { | |
79 | + if ($val == '~') { | |
68 | 80 | $rowspan ++; |
69 | 81 | $row["$key"]["$c"] = $val; |
70 | - }elseif($val == '>'){ | |
82 | + } elseif($val == '>') { | |
71 | 83 | $row["$key"]["$c"] = $val; |
72 | - }elseif($rowspan > 1){ | |
73 | - $row["$key"]["$c"] = '<td rowspan="'.$rowspan.'">'.$val.'</td>'; | |
84 | + } elseif($rowspan > 1) { | |
85 | + $row["$key"]["$c"] = '<td rowspan="' . intval($rowspan) . '">' . $val . '</td>'; | |
74 | 86 | $rowspan = 1; |
75 | 87 | }else{ |
76 | - $row["$key"]["$c"] = '<td>'.$val.'</td>'; | |
88 | + $row["$key"]["$c"] = '<td>' . $val . '</td>'; | |
77 | 89 | } |
78 | 90 | } |
79 | 91 | } |
80 | 92 | $row = array_reverse ($row, TRUE); |
81 | 93 | // print_r($row); |
82 | 94 | |
83 | - for($r = 0; $r < count($row); $r++){ | |
95 | + for ($r = 0; $r < count($row); $r++) { | |
84 | 96 | $out .= '<tr>'; |
85 | 97 | $colspan = 1; |
86 | - for($c =0; $c < count($row["$r"]); $c++){ | |
87 | - if($row["$r"]["$c"] == '~'){ | |
98 | + for ($c =0; $c < count($row["$r"]); $c++) { | |
99 | + if ($row["$r"]["$c"] == '~') { | |
88 | 100 | $out .= ''; |
89 | - }elseif($row["$r"]["$c"] == '>'){ | |
101 | + } elseif ($row["$r"]["$c"] == '>') { | |
90 | 102 | $out .= ''; |
91 | 103 | $colspan ++; |
92 | - }elseif($colspan >1){ | |
93 | - $out .= str_replace('<td>','<td colspan="'.$colspan.'">',$row["$r"]["$c"]); | |
104 | + } elseif ($colspan > 1) { | |
105 | + $out .= str_replace('<td>', '<td colspan="' . intval($colspan) . '">', $row["$r"]["$c"]); | |
94 | 106 | $colspan = 1; |
95 | - }else{ | |
107 | + } else { | |
96 | 108 | $out .= $row["$r"]["$c"]; |
97 | 109 | } |
98 | 110 | } |
@@ -100,7 +112,7 @@ class NP_Wtable extends NucleusPlugin { | ||
100 | 112 | $out .= '</tr>'; |
101 | 113 | } |
102 | 114 | |
103 | - return '<table border=1>'.$out.'</table>'; | |
115 | + return '<table border=1>' . $out . '</table>'; | |
104 | 116 | } |
105 | 117 | } |
106 | 118 | ?> |
\ No newline at end of file |