OSDN Git Service

cleanup, add $Id$.
authorpanda <panda>
Sun, 2 Mar 2003 02:39:01 +0000 (11:39 +0900)
committerpanda <panda>
Sun, 2 Mar 2003 02:39:01 +0000 (11:39 +0900)
plugin/ref.inc.php

index a21298d..e9c15c9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /*
-Last-Update:2003-01-09 rev.35
+ $Id: ref.inc.php,v 1.8 2003/03/02 02:39:01 panda Exp $
 
 *¥×¥é¥°¥¤¥ó ref
 ¥Ú¡¼¥¸¤ËźÉÕ¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤òŸ³«¤¹¤ë
@@ -22,12 +22,14 @@ Last-Update:2003-01-09 rev.35
 */
 
 // upload dir(must set end of /)
-if (!defined('UPLOAD_DIR')) {
+if (!defined('UPLOAD_DIR'))
+{
        define('UPLOAD_DIR','./attach/');
 }
 
 // file icon image
-if (!defined('FILE_ICON')) {
+if (!defined('FILE_ICON'))
+{
        define('FILE_ICON','<img src="./image/file.png" width="20" height="20" alt="file" style="border-width:0px" />');
 }
 
@@ -42,7 +44,8 @@ function plugin_ref_inline()
        global $vars;
        
        //¥¨¥é¡¼¥Á¥§¥Ã¥¯
-       if (!func_num_args()) {
+       if (!func_num_args())
+       {
                return 'no argument(s).';
        }
        
@@ -55,17 +58,20 @@ function plugin_ref_convert()
        global $vars;
 
        //¥¨¥é¡¼¥Á¥§¥Ã¥¯
-       if (!func_num_args()) {
+       if (!func_num_args())
+       {
                return '<p>no argument(s).</p>';
        }
        
        $params = plugin_ref_body(func_get_args(),$vars['page']);
        
-       if ($params['_error'] != '') {
+       if ($params['_error'] != '')
+       {
                return "<p>{$params['_error']}</p>";
        }
        
-       if ((REF_WRAP_TABLE and !$params['nowrap']) or $params['wrap']) {
+       if ((REF_WRAP_TABLE and !$params['nowrap']) or $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
@@ -80,10 +86,12 @@ function plugin_ref_convert()
 EOD;
        }
        // div¤ÇÊñ¤à
-       if ($params['around']) {
+       if ($params['around'])
+       {
                $style = ($params['_align'] == 'right') ? 'float:right' : 'float:left';
        }
-       else {
+       else
+       {
                $style = "text-align:{$params['_align']}";
        }
        return "<div class=\"img_margin\" style=\"$style\">{$params['_body']}</div>\n";
@@ -109,7 +117,6 @@ function plugin_ref_body($args,$page)
                        array_shift($args);
                }
        }
-
        
 /*
  $name¤ò¤â¤È¤Ë°Ê²¼¤ÎÊÑ¿ô¤òÀßÄê
@@ -124,49 +131,50 @@ function plugin_ref_body($args,$page)
        $file = $title = $url = $url2 = $info = $title = '';
        $width = $height = 0;
        
-       if (is_url($name)) {
-               //URL
-               
+       if (is_url($name))      //URL
+       {
                $url = htmlspecialchars($name);
                $title = preg_match('/([^\/]+)$/', $name, $match) ? $match[1] : $url;
                
                $is_image = preg_match("/\.(gif|png|jpe?g)$/i",$name);
-               if ($is_image) {
+               if ($is_image)
+               {
                        $size = getimagesize($name);
-                       if (is_array($size)) {
+                       if (is_array($size))
+                       {
                                $width = $size[0];
                                $height = $size[1];
                                $info = $size[3];
                        }
                }
-               else {
+               else
+               {
                        $info = $url;
                }
        }
-       else {
-               //źÉÕ¥Õ¥¡¥¤¥ë
-               if (!is_dir(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] == '.' or $matches[1] == '..')
+                       {
                                $matches[1] .= '/';
                        }
-                       if (function_exists('get_fullname')) {
-                               $page = get_fullname($matches[1],$page);
-                       }
-                       else {
-                               $page = $matches[1];
-                       }
+                       $page = get_fullname($matches[1],$page);
                        $name = $matches[2];
                }
                $title = $name;
                $file = UPLOAD_DIR.encode($page).'_'.encode($name);
-               if (!is_file($file)) {
+               if (!is_file($file))
+               {
                        $params['_error'] = 'file not found.';
                        return $params;
                }
@@ -174,15 +182,18 @@ function plugin_ref_body($args,$page)
                $is_image = 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) {
+               if ($is_image)
+               {
                        $url2 = $url;
                        $url = $file;
-                       if (is_array($size)) {
+                       if (is_array($size))
+                       {
                                $width = $size[0];
                                $height = $size[1];
                        }
                }
-               else {
+               else
+               {
                        $info = get_date('Y/m/d H:i:s',filemtime($file) - LOCALZONE).' '.sprintf('%01.1f',round(filesize($file)/1000,1)).'KB';
                }
        }
@@ -191,97 +202,123 @@ function plugin_ref_body($args,$page)
        $params = array('left'=>FALSE,'center'=>FALSE,'right'=>FALSE,'wrap'=>FALSE,'nowrap'=>FALSE,'around'=>FALSE,'noicon'=>FALSE,
                'zoom'=>FALSE,'size'=>FALSE,'w'=>0,'h'=>0,'%'=>0,'_args'=>array(),'_done'=>FALSE,'_error'=>'');
        
-       if (count($args) > 0) {
+       if (count($args) > 0)
+       {
                array_walk($args, 'ref_check_arg', &$params);
        }
        
        //³ÈÄ¥¥Ñ¥é¥á¡¼¥¿¤ò¥Á¥§¥Ã¥¯
-       if (count($params['_args'])) {
+       if (count($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,$m))
+                       {
                                $params['size'] = TRUE;
                                $params['w'] = $m[1];
                                $params['h'] = $m[2];
                        }
-                       else if (preg_match('/^([0-9.]+)%$/',$arg,$m) and $m[1] > 0) {
+                       else if (preg_match('/^([0-9.]+)%$/',$arg,$m) and $m[1] > 0)
+                       {
                                $params['%'] = $m[1];
                        }
-                       else {
+                       else
+                       {
                                $_title[] = $arg;
                        }
                }
-               if (count($_title)) {
+               if (count($_title))
+               {
                        $title2 = $title;
                        $title = join(',', $_title);
-                       if ($is_image) {
-                               if (is_url($title)) {
+                       if ($is_image)
+                       {
+                               if (is_url($title))
+                               {
                                        $url2 = $title;
                                        $title = $title2;
                                }
-                               else {
+                               else
+                               {
                                        $title = htmlspecialchars($title);
                                }
                        }
-                       else {
+                       else
+                       {
                                $title = make_user_rules($title);
                        }
                }
        }
        //²èÁü¥µ¥¤¥ºÄ´À°
-       if ($is_image) {
+       if ($is_image)
+       {
                // »ØÄꤵ¤ì¤¿¥µ¥¤¥º¤ò»ÈÍѤ¹¤ë
-               if ($params['size']) {
-                       if ($width == 0 and $height == 0) {
+               if ($params['size'])
+               {
+                       if ($width == 0 and $height == 0)
+                       {
                                $width = $params['w'];
                                $height = $params['h'];
                        }
-                       else if ($params['zoom']) {
+                       else if ($params['zoom'])
+                       {
                                $_w = $params['w'] ? $width / $params['w'] : 0;
                                $_h = $params['h'] ? $height / $params['h'] : 0;
                                $zoom = max($_w,$_h);
-                               if ($zoom) {
+                               if ($zoom)
+                               {
                                        $width = (int)($width / $zoom);
                                        $height = (int)($height / $zoom);
                                }
                        }
-                       else {
+                       else
+                       {
                                $width = $params['w'] ? $params['w'] : $width;
                                $height = $params['h'] ? $params['h'] : $height;
                        }
                }
-               if ($params['%']) {
+               if ($params['%'])
+               {
                        $width = (int)($width * $params['%'] / 100);
                        $height = (int)($height * $params['%'] / 100);
                }
-               if ($width and $height) {
+               if ($width and $height)
+               {
                        $info = "width=\"$width\" height=\"$height\"";
                }
        }
        
        //¥¢¥é¥¤¥ó¥á¥ó¥ÈȽÄê
-       if ($params['right']) {
+       if ($params['right'])
+       {
                $params['_align'] = 'right';
        }
-       else if ($params['left']) {
+       else if ($params['left'])
+       {
                $params['_align'] = 'left';
        }
-       else if ($params['center']) {
+       else if ($params['center'])
+       {
                $params['_align'] = 'center';
        }
-       else {
+       else
+       {
                $params['_align'] = REF_DEFAULT_ALIGN;
        }
 
        // ¥Õ¥¡¥¤¥ë¼ïÊÌȽÄê
-       if ($is_image) { // ²èÁü
+       if ($is_image)  // ²èÁü
+       {
                $_url = "<img src=\"$url\" alt=\"$title\" title=\"$title\" $info />";
-               if ($url2) {
+               if ($url2)
+               {
                        $_url = "<a href=\"$url2\" title=\"$title\">$_url</a>";
                }
                $params['_body'] = $_url;
        }
-       else { // Ä̾ï¥Õ¥¡¥¤¥ë
+       else    // Ä̾ï¥Õ¥¡¥¤¥ë
+       {
                $icon = $params['noicon'] ? '' : FILE_ICON;
                $params['_body'] = "<a href=\"$url\" title=\"$info\">$icon$title</a>\n";
        }
@@ -290,14 +327,19 @@ function plugin_ref_body($args,$page)
 
 //-----------------------------------------------------------------------------
 //¥ª¥×¥·¥ç¥ó¤ò²òÀϤ¹¤ë
-function ref_check_arg($val, $_key, &$params) {
-       if ($val == '') {
+function ref_check_arg($val, $_key, &$params)
+{
+       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;
                        }