Changeset 391

Show
Ignore:
Timestamp:
07/31/08 10:57:55 (5 months ago)
Author:
082net
Message:

## euckr-trackback ##

Fixed error for 'wp_html_excerpt' function
Show admin_notice when no required modules(mbstring or iconv)

Files:
1 modified

Legend:

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

    r390 r391  
    77Description: EUC-KR로 운영되는 블로그와의 트랙백 송수신 문제를 해결합니다. 
    88 
    9 Version: 0.3 
     9Version: 0.31 
    1010 
    1111Author: Choen, Youngmin 
     
    3232**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    3333*/ 
     34if ( !function_exists('mb_convert_encoding') && !function_exists('iconv') ) { 
     35        function korean_trackback_admin_notice() { 
     36                echo '<div class="error fade"><p>EUC-KR Trackback 플러그인을 사용할 수 없습니다. 현재 서버에 필요한 모듈(mbstring 또는 iconv)이 설치되지 않았습니다. 서버관리지에게 해당모듈(mbstring 권장)의 지원을 요청해 보시기 바랍니다.</p></div>'; 
     37        } 
     38        add_action('admin_notices', 'korean_trackback_admin_notice'); 
     39        return;// 더이상 플러그인 내용을 읽어들이지 않고 마칩니다. 
     40} 
    3441 
    3542// 바람님의 트랙백 패치(http://www.windlike.net/blog/279/)를 응용해서 만들었습니다. 
     
    157164// 기왕이면 if (function_exists('trackback_kr')) 을 사용해주는게 좋습니다. 
    158165function trackback_kr($url, $title, $excerpt, $id) { 
    159         // 블로그에서 EUC-KR을 사용중이라면 그냥 워드프레스 함수를 사용해도 됨. 
    160166        if ('EUC-KR' == strtoupper(get_option('blog_charset'))) 
    161167                return trackback($url, $title, $excerpt, $id); 
     
    177183        } else { 
    178184                foreach ($euckr_blogs as $blog) { 
    179                         if (strpos($url, $blog) !== false) { 
     185                        if (!empty($blog) && strpos($url, $blog) !== false) { 
    180186                                $tokr = true; 
    181187                                break; 
     
    196202} 
    197203endif; 
     204 
     205// iconv 만 설치된 서버를 위해 워드프레스 2.6에 포함된 함수들을 빌려왔습니다. 
     206if ( ! function_exists('wp_html_excerpt') ): 
     207 
     208function wp_html_excerpt( $str, $count ) { 
     209        $str = strip_tags( $str ); 
     210        $str = mb_strcut( $str, 0, $count ); 
     211        // remove part of an entity at the end 
     212        $str = preg_replace( '/&[^;\s]{0,6}$/', '', $str ); 
     213        return $str; 
     214} 
     215 
     216if ( ! function_exists('mb_strcut') ): 
     217        function mb_strcut( $str, $start, $length=null, $encoding=null ) { 
     218                return _mb_strcut($str, $start, $length, $encoding); 
     219        } 
     220endif; 
     221 
     222if ( ! function_exists('_mb_strcut') ): 
     223function _mb_strcut( $str, $start, $length=null, $encoding=null ) { 
     224        // the solution below, works only for utf-8, so in case of a different 
     225        // charset, just use built-in substr 
     226        $charset = get_option( 'blog_charset' ); 
     227        if ( !in_array( $charset, array('utf8', 'utf-8', 'UTF8', 'UTF-8') ) ) { 
     228                return is_null( $length )? substr( $str, $start ) : substr( $str, $start, $length); 
     229        } 
     230        // use the regex unicode support to separate the UTF-8 characters into an array 
     231        preg_match_all( '/./us', $str, $match ); 
     232        $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length ); 
     233        return implode( '', $chars ); 
     234} 
     235endif; 
     236 
     237endif; 
    198238?>