OSDN Git Service

BugTrack/425: #contentsや#relatedを「本当のブロックプラグイン」に近い動作に
authorarino <arino>
Tue, 29 Jul 2003 09:57:14 +0000 (18:57 +0900)
committerarino <arino>
Tue, 29 Jul 2003 09:57:14 +0000 (18:57 +0900)
convert_html.php
html.php
init.php

index 51e16e9..e66ecc9 100644 (file)
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: convert_html.php,v 1.50 2003/07/27 13:40:41 arino Exp $
+// $Id: convert_html.php,v 1.51 2003/07/29 09:57:13 arino Exp $
 //
 function convert_html($lines)
 {
@@ -807,12 +807,6 @@ class Body extends Block
                $this->contents_last =& $this->contents_last->add(new Contents_UList($text,$level,$id));
                return array($text.$anchor,$this->count > 1 ? $top : '',$id);
        }
-       function getContents()
-       {
-               $contents  = "<a id=\"contents_{$this->id}\"></a>";
-               $contents .= $this->contents->toString();
-               return "<div class=\"contents\">\n$contents</div>\n";
-       }
        function &insert(&$obj)
        {
                if (is_a($obj,'Inline')) {
@@ -827,14 +821,41 @@ class Body extends Block
                $text = parent::toString();
                
                // #contents
-               $text = preg_replace('/<p[^>]*>#contents<\/p>/',$this->getContents(),$text);
+               $text = preg_replace_callback('/(<p[^>]*>)<del>#contents<\/del>(.*)(<\/p>)/',
+                       array(&$this,'replace_contents'),$text);
                
                // ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸
                // <p>¤Î¤È¤­¤Ï¹ÔƬ¤«¤é¡¢<del>¤Î¤È¤­¤Ï¾¤ÎÍ×ÁǤλÒÍ×ÁǤȤ·¤Æ¸ºß
-               $text = preg_replace('/<p><del>#related<\/del><\/p>/',make_related($vars['page'],'p'),$text);
+               $text = preg_replace_callback('/(<p[^>]*>)<del>#related<\/del>(.*)(<\/p>)/',
+                       array(&$this,'replace_related'),$text);
                $text = preg_replace('/<del>#related<\/del>/',make_related($vars['page'],'del'),$text);
                return $text;
        }
+       function replace_contents($arr)
+       {
+               static $contents = NULL;
+               
+               if (is_null($contents))
+               {
+                       $contents  = "<div class=\"contents\">\n";
+                       $contents .= "<a id=\"contents_{$this->id}\"></a>";
+                       $contents .= $this->contents->toString();
+                       $contents .= "</div>\n";
+               }
+               array_shift($arr);
+               return ($arr[1] != '') ? $contents.join('',$arr) : $contents;
+       }
+       function replace_related($arr)
+       {
+               static $related = NULL;
+               
+               if (is_null($related))
+               {
+                       $related = make_related($vars['page'],'p');
+               }
+               array_shift($arr);
+               return ($arr[1] != '') ? $related.join('',$arr) : $related;
+       }
        function block(&$lines,$start,$end,$class)
        {
                if (rtrim($lines[0]) != $start)
index ff1df63..5ab2cac 100644 (file)
--- a/html.php
+++ b/html.php
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: html.php,v 1.90 2003/07/14 04:27:07 arino Exp $
+// $Id: html.php,v 1.91 2003/07/29 09:57:14 arino Exp $
 //
 
 // ËÜʸ¤ò½ÐÎÏ
@@ -240,6 +240,11 @@ function make_related($page,$tag='')
                        "<a href=\"$script?$r_page\">$s_page</a>$passage";
        }
        
+       if (count($_links) == 0)
+       {
+               return '';
+       }
+       
        if ($tag == 'p') // ¹ÔƬ¤«¤é
        {
                $margin = $_ul_left_margin + $_ul_margin;
index e3362d0..c18cced 100644 (file)
--- a/init.php
+++ b/init.php
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: init.php,v 1.58 2003/07/06 15:10:27 arino Exp $
+// $Id: init.php,v 1.59 2003/07/29 09:57:14 arino Exp $
 //
 
 /////////////////////////////////////////////////
@@ -280,6 +280,7 @@ $entity_pattern = trim(join('',file(CACHE_DIR.'entities.dat')));
 $line_rules = array_merge(array(
        '&amp;(#[0-9]+|#x[0-9a-f]+|'.$entity_pattern.');'=>'&$1;',
        "\r"=>"<br />\n", /* ¹ÔËö¤Ë¥Á¥ë¥À¤Ï²þ¹Ô */
-       '#related'=>'<del>#related</del>'
+       '#related$'=>'<del>#related</del>',
+       '^#contents$'=>'<del>#contents</del>'
 ),$line_rules);
 ?>