diff --git a/modules/comment/comment.controller.php b/modules/comment/comment.controller.php
index 50ad2d7a4..acd03f3e5 100644
--- a/modules/comment/comment.controller.php
+++ b/modules/comment/comment.controller.php
@@ -48,7 +48,7 @@
/**
* @brief 댓글 입력
**/
- function insertComment($obj) {
+ function insertComment($obj, $manual_inserted = false) {
// document_srl에 해당하는 글이 있는지 확인
$document_srl = $obj->document_srl;
@@ -58,25 +58,27 @@
$oDocumentModel = &getModel('document');
// 원본글을 가져옴
- $document = $oDocumentModel->getDocument($document_srl);
+ if(!$manual_inserted) {
+ $document = $oDocumentModel->getDocument($document_srl);
- if($document_srl != $document->document_srl) return new Object(-1,'msg_invalid_document');
- if($document->lock_comment=='Y') return new Object(-1,'msg_invalid_request');
+ if($document_srl != $document->document_srl) return new Object(-1,'msg_invalid_document');
+ if($document->lock_comment=='Y') return new Object(-1,'msg_invalid_request');
- $obj->list_order = $obj->comment_srl * -1;
- if($obj->password) $obj->password = md5($obj->password);
- if($obj->homepage && !eregi('^http:\/\/',$obj->homepage)) $obj->homepage = 'http://'.$obj->homepage;
+ if($obj->password) $obj->password = md5($obj->password);
+ if($obj->homepage && !eregi('^http:\/\/',$obj->homepage)) $obj->homepage = 'http://'.$obj->homepage;
- // 로그인 된 회원일 경우 회원의 정보를 입력
- if(Context::get('is_logged')) {
- $logged_info = Context::get('logged_info');
- $obj->member_srl = $logged_info->member_srl;
- $obj->user_id = $logged_info->user_id;
- $obj->user_name = $logged_info->user_name;
- $obj->nick_name = $logged_info->nick_name;
- $obj->email_address = $logged_info->email_address;
- $obj->homepage = $logged_info->homepage;
+ // 로그인 된 회원일 경우 회원의 정보를 입력
+ if(Context::get('is_logged')) {
+ $logged_info = Context::get('logged_info');
+ $obj->member_srl = $logged_info->member_srl;
+ $obj->user_id = $logged_info->user_id;
+ $obj->user_name = $logged_info->user_name;
+ $obj->nick_name = $logged_info->nick_name;
+ $obj->email_address = $logged_info->email_address;
+ $obj->homepage = $logged_info->homepage;
+ }
}
+ $obj->list_order = $obj->comment_srl * -1;
// begin transaction
$oDB = &DB::getInstance();
@@ -97,20 +99,22 @@
return $output;
}
- // comment model객체 생성
- $oCommentModel = &getModel('comment');
+ if(!$manual_inserted) {
+ // comment model객체 생성
+ $oCommentModel = &getModel('comment');
- // 해당 글의 전체 댓글 수를 구해옴
- $comment_count = $oCommentModel->getCommentCount($document_srl);
+ // 해당 글의 전체 댓글 수를 구해옴
+ $comment_count = $oCommentModel->getCommentCount($document_srl);
- // document의 controller 객체 생성
- $oDocumentController = &getController('document');
+ // document의 controller 객체 생성
+ $oDocumentController = &getController('document');
- // 해당글의 댓글 수를 업데이트
- $output = $oDocumentController->updateCommentCount($document_srl, $comment_count);
+ // 해당글의 댓글 수를 업데이트
+ $output = $oDocumentController->updateCommentCount($document_srl, $comment_count);
- // 댓글의 권한을 부여
- $this->addGrant($obj->comment_srl);
+ // 댓글의 권한을 부여
+ $this->addGrant($obj->comment_srl);
+ }
// commit
$oDB->commit();
diff --git a/modules/document/document.controller.php b/modules/document/document.controller.php
index 9e1523366..c6ee5df3e 100644
--- a/modules/document/document.controller.php
+++ b/modules/document/document.controller.php
@@ -46,7 +46,7 @@
/**
* @brief 문서 입력
**/
- function insertDocument($obj) {
+ function insertDocument($obj, $manual_inserted = false) {
// begin transaction
$oDB = &DB::getInstance();
@@ -83,15 +83,15 @@
$obj->tags = $oTagController->insertTag($obj->module_srl, $obj->document_srl, $obj->tags);
// 글 입력
- $obj->readed_count = 0;
+ if(!$obj->readed_count) $obj->readed_count = 0;
$obj->update_order = $obj->list_order = $obj->document_srl * -1;
- if($obj->password) $obj->password = md5($obj->password);
+ if($obj->password && !$obj->password_is_hashed) $obj->password = md5($obj->password);
// 공지사항일 경우 list_order에 무지막지한 값;;을 입력
if($obj->is_notice=='Y') $obj->list_order = $this->notice_list_order;
// 로그인 된 회원일 경우 회원의 정보를 입력
- if(Context::get('is_logged')) {
+ if(Context::get('is_logged')&&!$manual_inserted) {
$logged_info = Context::get('logged_info');
$obj->member_srl = $logged_info->member_srl;
$obj->user_id = $logged_info->user_id;
@@ -112,10 +112,6 @@
// 성공하였을 경우 category_srl이 있으면 카테고리 update
if($obj->category_srl) $this->updateCategoryCount($obj->category_srl);
- // 자동 저장 문서 삭제
- $oEditorController = &getController('editor');
- $oEditorController->deleteSavedDoc();
-
// 첨부 파일이 있었을 경우 해당 첨부파일들의 valid값을 Y로 변경
if($obj->uploaded_count) {
$oFileController = &getController('file');
@@ -125,6 +121,12 @@
// commit
$oDB->commit();
+ // 자동 저장 문서 삭제
+ if(!$manual_inserted) {
+ $oEditorController = &getController('editor');
+ $oEditorController->deleteSavedDoc();
+ }
+
// return
$this->addGrant($obj->document_srl);
$output->add('document_srl',$obj->document_srl);
diff --git a/modules/file/file.controller.php b/modules/file/file.controller.php
index 3fbbd244c..d16fb7491 100644
--- a/modules/file/file.controller.php
+++ b/modules/file/file.controller.php
@@ -24,7 +24,12 @@
// 업로드 권한이 없거나 정보가 없을시 종료
if(!$_SESSION['upload_enable'][$upload_target_srl]) exit();
- $output = $this->insertFile($module_srl, $upload_target_srl);
+ $file_info = Context::get('Filedata');
+
+ // 정상적으로 업로드된 파일이 아니면 오류 출력
+ if(!is_uploaded_file($file_info['tmp_name'])) return false;
+
+ $output = $this->insertFile($file_info, $module_srl, $upload_target_srl);
}
@@ -55,12 +60,7 @@
/**
* @brief 첨부파일 추가
**/
- function insertFile($module_srl, $upload_target_srl) {
- $file_info = Context::get('Filedata');
-
- // 정상적으로 업로드된 파일이 아니면 오류 출력
- if(!is_uploaded_file($file_info['tmp_name'])) return false;
-
+ function insertFile($file_info, $module_srl, $upload_target_srl, $download_count = 0) {
// 첨부파일 설정 가져옴
$logged_info = Context::get('logged_info');
if($logged_info->is_admin != 'Y') {
@@ -103,6 +103,7 @@
$args->direct_download = $direct_download;
$args->source_filename = $file_info['name'];
$args->uploaded_filename = $filename;
+ $args->download_count = $download_count;
$args->file_size = filesize($filename);
$args->comment = NULL;
$args->member_srl = $member_srl;
diff --git a/modules/importer/importer.controller.php b/modules/importer/importer.controller.php
index 98eaa0080..45def0692 100644
--- a/modules/importer/importer.controller.php
+++ b/modules/importer/importer.controller.php
@@ -10,11 +10,17 @@
var $oXml = null;
var $oMemberController = null;
var $oDocumentController = null;
+ var $oFileController = null;
+ var $oCommentController = null;
+ var $oTrackbackController = null;
var $position = 0;
var $imported_count = 0;
var $limit_count = 500;
+ var $module_srl = 0;
+ var $category_srl = 0;
+
/**
* @brief 초기화
**/
@@ -93,8 +99,8 @@
define('__STOP_DEBUG__', true);
// 변수 체크
- $module_srl = Context::get('module_srl');
- $category_srl = Context::get('category_list');
+ $this->module_srl = Context::get('module_srl');
+ $this->category_srl = Context::get('category_list');
$xml_file = Context::get('xml_file');
$this->position = (int)Context::get('position');
@@ -104,8 +110,12 @@
$this->oXml = new XmlParser();
// module_srl이 있으면 module데이터로 판단하여 처리, 아니면 회원정보로..
- if($module_srl) $this->importModule($xml_file, $module_srl, $category_srl);
- else $this->importMember($xml_file);
+ if($this->module_srl) {
+ $this->limit_count = 100;
+ $this->importDocument($xml_file);
+ } else {
+ $this->importMember($xml_file);
+ }
if($this->position+$this->limit_count > $this->imported_count) {
$this->add('is_finished', 'Y');
@@ -184,33 +194,130 @@
}
/**
- * @brief 게시물 import
+ * @brief 게시물정보 import
**/
- function importModule($xml_file) {
+ function importDocument($xml_file) {
$filesize = filesize($xml_file);
if($filesize<1) return;
$this->oDocumentController = &getController('document');
+ $this->oFileController = &getController('file');
+ $this->oCommentController = &getController('comment');
+ $this->oTrackbackController = &getController('trackback');
- $fp = fopen($xml_file, "r");
- $readed_size = 0;
+ $fp = @fopen($xml_file, "r");
if($fp) {
- while(!feof($fp) && $readed_size<=$filesize) {
- $str = fgets($fp, 1024);
- $readed_size += strlen($str);
-
+ $buff = '';
+ while(!feof($fp)) {
+ $str = fgets($fp,1024);
$buff .= $str;
- $buff = preg_replace_callback('!([^<]*)!is', array($this, '_importModule'), $buff);
+
+ $buff = preg_replace_callback("!(.*?)<\/document>!is", array($this, '_importDocument'), trim($buff));
+
+ if($this->position+$this->limit_count <= $this->imported_count) break;
}
fclose($fp);
}
-
- return new Object(-1,'haha');
}
- function _importModule($matches) {
- $user_id = $matches[1];
- $xml_doc = sprintf('%s',base64_decode($matches[2]));
+ function _importDocument($matches) {
+ if($this->position > $this->imported_count) {
+ $this->imported_count++;
+ return;
+ }
+
+ $sequence = $matches[1];
+ $xml_doc = $this->oXml->parse($matches[0]);
+
+ // 문서 번호 미리 따오기
+ $args->document_srl = getNextSequence();
+
+ // 첨부파일 미리 등록
+ $files = $xml_doc->document->files->file;
+ if($files && !is_array($files)) $files = array($files);
+ if(count($files)) {
+ foreach($files as $key => $val) {
+ $filename = $val->attrs->name;
+ $downloaded_count = (int)$val->downloaded_count->body;
+ $file_buff = base64_decode($val->buff);
+
+ $tmp_filename = './files/cache/tmp_uploaded_file';
+ FileHandler::writeFile($tmp_filename, $file_buff);
+
+ $file_info['tmp_name'] = $tmp_filename;
+ $file_info['name'] = $filename;
+ $this->oFileController->insertFile($file_info, $this->module_srl, $args->document_srl, $downloaded_count);
+ }
+ }
+
+ // 문서 입력
+ $args->module_srl = $this->module_srl;
+ $args->category_srl = $this->category_srl;
+ $args->is_notice = $xml_doc->document->is_notice->body;
+ $args->is_secret = $xml_doc->document->is_secret->body;
+ $args->title = $xml_doc->document->title->body;
+ $args->content = $xml_doc->document->content->body;
+ $args->readed_count = $xml_doc->document->readed_count->body;
+ $args->voted_count = $xml_doc->document->voted_count->body;
+ $args->comment_count = $xml_doc->document->comment_count->body;
+ $args->trackback_count = $xml_doc->document->trackback_count->body;
+ $args->uploaded_count = $xml_doc->document->uploaded_count->body;
+ $args->password = $xml_doc->document->password->body;
+ $args->nick_name = $xml_doc->document->nick_name->body;
+ $args->member_srl = -1;
+ $args->user_id = $xml_doc->document->user_id->body;
+ $args->user_name = $xml_doc->document->user_name->body;
+ $args->email_address = $xml_doc->document->email_address->body;
+ $args->homepage = $xml_doc->document->homepage->body;
+ $args->tags = $xml_doc->document->tags->body;
+ $args->regdate = $xml_doc->document->regdate->body;
+ $args->ipaddress = $xml_doc->document->ipaddress->body;
+ $args->allow_comment = $xml_doc->document->allow_comment->body;
+ $args->lock_comment = $xml_doc->document->lock_comment->body;
+ $args->allow_trackback = $xml_doc->document->allow_trackback->body;
+ $output = $this->oDocumentController->insertDocument($args, true);
+ if(!$output->toBool()) return;
+
+ // 코멘트 입력
+ $comments = $xml_doc->document->comments->comment;
+ if($comments && !is_array($comments)) $comments = array($comments);
+ if(count($comments)) {
+ foreach($comments as $key => $val) {
+ $comment_args->document_srl = $args->document_srl;
+ $comment_args->comment_srl = getNextSequence();
+ $comment_args->module_srl = $this->module_srl;
+ $comment_args->parent_srl = $val->parent_srl->body;
+ $comment_args->content = $val->content->body;
+ $comment_args->password = $val->password->body;
+ $comment_args->nick_name = $val->nick_name->body;
+ $comment_args->user_id = $val->user_id->body;
+ $comment_args->user_name = $val->user_name->body;
+ $comment_args->member_srl = -1;
+ $comment_args->email_address = $val->email_address->body;
+ $comment_args->regdate = $val->regdate->body;
+ $comment_args->ipaddress = $val->ipaddress->body;
+ $this->oCommentController->insertComment($comment_args, true);
+ }
+ }
+
+ // 트랙백 입력
+ $trackbacks = $xml_doc->document->trackbacks->trackback;
+ if($trackbacks && !is_array($trackbacks)) $trackbacks = array($trackbacks);
+ if(count($trackbacks)) {
+ foreach($trackbacks as $key => $val) {
+ $trackback_args->document_srl = $args->document_srl;
+ $trackback_args->module_srl = $this->module_srl;
+ $trackback_args->url = $val->url->body;
+ $trackback_args->title = $val->title->body;
+ $trackback_args->blog_name = $val->blog_name->body;
+ $trackback_args->excerpt = $val->excerpt->body;
+ $trackback_args->regdate = $val->regdate->body;
+ $trackback_args->ipaddress = $val->ipaddress->body;
+ $this->oTrackbackController->insertTrackback($trackback_args, true);
+ }
+ }
+
+ $this->imported_count ++;
return '';
}
}
diff --git a/modules/trackback/trackback.controller.php b/modules/trackback/trackback.controller.php
index 97bd08954..59d7562fb 100644
--- a/modules/trackback/trackback.controller.php
+++ b/modules/trackback/trackback.controller.php
@@ -42,18 +42,26 @@
Context::setRequestMethod("XMLRPC");
$obj = Context::gets('document_srl','url','title','excerpt');
+ if(!$obj->document_srl) return $this->stop('fail');
+ return $this->insertTrackback($obj);
+ }
+
+ function insertTrackback($obj, $manual_inserted = false) {
// GET으로 넘어온 document_srl을 참조, 없으면 오류~
$document_srl = $obj->document_srl;
- if(!$document_srl) return $this->stop('fail');
- // document model 객체 생성후 원본글을 가져옴
- $oDocumentModel = &getModel('document');
- $document = $oDocumentModel->getDocument($document_srl);
+ if(!$manual_inserted) {
+ // document model 객체 생성후 원본글을 가져옴
+ $oDocumentModel = &getModel('document');
+ $document = $oDocumentModel->getDocument($document_srl);
- // 원본글이 없거나 트랙백 허용을 하지 않으면 오류 표시
- if(!$document_srl) return $this->stop('fail');
- if($document->allow_trackback=='N') return $this->stop('fail');
+ // 원본글이 없거나 트랙백 허용을 하지 않으면 오류 표시
+ if(!$document_srl) return $this->stop('fail');
+ if($document->allow_trackback=='N') return new Object(-1,'fail');
+
+ $obj->module_srl = $document->module_srl;
+ }
// 엮인글 정리
$obj = Context::convertEncoding($obj);
@@ -62,28 +70,28 @@
// 엮인글를 입력
$obj->list_order = $obj->trackback_srl = getNextSequence();
- $obj->module_srl = $document->module_srl;
$output = executeQuery('trackback.insertTrackback', $obj);
+ if(!$output->toBool()) return $output;
// 입력에 이상이 없으면 해당 글의 엮인글 수를 올림
- if(!$output->toBool()) return $this->stop( 'fail');
+ if(!$manual_inserted) {
+ // trackback model 객체 생성
+ $oTrackbackModel = &getModel('trackback');
- // trackback model 객체 생성
- $oTrackbackModel = &getModel('trackback');
+ // 해당 글의 전체 엮인글 수를 구해옴
+ $trackback_count = $oTrackbackModel->getTrackbackCount($document_srl);
- // 해당 글의 전체 엮인글 수를 구해옴
- $trackback_count = $oTrackbackModel->getTrackbackCount($document_srl);
+ // document controller 객체 생성
+ $oDocumentController = &getController('document');
- // document controller 객체 생성
- $oDocumentController = &getController('document');
+ // 해당글의 엮인글 수를 업데이트
+ $output = $oDocumentController->updateTrackbackCount($document_srl, $trackback_count);
- // 해당글의 엮인글 수를 업데이트
- $output = $oDocumentController->updateTrackbackCount($document_srl, $trackback_count);
+ // 결과 return
+ if(!$output->toBool()) return $output;
+ }
- // 결과 return
- if(!$output->toBool()) return $this->stop('fail');
-
- $this->setMessage('success');
+ return new Object();
}
/**