친구이름에 자동으로 링크걸기

By | 2003-08-22

출처 : http://tidakada.com/board/viewtopic.php?t=1145

친구들의 리스트를 적어놓으면 자동으로 글 본문에 그 단어가 들어갔을 경우에 링크를 걸어주는 핵입니다.

먼저 B2DIR/b2-include/b2vars.php 를 열어서
아래 부분을 추가합니다.

$friendstrans = array(
‘홍길동’ => ‘홍길동사이트’,
‘춘향이’ => ‘춘향이사이트’ );

그리고 아래부분도 추가시킵니다. 여기서 자동으로 http://를 붙여주니 위의 목록에선 넣을필요가 없는것입니다.

# generates friends’ search & replace arrays
foreach($friendstrans as $friend => $url) {
$friendssearch[] = $friend;
$friend_masked = ”;
for ($ii = 0; $ii < strlen($friend); $ii = $ii + 1) {
$friend_masked .= substr($friend, $ii, 1);
}
$b2_friendsreplace[] = “<a href=’http://$url’ target=’_blank’>$friend_masked”;
}

b2functions.php 화일에 아래 내용을 추가시킵니다.

function convert_friends($content) {
global $friendssearch, $b2_friendsreplace;
$content = str_replace($friendssearch, $b2_friendsreplace, $content);
return ($content);
}

그리고 마지막으로 b2template.functions.php 를 열어서 function the_content 부분에 $content=convert_friends($content); 를 한줄 끼워넣습니다. 아래와 같은 모양이 될겁니다.

function the_content($more_link_text=”(more…)”,$stripteaser=”0″,$more_file=””) {
$content = get_the_content($more_link_text,$stripteaser,$more_file);
$content = convert_bbcode($content);
$content = convert_gmcode($content);
$content = convert_smilies($content);
$content=convert_friends($content);
$content = convert_chars($content,”html”);
echo $content;
}

음~ 지금 테스트로 달봉님을 넣었는데 잘 동작하려는지 모르겠네요. 달봉님 안녕하세요. 달봉의 스토리. 달봉만세. 달봉님 달봉달봉 -_-;;

One thought on “친구이름에 자동으로 링크걸기

  1. dalbong

    잘 되네요..
    베타 테스트로 선정해주셔서 감사합니다^^*

Comments are closed.