예제 #1
0
function plugin_read_action()
{
    global $vars, $_title_invalidwn, $_msg_invalidiwn;
    $page = isset($vars['page']) ? $vars['page'] : '';
    if (is_page($page)) {
        // ページを表示
        check_readable($page, true, true);
        header_lastmod($page);
        return array('msg' => '', 'body' => '');
    } else {
        if (!PKWK_SAFE_MODE && is_interwiki($page)) {
            return do_plugin_action('interwiki');
            // InterWikiNameを処理
        } else {
            if (is_pagename($page)) {
                $vars['cmd'] = 'edit';
                return do_plugin_action('edit');
                // 存在しないので、編集フォームを表示
            } else {
                // 無効なページ名
                return array('msg' => $_title_invalidwn, 'body' => str_replace('$1', htmlsc($page), str_replace('$2', 'WikiName', $_msg_invalidiwn)));
            }
        }
    }
}
예제 #2
0
 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);
     }
 }
예제 #3
0
function plugin_read_action()
{
    global $vars, $_title_invalidwn, $_msg_invalidiwn;
    $page = isset($vars['page']) ? $vars['page'] : '';
    if (is_page($page)) {
        // ページを表示
        check_readable($page, true, true);
        header_lastmod($page);
        return array('msg' => '', 'body' => '');
        // } else if (! PKWK_SAFE_MODE && is_interwiki($page)) {
    } else {
        if (!auth::check_role('safemode') && is_interwiki($page)) {
            return do_plugin_action('interwiki');
            // InterWikiNameを処理
        } else {
            if (is_pagename($page)) {
                $realpages = get_autoaliases($page);
                if (count($realpages) == 1) {
                    $realpage = $realpages[0];
                    if (is_page($realpage)) {
                        header('HTTP/1.0 301 Moved Permanently');
                        header('Location: ' . get_page_location_uri($realpage));
                        return;
                    } elseif (is_url($realpage)) {
                        header('HTTP/1.0 301 Moved Permanently');
                        header('Location: ' . $realpage);
                        return;
                    } elseif (is_interwiki($realpage)) {
                        header('HTTP/1.0 301 Moved Permanently');
                        $vars['page'] = $realpage;
                        return do_plugin_action('interwiki');
                        // header('Location');
                    } else {
                        // 存在しない場合、直接編集フォームに飛ばす // To avoid infinite loop
                        header('Location: ' . get_location_uri('edit', $realpage));
                        return;
                    }
                } elseif (count($realpages) >= 2) {
                    $body = '<p>';
                    $body .= _('This pagename is an alias to') . '<br />';
                    $link = '';
                    foreach ($realpages as $realpage) {
                        $link .= '[[' . $realpage . '>' . $realpage . ']]&br;';
                    }
                    $body .= make_link($link);
                    $body .= '</p>';
                    return array('msg' => _('Redirect'), 'body' => $body);
                }
                $vars['cmd'] = 'edit';
                return do_plugin_action('edit');
                // 存在しないので、編集フォームを表示
            } else {
                // 無効なページ名
                return array('msg' => $_title_invalidwn, 'body' => str_replace('$1', htmlspecialchars($page), str_replace('$2', 'WikiName', $_msg_invalidiwn)));
            }
        }
    }
}
예제 #4
0
파일: read.inc.php 프로젝트: big2men/qhm
function plugin_read_action()
{
    global $vars, $script;
    global $post;
    $qm = get_qm();
    $qt = get_qt();
    $page = isset($vars['page']) ? $vars['page'] : '';
    //キャッシュを無効化
    if (isset($vars['word'])) {
        $qt->enable_cache = false;
    }
    if (is_page($page)) {
        // ページを表示
        check_readable($page, true, true);
        header_lastmod($page);
        return array('msg' => '', 'body' => '');
    } else {
        if (!PKWK_SAFE_MODE && is_interwiki($page)) {
            return do_plugin_action('interwiki');
            // InterWikiNameを処理
        } else {
            if (is_pagename($page)) {
                $vars['cmd'] = 'edit';
                // 編集権限があれば、編集モードへ。なければ、メッセージを表示
                $editable = edit_auth($page, FALSE, FALSE);
                if ($editable) {
                    return do_plugin_action('edit');
                    // 存在しないので、編集フォームを表示
                } else {
                    //404 NOT FOUND
                    header('HTTP/1.1 404 Not Found');
                    return array('msg' => $qm->m['fmt_err_notfoundpage_title'], 'body' => $qm->replace('fmt_err_notfoundpage', $script));
                }
            } else {
                //EUCエンコーディングかチェック
                if (mb_detect_encoding($post['page'], 'UTF-8,EUC-JP') == 'EUC-JP') {
                    $u_page = mb_convert_encoding($post['page'], 'UTF-8', 'EUC-JP');
                    $enc_page = rawurlencode($u_page);
                    //redirect
                    header("HTTP/1.1 301 Moved Permanently");
                    header('Location: ' . $script . '?' . $enc_page);
                    exit;
                }
                // 無効なページ名
                return array('msg' => $qm->m['fmt_title_invalidiwn'], 'body' => $qm->replace('fmt_err_invalidiwn', h($page), 'WikiName'));
            }
        }
    }
}
예제 #5
0
function is_pagename($str)
{
    global $BracketName;
    $is_pagename = !is_interwiki($str) && preg_match('/^(?!\\/)' . $BracketName . '$(?<!\\/$)/', $str) && !preg_match('#(^|/)\\.{1,2}(/|$)#', $str);
    if (defined('SOURCE_ENCODING')) {
        switch (SOURCE_ENCODING) {
            case 'UTF-8':
                $pattern = '/^(?:[\\x00-\\x7F]|(?:[\\xC0-\\xDF][\\x80-\\xBF])|(?:[\\xE0-\\xEF][\\x80-\\xBF][\\x80-\\xBF]))+$/';
                break;
            case 'EUC-JP':
                $pattern = '/^(?:[\\x00-\\x7F]|(?:[\\x8E\\xA1-\\xFE][\\xA1-\\xFE])|(?:\\x8F[\\xA1-\\xFE][\\xA1-\\xFE]))+$/';
                break;
        }
        if (isset($pattern) && $pattern != '') {
            $is_pagename = $is_pagename && preg_match($pattern, $str);
        }
    }
    return $is_pagename;
}
예제 #6
0
function is_pagename($str)
{
	global $BracketName,$WikiName;
	
	$is_pagename = (!is_interwiki($str) and preg_match("/^(?!\/)$BracketName$(?<!\/$)/",$str)
		and !preg_match('/(^|\/)\.{1,2}(\/|$)/',$str));
	
	if (defined('SOURCE_ENCODING'))
	{
		if (SOURCE_ENCODING == 'UTF-8')
		{
			$is_pagename = ($is_pagename and preg_match('/^(?:[\x00-\x7F]|(?:[\xC0-\xDF][\x80-\xBF])|(?:[\xE0-\xEF][\x80-\xBF][\x80-\xBF]))+$/',$str)); // UTF-8
		}
		else if (SOURCE_ENCODING == 'EUC-JP')
		{
			$is_pagename = ($is_pagename and preg_match('/^(?:[\x00-\x7F]|(?:[\x8E\xA1-\xFE][\xA1-\xFE])|(?:\x8F[\xA1-\xFE][\xA1-\xFE]))+$/',$str)); // EUC-JP
		}
	}
	
	return $is_pagename;
}
예제 #7
0
 /**
  * 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;
 }
예제 #8
0
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' . '&amp;refer=' . rawurlencode($page) . '&amp;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' . '&amp;page=' . rawurlencode($page) . '&amp;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;
}