OSDN Git Service

BugTrack2/84: Experimental features: PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK
authorhenoheno <henoheno>
Sun, 3 Jul 2005 14:16:23 +0000 (23:16 +0900)
committerhenoheno <henoheno>
Sun, 3 Jul 2005 14:16:23 +0000 (23:16 +0900)
lib/convert_html.php
lib/file.php
lib/plugin.php
pukiwiki.ini.php

index 206267d..46e7d6e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
-// $Id: convert_html.php,v 1.13 2005/06/30 13:20:05 henoheno Exp $
+// $Id: convert_html.php,v 1.14 2005/07/03 14:16:23 henoheno Exp $
 // Copyright (C)
 //   2002-2005 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -137,9 +137,25 @@ function & Factory_Div(& $root, $text)
        $matches = array();
 
        // Seems block plugin?
-       if (preg_match('/^\#([^\(]+)(?:\((.*)\))?/', $text, $matches) &&
-           exist_plugin_convert($matches[1])) {
-               return new Div($matches);
+       if (PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) {
+               // Usual code
+               if (preg_match('/^\#([^\(]+)(?:\((.*)\))?/', $text, $matches) &&
+                   exist_plugin_convert($matches[1])) {
+                       return new Div($matches);
+               }
+       } else {
+               // Hack code
+               if(preg_match('/^#([^\(\{]+)(?:\(([^\r]*)\))?(\{*)/', $text, $matches) &&
+                  exist_plugin_convert($matches[1])) {
+                       $len  = strlen($matches[3]);
+                       $body = array();
+                       if ($len == 0) {
+                               return new Div($matches); // Seems legacy block plugin
+                       } else if (preg_match('/\{{' . $len . '}\s*\r(.*)\r\}{' . $len . '}/', $text, $body)) { 
+                               $matches[2] .= "\r" . $body[1] . "\r";
+                               return new Div($matches); // Seems multiline-enabled block plugin
+                       }
+               }
        }
 
        return new Paragraph($text);
@@ -835,6 +851,22 @@ class Body extends Element
                                continue;
                        }
 
+                       // Multiline-enabled block plugin
+                       if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK &&
+                           preg_match('/^#[^{]+(\{\{+)\s*$/', $line, $matches)) {
+                               $len = strlen($matches[1]);
+                               $line .= "\r"; // Delimiter
+                               while (! empty($lines)) {
+                                       $next_line = preg_replace("/[\r\n]*$/", '', array_shift($lines));
+                                       if (preg_match('/\}{' . $len . '}/', $next_line)) {
+                                               $line .= $next_line;
+                                               break;
+                                       } else {
+                                               $line .= $next_line .= "\r"; // Delimiter
+                                       }
+                               }
+                       }
+
                        // The first character
                        $head = $line{0};
 
index e90c77d..9ad23f9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: file.php,v 1.29 2005/07/03 02:55:54 henoheno Exp $
+// $Id: file.php,v 1.30 2005/07/03 14:16:23 henoheno Exp $
 // Copyright (C)
 //   2002-2005 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -66,13 +66,35 @@ function make_str_rules($source)
        $lines = explode("\n", $source);
        $count = count($lines);
 
-       $matches = array();
+       $modify    = TRUE;
+       $multiline = 0;
+       $matches   = array();
        for ($i = 0; $i < $count; $i++) {
                $line = & $lines[$i]; // Modify directly
 
                // Ignore null string and preformatted texts
                if ($line == '' || $line{0} == ' ' || $line{0} == "\t") continue;
 
+               // Modify this line?
+               if ($modify) {
+                       if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK &&
+                           $multiline == 0 &&
+                           preg_match('/#[^{]*(\{\{+)\s*$/', $line, $matches)) {
+                               // Multiline convert plugin start
+                               $modify    = FALSE;
+                               $multiline = strlen($matches[1]); // Set specific number
+                       }
+               } else {
+                       if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK &&
+                           $multiline != 0 &&
+                           preg_match('/^\}{' . $multiline . '}\s*$/', $line)) {
+                               // Multiline convert plugin end
+                               $modify    = TRUE;
+                               $multiline = 0;
+                       }
+               }
+               if ($modify === FALSE) continue;
+
                // Replace with $str_rules
                foreach ($str_rules as $pattern => $replacement)
                        $line = preg_replace('/' . $pattern . '/', $replacement, $line);
@@ -89,6 +111,11 @@ function make_str_rules($source)
                }
        }
 
+       // Multiline part has no stopper
+       if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK &&
+           $modify === FALSE && $multiline != 0)
+               $lines[] = str_repeat('}', $multiline);
+
        return implode("\n", $lines);
 }
 
index 3f79a1e..2444abc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: plugin.php,v 1.14 2005/06/30 13:20:05 henoheno Exp $
+// $Id: plugin.php,v 1.15 2005/07/03 14:16:23 henoheno Exp $
 // Copyright (C)
 //   2002-2005 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -112,11 +112,23 @@ function do_plugin_convert($name, $args = '')
        if(do_plugin_init($name) === FALSE)
                return '[Plugin init failed: ' . $name . ']';
 
+       if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) {
+               // Multiline plugin?
+               $pos  = strpos($args, "\r"); // "\r" is just a delimiter
+               if ($pos !== FALSE) {
+                       $body = substr($args, $pos + 1);
+                       $args = substr($args, 0, $pos);
+               }
+       }
+
        if ($args === '') {
                $aryargs = array();                 // #plugin()
        } else {
                $aryargs = csv_explode(',', $args); // #plugin(A,B,C,D)
        }
+       if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) {
+               if (isset($body)) $aryargs[] = & $body;     // #plugin(){{body}}
+       }
 
        $_digest = $digest;
        $retvar  = call_user_func_array('plugin_' . $name . '_convert', $aryargs);
index c94286c..e0fd12c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone
-// $Id: pukiwiki.ini.php,v 1.126 2005/06/07 14:37:47 henoheno Exp $
+// $Id: pukiwiki.ini.php,v 1.127 2005/07/03 14:16:23 henoheno Exp $
 // Copyright (C)
 //   2002-2005 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
@@ -42,6 +42,20 @@ if (! defined('PKWK_DISABLE_INLINE_IMAGE_FROM_URI'))
 define('PKWK_QUERY_STRING_MAX', 640); // Bytes, 0 = OFF
 
 /////////////////////////////////////////////////
+// Experimental features
+
+// Multiline plugin hack (See BugTrack2/84)
+// EXAMPLE(with a known BUG):
+//   #plugin(args1,args2,...,argsN){{
+//   argsN+1
+//   argsN+1
+//   #memo(foo)
+//   argsN+1
+//   }}
+//   #memo(This makes '#memo(foo)' to this)
+define('PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK', 1); // 1 = Disabled
+
+/////////////////////////////////////////////////
 // Language / Encoding settings
 
 // LANG - Internal content encoding ('en', 'ja', or ...)