<?php
-/////////////////////////////////////////////////
-// PukiWiki - Yet another WikiWikiWeb clone.
-//
-// $Id: ref.inc.php,v 1.35 2004/08/28 01:04:33 henoheno Exp $
+// PukiWiki - Yet another WikiWikiWeb clone
+// $Id: ref.inc.php,v 1.51 2011/01/25 15:01:01 henoheno Exp $
+// Copyright (C)
+// 2002-2006 PukiWiki Developers Team
+// 2001-2002 Originally written by yu-ji
+// License: GPL v2 or (at your option) any later version
//
+// Image refernce plugin
+// Include an attached image-file as an inline-image
+
+// 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 settings
+
+// Horizontal alignment
+define('PLUGIN_REF_DEFAULT_ALIGN', 'left'); // 'left', 'center', 'right'
+
+// Text wrapping
+define('PLUGIN_REF_WRAP_TABLE', FALSE); // TRUE, FALSE
+
+// URL»ØÄê»þ¤Ë²èÁü¥µ¥¤¥º¤ò¼èÆÀ¤¹¤ë¤«
+define('PLUGIN_REF_URL_GET_IMAGE_SIZE', FALSE); // FALSE, TRUE
// UPLOAD_DIR ¤Î¥Ç¡¼¥¿(²èÁü¥Õ¥¡¥¤¥ë¤Î¤ß)¤ËľÀÜ¥¢¥¯¥»¥¹¤µ¤»¤ë
define('PLUGIN_REF_DIRECT_ACCESS', FALSE); // FALSE or TRUE
// - ¥Ö¥é¥¦¥¶¤Ë¤è¤Ã¤Æ¤Ï¥¤¥ó¥é¥¤¥ó¥¤¥á¡¼¥¸¤Îɽ¼¨¤ä¡¢¡Ö¥¤¥ó¥é¥¤¥ó
// ¥¤¥á¡¼¥¸¤À¤±¤òɽ¼¨¡×¤µ¤»¤¿»þ¤Ê¤É¤ËÉÔ¶ñ¹ç¤¬½Ð¤ë¾ì¹ç¤¬¤¢¤ê¤Þ¤¹
-/*
-* ¥×¥é¥°¥¤¥ó 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)¤Î¤è¤¦¤Ë
-¥¿¥¤¥È¥ë¤ÎÁ°¤Ë¥«¥ó¥Þ¤ò;ʬ¤ËÆþ¤ì¤ë
-*/
-
-// Usage
-define('PLUGIN_REF_USAGE', "(attached-file-name[,page-name][,parameters][,title])");
+/////////////////////////////////////////////////
-// Image suffixes
+// Image suffixes allowed
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
-
-// URL»ØÄê»þ¤Ë²èÁü¥µ¥¤¥º¤ò¼èÆÀ¤¹¤ë¤«
-define('REF_URL_GETIMAGESIZE', FALSE);
+// Usage (a part of)
+define('PLUGIN_REF_USAGE', "([pagename/]attached-file-name[,parameters, ... ][,title])");
function plugin_ref_inline()
{
return "<p>#ref(): {$params['_error']}</p>\n";
}
- if ((REF_WRAP_TABLE && ! $params['nowrap']) || $params['wrap']) {
+ if ((PLUGIN_REF_WRAP_TABLE && ! $params['nowrap']) || $params['wrap']) {
// ÏȤÇÊñ¤à
// margin:auto
// Mozilla 1.x = x (wrap,around¤¬¸ú¤«¤Ê¤¤)
// źÉÕ¥Õ¥¡¥¤¥ë¤Î¤¢¤ë¥Ú¡¼¥¸: default¤Ï¸½ºß¤Î¥Ú¡¼¥¸Ì¾
$page = isset($vars['page']) ? $vars['page'] : '';
- // źÉÕ¥Õ¥¡¥¤¥ë̾
+ // źÉÕ¥Õ¥¡¥¤¥ë¤Î¥Õ¥¡¥¤¥ë̾
$name = '';
+ // źÉÕ¥Õ¥¡¥¤¥ë¤Þ¤Ç¤Î¥Ñ¥¹¤ª¤è¤Ó(¼ÂºÝ¤Î)¥Õ¥¡¥¤¥ë̾
+ $file = '';
+
// Âè°ì°ú¿ô: "[¥Ú¡¼¥¸Ì¾¤ª¤è¤Ó/]źÉÕ¥Õ¥¡¥¤¥ë̾"¡¢¤¢¤ë¤¤¤Ï"URL"¤ò¼èÆÀ
$name = array_shift($args);
$is_url = is_url($name);
}
$name = $matches[2];
$page = get_fullname(strip_bracket($matches[1]), $page); // strip is a compat
- $is_file = is_file(UPLOAD_DIR . encode($page) . '_' . encode($name));
+ $file = UPLOAD_DIR . encode($page) . '_' . encode($name);
+ $is_file = is_file($file);
// ÂèÆó°ú¿ô°Ê¹ß¤¬Â¸ºß¤·¡¢¤½¤ì¤Ïref¤Î¥ª¥×¥·¥ç¥ó̾¾Î¤Ê¤É¤È°ìÃפ·¤Ê¤¤
- } else if (isset($args[0]) && ! isset($params[$args[0]])) {
+ } else if (isset($args[0]) && $args[0] != '' && ! isset($params[$args[0]])) {
$e_name = encode($name);
// Try the second argument, as a page-name or a path-name
$_arg = get_fullname(strip_bracket($args[0]), $page); // strip is a compat
- $is_file_second = is_file(UPLOAD_DIR . encode($_arg) . '_' . $e_name);
+ $file = UPLOAD_DIR . encode($_arg) . '_' . $e_name;
+ $is_file_second = is_file($file);
// If the second argument is WikiName, or double-bracket-inserted pagename (compat)
$is_bracket_bracket = preg_match("/^($WikiName|\[\[$BracketName\]\])$/", $args[0]);
// Promote new design
if ($is_file_default && $is_file_second) {
// Because of race condition NOW
- $params['_error'] = htmlspecialchars('The same file name "' .
+ $params['_error'] = htmlsc('The same file name "' .
$name . '" at both page: "' . $page . '" and "' . $_arg .
- '". Try ref(pagename/filname) to specify one of them');
+ '". Try ref(pagename/filename) to specify one of them');
} else {
// Because of possibility of race condition, in the future
- $params['_error'] = 'This style is ambiguous and become obsolete. ' .
- 'Please try ref(pagename/filname)';
+ $params['_error'] = 'The style ref(filename,pagename) is ambiguous ' .
+ 'and become obsolete. ' .
+ 'Please try ref(pagename/filename)';
}
return $params;
}
} else {
// Simple single argument
- $is_file = is_file(UPLOAD_DIR . encode($page) . '_' . encode($name));
+ $file = UPLOAD_DIR . encode($page) . '_' . encode($name);
+ $is_file = is_file($file);
}
if (! $is_file) {
- $params['_error'] = htmlspecialchars('File not found: "' .
+ $params['_error'] = htmlsc('File not found: "' .
$name . '" at page "' . $page . '"');
return $params;
}
źÉÕ¥Õ¥¡¥¤¥ë¤Î¤È¤ : ¥Õ¥¡¥¤¥ë¤ÎºÇ½ª¹¹¿·Æü¤È¥µ¥¤¥º
URL¤Î¤È¤ : URL¤½¤Î¤â¤Î
*/
- $file = $title = $url = $url2 = $info = '';
+ $title = $url = $url2 = $info = '';
$width = $height = 0;
$matches = array();
if ($is_url) { // URL
- $url = $url2 = htmlspecialchars($name);
- $title = htmlspecialchars(preg_match('/([^\/]+)$/', $name, $matches) ? $matches[1] : $url);
+ if (PKWK_DISABLE_INLINE_IMAGE_FROM_URI) {
+ //$params['_error'] = 'PKWK_DISABLE_INLINE_IMAGE_FROM_URI prohibits this';
+ //return $params;
+ $url = htmlsc($name);
+ $params['_body'] = '<a href="' . $url . '">' . $url . '</a>';
+ return $params;
+ }
+
+ $url = $url2 = htmlsc($name);
+ $title = htmlsc(preg_match('/([^\/]+)$/', $name, $matches) ? $matches[1] : $url);
$is_image = (! $params['noimg'] && preg_match(PLUGIN_REF_IMAGE, $name));
- if ($is_image && REF_URL_GETIMAGESIZE && (bool)ini_get('allow_url_fopen')) {
+ if ($is_image && PLUGIN_REF_URL_GET_IMAGE_SIZE && (bool)ini_get('allow_url_fopen')) {
$size = @getimagesize($name);
if (is_array($size)) {
$width = $size[0];
} else { // źÉÕ¥Õ¥¡¥¤¥ë
- $title = htmlspecialchars($name);
+ $title = htmlsc($name);
$is_image = (! $params['noimg'] && preg_match(PLUGIN_REF_IMAGE, $name));
}
if (! empty($_title)) {
- $title = htmlspecialchars(join(',', $_title));
+ $title = htmlsc(join(',', $_title));
if ($is_image) $title = make_line_rules($title);
}
}
}
// ¥¢¥é¥¤¥ó¥á¥ó¥ÈȽÄê
- $params['_align'] = REF_DEFAULT_ALIGN;
+ $params['_align'] = PLUGIN_REF_DEFAULT_ALIGN;
foreach (array('right', 'left', 'center') as $align) {
if ($params[$align]) {
$params['_align'] = $align;
if (! isset($vars['page']) || ! isset($vars['src']))
return array('msg'=>'Invalid argument', 'body'=>$usage);
- $page = $vars['page'];
- $file = $vars['src'];
+ $page = $vars['page'];
+ $filename = $vars['src'] ;
- $ref = UPLOAD_DIR . encode($page) . '_' . encode(basename($file));
+ $ref = UPLOAD_DIR . encode($page) . '_' . encode(preg_replace('#^.*/#', '', $filename));
if(! file_exists($ref))
return array('msg'=>'Attach file not found', 'body'=>$usage);
return array('msg'=>'Seems not an image', 'body'=>$usage);
}
- // Output
- $file = htmlspecialchars($file);
+ // Care for Japanese-character-included file name
+ if (LANG == 'ja') {
+ switch(UA_NAME . '/' . UA_PROFILE){
+ case 'Opera/default':
+ // Care for using _auto-encode-detecting_ function
+ $filename = mb_convert_encoding($filename, 'UTF-8', 'auto');
+ break;
+ case 'MSIE/default':
+ $filename = mb_convert_encoding($filename, 'SJIS', 'auto');
+ break;
+ }
+ }
+ $file = htmlsc($filename);
$size = filesize($ref);
- header('Content-Disposition: inline; filename="' . $file . '"');
+
+ // Output
+ pkwk_common_headers();
+ header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Length: ' . $size);
header('Content-Type: ' . $type);
@readfile($ref);
-
exit;
}
?>