OSDN Git Service

Cleanup. Shrink. Rename defines
authorhenoheno <henoheno>
Tue, 23 Nov 2004 01:19:59 +0000 (10:19 +0900)
committerhenoheno <henoheno>
Tue, 23 Nov 2004 01:19:59 +0000 (10:19 +0900)
plugin/comment.inc.php

index ab8b278..75d1ece 100644 (file)
@@ -2,61 +2,47 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: comment.inc.php,v 1.24 2004/10/09 08:01:58 henoheno Exp $
+// $Id: comment.inc.php,v 1.25 2004/11/23 01:19:59 henoheno Exp $
 //
+// Comment plugin
 
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤Î̾Á°¥Æ¥­¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
-define('COMMENT_NAME_COLS',15);
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤Î¥Æ¥­¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
-define('COMMENT_COLS',70);
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È
-define('COMMENT_NAME_FORMAT','[[$name]]');
-define('COMMENT_MSG_FORMAT','$msg');
-define('COMMENT_NOW_FORMAT','&new{$now};');
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È(¥³¥á¥ó¥ÈÆâÍÆ)
-define('COMMENT_FORMAT',"\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤òÁÞÆþ¤¹¤ë°ÌÃÖ 1:Íó¤ÎÁ° 0:Íó¤Î¸å
-define('COMMENT_INS','1');
-/////////////////////////////////////////////////
-// ¥³¥á¥ó¥È¤¬Åê¹Æ¤µ¤ì¤¿¾ì¹ç¡¢ÆâÍƤò¥á¡¼¥ë¤ÇÁ÷¤ëÀè
-//define('COMMENT_MAIL',FALSE);
+define('PLUGIN_COMMENT_DIRECTION_DEFAULT', '1'); // 1: above 0: below
+define('PLUGIN_COMMENT_SIZE_MSG',  70);
+define('PLUGIN_COMMENT_SIZE_NAME', 15);
 
+// ----
+define('PLUGIN_COMMENT_FORMAT_MSG',  '$msg');
+define('PLUGIN_COMMENT_FORMAT_NAME', '[[$name]]');
+define('PLUGIN_COMMENT_FORMAT_NOW',  '&new{$now};');
+define('PLUGIN_COMMENT_FORMAT_STRING', "\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
 function plugin_comment_action()
 {
-       global $script, $vars, $now;
-       global $_title_updated, $_no_name;
+       global $script, $vars, $now, $_title_updated, $_no_name;
        global $_msg_comment_collided, $_title_comment_collided;
 
-       if (! isset($vars['msg']) || $vars['msg'] == '') {
+       if (! isset($vars['msg']) || $vars['msg'] == '')
                return array('msg'=>'', 'body'=>'');
-       } else {
-               $vars['msg'] = preg_replace("/\n/", '', $vars['msg']);
-       }
+
+       $vars['msg'] = preg_replace("/\n/", '', $vars['msg']);
 
        $head = '';
        $match = array();
-       if (preg_match('/^(-{1,2})(.*)/', $vars['msg'], $match))
-       {
-               $head = $match[1];
+       if (preg_match('/^(-{1,2})(.*)/', $vars['msg'], $match)) {
+               $head        = $match[1];
                $vars['msg'] = $match[2];
        }
        unset($match);
 
-       $_msg  = str_replace('$msg', $vars['msg'], COMMENT_MSG_FORMAT);
+       $_msg  = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
 
        $_name = (! isset($vars['name']) || $vars['name'] == '') ? $_no_name : $vars['name'];
-       $_name = ($_name == '') ? '' : str_replace('$name', $_name, COMMENT_NAME_FORMAT);
+       $_name = ($_name == '') ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
 
-       $_now  = ($vars['nodate'] == '1') ? '' : str_replace('$now', $now, COMMENT_NOW_FORMAT);
+       $_now  = ($vars['nodate'] == '1') ? '' : str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
 
-       $comment = str_replace("\x08MSG\x08", $_msg, COMMENT_FORMAT);
-       $comment = str_replace("\x08NAME\x08",$_name,$comment);
-       $comment = str_replace("\x08NOW\x08", $_now, $comment);
+       $comment = str_replace("\x08MSG\x08",  $_msg,  PLUGIN_COMMENT_FORMAT_STRING);
+       $comment = str_replace("\x08NAME\x08", $_name, $comment);
+       $comment = str_replace("\x08NOW\x08",  $_now,  $comment);
        $comment = $head . $comment;
 
        $postdata = '';
@@ -64,37 +50,25 @@ function plugin_comment_action()
        $comment_no = 0;
        $comment_ins = ($vars['above'] == '1');
 
-       foreach ($postdata_old as $line)
-       {
-               if (!$comment_ins)
-               {
-                       $postdata .= $line;
-               }
-               if (preg_match('/^#comment/i', $line) and $comment_no++ == $vars['comment_no'])
-               {
-                       $postdata = rtrim($postdata)."\n-$comment\n";
-                       if ($comment_ins)
-                       {
-                               $postdata .= "\n";
-                       }
-               }
-               if ($comment_ins)
-               {
-                       $postdata .= $line;
+       foreach ($postdata_old as $line) {
+               if (! $comment_ins) $postdata .= $line;
+               if (preg_match('/^#comment/i', $line) && $comment_no++ == $vars['comment_no']) {
+                       $postdata = rtrim($postdata) . "\n-$comment\n";
+                       if ($comment_ins) $postdata .= "\n";
                }
+               if ($comment_ins) $postdata .= $line;
        }
 
        $title = $_title_updated;
        $body = '';
-       if (md5(@join('',get_source($vars['refer']))) != $vars['digest'])
-       {
+       if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
                $title = $_title_comment_collided;
-               $body = $_msg_comment_collided . make_pagelink($vars['refer']);
+               $body  = $_msg_comment_collided . make_pagelink($vars['refer']);
        }
 
        page_write($vars['refer'], $postdata);
 
-       $retvars['msg'] = $title;
+       $retvars['msg']  = $title;
        $retvars['body'] = $body;
 
        $vars['page'] = $vars['refer'];
@@ -108,24 +82,24 @@ function plugin_comment_convert()
        global $_btn_comment, $_btn_name, $_msg_comment;
        static $numbers = array();
 
-       if (! isset($numbers[$vars['page']])) {
-               $numbers[$vars['page']] = 0;
-       }
+       if (! isset($numbers[$vars['page']])) $numbers[$vars['page']] = 0;
        $comment_no = $numbers[$vars['page']]++;
 
        $options = func_num_args() ? func_get_args() : array();
 
-       if (in_array('noname',$options)) {
+       if (in_array('noname', $options)) {
                $nametags = $_msg_comment;
        } else {
-               $nametags = $_btn_name . '<input type="text" name="name" size="' . COMMENT_NAME_COLS . "\" />\n";
+               $nametags = $_btn_name .
+                       '<input type="text" name="name" size="' . PLUGIN_COMMENT_SIZE_NAME . "\" />\n";
        }
 
        $nodate = in_array('nodate', $options) ? '1' : '0';
-       $above = in_array('above', $options) ? '1' : (in_array('below', $options) ? '0' : COMMENT_INS);
+       $above  = in_array('above',  $options) ? '1' :
+               (in_array('below', $options) ? '0' : PLUGIN_COMMENT_DIRECTION_DEFAULT);
 
        $s_page = htmlspecialchars($vars['page']);
-       $comment_cols = COMMENT_COLS;
+       static $comment_cols = PLUGIN_COMMENT_SIZE_MSG;
        $string = <<<EOD
 <br />
 <form action="$script" method="post">