공개보드 게시물을 설치형 블로그인 텍스트큐브나 태터툴즈로 복사하는 샘플 소스 코드입니다. 소스를 조금 수정해서 스케쥴링을 하면 주기적으로 게시판에 있는 글을 블로그에 포스팅할 수 있게 됩니다. 실시간으로 블로그에 글을 올려야 한다면 공개보드 스킨으로 수정해서 써도 되겠습니다. 이 소스는 그누보드를 샘플로 사용했으나 필요에 따라 제로보드 같은 다른 공개보드 또는 자신의 보드에 맞게 수정해서 사용할 수 있습니다. 그리고 RSS를 찍어준다던가 첨부파일을 추가하는 등의 기능 보완이 필요합니다. 또한 캐릭터셋이 서로 다를 경우 iconv 를 이용해서 인코딩을 해서 맞춰줄 필요가 있습니다. 이 소스와 다른 방법으로 블로그API(BlogAPI)를 이용할 수도 있습니다.
웹프로그래머의 홈페이지 정보 블로그 http://hompy.info
<?
/*board2blog.php */
include "global_variable.php";
include "mysql.php";
$dbsour = new mysql_class($db_info_mud4u);
$tbsour = "g4_write_news";
$dbdest = new mysql_class($db_info_blog);
$tbdest = "tc_Entries";
$b_blogid = 1;
$b_userid = 1;
$b_draft = 0;
$b_visibility = 3;
$b_contentFormatter = 'ttml';
$b_contentEditor = 'modern';
$b_location = '/';
$b_acceptComment = 1;
$b_acceptTrackback = 1;
$b_comments = 0;
$b_trackbacks = 0;
$query = "select *,UNIX_TIMESTAMP(wr_datetime) wr_unixtime,UNIX_TIMESTAMP(wr_last) wr_lasttime from $tbsour where wr_is_comment=0 order by wr_id asc";
if ($dbsour->query($query))
while ($row = $dbsour->fetch()) {
extract($row);
echo $wr_id . ":" . $wr_subject . "\n";
switch($ca_name){
case '공지사항': $wr_category_id = 1; break;
case '자유게시판': $wr_category_id = 2; break;
default: $wr_category_id = 3; break;
}
$b_id = 1;
$query = "select max(id) as max from $tbdest";
if ($dbdest->query($query))
if ($row2 = $dbdest->fetch()) {
$b_id = intval($row2[max]) + 1;
}
$b_category = $wr_category_id;
$b_title = mysql_escape_string($wr_subject);
$b_slogan = getSlogan($wr_subject) . "--" . $wr_id;
$b_content = mysql_escape_string($wr_content);
$b_password = generatePassword();
$b_published = $wr_unixtime;
$b_created = $wr_unixtime;
$b_modified = $wr_lasttime;
$query = "INSERT INTO $tbdest SET blogid='$b_blogid', userid='$b_userid', id='$b_id', draft='$b_draft', visibility='$b_visibility', category='$b_category', title='$b_title', slogan='$b_slogan', content='$b_content', contentFormatter='$b_contentFormatter', contentEditor='$b_contentEditor', location='$b_location', password='$b_password', acceptComment='$b_acceptComment', acceptTrackback='$b_acceptTrackback', published='$b_published', created='$b_created', modified='$b_modified', comments='$b_comments', trackbacks='$b_trackbacks'";
$dbdest->query($query);
}
echo "\n";
function getSlogan($slogan) {
$slogan = preg_replace('/-+/', ' ', $slogan);
$slogan = preg_replace('@[!-/:-\@\[-\^`{-~]+@', '', $slogan);
$slogan = preg_replace('/\s+/', '-', $slogan);
$slogan = trim($slogan, '-');
return strlen($slogan) > 0 ? $slogan : 'XFile';
}
function generatePassword() {
return strtolower(substr(base64_encode(rand(0x10000000, 0x70000000)), 3, 8));
}
?>
<?
/* mysql.php */
class mysql_class {
var $user_id = "";
function __construct($db_info) {
$this->db_info = $db_info;
$this->ip = $db_info['host'];
$this->db = $db_info['db'];
$this->id = $db_info['user'];
$this->pw = $db_info['password'];
$this->ch = $db_info['char'];
$this->sess = mysql_connect($this->ip, $this->id, $this->pw) or die("SQL서버에 접속할 수 없습니다.");
mysql_select_db($this->db, $this->sess) or die("데이터베이스와의 접속에 실패하였습니다.");
mysql_query("set names $this->ch", $this->sess);
}
function __destruct() {
mysql_close($this->sess);
}
public function query($query){
$this->result = mysql_query($query,$this->sess);
return $this->result;
}
public function query_one($query){
$this->result = mysql_query($query,$this->sess);
if ($this->result) {
$board = mysql_fetch_array($this->result);
if ($board) return $board[0];
}
return null;
}
public function fetch(){
if ($this->result) {
$board = mysql_fetch_array($this->result, MYSQL_ASSOC);
return $board;
}
return null;
}
}
?>
<?
/* global_variable.php */
$db_info_mud4u['host'] = "localhost";
$db_info_mud4u['db'] = "board";
$db_info_mud4u['user'] = "board";
$db_info_mud4u['password'] = "boardpw";
$db_info_mud4u['char'] = "utf8";
$db_info_blog['host'] = "localhost";
$db_info_blog['db'] = "blog";
$db_info_blog['user'] = "blog";
$db_info_blog['password'] = "blogpw";
$db_info_blog['char'] = "utf8";
?>
웹프로그래머의 홈페이지 정보 블로그 http://hompy.info
<?
/*board2blog.php */
include "global_variable.php";
include "mysql.php";
$dbsour = new mysql_class($db_info_mud4u);
$tbsour = "g4_write_news";
$dbdest = new mysql_class($db_info_blog);
$tbdest = "tc_Entries";
$b_blogid = 1;
$b_userid = 1;
$b_draft = 0;
$b_visibility = 3;
$b_contentFormatter = 'ttml';
$b_contentEditor = 'modern';
$b_location = '/';
$b_acceptComment = 1;
$b_acceptTrackback = 1;
$b_comments = 0;
$b_trackbacks = 0;
$query = "select *,UNIX_TIMESTAMP(wr_datetime) wr_unixtime,UNIX_TIMESTAMP(wr_last) wr_lasttime from $tbsour where wr_is_comment=0 order by wr_id asc";
if ($dbsour->query($query))
while ($row = $dbsour->fetch()) {
extract($row);
echo $wr_id . ":" . $wr_subject . "\n";
switch($ca_name){
case '공지사항': $wr_category_id = 1; break;
case '자유게시판': $wr_category_id = 2; break;
default: $wr_category_id = 3; break;
}
$b_id = 1;
$query = "select max(id) as max from $tbdest";
if ($dbdest->query($query))
if ($row2 = $dbdest->fetch()) {
$b_id = intval($row2[max]) + 1;
}
$b_category = $wr_category_id;
$b_title = mysql_escape_string($wr_subject);
$b_slogan = getSlogan($wr_subject) . "--" . $wr_id;
$b_content = mysql_escape_string($wr_content);
$b_password = generatePassword();
$b_published = $wr_unixtime;
$b_created = $wr_unixtime;
$b_modified = $wr_lasttime;
$query = "INSERT INTO $tbdest SET blogid='$b_blogid', userid='$b_userid', id='$b_id', draft='$b_draft', visibility='$b_visibility', category='$b_category', title='$b_title', slogan='$b_slogan', content='$b_content', contentFormatter='$b_contentFormatter', contentEditor='$b_contentEditor', location='$b_location', password='$b_password', acceptComment='$b_acceptComment', acceptTrackback='$b_acceptTrackback', published='$b_published', created='$b_created', modified='$b_modified', comments='$b_comments', trackbacks='$b_trackbacks'";
$dbdest->query($query);
}
echo "\n";
function getSlogan($slogan) {
$slogan = preg_replace('/-+/', ' ', $slogan);
$slogan = preg_replace('@[!-/:-\@\[-\^`{-~]+@', '', $slogan);
$slogan = preg_replace('/\s+/', '-', $slogan);
$slogan = trim($slogan, '-');
return strlen($slogan) > 0 ? $slogan : 'XFile';
}
function generatePassword() {
return strtolower(substr(base64_encode(rand(0x10000000, 0x70000000)), 3, 8));
}
?>
<?
/* mysql.php */
class mysql_class {
var $user_id = "";
function __construct($db_info) {
$this->db_info = $db_info;
$this->ip = $db_info['host'];
$this->db = $db_info['db'];
$this->id = $db_info['user'];
$this->pw = $db_info['password'];
$this->ch = $db_info['char'];
$this->sess = mysql_connect($this->ip, $this->id, $this->pw) or die("SQL서버에 접속할 수 없습니다.");
mysql_select_db($this->db, $this->sess) or die("데이터베이스와의 접속에 실패하였습니다.");
mysql_query("set names $this->ch", $this->sess);
}
function __destruct() {
mysql_close($this->sess);
}
public function query($query){
$this->result = mysql_query($query,$this->sess);
return $this->result;
}
public function query_one($query){
$this->result = mysql_query($query,$this->sess);
if ($this->result) {
$board = mysql_fetch_array($this->result);
if ($board) return $board[0];
}
return null;
}
public function fetch(){
if ($this->result) {
$board = mysql_fetch_array($this->result, MYSQL_ASSOC);
return $board;
}
return null;
}
}
?>
<?
/* global_variable.php */
$db_info_mud4u['host'] = "localhost";
$db_info_mud4u['db'] = "board";
$db_info_mud4u['user'] = "board";
$db_info_mud4u['password'] = "boardpw";
$db_info_mud4u['char'] = "utf8";
$db_info_blog['host'] = "localhost";
$db_info_blog['db'] = "blog";
$db_info_blog['user'] = "blog";
$db_info_blog['password'] = "blogpw";
$db_info_blog['char'] = "utf8";
?>


댓글을 달아 주세요