OSDN Git Service

BugTrack/480: ディレクトリの設定をpukiwiki.ini.phpに移動
[pukiwiki/pukiwiki.git] / plugin / paint.inc.php
index 5062abf..60812ea 100644 (file)
@@ -1,7 +1,11 @@
 <?php
-/*
-Last-Update:2002-10-30 rev.20
+/////////////////////////////////////////////////
+// PukiWiki - Yet another WikiWikiWeb clone.
+//
+// $Id: paint.inc.php,v 1.13 2003/11/05 10:40:48 arino Exp $
+//
 
+/*
 *¥×¥é¥°¥¤¥ó paint
 ³¨¤òÉÁ¤¯
 
@@ -14,9 +18,6 @@ Last-Update:2002-10-30 rev.20
 
 */
 
-// upload dir(must set end of /) attach.inc.php¤È¹ç¤ï¤»¤ë
-define('PAINT_UPLOAD_DIR','./attach/');
-//
 // ÁÞÆþ¤¹¤ë°ÌÃÖ 1:Íó¤ÎÁ° 0:Íó¤Î¸å
 define('PAINT_INSERT_INS',0);
 //
@@ -33,32 +34,17 @@ define('PAINT_APPLET_WIDTH',800);
 define('PAINT_APPLET_HEIGHT',300);
 //
 //¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È
-define('PAINT_FORMAT_NAME','[[%s]]');
-define('PAINT_FORMAT_MSG','%s');
-define('PAINT_FORMAT_DATE','SIZE(10){%s}');
+define('PAINT_NAME_FORMAT','[[$name]]');
+define('PAINT_MSG_FORMAT','$msg');
+define('PAINT_NOW_FORMAT','&new{$now};');
 //¥á¥Ã¥»¡¼¥¸¤¬¤¢¤ë¾ì¹ç
-define('PAINT_FORMAT',"\x08MSG\x08 -- \x08NAME\x08 \x08DATE\x08");
+define('PAINT_FORMAT',"\x08MSG\x08 -- \x08NAME\x08 \x08NOW\x08");
 //¥á¥Ã¥»¡¼¥¸¤¬¤Ê¤¤¾ì¹ç
-define('PAINT_FORMAT_NOMSG',"\x08NAME\x08 \x08DATE\x08"); 
+define('PAINT_FORMAT_NOMSG',"\x08NAME\x08 \x08NOW\x08"); 
 
