/////////////////////////////////////////////////
// PukiWiki - Yet another WikiWikiWeb clone.
//
-// $Id: ref.inc.php,v 1.23 2004/07/31 03:09:20 henoheno Exp $
+// $Id: ref.inc.php,v 1.24 2004/08/18 13:14:53 henoheno Exp $
//
/*
-*¥×¥é¥°¥¤¥ó ref
+
+* ¥×¥é¥°¥¤¥ó ref
¥Ú¡¼¥¸¤ËźÉÕ¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤òŸ³«¤¹¤ë
URL¤òŸ³«¤¹¤ë
-*Usage
+* Usage
#ref(filename[,page][,parameters][,title])
-*¥Ñ¥é¥á¡¼¥¿
--filename~
-źÉÕ¥Õ¥¡¥¤¥ë̾¡¢¤¢¤ë¤¤¤ÏURL~
+* ¥Ñ¥é¥á¡¼¥¿
+- filename~
+źÉÕ¥Õ¥¡¥¤¥ë̾¡¢¤¢¤ë¤¤¤ÏURL
+
'¥Ú¡¼¥¸Ì¾/źÉÕ¥Õ¥¡¥¤¥ë̾'¤ò»ØÄꤹ¤ë¤È¡¢¤½¤Î¥Ú¡¼¥¸¤ÎźÉÕ¥Õ¥¡¥¤¥ë¤ò»²¾È¤¹¤ë
--page~
+
+- page~
¥Õ¥¡¥¤¥ë¤òźÉÕ¤·¤¿¥Ú¡¼¥¸Ì¾(¾Êά²Ä)~
--¥Ñ¥é¥á¡¼¥¿
---Left|Center|Right~
+
+- Left|Center|Right
²£¤Î°ÌÃÖ¹ç¤ï¤»
---Wrap|Nowrap~
+
+- Wrap|Nowrap
¥Æ¡¼¥Ö¥ë¥¿¥°¤Ç°Ï¤à/°Ï¤Þ¤Ê¤¤
--Around~
+
+- Around
¥Æ¥¥¹¥È¤Î²ó¤ê¹þ¤ß
--noicon~
+
+- noicon
¥¢¥¤¥³¥ó¤òɽ¼¨¤·¤Ê¤¤
--nolink~
+
+- nolink
¸µ¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯¤òÄ¥¤é¤Ê¤¤
--noimg~
+
+- noimg
²èÁü¤òŸ³«¤·¤Ê¤¤
--zoom~
+
+- zoom
½Ä²£Èæ¤òÊÝ»ý¤¹¤ë
--999x999~
+
+- 999x999
¥µ¥¤¥º¤ò»ØÄê(Éýx¹â¤µ)
--999%~
+
+- 999%
¥µ¥¤¥º¤ò»ØÄê(³ÈÂçΨ)
--¤½¤Î¾~
+
+- ¤½¤Î¾¤Îʸ»úÎó
img¤Îalt/href¤Îtitle¤È¤·¤Æ»ÈÍÑ~
¥Ú¡¼¥¸Ì¾¤ä¥Ñ¥é¥á¡¼¥¿¤Ë¸«¤¨¤ëʸ»úÎó¤ò»ÈÍѤ¹¤ë¤È¤¤Ï¡¢#ref(hoge.png,,zoom)¤Î¤è¤¦¤Ë
¥¿¥¤¥È¥ë¤ÎÁ°¤Ë¥«¥ó¥Þ¤ò;ʬ¤ËÆþ¤ì¤ë
+
*/
-// 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" />');
+// 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 '&ref(): No arguments;';
- $params = plugin_ref_body(func_get_args(),$vars['page']);
+ $params = plugin_ref_body(func_get_args(), $vars['page']);
- return ($params['_error'] != '') ? $params['_error'] : $params['_body'];
+ if (isset($params['_error']) && $params['_error'] != '') {
+ return '&ref(): ' . $params['_error'] . ';';
+ } else {
+ return $params['_body'];
+ }
}
+
function plugin_ref_convert()
{
global $vars;
- //¥¨¥é¡¼¥Á¥§¥Ã¥¯
- if (!func_num_args())
- {
- return '<p>no argument(s).</p>';
- }
+ if (! func_num_args()) return '<p>#ref(): No arguments</p>';
- $params = plugin_ref_body(func_get_args(),$vars['page']);
+ $params = plugin_ref_body(func_get_args(), $vars['page']);
- if ($params['_error'] != '')
- {
- return "<p>{$params['_error']}</p>";
+ if (isset($params['_error']) && $params['_error'] != '') {
+ return "<p>#ref(): {$params['_error']}</p>";
}
- 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
</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, $page)
{
- global $script,$WikiName,$BracketName;
+ global $script, $WikiName, $BracketName;
// Ìá¤êÃÍ
$params = array();
$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, // Ãæ±û´ó¤»
'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 $key=>$val) {
+ ref_check_arg($val, $key, $params);
}
}
*/
$file = $title = $url = $url2 = $info = '';
$width = $height = 0;
+ $matches = array();
- if (is_url($name)) //URL
- {
+ if (is_url($name)) { // URL
$url = $url2 = htmlspecialchars($name);
- $title = htmlspecialchars(preg_match('/([^\/]+)$/', $name, $match) ? $match[1] : $url);
+ $title = htmlspecialchars(preg_match('/([^\/]+)$/', $name, $matches) ? $matches[1] : $url);
+
+ $is_image = (! $params['noimg'] && preg_match("/\.(gif|png|jpe?g)$/i",$name));
- $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'))
- {
+ 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&openfile='.rawurlencode($name).'&refer='.rawurlencode($page);
- if ($is_image)
- {
+
+ $is_image = (! $params['noimg'] && preg_match('/\.(gif|png|jpe?g)$/i', $name));
+
+ $url = $script . '?plugin=attach' . '&refer=' . rawurlencode($page) .
+ '&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];
+ $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 ($width && $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 ($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, $_key, & $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;
}
?>