OSDN Git Service

Merged from r1_4_4 to branch_r1_4_4_php5_end
authorhenoheno <henoheno>
Sun, 19 Sep 2004 14:05:30 +0000 (23:05 +0900)
committerhenoheno <henoheno>
Sun, 19 Sep 2004 14:05:30 +0000 (23:05 +0900)
lib/convert_html.php
lib/make_link.php
plugin/attach.inc.php
plugin/ref.inc.php
plugin/showrss.inc.php

index c41c057..013ca1e 100644 (file)
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: convert_html.php,v 1.1 2004/08/01 01:54:35 henoheno Exp $
+// $Id: convert_html.php,v 1.2 2004/09/19 14:05:30 henoheno Exp $
 //
 
 function convert_html($lines)
@@ -96,6 +96,54 @@ class Element
        }
 }
 
+  // PHP5 mod: $this cannot be reassigned
+function &Factory_Inline($text)
+{
+       if (substr($text,0,1) == '~') { // ¹ÔƬ~¡£¥Ñ¥é¥°¥é¥Õ³«»Ï
+               return new Paragraph(' '.substr($text,1));
+       }
+       return new Inline($text);
+}
+
+  // PHP5 mod: $this cannot be reassigned
+function &Factory_DList(&$root, $text)
+{
+       $out = explode('|', ltrim($text), 2);
+       if (count($out) < 2) {
+               return Factory_Inline($text);
+       }
+
+       return new DList($out);
+}
+
+  // PHP5 mod: $this cannot be reassigned
+function &Factory_Table(&$root, $text)
+{
+       if (!preg_match("/^\|(.+)\|([hHfFcC]?)$/",$text,$out)) {
+               return Factory_Inline($text);
+       }
+       return new Table($out);
+}
+
+  // PHP5 mod: $this cannot be reassigned
+function &Factory_YTable(&$root,$text)
+{
+       $_value = csv_explode(',', substr($text,1));
+       if (count($_value) == 0) {
+               return Factory_Inline($text);
+       }
+       return new YTable($_value);
+}
+
+  // PHP5 mod: $this cannot be reassigned
+function &Factory_Div(&$root,$text)
+{
+       if (!preg_match("/^\#([^\(]+)(?:\((.*)\))?/", $text, $out) or !exist_plugin_convert($out[1])) {
+               return new Paragraph($text);
+       }
+       return new Div($out);
+}
+
 class Inline extends Element
 { // ¥¤¥ó¥é¥¤¥óÍ×ÁÇ
 
@@ -103,13 +151,6 @@ class Inline extends Element
        {
                parent::Element();
 
-               if (substr($text,0,1) == '~') // ¹ÔƬ~¡£¥Ñ¥é¥°¥é¥Õ³«»Ï
-               {
-                       $this = new Paragraph(' '.substr($text,1));
-                       $this->last = &$this;
-
-                       return;
-               }
                $this->elements[] = trim((substr($text, 0, 1) == "\n") ? $text : make_link($text));
        }
 
@@ -157,7 +198,7 @@ class Paragraph extends Element
                {
                        $text = ' '.substr($text, 1);
                }
-               $this->insert(new Inline($text));
+               $this->insert(Factory_Inline($text));
        }
 
        function canContain($obj)
@@ -183,7 +224,7 @@ class Heading extends Element
 
                $this->level = min(3, strspn($text, '*'));
                list($text, $this->msg_top, $this->id) = $root->getAnchor($text, $this->level);
-               $this->insert(new Inline($text));
+               $this->insert(Factory_Inline($text));
                $this->level++; // h2,h3,h4
        }
 
@@ -254,7 +295,7 @@ class ListContainer extends Element
                parent::insert(new ListElement($this->level, $tag2));
                if ($text != '')
                {
-                       $this->last = &$this->last->insert(new Inline($text));
+                       $this->last = &$this->last->insert(Factory_Inline($text));
                }
        }
 
@@ -348,22 +389,14 @@ class OList extends ListContainer
 
 class DList extends ListContainer
 { // :
-       function DList(&$root, $text)
+       function DList($out)
        {
-               $out = explode('|', $text, 2);
-               if (count($out) < 2)
-               {
-                       $this = new Inline($text);
-                       $this->last = &$this;
-
-                       return;
-               }
                parent::ListContainer('dl', 'dt', ':', $out[0]);
 
                $this->last = &Element::insert(new ListElement($this->level, 'dd'));
                if ($out[1] != '')
                {
-                       $this->last = &$this->last->insert(new Inline($out[1]));
+                       $this->last = &$this->last->insert(Factory_Inline($out[1]));
                }
        }
 }