-function plugin_paint_init()
-{
-       $messages = array('_paint_messages'=>array(
-               'field_name'    => '¤ªÌ¾Á°',
-               'field_filename'=> '¥Õ¥¡¥¤¥ë̾',
-               'field_comment' => '¥³¥á¥ó¥È',
-               'btn_submit'    => 'paint',
-               'msg_max'       => '(ºÇÂç %d x %d)',
-               'msg_title'     => 'Paint and Attach to $1',
-               'msg_title_collided' => '$1 ¤Ç¡Ú¹¹¿·¤Î¾×ÆÍ¡Û¤¬µ¯¤­¤Þ¤·¤¿',
-               'msg_collided'  => '¤¢¤Ê¤¿¤¬²èÁü¤òÊÔ½¸¤·¤Æ¤¤¤ë´Ö¤Ë¡¢Â¾¤Î¿Í¤¬Æ±¤¸¥Ú¡¼¥¸¤ò¹¹¿·¤·¤Æ¤·¤Þ¤Ã¤¿¤è¤¦¤Ç¤¹¡£<br />
-²èÁü¤È¥³¥á¥ó¥È¤òÄɲä·¤Þ¤·¤¿¤¬¡¢°ã¤¦°ÌÃÖ¤ËÁÞÆþ¤µ¤ì¤Æ¤¤¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¡£<br />',
-       ));
-  set_plugin_messages($messages);
-}
 function plugin_paint_action()
 {
-       global $script,$vars,$HTTP_POST_FILES;
+       global $script,$vars;
        global $_paint_messages;
        global $html_transitional;
        
@@ -66,35 +52,44 @@ function plugin_paint_action()
        $retval['msg'] = $_paint_messages['msg_title'];
        $retval['body'] = '';
        
-       if (array_key_exists('attach_file',$HTTP_POST_FILES) and is_uploaded_file($HTTP_POST_FILES['attach_file']['tmp_name'])) {
+       if (array_key_exists('attach_file',$_FILES)
+               and array_key_exists('refer',$vars))
+       {
+               $file = $_FILES['attach_file'];
                //BBSPaiter.jar¤Ï¡¢shift-jis¤ÇÆâÍƤòÁ÷¤Ã¤Æ¤¯¤ë¡£ÌÌÅݤʤΤǥڡ¼¥¸Ì¾¤Ï¥¨¥ó¥³¡¼¥É¤·¤Æ¤«¤éÁ÷¿®¤µ¤»¤ë¤è¤¦¤Ë¤·¤¿¡£
                $vars['page'] = $vars['refer'] = decode($vars['refer']);
                
                $filename = $vars['filename'];
-               if (function_exists('mb_convert_encoding'))
-                       $filename = mb_convert_encoding($filename,ENCODING,'auto');
+               $filename = mb_convert_encoding($filename,SOURCE_ENCODING,'auto');
                
                //¥Õ¥¡¥¤¥ë̾ÃÖ´¹
-               $attachname = preg_replace('/^[^\.]+/', $filename, $HTTP_POST_FILES['attach_file']['name']);
+               $attachname = preg_replace('/^[^\.]+/',$filename,$file['name']);
                //¤¹¤Ç¤Ë¸ºß¤·¤¿¾ì¹ç¡¢ ¥Õ¥¡¥¤¥ë̾¤Ë'_0','_1',...¤òÉÕ¤±¤Æ²óÈò(¸È©)
                $count = '_0';
-               while (file_exists(PAINT_UPLOAD_DIR.encode($vars['refer']).'_'.encode($attachname))) {
-                       $attachname = preg_replace('/^[^\.]+/', $filename.$count++, $HTTP_POST_FILES['attach_file']['name']);
+               while (file_exists(UPLOAD_DIR.encode($vars['refer']).'_'.encode($attachname)))
+               {
+                       $attachname = preg_replace('/^[^\.]+/',$filename.$count++,$file['name']);
                }
                
-               $HTTP_POST_FILES['attach_file']['name'] = $attachname;
+               $file['name'] = $attachname;
                
-               $retval = do_plugin_action('attach');
-               $retval = insert_ref($HTTP_POST_FILES['attach_file']['name']);
-       }
-       else {
-               $message = '';
-               if (!function_exists('mb_convert_encoding')) {
-                       $message = 'cannot use KANJI in filename.';
+               if (!exist_plugin('attach') or !function_exists('attach_upload'))
+               {
+                       return array('msg'=>'attach.inc.php not found or not correct version.');
                }
                
+               $retval = attach_upload($file,$vars['refer'],TRUE);
+               if ($retval['result'] == TRUE)
+               {
+                       $retval = paint_insert_ref($file['name']);
+               }
+       }
+       else
+       {
+               $message = '';
                $r_refer = $s_refer = '';
-               if (array_key_exists('refer',$vars)) {
+               if (array_key_exists('refer',$vars))
+               {
                        $r_refer = rawurlencode($vars['refer']);
                        $s_refer = htmlspecialchars($vars['refer']);
                }
@@ -103,6 +98,17 @@ function plugin_paint_action()
                $w = PAINT_APPLET_WIDTH;
                $h = PAINT_APPLET_HEIGHT;
                
+               //¥¦¥¤¥ó¥É¥¦¥â¡¼¥É :)
+               if ($w < 50 and $h < 50)
+               {
+                       $w = $h = 0;
+                       $retval['msg'] = '';
+                       $vars['page'] = $vars['refer'];
+                       $vars['cmd'] = 'read';
+                       $retval['body'] = convert_html(get_source($vars['refer']));
+                       $link = '';
+               }
+               
                //XSSÀȼåÀ­ÌäÂê - ³°Éô¤«¤éÍ褿ÊÑ¿ô¤ò¥¨¥¹¥±¡¼¥×
                $width = empty($vars['width']) ? PAINT_DEFAULT_WIDTH : $vars['width'];
                $height = empty($vars['height']) ? PAINT_DEFAULT_HEIGHT : $vars['height'];
@@ -113,14 +119,16 @@ function plugin_paint_action()
                $f_no = (array_key_exists('paint_no',$vars) and is_numeric($vars['paint_no'])) ?
                        $vars['paint_no'] + 0 : 0;
                
-               if ($f_w > PAINT_MAX_WIDTH) {
+               if ($f_w > PAINT_MAX_WIDTH)
+               {
                        $f_w = PAINT_MAX_WIDTH;
                }
-               if ($f_h > PAINT_MAX_HEIGHT) {
+               if ($f_h > PAINT_MAX_HEIGHT)
+               {
                        $f_h = PAINT_MAX_HEIGHT;
                }
                
-               $retval['body'] = <<<EOD
+               $retval['body'] .= <<<EOD
  <div>
  $link
  $message
@@ -141,6 +149,7 @@ function plugin_paint_action()
  </applet>
  </div>
 EOD;
+               // XHTML 1.0 Transitional
                $html_transitional = TRUE;
        }
        return $retval;
@@ -149,24 +158,31 @@ function plugin_paint_convert()
 {
        global $script,$vars,$digest;
        global $_paint_messages;
-       static $paint_no = 0;
+       static $numbers = array();
+       
+       if (!array_key_exists($vars['page'],$numbers))
+       {
+               $numbers[$vars['page']] = 0;
+       }
+       $paint_no = $numbers[$vars['page']]++;
        
        //Ìá¤êÃÍ
        $ret = '';
        
-       $paint_no++;
-       
        //ʸ»úÎó¤ò¼èÆÀ
        $width = $height = 0;
        $args = func_get_args();
-       if (count($args) >= 2) {
+       if (count($args) >= 2)
+       {
                $width = array_shift($args);
                $height = array_shift($args);
        }
-       if (!is_numeric($width) or $width <= 0) {
+       if (!is_numeric($width) or $width <= 0)
+       {
                $width = PAINT_DEFAULT_WIDTH;
        }
-       if (!is_numeric($height) or $height <= 0) {
+       if (!is_numeric($height) or $height <= 0)
+       {
                $height = PAINT_DEFAULT_HEIGHT;
        }
        
@@ -182,9 +198,9 @@ function plugin_paint_convert()
   <input type="hidden" name="digest" value="$digest" />
   <input type="hidden" name="plugin" value="paint" />
   <input type="hidden" name="refer" value="$f_page" />
-  <input type="text" name="width" size="3" value="$width" accesskey="w" />
+  <input type="text" name="width" size="3" value="$width" />
   x
-  <input type="text" name="height" size="3" value="$height" accesskey="h" />
+  <input type="text" name="height" size="3" value="$height" />
   $max
   <input type="submit" value="{$_paint_messages['btn_submit']}" />
   </div>
@@ -192,31 +208,27 @@ function plugin_paint_convert()
 EOD;
        return $ret;
 }
-function insert_ref($filename)
+function paint_insert_ref($filename)
 {
        global $script,$vars,$now,$do_backup;
-       global $_paint_messages;
+       global $_paint_messages,$_no_name;
        
        $ret['msg'] = $_paint_messages['msg_title'];
+
+       $msg = mb_convert_encoding(rtrim($vars['msg']),SOURCE_ENCODING,'auto');
+       $name = mb_convert_encoding($vars['yourname'],SOURCE_ENCODING,'auto');
        
-       $msg = sprintf(PAINT_FORMAT_MSG, rtrim($vars['msg']));
-       
-       if ($vars['yourname'] != '') {
-               $name = sprintf(PAINT_FORMAT_NAME, $vars['yourname']);
-       }
-       $date = sprintf(PAINT_FORMAT_DATE, $now);
-       
-       if (function_exists('mb_convert_encoding')) {
-               $msg = mb_convert_encoding($msg, ENCODING, 'auto');
-               $name = mb_convert_encoding($name, ENCODING, 'auto');
-       }
+       $msg  = str_replace('$msg',$msg,PAINT_MSG_FORMAT);
+       $name = ($name == '') ? $_no_name : $vars['yourname'];
+       $name = ($name == '') ? '' : str_replace('$name',$name,PAINT_NAME_FORMAT);
+       $now  = str_replace('$now',$now,PAINT_NOW_FORMAT);
        
        $msg = trim($msg);
        $msg = ($msg == '') ?
                PAINT_FORMAT_NOMSG :
                str_replace("\x08MSG\x08", $msg, PAINT_FORMAT);
        $msg = str_replace("\x08NAME\x08",$name, $msg);
-       $msg = str_replace("\x08DATE\x08",$date, $msg);
+       $msg = str_replace("\x08NOW\x08",$now, $msg);
        //¥Ö¥í¥Ã¥¯¤Ë¿©¤ï¤ì¤Ê¤¤¤è¤¦¤Ë¡¢#img¤ÎľÁ°¤Ë\n¤ò2¸Ä½ñ¤¤¤Æ¤ª¤¯¡£
        $msg = "#ref($filename,wrap,around)\n".trim($msg)."\n\n#img(,clear)\n";
        
@@ -225,19 +237,27 @@ function insert_ref($filename)
        $paint_no = 0; //'#paint'¤Î½Ð¸½²ó¿ô
        foreach ($postdata_old as $line)
        {
-               if (!PAINT_INSERT_INS) {
+               if (!PAINT_INSERT_INS)
+               {
                        $postdata .= $line;
                }
-               if (preg_match('/^#paint/',$line) and (++$paint_no == $vars['paint_no'])) {
+               if (preg_match('/^#paint/',$line))
+               {
+                       if ($paint_no == $vars['paint_no'])
+                       {
                                $postdata .= $msg;
+                       }
+                       $paint_no++;
                }
-               if (PAINT_INSERT_INS) {
+               if (PAINT_INSERT_INS)
+               {
                        $postdata .= $line;
                }
        }
        
        // ¹¹¿·¤Î¾×Æͤò¸¡½Ð
-       if (md5(join('',$postdata_old)) != $vars['digest']) {
+       if (md5(join('',$postdata_old)) != $vars['digest'])
+       {
                $ret['msg'] = $_paint_messages['msg_title_collided'];
                $ret['body'] = $_paint_messages['msg_collided'];
        }