OSDN Git Service

BugTrack/664 Should replace #img(,clear) => #clear
[pukiwiki/pukiwiki.git] / plugin / ref.inc.php
index b21c673..fff7256 100644 (file)
 <?php
-// $Id: ref.inc.php,v 1.2 2002/12/07 09:43:43 panda Exp $
+/////////////////////////////////////////////////
+// PukiWiki - Yet another WikiWikiWeb clone.
+//
+// $Id: ref.inc.php,v 1.30 2004/08/21 02:36:57 henoheno Exp $
+//
+
+// UPLOAD_DIR ¤Î¥Ç¡¼¥¿(²èÁü¥Õ¥¡¥¤¥ë¤Î¤ß)¤ËľÀÜ¥¢¥¯¥»¥¹¤µ¤»¤ë
+define('PLUGIN_REF_DIRECT_ACCESS', FALSE); // FALSE or TRUE
+// - ¤³¤ì¤Ï½¾Íè¤Î¥¤¥ó¥é¥¤¥ó¥¤¥á¡¼¥¸½èÍý¤ò¸ß´¹¤Î¤¿¤á¤Ë»Ä¤¹¤â¤Î¤Ç
+//   ¤¢¤ê¡¢¹â®²½¤Î¤¿¤á¤Î¥ª¥×¥·¥ç¥ó¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó
+// - UPLOAD_DIR ¤òWeb¥µ¡¼¥Ð¡¼¾å¤ËϪ½Ð¤µ¤»¤Æ¤ª¤ê¡¢¤«¤ÄľÀÜ¥¢¥¯¥»¥¹
+//   ¤Ç¤­¤ë(¥¢¥¯¥»¥¹À©¸Â¤¬¤Ê¤¤)¾õÂ֤Ǥ¢¤ëɬÍפ¬¤¢¤ê¤Þ¤¹
+// - Apache ¤Ê¤É¤Ç¤Ï UPLOAD_DIR/.htaccess ¤òºï½ü¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹
+// - ¥Ö¥é¥¦¥¶¤Ë¤è¤Ã¤Æ¤Ï¥¤¥ó¥é¥¤¥ó¥¤¥á¡¼¥¸¤Îɽ¼¨¤ä¡¢¡Ö¥¤¥ó¥é¥¤¥ó
+//   ¥¤¥á¡¼¥¸¤À¤±¤òɽ¼¨¡×¤µ¤»¤¿»þ¤Ê¤É¤ËÉÔ¶ñ¹ç¤¬½Ð¤ë¾ì¹ç¤¬¤¢¤ê¤Þ¤¹
+
 /*
-Last-Update:2002-10-29 rev.33
-
-*¥×¥é¥°¥¤¥ó ref
-¥Ú¡¼¥¸¤ËźÉÕ¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤òŸ³«¤¹¤ë
-
-*Usage
- #ref(filename[,Page][[,{Left|Center|Right}]|[,{Wrap|Nowrap}]|[,Around]]{}[,comments])
-
-*¥Ñ¥é¥á¡¼¥¿
--filename~
- ÅºÉÕ¥Õ¥¡¥¤¥ë̾¡¢¤¢¤ë¤¤¤ÏURL
--Page~
- WikiName¤Þ¤¿¤ÏBracketName¤ò»ØÄꤹ¤ë¤È¡¢¤½¤Î¥Ú¡¼¥¸¤ÎźÉÕ¥Õ¥¡¥¤¥ë¤ò»²¾È¤¹¤ë
--Left|Center|Right~
- ²£¤Î°ÌÃÖ¹ç¤ï¤»
--Wrap|Nowrap~
- ¥Æ¡¼¥Ö¥ë¥¿¥°¤Ç°Ï¤à/°Ï¤Þ¤Ê¤¤
--Around~
- ¥Æ¥­¥¹¥È¤Î²ó¤ê¹þ¤ß
+* ¥×¥é¥°¥¤¥ó ref
+- ¥Ú¡¼¥¸¤ËźÉÕ¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤òŸ³«¤¹¤ë
+- URL¤òŸ³«¤¹¤ë
+
+* Usage
+ #ref(filename[,page][,parameters][,title])
 
+* ¥Ñ¥é¥á¡¼¥¿
+- filename -- ÅºÉÕ¥Õ¥¡¥¤¥ë̾¡¢¤¢¤ë¤¤¤ÏURL
+-- '¥Ú¡¼¥¸Ì¾/źÉÕ¥Õ¥¡¥¤¥ë̾'¤ò»ØÄꤹ¤ë¤È¡¢»ØÄꤷ¤¿¥Ú¡¼¥¸¤ÎźÉÕ¥Õ¥¡¥¤¥ë¤ò»²¾È¤¹¤ë
+- page    -- ¥Õ¥¡¥¤¥ë¤òźÉÕ¤·¤¿¥Ú¡¼¥¸Ì¾(¾Êά²Ä)
+- Left|Center|Right -- ²£¤Î°ÌÃÖ¹ç¤ï¤»
+- Wrap|Nowrap -- ¥Æ¡¼¥Ö¥ë¥¿¥°¤Ç°Ï¤à/°Ï¤Þ¤Ê¤¤
+- Around  -- ¥Æ¥­¥¹¥È¤Î²ó¤ê¹þ¤ß
+- noicon  -- ¥¢¥¤¥³¥ó¤òɽ¼¨¤·¤Ê¤¤
+- nolink  -- ¸µ¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯¤òÄ¥¤é¤Ê¤¤
+- noimg   -- ²èÁü¤òŸ³«¤·¤Ê¤¤
+- zoom    -- ½Ä²£Èæ¤òÊÝ»ý¤¹¤ë
+- 999x999 -- ¥µ¥¤¥º¤ò»ØÄê(Éýx¹â¤µ)
+- 999%    -- ¥µ¥¤¥º¤ò»ØÄê(³ÈÂçΨ)
+- ¤½¤Î¾¤Îʸ»úÎó -- img¤Îalt/href¤Îtitle¤È¤·¤Æ»ÈÍÑ
+¥Ú¡¼¥¸Ì¾¤ä¥Ñ¥é¥á¡¼¥¿¤Ë¸«¤¨¤ëʸ»úÎó¤ò»ÈÍѤ¹¤ë¤È¤­¤Ï¡¢#ref(hoge.png,,zoom)¤Î¤è¤¦¤Ë
+¥¿¥¤¥È¥ë¤ÎÁ°¤Ë¥«¥ó¥Þ¤ò;ʬ¤ËÆþ¤ì¤ë
 */
 