@@ -387,12 +420,12 @@ class BQuote extends Element
                        $this->last = &$this->end($root, $level);
                        if ($text != '')
                        {
-                               $this->last = &$this->last->insert(new Inline($text));
+                               $this->last = &$this->last->insert(Factory_Inline($text));
                        }
                }
                else
                {
-                       $this->insert(new Inline($text));
+                       $this->insert(Factory_Inline($text));
                }
        }
 
@@ -490,7 +523,7 @@ class TableCell extends Element
                if ($text != '' and $text{0} == '#')
                {
                        // ¥»¥ëÆâÍƤ¬'#'¤Ç»Ï¤Þ¤ë¤È¤­¤ÏDiv¥¯¥é¥¹¤òÄ̤·¤Æ¤ß¤ë
-                       $obj = &new Div($this, $text);
+                       $obj = &Factory_Div($this, $text);
                        if (is_a($obj, 'Paragraph'))
                        {
                                $obj = &$obj->elements[0];
@@ -498,7 +531,7 @@ class TableCell extends Element
                }
                else
                {
-                       $obj = &new Inline($text);
+                       $obj = &Factory_Inline($text);
                }
                $this->insert($obj);
        }
@@ -545,18 +578,10 @@ class Table extends Element
        var $types;
        var $col; // number of column
 
-       function Table(&$root, $text)
+       function Table($out)
        {
                parent::Element();
 
-               $out = array();
-               if (!preg_match("/^\|(.+)\|([hHfFcC]?)$/", $text, $out))
-               {
-                       $this = new Inline($text);
-                       $this->last = &$this;
-
-                       return;
-               }
                $cells = explode('|', $out[1]);
                $this->col = count($cells);
                $this->type = strtolower($out[2]);
@@ -666,18 +691,10 @@ class YTable extends Element
 { // ,
        var $col;
 
-       function YTable(&$root, $text)
+       function YTable($_value)
        {
                parent::Element();
 
-               $_value = csv_explode(',', substr($text,1));
-               if (count($_value) == 0)
-               {
-                       $this = new Inline($text);
-                       $this->last = &$this;
-
-                       return;
-               }
                $align = $value = $matches = array();
                foreach($_value as $val)
                {
@@ -776,17 +793,10 @@ class Div extends Element
        var $name;
        var $param;
 
-       function Div(&$root, $text)
+       function Div($out)
        {
                parent::Element();
 
-               if (!preg_match("/^\#([^\(]+)(?:\((.*)\))?/", $text, $out) or !exist_plugin_convert($out[1]))
-               {
-                       $this = new Paragraph($text);
-                       $this->last = &$this;
-
-                       return;
-               }
                list(, $this->name, $this->param) = array_pad($out,3,'');
        }
 
@@ -832,11 +842,13 @@ class Body extends Element
        var $classes = array(
                '-' => 'UList',
                '+' => 'OList',
+               '>' => 'BQuote',
+               '<' => 'BQuote'
+       );
+       var $factories = array(
                ':' => 'DList',
                '|' => 'Table',
                ',' => 'YTable',
-               '>' => 'BQuote',
-               '<' => 'BQuote',
                '#' => 'Div'
        );
 
@@ -912,9 +924,16 @@ class Body extends Element
                                $this->last = &$this->last->add(new $classname($this,$line));
                                continue;
                        }
+                       // Other Character
+                       if (array_key_exists($head, $this->factories))
+                       {
+                               $factoryname = 'Factory_'. $this->factories[$head];
+                               $this->last = &$this->last->add($factoryname($this,$line));
+                               continue;
+                       }
 
                        // Default
-                       $this->last = &$this->last->add(new Inline($line));
+                       $this->last = &$this->last->add(Factory_Inline($line));
                }
        }
 
@@ -992,7 +1011,7 @@ class Contents_UList extends ListContainer
                make_heading($text);
                $text = "\n<a href=\"#$id\">$text</a>\n";
                parent::ListContainer('ul', 'li', '-', str_repeat('-',$level));
-               $this->insert(new Inline($text));
+               $this->insert(Factory_Inline($text));
        }
 
        function setParent(&$parent)
index f2dd148..2572a43 100644 (file)
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: make_link.php,v 1.1 2004/08/01 01:54:35 henoheno Exp $
+// $Id: make_link.php,v 1.2 2004/09/19 14:05:30 henoheno Exp $
 //
 
 // ¥ê¥ó¥¯¤òÉղ乤ë
@@ -15,7 +15,7 @@ function make_link($string,$page = '')
        {
                $converter = new InlineConverter();
        }
-       $_converter = $converter; // copy
+       $_converter = $converter->get_clone($converter);
        return $_converter->convert($string, ($page != '') ? $page : $vars['page']);
 }
 //¥¤¥ó¥é¥¤¥óÍ×ÁǤòÃÖ´¹¤¹¤ë
