OSDN Git Service

BugTrack/664 Should replace #img(,clear) => #clear
[pukiwiki/pukiwiki.git] / plugin / ref.inc.php
index 579f538..fff7256 100644 (file)
 /////////////////////////////////////////////////
 // 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.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 ¤òºï½ü¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹
+// - ¥Ö¥é¥¦¥¶¤Ë¤è¤Ã¤Æ¤Ï¥¤¥ó¥é¥¤¥ó¥¤¥á¡¼¥¸¤Îɽ¼¨¤ä¡¢¡Ö¥¤¥ó¥é¥¤¥ó
+//   ¥¤¥á¡¼¥¸¤À¤±¤òɽ¼¨¡×¤µ¤»¤¿»þ¤Ê¤É¤ËÉÔ¶ñ¹ç¤¬½Ð¤ë¾ì¹ç¤¬¤¢¤ê¤Þ¤¹
+
 /*
-*¥×¥é¥°¥¤¥ó ref
-¥Ú¡¼¥¸¤ËźÉÕ¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤òŸ³«¤¹¤ë
-URL¤òŸ³«¤¹¤ë
+* ¥×¥é¥°¥¤¥ó ref
+¥Ú¡¼¥¸¤ËźÉÕ¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤òŸ³«¤¹¤ë
+URL¤òŸ³«¤¹¤ë
 
-*Usage
+* 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¤È¤·¤Æ»ÈÍÑ~
+* ¥Ñ¥é¥á¡¼¥¿
+- filename -- ÅºÉÕ¥Õ¥¡¥¤¥ë̾¡¢¤¢¤ë¤¤¤ÏURL
+-- '¥Ú¡¼¥¸Ì¾/źÉÕ¥Õ¥¡¥¤¥ë̾'¤ò»ØÄꤹ¤ë¤È¡¢»ØÄꤷ¤¿¥Ú¡¼¥¸¤ÎźÉÕ¥Õ¥¡¥¤¥ë¤ò»²¾È¤¹¤ë
+- page    -- ¥Õ¥¡¥¤¥ë¤òźÉÕ¤·¤¿¥Ú¡¼¥¸Ì¾(¾Êά²Ä)
+- Left|Center|Right -- ²£¤Î°ÌÃÖ¹ç¤ï¤»
+- Wrap|Nowrap -- ¥Æ¡¼¥Ö¥ë¥¿¥°¤Ç°Ï¤à/°Ï¤Þ¤Ê¤¤
+- Around  -- ¥Æ¥­¥¹¥È¤Î²ó¤ê¹þ¤ß
+- noicon  -- ¥¢¥¤¥³¥ó¤òɽ¼¨¤·¤Ê¤¤
+- nolink  -- ¸µ¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯¤òÄ¥¤é¤Ê¤¤
+- noimg   -- ²èÁü¤òŸ³«¤·¤Ê¤¤
+- zoom    -- ½Ä²£Èæ¤òÊÝ»ý¤¹¤ë
+- 999x999 -- ¥µ¥¤¥º¤ò»ØÄê(Éýx¹â¤µ)
+- 999%    -- ¥µ¥¤¥º¤ò»ØÄê(³ÈÂçΨ)
+- ¤½¤Î¾¤Îʸ»úÎó -- img¤Îalt/href¤Îtitle¤È¤·¤Æ»ÈÍÑ
 ¥Ú¡¼¥¸Ì¾¤ä¥Ñ¥é¥á¡¼¥¿¤Ë¸«¤¨¤ëʸ»úÎó¤ò»ÈÍѤ¹¤ë¤È¤­¤Ï¡¢#ref(hoge.png,,zoom)¤Î¤è¤¦¤Ë
 ¥¿¥¤¥È¥ë¤ÎÁ°¤Ë¥«¥ó¥Þ¤ò;ʬ¤ËÆþ¤ì¤ë
 */
 
