Changeset 390

Show
Ignore:
Timestamp:
07/30/08 12:42:23 (5 months ago)
Author:
082net
Message:

## euckr-trackback ##

Applied new method for receiving trackback.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • euckr-trackback/trunk/euckr-trackback.php

    r387 r390  
    55Plugin URI: http://082net.com/2008/859/euckr-trackback-plugin/ 
    66 
    7 Description: EUC-KR 트랙백을 문제없이 받고, 보낼 수 있게 합니다. 
     7Description: EUC-KR로 운영되는 블로그와의 트랙백 송수신 문제를 해결합니다. 
    88 
    9 Version: 0.2 
     9Version: 0.3 
    1010 
    1111Author: Choen, Youngmin 
     
    3333*/ 
    3434 
    35 // 바람님(http://windlike.net)과 태영님(http://mytears.org)이 작성하신 내용. 
    36 // is_utf8 대신에 워드프레스에 포함된 seems_utf8 함수를 이용했습니다. 
    37 function korean_trackback_post( $insert_id ) { 
    38         global $_POST; 
    39  
    40         // 블로그에서 EUC-KR을 사용중이라면 그냥 워드프레스 함수를 사용해도 됨. 
    41         if ('EUC-KR' == strtoupper(get_option('blog_charset'))) 
     35// 바람님의 트랙백 패치(http://www.windlike.net/blog/279/)를 응용해서 만들었습니다. 
     36function korean_trackback_pre() { 
     37        if ( 'EUC-KR' == strtoupper(get_option('blog_charset')) ) 
     38                return; 
     39        if ( is_robots() || is_feed() || !is_trackback() ) 
    4240                return; 
    4341 
    44         $title          = $_POST['title']; 
    45         $excerpt        = $_POST['excerpt']; 
    46         $blog_name      = $_POST['blog_name']; 
    47         $tb_url = $_POST['url']; 
     42        if ( seems_utf8($_POST['url']) ) {// fix url from tistory 
     43                if (function_exists('mb_strtolower')) { 
     44                        $_POST['url'] = mb_strtolower($_POST['url'], 'UTF-8'); 
     45                } 
     46                $_POST['url'] = utf8_uri_encode($_POST['url']); 
     47        } 
    4848 
    49 //      $tb_url = remove_accents($tb_url); 
    50         if (seems_utf8($tb_url)) {// fix url from tistory 
    51                 if (function_exists('mb_strtolower')) { 
    52                         $tb_url = mb_strtolower($tb_url, 'UTF-8'); 
    53                 } 
    54                 $tb_url = utf8_uri_encode($tb_url); 
     49        if ( !$_POST['charset'] ) 
     50                $_POST['charset'] = 'ASCII, UTF-8, EUC-KR, ISO-8859-1, JIS, EUC-JP, SJIS'; 
     51 
     52        // mbstring 을 지원하지 않고 iconv 만 지원하는 서버를 위한 내용 
     53        if ( !function_exists('mb_convert_encoding') && function_exists('iconv') ) { 
     54                // These three are stripslashed here so that they can be properly escaped after iconv() 
     55                $_POST['title']     = stripslashes($_POST['title']); 
     56                $_POST['excerpt']   = stripslashes($_POST['excerpt']); 
     57                $_POST['blog_name'] = stripslashes($_POST['blog_name']); 
     58                $charset = 'EUC-KR'; 
     59                if ( !seems_utf8($_POST['title']) ) 
     60                        $_POST['title'] = iconv($charset, 'UTF-8', $_POST['title']); 
     61                if ( !seems_utf8($_POST['excerpt']) ) 
     62                        $_POST['excerpt'] = iconv($charset, 'UTF-8', $_POST['excerpt']); 
     63                if ( !seems_utf8($_POST['blog_name']) ) 
     64                        $_POST['blog_name'] = iconv($charset, 'UTF-8', $_POST['blog_name']); 
     65                // addslashes again. 
     66                $_POST['title']     = addslashes($_POST['title']); 
     67                $_POST['excerpt']   = addslashes($_POST['excerpt']); 
     68                $_POST['blog_name'] = addslashes($_POST['blog_name']); 
    5569        } 
    56          
    57         if ($_POST['charset']) 
    58                 $charset = strtoupper( trim($_POST['charset']) ); 
    59         else 
    60                 $charset = 'UTF-8, EUC-KR, ISO-8859-1, JIS, EUC-JP, SJIS';// just added EUC-KR right after UTF-8 
    61  
    62         // For international trackbacks  
    63         if ( function_exists('mb_convert_encoding') ) {// recommended 
    64                 $title     = mb_convert_encoding($title, get_option('blog_charset'), $charset); 
    65                 $excerpt   = mb_convert_encoding($excerpt, get_option('blog_charset'), $charset); 
    66                 $blog_name = mb_convert_encoding($blog_name, get_option('blog_charset'), $charset); 
    67         } else if ( function_exists('iconv') ) { 
    68                 $charset = 'EUC-KR'; 
    69                  
    70                 if ( !seems_utf8($title) ) 
    71                         $title = iconv($charset, 'UTF-8', $title); 
    72                 if ( !seems_utf8($excerpt) ) 
    73                         $excerpt = iconv($charset, 'UTF-8', $excerpt); 
    74                 if ( !seems_utf8($blog_name) ) 
    75                         $blog_name = iconv($charset, 'UTF-8', $blog_name); 
    76         } else  
    77                 return; 
    78  
    79         $comment_ID = $insert_id; 
    80         $comment_author = $blog_name; 
    81         $comment_content = "<strong>$title</strong>\n\n$excerpt..."; 
    82         $comment_author_url = $tb_url; 
    83          
    84         $commentdata = compact('comment_ID', 'comment_author', 'comment_content', 'comment_author_url' ); 
    85  
    86         wp_update_comment($commentdata); 
    8770} 
    8871 
    89 add_filter('trackback_post', 'korean_trackback_post'); 
     72add_action('template_redirect', 'korean_trackback_pre'); 
    9073 
     74// EUC-KR 블로그로 전송할 트랙백을 미리 보냅니다. 
    9175function do_trackbacks_kr() { 
    9276        global $wpdb; 
     
    165149        return 'EUC-KR'; 
    166150} 
    167  
     151// Send EUC-KR trackbacks with our fix before wordpress 'do_pings' 
    168152add_action('do_pings', 'do_trackbacks_kr', 0, 1); 
    169153