Beispiel #1
0
/**
 * PukiWiki Plus! Anchor Plugin
 *
 * @copyright   Copyright &copy; 2008, Katsumi Saito <*****@*****.**>
 * @version     $Id: a.inc.php,v 0.2 2008/02/24 18:47:00 upk Exp $
 * @license     http://opensource.org/licenses/gpl-license.php GNU Public License (GPL2)
 *
 */
function plugin_a_inline()
{
    global $_symbol_innanchor, $_symbol_extanchor;
    list($href, $name, $opt) = func_get_args();
    $href = trim($href);
    if (empty($href)) {
        return;
    }
    $name = trim($name);
    if (empty($name)) {
        $name = $href;
    }
    $opt = trim($opt);
    if (!empty($opt)) {
        $opt = ' ' . $opt;
    }
    $is_url = is_url($href);
    if (!$is_url && !a_rel_check($href)) {
        return $href;
    }
    $is_ext = $is_url && !is_inside_uri($href);
    $symbol = $is_ext ? $_symbol_extanchor : $_symbol_innanchor;
    $r_href = PKWK_USE_REDIRECT && $is_ext ? get_cmd_uri('redirect', '', '', 'u=') . rawurlencode($href) : htmlspecialchars($href);
    if (!$is_url) {
        return '<a href="' . $r_href . '"' . $opt . '>' . $name . '</a>';
    } else {
        return '<a class="inn" href="' . $r_href . '" rel="nofollow"' . $opt . '>' . $name . str_replace('$1', $r_href, str_replace('$2', '_blank', $symbol)) . '</a>';
    }
}
function open_uri_in_new_window($anchor, $which)
{
    global $use_open_uri_in_new_window, $open_uri_in_new_window_opis, $open_uri_in_new_window_opisi, $open_uri_in_new_window_opos, $open_uri_in_new_window_oposi;
    // 外部サーバーのInterWiki
    global $_symbol_extanchor, $_symbol_innanchor;
    // 新規ウィンドウを開くアイコン
    // この関数を使わない OR 呼び出し元が不正な場合はスルーする
    if (!$use_open_uri_in_new_window || !$which || !$_symbol_extanchor || !$_symbol_innanchor) {
        return $anchor;
    }
    // 外部形式のリンクをどうするか
    $frame = '';
    // 質問箱/115 対応
    /*
    if ($which == 'link_interwikiname') {
    	$frame = (is_inside_uri($anchor) ? $open_uri_in_new_window_opisi:$open_uri_in_new_window_oposi);
    	$symbol = (is_inside_uri($anchor) ? $_symbol_innanchor:$_symbol_extanchor);
    	$aclass = (is_inside_uri($anchor) ? 'class="inn" ':'class="ext" ');
    } elseif ($which == 'link_url_interwiki') {
    	$frame = (is_inside_uri($anchor) ? $open_uri_in_new_window_opisi:$open_uri_in_new_window_oposi);
    	$symbol = (is_inside_uri($anchor) ? $_symbol_innanchor:$_symbol_extanchor);
    	$aclass = (is_inside_uri($anchor) ? 'class="inn" ':'class="ext" ');
    } elseif ($which == 'link_url') {
    	$frame = (is_inside_uri($anchor) ? $open_uri_in_new_window_opis:$open_uri_in_new_window_opos);
    	$symbol = (is_inside_uri($anchor) ? $_symbol_innanchor:$_symbol_extanchor);
    	$aclass = (is_inside_uri($anchor) ? 'class="inn" ':'class="ext" ');
    }
    */
    switch (strtolower($which)) {
        case 'link_interwikiname':
        case 'link_url_interwiki':
            $frame = is_inside_uri($anchor) ? $open_uri_in_new_window_opisi : $open_uri_in_new_window_oposi;
            $symbol = is_inside_uri($anchor) ? $_symbol_innanchor : $_symbol_extanchor;
            $aclass = is_inside_uri($anchor) ? 'class="inn" ' : 'class="ext" ';
            break;
        case 'link_url':
            $frame = is_inside_uri($anchor) ? $open_uri_in_new_window_opis : $open_uri_in_new_window_opos;
            $symbol = is_inside_uri($anchor) ? $_symbol_innanchor : $_symbol_extanchor;
            $aclass = is_inside_uri($anchor) ? 'class="inn" ' : 'class="ext" ';
    }
    if ($frame == '') {
        return $anchor;
    }
    // 引数 $anchor は a タグの中にクラスはない
    $aclasspos = mb_strpos($anchor, '<a ', 0, mb_detect_encoding($anchor)) + 3;
    // 3 is strlen('<a ')
    // $insertpos = mb_strpos($anchor, '</a>', mb_detect_encoding($anchor));
    $insertpos = mb_strpos($anchor, '</a>', $aclasspos, mb_detect_encoding($anchor));
    preg_match('#href="([^"]+)"#', $anchor, $href);
    return mb_substr($anchor, 0, $aclasspos) . $aclass . mb_substr($anchor, $aclasspos, $insertpos - $aclasspos) . str_replace('$1', $href[1], str_replace('$2', $frame, $symbol)) . mb_substr($anchor, $insertpos);
}