Commit MetaInfo

修订版31745e603e8e10f1d7ff59cee3793afdd7440806 (tree)
时间2004-09-05 00:56:37
作者arino <arino>
Commiterarino

Log Message

php5 compat

更改概述

差异

--- a/lib/convert_html.php
+++ b/lib/convert_html.php
@@ -2,7 +2,7 @@
22 /////////////////////////////////////////////////
33 // PukiWiki - Yet another WikiWikiWeb clone.
44 //
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 $
66 //
77
88 function convert_html($lines)
@@ -96,6 +96,54 @@ class Element
9696 }
9797 }
9898
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+
99147 class Inline extends Element
100148 { // インライン要素
101149
@@ -103,13 +151,6 @@ class Inline extends Element
103151 {
104152 parent::Element();
105153
106- if (substr($text,0,1) == '~') // 行頭~。パラグラフ開始
107- {
108- $this = new Paragraph(' '.substr($text,1));
109- $this->last = &$this;
110-
111- return;
112- }
113154 $this->elements[] = trim((substr($text, 0, 1) == "\n") ? $text : make_link($text));
114155 }
115156
@@ -157,7 +198,7 @@ class Paragraph extends Element
157198 {
158199 $text = ' '.substr($text, 1);
159200 }
160- $this->insert(new Inline($text));
201+ $this->insert(Factory_Inline($text));
161202 }
162203
163204 function canContain($obj)
@@ -183,7 +224,7 @@ class Heading extends Element
183224
184225 $this->level = min(3, strspn($text, '*'));
185226 list($text, $this->msg_top, $this->id) = $root->getAnchor($text, $this->level);
186- $this->insert(new Inline($text));
227+ $this->insert(Factory_Inline($text));
187228 $this->level++; // h2,h3,h4
188229 }
189230
@@ -254,7 +295,7 @@ class ListContainer extends Element
254295 parent::insert(new ListElement($this->level, $tag2));
255296 if ($text != '')
256297 {
257- $this->last = &$this->last->insert(new Inline($text));
298+ $this->last = &$this->last->insert(Factory_Inline($text));
258299 }
259300 }
260301
@@ -348,22 +389,14 @@ class OList extends ListContainer
348389
349390 class DList extends ListContainer
350391 { // :
351- function DList(&$root, $text)
392+ function DList($out)
352393 {
353- $out = explode('|', $text, 2);
354- if (count($out) < 2)
355- {
356- $this = new Inline($text);
357- $this->last = &$this;
358-
359- return;
360- }
361394 parent::ListContainer('dl', 'dt', ':', $out[0]);
362395
363396 $this->last = &Element::insert(new ListElement($this->level, 'dd'));
364397 if ($out[1] != '')
365398 {
366- $this->last = &$this->last->insert(new Inline($out[1]));
399+ $this->last = &$this->last->insert(Factory_Inline($out[1]));
367400 }
368401 }
369402 }
@@ -387,12 +420,12 @@ class BQuote extends Element
387420 $this->last = &$this->end($root, $level);
388421 if ($text != '')
389422 {
390- $this->last = &$this->last->insert(new Inline($text));
423+ $this->last = &$this->last->insert(Factory_Inline($text));
391424 }
392425 }
393426 else
394427 {
395- $this->insert(new Inline($text));
428+ $this->insert(Factory_Inline($text));
396429 }
397430 }
398431
@@ -490,7 +523,7 @@ class TableCell extends Element
490523 if ($text != '' and $text{0} == '#')
491524 {
492525 // セル内容が'#'で始まるときはDivクラスを通してみる
493- $obj = &new Div($this, $text);
526+ $obj = &Factory_Div($this, $text);
494527 if (is_a($obj, 'Paragraph'))
495528 {
496529 $obj = &$obj->elements[0];
@@ -498,7 +531,7 @@ class TableCell extends Element
498531 }
499532 else
500533 {
501- $obj = &new Inline($text);
534+ $obj = &Factory_Inline($text);
502535 }
503536 $this->insert($obj);
504537 }
@@ -545,18 +578,10 @@ class Table extends Element
545578 var $types;
546579 var $col; // number of column
547580
548- function Table(&$root, $text)
581+ function Table($out)
549582 {
550583 parent::Element();
551584
552- $out = array();
553- if (!preg_match("/^\|(.+)\|([hHfFcC]?)$/", $text, $out))
554- {
555- $this = new Inline($text);
556- $this->last = &$this;
557-
558- return;
559- }
560585 $cells = explode('|', $out[1]);
561586 $this->col = count($cells);
562587 $this->type = strtolower($out[2]);
@@ -666,18 +691,10 @@ class YTable extends Element
666691 { // ,
667692 var $col;
668693
669- function YTable(&$root, $text)
694+ function YTable($_value)
670695 {
671696 parent::Element();
672697
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- }
681698 $align = $value = $matches = array();
682699 foreach($_value as $val)
683700 {
@@ -776,17 +793,10 @@ class Div extends Element
776793 var $name;
777794 var $param;
778795
779- function Div(&$root, $text)
796+ function Div($out)
780797 {
781798 parent::Element();
782799
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- }
790800 list(, $this->name, $this->param) = array_pad($out,3,'');
791801 }
792802
@@ -832,11 +842,13 @@ class Body extends Element
832842 var $classes = array(
833843 '-' => 'UList',
834844 '+' => 'OList',
845+ '>' => 'BQuote',
846+ '<' => 'BQuote'
847+ );
848+ var $factories = array(
835849 ':' => 'DList',
836850 '|' => 'Table',
837851 ',' => 'YTable',
838- '>' => 'BQuote',
839- '<' => 'BQuote',
840852 '#' => 'Div'
841853 );
842854
@@ -912,9 +924,16 @@ class Body extends Element
912924 $this->last = &$this->last->add(new $classname($this,$line));
913925 continue;
914926 }
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+ }
915934
916935 // Default
917- $this->last = &$this->last->add(new Inline($line));
936+ $this->last = &$this->last->add(Factory_Inline($line));
918937 }
919938 }
920939
@@ -992,7 +1011,7 @@ class Contents_UList extends ListContainer
9921011 make_heading($text);
9931012 $text = "\n<a href=\"#$id\">$text</a>\n";
9941013 parent::ListContainer('ul', 'li', '-', str_repeat('-',$level));
995- $this->insert(new Inline($text));
1014+ $this->insert(Factory_Inline($text));
9961015 }
9971016
9981017 function setParent(&$parent)
--- a/lib/make_link.php
+++ b/lib/make_link.php
@@ -2,7 +2,7 @@
22 /////////////////////////////////////////////////
33 // PukiWiki - Yet another WikiWikiWeb clone.
44 //
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 $
66 //
77
88 // リンクを付加する
@@ -15,7 +15,7 @@ function make_link($string,$page = '')
1515 {
1616 $converter = new InlineConverter();
1717 }
18- $_converter = $converter; // copy
18+ $_converter = $converter->get_clone($converter);
1919 return $_converter->convert($string, ($page != '') ? $page : $vars['page']);
2020 }
2121 //インライン要素を置換する
@@ -26,6 +26,25 @@ class InlineConverter
2626 var $pos;
2727 var $result;
2828
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+ }
2948 function InlineConverter($converters=NULL,$excludes=NULL)
3049 {
3150 if ($converters === NULL)
@@ -101,7 +120,7 @@ class InlineConverter
101120 $obj = $this->get_converter($match);
102121 if ($obj->set($match,$page) !== FALSE)
103122 {
104- $arr[] = $obj; // copy
123+ $arr[] = $this->get_clone($obj);
105124 if ($obj->body != '')
106125 {
107126 $arr = array_merge($arr,$this->get_objects($obj->body,$page));
--- a/plugin/attach.inc.php
+++ b/plugin/attach.inc.php
@@ -2,7 +2,7 @@
22 /////////////////////////////////////////////////
33 // PukiWiki - Yet another WikiWikiWeb clone.
44 //
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 $
66 //
77
88 /*
@@ -384,7 +384,7 @@ class AttachFile
384384 function AttachFile($page, $file, $age = 0)
385385 {
386386 $this->page = $page;
387- $this->file = basename($file);
387+ $this->file = preg_replace('#^.*/#','',$file);
388388 $this->age = is_numeric($age) ? $age : 0;
389389
390390 $this->basename = UPLOAD_DIR . encode($page) . '_' . encode($this->file);
--- a/plugin/ref.inc.php
+++ b/plugin/ref.inc.php
@@ -2,7 +2,7 @@
22 /////////////////////////////////////////////////
33 // PukiWiki - Yet another WikiWikiWeb clone.
44 //
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 $
66 //
77
88 // UPLOAD_DIR のデータ(画像ファイルのみ)に直接アクセスさせる
@@ -403,7 +403,7 @@ function plugin_ref_action()
403403 $page = $vars['page'];
404404 $file = $vars['src'];
405405
406- $ref = UPLOAD_DIR . encode($page) . '_' . encode(basename($file));
406+ $ref = UPLOAD_DIR . encode($page) . '_' . encode(preg_replace('#^.*/#','',$file));
407407 if(! file_exists($ref))
408408 return array('msg'=>'Attach file not found', 'body'=>$usage);
409409
--- a/plugin/showrss.inc.php
+++ b/plugin/showrss.inc.php
@@ -2,7 +2,7 @@
22 /////////////////////////////////////////////////
33 // PukiWiki - Yet another WikiWikiWeb clone.
44 //
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 $
66 //
77 // Modified version by PANDA <panda@arino.jp>
88 //
@@ -239,6 +239,7 @@ class ShowRSS_XML
239239 var $item;
240240 var $is_item;
241241 var $tag;
242+ var $encoding;
242243
243244 function parse($buf)
244245 {
@@ -248,7 +249,13 @@ class ShowRSS_XML
248249 $this->is_item = FALSE;
249250 $this->tag = '';
250251
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);
252259 xml_set_element_handler($xml_parser,array(&$this,'start_element'),array(&$this,'end_element'));
253260 xml_set_character_data_handler($xml_parser,array(&$this,'character_data'));
254261
@@ -270,7 +277,7 @@ class ShowRSS_XML
270277 $str = htmlspecialchars($str);
271278
272279 // 文字コード変換
273- $str = mb_convert_encoding($str, SOURCE_ENCODING, 'auto');
280+ $str = mb_convert_encoding($str, SOURCE_ENCODING, $this->encoding);
274281
275282 return trim($str);
276283 }
Show on old repository browser