修訂 | 31745e603e8e10f1d7ff59cee3793afdd7440806 (tree) |
---|---|
時間 | 2004-09-05 00:56:37 |
作者 | arino <arino> |
Commiter | arino |
php5 compat
@@ -2,7 +2,7 @@ | ||
2 | 2 | ///////////////////////////////////////////////// |
3 | 3 | // PukiWiki - Yet another WikiWikiWeb clone. |
4 | 4 | // |
5 | -// $Id: convert_html.php,v 1.1 2004/08/01 01:54:35 henoheno Exp $ | |
5 | +// $Id: convert_html.php,v 1.1.2.1 2004/09/04 15:56:37 arino Exp $ | |
6 | 6 | // |
7 | 7 | |
8 | 8 | function convert_html($lines) |
@@ -96,6 +96,54 @@ class Element | ||
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | + // PHP5 mod: $this cannot be reassigned | |
100 | +function &Factory_Inline($text) | |
101 | +{ | |
102 | + if (substr($text,0,1) == '~') { // 行頭~。パラグラフ開始 | |
103 | + return new Paragraph(' '.substr($text,1)); | |
104 | + } | |
105 | + return new Inline($text); | |
106 | +} | |
107 | + | |
108 | + // PHP5 mod: $this cannot be reassigned | |
109 | +function &Factory_DList(&$root, $text) | |
110 | +{ | |
111 | + $out = explode('|', ltrim($text), 2); | |
112 | + if (count($out) < 2) { | |
113 | + return Factory_Inline($text); | |
114 | + } | |
115 | + | |
116 | + return new DList($out); | |
117 | +} | |
118 | + | |
119 | + // PHP5 mod: $this cannot be reassigned | |
120 | +function &Factory_Table(&$root, $text) | |
121 | +{ | |
122 | + if (!preg_match("/^\|(.+)\|([hHfFcC]?)$/",$text,$out)) { | |
123 | + return Factory_Inline($text); | |
124 | + } | |
125 | + return new Table($out); | |
126 | +} | |
127 | + | |
128 | + // PHP5 mod: $this cannot be reassigned | |
129 | +function &Factory_YTable(&$root,$text) | |
130 | +{ | |
131 | + $_value = csv_explode(',', substr($text,1)); | |
132 | + if (count($_value) == 0) { | |
133 | + return Factory_Inline($text); | |
134 | + } | |
135 | + return new YTable($_value); | |
136 | +} | |
137 | + | |
138 | + // PHP5 mod: $this cannot be reassigned | |
139 | +function &Factory_Div(&$root,$text) | |
140 | +{ | |
141 | + if (!preg_match("/^\#([^\(]+)(?:\((.*)\))?/", $text, $out) or !exist_plugin_convert($out[1])) { | |
142 | + return new Paragraph($text); | |
143 | + } | |
144 | + return new Div($out); | |
145 | +} | |
146 | + | |
99 | 147 | class Inline extends Element |
100 | 148 | { // インライン要素 |
101 | 149 |
@@ -103,13 +151,6 @@ class Inline extends Element | ||
103 | 151 | { |
104 | 152 | parent::Element(); |
105 | 153 | |
106 | - if (substr($text,0,1) == '~') // 行頭~。パラグラフ開始 | |
107 | - { | |
108 | - $this = new Paragraph(' '.substr($text,1)); | |
109 | - $this->last = &$this; | |
110 | - | |
111 | - return; | |
112 | - } | |
113 | 154 | $this->elements[] = trim((substr($text, 0, 1) == "\n") ? $text : make_link($text)); |
114 | 155 | } |
115 | 156 |
@@ -157,7 +198,7 @@ class Paragraph extends Element | ||
157 | 198 | { |
158 | 199 | $text = ' '.substr($text, 1); |
159 | 200 | } |
160 | - $this->insert(new Inline($text)); | |
201 | + $this->insert(Factory_Inline($text)); | |
161 | 202 | } |
162 | 203 | |
163 | 204 | function canContain($obj) |
@@ -183,7 +224,7 @@ class Heading extends Element | ||
183 | 224 | |
184 | 225 | $this->level = min(3, strspn($text, '*')); |
185 | 226 | list($text, $this->msg_top, $this->id) = $root->getAnchor($text, $this->level); |
186 | - $this->insert(new Inline($text)); | |
227 | + $this->insert(Factory_Inline($text)); | |
187 | 228 | $this->level++; // h2,h3,h4 |
188 | 229 | } |
189 | 230 |
@@ -254,7 +295,7 @@ class ListContainer extends Element | ||
254 | 295 | parent::insert(new ListElement($this->level, $tag2)); |
255 | 296 | if ($text != '') |
256 | 297 | { |
257 | - $this->last = &$this->last->insert(new Inline($text)); | |
298 | + $this->last = &$this->last->insert(Factory_Inline($text)); | |
258 | 299 | } |
259 | 300 | } |
260 | 301 |
@@ -348,22 +389,14 @@ class OList extends ListContainer | ||
348 | 389 | |
349 | 390 | class DList extends ListContainer |
350 | 391 | { // : |
351 | - function DList(&$root, $text) | |
392 | + function DList($out) | |
352 | 393 | { |
353 | - $out = explode('|', $text, 2); | |
354 | - if (count($out) < 2) | |
355 | - { | |
356 | - $this = new Inline($text); | |
357 | - $this->last = &$this; | |
358 | - | |
359 | - return; | |
360 | - } | |
361 | 394 | parent::ListContainer('dl', 'dt', ':', $out[0]); |
362 | 395 | |
363 | 396 | $this->last = &Element::insert(new ListElement($this->level, 'dd')); |
364 | 397 | if ($out[1] != '') |
365 | 398 | { |
366 | - $this->last = &$this->last->insert(new Inline($out[1])); | |
399 | + $this->last = &$this->last->insert(Factory_Inline($out[1])); | |
367 | 400 | } |
368 | 401 | } |
369 | 402 | } |
@@ -387,12 +420,12 @@ class BQuote extends Element | ||
387 | 420 | $this->last = &$this->end($root, $level); |
388 | 421 | if ($text != '') |
389 | 422 | { |
390 | - $this->last = &$this->last->insert(new Inline($text)); | |
423 | + $this->last = &$this->last->insert(Factory_Inline($text)); | |
391 | 424 | } |
392 | 425 | } |
393 | 426 | else |
394 | 427 | { |
395 | - $this->insert(new Inline($text)); | |
428 | + $this->insert(Factory_Inline($text)); | |
396 | 429 | } |
397 | 430 | } |
398 | 431 |
@@ -490,7 +523,7 @@ class TableCell extends Element | ||
490 | 523 | if ($text != '' and $text{0} == '#') |
491 | 524 | { |
492 | 525 | // セル内容が'#'で始まるときはDivクラスを通してみる |
493 | - $obj = &new Div($this, $text); | |
526 | + $obj = &Factory_Div($this, $text); | |
494 | 527 | if (is_a($obj, 'Paragraph')) |
495 | 528 | { |
496 | 529 | $obj = &$obj->elements[0]; |
@@ -498,7 +531,7 @@ class TableCell extends Element | ||
498 | 531 | } |
499 | 532 | else |
500 | 533 | { |
501 | - $obj = &new Inline($text); | |
534 | + $obj = &Factory_Inline($text); | |
502 | 535 | } |
503 | 536 | $this->insert($obj); |
504 | 537 | } |
@@ -545,18 +578,10 @@ class Table extends Element | ||
545 | 578 | var $types; |
546 | 579 | var $col; // number of column |
547 | 580 | |
548 | - function Table(&$root, $text) | |
581 | + function Table($out) | |
549 | 582 | { |
550 | 583 | parent::Element(); |
551 | 584 | |
552 | - $out = array(); | |
553 | - if (!preg_match("/^\|(.+)\|([hHfFcC]?)$/", $text, $out)) | |
554 | - { | |
555 | - $this = new Inline($text); | |
556 | - $this->last = &$this; | |
557 | - | |
558 | - return; | |
559 | - } | |
560 | 585 | $cells = explode('|', $out[1]); |
561 | 586 | $this->col = count($cells); |
562 | 587 | $this->type = strtolower($out[2]); |
@@ -666,18 +691,10 @@ class YTable extends Element | ||
666 | 691 | { // , |
667 | 692 | var $col; |
668 | 693 | |
669 | - function YTable(&$root, $text) | |
694 | + function YTable($_value) | |
670 | 695 | { |
671 | 696 | parent::Element(); |
672 | 697 | |
673 | - $_value = csv_explode(',', substr($text,1)); | |
674 | - if (count($_value) == 0) | |
675 | - { | |
676 | - $this = new Inline($text); | |
677 | - $this->last = &$this; | |
678 | - | |
679 | - return; | |
680 | - } | |
681 | 698 | $align = $value = $matches = array(); |
682 | 699 | foreach($_value as $val) |
683 | 700 | { |
@@ -776,17 +793,10 @@ class Div extends Element | ||
776 | 793 | var $name; |
777 | 794 | var $param; |
778 | 795 | |
779 | - function Div(&$root, $text) | |
796 | + function Div($out) | |
780 | 797 | { |
781 | 798 | parent::Element(); |
782 | 799 | |
783 | - if (!preg_match("/^\#([^\(]+)(?:\((.*)\))?/", $text, $out) or !exist_plugin_convert($out[1])) | |
784 | - { | |
785 | - $this = new Paragraph($text); | |
786 | - $this->last = &$this; | |
787 | - | |
788 | - return; | |
789 | - } | |
790 | 800 | list(, $this->name, $this->param) = array_pad($out,3,''); |
791 | 801 | } |
792 | 802 |
@@ -832,11 +842,13 @@ class Body extends Element | ||
832 | 842 | var $classes = array( |
833 | 843 | '-' => 'UList', |
834 | 844 | '+' => 'OList', |
845 | + '>' => 'BQuote', | |
846 | + '<' => 'BQuote' | |
847 | + ); | |
848 | + var $factories = array( | |
835 | 849 | ':' => 'DList', |
836 | 850 | '|' => 'Table', |
837 | 851 | ',' => 'YTable', |
838 | - '>' => 'BQuote', | |
839 | - '<' => 'BQuote', | |
840 | 852 | '#' => 'Div' |
841 | 853 | ); |
842 | 854 |
@@ -912,9 +924,16 @@ class Body extends Element | ||
912 | 924 | $this->last = &$this->last->add(new $classname($this,$line)); |
913 | 925 | continue; |
914 | 926 | } |
927 | + // Other Character | |
928 | + if (array_key_exists($head, $this->factories)) | |
929 | + { | |
930 | + $factoryname = 'Factory_'. $this->factories[$head]; | |
931 | + $this->last = &$this->last->add($factoryname($this,$line)); | |
932 | + continue; | |
933 | + } | |
915 | 934 | |
916 | 935 | // Default |
917 | - $this->last = &$this->last->add(new Inline($line)); | |
936 | + $this->last = &$this->last->add(Factory_Inline($line)); | |
918 | 937 | } |
919 | 938 | } |
920 | 939 |
@@ -992,7 +1011,7 @@ class Contents_UList extends ListContainer | ||
992 | 1011 | make_heading($text); |
993 | 1012 | $text = "\n<a href=\"#$id\">$text</a>\n"; |
994 | 1013 | parent::ListContainer('ul', 'li', '-', str_repeat('-',$level)); |
995 | - $this->insert(new Inline($text)); | |
1014 | + $this->insert(Factory_Inline($text)); | |
996 | 1015 | } |
997 | 1016 | |
998 | 1017 | function setParent(&$parent) |
@@ -2,7 +2,7 @@ | ||
2 | 2 | ///////////////////////////////////////////////// |
3 | 3 | // PukiWiki - Yet another WikiWikiWeb clone. |
4 | 4 | // |
5 | -// $Id: make_link.php,v 1.1 2004/08/01 01:54:35 henoheno Exp $ | |
5 | +// $Id: make_link.php,v 1.1.2.1 2004/09/04 15:56:37 arino Exp $ | |
6 | 6 | // |
7 | 7 | |
8 | 8 | // リンクを付加する |
@@ -15,7 +15,7 @@ function make_link($string,$page = '') | ||
15 | 15 | { |
16 | 16 | $converter = new InlineConverter(); |
17 | 17 | } |
18 | - $_converter = $converter; // copy | |
18 | + $_converter = $converter->get_clone($converter); | |
19 | 19 | return $_converter->convert($string, ($page != '') ? $page : $vars['page']); |
20 | 20 | } |
21 | 21 | //インライン要素を置換する |
@@ -26,6 +26,25 @@ class InlineConverter | ||
26 | 26 | var $pos; |
27 | 27 | var $result; |
28 | 28 | |
29 | + function get_clone($obj) { | |
30 | + static $clone_func; | |
31 | + | |
32 | + if (!isset($clone_func)) { | |
33 | + if (version_compare(PHP_VERSION,'5.0.0','<')) { | |
34 | + $clone_func = create_function('$a','return $a;'); | |
35 | + } else { | |
36 | + $clone_func = create_function('$a','return clone $a;'); | |
37 | + } | |
38 | + } | |
39 | + return $clone_func($obj); | |
40 | + } | |
41 | + function __clone() { | |
42 | + $converters = array(); | |
43 | + foreach ($this->converters as $key=>$converter) { | |
44 | + $converters[$key] = $this->get_clone($converter); | |
45 | + } | |
46 | + $this->converters = $converters; | |
47 | + } | |
29 | 48 | function InlineConverter($converters=NULL,$excludes=NULL) |
30 | 49 | { |
31 | 50 | if ($converters === NULL) |
@@ -101,7 +120,7 @@ class InlineConverter | ||
101 | 120 | $obj = $this->get_converter($match); |
102 | 121 | if ($obj->set($match,$page) !== FALSE) |
103 | 122 | { |
104 | - $arr[] = $obj; // copy | |
123 | + $arr[] = $this->get_clone($obj); | |
105 | 124 | if ($obj->body != '') |
106 | 125 | { |
107 | 126 | $arr = array_merge($arr,$this->get_objects($obj->body,$page)); |
@@ -2,7 +2,7 @@ | ||
2 | 2 | ///////////////////////////////////////////////// |
3 | 3 | // PukiWiki - Yet another WikiWikiWeb clone. |
4 | 4 | // |
5 | -// $Id: attach.inc.php,v 1.60 2004/08/15 00:19:35 henoheno Exp $ | |
5 | +// $Id: attach.inc.php,v 1.60.2.1 2004/09/04 15:56:37 arino Exp $ | |
6 | 6 | // |
7 | 7 | |
8 | 8 | /* |
@@ -384,7 +384,7 @@ class AttachFile | ||
384 | 384 | function AttachFile($page, $file, $age = 0) |
385 | 385 | { |
386 | 386 | $this->page = $page; |
387 | - $this->file = basename($file); | |
387 | + $this->file = preg_replace('#^.*/#','',$file); | |
388 | 388 | $this->age = is_numeric($age) ? $age : 0; |
389 | 389 | |
390 | 390 | $this->basename = UPLOAD_DIR . encode($page) . '_' . encode($this->file); |
@@ -2,7 +2,7 @@ | ||
2 | 2 | ///////////////////////////////////////////////// |
3 | 3 | // PukiWiki - Yet another WikiWikiWeb clone. |
4 | 4 | // |
5 | -// $Id: ref.inc.php,v 1.38 2004/09/01 13:15:16 henoheno Exp $ | |
5 | +// $Id: ref.inc.php,v 1.38.2.1 2004/09/04 15:56:37 arino Exp $ | |
6 | 6 | // |
7 | 7 | |
8 | 8 | // UPLOAD_DIR のデータ(画像ファイルのみ)に直接アクセスさせる |
@@ -403,7 +403,7 @@ function plugin_ref_action() | ||
403 | 403 | $page = $vars['page']; |
404 | 404 | $file = $vars['src']; |
405 | 405 | |
406 | - $ref = UPLOAD_DIR . encode($page) . '_' . encode(basename($file)); | |
406 | + $ref = UPLOAD_DIR . encode($page) . '_' . encode(preg_replace('#^.*/#','',$file)); | |
407 | 407 | if(! file_exists($ref)) |
408 | 408 | return array('msg'=>'Attach file not found', 'body'=>$usage); |
409 | 409 |
@@ -2,7 +2,7 @@ | ||
2 | 2 | ///////////////////////////////////////////////// |
3 | 3 | // PukiWiki - Yet another WikiWikiWeb clone. |
4 | 4 | // |
5 | -// $Id: showrss.inc.php,v 1.13 2004/07/31 03:09:20 henoheno Exp $ | |
5 | +// $Id: showrss.inc.php,v 1.13.2.1 2004/09/04 15:56:37 arino Exp $ | |
6 | 6 | // |
7 | 7 | // Modified version by PANDA <panda@arino.jp> |
8 | 8 | // |
@@ -239,6 +239,7 @@ class ShowRSS_XML | ||
239 | 239 | var $item; |
240 | 240 | var $is_item; |
241 | 241 | var $tag; |
242 | + var $encoding; | |
242 | 243 | |
243 | 244 | function parse($buf) |
244 | 245 | { |
@@ -248,7 +249,13 @@ class ShowRSS_XML | ||
248 | 249 | $this->is_item = FALSE; |
249 | 250 | $this->tag = ''; |
250 | 251 | |
251 | - $xml_parser = xml_parser_create(); | |
252 | + // 文字コード検出 | |
253 | + $this->encoding = mb_detect_encoding($buf); | |
254 | + if (!in_array(strtolower($this->encoding),array('us-ascii','iso-8859-1','utf-8'))) { | |
255 | + $buf = mb_convert_encoding($buf,'utf-8',$this->encoding); | |
256 | + $this->encoding = 'utf-8'; | |
257 | + } | |
258 | + $xml_parser = xml_parser_create($this->encoding); | |
252 | 259 | xml_set_element_handler($xml_parser,array(&$this,'start_element'),array(&$this,'end_element')); |
253 | 260 | xml_set_character_data_handler($xml_parser,array(&$this,'character_data')); |
254 | 261 |
@@ -270,7 +277,7 @@ class ShowRSS_XML | ||
270 | 277 | $str = htmlspecialchars($str); |
271 | 278 | |
272 | 279 | // 文字コード変換 |
273 | - $str = mb_convert_encoding($str, SOURCE_ENCODING, 'auto'); | |
280 | + $str = mb_convert_encoding($str, SOURCE_ENCODING, $this->encoding); | |
274 | 281 | |
275 | 282 | return trim($str); |
276 | 283 | } |