@@ -26,6 +26,25 @@ class InlineConverter
        var $pos;
        var $result;
 
+       function get_clone($obj) {
+               static $clone_func;
+
+               if (!isset($clone_func)) {
+                       if (version_compare(PHP_VERSION,'5.0.0','<')) {
+                               $clone_func = create_function('$a','return $a;');
+                       } else {
+                               $clone_func = create_function('$a','return clone $a;');
+                       }
+               }
+               return $clone_func($obj);
+       }
+       function __clone() {
+               $converters = array();
+               foreach ($this->converters as $key=>$converter) {
+                       $converters[$key] = $this->get_clone($converter);
+               }
+               $this->converters = $converters;
+       }
        function InlineConverter($converters=NULL,$excludes=NULL)
        {
                if ($converters === NULL)
@@ -101,7 +120,7 @@ class InlineConverter
                        $obj = $this->get_converter($match);
                        if ($obj->set($match,$page) !== FALSE)
                        {
-                               $arr[] = $obj; // copy
+                               $arr[] = $this->get_clone($obj);
                                if ($obj->body != '')
                                {
                                        $arr = array_merge($arr,$this->get_objects($obj->body,$page));
index 85bd003..ad07af0 100644 (file)
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-//  $Id: attach.inc.php,v 1.60 2004/08/15 00:19:35 henoheno Exp $
+//  $Id: attach.inc.php,v 1.61 2004/09/19 14:05:30 henoheno Exp $
 //
 
 /*
@@ -384,7 +384,7 @@ class AttachFile
        function AttachFile($page, $file, $age = 0)
        {
                $this->page = $page;
-               $this->file = basename($file);
+               $this->file = preg_replace('#^.*/#','',$file);
                $this->age  = is_numeric($age) ? $age : 0;
 
                $this->basename = UPLOAD_DIR . encode($page) . '_' . encode($this->file);
index d44408e..be7328c 100644 (file)
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: ref.inc.php,v 1.38 2004/09/01 13:15:16 henoheno Exp $
+// $Id: ref.inc.php,v 1.39 2004/09/19 14:05:30 henoheno Exp $
 //
 
 // UPLOAD_DIR ¤Î¥Ç¡¼¥¿(²èÁü¥Õ¥¡¥¤¥ë¤Î¤ß)¤ËľÀÜ¥¢¥¯¥»¥¹¤µ¤»¤ë
@@ -403,7 +403,7 @@ function plugin_ref_action()
        $page = $vars['page'];
        $file = $vars['src'];
 
-       $ref = UPLOAD_DIR . encode($page) . '_' . encode(basename($file));
+       $ref = UPLOAD_DIR . encode($page) . '_' . encode(preg_replace('#^.*/#','',$file));
        if(! file_exists($ref))
                return array('msg'=>'Attach file not found', 'body'=>$usage);
 
index 3f9dc63..ee565d3 100644 (file)
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: showrss.inc.php,v 1.13 2004/07/31 03:09:20 henoheno Exp $
+// $Id: showrss.inc.php,v 1.14 2004/09/19 14:05:30 henoheno Exp $
 //
 // Modified version by PANDA <panda@arino.jp>
 //
@@ -239,6 +239,7 @@ class ShowRSS_XML
        var $item;
        var $is_item;
        var $tag;
+       var $encoding;
 
        function parse($buf)
        {
@@ -248,7 +249,13 @@ class ShowRSS_XML
                $this->is_item = FALSE;
                $this->tag = '';
 
-               $xml_parser = xml_parser_create();
+               // Ê¸»ú¥³¡¼¥É¸¡½Ð
+               $this->encoding = mb_detect_encoding($buf);
+               if (!in_array(strtolower($this->encoding),array('us-ascii','iso-8859-1','utf-8'))) {
+                       $buf = mb_convert_encoding($buf,'utf-8',$this->encoding);
+                       $this->encoding = 'utf-8';
+               }
+               $xml_parser = xml_parser_create($this->encoding);
                xml_set_element_handler($xml_parser,array(&$this,'start_element'),array(&$this,'end_element'));
                xml_set_character_data_handler($xml_parser,array(&$this,'character_data'));
 
@@ -270,7 +277,7 @@ class ShowRSS_XML
                $str = htmlspecialchars($str);
 
                // Ê¸»ú¥³¡¼¥ÉÊÑ´¹
-               $str = mb_convert_encoding($str, SOURCE_ENCODING, 'auto');
+               $str = mb_convert_encoding($str, SOURCE_ENCODING, $this->encoding);
 
                return trim($str);
        }