--- pukiwiki/plugin/attach.inc.php.orig 2004-03-18 19:02:13.000000000 +0900 +++ pukiwiki/plugin/attach.inc.php 2004-09-20 15:07:19.000000000 +0900 @@ -2,7 +2,7 @@ ///////////////////////////////////////////////// // PukiWiki - Yet another WikiWikiWeb clone. // -// $Id: attach.inc.php,v 1.39 2004/03/18 10:02:13 arino Exp $ +// $Id: attach.inc.php,v 1.39 2004/09/20 14:02:26 diabah Exp $ // /* @@ -10,6 +10,8 @@ changed by Y.MASUI http://masui.net/pukiwiki/ modified by PANDA http://home.arino.jp/ + modified by ARAI + modified by DIABAH http://cubic9.com/ */ // max file size for upload on PHP(PHP default 2MB) @@ -33,6 +35,15 @@ define('ATTACH_FILE_MODE',0644); //define('ATTACH_FILE_MODE',0604); // for XREA.COM +// ファイルオープンの場合、直リンを弾く +define('OPEN_AVOID_DIRECT', TRUE); + +// サムネイルのデフォルトクオリティ +define('THUMB_DEFAULT_QUAL', 40); + +// サムネイルの変換方法 (TRUE:全て滑らかなJPEGに変換, FALSE:JPEGは滑らかなJPEGにその他はPNGに変換) +define('THUMB_RESAMPLE_ALL', TRUE); // TRUE or FALSE + // file icon image if (!defined('FILE_ICON')) { @@ -42,6 +53,16 @@ // mime-typeを記述したページ define('ATTACH_CONFIG_PAGE_MIME','plugin/attach/mime-type'); +// tar +define('TAR_HDR_LEN',512); // ヘッダの大きさ +define('TAR_BLK_LEN',512); // 単位ブロック長さ +define('TAR_HDR_NAME_OFFSET',0); // ファイル名のオフセット +define('TAR_HDR_NAME_LEN',100); // ファイル名の最大長さ +define('TAR_HDR_SIZE_OFFSET',124); // サイズへのオフセット +define('TAR_HDR_SIZE_LEN',12); // サイズの長さ +define('TAR_HDR_TYPE_OFFSET',156); // ファイルタイプへのオフセット +define('TAR_HDR_TYPE_LEN',1); // ファイルタイプの長さ + //-------- convert function plugin_attach_convert() { @@ -88,6 +109,12 @@ $vars['pcmd'] = 'open'; $vars['file'] = $vars['openfile']; } + // backward compatible + if (array_key_exists('thumb',$vars)) + { + $vars['pcmd'] = 'thumb'; + $vars['file'] = $vars['thumb']; + } if (array_key_exists('delfile',$vars)) { $vars['pcmd'] = 'delete'; @@ -100,7 +127,7 @@ // Authentication if (array_key_exists('refer',$vars) and is_pagename($vars['refer'])) { - $read_cmds = array('info','open','list'); + $read_cmds = array('info','open','list','thumb'); in_array($pcmd,$read_cmds) ? check_readable($vars['refer']) : check_editable($vars['refer']); } @@ -117,6 +144,7 @@ case 'info': return attach_info(); case 'delete': return attach_delete(); case 'open': return attach_open(); + case 'thumb': return attach_thumb(); case 'list': return attach_list(); case 'freeze': return attach_freeze(TRUE); case 'unfreeze':return attach_freeze(FALSE); @@ -148,7 +176,7 @@ { // $pass=NULL : パスワードが指定されていない // $pass=TRUE : アップロード許可 - global $adminpass,$_attach_messages; + global $adminpass,$_attach_messages,$post; if ($file['tmp_name'] == '' or !is_uploaded_file($file['tmp_name'])) { @@ -167,16 +195,52 @@ { return array('result'=>FALSE,'msg'=>$_attach_messages['err_adminpass']); } + + if ( strcasecmp(substr($file['name'],-4),".tar") == 0 && $post['untar_mode'] == "on" ) { + // UploadされたTarアーカイブを展開添付する + + // Tarファイル展開 + $etars = untar( $file['tmp_name'], UPLOAD_DIR); + + // 展開されたファイルを全てアップロードファイルとして追加 + foreach ( $etars as $efile ) { + $res = do_upload( $page, + mb_convert_encoding($efile['extname'], SOURCE_ENCODING,"auto"), + $efile['tmpname']); + if ( ! $res['result'] ) { + unlink( $efile['tmpname']); + } + } + + // 最後の返り値でreturn + return $res; + } else { + // 通常の単一ファイル添付処理 + return do_upload($page,$file['name'],$file['tmp_name']); + } +} + +function do_upload($page,$fname,$tmpname) +{ + global $_attach_messages; - $obj = &new AttachFile($page,$file['name']); + $obj = &new AttachFile($page,$fname); if ($obj->exist) { return array('result'=>FALSE,'msg'=>$_attach_messages['err_exists']); } - if (move_uploaded_file($file['tmp_name'],$obj->filename)) - { - chmod($obj->filename,ATTACH_FILE_MODE); + + if ( is_uploaded_file($tmpname) ) { + if (move_uploaded_file($tmpname,$obj->filename)) + { + chmod($obj->filename,ATTACH_FILE_MODE); + } + } else { + if (rename($tmpname,$obj->filename)) + { + chmod($obj->filename,ATTACH_FILE_MODE); + } } if (is_page($page)) @@ -248,10 +312,40 @@ { $$var = array_key_exists($var,$vars) ? $vars[$var] : ''; } + + if ( OPEN_AVOID_DIRECT && !strstr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST'])) { + header("Location: http://" . $_SERVER['HTTP_HOST'] . + $_SERVER['SCRIPT_NAME'] ); + exit; + } $obj = &new AttachFile($refer,$file,$age); return $obj->getstatus() ? $obj->open() : array('msg'=>$_attach_messages['err_notfound']); } +//イメージサムネイル出力 +function attach_thumb() +{ + global $vars,$_attach_messages; + + foreach (array('refer','file','age') as $var) + { + $$var = array_key_exists($var,$vars) ? $vars[$var] : ''; + } + + if ( OPEN_AVOID_DIRECT && !strstr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST'])) { + header("Location: http://" . $_SERVER['HTTP_HOST'] . + $_SERVER['SCRIPT_NAME'] ); + exit; + } + + $obj = &new AttachFile($refer,$file,$age); + + $dstw = $vars['width'] ? $vars['width'] : 0; + $dsth = $vars['height'] ? $vars['height']: 0; + $qual = $vars['qual'] ? $vars['qual']: THUMB_DEFAULT_QUAL; + + return $obj->getstatus() ? $obj->thumb($dstw,$dsth,$qual) : array('msg'=>$_attach_messages['err_notfound']); +} //一覧取得 function attach_list() { @@ -376,6 +470,7 @@ {$_attach_messages['msg_file']}: $pass + ({$_attach_messages['untar_mode']}:) EOD; @@ -633,6 +728,108 @@ @readfile($this->filename); exit; } + function thumb($dw,$dh,$qual) + { + global $vars; + + // for japanese (???) + $filename = htmlspecialchars(mb_convert_encoding($this->file,'SJIS','auto')); + + $thumbname = CACHE_DIR.encode($vars['refer']).'_'.$dw.'x'.$dh.'_'.$vars['thumb'].'.thumb'; + + // サムネイルを出力 + if ((is_readable($thumbname)) && (filemtime($thumbname) > filemtime($this->filename))) { + if ( THUMB_RESAMPLE_ALL ) { + $thumb = imagecreatefromjpeg($thumbname); + header('Content-Type: image/jpeg'); + imagejpeg( $thumb ); + } else { + switch ( $type = strtolower(substr($thumbname,strrpos(substr($thumbname,0,-6),'.')+1,-6))) { + case 'jpeg': + case 'jpg': + $thumb = imagecreatefromjpeg($thumbname); + header('Content-Type: image/jpeg'); + imagejpeg( $thumb ); + break; + default: + $thumb = imagecreatefrompng($thumbname); + header('Content-Type: image/png'); + imagepng( $thumb ); + break; + } + } + exit; + } + + switch ( $type = strtolower(substr($filename,strrpos($filename,'.')+1))) { + case 'jpeg': + case 'jpg': + $src = imagecreatefromjpeg($this->filename); + break; + case 'png': + $src = imagecreatefrompng($this->filename); + break; + case 'bmp': + $src = imagecreatefromwbmp($this->filename); + break; + case 'gif': + $src = imagecreatefromgif($this->filename); + break; + default: + exit; + } + + if ( !$src ) { + exit; + } + + $sw = imagesx( $src); $sh = imagesy( $src); + + if ( $dw == 0 && $dh > 0 ) { + $dw = (int)($sw*$dh/$sh); + } + if ( $dh == 0 && $dw > 0 ) { + $dh = (int)($sh*$dw/$sw); + } + if ( $dw == 0 && $dh == 0 ) { + $dw = $sw; + $dh = $sh; + } + $dst = imagecreatetruecolor($dw,$dh); + + if ( !$qual ) { + $qual = THUMB_DEFAULT_QUAL; + } + + switch ( $type ) { + case 'jpeg': + case 'jpg': + imagecopyresampled( $dst, $src, 0, 0, 0, 0, $dw, $dh, $sw, $sh); + imageinterlace( $dst, 1); + header('Content-Type: image/jpeg'); + imagejpeg( $dst, "", $qual); + imagejpeg( $dst, $thumbname, $qual); + break; + case 'png': + case 'bmp': + case 'gif': + if ( THUMB_RESAMPLE_ALL ) { + imagecopyresampled( $dst, $src, 0, 0, 0, 0, $dw, $dh, $sw, $sh); + imageinterlace( $dst, 1); + header('Content-Type: image/jpeg'); + imagejpeg( $dst, "", $qual); + imagejpeg( $dst, $thumbname, $qual); + } else { + imagecopyresized( $dst, $src, 0, 0, 0, 0, $dw, $dh, $sw, $sh); + imageinterlace( $dst, 1); + header('Content-Type: image/png'); + imagepng( $dst ); + imagepng( $dst, $thumbname); + } + break; + } + exit; + } } // ファイルコンテナ @@ -763,4 +960,50 @@ } } + +// $tname: tarファイルネーム +// $odir : 展開先ディレクトリ +// 返り値: 特に無し。大したチェックはせず、やるだけやって後は野となれ山となれ +function untar( $tname, $odir) +{ + if (!( $fp = fopen( $tname, "rb") ) ) { + return; + } + + unset($files); + $cnt = 0; + while ( strlen($buff=fread( $fp,TAR_HDR_LEN)) == TAR_HDR_LEN ) { + for ( $i=TAR_HDR_NAME_OFFSET,$name=""; + $buff[$i] != "\0" && $i --- pukiwiki/plugin/ref.inc.php.orig Sun Feb 29 23:29:28 2004 +++ pukiwiki/plugin/ref.inc.php Fri Jul 2 23:53:10 2004 @@ -2,7 +2,7 @@ ///////////////////////////////////////////////// // PukiWiki - Yet another WikiWikiWeb clone. // -// $Id: ref.inc.php,v 1.21 2004/02/29 14:29:28 arino Exp $ +// $Id: ref.inc.php,v 1.10 2004/07/02 14:28:32 m-arai Exp $ // /* @@ -32,12 +32,20 @@ 元ファイルへのリンクを張らない -noimg~ 画像を展開しない +-height=YYYY~ +サイズを指定(高さ) +-width=XXX~ +サイズを指定(幅) +-nothumb +サムネイルを使わない -zoom~ -縦横比を保持する +無効(refとの互換性の為だけに存在) -999x999~ サイズを指定(幅x高さ) -999%~ サイズを指定(拡大率) +-info~ +ファイル情報を表示する -その他~ imgのalt/hrefのtitleとして使用~ ページ名やパラメータに見える文字列を使用するときは、#ref(hoge.png,,zoom)のように @@ -59,6 +67,9 @@ // URL指定時に画像サイズを取得するか define('REF_URL_GETIMAGESIZE',FALSE); +// サムネイルを使う場合のクオリティ 0〜100 +define('REF_IMGTHUM_QUAL',50); + function plugin_ref_inline() { global $vars; @@ -149,11 +160,11 @@ 'noicon' => FALSE, // アイコンを表示しない 'nolink' => FALSE, // 元ファイルへのリンクを張らない 'noimg' => FALSE, // 画像を展開しない - 'zoom' => FALSE, // 縦横比を保持する + 'nothumb'=> FALSE, // サムネイルを使わない + 'info' => FALSE, // ファイル情報を表示する '_size' => FALSE, //(サイズ指定あり) '_w' => 0, //(幅) '_h' => 0, //(高さ) - '_%' => 0, //(拡大率) '_args' => array(), '_done' => FALSE, '_error' => '' @@ -224,13 +235,21 @@ return $params; } $size = @getimagesize($file); + + if ( $params['_size'] && ( $params['_%'] > 99 || + $params['_w'] > $size[0] || $params['_h'] > $size[1] ) ){ + $params['nothumb'] = TRUE; + } + $is_image = (!$params['noimg'] and preg_match("/\.(gif|png|jpe?g)$/i",$name)); $width = $height = 0; $url = $script.'?plugin=attach&openfile='.rawurlencode($name).'&refer='.rawurlencode($page); + $thm = $script.'?plugin=attach&thumb='.rawurlencode($name).'&refer='.rawurlencode($page)."&qual=".REF_IMGTHUM_QUAL; + if ($is_image) { $url2 = $url; - $url = $file; + $url = $params['nothumb'] ? $url: $thm; if (is_array($size)) { $width = $size[0]; @@ -249,12 +268,28 @@ $_title = array(); foreach ($params['_args'] as $arg) { - if (preg_match('/^([0-9]+)x([0-9]+)$/',$arg,$m)) + if ( strncmp( $arg, "height=", 7) == 0 ) { + $params['_size'] = TRUE; + $params['_h'] = substr($arg,7); + } + else if ( strncmp( $arg, "width=", 6) == 0 ) { + $params['_size'] = TRUE; + $params['_w'] = substr($arg,6); + } + else if (preg_match('/^([0-9]+)x([0-9]+)$/',$arg,$m)) { $params['_size'] = TRUE; $params['_w'] = $m[1]; $params['_h'] = $m[2]; } + else if ( strcmp($arg,"zoom") == 0 ) + { + // zoomは削除 + } + else if ( strcmp($arg,"nothumb") == 0 ) + { + $params['nothumb'] = TRUE; + } else if (preg_match('/^([0-9.]+)%$/',$arg,$m) and $m[1] > 0) { $params['_%'] = $m[1]; @@ -270,7 +305,7 @@ $title = $is_image ? htmlspecialchars($title) : make_line_rules(htmlspecialchars($title)); } } - + //画像サイズ調整 if ($is_image) { @@ -282,32 +317,44 @@ $width = $params['_w']; $height = $params['_h']; } - else if ($params['zoom']) + else if ( !$params['_w'] || !$params['_h']) { - $_w = $params['_w'] ? $width / $params['_w'] : 0; - $_h = $params['_h'] ? $height / $params['_h'] : 0; - $zoom = max($_w,$_h); - if ($zoom) - { - $width = (int)($width / $zoom); - $height = (int)($height / $zoom); + if ( !$params['_h'] ) { + $height = (int)($height*$params['_w']/$width); + $width = $params['_w']; + } + if ( !$params['_w'] ) { + $width = (int)($width*$params['_h']/$height); + $height = $params['_h']; } } else { - $width = $params['_w'] ? $params['_w'] : $width; - $height = $params['_h'] ? $params['_h'] : $height; + $width = $params['_w']; + $height = $params['_h']; } - } - if ($params['_%']) + } else if ($params['_%']) { $width = (int)($width * $params['_%'] / 100); $height = (int)($height * $params['_%'] / 100); } + if ($width and $height) { $info = "width=\"$width\" height=\"$height\" "; } + + if ( !$params['nothumb'] && !is_url($name) ) { + if ( $width ) { + $url .= "&width={$width}"; + } + if ( $height ) { + $url .= "&height={$height}"; + } + } else { + $url .= "\" " . ( $width ? "width={$width} ": "" ) . + ( $height ? "height={$height} ": "" ); + } } //アラインメント判定 @@ -341,7 +388,8 @@ else // 通常ファイル { $icon = $params['noicon'] ? '' : FILE_ICON; - $params['_body'] = "$icon$title"; + $fileinfo = $params['info'] ? " ($info)" : ''; + $params['_body'] = "$icon$title$fileinfo\n"; } return $params; } --- pukiwiki/ja.lng.orig Sun Apr 4 00:27:07 2004 +++ pukiwiki/ja.lng Sat Jul 3 00:28:41 2004 @@ -147,7 +147,8 @@ 'err_adminpass'=> '管理者パスワードが一致しません。', 'btn_upload' => 'アップロード', 'btn_info' => '詳細', - 'btn_submit' => '実行' + 'btn_submit' => '実行', + 'untar_mode' => 'Untar', ); /////////////////////////////////////// --- pukiwiki/en.lng.orig Sun Apr 4 00:27:07 2004 +++ pukiwiki/en.lng Sat Jul 3 00:29:34 2004 @@ -145,7 +145,8 @@ 'err_adminpass'=> 'Wrong administrator password', 'btn_upload' => 'Upload', 'btn_info' => 'Information', - 'btn_submit' => 'Submit' + 'btn_submit' => 'Submit', + 'untar_mode' => 'Untar', ); ///////////////////////////////////////