function toString() { $body = $this->body == '' ? '' : make_link($this->body); $str = FALSE; // Try to call the plugin if (exist_plugin_inline($this->name)) { $str = do_plugin_inline($this->name, $this->param, $body); } if ($str !== FALSE) { return $str; // Succeed } else { // No such plugin, or Failed $body = ($body == '' ? '' : '{' . $body . '}') . ';'; return make_line_rules(htmlspecialchars('&' . $this->plain) . $body); } }
function plugin_ref2_body($args) { global $script, $vars; global $WikiName, $BracketName; // compat $qm = get_qm(); // 戻り値 $params = array('left' => FALSE, 'center' => FALSE, 'right' => FALSE, 'wrap' => FALSE, 'nowrap' => FALSE, 'around' => FALSE, 'noicon' => FALSE, 'nolink' => FALSE, 'noimg' => FALSE, 'zoom' => FALSE, 'change' => FALSE, '_size' => FALSE, '_w' => 0, '_h' => 0, '_%' => 0, '_args' => array(), '_done' => FALSE, '_error' => ''); // 添付ファイルのあるページ: defaultは現在のページ名 $page = isset($vars['page']) ? $vars['page'] : ''; // 添付ファイルのファイル名 $name = ''; // 添付ファイルまでのパスおよび(実際の)ファイル名 $file = ''; // 第一引数: "[ページ名および/]添付ファイル名"、あるいは"URL"を取得 $name = array_shift($args); $is_url = is_url($name); if (!$is_url) { $is_file = is_file($name); $file = $name; if (!$is_file) { $params['_error'] = $qm->replace('plg_ref2.err_notfound', h($name)); return $params; } } // 残りの引数の処理 if (!empty($args)) { foreach ($args as $arg) { ref2_check_arg($arg, $params); } } /* $nameをもとに以下の変数を設定 $url,$url2 : URL $title :タイトル $is_image : 画像のときTRUE $info : 画像ファイルのときgetimagesize()の'size' 画像ファイル以外のファイルの情報 添付ファイルのとき : ファイルの最終更新日とサイズ URLのとき : URLそのもの */ $title = $url = $url2 = $info = ''; $width = $height = 0; $matches = array(); if ($is_url) { // URL if (PKWK_DISABLE_INLINE_IMAGE_FROM_URI) { //$params['_error'] = 'PKWK_DISABLE_INLINE_IMAGE_FROM_URI prohibits this'; //return $params; $url = h($name); $params['_body'] = '<a href="' . $url . '">' . $url . '</a>'; return $params; } $url = $url2 = h($name); $title = h(preg_match('/([^\\/]+)$/', $name, $matches) ? $matches[1] : $url); $is_image = !$params['noimg'] && preg_match(PLUGIN_REF2_IMAGE, $name); if ($is_image && PLUGIN_REF2_URL_GET_IMAGE_SIZE && (bool) ini_get('allow_url_fopen')) { $size = @getimagesize($name); if (is_array($size)) { $width = $size[0]; $height = $size[1]; $info = $size[3]; } } } else { // 添付ファイル $title = htmlspecialchars($name); $is_image = !$params['noimg'] && preg_match(PLUGIN_REF2_IMAGE, $name); // Count downloads with attach plugin $url = $script . '?plugin=attach' . '&refer=' . rawurlencode($page) . '&openfile=' . rawurlencode($name); // Show its filename at the last if ($is_image) { $url = $url2 = $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) / 1024, 1)) . 'KB'; } } // 拡張パラメータをチェック 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 ($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}\" "; } } // アラインメント判定 $params['_align'] = PLUGIN_REF2_DEFAULT_ALIGN; foreach (array('right', 'left', 'center') as $align) { if ($params[$align]) { $params['_align'] = $align; break; } } if ($is_image) { // 画像 $mouseover = ''; if ($params['change']) { $a_path = explode('.', $url); $a_path[count($a_path) - 2] .= '_onmouse'; $mo_url = implode('.', $a_path); $mouseover = " onMouseOver=\"this.src='{$mo_url}'\" onMouseOut=\"this.src='{$url}'\" "; } $params['_body'] = "<img src=\"{$url}\" alt=\"{$title}\" title=\"{$title}\" {$info} {$mouseover}/>"; 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 plugin_show_body($args) { global $script, $vars; global $WikiName, $BracketName; // compat $qm = get_qm(); $qt = get_qt(); $qt->setv('jquery_include', true); // 戻り値 $params = array('left' => FALSE, 'center' => FALSE, 'right' => FALSE, 'aroundl' => FALSE, 'aroundc' => FALSE, 'aroundr' => FALSE, 'wrap' => FALSE, 'nowrap' => FALSE, 'around' => FALSE, 'noicon' => FALSE, 'nolink' => TRUE, 'greybox' => FALSE, 'lightbox2' => FALSE, 'colorbox' => FALSE, 'normal' => FALSE, 'linkurl' => FALSE, 'label' => FALSE, 'crop' => TRUE, 'nocrop' => FALSE, 'noimg' => FALSE, 'zoom' => FALSE, 'change' => FALSE, '_size' => FALSE, '_w' => 0, '_h' => 0, '_%' => 0, '_ratio' => FALSE, '_args' => array(), '_done' => FALSE, '_error' => '', '_block' => FALSE); $is_bootstrap_skin = is_bootstrap_skin(); $bs_image_deco = array('circle' => FALSE, 'rounded' => FALSE, 'round' => FALSE, 'thumbnail' => FALSE, 'pola' => FALSE, 'polaroid ' => FALSE); if ($is_bootstrap_skin) { foreach ($bs_image_deco as $key => $val) { $params[$key] = $val; } } // 添付ファイルのあるページ: defaultは現在のページ名 $page = isset($vars['page']) ? $vars['page'] : ''; // 添付ファイルのファイル名 $name = ''; // 添付ファイルまでのパスおよび(実際の)ファイル名 $file = ''; // 第一引数: "画像ファイル名"、あるいは"画像ファイルパス"、あるいは"画像ファイルURL"を指定 $name = array_shift($args); $is_url = is_url($name, false, true); //画像ファイルかどうか if (!preg_match(PLUGIN_SHOW_IMAGE, $name)) { $params['_error'] = $qm->replace('plg_show.err_noimg', h($name)); } if (!$is_url) { $file = $name; if (!is_file($file)) { $file = SWFU_IMAGE_DIR . $file; if (!is_file($file)) { $params['_error'] = $qm->replace('plg_show.err_notfound', h($name)); return $params; } } } // 残りの引数の処理 if (!empty($args)) { foreach ($args as $arg) { plugin_show_check_arg($arg, $params); } } if (is_page($params['linkurl'])) { $params['linkurl'] = $script . '?' . rawurlencode($params['linkurl']); } /* $nameをもとに以下の変数を設定 $url,$url2 : URL $title :タイトル $info : 画像ファイルのときgetimagesize()の'size' 画像ファイル以外のファイルの情報 添付ファイルのとき : ファイルの最終更新日とサイズ URLのとき : URLそのもの */ $title = $url = $url2 = $info = $style = ''; $width = $height = 0; $matches = array(); if ($is_url) { // URL if (PKWK_DISABLE_INLINE_IMAGE_FROM_URI) { $url = h($name); $params['_body'] = '<a href="' . $url . '">' . $url . '</a>'; return $params; } $url = $url2 = h($name); $title = h(preg_match('/\\/(.+?)$/', $name, $matches) ? $matches[1] : $url); if (PLUGIN_SHOW_URL_GET_IMAGE_SIZE && (bool) ini_get('allow_url_fopen')) { $size = @getimagesize($name); if (is_array($size)) { $width = $size[0]; $height = $size[1]; $info = $size[3]; } } } else { // 添付ファイル $title = h($name); /* // Count downloads with attach plugin $url = $script . '?plugin=attach' . '&refer=' . rawurlencode($page) . '&openfile=' . rawurlencode($name); // Show its filename at the last */ $file = substr($file, 0, 2) == './' ? substr($file, 2) : $file; $url = $url2 = $file; $width = $height = 0; $size = @getimagesize($file); if (is_array($size)) { $width = $size[0]; $height = $size[1]; } } //first Image をセット $qt->set_first_image($is_url ? $url : dirname($script) . '/' . $url); // 拡張パラメータをチェック 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 = h(join(',', $_title)); $title = make_line_rules($title); } } // 画像サイズ調整 // 指定されたサイズを使用する 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['nocrop']) { $params['crop'] = FALSE; } if ($params['crop']) { $params['class'] .= ' qhm-show-crop'; plugin_show_set_crop_style(); } } if ($params['_%']) { $width = (int) ($width * $params['_%'] / 100); $height = (int) ($height * $params['_%'] / 100); } if ($params['_size'] or $params['_%']) { if ($width && $height) { $info = "width=\"{$width}\" height=\"{$height}\" "; // 表示領域が画像の幅よりも小さい場合 // 縦横日が崩れるので修正する JavaScript を出力する $params['class'] .= ' qhm-plugin-show-keep-ratio'; $params['class'] .= $params['_size'] ? ' qhm-plugin-show-size-given' : ''; plugin_show_set_keep_ratio(); } } if ($is_bootstrap_skin) { $params['class'] .= $params['_block'] ? ' img-responsive' : ''; } else { $style = 'style="max-width:100%;" '; } // アラインメント判定 $params['_align'] = PLUGIN_SHOW_DEFAULT_ALIGN; foreach (array('right', 'left', 'center', 'aroundr', 'aroundc', 'aroundl') as $align) { //aroundx if (strpos($align, 'around') === 0 && $params[$align]) { $params['around'] = TRUE; $align = substr($align, -1, 1); switch ($align) { case 'r': $align = 'right'; break; case 'c': $align = 'center'; break; default: $align = 'left'; } $params['_align'] = $align; break; } else { if ($params[$align]) { $params['_align'] = $align; break; } } } $mouseover = ''; if ($params['change']) { $a_path = explode('.', $url); $a_path[count($a_path) - 2] .= '_onmouse'; $mo_url = join('.', $a_path); $mouseover = " onmouseover=\"this.src='{$mo_url}'\" onmouseout=\"this.src='{$url}'\" "; $mouseover .= 'onload="qhm_preload(\'' . $mo_url . '\');"'; //preload $addscript = ' <script type="text/javascript"> var qhm_preloaded = {}; function qhm_preload(src) { if (typeof document.images != "undefined" && typeof qhm_preloaded[src] == "undefined") { var img = new Image(); img.src = src; qhm_preloaded[src] = 1; } } </script> '; $qt->appendv_once('plugin_show_preload', 'beforescript', $addscript); } $aclass = $arel = ''; $url2 = $params['linkurl'] ? $params['linkurl'] : $url2; //異なるURLが2つある場合、nolink をFALSEに if ($url2 != $url) { $params['nolink'] = FALSE; } //表示設定 if ($params['greybox']) { $addscript = ' <script type="text/javascript"> var GB_ROOT_DIR = "./plugin/greybox/"; </script> <script type="text/javascript" src="./plugin/greybox/AJS.js"></script> <script type="text/javascript" src="./plugin/greybox/AJS_fx.js"></script> <script type="text/javascript" src="./plugin/greybox/gb_scripts.js"></script> <link href="./plugin/greybox/gb_styles.css" rel="stylesheet" type="text/css" /> '; $qt->appendv_once('plugin_greybox', 'beforescript', $addscript); //文字列の場合:グループ if ($params['greybox'] !== TRUE) { $gb_type = $url == $url2 ? 'imageset' : 'pageset'; $gb_grp = $params['greybox']; $arel = ' rel="gb_' . $gb_type . '[' . $gb_grp . ']"'; } else { $gb_type = $url == $url2 ? 'image' : 'page_fs'; $arel = ' rel="gb_' . $gb_type . '[]"'; } $params['nolink'] = FALSE; } else { if ($params['lightbox2']) { require_once PLUGIN_DIR . '/lightbox2.inc.php'; $addscript = ' <script type="text/javascript" src="js/jquery.dimensions.min.js"></script> <script type="text/javascript" src="js/jquery.dropshadow.js"></script> <script type="text/javascript" src="' . LIGHTBOX2_LIB . '/js/jquery.lightbox.js"></script> <link href="' . LIGHTBOX2_LIB . '/css/lightbox.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $(document).ready(function(){ $(".lightbox").lightbox(); }); </script> '; $qt->appendv_once('plugin_lightbox2', 'beforescript', $addscript); $aclass = ' class="lightbox"'; if ($params['lightbox2'] !== TRUE) { $arel = ' rel="' . $params['lightbox2'] . '"'; } //$url2 が画像ファイルでない場合、無効にする|エラーを出す if (!preg_match(PLUGIN_SHOW_IMAGE, $url2)) { $url2 = $url; // $params['_error'] = 'lightbox2 cannot show except images'; } $params['nolink'] = FALSE; } else { if ($params['colorbox']) { $addscript = ' <script type="text/javascript" src="./plugin/colorbox/jquery.colorbox-min.js"></script> <link href="./plugin/colorbox/colorbox.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $(function(){ var options = { opacity:0.5, current: "{current}/{total}", maxWidth: "100%", maxHeight: "90%" }; var slideshowOptions = $.extend({}, options, { opacity: 0.8, slideshow: true }); $("a.colorbox").colorbox(options); $("a.colorbox_slideshow").colorbox(slideshowOptions); }); </script> '; $qt->appendv_once('plugin_show_colorbox', 'beforescript', $addscript); //文字列の場合:グループ //グループ名がslideshow で始まる場合、スライドショー if (substr($params['colorbox'], 0, 9) === 'slideshow') { $aclass = ' class="colorbox_slideshow"'; $gb_grp = $params['colorbox']; $arel = ' rel="cb_' . $gb_grp . '"'; } else { if ($params['colorbox'] !== TRUE) { $gb_type = $url == $url2 ? 'imageset' : 'pageset'; $gb_grp = $params['colorbox']; $arel = ' rel="cb_' . $gb_grp . '"'; $aclass = ' class="colorbox"'; } else { $aclass = ' class="colorbox"'; // } } $params['nolink'] = FALSE; } else { if ($params['normal']) { $params['nolink'] = FALSE; } } } } if ($is_bootstrap_skin) { $img_thumbnail = false; $img_rounded = false; $img_circle = false; foreach (array_keys($bs_image_deco) as $deco) { if (isset($params[$deco]) && $params[$deco] !== FALSE) { switch ($deco) { case 'pola': case 'polaroid': case 'thumbnail': if (!$img_thumbnail) { $params['class'] .= ' img-thumbnail'; $img_thumbnail = true; } break; case 'round': case 'rounded': if (!$img_rounded) { $params['class'] .= ' img-rounded'; $img_rounded = true; } break; case 'circle': if (!$img_circle) { $params['class'] .= ' img-circle'; $img_circle = true; } break; } } } } //指定されたクラスを追加する $imgclass = ' class="' . h($params['class']) . '"'; if ($params['label'] !== FALSE && $params['label'] != '') { //画像を指定した場合、画像を表示する if (preg_match('/\\.(jpe?g|gif|png)$/', $params['label'])) { $url = plugin_show_get_filepath($params['label']); $size = plugin_show_get_imagesize($params['label']); //高さと幅を指定している場合はそちらを利用する if ($params['_w'] === 0 && $params['_h'] === 0 && $size !== FALSE) { $info = ''; if (is_array($size)) { $width = $size[0]; $height = $size[1]; if ($params['_%'] !== 0) { $width = floor($width * $params['_%'] / 100); $height = floor($height * $params['_%'] / 100); } $info = "width=\"{$width}\" height=\"{$height}\""; } $params['_body'] = "<img src=\"{$url}\" alt=\"{$title}\" title=\"{$title}\" {$info} {$mouseover} {$style}{$imgclass}{$ratio_attr}>"; } $params['_body'] = "<img src=\"{$url}\" alt=\"{$title}\" title=\"{$title}\" {$info} {$mouseover} {$style}{$imgclass}{$ratio_attr}>"; } else { $params['_body'] = h($params['label']); } } else { $params['_body'] = "<img src=\"{$url}\" alt=\"{$title}\" title=\"{$title}\" {$info} {$mouseover} {$style}{$imgclass}{$ratio_attr}>"; } if (!$params['nolink'] && $url2) { $params['_body'] = "<a href=\"{$url2}\" title=\"{$title}\"{$aclass}{$arel}>{$params['_body']}</a>"; } return $params; }
function plugin_ref_body($args) { global $script, $vars; global $WikiName, $BracketName; // compat $qm = get_qm(); // 戻り値 $params = array('left' => FALSE, 'center' => FALSE, 'right' => FALSE, 'wrap' => FALSE, 'nowrap' => FALSE, 'around' => FALSE, 'noicon' => FALSE, 'nolink' => FALSE, 'noimg' => FALSE, 'zoom' => FALSE, '_size' => FALSE, '_w' => 0, '_h' => 0, '_%' => 0, '_args' => array(), '_done' => FALSE, '_error' => ''); // 添付ファイルのあるページ: defaultは現在のページ名 $page = isset($vars['page']) ? $vars['page'] : ''; // 添付ファイルのファイル名 $name = ''; // 添付ファイルまでのパスおよび(実際の)ファイル名 $file = ''; // 第一引数: "[ページ名および/]添付ファイル名"、あるいは"URL"を取得 $name = array_shift($args); $is_url = is_url($name); if (!$is_url) { // 添付ファイル if (!is_dir(UPLOAD_DIR)) { $params['_error'] = $qm->m['plg_ref']['err_no_dir']; return $params; } $matches = array(); // ファイル名にページ名(ページ参照パス)が合成されているか // (Page_name/maybe-separated-with/slashes/ATTACHED_FILENAME) if (preg_match('#^(.+)/([^/]+)$#', $name, $matches)) { if ($matches[1] == '.' || $matches[1] == '..') { $matches[1] .= '/'; // Restore relative paths } $name = $matches[2]; $page = get_fullname(strip_bracket($matches[1]), $page); // strip is a compat $file = UPLOAD_DIR . encode($page) . '_' . encode($name); $is_file = is_file($file); // 第二引数以降が存在し、それはrefのオプション名称などと一致しない } 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 $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]); if ($is_file_second && $is_bracket_bracket) { // Believe the second argument (compat) array_shift($args); $page = $_arg; $is_file = TRUE; } else { // Try default page, with default params $is_file_default = is_file(UPLOAD_DIR . encode($page) . '_' . $e_name); // Promote new design if ($is_file_default && $is_file_second) { // Because of race condition NOW $params['_error'] = $qm->replace('plg_ref.err_dup_fname', h($name), h($page), h($_arg)); } else { // Because of possibility of race condition, in the future $params['_error'] = $qm->m['plg_ref']['err_ambiguous']; } return $params; } } else { // Simple single argument $file = UPLOAD_DIR . encode($page) . '_' . encode($name); $is_file = is_file($file); } } if (!$is_file) { $params['_error'] = $qm->replace('plg_ref.err_notfound', h($name), h($page)); return $params; } } // 残りの引数の処理 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そのもの */ $title = $url = $url2 = $info = ''; $width = $height = 0; $matches = array(); if ($is_url) { // URL if (PKWK_DISABLE_INLINE_IMAGE_FROM_URI) { //$params['_error'] = 'PKWK_DISABLE_INLINE_IMAGE_FROM_URI prohibits this'; //return $params; $url = htmlspecialchars($name); $params['_body'] = '<a href="' . $url . '">' . $url . '</a>'; return $params; } $url = $url2 = htmlspecialchars($name); $title = htmlspecialchars(preg_match('/([^\\/]+)$/', $name, $matches) ? $matches[1] : $url); $is_image = !$params['noimg'] && preg_match(PLUGIN_REF_IMAGE, $name); 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]; $height = $size[1]; $info = $size[3]; } } } else { // 添付ファイル $title = htmlspecialchars($name); $is_image = !$params['noimg'] && preg_match(PLUGIN_REF_IMAGE, $name); // Count downloads with attach plugin $url = $script . '?plugin=attach' . '&refer=' . rawurlencode($page) . '&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' . '&page=' . rawurlencode($page) . '&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) / 1024, 1)) . 'KB'; } } // 拡張パラメータをチェック 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 ($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}\" "; } } // アラインメント判定 $params['_align'] = PLUGIN_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 { $icon = $params['noicon'] ? '' : FILE_ICON; $params['_body'] = "<a href=\"{$url}\" title=\"{$info}\">{$icon}{$title}</a>"; } return $params; }
function toString() { $body = ($this->body == '') ? '' : make_link($this->body); // プラグイン呼び出し if (exist_plugin_inline($this->name)) { $str = do_plugin_inline($this->name,$this->param,$body); if ($str !== FALSE) //成功 { return $str; } } // プラグインが存在しないか、変換に失敗 return make_line_rules(htmlspecialchars('&'.$this->plain).($body == '' ? ';' : "\{$body};")); }
function plugin_ref_body($args) { global $script, $vars; global $WikiName, $BracketName; // compat // 戻り値 $params = array('left' => FALSE, 'center' => FALSE, 'right' => FALSE, 'wrap' => FALSE, 'nowrap' => FALSE, 'around' => FALSE, 'noicon' => FALSE, 'nolink' => FALSE, 'noimg' => FALSE, 'nomargin' => FALSE, 'zoom' => FALSE, '_size' => FALSE, '_w' => 0, '_h' => 0, '_%' => 0, '_args' => array(), '_done' => FALSE, '_error' => ''); // 添付ファイルのあるページ: defaultは現在のページ名 $page = isset($vars['page']) ? $vars['page'] : ''; // 添付ファイルのファイル名 $name = ''; // 添付ファイルまでのパスおよび(実際の)ファイル名 $file = ''; // 第一引数: "[ページ名および/]添付ファイル名"、あるいは"URL"を取得 $name = array_shift($args); $is_url = is_url($name); // 第一引数が InterWiki か if (is_interwiki($name)) { global $InterWikiName; preg_match("/^{$InterWikiName}\$/", $name, $intermatch); $intername = $intermatch[2]; $interparam = $intermatch[3]; $interurl = get_interwiki_url($intername, $interparam); if ($interurl !== FALSE) { $name = $interurl; $is_url = is_url($name); } } if (!$is_url) { // 添付ファイル if (!is_dir(UPLOAD_DIR)) { $params['_error'] = 'No UPLOAD_DIR'; return $params; } $matches = array(); // ファイル名にページ名(ページ参照パス)が合成されているか // (Page_name/maybe-separated-with/slashes/ATTACHED_FILENAME) if (preg_match('#^(.+)/([^/]+)$#', $name, $matches)) { if ($matches[1] == '.' || $matches[1] == '..') { $matches[1] .= '/'; // Restore relative paths } $name = $matches[2]; $page = get_fullname(strip_bracket($matches[1]), $page); // strip is a compat $file = UPLOAD_DIR . encode($page) . '_' . encode($name); $is_file = is_file($file); // 第二引数以降が存在し、それはrefのオプション名称などと一致しない } 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 $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]); if ($is_file_second && $is_bracket_bracket) { // Believe the second argument (compat) array_shift($args); $page = $_arg; $is_file = TRUE; } else { // Try default page, with default params $is_file_default = is_file(UPLOAD_DIR . encode($page) . '_' . $e_name); // Promote new design if ($is_file_default && $is_file_second) { // Because of race condition NOW $params['_error'] = htmlspecialchars('The same file name "' . $name . '" at both page: "' . $page . '" and "' . $_arg . '". Try ref(pagename/filename) to specify one of them'); } else { // Because of possibility of race condition, in the future // BugTrack2/163 $params['_error'] = 'The style ref(filename,pagename) is ambiguous ' . 'and become obsolete. ' . 'Please try ref(pagename/filename)'; } return $params; } } else { // Simple single argument $file = UPLOAD_DIR . encode($page) . '_' . encode($name); $is_file = is_file($file); } } if (!$is_file) { $params['_error'] = htmlspecialchars('File not found: "' . $name . '" at page "' . $page . '"'); return $params; } } // 残りの引数の処理 if (!empty($args)) { get_plugin_option($args, $params); } /* $nameをもとに以下の変数を設定 $url,$url2 : URL $title :タイトル $is_image : 画像のときTRUE $info : 画像ファイルのときgetimagesize()の'size' 画像ファイル以外のファイルの情報 添付ファイルのとき : ファイルの最終更新日とサイズ URLのとき : URLそのもの */ $title = $url = $url2 = $info = ''; $rawwidth = $rawheight = 0; $width = $height = 0; $matches = array(); if ($is_url) { // URL if (PKWK_DISABLE_INLINE_IMAGE_FROM_URI) { //$params['_error'] = 'PKWK_DISABLE_INLINE_IMAGE_FROM_URI prohibits this'; //return $params; $url = htmlspecialchars($name); $params['_body'] = '<a href="' . $url . '">' . $url . '</a>'; return $params; } $url = $url2 = htmlspecialchars($name); $title = htmlspecialchars(preg_match('/([^\\/]+)$/', $name, $matches) ? $matches[1] : $url); $is_image = !$params['noimg'] && preg_match(PLUGIN_REF_IMAGE, $name); if ($is_image && PLUGIN_REF_URL_GET_IMAGE_SIZE && (bool) ini_get('allow_url_fopen')) { $size = @getimagesize($name); if (is_array($size)) { $rawwidth = $width = $size[0]; $rawheight = $height = $size[1]; $info = $size[3]; } } } else { // 添付ファイル $title = htmlspecialchars($name); $is_image = !$params['noimg'] && preg_match(PLUGIN_REF_IMAGE, $name); // Count downloads with attach plugin $url = $script . '?plugin=attach' . '&refer=' . rawurlencode($page) . '&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' . '&page=' . rawurlencode($page) . '&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)) { $rawwidth = $width = $size[0]; $rawheight = $height = $size[1]; } } else { $info = get_date('Y/m/d H:i:s', filemtime($file)) . ' ' . sprintf('%01.1f', round(filesize($file) / 1024, 1)) . 'KB'; } } // 拡張パラメータをチェック 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 ($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 . '" '; } } // Check alignment $params['_align'] = PLUGIN_REF_DEFAULT_ALIGN; foreach (array('right', 'left', 'center') as $align) { if ($params[$align]) { $params['_align'] = $align; break; } } if ($is_image) { // DoCoMo recommended picture size is 128x128 // http://www.nttdocomo.co.jp/p_s/imode/xhtml/s1.html#1_4_2 if (defined('UA_MOBILE') && UA_MOBILE != 0) { if ($rawwidth > 0 && $rawheight > 0 && $rawwidth <= 128 && $rawheight <= 128 && PLUGIN_REF_SHOW_IMAGE_TO_MOBILEPHONE) { $params['_body'] = '<img src="' . $url . '" alt="' . $title . '" title="keitai" ' . $info . '/>'; } else { $params['_body'] = '<a href="' . $url . '" title="keitai">[PHOTO:' . $title . ']</a>'; } } else { $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; if (defined('PLUGIN_REF_DOWNLOAD_OTHER_WINDOW') && PLUGIN_REF_DOWNLOAD_OTHER_WINDOW) { $params['_body'] = '<a href="' . $url . '" title="' . $info . '" onclick="return open_attach_uri(' . "'" . $url . "', '_blank'" . ');">' . $icon . $title . '</a>'; } else { $params['_body'] = '<a href="' . $url . '" title="' . $info . '">' . $icon . $title . '</a>'; } } return $params; }