-// upload dir(must set end of /)
-define('REF_UPLOAD_DIR','./attach/');
+// Usage
+define('PLUGIN_REF_USAGE', "(attached-file-name[,page-name][,parameters][,title])");
+
+// Image suffixes
+define('PLUGIN_REF_IMAGE', '/\.(gif|png|jpe?g)$/i');
+
+// File icon image
+if (! defined('FILE_ICON')) {
+       define('FILE_ICON',
+       '<img src="' . IMAGE_DIR . 'file.png" width="20" height="20"' .
+       ' alt="file" style="border-width:0px" />');
+}
+
+// Default alignment
+define('REF_DEFAULT_ALIGN', 'left'); // 'left', 'center', 'right'
+
+// Force wrap on default
+define('REF_WRAP_TABLE', FALSE); // TRUE, FALSE
 
-// file icon image
-define('REF_FILE_ICON','<img src="./image/file.gif" alt="file" width="20" height="20" />');
+// URL»ØÄê»þ¤Ë²èÁü¥µ¥¤¥º¤ò¼èÆÀ¤¹¤ë¤«
+define('REF_URL_GETIMAGESIZE', FALSE);
 
-// default alignment
-define('REF_DEFAULT_ALIGN','left'); // 'left','center','right'
+function plugin_ref_inline()
+{
+       // Not reached, because of "$aryargs[] = & $body" at plugin.php
+       // if (! func_num_args())
+       //      return '&amp;ref(): Usage:' . PLUGIN_REF_USAGE . ';';
 
-// force wrap on default
-define('REF_WRAP_TABLE',FALSE); // TRUE,FALSE
+       $params = plugin_ref_body(func_get_args());
 
-function plugin_ref_convert() {
+       if (isset($params['_error']) && $params['_error'] != '') {
+               // Error
+               return '&amp;ref(): ' . $params['_error'] . ';';
+       } else {
+               return $params['_body'];
+       }
+}
+
+function plugin_ref_convert()
+{
+       if (! func_num_args())
+               return '<p>#ref(): Usage:' . PLUGIN_REF_USAGE . "</p>\n";
+
+       $params = plugin_ref_body(func_get_args());
+
+       if (isset($params['_error']) && $params['_error'] != '') {
+               return "<p>#ref(): {$params['_error']}</p>\n";
+       }
+
+       if ((REF_WRAP_TABLE && ! $params['nowrap']) || $params['wrap']) {
+               // ÏȤÇÊñ¤à
+               // margin:auto
+               //      Mozilla 1.x  = x (wrap,around¤¬¸ú¤«¤Ê¤¤)
+               //      Opera 6      = o
+               //      Netscape 6   = x (wrap,around¤¬¸ú¤«¤Ê¤¤)
+               //      IE 6         = x (wrap,around¤¬¸ú¤«¤Ê¤¤)
+               // margin:0px
+               //      Mozilla 1.x  = x (wrap¤Ç´ó¤»¤¬¸ú¤«¤Ê¤¤)
+               //      Opera 6      = x (wrap¤Ç´ó¤»¤¬¸ú¤«¤Ê¤¤)
+               //      Netscape 6   = x (wrap¤Ç´ó¤»¤¬¸ú¤«¤Ê¤¤)
+               //      IE6          = o
+               $margin = ($params['around'] ? '0px' : 'auto');
+               $margin_align = ($params['_align'] == 'center') ? '' : ";margin-{$params['_align']}:0px";
+               $params['_body'] = <<<EOD
+<table class="style_table" style="margin:$margin$margin_align">
+ <tr>
+  <td class="style_td">{$params['_body']}</td>
+ </tr>
+</table>
+EOD;
+       }
+
+       if ($params['around']) {
+               $style = ($params['_align'] == 'right') ? 'float:right' : 'float:left';
+       } else {
+               $style = "text-align:{$params['_align']}";
+       }
 
-       global $script,$vars;
-       global $WikiName, $BracketName;
+       // div¤ÇÊñ¤à
+       return "<div class=\"img_margin\" style=\"$style\">{$params['_body']}</div>\n";
+}
 
-       //Ìá¤êÃÍ
-       $ret = '';
+function plugin_ref_body($args)
+{
+       global $script, $vars, $WikiName, $BracketName;
 
-       //¥¨¥é¡¼¥Á¥§¥Ã¥¯
-       if (!func_num_args()) return 'no argument(s).';
+       $params = array(); // Ìá¤êÃÍ
+       $page = isset($vars['page']) ? $vars['page'] : '';
 
-       //źÉÕ¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ
-       $args = func_get_args();
+       // ÅºÉÕ¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ
        $name = array_shift($args);
 
-// $name¤ò¤â¤È¤Ë°Ê²¼¤ÎÊÑ¿ô¤òÀßÄê
-// $url : URL
-// $title :¥¿¥¤¥È¥ë
-// $ext : ³ÈÄ¥»ÒȽÊÌÍÑʸ»úÎó
-// $icon : ¥¢¥¤¥³¥ó¤Îimg¥¿¥°
-// $size : ²èÁü¥Õ¥¡¥¤¥ë¤Î¤È¤­¥µ¥¤¥º
-// $info : ²èÁü¥Õ¥¡¥¤¥ë°Ê³°¤Î¥Õ¥¡¥¤¥ë¤Î¾ðÊó
-//  ÅºÉÕ¥Õ¥¡¥¤¥ë¤Î¤È¤­ : ¥Õ¥¡¥¤¥ë¤ÎºÇ½ª¹¹¿·Æü¤È¥µ¥¤¥º
-//  URL¤Î¤È¤­ : URL¤½¤Î¤â¤Î
-
-       if (is_url($name)) { //URL
-               $url = $ext = $info = htmlspecialchars($name);
-               $icon = $size = '';
-               if (preg_match('/([^\/]+)$/', $name, $match)) { $ext = $match[1]; }
-       } else { //źÉÕ¥Õ¥¡¥¤¥ë
-               $icon = REF_FILE_ICON;
-               if (!is_dir(REF_UPLOAD_DIR)) return 'no REF_UPLOAD_DIR.';
-               //¥Ú¡¼¥¸»ØÄê¤Î¥Á¥§¥Ã¥¯
-               $page = $vars['page'];
-               if (count($args) > 0) {
-                       $_page = get_fullname($args[0],$vars['page']);
-                       if (is_page($_page)) {
-                               $page = $_page;
-                               array_shift($args);
+       // ¼¡¤Î°ú¿ô¤¬¥Ú¡¼¥¸Ì¾¤«¤É¤¦¤«
+       if (! empty($args) &&
+               preg_match("/^($WikiName|\[\[$BracketName\]\])$/", $args[0]))
+       {
+               $_page = get_fullname(strip_bracket($args[0]), $page);
+               if (is_pagename($_page)) {
+                       $page = $_page;
+                       array_shift($args);
+               }
+       }
+
+       // ¥Ñ¥é¥á¡¼¥¿
+       $params = array(
+               'left'   => FALSE, // º¸´ó¤»
+               'center' => FALSE, // Ãæ±û´ó¤»
+               'right'  => FALSE, // ±¦´ó¤»
+               'wrap'   => FALSE, // TABLE¤Ç°Ï¤à
+               'nowrap' => FALSE, // TABLE¤Ç°Ï¤Þ¤Ê¤¤
+               'around' => FALSE, // ²ó¤ê¹þ¤ß
+               'noicon' => FALSE, // ¥¢¥¤¥³¥ó¤òɽ¼¨¤·¤Ê¤¤
+               'nolink' => FALSE, // ¸µ¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯¤òÄ¥¤é¤Ê¤¤
+               'noimg'  => FALSE, // ²èÁü¤òŸ³«¤·¤Ê¤¤
+               'zoom'   => FALSE, // ½Ä²£Èæ¤òÊÝ»ý¤¹¤ë
+               '_size'  => FALSE, // ¥µ¥¤¥º»ØÄꤢ¤ê
+               '_w'     => 0,       // Éý
+               '_h'     => 0,       // ¹â¤µ
+               '_%'     => 0,     // ³ÈÂçΨ
+               '_args'  => array(),
+               '_done'  => FALSE,
+               '_error' => ''
+       );
+
+       if (! empty($args))
+               foreach ($args as $arg)
+                       ref_check_arg($arg, $params);
+
+/*
+ $name¤ò¤â¤È¤Ë°Ê²¼¤ÎÊÑ¿ô¤òÀßÄê
+ $url,$url2 : URL
+ $title :¥¿¥¤¥È¥ë
+ $is_image : ²èÁü¤Î¤È¤­TRUE
+ $info : ²èÁü¥Õ¥¡¥¤¥ë¤Î¤È¤­getimagesize()¤Î'size'
+         ²èÁü¥Õ¥¡¥¤¥ë°Ê³°¤Î¥Õ¥¡¥¤¥ë¤Î¾ðÊó
+         ÅºÉÕ¥Õ¥¡¥¤¥ë¤Î¤È¤­ : ¥Õ¥¡¥¤¥ë¤ÎºÇ½ª¹¹¿·Æü¤È¥µ¥¤¥º
+         URL¤Î¤È¤­ : URL¤½¤Î¤â¤Î
+*/
+       $file = $title = $url = $url2 = $info = '';
+       $width = $height = 0;
+       $matches = array();
+
+       if (is_url($name)) {    // URL
+               $url = $url2 = htmlspecialchars($name);
+               $title = htmlspecialchars(preg_match('/([^\/]+)$/', $name, $matches) ? $matches[1] : $url);
+
+               $is_image = (! $params['noimg'] && preg_match(PLUGIN_REF_IMAGE, $name));
+
+               if (REF_URL_GETIMAGESIZE && $is_image && (bool)ini_get('allow_url_fopen')) {
+                       $size = @getimagesize($name);
+                       if (is_array($size)) {
+                               $width  = $size[0];
+                               $height = $size[1];
+                               $info   = $size[3];
                        }
                }
-               if (!is_page($page)) { return 'page not found.'; }
 
-               $ext = $name;
-               $file = REF_UPLOAD_DIR.encode($page).'_'.encode($name);
-               if (!is_file($file)) { return 'not found.'; }
+       } else { // ÅºÉÕ¥Õ¥¡¥¤¥ë
+               if (! is_dir(UPLOAD_DIR)) {
+                       $params['_error'] = 'No UPLOAD_DIR';
+                       return $params;
+               }
+
+               // ¥Ú¡¼¥¸»ØÄê¤Î¥Á¥§¥Ã¥¯
+               if (preg_match('/^(.+)\/([^\/]+)$/', $name, $matches)) {
+                       if ($matches[1] == '.' || $matches[1] == '..') {
+                               $matches[1] .= '/';
+                       }
+                       $page = get_fullname($matches[1],$page);
+                       $name = $matches[2];
+               }
+               $title = htmlspecialchars($name);
+               $file = UPLOAD_DIR . encode($page) . '_' . encode($name);
+
+               if (! is_file($file)) {
+                       $params['_error'] = 'File not found';
+                       return $params;
+               }
+
+               $is_image = (! $params['noimg'] && preg_match(PLUGIN_REF_IMAGE, $name));
 
-               if (is_picture($ext)) {
-                       $url = $file;
-                       $size = getimagesize($file);
-                       $size = $size[3];
+               // Count downloads with attach plugin
+               $url = $script . '?plugin=attach' . '&amp;refer=' . rawurlencode($page) .
+                       '&amp;openfile=' . rawurlencode($name); // Show its filename at the last
+
+               if ($is_image) {
+                       // Swap $url
+                       $url2 = $url;
+
+                       // URI for in-line image output
+                       if (! PLUGIN_REF_DIRECT_ACCESS) {
+                               // With ref plugin (faster than attach)
+                               $url = $script . '?plugin=ref' . '&amp;page=' . rawurlencode($page) .
+                                       '&amp;src=' . rawurlencode($name); // Show its filename at the last
+                       } else {
+                               // Try direct-access, if possible
+                               $url = $file;
+                       }
+
+                       $width = $height = 0;
+                       $size = @getimagesize($file);
+                       if (is_array($size)) {
+                               $width  = $size[0];
+                               $height = $size[1];
+                       }
                } else {
-                       $url = $script.'?plugin=attach&amp;openfile='.rawurlencode($name).'&amp;refer='.rawurlencode($page);
-                       $lastmod = date('Y/m/d H:i:s',filemtime($file));
-                       $size = sprintf('%01.1f',round(filesize($file)/1000,1)).'KB';
-                       $info = "$lastmod $size";
+                       $info = get_date('Y/m/d H:i:s', filemtime($file) - LOCALZONE) .
+                               ' ' . sprintf('%01.1f', round(filesize($file)/1024, 1)) . 'KB';
                }
        }
 
-       //¥Ñ¥é¥á¡¼¥¿ÊÑ´¹
-       $params = array('left'=>FALSE,'center'=>FALSE,'right'=>FALSE,'wrap'=>FALSE,'nowrap'=>FALSE,'around'=>FALSE,'_args'=>array(),'_done'=>FALSE);
-       array_walk($args, 'ref_check_arg', &$params);
-       if (count($params['_args']) > 0) { $title = join(',', $params['_args']); }
-
-       //¥¿¥¤¥È¥ë¤ò·èÄê
-       if (!isset($title) or $title == '') { $title = $ext; }
-       $title = htmlspecialchars($title);
-
-       //¥¢¥é¥¤¥ó¥á¥ó¥ÈȽÄê
-       if ($params['right'])
-               $align = 'right';
-       else if ($params['left'])
-               $align = 'left';
-       else if ($params['center'])
-               $align = 'center';
-       else
-               $align = REF_DEFAULT_ALIGN;
-
-       // ¥Õ¥¡¥¤¥ë¼ïÊÌȽÄê
-       if (is_picture($ext)) { // ²èÁü
-               $ret .= "<img src=\"$url\" alt=\"$title\" title=\"$title\" $size />";
-       } else { // Ä̾ï¥Õ¥¡¥¤¥ë
-               $ret .= "<a href=\"$url\" title=\"$info\">$icon$title</a>\n";
+       // ³ÈÄ¥¥Ñ¥é¥á¡¼¥¿¤ò¥Á¥§¥Ã¥¯
+       if (! empty($params['_args'])) {
+               $_title = array();
+               foreach ($params['_args'] as $arg) {
+                       if (preg_match('/^([0-9]+)x([0-9]+)$/', $arg, $matches)) {
+                               $params['_size'] = TRUE;
+                               $params['_w'] = $matches[1];
+                               $params['_h'] = $matches[2];
+
+                       } else if (preg_match('/^([0-9.]+)%$/', $arg, $matches) && $matches[1] > 0) {
+                               $params['_%'] = $matches[1];
+
+                       } else {
+                               $_title[] = $arg;
+                       }
+               }
+
+               if (! empty($_title)) {
+                       $title = htmlspecialchars(join(',', $_title));
+                       if ($is_image) $title = make_line_rules($title);
+               }
        }
 
-       if ((REF_WRAP_TABLE and !$params['nowrap']) or $params['wrap']) {
-               $ret = wrap_table($ret, $align, $params['around']);
+       // ²èÁü¥µ¥¤¥ºÄ´À°
+       if ($is_image) {
+               // »ØÄꤵ¤ì¤¿¥µ¥¤¥º¤ò»ÈÍѤ¹¤ë
+               if ($params['_size']) {
+                       if ($width == 0 && $height == 0) {
+                               $width  = $params['_w'];
+                               $height = $params['_h'];
+                       } else if ($params['zoom']) {
+                               $_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);
+                               }
+                       } else {
+                               $width  = $params['_w'] ? $params['_w'] : $width;
+                               $height = $params['_h'] ? $params['_h'] : $height;
+                       }
+               }
+               if ($params['_%']) {
+                       $width  = (int)($width  * $params['_%'] / 100);
+                       $height = (int)($height * $params['_%'] / 100);
+               }
+               if ($width && $height) $info = "width=\"$width\" height=\"$height\" ";
        }
-       $ret = wrap_div($ret, $align, $params['around']);
-       return $ret;
-}
 
-//-----------------------------------------------------------------------------
-// ²èÁü¤«¤É¤¦¤«
-function is_picture($text) {
-       return preg_match('/(\.gif|\.png|\.jpeg|\.jpg)$/i', $text);
-}
-// URL¤«¤É¤¦¤«
-function is_url($text) {
-       return preg_match('/^(https?|ftp|news)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $text);
-}
-// div¤ÇÊñ¤à
-function wrap_div($text, $align, $around) {
-       if ($around) {
-               $style = ($align == 'right') ? 'float:right' : 'float:left';
+       // ¥¢¥é¥¤¥ó¥á¥ó¥ÈȽÄê
+       $params['_align'] = REF_DEFAULT_ALIGN;
+       foreach (array('right', 'left', 'center') as $align) {
+               if ($params[$align])  {
+                       $params['_align'] = $align;
+                       break;
+               }
+       }
+
+       if ($is_image) { // ²èÁü
+               $params['_body'] = "<img src=\"$url\" alt=\"$title\" title=\"$title\" $info/>";
+               if (! $params['nolink'] && $url2)
+                       $params['_body'] = "<a href=\"$url2\" title=\"$title\">{$params['_body']}</a>";
        } else {
-               $style = "text-align:$align";
+               $icon = $params['noicon'] ? '' : FILE_ICON;
+               $params['_body'] = "<a href=\"$url\" title=\"$info\">$icon$title</a>";
        }
-       return "<div class=\"img_margin\" style=\"$style\">$text</div>\n";
-}
-// ÏȤÇÊñ¤à
-// margin:auto Moz1=x(wrap,around¤¬¸ú¤«¤Ê¤¤),op6=oNN6=x(wrap,around¤¬¸ú¤«¤Ê¤¤)IE6=x(wrap,around¤¬¸ú¤«¤Ê¤¤)
-// margin:0px Moz1=x(wrap¤Ç´ó¤»¤¬¸ú¤«¤Ê¤¤),op6=x(wrap¤Ç´ó¤»¤¬¸ú¤«¤Ê¤¤),nn6=x(wrap¤Ç´ó¤»¤¬¸ú¤«¤Ê¤¤),IE6=o
-function wrap_table($text, $align, $around) {
-       $margin = ($around ? '0px' : 'auto');
-       $margin_align = ($align == 'center') ? '' : ";margin-$align:0px";
-       return "<table class=\"style_table\" style=\"margin:$margin$margin_align\">\n<tr><td class=\"style_td\">\n$text\n</td></tr>\n</table>\n";
+
+       return $params;
 }
-//¥ª¥×¥·¥ç¥ó¤ò²òÀϤ¹¤ë
-function ref_check_arg($val, $_key, &$params) {
-       if ($val == '') { $params['_done'] = TRUE; return; }
-       if (!$params['_done']) {
+
+// ¥ª¥×¥·¥ç¥ó¤ò²òÀϤ¹¤ë
+function ref_check_arg($val, & $params)
+{
+       if ($val == '') {
+               $params['_done'] = TRUE;
+               return;
+       }
+
+       if (! $params['_done']) {
                foreach (array_keys($params) as $key) {
                        if (strpos($key, strtolower($val)) === 0) {
                                $params[$key] = TRUE;
@@ -165,6 +340,46 @@ function ref_check_arg($val, $_key, &$params) {
                }
                $params['_done'] = TRUE;
        }
+
        $params['_args'][] = $val;
 }
+
+// Output an image (fast, non-logging <==> attach plugin)
+function plugin_ref_action()
+{
+       global $vars;
+
+       $usage = 'Usage: plugin=ref&amp;page=page_name&amp;src=attached_image_name';
+
+       if (! isset($vars['page']) || ! isset($vars['src']))
+               return array('msg'=>'Invalid argument', 'body'=>$usage);
+
+       $page = $vars['page'];
+       $file = $vars['src'];
+
+       $ref = UPLOAD_DIR . encode($page) . '_' . encode(basename($file));
+       if(! file_exists($ref))
+               return array('msg'=>'Attach file not found', 'body'=>$usage);
+
+       $got = @getimagesize($ref);
+       if (! isset($got[2])) $got[2] = FALSE;
+       switch ($got[2]) {
+       case 1: $type = 'image/gif' ; break;
+       case 2: $type = 'image/jpeg'; break;
+       case 3: $type = 'image/png' ; break;
+       case 4: $type = 'application/x-shockwave-flash'; break;
+       default:
+               return array('msg'=>'Seems not an image', 'body'=>$usage);
+       }
+
+       // Output
+       $file = htmlspecialchars($file);
+       $size = filesize($ref);
+       header('Content-Disposition: inline; filename="' . $file . '"');
+       header('Content-Length: ' . $size);
+       header('Content-Type: '   . $type);
+       @readfile($ref);
+
+       exit;
+}
 ?>