function plugin_siteimage_convert()
{
    global $link_target;
    $args = func_get_args();
    $url = array_shift($args);
    if (!is_url($url)) {
        return '<p>Usage: #siteimage([url],[option(s),...]);</p>';
    }
    $options = array('nolink' => false, 'around' => false, 'left' => false, 'right' => false, 'center' => false);
    get_plugin_option($args, &$options);
    $style = 'width:128px;height:128px;margin:10px;';
    if ($options['around']) {
        if ($options['right']) {
            $style .= 'float:right;margin-right:5px;';
        } else {
            $style .= 'float:left;margin-left:5px;';
        }
    } else {
        if ($options['right']) {
            $style .= 'margin-right:10px;margin-left:auto;';
        } else {
            if ($options['center']) {
                $style .= 'margin-right:auto;margin-left:auto;';
            } else {
                $style .= 'margin-right:auto;margin-left:10px;';
            }
        }
    }
    //	$img = plugin_siteimage_make($url, $options['nolink'], $options['target']);
    $img = plugin_siteimage_make($url, $options['nolink']);
    return '<div style="' . $style . '">' . $img . "</div>\n";
}
Esempio n. 2
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;
}