초간단한 블로그 파싱 스킨 설정.

Tag : 그누보드
  
                

1. list.skin.php 파일 에 파싱버튼 추가


블로그 파싱
2. list.skin.php 파일 파단에 스크립트 추가

function naverblog() {
    var url = "parsing_naverblog.php";
    window.open(url, "naverblog", "left=100,top=100,width=550,height=650,scrollbars=yes,resizable=yes");
    return false;
}
3. parsing_naverblog.php 파일에 게시판아이디 블로그 아이디 설정

ini_set('allow_url_fopen', 'ON');
include_once('_common.php');
//simple_html_dom.php 경로
include_once('simple_html_dom.php');


$img_php = "img.php";
$bo_table = "talk";//게시판 아이디

//수집할 RSS 주소
$rss = array(
    "https://rss.blog.naver.com/xxxxxxx.xml",  //블로그 아이디
);
$wr_1 = "naverblog";
$write_table = $g5['write_prefix'].$bo_table;

foreach($rss as $k=>$v) {
    $xml=simplexml_load_string(file_get_contents("$v")) or die("Error: Cannot create object");
    foreach($xml->channel->item as $c) {
        $subject = $c->title;
        $wr_datetime = date("Y-m-d H:i:s",strtotime($c->pubDate));
        $a = explode("/", $c->link); //제목 CDATA 제거        
        $ca_name = $k; //게시판 카테고리(광주광역시/광산구/남구/동구/서구/북구)
        $wr_subject = $c->title; //게시판 저장용 글제목
        $wr_link1 =  'https://blog.naver.com/'.$a[3].'/'.$a[4];
        $wr_2 = $a[3]; //게시판 저장용 블로그 아이디
        $wr_3 = $a[4]; //게시판 저장용 글 아이디

        $sql = "select * from $write_table where wr_2 = '{$wr_2}' and wr_3 = '{$wr_3}'";
        $result = sql_fetch($sql);

        if ($result['wr_id']) { //등록된 글이면 Pass
            continue;
        } else {
            //실제 블로그 페이지 읽어오기
            $file_content = file_get_html('https://blog.naver.com/PostView.nhn?blogId='.$a[3].'&logNo='.$a[4]);
            
            foreach($file_content->find('div.se-main-container') as $e) {
                $blog_txt = $e->innertext;
                $blog_txt = preg_replace('%\?type=[^"]+%i','?type=w2',$blog_txt);
                
                //img.php 파일로 이미지 경로 대체
                $blog_txt = preg_replace('%(https://postfiles\.pstatic\.net/)%i','http://thuy.cafe24.com/theme/simple/skin/board/test/img.php?url=$1',$blog_txt);
                $blog_txt = preg_replace('%)%U','',$blog_txt);
                $blog_txt = preg_replace('%<\/a>%U','',$blog_txt);
                $blog_txt = str_replace("'",""",$blog_txt);
                $blog_txt = preg_replace("%class=(\"|\')?([^\"\']+)(\"|\')?%","",$blog_txt);
                $blog_txt = preg_replace("%style=(\"|\')?([^\"\']+)(\"|\')?%","",$blog_txt);
                $blog_txt = addslashes($blog_txt);
                

                //게시판에 글등록
                $wr_subject = str_replace("'","",$wr_subject);
                $wr_subject = preg_replace("#[\\\]+$#", "", $wr_subject);
                $wr_content = $blog_txt;
                
                //여분필드 - (사이트명, 게시판 아이디, 글 아이디의 순. 필요한 게 있으면 wr_4~10까지 추가)
                $wr = array($wr_1, $wr_2, $wr_3);
                board_update($bo_table, $ca_name, $wr_subject, $wr_content, $wr, $wr_link1, $wr_datetime);
            }
        }
    }
}


//게시판 글등록
function board_update($bo_table = '', $ca_name = '', $wr_subject = '', $wr_content = '', $wr = array(), $wr_link1 = '', $wr_datetime = '') 
{

    global $g5;

    $write_table = $g5['write_prefix'].$bo_table;

    $wr_subject = str_replace("'","",$wr_subject);
    $wr_subject = preg_replace("#[\\\]+$#", "", $wr_subject);
    $wr_subject = trim($wr_subject);
    $wr_content = $wr_content;

    if (!$wr_datetime) {
        $wr_datetime = date("Y-m-d H:i:s");
    }
    
    $mb_id = 'admin';
    $wr_name = '정보맨';
    $wr_password = '';
    $wr_email = addslashes($member['mb_email']);
    $wr_homepage = addslashes(clean_xss_tags($member['mb_homepage']));

    if(!empty($wr)) {
        $k=1;
        for($i=0;$i <= count($wr); $i++) {
            $var = "wr_{$k}";
            $$var = trim($wr[$i]);
            $k++;
        }
    }

    $wr_num = get_next_num($write_table);
    $wr_reply = '';

    $sql = " insert into $write_table
            set wr_num = '$wr_num',
                 wr_reply = '$wr_reply',
                 wr_comment = 0,
                 ca_name = '$ca_name',
                 wr_option = 'html1',
                 wr_subject = '$wr_subject',
                 wr_content = '$wr_content',
                 wr_link1 = '$wr_link1',
                 wr_link2 = '$wr_link2',
                 wr_link1_hit = 0,
                 wr_link2_hit = 0,
                 wr_hit = 0,
                 wr_good = 0,
                 wr_nogood = 0,
                 mb_id = '{$member['mb_id']}',
                 wr_password = '$wr_password',
                 wr_name = '$wr_name',
                 wr_email = '$wr_email',
                 wr_homepage = '$wr_homepage',
                 wr_datetime = '".$wr_datetime."',
                 wr_last = '".G5_TIME_YMDHIS."',
                 wr_ip = '{$_SERVER['REMOTE_ADDR']}',
                 wr_1 = '$wr_1',
                 wr_2 = '$wr_2',
                 wr_3 = '$wr_3',
                 wr_4 = '$wr_4',
                 wr_5 = '$wr_5',
                 wr_6 = '$wr_6',
                 wr_7 = '$wr_7',
                 wr_8 = '$wr_8',
                 wr_9 = '$wr_9',
                 wr_10 = '$wr_10' ";
    sql_query($sql) or die(sql_error_info());
    $wr_id = sql_insert_id();
    $count++;
    // 부모 아이디에 UPDATE
    sql_query(" update $write_table set wr_parent = '$wr_id' where wr_id = '$wr_id' ") or die(sql_error_info());
    // 새글 INSERT
    sql_query(" insert into {$g5['board_new_table']} ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '{$bo_table}', '{$wr_id}', '{$wr_id}', '".$wr_datetime."', '{$member['mb_id']}' ) ") or die(sql_error_info());
    // 게시글 1 증가
    sql_query("update {$g5['board_table']} set bo_count_write = bo_count_write + 1 where bo_table = '{$bo_table}'") or die(sql_error_info());
    set_time_limit(30);

}