function plugin_lookup_action() { global $post; // Deny GET method to avlid GET loop $qm = get_qm(); $page = isset($post['page']) ? $post['page'] : ''; $inter = isset($post['inter']) ? $post['inter'] : ''; if ($page == '') { return FALSE; } // Do nothing if ($inter == '') { return array('msg' => $qm->m['plg_lookup']['err_invalid_access'], 'body' => ''); } $url = get_interwiki_url($inter, $page); if ($url === FALSE) { $msg = $qm->replace('fmt_err_iw_not_found', $inter); $msg = h($msg); return array('msg' => $qm->m['plg_lookup']['title_not_found'], 'body' => $msg); } pkwk_headers_sent(); header('Location: ' . $url); // Publish as GET method exit; }
function convert() { if (func_num_args() == 0) { return '<p>$this->plugin(): no argument(s). </p>'; } global $vars; $args = func_get_args(); $url = array_shift($args); if (!is_url($url) && is_interwiki($url)) { list($interwiki, $page) = explode(':', $url, 2); $url = get_interwiki_url($interwiki, $page); } $page = $vars['page']; if (!(PKWK_READONLY > 0 or is_freeze($page) or $this->is_edit_auth($page))) { if (!$this->accept($url)) { return "<p>{$this->plugin}(): The specified url, {$url}, is not allowed, modify iframe.inc.php<br />" . "Or, restrict editing of current page using freeze or edit_auth or PKWK_READONLY.</p>"; } } $url = htmlspecialchars($url); $options = array(); foreach ($args as $arg) { list($key, $val) = array_pad(explode('=', $arg, 2), 2, TRUE); $options[$key] = htmlspecialchars($val); } $style = isset($options['style']) ? $options['style'] : NULL; if (preg_match("/MSIE (3|4|5|6|7)/", getenv("HTTP_USER_AGENT"))) { $style = isset($options['iestyle']) ? $options['iestyle'] : $style; return $this->show_iframe($url, $style); } else { return $this->show_object($url, $style); } }
function plugin_interwiki_action() { global $vars, $InterWikiName; if (PKWK_SAFE_MODE) { die_message('InterWiki plugin is not allowed'); } $match = array(); if (!preg_match("/^{$InterWikiName}\$/", $vars['page'], $match)) { return plugin_interwiki_invalid(); } $url = get_interwiki_url($match[2], $match[3]); if ($url === FALSE) { return plugin_interwiki_invalid(); } pkwk_headers_sent(); header('Location: ' . $url); exit; }
function plugin_lookup_action() { global $post; // Deny GET method to avlid GET loop $page = isset($post['page']) ? $post['page'] : ''; $inter = isset($post['inter']) ? $post['inter'] : ''; if ($page == '') { return false; } // Do nothing if ($inter == '') { return array('msg' => 'Invalid access', 'body' => ''); } $url = get_interwiki_url($inter, $page); if ($url === false) { $msg = sprintf('InterWikiName "%s" not found', $inter); $msg = htmlsc($msg); return array('msg' => 'Not found', 'body' => $msg); } pkwk_headers_sent(); header('Location: ' . $url); // Publish as GET method exit; }
function set($arr, $page) { global $script; list(, $alias, , $name, $this->param) = $this->splice($arr); $matches = array(); if (preg_match('/^([^#]+)(#[A-Za-z][\\w-]*)$/', $this->param, $matches)) { list(, $this->param, $this->anchor) = $matches; } $url = get_interwiki_url($name, $this->param); $this->url = $url === FALSE ? $script . '?' . rawurlencode('[[' . $name . ':' . $this->param . ']]') : htmlspecialchars($url); return parent::setParam($page, htmlspecialchars($name . ':' . $this->param), '', 'InterWikiName', $alias == '' ? $name . ':' . $this->param : $alias); }
/** * Resolve InterWiki name * * PukiWiki API Extension * * @access public * @static * @param string $interwiki InterWiki string such as pukiwiki:PageName * @return string url * @uses is_url (PukiWiki lib/func.php) * @uses is_interwiki (PukiWiki lib/func.php) * @uses get_interwiki_url (PukiWiki lib/func.php) * @version $Id: v 1.0 2008-06-05 11:14:46 sonots $ */ function get_interwiki_url($interwiki) { if (is_url($interwiki) || !is_interwiki($interwiki)) { return false; } list($interwiki, $page) = explode(':', $interwiki, 2); $url = get_interwiki_url($interwiki, $page); return $url; }
function plugin_geshi_get_source($str) { if (strpos($str, ':') !== false) { if (preg_match('#^(https?|ftps?)://#', $str)) { $url = $str; } else { list($interwiki, $page) = explode(':', $str, 2); $url = get_interwiki_url($interwiki, $page); } $allowed = false; foreach ($GLOBALS['plugin_geshi_allowed_url'] as $pattern) { if (preg_match('#' . $pattern . '#', $url)) { $allowed = true; break; } } if ($allowed === true) { return file_get_contents($url); } } else { // TODO (Include local file) } return ''; }
function plugin_geshi_get_filename($str) { global $vars; // URL if (preg_match('#^(?:https?|ftps?)://#', $str)) { return $str; } // InterWikiName if (strpos($str, ':') > 0) { list($interwiki, $page) = explode(':', $str, 2); $url = get_interwiki_url($interwiki, $page); if ($url !== false) { return $url; } } // Attached file if (($pos = strrpos($str, '/')) === false) { $attachment = $str; $page = $vars['page']; } else { $attachment = substr($str, $pos + 1); $page = substr($str, 0, $pos); if ($page == '' || $page == '.' || $page == '..') { $page .= '/'; } $page = get_fullname($page, $vars['page']); } return UPLOAD_DIR . encode($page) . '_' . encode($attachment); }
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; }