-// file icon image
-if (!defined('FILE_ICON'))
-{
-       define('FILE_ICON','<img src="./image/file.png" width="20" height="20" alt="file" style="border-width:0px" />');
+// 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'
+// Default alignment
+define('REF_DEFAULT_ALIGN', 'left'); // 'left', 'center', 'right'
 
-// force wrap on default
-define('REF_WRAP_TABLE',FALSE); // TRUE,FALSE
+// Force wrap on default
+define('REF_WRAP_TABLE', FALSE); // TRUE, FALSE
 
 // URL»ØÄê»þ¤Ë²èÁü¥µ¥¤¥º¤ò¼èÆÀ¤¹¤ë¤«
-define('REF_URL_GETIMAGESIZE',FALSE);
+define('REF_URL_GETIMAGESIZE', FALSE);
 
 function plugin_ref_inline()
 {
-       global $vars;
-       
-       //¥¨¥é¡¼¥Á¥§¥Ã¥¯
-       if (!func_num_args())
-       {
-               return 'no argument(s).';
+       // Not reached, because of "$aryargs[] = & $body" at plugin.php
+       // if (! func_num_args())
+       //      return '&amp;ref(): Usage:' . PLUGIN_REF_USAGE . ';';
+
+       $params = plugin_ref_body(func_get_args());
+
+       if (isset($params['_error']) && $params['_error'] != '') {
+               // Error
+               return '&amp;ref(): ' . $params['_error'] . ';';
+       } else {
+               return $params['_body'];
        }
-       
-       $params = plugin_ref_body(func_get_args(),$vars['page']);
-       
-       return ($params['_error'] != '') ? $params['_error'] : $params['_body'];
 }
+
 function plugin_ref_convert()
 {
-       global $vars;
+       if (! func_num_args())
+               return '<p>#ref(): Usage:' . PLUGIN_REF_USAGE . "</p>\n";
 
-       //¥¨¥é¡¼¥Á¥§¥Ã¥¯
-       if (!func_num_args())
-       {
-               return '<p>no argument(s).</p>';
-       }
-       
-       $params = plugin_ref_body(func_get_args(),$vars['page']);
-       
-       if ($params['_error'] != '')
-       {
-               return "<p>{$params['_error']}</p>";
+       $params = plugin_ref_body(func_get_args());
+
+       if (isset($params['_error']) && $params['_error'] != '') {
+               return "<p>#ref(): {$params['_error']}</p>\n";
        }
-       
-       if ((REF_WRAP_TABLE and !$params['nowrap']) or $params['wrap'])
-       {
+
+       if ((REF_WRAP_TABLE && ! $params['nowrap']) || $params['wrap']) {
                // ÏȤÇÊñ¤à
-               // 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
+               // 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
@@ -105,40 +112,39 @@ function plugin_ref_convert()
 </table>
 EOD;
        }
-       // div¤ÇÊñ¤à
-       if ($params['around'])
-       {
+
+       if ($params['around']) {
                $style = ($params['_align'] == 'right') ? 'float:right' : 'float:left';
-       }
-       else
-       {
+       } else {
                $style = "text-align:{$params['_align']}";
        }
+
+       // div¤ÇÊñ¤à
        return "<div class=\"img_margin\" style=\"$style\">{$params['_body']}</div>\n";
 }
 
-function plugin_ref_body($args,$page)
+function plugin_ref_body($args)
 {
-       global $script,$WikiName,$BracketName;
-       
-       // Ìá¤êÃÍ
-       $params = array();
-       
+       global $script, $vars, $WikiName, $BracketName;
+
+       $params = array(); // Ìá¤êÃÍ
+       $page = isset($vars['page']) ? $vars['page'] : '';
+
        // ÅºÉÕ¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ
        $name = array_shift($args);
-       
+
        // ¼¡¤Î°ú¿ô¤¬¥Ú¡¼¥¸Ì¾¤«¤É¤¦¤«
-       if (count($args) and preg_match("/^($WikiName|\[\[$BracketName\]\])$/",$args[0]))
+       if (! empty($args) &&
+               preg_match("/^($WikiName|\[\[$BracketName\]\])$/", $args[0]))
        {
-               $_page = get_fullname(strip_bracket($args[0]),$page);
-               if (is_pagename($_page))
-               {
+               $_page = get_fullname(strip_bracket($args[0]), $page);
+               if (is_pagename($_page)) {
                        $page = $_page;
                        array_shift($args);
                }
        }
-       
-       //¥Ñ¥é¥á¡¼¥¿
+
+       // ¥Ñ¥é¥á¡¼¥¿
        $params = array(
                'left'   => FALSE, // º¸´ó¤»
                'center' => FALSE, // Ãæ±û´ó¤»
@@ -150,23 +156,19 @@ function plugin_ref_body($args,$page)
                'nolink' => FALSE, // ¸µ¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯¤òÄ¥¤é¤Ê¤¤
                'noimg'  => FALSE, // ²èÁü¤òŸ³«¤·¤Ê¤¤
                'zoom'   => FALSE, // ½Ä²£Èæ¤òÊÝ»ý¤¹¤ë
-               '_size'  => FALSE, //(¥µ¥¤¥º»ØÄꤢ¤ê)
-               '_w'     => 0,      //(Éý)
-               '_h'     => 0,      //(¹â¤µ)
-               '_%'     => 0,      //(³ÈÂçΨ)
+               '_size'  => FALSE, // ¥µ¥¤¥º»ØÄꤢ¤ê
+               '_w'     => 0,       // Éý
+               '_h'     => 0,       // ¹â¤µ
+               '_%'     => 0,     // ³ÈÂçΨ
                '_args'  => array(),
                '_done'  => FALSE,
                '_error' => ''
        );
-       
-       if (count($args) > 0)
-       {
-               foreach ($args as $key=>$val)
-               {
-                       ref_check_arg($val,$key,$params);
-               }
-       }
-       
+
+       if (! empty($args))
+               foreach ($args as $arg)
+                       ref_check_arg($arg, $params);
+
 /*
  $name¤ò¤â¤È¤Ë°Ê²¼¤ÎÊÑ¿ô¤òÀßÄê
  $url,$url2 : URL
@@ -179,194 +181,205 @@ function plugin_ref_body($args,$page)
 */
        $file = $title = $url = $url2 = $info = '';
        $width = $height = 0;
-       
-       if (is_url($name))      //URL
-       {
+       $matches = array();
+
+       if (is_url($name)) {    // URL
                $url = $url2 = htmlspecialchars($name);
-               $title = htmlspecialchars(preg_match('/([^\/]+)$/', $name, $match) ? $match[1] : $url);
-               
-               $is_image = (!$params['noimg'] and preg_match("/\.(gif|png|jpe?g)$/i",$name));
-               if (REF_URL_GETIMAGESIZE and $is_image and (bool)ini_get('allow_url_fopen'))
-               {
+               $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];
+                       if (is_array($size)) {
+                               $width  = $size[0];
                                $height = $size[1];
-                               $info = $size[3];
+                               $info   = $size[3];
                        }
                }
-       }
-       else //źÉÕ¥Õ¥¡¥¤¥ë
-       {
-               if (!is_dir(UPLOAD_DIR))
-               {
-                       $params['_error'] = 'no UPLOAD_DIR.';
+
+       } else { // ÅºÉÕ¥Õ¥¡¥¤¥ë
+               if (! is_dir(UPLOAD_DIR)) {
+                       $params['_error'] = 'No UPLOAD_DIR';
                        return $params;
                }
-               
-               //¥Ú¡¼¥¸»ØÄê¤Î¥Á¥§¥Ã¥¯
-//             $page = $vars['page'];
-               if (preg_match('/^(.+)\/([^\/]+)$/',$name,$matches))
-               {
-                       if ($matches[1] == '.' or $matches[1] == '..')
-                       {
+
+               // ¥Ú¡¼¥¸»ØÄê¤Î¥Á¥§¥Ã¥¯
+               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.';
+               $file = UPLOAD_DIR . encode($page) . '_' . encode($name);
+
+               if (! is_file($file)) {
+                       $params['_error'] = 'File not found';
                        return $params;
                }
-               $size = @getimagesize($file);
-               $is_image = (!$params['noimg'] and preg_match("/\.(gif|png|jpe?g)$/i",$name));
-               $width = $height = 0;
-               $url = $script.'?plugin=attach&amp;openfile='.rawurlencode($name).'&amp;refer='.rawurlencode($page);
-               if ($is_image)
-               {
+
+               $is_image = (! $params['noimg'] && preg_match(PLUGIN_REF_IMAGE, $name));
+
+               // 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;
-                       $url = $file;
-                       if (is_array($size))
-                       {
-                               $width = $size[0];
+
+                       // 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
-               {
-                       $info = get_date('Y/m/d H:i:s',filemtime($file) - LOCALZONE).' '.sprintf('%01.1f',round(filesize($file)/1000,1)).'KB';
+               } else {
+                       $info = get_date('Y/m/d H:i:s', filemtime($file) - LOCALZONE) .
+                               ' ' . sprintf('%01.1f', round(filesize($file)/1024, 1)) . 'KB';
                }
        }
-       
-       //³ÈÄ¥¥Ñ¥é¥á¡¼¥¿¤ò¥Á¥§¥Ã¥¯
-       if (count($params['_args']))
-       {
+
+       // ³ÈÄ¥¥Ñ¥é¥á¡¼¥¿¤ò¥Á¥§¥Ã¥¯
+       if (! empty($params['_args'])) {
                $_title = array();
-               foreach ($params['_args'] as $arg)
-               {
-                       if (preg_match('/^([0-9]+)x([0-9]+)$/',$arg,$m))
-                       {
+               foreach ($params['_args'] as $arg) {
+                       if (preg_match('/^([0-9]+)x([0-9]+)$/', $arg, $matches)) {
                                $params['_size'] = TRUE;
-                               $params['_w'] = $m[1];
-                               $params['_h'] = $m[2];
-                       }
-                       else if (preg_match('/^([0-9.]+)%$/',$arg,$m) and $m[1] > 0)
-                       {
-                               $params['_%'] = $m[1];
-                       }
-                       else
-                       {
+                               $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 (count($_title))
-               {
-                       $title = join(',', $_title);
-                       $title = $is_image ? htmlspecialchars($title) : make_line_rules(htmlspecialchars($title));
+
+               if (! empty($_title)) {
+                       $title = htmlspecialchars(join(',', $_title));
+                       if ($is_image) $title = make_line_rules($title);
                }
        }
-       
-       //²èÁü¥µ¥¤¥ºÄ´À°
-       if ($is_image)
-       {
+
+       // ²èÁü¥µ¥¤¥ºÄ´À°
+       if ($is_image) {
                // »ØÄꤵ¤ì¤¿¥µ¥¤¥º¤ò»ÈÍѤ¹¤ë
-               if ($params['_size'])
-               {
-                       if ($width == 0 and $height == 0)
-                       {
-                               $width = $params['_w'];
+               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;
+                       } 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);
+                               $zoom = max($_w, $_h);
+                               if ($zoom) {
+                                       $width  = (int)($width  / $zoom);
                                        $height = (int)($height / $zoom);
                                }
-                       }
-                       else
-                       {
-                               $width = $params['_w'] ? $params['_w'] : $width;
+                       } else {
+                               $width  = $params['_w'] ? $params['_w'] : $width;
                                $height = $params['_h'] ? $params['_h'] : $height;
                        }
                }
-               if ($params['_%'])
-               {
-                       $width = (int)($width * $params['_%'] / 100);
+               if ($params['_%']) {
+                       $width  = (int)($width  * $params['_%'] / 100);
                        $height = (int)($height * $params['_%'] / 100);
                }
-               if ($width and $height)
-               {
-                       $info = "width=\"$width\" height=\"$height\" ";
-               }
-       }
-       
-       //¥¢¥é¥¤¥ó¥á¥ó¥ÈȽÄê
-       if ($params['right'])
-       {
-               $params['_align'] = 'right';
-       }
-       else if ($params['left'])
-       {
-               $params['_align'] = 'left';
-       }
-       else if ($params['center'])
-       {
-               $params['_align'] = 'center';
-       }
-       else
-       {
-               $params['_align'] = REF_DEFAULT_ALIGN;
+               if ($width && $height) $info = "width=\"$width\" height=\"$height\" ";
        }
 
-       // ¥Õ¥¡¥¤¥ë¼ïÊÌȽÄê
-       if ($is_image)  // ²èÁü
-       {
-               $_url = "<img src=\"$url\" alt=\"$title\" title=\"$title\" $info/>";
-               if (!$params['nolink'] and $url2)
-               {
-                       $_url = "<a href=\"$url2\" title=\"$title\">$_url</a>";
+       // ¥¢¥é¥¤¥ó¥á¥ó¥ÈȽÄê
+       $params['_align'] = REF_DEFAULT_ALIGN;
+       foreach (array('right', 'left', 'center') as $align) {
+               if ($params[$align])  {
+                       $params['_align'] = $align;
+                       break;
                }
-               $params['_body'] = $_url;
        }
-       else    // Ä̾ï¥Õ¥¡¥¤¥ë
-       {
+
+       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 {
                $icon = $params['noicon'] ? '' : FILE_ICON;
                $params['_body'] = "<a href=\"$url\" title=\"$info\">$icon$title</a>";
        }
+
        return $params;
 }
 
-//-----------------------------------------------------------------------------
-//¥ª¥×¥·¥ç¥ó¤ò²òÀϤ¹¤ë
-function ref_check_arg($val, $_key, &$params)
+// ¥ª¥×¥·¥ç¥ó¤ò²òÀϤ¹¤ë
+function ref_check_arg($val, & $params)
 {
-       if ($val == '')
-       {
+       if ($val == '') {
                $params['_done'] = TRUE;
                return;
        }
-       if (!$params['_done'])
-       {
-               foreach (array_keys($params) as $key)
-               {
-                       if (strpos($key, strtolower($val)) === 0)
-                       {
+
+       if (! $params['_done']) {
+               foreach (array_keys($params) as $key) {
+                       if (strpos($key, strtolower($val)) === 0) {
                                $params[$key] = TRUE;
                                return;
                        }
                }
                $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;
+}
 ?>