From e7177034b32dbd3fa85b5144213335b289d50d91 Mon Sep 17 00:00:00 2001 From: ovclas Date: Fri, 16 Nov 2012 10:01:32 +0000 Subject: [PATCH] issue 2662 import git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12248 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- modules/importer/extract.class.php | 543 ++-- .../importer/importer.admin.controller.php | 2244 +++++++++-------- modules/importer/importer.admin.view.php | 132 +- modules/importer/importer.class.php | 78 +- modules/importer/ttimport.class.php | 1281 +++++----- 5 files changed, 2250 insertions(+), 2028 deletions(-) diff --git a/modules/importer/extract.class.php b/modules/importer/extract.class.php index 88fc25c12..c20d4e341 100644 --- a/modules/importer/extract.class.php +++ b/modules/importer/extract.class.php @@ -1,287 +1,318 @@ filename = $filename; + /** + * Get arguments for constructor, file name, start tag, end tag, tag name for each item + * @param string $filename + * @param string $startTag + * @param string $endTag + * @param string $itemTag + * @param string $itemEndTag + * @return Object + */ + function set($filename, $startTag, $endTag, $itemTag, $itemEndTag) + { + $this->filename = $filename; - $this->startTag = $startTag; - if($endTag) $this->endTag = $endTag; - $this->itemStartTag = $itemTag; - $this->itemEndTag = $itemEndTag; + $this->startTag = $startTag; + if($endTag) $this->endTag = $endTag; + $this->itemStartTag = $itemTag; + $this->itemEndTag = $itemEndTag; - $this->key = md5($filename); + $this->key = md5($filename); - $this->cache_path = './files/cache/importer/'.$this->key; - $this->cache_index_file = $this->cache_path.'/index'; + $this->cache_path = './files/cache/importer/'.$this->key; + $this->cache_index_file = $this->cache_path.'/index'; - if(!is_dir($this->cache_path)) FileHandler::makeDir($this->cache_path); + if(!is_dir($this->cache_path)) FileHandler::makeDir($this->cache_path); - return $this->openFile(); - } + return $this->openFile(); + } - /** - * Open an indicator of the file - * @return Object - */ - function openFile() { - FileHandler::removeFile($this->cache_index_file); - $this->index_fd = fopen($this->cache_index_file,"a"); - // If local file - if(!preg_match('/^http:/i',$this->filename)) { - if(!file_exists($this->filename)) return new Object(-1,'msg_no_xml_file'); - $this->fd = fopen($this->filename,"r"); - // If remote file - } else { - $url_info = parse_url($this->filename); - if(!$url_info['port']) $url_info['port'] = 80; - if(!$url_info['path']) $url_info['path'] = '/'; + /** + * Open an indicator of the file + * @return Object + */ + function openFile() + { + FileHandler::removeFile($this->cache_index_file); + $this->index_fd = fopen($this->cache_index_file,"a"); + // If local file + if(!preg_match('/^http:/i',$this->filename)) + { + if(!file_exists($this->filename)) return new Object(-1,'msg_no_xml_file'); + $this->fd = fopen($this->filename,"r"); + // If remote file + } + else + { + $url_info = parse_url($this->filename); + if(!$url_info['port']) $url_info['port'] = 80; + if(!$url_info['path']) $url_info['path'] = '/'; - $this->fd = @fsockopen($url_info['host'], $url_info['port']); - if(!$this->fd) return new Object(-1,'msg_no_xml_file'); - // If the file name contains Korean, do urlencode(iconv required) - $path = $url_info['path']; - if(preg_match('/[\xEA-\xED][\x80-\xFF]{2}/', $path)&&function_exists('iconv')) { - $path_list = explode('/',$path); - $cnt = count($path_list); - $filename = $path_list[$cnt-1]; - $filename = urlencode(iconv("UTF-8","EUC-KR",$filename)); - $path_list[$cnt-1] = $filename; - $path = implode('/',$path_list); - $url_info['path'] = $path; - } - - $header = sprintf("GET %s?%s HTTP/1.0\r\nHost: %s\r\nReferer: %s://%s\r\nConnection: Close\r\n\r\n", $url_info['path'], $url_info['query'], $url_info['host'], $url_info['scheme'], $url_info['host']); - @fwrite($this->fd, $header); - $buff = ''; - while(!feof($this->fd)) { - $buff .= $str = fgets($this->fd, 1024); - if(!trim($str)) break; - } - if(preg_match('/404 Not Found/i',$buff)) return new Object(-1,'msg_no_xml_file'); - } - - if($this->startTag) { - while(!feof($this->fd)) { - $str = fgets($this->fd, 1024); - $pos = strpos($str, $this->startTag); - if($pos !== false) { - $this->buff = substr($this->buff, $pos+strlen($this->startTag)); - $this->isStarted = true; - $this->isFinished = false; - break; - } - } - } else { - $this->isStarted = true; - $this->isFinished = false; - } - - return new Object(); - } - - /** - * Close an indicator of the file - * @return void - */ - function closeFile() { - $this->isFinished = true; - fclose($this->fd); - fclose($this->index_fd); - } - - function isFinished() { - return $this->isFinished || !$this->fd || feof($this->fd); - } - - /** - * Save item - * @return void - */ - function saveItems() { - FileHandler::removeDir($this->cache_path.$this->key); - $this->index = 0; - while(!$this->isFinished()) { - $this->getItem(); + $this->fd = @fsockopen($url_info['host'], $url_info['port']); + if(!$this->fd) return new Object(-1,'msg_no_xml_file'); + // If the file name contains Korean, do urlencode(iconv required) + $path = $url_info['path']; + if(preg_match('/[\xEA-\xED][\x80-\xFF]{2}/', $path)&&function_exists('iconv')) + { + $path_list = explode('/',$path); + $cnt = count($path_list); + $filename = $path_list[$cnt-1]; + $filename = urlencode(iconv("UTF-8","EUC-KR",$filename)); + $path_list[$cnt-1] = $filename; + $path = implode('/',$path_list); + $url_info['path'] = $path; } - } - /** - * Merge item - * @return void - */ - function mergeItems($filename) { - $this->saveItems(); + $header = sprintf("GET %s?%s HTTP/1.0\r\nHost: %s\r\nReferer: %s://%s\r\nConnection: Close\r\n\r\n", $url_info['path'], $url_info['query'], $url_info['host'], $url_info['scheme'], $url_info['host']); + @fwrite($this->fd, $header); + $buff = ''; + while(!feof($this->fd)) + { + $buff .= $str = fgets($this->fd, 1024); + if(!trim($str)) break; + } + if(preg_match('/404 Not Found/i',$buff)) return new Object(-1,'msg_no_xml_file'); + } - $filename = sprintf('%s/%s', $this->cache_path, $filename); + if($this->startTag) + { + while(!feof($this->fd)) + { + $str = fgets($this->fd, 1024); + $pos = strpos($str, $this->startTag); + if($pos !== false) + { + $this->buff = substr($this->buff, $pos+strlen($this->startTag)); + $this->isStarted = true; + $this->isFinished = false; + break; + } + } + } + else + { + $this->isStarted = true; + $this->isFinished = false; + } - $index_fd = fopen($this->cache_index_file,"r"); - $fd = fopen($filename,'w'); + return new Object(); + } - fwrite($fd, ''); - while(!feof($index_fd)) { - $target_file = trim(fgets($index_fd,1024)); - if(!file_exists($target_file)) continue; - $buff = FileHandler::readFile($target_file); - fwrite($fd, FileHandler::readFile($target_file)); + /** + * Close an indicator of the file + * @return void + */ + function closeFile() + { + $this->isFinished = true; + fclose($this->fd); + fclose($this->index_fd); + } - FileHandler::removeFile($target_file); - } - fwrite($fd, ''); - fclose($fd); - } + function isFinished() + { + return $this->isFinished || !$this->fd || feof($this->fd); + } - /** - * Get item. Put data to buff - * @return void - */ - function getItem() { - if($this->isFinished()) return; + /** + * Save item + * @return void + */ + function saveItems() + { + FileHandler::removeDir($this->cache_path.$this->key); + $this->index = 0; + while(!$this->isFinished()) + { + $this->getItem(); + } + } - while(!feof($this->fd)) { - $startPos = strpos($this->buff, $this->itemStartTag); - if($startPos !== false) { - $this->buff = substr($this->buff, $startPos); - $this->buff = preg_replace("/\>/",">\r\n",$this->buff,1); - break; - } elseif($this->endTag) { - $endPos = strpos($this->buff, $this->endTag); - if($endPos !== false) { - $this->closeFile(); - return; - } - } - $this->buff .= fgets($this->fd, 1024); - } + /** + * Merge item + * @return void + */ + function mergeItems($filename) + { + $this->saveItems(); - $startPos = strpos($this->buff, $this->itemStartTag); - if($startPos === false) { - $this->closeFile(); - return; - } + $filename = sprintf('%s/%s', $this->cache_path, $filename); - $filename = sprintf('%s/%s.xml',$this->cache_path, $this->index++); - fwrite($this->index_fd, $filename."\r\n"); + $index_fd = fopen($this->cache_index_file,"r"); + $fd = fopen($filename,'w'); - $fd = fopen($filename,'w'); + fwrite($fd, ''); + while(!feof($index_fd)) + { + $target_file = trim(fgets($index_fd,1024)); + if(!file_exists($target_file)) continue; + $buff = FileHandler::readFile($target_file); + fwrite($fd, FileHandler::readFile($target_file)); - while(!feof($this->fd)) { - $endPos = strpos($this->buff, $this->itemEndTag); - if($endPos !== false) { - $endPos += strlen($this->itemEndTag); - $buff = substr($this->buff, 0, $endPos); - fwrite($fd, $this->_addTagCRTail($buff)); - fclose($fd); - $this->buff = substr($this->buff, $endPos); - break; - } + FileHandler::removeFile($target_file); + } + fwrite($fd, ''); + fclose($fd); + } - fwrite($fd, $this->_addTagCRTail($this->buff)); - $this->buff = fgets($this->fd, 1024); - } - } + /** + * Get item. Put data to buff + * @return void + */ + function getItem() + { + if($this->isFinished()) return; - function getTotalCount() { - return $this->index; - } + while(!feof($this->fd)) + { + $startPos = strpos($this->buff, $this->itemStartTag); + if($startPos !== false) + { + $this->buff = substr($this->buff, $startPos); + $this->buff = preg_replace("/\>/",">\r\n",$this->buff,1); + break; + } + elseif($this->endTag) + { + $endPos = strpos($this->buff, $this->endTag); + if($endPos !== false) + { + $this->closeFile(); + return; + } + } + $this->buff .= fgets($this->fd, 1024); + } - function getKey() { - return $this->key; - } + $startPos = strpos($this->buff, $this->itemStartTag); + if($startPos === false) + { + $this->closeFile(); + return; + } - function _addTagCRTail($str) { - $str = preg_replace('/<\/([^>]*)>\r\n<", $str); - return $str; - } - } -?> + $filename = sprintf('%s/%s.xml',$this->cache_path, $this->index++); + fwrite($this->index_fd, $filename."\r\n"); + + $fd = fopen($filename,'w'); + + while(!feof($this->fd)) + { + $endPos = strpos($this->buff, $this->itemEndTag); + if($endPos !== false) + { + $endPos += strlen($this->itemEndTag); + $buff = substr($this->buff, 0, $endPos); + fwrite($fd, $this->_addTagCRTail($buff)); + fclose($fd); + $this->buff = substr($this->buff, $endPos); + break; + } + + fwrite($fd, $this->_addTagCRTail($this->buff)); + $this->buff = fgets($this->fd, 1024); + } + } + + function getTotalCount() + { + return $this->index; + } + + function getKey() + { + return $this->key; + } + + function _addTagCRTail($str) { + $str = preg_replace('/<\/([^>]*)>\r\n<", $str); + return $str; + } +} +/* End of file extract.class.php */ +/* Location: ./modules/importer/extract.class.php */ diff --git a/modules/importer/importer.admin.controller.php b/modules/importer/importer.admin.controller.php index 53e436997..a5adb9160 100644 --- a/modules/importer/importer.admin.controller.php +++ b/modules/importer/importer.admin.controller.php @@ -1,1101 +1,1203 @@ 0) - { - $isExists = 'true'; - $type = 'XML'; - if(stristr($str, 'tattertools')) $type = 'TTXML'; - - $this->add('type', $type); - } - fclose($fp); - $resultMessage = $lang->found_xml_file; - } - else $resultMessage = $lang->cannot_url_file; - } - else $resultMessage = $lang->cannot_allow_fopen_in_phpini; - - $this->add('exists', $isExists); - } - else - { - $realPath = FileHandler::getRealPath($filename); - - if(file_exists($realPath) && is_file($realPath)) $isExists = 'true'; - $this->add('exists', $isExists); - - if($isExists == 'true') - { - $type = 'XML'; - - $fp = fopen($realPath, "r"); $str = fgets($fp, 100); - if(stristr($str, 'tattertools')) $type = 'TTXML'; - fclose($fp); + if(strlen($str) > 0) + { + $isExists = 'true'; + $type = 'XML'; + if(stristr($str, 'tattertools')) $type = 'TTXML'; - $this->add('type', $type); + $this->add('type', $type); + } + fclose($fp); $resultMessage = $lang->found_xml_file; } - else $resultMessage = $lang->not_found_xml_file; + else $resultMessage = $lang->cannot_url_file; } - $this->add('result_message', $resultMessage); + else $resultMessage = $lang->cannot_allow_fopen_in_phpini; + + $this->add('exists', $isExists); + } + else + { + $realPath = FileHandler::getRealPath($filename); + + if(file_exists($realPath) && is_file($realPath)) $isExists = 'true'; + $this->add('exists', $isExists); + + if($isExists == 'true') + { + $type = 'XML'; + + $fp = fopen($realPath, "r"); + $str = fgets($fp, 100); + if(stristr($str, 'tattertools')) $type = 'TTXML'; + fclose($fp); + + $this->add('type', $type); + $resultMessage = $lang->found_xml_file; + } + else $resultMessage = $lang->not_found_xml_file; + } + $this->add('result_message', $resultMessage); + } + + /** + * Sync member information with document information + * @return void + */ + function procImporterAdminSync() + { + $oMemberModel = &getModel('member'); + $member_config = $oMemberModel->getMemberConfig(); + + $postFix = ($member_config->identifier == 'email_address') ? 'ByEmail' : ''; + + // 계정이 이메일인 경우 이메일 정보로 사용자를 싱크하도록 한다. 이때 변수명은 그대로 user_id를 사용한다. + + /* DBMS가 CUBRID인 경우 MySQL과 동일한 방법으로는 문서 및 댓글에 대한 사용자 정보를 동기화 할 수 없으므로 예외 처리 합니다. + CUBRID를 사용하지 않는 경우에만 보편적인 기존 질의문을 사용합니다. */ + $db_info = Context::getDBInfo (); + if($db_info->db_type != "cubrid") + { + $output = executeQuery('importer.updateDocumentSync'.$postFix); + $output = executeQuery('importer.updateCommentSync'.$postFix); + } + else + { + $output = executeQueryArray ('importer.getDocumentMemberSrlWithUserID'.$postFix); + if(is_array ($output->data) && count ($output->data)) + { + $success_count = 0; + $error_count = 0; + $total_count = 0; + foreach ($output->data as $val) + { + $args->user_id = $val->user_id; + $args->member_srl = $val->member_srl; + $tmp = executeQuery ('importer.updateDocumentSyncForCUBRID'.$postFix, $args); + if($tmp->toBool () === true) + { + $success_count++; + } + else + { + $error_count++; + } + $total_count++; + } + } // documents section + + $output = executeQueryArray ('importer.getCommentMemberSrlWithUserID'.$postFix); + if(is_array ($output->data) && count ($output->data)) + { + $success_count = 0; + $error_count = 0; + $total_count = 0; + foreach ($output->data as $val) + { + $args->user_id = $val->user_id; + $args->member_srl = $val->member_srl; + $tmp = executeQuery ('importer.updateCommentSyncForCUBRID'.$postFix, $args); + if($tmp->toBool () === true) + { + $success_count++; + } + else + { + $error_count++; + } + $total_count++; + } + } // comments section } - /** - * Sync member information with document information - * @return void - */ - function procImporterAdminSync() { - $oMemberModel = &getModel('member'); - $member_config = $oMemberModel->getMemberConfig(); - - $postFix = ($member_config->identifier == 'email_address') ? 'ByEmail' : ''; - - // 계정이 이메일인 경우 이메일 정보로 사용자를 싱크하도록 한다. 이때 변수명은 그대로 user_id를 사용한다. - - /* DBMS가 CUBRID인 경우 MySQL과 동일한 방법으로는 문서 및 댓글에 대한 사용자 정보를 동기화 할 수 없으므로 예외 처리 합니다. - CUBRID를 사용하지 않는 경우에만 보편적인 기존 질의문을 사용합니다. */ - $db_info = Context::getDBInfo (); - if ($db_info->db_type != "cubrid") { - $output = executeQuery('importer.updateDocumentSync'.$postFix); - $output = executeQuery('importer.updateCommentSync'.$postFix); - } - else { - $output = executeQueryArray ('importer.getDocumentMemberSrlWithUserID'.$postFix); - if (is_array ($output->data) && count ($output->data)) { - $success_count = 0; - $error_count = 0; - $total_count = 0; - foreach ($output->data as $val) { - $args->user_id = $val->user_id; - $args->member_srl = $val->member_srl; - $tmp = executeQuery ('importer.updateDocumentSyncForCUBRID'.$postFix, $args); - if ($tmp->toBool () === true) { - $success_count++; - } - else { - $error_count++; - } - $total_count++; - } - } // documents section - - $output = executeQueryArray ('importer.getCommentMemberSrlWithUserID'.$postFix); - if (is_array ($output->data) && count ($output->data)) { - $success_count = 0; - $error_count = 0; - $total_count = 0; - foreach ($output->data as $val) { - $args->user_id = $val->user_id; - $args->member_srl = $val->member_srl; - $tmp = executeQuery ('importer.updateCommentSyncForCUBRID'.$postFix, $args); - if ($tmp->toBool () === true) { - $success_count++; - } - else { - $error_count++; - } - $total_count++; - } - } // comments section - } - - $this->setMessage('msg_sync_completed'); - } - - /** - * Pre-analyze the xml file and cache it - * @return void - */ - function procImporterAdminPreProcessing() { - // Get the target xml file to import - $xml_file = Context::get('xml_file'); - // Get a type of the target - $type = Context::get('type'); - // Extract and cache information from the xml file - $oExtract = new extract(); - - switch($type) { - case 'member' : - $output = $oExtract->set($xml_file,'', '', ''); - if($output->toBool()) $oExtract->saveItems(); - break; - case 'message' : - $output = $oExtract->set($xml_file,'', '',''); - if($output->toBool()) $oExtract->saveItems(); - break; - case 'ttxml' : - // Category information - $output = $oExtract->set($xml_file, '', '', '', ''); - if ($output->toBool()) { - // Get a category of ttxml separately - $started = false; - $buff = ''; - while (!feof($oExtract->fd)) { - $str = fgets($oExtract->fd, 1024); - if(strstr($str, '')) { - $started = true; - $str = strstr($str, ''); - } - if(substr($str,0,strlen(''; - $oExtract->closeFile(); - $category_filename = sprintf('%s/%s', $oExtract->cache_path, 'category.xml'); - FileHandler::writeFile($category_filename, $buff); - - - // Guestbook information - $output = $oExtract->set($xml_file, '', '', '', ''); - if ($output->toBool()) { - $started = false; - $buff = ''; - while (!feof($oExtract->fd)) { - $str = fgets($oExtract->fd, 1024); - if(strstr($str, '')) { - $started = true; - $str = strstr($str, ''); - } - if ($started) { - $pos = strpos($str, ''); - if ($pos !== false) { - $buff .= substr($str, 0, $pos + strlen('')); - break; - } - $buff .= $str; - } - } - $oExtract->closeFile(); - $guestbook_filename = sprintf('%s/%s', $oExtract->cache_path, 'guestbook.xml'); - FileHandler::writeFile($guestbook_filename, $buff); - // Individual items - $output = $oExtract->set($xml_file,'', ''); - if($output->toBool()) $oExtract->saveItems(); - - } - } - break; - default : - // First get category information - $output = $oExtract->set($xml_file,'', '', ''); - if($output->toBool()) { - $oExtract->mergeItems('category.xml'); - // Get each item - $output = $oExtract->set($xml_file,'', '', ''); - if($output->toBool()) $oExtract->saveItems(); - } - break; - - } - - if(!$output->toBool()) { - $this->add('error',0); - $this->add('status',-1); - $this->setMessage($output->getMessage()); - return; - } - // Notify that all data completely extracted - $this->add('type',$type); - $this->add('total',$oExtract->getTotalCount()); - $this->add('cur',0); - $this->add('key', $oExtract->getKey()); - $this->add('status',0); - } - - /** - * Migrate data after completing xml file extraction - * @return void - */ - function procImporterAdminImport() { - // Variable setting - $type = Context::get('type'); - $total = Context::get('total'); - $cur = Context::get('cur'); - $key = Context::get('key'); - $user_id = Context::get('user_id'); - $target_module = Context::get('target_module'); - $guestbook_target_module = Context::get('guestbook_target_module'); - $this->unit_count = Context::get('unit_count'); - // Check if an index file exists - $index_file = './files/cache/importer/'.$key.'/index'; - if(!file_exists($index_file)) return new Object(-1, 'msg_invalid_xml_file'); - - switch($type) { - case 'ttxml' : - if(!$target_module) return new Object(-1,'msg_invalid_request'); - - $oModuleModel = &getModel('module'); - $columnList = array('module_srl', 'module'); - $target_module_info = $oModuleModel->getModuleInfoByModuleSrl($target_module, $columnList); - - require_once('./modules/importer/ttimport.class.php'); - $oTT = new ttimport(); - $cur = $oTT->importModule($key, $cur, $index_file, $this->unit_count, $target_module, $guestbook_target_module, $user_id, $target_module_info->module); - break; - case 'message' : - $cur = $this->importMessage($key, $cur, $index_file); - break; - case 'member' : - $cur = $this->importMember($key, $cur, $index_file); - break; - case 'module' : - // Check if the target module exists - if(!$target_module) return new Object(-1,'msg_invalid_request'); - $cur = $this->importModule($key, $cur, $index_file, $target_module); - break; - } - // Notify that all data completely extracted - $this->add('type',$type); - $this->add('total',$total); - $this->add('cur',$cur); - $this->add('key', $key); - $this->add('target_module', $target_module); - // When completing, success message appears and remove the cache files - if($total <= $cur) { - $this->setMessage( sprintf(Context::getLang('msg_import_finished'), $cur, $total) ); - FileHandler::removeDir('./files/cache/importer/'.$key); - } else $this->setMessage( sprintf(Context::getLang('msg_importing'), $total, $cur) ); - } - - /** - * Import member information - * @param int $key - * @param int $cur - * @param string $index_file - * @return int - */ - function importMember($key, $cur, $index_file) { - if(!$cur) $cur = 0; - // Create the xmlParser object - $oXmlParser = new XmlParser(); - // Create objects for importing member information - $this->oMemberController = &getController('member'); - $this->oMemberModel = &getModel('member'); - // Get a default member group - $default_group = $this->oMemberModel->getDefaultGroup(); - $default_group_srl = $default_group->group_srl; - // Get information of the Webmaster - $oModuleModel = &getModel('module'); - $member_config = $oModuleModel->getModuleConfig('member'); - // Open an index file - $f = fopen($index_file,"r"); - // Pass if already read - for($i=0;$i<$cur;$i++) fgets($f, 1024); - // Read by each line until the condition meets - for($idx=$cur;$idx<$cur+$this->unit_count;$idx++) { - if(feof($f)) break; - // Find a given location - $target_file = trim(fgets($f, 1024)); - // Load and parse the file - $xmlObj = $oXmlParser->loadXmlFile($target_file); - FileHandler::removeFile($target_file); - if(!$xmlObj) continue; - // List Objects - $obj = null; - $obj->user_id = base64_decode($xmlObj->member->user_id->body); - $obj->password = base64_decode($xmlObj->member->password->body); - $obj->user_name = base64_decode($xmlObj->member->user_name->body); - $obj->nick_name = base64_decode($xmlObj->member->nick_name->body); - if(!$obj->user_name) $obj->user_name = $obj->nick_name; - $obj->email = base64_decode($xmlObj->member->email->body); - $obj->homepage = base64_decode($xmlObj->member->homepage->body); - $obj->blog = base64_decode($xmlObj->member->blog->body); - $obj->birthday = substr(base64_decode($xmlObj->member->birthday->body),0,8); - $obj->allow_mailing = base64_decode($xmlObj->member->allow_mailing->body); - $obj->point = base64_decode($xmlObj->member->point->body); - $obj->image_nickname = base64_decode($xmlObj->member->image_nickname->buff->body); - $obj->image_mark = base64_decode($xmlObj->member->image_mark->buff->body); - $obj->profile_image = base64_decode($xmlObj->member->profile_image->buff->body); - $obj->signature = base64_decode($xmlObj->member->signature->body); - $obj->regdate = base64_decode($xmlObj->member->regdate->body); - $obj->last_login = base64_decode($xmlObj->member->last_login->body); - - if($xmlObj->member->extra_vars) { - foreach($xmlObj->member->extra_vars as $key => $val) { - if(in_array($key, array('node_name','attrs','body'))) continue; - $obj->extra_vars->{$key} = base64_decode($val->body); - } - } - // Create url for homepage and blog - if($obj->homepage && !preg_match("/^http:\/\//i",$obj->homepage)) $obj->homepage = 'http://'.$obj->homepage; - if($obj->blog && !preg_match("/^http:\/\//i",$obj->blog)) $obj->blog = 'http://'.$obj->blog; - // email address column - $obj->email_address = $obj->email; - list($obj->email_id, $obj->email_host) = explode('@', $obj->email); - // Set the mailing option - if($obj->allow_mailing!='Y') $obj->allow_mailing = 'N'; - // Set the message option - $obj->allow_message = 'Y'; - if(!in_array($obj->allow_message, array('Y','N','F'))) $obj->allow_message= 'Y'; - // Get member-join date if the last login time is not found - if(!$obj->last_login) $obj->last_login = $obj->regdate; - // Get a member_srl - $obj->member_srl = getNextSequence(); - $obj->list_order = -1 * $obj->member_srl; - // List extra vars - $extra_vars = $obj->extra_vars; - unset($obj->extra_vars); - $obj->extra_vars = serialize($extra_vars); - // Check if the same nickname is existing - $nick_args = null; - $nick_args->nick_name = $obj->nick_name; - $nick_output = executeQuery('member.getMemberSrl', $nick_args); - if(!$nick_output->toBool()) $obj->nick_name .= '_'.$obj->member_srl; - // Add a member - $output = executeQuery('member.insertMember', $obj); - - if($output->toBool() && !($obj->password)){ - // Send a mail telling the user to reset his password. - $oMail = new Mail(); - $oMail->setTitle("Password update for your " . getFullSiteUrl() . " account"); - $webmaster_name = $member_config->webmaster_name?$member_config->webmaster_name:'Webmaster'; - $oMail->setContent("Dear $obj->user_name,

- We recently migrated our phpBB forum to XpressEngine. Since you password was encrypted we could not migrate it too, so please reset it by following this link: - " . getFullSiteUrl() . "?act=dispMemberFindAccount. You need to enter you email address and hit the 'Find account' button. You will then receive an email with a new, generated password that you can change after login.

- - Thank you for your understanding,
- {$webmaster_name}" - ); - $oMail->setSender($webmaster_name, $member_config->webmaster_email); - $oMail->setReceiptor( $obj->user_name, $obj->email); - $oMail->send(); - } - - // add group join/image name-mark-signiture and so on if a new member successfully added - if($output->toBool()) { - // Join to the default group - $obj->group_srl = $default_group_srl; - executeQuery('member.addMemberToGroup',$obj); - // Image name - if($obj->image_nickname) { - $target_path = sprintf('files/member_extra_info/image_name/%s/', getNumberingPath($obj->member_srl)); - $target_filename = sprintf('%s%d.gif', $target_path, $obj->member_srl); - FileHandler::writeFile($target_filename, $obj->image_nickname); - } - // Image mark - if($obj->image_mark && file_exists($obj->image_mark)) { - $target_path = sprintf('files/member_extra_info/image_mark/%s/', getNumberingPath($obj->member_srl)); - $target_filename = sprintf('%s%d.gif', $target_path, $obj->member_srl); - FileHandler::writeFile($target_filename, $obj->image_mark); - } - // Profile image - if($obj->profile_image) { - $target_path = sprintf('files/member_extra_info/profile_image/%s/', getNumberingPath($obj->member_srl)); - $target_filename = sprintf('%s%d.gif', $target_path, $obj->member_srl); - FileHandler::writeFile($target_filename, $obj->profile_image); - } - // Signiture - if($obj->signature) { - $signature = removeHackTag($obj->signature); - $signature_buff = sprintf('%s', $signature); - - $target_path = sprintf('files/member_extra_info/signature/%s/', getNumberingPath($obj->member_srl)); - if(!is_dir($target_path)) FileHandler::makeDir($target_path); - $target_filename = sprintf('%s%d.signature.php', $target_path, $obj->member_srl); - - FileHandler::writeFile($target_filename, $signature_buff); - } - } - } - - fclose($f); - - return $idx-1; - } - - /** - * Import message information parsed from a given xml file - * @param int $key - * @param int $cur - * @param string $index_file - * @return int - */ - function importMessage($key, $cur, $index_file) { - if(!$cur) $cur = 0; - // Create the xmlParser object - $oXmlParser = new XmlParser(); - // Open an index file - $f = fopen($index_file,"r"); - // Pass if already read - for($i=0;$i<$cur;$i++) fgets($f, 1024); - // Read each line until the condition meets - for($idx=$cur;$idx<$cur+$this->unit_count;$idx++) { - if(feof($f)) break; - // Find a location - $target_file = trim(fgets($f, 1024)); - // Load and parse the file - $xmlObj = $oXmlParser->loadXmlFile($target_file); - FileHandler::removeFile($target_file); - if(!$xmlObj) continue; - // List objects - $obj = null; - $obj->receiver = base64_decode($xmlObj->message->receiver->body); - $obj->sender = base64_decode($xmlObj->message->sender->body); - $obj->title = base64_decode($xmlObj->message->title->body); - $obj->content = base64_decode($xmlObj->message->content->body); - $obj->readed = base64_decode($xmlObj->message->readed->body)=='Y'?'Y':'N'; - $obj->regdate = base64_decode($xmlObj->message->regdate->body); - $obj->readed_date = base64_decode($xmlObj->message->readed_date->body); - // Get member_srl of sender/recipient (If not exists, pass) - if(!$obj->sender) continue; - $sender_args->user_id = $obj->sender; - $sender_output = executeQuery('member.getMemberInfo',$sender_args); - $sender_srl = $sender_output->data->member_srl; - if(!$sender_srl){ - unset($sender_args); - $sender_args->email_address = $obj->sender; - $sender_output = executeQuery('member.getMemberInfoByEmailAddress',$sender_args); - $sender_srl = $sender_output->data->member_srl; - } - if(!$sender_srl) continue; - - $receiver_args->user_id = $obj->receiver; - if(!$obj->receiver) continue; - $receiver_output = executeQuery('member.getMemberInfo',$receiver_args); - $receiver_srl = $receiver_output->data->member_srl; - if(!$receiver_srl){ - unset($receiver_args); - $receiver_args->email_address = $obj->receiver; - $receiver_output = executeQuery('member.getMemberInfoByEmailAddress',$receiver_args); - $receiver_srl = $receiver_output->data->member_srl; - } - if(!$receiver_srl) continue; - // Message to save into sender's message box - $sender_args->sender_srl = $sender_srl; - $sender_args->receiver_srl = $receiver_srl; - $sender_args->message_type = 'S'; - $sender_args->title = $obj->title; - $sender_args->content = $obj->content; - $sender_args->readed = $obj->readed; - $sender_args->regdate = $obj->regdate; - $sender_args->readed_date = $obj->readed_date; - $sender_args->related_srl = getNextSequence(); - $sender_args->message_srl = getNextSequence(); - $sender_args->list_order = $sender_args->message_srl * -1; - - $output = executeQuery('communication.sendMessage', $sender_args); - if($output->toBool()) { - // Message to save into recipient's massage box - $receiver_args->message_srl = $sender_args->related_srl; - $receiver_args->list_order = $sender_args->related_srl*-1; - $receiver_args->sender_srl = $sender_srl; - if(!$receiver_args->sender_srl) $receiver_args->sender_srl = $receiver_srl; - $receiver_args->receiver_srl = $receiver_srl; - $receiver_args->message_type = 'R'; - $receiver_args->title = $obj->title; - $receiver_args->content = $obj->content; - $receiver_args->readed = $obj->readed; - $receiver_args->regdate = $obj->regdate; - $receiver_args->readed_date = $obj->readed_date; - $output = executeQuery('communication.sendMessage', $receiver_args); - } - } - - fclose($f); - - return $idx-1; - } - - /** - * Import data in module.xml format - * @param int $key - * @param int $cur - * @param string $index_file - * @param int $module_srl - * @return int - */ - function importModule($key, $cur, $index_file, $module_srl) { - // Pre-create the objects needed - $this->oXmlParser = new XmlParser(); - // Get category information of the target module - $oDocumentController = &getController('document'); - $oDocumentModel = &getModel('document'); - $category_list = $category_titles = array(); - $category_list = $oDocumentModel->getCategoryList($module_srl); - if(count($category_list)) foreach($category_list as $key => $val) $category_titles[$val->title] = $val->category_srl; - // Extract category information - $category_file = preg_replace('/index$/i', 'category.xml', $index_file); - if(file_exists($category_file)) { - $buff = FileHandler::readFile($category_file); - - // Create the xmlParser object - $xmlDoc = $this->oXmlParser->loadXmlFile($category_file); - - $categories = $xmlDoc->items->category; - if($categories) { - if(!is_array($categories)) $categories = array($categories); - $match_sequence = array(); - foreach($categories as $k => $v) { - $category = trim(base64_decode($v->body)); - if(!$category || $category_titles[$category]) continue; - - $sequence = $v->attrs->sequence; - $parent = $v->attrs->parent; - - $obj = null; - $obj->title = $category; - $obj->module_srl = $module_srl; - if($parent) $obj->parent_srl = $match_sequence[$parent]; - - $output = $oDocumentController->insertCategory($obj); - if($output->toBool()) $match_sequence[$sequence] = $output->get('category_srl'); - } - $oDocumentController = &getController('document'); - $oDocumentController->makeCategoryFile($module_srl); - } - FileHandler::removeFile($category_file); - } - - $category_list = $category_titles = array(); - $category_list = $oDocumentModel->getCategoryList($module_srl); - if(count($category_list)) foreach($category_list as $key => $val) $category_titles[$val->title] = $val->category_srl; - - $ek_args->module_srl = $module_srl; - $output = executeQueryArray('document.getDocumentExtraKeys', $ek_args); - if($output->data) { - foreach($output->data as $key => $val) $extra_keys[$val->eid] = true; - } - - if(!$cur) $cur = 0; - // Open an index file - $f = fopen($index_file,"r"); - // Pass if already read - for($i=0;$i<$cur;$i++) fgets($f, 1024); - // Read each line until the condition meets - for($idx=$cur;$idx<$cur+$this->unit_count;$idx++) { - if(feof($f)) break; - // Find a location - $target_file = trim(fgets($f, 1024)); - - if(!file_exists($target_file)) continue; - // Importing data from now on - $fp = fopen($target_file,"r"); - if(!$fp) continue; - - $obj = null; - $obj->module_srl = $module_srl; - $obj->document_srl = getNextSequence(); - - $files = array(); - $extra_vars = array(); - - $started = false; - $buff = null; - // Start from the body data - while(!feof($fp)) { - $str = fgets($fp, 1024); - // Prepare an item - if(trim($str) == '') { - $started = true; - // Trackback inserted - } else if(substr($str,0,11) == 'trackback_count = $this->importTrackbacks($fp, $module_srl, $obj->document_srl); - continue; - // Comments inserted - } else if(substr($str,0,9) == 'comment_count = $this->importComments($fp, $module_srl, $obj->document_srl); - continue; - // Attachment inserted - } else if(substr($str,0,9) == 'uploaded_count = $this->importAttaches($fp, $module_srl, $obj->document_srl, $files); - continue; - // When starting extra variabls - } elseif(trim($str) == '') { - $extra_vars = $this->importExtraVars($fp); - continue; - } - - if($started) $buff .= $str; - } - - $xmlDoc = $this->oXmlParser->parse($buff); - - $category = base64_decode($xmlDoc->post->category->body); - if($category_titles[$category]) $obj->category_srl = $category_titles[$category]; - - $obj->member_srl = 0; - - $obj->is_notice = base64_decode($xmlDoc->post->is_notice->body)=='Y'?'Y':'N'; - $obj->status = base64_decode($xmlDoc->post->is_secret->body)=='Y'?$oDocumentModel->getConfigStatus('secret'):$oDocumentModel->getConfigStatus('public'); - $obj->title = base64_decode($xmlDoc->post->title->body); - $obj->content = base64_decode($xmlDoc->post->content->body); - $obj->readed_count = base64_decode($xmlDoc->post->readed_count->body); - $obj->voted_count = base64_decode($xmlDoc->post->voted_count->body); - $obj->blamed_count = base64_decode($xmlDoc->post->blamed_count->body); - $obj->password = base64_decode($xmlDoc->post->password->body); - $obj->user_name = base64_decode($xmlDoc->post->user_name->body); - $obj->nick_name = base64_decode($xmlDoc->post->nick_name->body); - if(!$obj->user_name) $obj->user_name = $obj->nick_name; - $obj->user_id = base64_decode($xmlDoc->post->user_id->body); - $obj->email_address = base64_decode($xmlDoc->post->email->body); - $obj->homepage = base64_decode($xmlDoc->post->homepage->body); - if($obj->homepage && !preg_match('/^http:\/\//i',$obj->homepage)) $obj->homepage = 'http://'.$obj->homepage; - $obj->tags = base64_decode($xmlDoc->post->tags->body); - $obj->regdate = base64_decode($xmlDoc->post->regdate->body); - $obj->last_update = base64_decode($xmlDoc->post->update->body); - $obj->last_updater = base64_decode($xmlDoc->post->last_updater->body); - if(!$obj->last_update) $obj->last_update = $obj->regdate; - $obj->ipaddress = base64_decode($xmlDoc->post->ipaddress->body); - $obj->list_order = $obj->update_order = $obj->document_srl*-1; - $obj->commentStatus = base64_decode($xmlDoc->post->allow_comment->body)!='N'?'ALLOW':'DENY'; - $obj->allow_trackback = base64_decode($xmlDoc->post->allow_trackback->body)!='N'?'Y':'N'; - $obj->notify_message = base64_decode($xmlDoc->post->is_notice->body); - // Change content information (attachment) - if(count($files)) { - foreach($files as $key => $val) { - $obj->content = preg_replace('/(src|href)\=(["\']?)'.preg_quote($key).'(["\']?)/i','$1="'.$val.'"',$obj->content); - $obj->content = preg_replace('/(["\']?).\/files\/(.+)\/'.preg_quote($key).'([^"\']+)(["\']?)/i','"'.$val.'"',$obj->content); - $obj->content = preg_replace('/(["\']?)files\/(.+)\/'.preg_quote($key).'([^"\']+)(["\']?)/i','"'.$val.'"',$obj->content); - } - } - - $output = executeQuery('document.insertDocument', $obj); - - if($output->toBool() && $obj->tags) { - $tag_list = explode(',',$obj->tags); - $tag_count = count($tag_list); - for($i=0;$i<$tag_count;$i++) { - $args = null; - $args->tag_srl = getNextSequence(); - $args->module_srl = $module_srl; - $args->document_srl = $obj->document_srl; - $args->tag = trim($tag_list[$i]); - $args->regdate = $obj->regdate; - if(!$args->tag) continue; - $output = executeQuery('tag.insertTag', $args); - } - - } - // Add extra variables - if(count($extra_vars)) { - foreach($extra_vars as $key => $val) { - if(!$val->value) continue; - unset($e_args); - $e_args->module_srl = $module_srl; - $e_args->document_srl = $obj->document_srl; - $e_args->var_idx = $val->var_idx; - $e_args->value = $val->value; - $e_args->lang_code = $val->lang_code; - $e_args->eid = $val->eid; - // Create a key for extra vars if not exists (except vars for title and content) - if(!preg_match('/^(title|content)_(.+)$/i',$e_args->eid) && !$extra_keys[$e_args->eid]) { - unset($ek_args); - $ek_args->module_srl = $module_srl; - $ek_args->var_idx = $val->var_idx; - $ek_args->var_name = $val->eid; - $ek_args->var_type = 'text'; - $ek_args->var_is_required = 'N'; - $ek_args->var_default = ''; - $ek_args->eid = $val->eid; - $output = executeQuery('document.insertDocumentExtraKey', $ek_args); - $extra_keys[$ek_args->eid] = true; - } - - $output = executeQuery('document.insertDocumentExtraVar', $e_args); - } - } - - fclose($fp); - FileHandler::removeFile($target_file); - } - - fclose($f); - // Sync category counts - if(count($category_list)) foreach($category_list as $key => $val) $oDocumentController->updateCategoryCount($module_srl, $val->category_srl); - - return $idx-1; - } - - /** - * Trackbacks - * @param resource $fp - * @param int $module_srl - * @param int $document_srl - * @return int - */ - function importTrackbacks($fp, $module_srl, $document_srl) { - $started = false; - $buff = null; - $cnt = 0; - while(!feof($fp)) { - - $str = fgets($fp, 1024); - // If is, break - if(trim($str) == '') break; - // If , start importing - if(trim($str) == '') $started = true; - - if($started) $buff .= $str; - // If , insert to the DB - if(trim($str) == '') { - $xmlDoc = $this->oXmlParser->parse($buff); - - $obj = null; - $obj->trackback_srl = getNextSequence(); - $obj->module_srl = $module_srl; - $obj->document_srl = $document_srl; - $obj->url = base64_decode($xmlDoc->trackback->url->body); - $obj->title = base64_decode($xmlDoc->trackback->title->body); - $obj->blog_name = base64_decode($xmlDoc->trackback->blog_name->body); - $obj->excerpt = base64_decode($xmlDoc->trackback->excerpt->body); - $obj->regdate = base64_decode($xmlDoc->trackback->regdate->body); - $obj->ipaddress = base64_decode($xmlDoc->trackback->ipaddress->body); - $obj->list_order = -1*$obj->trackback_srl; - $output = executeQuery('trackback.insertTrackback', $obj); - if($output->toBool()) $cnt++; - - $buff = null; - $started = false; - } - } - return $cnt; - } - - /** - * Comments - * @param resource $fp - * @param int $module_srl - * @param int $document_srl - * @return int - */ - function importComments($fp, $module_srl, $document_srl) { - $started = false; - $buff = null; - $cnt = 0; - - $sequences = array(); - - while(!feof($fp)) { - - $str = fgets($fp, 1024); - // If is, break - if(trim($str) == '') break; - // If is, start importing - if(trim($str) == '') { - $started = true; - $obj = null; - $obj->comment_srl = getNextSequence(); - $files = array(); - } - // If uploaded_count = $this->importAttaches($fp, $module_srl, $obj->comment_srl, $files); - continue; - } - - if($started) $buff .= $str; - // If is, insert to the DB - if(trim($str) == '') { - $xmlDoc = $this->oXmlParser->parse($buff); - - $sequence = base64_decode($xmlDoc->comment->sequence->body); - $sequences[$sequence] = $obj->comment_srl; - $parent = base64_decode($xmlDoc->comment->parent->body); - - $obj->module_srl = $module_srl; - - if($parent) $obj->parent_srl = $sequences[$parent]; - else $obj->parent_srl = 0; - - $obj->document_srl = $document_srl; - $obj->is_secret = base64_decode($xmlDoc->comment->is_secret->body)=='Y'?'Y':'N'; - $obj->notify_message = base64_decode($xmlDoc->comment->notify_message->body)=='Y'?'Y':'N'; - $obj->content = base64_decode($xmlDoc->comment->content->body); - $obj->voted_count = base64_decode($xmlDoc->comment->voted_count->body); - $obj->blamed_count = base64_decode($xmlDoc->comment->blamed_count->body); - $obj->password = base64_decode($xmlDoc->comment->password->body); - $obj->user_name =base64_decode($xmlDoc->comment->user_name->body); - $obj->nick_name = base64_decode($xmlDoc->comment->nick_name->body); - if(!$obj->user_name) $obj->user_name = $obj->nick_name; - $obj->user_id = base64_decode($xmlDoc->comment->user_id->body); - $obj->member_srl = 0; - $obj->email_address = base64_decode($xmlDoc->comment->email->body); - $obj->homepage = base64_decode($xmlDoc->comment->homepage->body); - $obj->regdate = base64_decode($xmlDoc->comment->regdate->body); - $obj->last_update = base64_decode($xmlDoc->comment->update->body); - if(!$obj->last_update) $obj->last_update = $obj->regdate; - $obj->ipaddress = base64_decode($xmlDoc->comment->ipaddress->body); - $obj->list_order = $obj->comment_srl*-1; - // Change content information (attachment) - if(count($files)) { - foreach($files as $key => $val) { - $obj->content = preg_replace('/(src|href)\=(["\']?)'.preg_quote($key).'(["\']?)/i','$1="'.$val.'"',$obj->content); - } - } - // Comment list first - $list_args = null; - $list_args->comment_srl = $obj->comment_srl; - $list_args->document_srl = $obj->document_srl; - $list_args->module_srl = $obj->module_srl; - $list_args->regdate = $obj->regdate; - // Set data directly if parent comment doesn't exist - if(!$obj->parent_srl) { - $list_args->head = $list_args->arrange = $obj->comment_srl; - $list_args->depth = 0; - // Get parent_srl if parent comment exists - } else { - // Get parent comment infomation - $parent_args->comment_srl = $obj->parent_srl; - $parent_output = executeQuery('comment.getCommentListItem', $parent_args); - // Return if parent comment doesn't exist - if(!$parent_output->toBool() || !$parent_output->data) continue; - $parent = $parent_output->data; - - $list_args->head = $parent->head; - $list_args->depth = $parent->depth+1; - if($list_args->depth<2) $list_args->arrange = $obj->comment_srl; - else { - $list_args->arrange = $parent->arrange; - $output = executeQuery('comment.updateCommentListArrange', $list_args); - if(!$output->toBool()) return $output; - } - } - - $output = executeQuery('comment.insertCommentList', $list_args); - if($output->toBool()) { - $output = executeQuery('comment.insertComment', $obj); - if($output->toBool()) $cnt++; - } - - $buff = null; - $started = false; - } - } - return $cnt; - } - - /** - * Import attachment - * @param resource $fp - * @param int $module_srl - * @param int $upload_target_srl - * @param array $files - * @return int - */ - function importAttaches($fp, $module_srl, $upload_target_srl, &$files) { - $uploaded_count = 0; - - $started = false; - $buff = null; - - while(!feof($fp)) { - $str = trim(fgets($fp, 1024)); - // If it ends with , break - if(trim($str) == '') break; - // If it starts with , collect attachments - if(trim($str) == '') { - $file_obj = null; - $file_obj->file_srl = getNextSequence(); - $file_obj->upload_target_srl = $upload_target_srl; - $file_obj->module_srl = $module_srl; - - $started = true; - $buff = null; - // If it starts with , handle the attachement in xml file - } else if(trim($str) == '') { - $file_obj->file = $this->saveTemporaryFile($fp); - continue; - } - - if($started) $buff .= $str; - // If it ends with , handle attachements - if(trim($str) == '') { - $xmlDoc = $this->oXmlParser->parse($buff.$str); - - $file_obj->source_filename = base64_decode($xmlDoc->attach->filename->body); - $file_obj->download_count = base64_decode($xmlDoc->attach->download_count->body); - - if(!$file_obj->file) { - $url = base64_decode($xmlDoc->attach->url->body); - $path = base64_decode($xmlDoc->attach->path->body); - if($path && file_exists($path)) $file_obj->file = $path; - else { - $file_obj->file = $this->getTmpFilename(); - FileHandler::getRemoteFile($url, $file_obj->file); - } - } - - if(file_exists($file_obj->file)) { - // Set upload path by checking if the attachement is an image or other kind of file - if(preg_match("/\.(jpe?g|gif|png|wm[va]|mpe?g|avi|swf|flv|mp[1-4]|as[fx]|wav|midi?|moo?v|qt|r[am]{1,2}|m4v)$/i", $file_obj->source_filename)) + $this->setMessage('msg_sync_completed'); + } + + /** + * Pre-analyze the xml file and cache it + * @return void + */ + function procImporterAdminPreProcessing() + { + // Get the target xml file to import + $xml_file = Context::get('xml_file'); + // Get a type of the target + $type = Context::get('type'); + // Extract and cache information from the xml file + $oExtract = new extract(); + + switch($type) + { + case 'member' : + $output = $oExtract->set($xml_file,'', '', ''); + if($output->toBool()) $oExtract->saveItems(); + break; + case 'message' : + $output = $oExtract->set($xml_file,'', '',''); + if($output->toBool()) $oExtract->saveItems(); + break; + case 'ttxml' : + // Category information + $output = $oExtract->set($xml_file, '', '', '', ''); + if ($output->toBool()) + { + // Get a category of ttxml separately + $started = false; + $buff = ''; + while (!feof($oExtract->fd)) + { + $str = fgets($oExtract->fd, 1024); + if(strstr($str, '')) { - // Immediately remove the direct file if it has any kind of extensions for hacking - $file_obj->source_filename = preg_replace('/\.(php|phtm|html?|cgi|pl|exe|jsp|asp|inc)/i', '$0-x', $file_obj->source_filename); - $file_obj->source_filename = str_replace(array('<', '>'), array('%3C', '%3E'), $file_obj->source_filename); - - $path = sprintf("./files/attach/images/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); - - $ext = substr(strrchr($file_obj->source_filename,'.'),1); - $_filename = md5(crypt(rand(1000000, 900000), rand(0, 100))).'.'.$ext; - $filename = $path.$_filename; - - $idx = 1; - while(file_exists($filename)) { - $filename = $path.preg_replace('/\.([a-z0-9]+)$/i','_'.$idx.'.$1', $_filename); - $idx++; - } - - $file_obj->direct_download = 'Y'; + $started = true; + $str = strstr($str, ''); } - else { - $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); - $filename = $path.md5(crypt(rand(1000000,900000), rand(0,100))); - $file_obj->direct_download = 'N'; - } - // Create a directory - if(!FileHandler::makeDir($path)) continue; + if(substr($str,0,strlen(''; + $oExtract->closeFile(); + $category_filename = sprintf('%s/%s', $oExtract->cache_path, 'category.xml'); + FileHandler::writeFile($category_filename, $buff); - if(preg_match('/^\.\/files\/cache\/importer/i',$file_obj->file)) FileHandler::rename($file_obj->file, $filename); - else @copy($file_obj->file, $filename); - // Insert the file to the DB - unset($file_obj->file); - if(file_exists($filename)) { - $file_obj->uploaded_filename = $filename; - $file_obj->file_size = filesize($filename); - $file_obj->comment = NULL; - $file_obj->member_srl = 0; - $file_obj->sid = md5(rand(rand(1111111,4444444),rand(4444445,9999999))); - $file_obj->isvalid = 'Y'; - $output = executeQuery('file.insertFile', $file_obj); + // Guestbook information + $output = $oExtract->set($xml_file, '', '', '', ''); + if($output->toBool()) + { + $started = false; + $buff = ''; + while (!feof($oExtract->fd)) + { + $str = fgets($oExtract->fd, 1024); + if(strstr($str, '')) + { + $started = true; + $str = strstr($str, ''); + } + if($started) + { + $pos = strpos($str, ''); + if($pos !== false) + { + $buff .= substr($str, 0, $pos + strlen('')); + break; + } + $buff .= $str; + } + } + $oExtract->closeFile(); + $guestbook_filename = sprintf('%s/%s', $oExtract->cache_path, 'guestbook.xml'); + FileHandler::writeFile($guestbook_filename, $buff); + // Individual items + $output = $oExtract->set($xml_file,'', ''); + if($output->toBool()) $oExtract->saveItems(); + } + } + break; + default : + // First get category information + $output = $oExtract->set($xml_file,'', '', ''); + if($output->toBool()) + { + $oExtract->mergeItems('category.xml'); + // Get each item + $output = $oExtract->set($xml_file,'', '', ''); + if($output->toBool()) $oExtract->saveItems(); + } + break; + } - if($output->toBool()) { - $uploaded_count++; - $tmp_obj = null; - $tmp_obj->source_filename = $file_obj->source_filename; - if($file_obj->direct_download == 'Y') $files[$file_obj->source_filename] = $file_obj->uploaded_filename; - else $files[$file_obj->source_filename] = getUrl('','module','file','act','procFileDownload','file_srl',$file_obj->file_srl,'sid',$file_obj->sid); - } - } - } - } - } - return $uploaded_count; - } + if(!$output->toBool()) + { + $this->add('error',0); + $this->add('status',-1); + $this->setMessage($output->getMessage()); + return; + } + // Notify that all data completely extracted + $this->add('type',$type); + $this->add('total',$oExtract->getTotalCount()); + $this->add('cur',0); + $this->add('key', $oExtract->getKey()); + $this->add('status',0); + } - /** - * Return a filename to temporarily use - * @return string - */ - function getTmpFilename() { - $path = "./files/cache/importer"; - if(!is_dir($path)) FileHandler::makeDir($path); - $filename = sprintf("%s/%d", $path, rand(11111111,99999999)); - if(file_exists($filename)) $filename .= rand(111,999); - return $filename; - } + /** + * Migrate data after completing xml file extraction + * @return void + */ + function procImporterAdminImport() + { + // Variable setting + $type = Context::get('type'); + $total = Context::get('total'); + $cur = Context::get('cur'); + $key = Context::get('key'); + $user_id = Context::get('user_id'); + $target_module = Context::get('target_module'); + $guestbook_target_module = Context::get('guestbook_target_module'); + $this->unit_count = Context::get('unit_count'); + // Check if an index file exists + $index_file = './files/cache/importer/'.$key.'/index'; + if(!file_exists($index_file)) return new Object(-1, 'msg_invalid_xml_file'); - /** - * Read buff until key value comes out from a specific file point - * @param resource $fp - * @return string - */ - function saveTemporaryFile($fp) { - $temp_filename = $this->getTmpFilename(); - $f = fopen($temp_filename, "w"); + switch($type) + { + case 'ttxml' : + if(!$target_module) return new Object(-1,'msg_invalid_request'); - $buff = ''; - while(!feof($fp)) { - $str = trim(fgets($fp, 1024)); - if(trim($str) == '') break; + $oModuleModel = &getModel('module'); + $columnList = array('module_srl', 'module'); + $target_module_info = $oModuleModel->getModuleInfoByModuleSrl($target_module, $columnList); - $buff .= $str; + require_once('./modules/importer/ttimport.class.php'); + $oTT = new ttimport(); + $cur = $oTT->importModule($key, $cur, $index_file, $this->unit_count, $target_module, $guestbook_target_module, $user_id, $target_module_info->module); + break; + case 'message' : + $cur = $this->importMessage($key, $cur, $index_file); + break; + case 'member' : + $cur = $this->importMember($key, $cur, $index_file); + break; + case 'module' : + // Check if the target module exists + if(!$target_module) return new Object(-1,'msg_invalid_request'); + $cur = $this->importModule($key, $cur, $index_file, $target_module); + break; + } + // Notify that all data completely extracted + $this->add('type',$type); + $this->add('total',$total); + $this->add('cur',$cur); + $this->add('key', $key); + $this->add('target_module', $target_module); + // When completing, success message appears and remove the cache files + if($total <= $cur) + { + $this->setMessage( sprintf(Context::getLang('msg_import_finished'), $cur, $total) ); + FileHandler::removeDir('./files/cache/importer/'.$key); + } + else $this->setMessage( sprintf(Context::getLang('msg_importing'), $total, $cur) ); + } - if(substr($buff,-7)=='') { - fwrite($f, base64_decode(substr($buff, 6, -7))); - $buff = ''; - } - } - fclose($f); - return $temp_filename; - } + /** + * Import member information + * @param int $key + * @param int $cur + * @param string $index_file + * @return int + */ + function importMember($key, $cur, $index_file) + { + if(!$cur) $cur = 0; + // Create the xmlParser object + $oXmlParser = new XmlParser(); + // Create objects for importing member information + $this->oMemberController = &getController('member'); + $this->oMemberModel = &getModel('member'); + // Get a default member group + $default_group = $this->oMemberModel->getDefaultGroup(); + $default_group_srl = $default_group->group_srl; + // Get information of the Webmaster + $oModuleModel = &getModel('module'); + $member_config = $oModuleModel->getModuleConfig('member'); + // Open an index file + $f = fopen($index_file,"r"); + // Pass if already read + for($i=0;$i<$cur;$i++) fgets($f, 1024); + // Read by each line until the condition meets + for($idx=$cur;$idx<$cur+$this->unit_count;$idx++) + { + if(feof($f)) break; + // Find a given location + $target_file = trim(fgets($f, 1024)); + // Load and parse the file + $xmlObj = $oXmlParser->loadXmlFile($target_file); + FileHandler::removeFile($target_file); + if(!$xmlObj) continue; + // List Objects + $obj = null; + $obj->user_id = base64_decode($xmlObj->member->user_id->body); + $obj->password = base64_decode($xmlObj->member->password->body); + $obj->user_name = base64_decode($xmlObj->member->user_name->body); + $obj->nick_name = base64_decode($xmlObj->member->nick_name->body); + if(!$obj->user_name) $obj->user_name = $obj->nick_name; + $obj->email = base64_decode($xmlObj->member->email->body); + $obj->homepage = base64_decode($xmlObj->member->homepage->body); + $obj->blog = base64_decode($xmlObj->member->blog->body); + $obj->birthday = substr(base64_decode($xmlObj->member->birthday->body),0,8); + $obj->allow_mailing = base64_decode($xmlObj->member->allow_mailing->body); + $obj->point = base64_decode($xmlObj->member->point->body); + $obj->image_nickname = base64_decode($xmlObj->member->image_nickname->buff->body); + $obj->image_mark = base64_decode($xmlObj->member->image_mark->buff->body); + $obj->profile_image = base64_decode($xmlObj->member->profile_image->buff->body); + $obj->signature = base64_decode($xmlObj->member->signature->body); + $obj->regdate = base64_decode($xmlObj->member->regdate->body); + $obj->last_login = base64_decode($xmlObj->member->last_login->body); + + if($xmlObj->member->extra_vars) + { + foreach($xmlObj->member->extra_vars as $key => $val) + { + if(in_array($key, array('node_name','attrs','body'))) continue; + $obj->extra_vars->{$key} = base64_decode($val->body); + } + } + // Create url for homepage and blog + if($obj->homepage && !preg_match("/^http:\/\//i",$obj->homepage)) $obj->homepage = 'http://'.$obj->homepage; + if($obj->blog && !preg_match("/^http:\/\//i",$obj->blog)) $obj->blog = 'http://'.$obj->blog; + // email address column + $obj->email_address = $obj->email; + list($obj->email_id, $obj->email_host) = explode('@', $obj->email); + // Set the mailing option + if($obj->allow_mailing!='Y') $obj->allow_mailing = 'N'; + // Set the message option + $obj->allow_message = 'Y'; + if(!in_array($obj->allow_message, array('Y','N','F'))) $obj->allow_message= 'Y'; + // Get member-join date if the last login time is not found + if(!$obj->last_login) $obj->last_login = $obj->regdate; + // Get a member_srl + $obj->member_srl = getNextSequence(); + $obj->list_order = -1 * $obj->member_srl; + // List extra vars + $extra_vars = $obj->extra_vars; + unset($obj->extra_vars); + $obj->extra_vars = serialize($extra_vars); + // Check if the same nickname is existing + $nick_args = null; + $nick_args->nick_name = $obj->nick_name; + $nick_output = executeQuery('member.getMemberSrl', $nick_args); + if(!$nick_output->toBool()) $obj->nick_name .= '_'.$obj->member_srl; + // Add a member + $output = executeQuery('member.insertMember', $obj); + + if($output->toBool() && !($obj->password)) + { + // Send a mail telling the user to reset his password. + $oMail = new Mail(); + $oMail->setTitle("Password update for your " . getFullSiteUrl() . " account"); + $webmaster_name = $member_config->webmaster_name?$member_config->webmaster_name:'Webmaster'; + $oMail->setContent("Dear $obj->user_name,

+ We recently migrated our phpBB forum to XpressEngine. Since you password was encrypted we could not migrate it too, so please reset it by following this link: + " . getFullSiteUrl() . "?act=dispMemberFindAccount. You need to enter you email address and hit the 'Find account' button. You will then receive an email with a new, generated password that you can change after login.

+ + Thank you for your understanding,
+ {$webmaster_name}" + ); + $oMail->setSender($webmaster_name, $member_config->webmaster_email); + $oMail->setReceiptor( $obj->user_name, $obj->email); + $oMail->send(); + } + + // add group join/image name-mark-signiture and so on if a new member successfully added + if($output->toBool()) + { + // Join to the default group + $obj->group_srl = $default_group_srl; + executeQuery('member.addMemberToGroup',$obj); + // Image name + if($obj->image_nickname) + { + $target_path = sprintf('files/member_extra_info/image_name/%s/', getNumberingPath($obj->member_srl)); + $target_filename = sprintf('%s%d.gif', $target_path, $obj->member_srl); + FileHandler::writeFile($target_filename, $obj->image_nickname); + } + // Image mark + if($obj->image_mark && file_exists($obj->image_mark)) + { + $target_path = sprintf('files/member_extra_info/image_mark/%s/', getNumberingPath($obj->member_srl)); + $target_filename = sprintf('%s%d.gif', $target_path, $obj->member_srl); + FileHandler::writeFile($target_filename, $obj->image_mark); + } + // Profile image + if($obj->profile_image) + { + $target_path = sprintf('files/member_extra_info/profile_image/%s/', getNumberingPath($obj->member_srl)); + $target_filename = sprintf('%s%d.gif', $target_path, $obj->member_srl); + FileHandler::writeFile($target_filename, $obj->profile_image); + } + // Signiture + if($obj->signature) + { + $signature = removeHackTag($obj->signature); + $signature_buff = sprintf('%s', $signature); + + $target_path = sprintf('files/member_extra_info/signature/%s/', getNumberingPath($obj->member_srl)); + if(!is_dir($target_path)) FileHandler::makeDir($target_path); + $target_filename = sprintf('%s%d.signature.php', $target_path, $obj->member_srl); + + FileHandler::writeFile($target_filename, $signature_buff); + } + } + } + + fclose($f); + + return $idx-1; + } + + /** + * Import message information parsed from a given xml file + * @param int $key + * @param int $cur + * @param string $index_file + * @return int + */ + function importMessage($key, $cur, $index_file) + { + if(!$cur) $cur = 0; + // Create the xmlParser object + $oXmlParser = new XmlParser(); + // Open an index file + $f = fopen($index_file,"r"); + // Pass if already read + for($i=0;$i<$cur;$i++) fgets($f, 1024); + // Read each line until the condition meets + for($idx=$cur;$idx<$cur+$this->unit_count;$idx++) + { + if(feof($f)) break; + // Find a location + $target_file = trim(fgets($f, 1024)); + // Load and parse the file + $xmlObj = $oXmlParser->loadXmlFile($target_file); + FileHandler::removeFile($target_file); + if(!$xmlObj) continue; + // List objects + $obj = null; + $obj->receiver = base64_decode($xmlObj->message->receiver->body); + $obj->sender = base64_decode($xmlObj->message->sender->body); + $obj->title = base64_decode($xmlObj->message->title->body); + $obj->content = base64_decode($xmlObj->message->content->body); + $obj->readed = base64_decode($xmlObj->message->readed->body)=='Y'?'Y':'N'; + $obj->regdate = base64_decode($xmlObj->message->regdate->body); + $obj->readed_date = base64_decode($xmlObj->message->readed_date->body); + // Get member_srl of sender/recipient (If not exists, pass) + if(!$obj->sender) continue; + $sender_args->user_id = $obj->sender; + $sender_output = executeQuery('member.getMemberInfo',$sender_args); + $sender_srl = $sender_output->data->member_srl; + if(!$sender_srl) + { + unset($sender_args); + $sender_args->email_address = $obj->sender; + $sender_output = executeQuery('member.getMemberInfoByEmailAddress',$sender_args); + $sender_srl = $sender_output->data->member_srl; + } + if(!$sender_srl) continue; + + $receiver_args->user_id = $obj->receiver; + if(!$obj->receiver) continue; + $receiver_output = executeQuery('member.getMemberInfo',$receiver_args); + $receiver_srl = $receiver_output->data->member_srl; + if(!$receiver_srl) + { + unset($receiver_args); + $receiver_args->email_address = $obj->receiver; + $receiver_output = executeQuery('member.getMemberInfoByEmailAddress',$receiver_args); + $receiver_srl = $receiver_output->data->member_srl; + } + if(!$receiver_srl) continue; + // Message to save into sender's message box + $sender_args->sender_srl = $sender_srl; + $sender_args->receiver_srl = $receiver_srl; + $sender_args->message_type = 'S'; + $sender_args->title = $obj->title; + $sender_args->content = $obj->content; + $sender_args->readed = $obj->readed; + $sender_args->regdate = $obj->regdate; + $sender_args->readed_date = $obj->readed_date; + $sender_args->related_srl = getNextSequence(); + $sender_args->message_srl = getNextSequence(); + $sender_args->list_order = $sender_args->message_srl * -1; + + $output = executeQuery('communication.sendMessage', $sender_args); + if($output->toBool()) + { + // Message to save into recipient's massage box + $receiver_args->message_srl = $sender_args->related_srl; + $receiver_args->list_order = $sender_args->related_srl*-1; + $receiver_args->sender_srl = $sender_srl; + if(!$receiver_args->sender_srl) $receiver_args->sender_srl = $receiver_srl; + $receiver_args->receiver_srl = $receiver_srl; + $receiver_args->message_type = 'R'; + $receiver_args->title = $obj->title; + $receiver_args->content = $obj->content; + $receiver_args->readed = $obj->readed; + $receiver_args->regdate = $obj->regdate; + $receiver_args->readed_date = $obj->readed_date; + $output = executeQuery('communication.sendMessage', $receiver_args); + } + } + + fclose($f); + + return $idx-1; + } + + /** + * Import data in module.xml format + * @param int $key + * @param int $cur + * @param string $index_file + * @param int $module_srl + * @return int + */ + function importModule($key, $cur, $index_file, $module_srl) + { + // Pre-create the objects needed + $this->oXmlParser = new XmlParser(); + // Get category information of the target module + $oDocumentController = &getController('document'); + $oDocumentModel = &getModel('document'); + $category_list = $category_titles = array(); + $category_list = $oDocumentModel->getCategoryList($module_srl); + if(count($category_list)) foreach($category_list as $key => $val) $category_titles[$val->title] = $val->category_srl; + // Extract category information + $category_file = preg_replace('/index$/i', 'category.xml', $index_file); + if(file_exists($category_file)) + { + $buff = FileHandler::readFile($category_file); + + // Create the xmlParser object + $xmlDoc = $this->oXmlParser->loadXmlFile($category_file); + + $categories = $xmlDoc->items->category; + if($categories) + { + if(!is_array($categories)) $categories = array($categories); + $match_sequence = array(); + foreach($categories as $k => $v) + { + $category = trim(base64_decode($v->body)); + if(!$category || $category_titles[$category]) continue; + + $sequence = $v->attrs->sequence; + $parent = $v->attrs->parent; + + $obj = null; + $obj->title = $category; + $obj->module_srl = $module_srl; + if($parent) $obj->parent_srl = $match_sequence[$parent]; + + $output = $oDocumentController->insertCategory($obj); + if($output->toBool()) $match_sequence[$sequence] = $output->get('category_srl'); + } + $oDocumentController = &getController('document'); + $oDocumentController->makeCategoryFile($module_srl); + } + FileHandler::removeFile($category_file); + } + + $category_list = $category_titles = array(); + $category_list = $oDocumentModel->getCategoryList($module_srl); + if(count($category_list)) foreach($category_list as $key => $val) $category_titles[$val->title] = $val->category_srl; + + $ek_args->module_srl = $module_srl; + $output = executeQueryArray('document.getDocumentExtraKeys', $ek_args); + if($output->data) + { + foreach($output->data as $key => $val) $extra_keys[$val->eid] = true; + } + + if(!$cur) $cur = 0; + // Open an index file + $f = fopen($index_file,"r"); + // Pass if already read + for($i=0;$i<$cur;$i++) fgets($f, 1024); + // Read each line until the condition meets + for($idx=$cur;$idx<$cur+$this->unit_count;$idx++) + { + if(feof($f)) break; + // Find a location + $target_file = trim(fgets($f, 1024)); + + if(!file_exists($target_file)) continue; + // Importing data from now on + $fp = fopen($target_file,"r"); + if(!$fp) continue; + + $obj = null; + $obj->module_srl = $module_srl; + $obj->document_srl = getNextSequence(); + + $files = array(); + $extra_vars = array(); + + $started = false; + $buff = null; + // Start from the body data + while(!feof($fp)) + { + $str = fgets($fp, 1024); + // Prepare an item + if(trim($str) == '') + { + $started = true; + // Trackback inserted + } + else if(substr($str,0,11) == 'trackback_count = $this->importTrackbacks($fp, $module_srl, $obj->document_srl); + continue; + // Comments inserted + } + else if(substr($str,0,9) == 'comment_count = $this->importComments($fp, $module_srl, $obj->document_srl); + continue; + // Attachment inserted + } + else if(substr($str,0,9) == 'uploaded_count = $this->importAttaches($fp, $module_srl, $obj->document_srl, $files); + continue; + // When starting extra variabls + } + elseif(trim($str) == '') + { + $extra_vars = $this->importExtraVars($fp); + continue; + } + + if($started) $buff .= $str; + } + + $xmlDoc = $this->oXmlParser->parse($buff); + + $category = base64_decode($xmlDoc->post->category->body); + if($category_titles[$category]) $obj->category_srl = $category_titles[$category]; + + $obj->member_srl = 0; + + $obj->is_notice = base64_decode($xmlDoc->post->is_notice->body)=='Y'?'Y':'N'; + $obj->status = base64_decode($xmlDoc->post->is_secret->body)=='Y'?$oDocumentModel->getConfigStatus('secret'):$oDocumentModel->getConfigStatus('public'); + $obj->title = base64_decode($xmlDoc->post->title->body); + $obj->content = base64_decode($xmlDoc->post->content->body); + $obj->readed_count = base64_decode($xmlDoc->post->readed_count->body); + $obj->voted_count = base64_decode($xmlDoc->post->voted_count->body); + $obj->blamed_count = base64_decode($xmlDoc->post->blamed_count->body); + $obj->password = base64_decode($xmlDoc->post->password->body); + $obj->user_name = base64_decode($xmlDoc->post->user_name->body); + $obj->nick_name = base64_decode($xmlDoc->post->nick_name->body); + if(!$obj->user_name) $obj->user_name = $obj->nick_name; + $obj->user_id = base64_decode($xmlDoc->post->user_id->body); + $obj->email_address = base64_decode($xmlDoc->post->email->body); + $obj->homepage = base64_decode($xmlDoc->post->homepage->body); + if($obj->homepage && !preg_match('/^http:\/\//i',$obj->homepage)) $obj->homepage = 'http://'.$obj->homepage; + $obj->tags = base64_decode($xmlDoc->post->tags->body); + $obj->regdate = base64_decode($xmlDoc->post->regdate->body); + $obj->last_update = base64_decode($xmlDoc->post->update->body); + $obj->last_updater = base64_decode($xmlDoc->post->last_updater->body); + if(!$obj->last_update) $obj->last_update = $obj->regdate; + $obj->ipaddress = base64_decode($xmlDoc->post->ipaddress->body); + $obj->list_order = $obj->update_order = $obj->document_srl*-1; + $obj->commentStatus = base64_decode($xmlDoc->post->allow_comment->body)!='N'?'ALLOW':'DENY'; + $obj->allow_trackback = base64_decode($xmlDoc->post->allow_trackback->body)!='N'?'Y':'N'; + $obj->notify_message = base64_decode($xmlDoc->post->is_notice->body); + // Change content information (attachment) + if(count($files)) + { + foreach($files as $key => $val) + { + $obj->content = preg_replace('/(src|href)\=(["\']?)'.preg_quote($key).'(["\']?)/i','$1="'.$val.'"',$obj->content); + $obj->content = preg_replace('/(["\']?).\/files\/(.+)\/'.preg_quote($key).'([^"\']+)(["\']?)/i','"'.$val.'"',$obj->content); + $obj->content = preg_replace('/(["\']?)files\/(.+)\/'.preg_quote($key).'([^"\']+)(["\']?)/i','"'.$val.'"',$obj->content); + } + } + + $output = executeQuery('document.insertDocument', $obj); + + if($output->toBool() && $obj->tags) + { + $tag_list = explode(',',$obj->tags); + $tag_count = count($tag_list); + for($i=0;$i<$tag_count;$i++) + { + $args = null; + $args->tag_srl = getNextSequence(); + $args->module_srl = $module_srl; + $args->document_srl = $obj->document_srl; + $args->tag = trim($tag_list[$i]); + $args->regdate = $obj->regdate; + if(!$args->tag) continue; + $output = executeQuery('tag.insertTag', $args); + } + + } + // Add extra variables + if(count($extra_vars)) + { + foreach($extra_vars as $key => $val) + { + if(!$val->value) continue; + unset($e_args); + $e_args->module_srl = $module_srl; + $e_args->document_srl = $obj->document_srl; + $e_args->var_idx = $val->var_idx; + $e_args->value = $val->value; + $e_args->lang_code = $val->lang_code; + $e_args->eid = $val->eid; + // Create a key for extra vars if not exists (except vars for title and content) + if(!preg_match('/^(title|content)_(.+)$/i',$e_args->eid) && !$extra_keys[$e_args->eid]) + { + unset($ek_args); + $ek_args->module_srl = $module_srl; + $ek_args->var_idx = $val->var_idx; + $ek_args->var_name = $val->eid; + $ek_args->var_type = 'text'; + $ek_args->var_is_required = 'N'; + $ek_args->var_default = ''; + $ek_args->eid = $val->eid; + $output = executeQuery('document.insertDocumentExtraKey', $ek_args); + $extra_keys[$ek_args->eid] = true; + } + + $output = executeQuery('document.insertDocumentExtraVar', $e_args); + } + } + + fclose($fp); + FileHandler::removeFile($target_file); + } + + fclose($f); + // Sync category counts + if(count($category_list)) foreach($category_list as $key => $val) $oDocumentController->updateCategoryCount($module_srl, $val->category_srl); + + return $idx-1; + } + + /** + * Trackbacks + * @param resource $fp + * @param int $module_srl + * @param int $document_srl + * @return int + */ + function importTrackbacks($fp, $module_srl, $document_srl) + { + $started = false; + $buff = null; + $cnt = 0; + + while(!feof($fp)) + { + $str = fgets($fp, 1024); + // If is, break + if(trim($str) == '') break; + // If , start importing + if(trim($str) == '') $started = true; + + if($started) $buff .= $str; + // If , insert to the DB + if(trim($str) == '') + { + $xmlDoc = $this->oXmlParser->parse($buff); + + $obj = null; + $obj->trackback_srl = getNextSequence(); + $obj->module_srl = $module_srl; + $obj->document_srl = $document_srl; + $obj->url = base64_decode($xmlDoc->trackback->url->body); + $obj->title = base64_decode($xmlDoc->trackback->title->body); + $obj->blog_name = base64_decode($xmlDoc->trackback->blog_name->body); + $obj->excerpt = base64_decode($xmlDoc->trackback->excerpt->body); + $obj->regdate = base64_decode($xmlDoc->trackback->regdate->body); + $obj->ipaddress = base64_decode($xmlDoc->trackback->ipaddress->body); + $obj->list_order = -1*$obj->trackback_srl; + $output = executeQuery('trackback.insertTrackback', $obj); + if($output->toBool()) $cnt++; + + $buff = null; + $started = false; + } + } + return $cnt; + } + + /** + * Comments + * @param resource $fp + * @param int $module_srl + * @param int $document_srl + * @return int + */ + function importComments($fp, $module_srl, $document_srl) + { + $started = false; + $buff = null; + $cnt = 0; + + $sequences = array(); + + while(!feof($fp)) + { + $str = fgets($fp, 1024); + // If is, break + if(trim($str) == '') break; + // If is, start importing + if(trim($str) == '') + { + $started = true; + $obj = null; + $obj->comment_srl = getNextSequence(); + $files = array(); + } + // If uploaded_count = $this->importAttaches($fp, $module_srl, $obj->comment_srl, $files); + continue; + } + + if($started) $buff .= $str; + // If is, insert to the DB + if(trim($str) == '') + { + $xmlDoc = $this->oXmlParser->parse($buff); + + $sequence = base64_decode($xmlDoc->comment->sequence->body); + $sequences[$sequence] = $obj->comment_srl; + $parent = base64_decode($xmlDoc->comment->parent->body); + + $obj->module_srl = $module_srl; + + if($parent) $obj->parent_srl = $sequences[$parent]; + else $obj->parent_srl = 0; + + $obj->document_srl = $document_srl; + $obj->is_secret = base64_decode($xmlDoc->comment->is_secret->body)=='Y'?'Y':'N'; + $obj->notify_message = base64_decode($xmlDoc->comment->notify_message->body)=='Y'?'Y':'N'; + $obj->content = base64_decode($xmlDoc->comment->content->body); + $obj->voted_count = base64_decode($xmlDoc->comment->voted_count->body); + $obj->blamed_count = base64_decode($xmlDoc->comment->blamed_count->body); + $obj->password = base64_decode($xmlDoc->comment->password->body); + $obj->user_name =base64_decode($xmlDoc->comment->user_name->body); + $obj->nick_name = base64_decode($xmlDoc->comment->nick_name->body); + if(!$obj->user_name) $obj->user_name = $obj->nick_name; + $obj->user_id = base64_decode($xmlDoc->comment->user_id->body); + $obj->member_srl = 0; + $obj->email_address = base64_decode($xmlDoc->comment->email->body); + $obj->homepage = base64_decode($xmlDoc->comment->homepage->body); + $obj->regdate = base64_decode($xmlDoc->comment->regdate->body); + $obj->last_update = base64_decode($xmlDoc->comment->update->body); + if(!$obj->last_update) $obj->last_update = $obj->regdate; + $obj->ipaddress = base64_decode($xmlDoc->comment->ipaddress->body); + $obj->list_order = $obj->comment_srl*-1; + // Change content information (attachment) + if(count($files)) + { + foreach($files as $key => $val) + { + $obj->content = preg_replace('/(src|href)\=(["\']?)'.preg_quote($key).'(["\']?)/i','$1="'.$val.'"',$obj->content); + } + } + // Comment list first + $list_args = null; + $list_args->comment_srl = $obj->comment_srl; + $list_args->document_srl = $obj->document_srl; + $list_args->module_srl = $obj->module_srl; + $list_args->regdate = $obj->regdate; + // Set data directly if parent comment doesn't exist + if(!$obj->parent_srl) + { + $list_args->head = $list_args->arrange = $obj->comment_srl; + $list_args->depth = 0; + // Get parent_srl if parent comment exists + } + else + { + // Get parent comment infomation + $parent_args->comment_srl = $obj->parent_srl; + $parent_output = executeQuery('comment.getCommentListItem', $parent_args); + // Return if parent comment doesn't exist + if(!$parent_output->toBool() || !$parent_output->data) continue; + $parent = $parent_output->data; + + $list_args->head = $parent->head; + $list_args->depth = $parent->depth+1; + if($list_args->depth<2) $list_args->arrange = $obj->comment_srl; + else + { + $list_args->arrange = $parent->arrange; + $output = executeQuery('comment.updateCommentListArrange', $list_args); + if(!$output->toBool()) return $output; + } + } + + $output = executeQuery('comment.insertCommentList', $list_args); + if($output->toBool()) + { + $output = executeQuery('comment.insertComment', $obj); + if($output->toBool()) $cnt++; + } + + $buff = null; + $started = false; + } + } + return $cnt; + } + + /** + * Import attachment + * @param resource $fp + * @param int $module_srl + * @param int $upload_target_srl + * @param array $files + * @return int + */ + function importAttaches($fp, $module_srl, $upload_target_srl, &$files) + { + $uploaded_count = 0; + + $started = false; + $buff = null; + + while(!feof($fp)) + { + $str = trim(fgets($fp, 1024)); + // If it ends with , break + if(trim($str) == '') break; + // If it starts with , collect attachments + if(trim($str) == '') + { + $file_obj = null; + $file_obj->file_srl = getNextSequence(); + $file_obj->upload_target_srl = $upload_target_srl; + $file_obj->module_srl = $module_srl; + + $started = true; + $buff = null; + // If it starts with , handle the attachement in xml file + } + else if(trim($str) == '') + { + $file_obj->file = $this->saveTemporaryFile($fp); + continue; + } + + if($started) $buff .= $str; + // If it ends with , handle attachements + if(trim($str) == '') + { + $xmlDoc = $this->oXmlParser->parse($buff.$str); + + $file_obj->source_filename = base64_decode($xmlDoc->attach->filename->body); + $file_obj->download_count = base64_decode($xmlDoc->attach->download_count->body); + + if(!$file_obj->file) + { + $url = base64_decode($xmlDoc->attach->url->body); + $path = base64_decode($xmlDoc->attach->path->body); + if($path && file_exists($path)) $file_obj->file = $path; + else + { + $file_obj->file = $this->getTmpFilename(); + FileHandler::getRemoteFile($url, $file_obj->file); + } + } + + if(file_exists($file_obj->file)) + { + // Set upload path by checking if the attachement is an image or other kind of file + if(preg_match("/\.(jpe?g|gif|png|wm[va]|mpe?g|avi|swf|flv|mp[1-4]|as[fx]|wav|midi?|moo?v|qt|r[am]{1,2}|m4v)$/i", $file_obj->source_filename)) + { + // Immediately remove the direct file if it has any kind of extensions for hacking + $file_obj->source_filename = preg_replace('/\.(php|phtm|html?|cgi|pl|exe|jsp|asp|inc)/i', '$0-x', $file_obj->source_filename); + $file_obj->source_filename = str_replace(array('<', '>'), array('%3C', '%3E'), $file_obj->source_filename); + + $path = sprintf("./files/attach/images/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3)); + + $ext = substr(strrchr($file_obj->source_filename,'.'),1); + $_filename = md5(crypt(rand(1000000, 900000), rand(0, 100))).'.'.$ext; + $filename = $path.$_filename; + + $idx = 1; + while(file_exists($filename)) + { + $filename = $path.preg_replace('/\.([a-z0-9]+)$/i','_'.$idx.'.$1', $_filename); + $idx++; + } + + $file_obj->direct_download = 'Y'; + } + else + { + $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); + $filename = $path.md5(crypt(rand(1000000,900000), rand(0,100))); + $file_obj->direct_download = 'N'; + } + // Create a directory + if(!FileHandler::makeDir($path)) continue; + + if(preg_match('/^\.\/files\/cache\/importer/i',$file_obj->file)) FileHandler::rename($file_obj->file, $filename); + else @copy($file_obj->file, $filename); + // Insert the file to the DB + unset($file_obj->file); + if(file_exists($filename)) + { + $file_obj->uploaded_filename = $filename; + $file_obj->file_size = filesize($filename); + $file_obj->comment = NULL; + $file_obj->member_srl = 0; + $file_obj->sid = md5(rand(rand(1111111,4444444),rand(4444445,9999999))); + $file_obj->isvalid = 'Y'; + $output = executeQuery('file.insertFile', $file_obj); + + if($output->toBool()) + { + $uploaded_count++; + $tmp_obj = null; + $tmp_obj->source_filename = $file_obj->source_filename; + if($file_obj->direct_download == 'Y') $files[$file_obj->source_filename] = $file_obj->uploaded_filename; + else $files[$file_obj->source_filename] = getUrl('','module','file','act','procFileDownload','file_srl',$file_obj->file_srl,'sid',$file_obj->sid); + } + } + } + } + } + return $uploaded_count; + } + + /** + * Return a filename to temporarily use + * @return string + */ + function getTmpFilename() + { + $path = "./files/cache/importer"; + if(!is_dir($path)) FileHandler::makeDir($path); + $filename = sprintf("%s/%d", $path, rand(11111111,99999999)); + if(file_exists($filename)) $filename .= rand(111,999); + return $filename; + } + + /** + * Read buff until key value comes out from a specific file point + * @param resource $fp + * @return string + */ + function saveTemporaryFile($fp) + { + $temp_filename = $this->getTmpFilename(); + $f = fopen($temp_filename, "w"); + + $buff = ''; + while(!feof($fp)) + { + $str = trim(fgets($fp, 1024)); + if(trim($str) == '') break; + + $buff .= $str; + + if(substr($buff,-7)=='') + { + fwrite($f, base64_decode(substr($buff, 6, -7))); + $buff = ''; + } + } + fclose($f); + return $temp_filename; + } - /** - * Set extra variables - * @param resource $fp - * @return array - */ - function importExtraVars($fp) { - $buff = null; - while(!feof($fp)) { - $buff .= $str = trim(fgets($fp, 1024)); - if(trim($str) == '') break; - } - if(!$buff) return array(); + /** + * Set extra variables + * @param resource $fp + * @return array + */ + function importExtraVars($fp) + { + $buff = null; + while(!feof($fp)) + { + $buff .= $str = trim(fgets($fp, 1024)); + if(trim($str) == '
') break; + } + if(!$buff) return array(); - $buff = ''.$buff; - $oXmlParser = new XmlParser(); - $xmlDoc = $this->oXmlParser->parse($buff); - if(!count($xmlDoc->extra_vars->key)) return array(); + $buff = ''.$buff; + $oXmlParser = new XmlParser(); + $xmlDoc = $this->oXmlParser->parse($buff); + if(!count($xmlDoc->extra_vars->key)) return array(); - $index = 1; - foreach($xmlDoc->extra_vars->key as $k => $v) { - unset($vobj); - if($v->var_idx) { - $vobj->var_idx = base64_decode($v->var_idx->body); - $vobj->lang_code = base64_decode($v->lang_code->body); - $vobj->value = base64_decode($v->value->body); - $vobj->eid = base64_decode($v->eid->body); + $index = 1; + foreach($xmlDoc->extra_vars->key as $k => $v) + { + unset($vobj); + if($v->var_idx) + { + $vobj->var_idx = base64_decode($v->var_idx->body); + $vobj->lang_code = base64_decode($v->lang_code->body); + $vobj->value = base64_decode($v->value->body); + $vobj->eid = base64_decode($v->eid->body); - } else if($v->body) { - $vobj->var_idx = $index; - $vobj->lang_code = Context::getLangType(); - $vobj->value = base64_decode($v->body); - $vobj->eid = 'extra_vars'.$index; - } - $extra_vars["extra_vars".$index] = $vobj; - $index++; - } - return $extra_vars; - } - - } -?> + } + else if($v->body) + { + $vobj->var_idx = $index; + $vobj->lang_code = Context::getLangType(); + $vobj->value = base64_decode($v->body); + $vobj->eid = 'extra_vars'.$index; + } + $extra_vars["extra_vars".$index] = $vobj; + $index++; + } + return $extra_vars; + } +} +/* End of file importer.admin.controller.php */ +/* Location: ./modules/importer/importer.admin.controller.php */ diff --git a/modules/importer/importer.admin.view.php b/modules/importer/importer.admin.view.php index cb149660a..0067a580b 100644 --- a/modules/importer/importer.admin.view.php +++ b/modules/importer/importer.admin.view.php @@ -1,71 +1,77 @@ setTemplatePath($this->module_path.'tpl'); + /** + * Display a form to upload the xml file + * @return void + */ + function dispImporterAdminContent() + { + $this->setTemplatePath($this->module_path.'tpl'); - $source_type = Context::get('source_type'); - switch($source_type) { - case 'member' : - $template_filename = "member"; - break; - case 'ttxml' : - $oModuleModel = &getModel('module'); - //$mid_list = $oModuleModel->getMidList(); //perhaps mid_list variables not use - //Context::set('mid_list', $mid_list); - - $template_filename = "ttxml"; - break; - case 'module' : - $oModuleModel = &getModel('module'); - //$mid_list = $oModuleModel->getMidList(); //perhaps mid_list variables not use - //Context::set('mid_list', $mid_list); - - $template_filename = "module"; - break; - case 'message' : - $template_filename = "message"; - break; - case 'sync' : - $template_filename = "sync"; - break; - default : - $template_filename = "index"; - break; - } + $source_type = Context::get('source_type'); + switch($source_type) + { + case 'member' : + $template_filename = "member"; + break; + case 'ttxml' : + $oModuleModel = &getModel('module'); + //$mid_list = $oModuleModel->getMidList(); //perhaps mid_list variables not use + //Context::set('mid_list', $mid_list); - $this->setTemplateFile($template_filename); - } + $template_filename = "ttxml"; + break; + case 'module' : + $oModuleModel = &getModel('module'); + //$mid_list = $oModuleModel->getMidList(); //perhaps mid_list variables not use + //Context::set('mid_list', $mid_list); - /** - * Display a form to upload the xml file - * @return void - */ - function dispImporterAdminImportForm() { - $oDocumentModel = &getModel('document'); //for document lang use in this page + $template_filename = "module"; + break; + case 'message' : + $template_filename = "message"; + break; + case 'sync' : + $template_filename = "sync"; + break; + default : + $template_filename = "index"; + break; + } - $this->setTemplatePath($this->module_path.'tpl'); - $this->setTemplateFile('index'); - } - - } -?> + $this->setTemplateFile($template_filename); + } + + /** + * Display a form to upload the xml file + * @return void + */ + function dispImporterAdminImportForm() + { + $oDocumentModel = &getModel('document'); //for document lang use in this page + + $this->setTemplatePath($this->module_path.'tpl'); + $this->setTemplateFile('index'); + } + +} +/* End of file importer.admin.view.php */ +/* Location: ./modules/importer/importer.admin.view.php */ diff --git a/modules/importer/importer.class.php b/modules/importer/importer.class.php index dca74b282..8bd420e54 100644 --- a/modules/importer/importer.class.php +++ b/modules/importer/importer.class.php @@ -1,42 +1,48 @@ + /** + * Re-generate the cache file + * @return void + */ + function recompileCache() + { + } +} +/* End of file importer.class.php */ +/* Location: ./modules/importer/importer.class.php */ diff --git a/modules/importer/ttimport.class.php b/modules/importer/ttimport.class.php index 53efff1c7..008b7c692 100644 --- a/modules/importer/ttimport.class.php +++ b/modules/importer/ttimport.class.php @@ -1,655 +1,732 @@ oXmlParser = new XmlParser(); + // Get category information of the target module + $oDocumentController = &getController('document'); + $oDocumentModel = &getModel('document'); + $category_list = $category_titles = array(); + $category_list = $oDocumentModel->getCategoryList($module_srl); + if(count($category_list)) foreach($category_list as $key => $val) $category_titles[$val->title] = $val->category_srl; + // First handle categorty information + $category_file = preg_replace('/index$/i', 'category.xml', $index_file); + if(file_exists($category_file)) + { + // Create the xmlParser object + $xmlDoc = $this->oXmlParser->loadXmlFile($category_file); + // List category information + if($xmlDoc->categories->category) + { + $categories = array(); + $idx = 0; + $this->arrangeCategory($xmlDoc->categories, $categories, $idx, 0); - /** - * Import data in module.xml format - * @param int $key - * @param int $cur - * @param string $index_file - * @param int $unit_count - * @param int $module_srl - * @param int $guestbook_module_srl - * @param string $user_id - * @param string $module_name - * @return int - */ - function importModule($key, $cur, $index_file, $unit_count, $module_srl, $guestbook_module_srl, $user_id, $module_name=null) { - // Pre-create the objects needed - $this->oXmlParser = new XmlParser(); - // Get category information of the target module - $oDocumentController = &getController('document'); - $oDocumentModel = &getModel('document'); - $category_list = $category_titles = array(); - $category_list = $oDocumentModel->getCategoryList($module_srl); - if(count($category_list)) foreach($category_list as $key => $val) $category_titles[$val->title] = $val->category_srl; - // First handle categorty information - $category_file = preg_replace('/index$/i', 'category.xml', $index_file); - if(file_exists($category_file)) { - // Create the xmlParser object - $xmlDoc = $this->oXmlParser->loadXmlFile($category_file); - // List category information - if($xmlDoc->categories->category) { - $categories = array(); - $idx = 0; - $this->arrangeCategory($xmlDoc->categories, $categories, $idx, 0); + $match_sequence = array(); + foreach($categories as $k => $v) + { + $category = $v->name; + if(!$category || $category_titles[$category]) continue; - $match_sequence = array(); - foreach($categories as $k => $v) { - $category = $v->name; - if(!$category || $category_titles[$category]) continue; + $obj = null; + $obj->title = $category; + $obj->module_srl = $module_srl; + if($v->parent) $obj->parent_srl = $match_sequence[$v->parent]; + $output = $oDocumentController->insertCategory($obj); - $obj = null; - $obj->title = $category; - $obj->module_srl = $module_srl; - if($v->parent) $obj->parent_srl = $match_sequence[$v->parent]; - $output = $oDocumentController->insertCategory($obj); + if($output->toBool()) $match_sequence[$v->sequence] = $category_titles[$category] = $output->get('category_srl'); + } + $oDocumentController->makeCategoryFile($module_srl); + } + FileHandler::removeFile($category_file); + } + $category_list = $category_titles = array(); + $category_list = $oDocumentModel->getCategoryList($module_srl); + if(count($category_list)) foreach($category_list as $key => $val) $category_titles[$val->title] = $val->category_srl; + // Get administrator information + $oMemberModel = &getModel('member'); + $member_info = $oMemberModel->getMemberInfoByUserID($user_id); + $author_xml_id = 0; - if($output->toBool()) $match_sequence[$v->sequence] = $category_titles[$category] = $output->get('category_srl'); - } - $oDocumentController->makeCategoryFile($module_srl); - } - FileHandler::removeFile($category_file); - } - $category_list = $category_titles = array(); - $category_list = $oDocumentModel->getCategoryList($module_srl); - if(count($category_list)) foreach($category_list as $key => $val) $category_titles[$val->title] = $val->category_srl; - // Get administrator information - $oMemberModel = &getModel('member'); - $member_info = $oMemberModel->getMemberInfoByUserID($user_id); - $author_xml_id = 0; - - if(!$cur) $cur = 0; - // Open an index file - $f = fopen($index_file,"r"); - // Pass if already read - for($i=0;$i<$cur;$i++) fgets($f, 1024); - // Read each line until the codition meets - for($idx=$cur;$idx<$cur+$unit_count;$idx++) { - if(feof($f)) break; - // Find a location - $target_file = trim(fgets($f, 1024)); + if(!$cur) $cur = 0; + // Open an index file + $f = fopen($index_file,"r"); + // Pass if already read + for($i=0;$i<$cur;$i++) fgets($f, 1024); + // Read each line until the codition meets + for($idx=$cur;$idx<$cur+$unit_count;$idx++) + { + if(feof($f)) break; + // Find a location + $target_file = trim(fgets($f, 1024)); - if(!file_exists($target_file)) continue; - // Start importing data - $fp = fopen($target_file,"r"); - if(!$fp) continue; + if(!file_exists($target_file)) continue; + // Start importing data + $fp = fopen($target_file,"r"); + if(!$fp) continue; - $obj = null; - $obj->module_srl = $module_srl; - $obj->document_srl = getNextSequence(); - $obj->uploaded_count = 0; + $obj = null; + $obj->module_srl = $module_srl; + $obj->document_srl = getNextSequence(); + $obj->uploaded_count = 0; - $files = array(); + $files = array(); - $started = false; - $buff = null; - // Start importing from the body data - while(!feof($fp)) { - $str = fgets($fp, 1024); - // Prepare an item - if(substr($str,0,5) == 'importAttaches($fp, $module_srl, $obj->document_srl, $files, $str)) $obj->uploaded_count++; - continue; - } + $started = false; + $buff = null; + // Start importing from the body data + while(!feof($fp)) + { + $str = fgets($fp, 1024); + // Prepare an item + if(substr($str,0,5) == 'importAttaches($fp, $module_srl, $obj->document_srl, $files, $str)) $obj->uploaded_count++; + continue; + } - if($started) $buff .= $str; - } + if($started) $buff .= $str; + } - $xmlDoc = $this->oXmlParser->parse(''.$buff); - - $author_xml_id = $xmlDoc->post->author->body; + $xmlDoc = $this->oXmlParser->parse(''.$buff); + $author_xml_id = $xmlDoc->post->author->body; - if($xmlDoc->post->category->body) { - $tmp_arr = explode('/',$xmlDoc->post->category->body); - $category = trim($tmp_arr[count($tmp_arr)-1]); - if($category_titles[$category]) $obj->category_srl = $category_titles[$category]; - } + if($xmlDoc->post->category->body) + { + $tmp_arr = explode('/',$xmlDoc->post->category->body); + $category = trim($tmp_arr[count($tmp_arr)-1]); + if($category_titles[$category]) $obj->category_srl = $category_titles[$category]; + } - $obj->is_notice = 'N'; - $obj->status = in_array($xmlDoc->post->visibility->body, array('public','syndicated'))?$oDocumentModel->getConfigStatus('public'):$oDocumentModel->getConfigStatus('secret'); - $obj->title = $xmlDoc->post->title->body; - $obj->content = $xmlDoc->post->content->body; - $obj->password = md5($xmlDoc->post->password->body); - $obj->commentStatus = $xmlDoc->post->acceptcomment->body=='1'?'ALLOW':'DENY'; - $obj->allow_trackback = $xmlDoc->post->accepttrackback->body=='1'?'Y':'N'; - //$obj->allow_comment = $xmlDoc->post->acceptComment->body=='1'?'Y':'N'; - //$obj->allow_trackback = $xmlDoc->post->acceptTrackback->body=='1'?'Y':'N'; - $obj->regdate = date("YmdHis",$xmlDoc->post->published->body); - $obj->last_update = date("YmdHis", $xmlDoc->post->modified->body); - if(!$obj->last_update) $obj->last_update = $obj->regdate; + $obj->is_notice = 'N'; + $obj->status = in_array($xmlDoc->post->visibility->body, array('public','syndicated'))?$oDocumentModel->getConfigStatus('public'):$oDocumentModel->getConfigStatus('secret'); + $obj->title = $xmlDoc->post->title->body; + $obj->content = $xmlDoc->post->content->body; + $obj->password = md5($xmlDoc->post->password->body); + $obj->commentStatus = $xmlDoc->post->acceptcomment->body=='1'?'ALLOW':'DENY'; + $obj->allow_trackback = $xmlDoc->post->accepttrackback->body=='1'?'Y':'N'; + //$obj->allow_comment = $xmlDoc->post->acceptComment->body=='1'?'Y':'N'; + //$obj->allow_trackback = $xmlDoc->post->acceptTrackback->body=='1'?'Y':'N'; + $obj->regdate = date("YmdHis",$xmlDoc->post->published->body); + $obj->last_update = date("YmdHis", $xmlDoc->post->modified->body); + if(!$obj->last_update) $obj->last_update = $obj->regdate; - $tag = null; - $tmp_tags = null; - $tag = $xmlDoc->post->tag; - if($tag) { - if(!is_array($tag)) $tag = array($tag); - foreach($tag as $key => $val) $tmp_tags[] = $val->body; - $obj->tags = implode(',',$tmp_tags); - } + $tag = null; + $tmp_tags = null; + $tag = $xmlDoc->post->tag; + if($tag) + { + if(!is_array($tag)) $tag = array($tag); + foreach($tag as $key => $val) $tmp_tags[] = $val->body; + $obj->tags = implode(',',$tmp_tags); + } - $obj->readed_count = 0; - $obj->voted_count = 0; - $obj->nick_name = $member_info->nick_name; - $obj->user_name = $member_info->user_name; - $obj->user_id = $member_info->user_id; - $obj->member_srl = $member_info->member_srl; - $obj->email_address = $member_info->email_address; - $obj->homepage = $member_info->homepage; - $obj->ipaddress = $_REMOTE['SERVER_ADDR']; - $obj->list_order = $obj->update_order = $obj->document_srl*-1; - $obj->notify_message = 'N'; - // Change content information (attachment) - $obj->content = str_replace('[##_ATTACH_PATH_##]/','',$obj->content); - if(count($files)) { - foreach($files as $key => $val) { - $obj->content = preg_replace('/(src|href)\=(["\']?)'.preg_quote($key).'(["\']?)/i','$1="'.$val->url.'"',$obj->content); - } - } + $obj->readed_count = 0; + $obj->voted_count = 0; + $obj->nick_name = $member_info->nick_name; + $obj->user_name = $member_info->user_name; + $obj->user_id = $member_info->user_id; + $obj->member_srl = $member_info->member_srl; + $obj->email_address = $member_info->email_address; + $obj->homepage = $member_info->homepage; + $obj->ipaddress = $_REMOTE['SERVER_ADDR']; + $obj->list_order = $obj->update_order = $obj->document_srl*-1; + $obj->notify_message = 'N'; + // Change content information (attachment) + $obj->content = str_replace('[##_ATTACH_PATH_##]/','',$obj->content); + if(count($files)) + { + foreach($files as $key => $val) { + $obj->content = preg_replace('/(src|href)\=(["\']?)'.preg_quote($key).'(["\']?)/i','$1="'.$val->url.'"',$obj->content); + } + } - $obj->content = preg_replace_callback('!\[##_Movie\|([^\|]*)\|(.*?)_##\]!is', array($this, '_replaceTTMovie'), $obj->content); + $obj->content = preg_replace_callback('!\[##_Movie\|([^\|]*)\|(.*?)_##\]!is', array($this, '_replaceTTMovie'), $obj->content); - if(count($files)) { - $this->files = $files; - $obj->content = preg_replace_callback('!\[##_([a-z0-9]+)\|([^\|]*)\|([^\|]*)\|(.*?)_##\]!is', array($this, '_replaceTTAttach'), $obj->content); - } - // Trackback inserted - $obj->trackback_count = 0; - if($xmlDoc->post->trackback) { - $trackbacks = $xmlDoc->post->trackback; - if(!is_array($trackbacks)) $trackbacks = array($trackbacks); - if(count($trackbacks)) { - foreach($trackbacks as $key => $val) { - $tobj = null; - $tobj->trackback_srl = getNextSequence(); - $tobj->module_srl = $module_srl; - $tobj->document_srl = $obj->document_srl; - $tobj->url = $val->url->body; - $tobj->title = $val->title->body; - $tobj->blog_name = $val->site->body; - $tobj->excerpt = $val->excerpt->body; - $tobj->regdate = date("YmdHis",$val->received->body); - $tobj->ipaddress = $val->ip->body; - $tobj->list_order = -1*$tobj->trackback_srl; - $output = executeQuery('trackback.insertTrackback', $tobj); - if($output->toBool()) $obj->trackback_count++; - } - } - } - // Comment - $obj->comment_count = 0; - if($xmlDoc->post->comment) { - $comment = $xmlDoc->post->comment; - if(!is_array($comment)) $comment = array($comment); - foreach($comment as $key => $val) { - $parent_srl = $this->insertComment($val, $module_srl, $obj->document_srl, $member_info, 0, $author_xml_id); - if($parent_srl === false) continue; + if(count($files)) + { + $this->files = $files; + $obj->content = preg_replace_callback('!\[##_([a-z0-9]+)\|([^\|]*)\|([^\|]*)\|(.*?)_##\]!is', array($this, '_replaceTTAttach'), $obj->content); + } + // Trackback inserted + $obj->trackback_count = 0; + if($xmlDoc->post->trackback) + { + $trackbacks = $xmlDoc->post->trackback; + if(!is_array($trackbacks)) $trackbacks = array($trackbacks); + if(count($trackbacks)) + { + foreach($trackbacks as $key => $val) + { + $tobj = null; + $tobj->trackback_srl = getNextSequence(); + $tobj->module_srl = $module_srl; + $tobj->document_srl = $obj->document_srl; + $tobj->url = $val->url->body; + $tobj->title = $val->title->body; + $tobj->blog_name = $val->site->body; + $tobj->excerpt = $val->excerpt->body; + $tobj->regdate = date("YmdHis",$val->received->body); + $tobj->ipaddress = $val->ip->body; + $tobj->list_order = -1*$tobj->trackback_srl; + $output = executeQuery('trackback.insertTrackback', $tobj); + if($output->toBool()) $obj->trackback_count++; + } + } + } + // Comment + $obj->comment_count = 0; + if($xmlDoc->post->comment) + { + $comment = $xmlDoc->post->comment; + if(!is_array($comment)) $comment = array($comment); + foreach($comment as $key => $val) + { + $parent_srl = $this->insertComment($val, $module_srl, $obj->document_srl, $member_info, 0, $author_xml_id); + if($parent_srl === false) continue; - $obj->comment_count++; - if($val->comment) { - $child_comment = $val->comment; - if(!is_array($child_comment)) $child_comment = array($child_comment); - foreach($child_comment as $k => $v) { - $result = $this->insertComment($v, $module_srl, $obj->document_srl, $member_info, $parent_srl, $author_xml_id); - if($result !== false) $obj->comment_count++; - } - } - } - } - - if($module_name == 'textyle') { - $args->document_srl = $obj->document_srl; - $args->module_srl = $obj->module_srl; - $args->logs = serialize(null); - $output = executeQuery('textyle.insertPublishLog', $args); - // Visibility value of published state - $status_published = array('public', 'syndicated'); - // Save state if not published - if(!in_array($xmlDoc->post->visibility->body, $status_published)) { - $obj->module_srl = $member_info->member_srl; - } - } - // Document - $output = executeQuery('document.insertDocument', $obj); - - if($output->toBool()) { - // Tags - if($obj->tags) { - $tag_list = explode(',',$obj->tags); - $tag_count = count($tag_list); - for($i=0;$i<$tag_count;$i++) { - $args = null; - $args->tag_srl = getNextSequence(); - $args->module_srl = $module_srl; - $args->document_srl = $obj->document_srl; - $args->tag = trim($tag_list[$i]); - $args->regdate = $obj->regdate; - if(!$args->tag) continue; - $output = executeQuery('tag.insertTag', $args); - } - } - } - - fclose($fp); - FileHandler::removeFile($target_file); - } - - fclose($f); - - if(count($category_list)) foreach($category_list as $key => $val) $oDocumentController->updateCategoryCount($module_srl, $val->category_srl); - // Guestbook information - $guestbook_file = preg_replace('/index$/i', 'guestbook.xml', $index_file); - if (file_exists($guestbook_file)) { - // Create the xmlParser object - $xmlDoc = $this->oXmlParser->loadXmlFile($guestbook_file); - // Handle guest book information - if($guestbook_module_srl && $xmlDoc->guestbook->comment) { - $comment = $xmlDoc->guestbook->comment; - if(!is_array($comment)) $comment = array($comment); - - if($module_name =='textyle'){ - foreach($comment as $key => $val) { - $textyle_guestbook_srl = getNextSequence(); - - if($val->comment) { - $child_comment = $val->comment; - if(!is_array($child_comment)) $child_comment = array($child_comment); - foreach($child_comment as $k => $v) { - $result = $this->insertTextyleGuestbookItem($v, $module_srl, $member_info,0,$textyle_guestbook_srl,$author_xml_id); - } - } - - $result = $this->insertTextyleGuestbookItem($val, $module_srl, $member_info,$textyle_guestbook_srl,0,$author_xml_id); - } - }else{ - foreach($comment as $key => $val) { - $obj = null; - $obj->module_srl = $guestbook_module_srl; - $obj->document_srl = getNextSequence(); - $obj->uploaded_count = 0; - $obj->is_notice = 'N'; - $obj->status = $val->secret->body=='1'?$oDocumentModel->getConfigStatus('secret'):$oDocumentModel->getConfigStatus('public'); - $obj->content = nl2br($val->content->body); - - // Extract a title form the bocy - $obj->title = cut_str(strip_tags($obj->content),20,'...'); - if ($obj->title == '') $obj->title = 'Untitled'; - - $obj->commentStatus = 'ALLOW'; - $obj->allow_trackback = 'N'; - $obj->regdate = date("YmdHis",$val->written->body); - $obj->last_update = date("YmdHis", $val->written->body); - if(!$obj->last_update) $obj->last_update = $obj->regdate; - $obj->tags = ''; - $obj->readed_count = 0; - $obj->voted_count = 0; - if ($author_xml_id && $val->commenter->attrs->id == $author_xml_id) { - $obj->password = ''; - $obj->nick_name = $member_info->nick_name; - $obj->user_name = $member_info->user_name; - $obj->user_id = $member_info->user_id; - $obj->member_srl = $member_info->member_srl; - $obj->email_address = $member_info->email_address; - $obj->homepage = $member_info->homepage; - } - else { - $obj->password = $val->password->body; - $obj->nick_name = $val->commenter->name->body; - $obj->member_srl = 0; - $homepage = $val->commenter->homepage->body; - } - $obj->ipaddress = $val->commenter->ip->body; - $obj->list_order = $obj->update_order = $obj->document_srl*-1; - $obj->notify_message = 'N'; - $obj->trackback_count = 0; - - $obj->comment_count = 0; - if($val->comment) { - $child_comment = $val->comment; - if(!is_array($child_comment)) $child_comment = array($child_comment); - foreach($child_comment as $k => $v) { - $result = $this->insertComment($v, $module_srl, $obj->document_srl, $member_info, 0,$author_xml_id); - if($result !== false) $obj->comment_count++; - } - } - - // Document - $output = executeQuery('document.insertDocument', $obj); + $obj->comment_count++; + if($val->comment) + { + $child_comment = $val->comment; + if(!is_array($child_comment)) $child_comment = array($child_comment); + foreach($child_comment as $k => $v) + { + $result = $this->insertComment($v, $module_srl, $obj->document_srl, $member_info, $parent_srl, $author_xml_id); + if($result !== false) $obj->comment_count++; } } - } - FileHandler::removeFile($guestbook_file); - } - - return $idx-1; - } - - /** - * Insert textyle guest book - * @param object $val - * @param int $module_srl - * @param object $member_info - * @param int $textyle_guestbook_srl - * @param int $parent_srl - * @param int $author_xml_id - * @return int|bool - */ - function insertTextyleGuestbookItem($val, $module_srl, $member_info, $textyle_guestbook_srl,$parent_srl = 0, $author_xml_id=null) { - $tobj = null; - if($textyle_guestbook_srl>0){ - $tobj->textyle_guestbook_srl = $textyle_guestbook_srl; - }else{ - $tobj->textyle_guestbook_srl = getNextSequence(); - } - $tobj->module_srl = $module_srl; - $tobj->is_secret = $val->secret->body=='1'?1:-1; - $tobj->content = nl2br($val->content->body); - if($author_xml_id && $val->commenter->attrs->id == $author_xml_id) { - $tobj->password = ''; - $tobj->nick_name = $member_info->nick_name; - $tobj->user_name = $member_info->user_name; - $tobj->user_id = $member_info->user_id; - $tobj->member_srl = $member_info->member_srl; - $tobj->homepage = $member_info->homepage; - $tobj->email_address = $member_info->email_address; - } else { - $tobj->password = $val->password->body; - $tobj->nick_name = $val->commenter->name->body; - $tobj->homepage = $val->commenter->homepage->body; - $tobj->member_srl = 0; - } - $tobj->last_update = $tobj->regdate = date("YmdHis",$val->written->body); - $tobj->ipaddress = $val->commenter->ip->body; - - if($parent_srl>0){ - $tobj->parent_srl = $parent_srl; - $tobj->list_order = $tobj->parent_srl * -1; - }else{ - $tobj->list_order = $tobj->textyle_guestbook_srl*-1; + } } - $output = executeQuery('textyle.insertTextyleGuestbook', $tobj); + if($module_name == 'textyle') + { + $args->document_srl = $obj->document_srl; + $args->module_srl = $obj->module_srl; + $args->logs = serialize(null); + $output = executeQuery('textyle.insertPublishLog', $args); + // Visibility value of published state + $status_published = array('public', 'syndicated'); + // Save state if not published + if(!in_array($xmlDoc->post->visibility->body, $status_published)) + { + $obj->module_srl = $member_info->member_srl; + } + } + // Document + $output = executeQuery('document.insertDocument', $obj); - if($output->toBool()) return $tobj->textyle_guestbook_srl; - return false; + if($output->toBool()) + { + // Tags + if($obj->tags) + { + $tag_list = explode(',',$obj->tags); + $tag_count = count($tag_list); + for($i=0;$i<$tag_count;$i++) + { + $args = null; + $args->tag_srl = getNextSequence(); + $args->module_srl = $module_srl; + $args->document_srl = $obj->document_srl; + $args->tag = trim($tag_list[$i]); + $args->regdate = $obj->regdate; + if(!$args->tag) continue; + $output = executeQuery('tag.insertTag', $args); + } + } + } + + fclose($fp); + FileHandler::removeFile($target_file); } + fclose($f); - /** - * Attachment - * @param resource $fp - * @param int $module_srl - * @param int $upload_target_srl - * @param array $files - * @param string $buff - * @return bool - */ - function importAttaches($fp, $module_srl, $upload_target_srl, &$files, $buff) { - $uploaded_count = 0; + if(count($category_list)) foreach($category_list as $key => $val) $oDocumentController->updateCategoryCount($module_srl, $val->category_srl); + // Guestbook information + $guestbook_file = preg_replace('/index$/i', 'guestbook.xml', $index_file); + if(file_exists($guestbook_file)) + { + // Create the xmlParser object + $xmlDoc = $this->oXmlParser->loadXmlFile($guestbook_file); + // Handle guest book information + if($guestbook_module_srl && $xmlDoc->guestbook->comment) + { + $comment = $xmlDoc->guestbook->comment; + if(!is_array($comment)) $comment = array($comment); - $file_obj = null; - $file_obj->file_srl = getNextSequence(); - $file_obj->upload_target_srl = $upload_target_srl; - $file_obj->module_srl = $module_srl; + if($module_name =='textyle') + { + foreach($comment as $key => $val) + { + $textyle_guestbook_srl = getNextSequence(); - while(!feof($fp)) { - $str = fgets($fp, 1024); - // If it ends with , break - if(trim($str) == '') break; - // If it starts with , handle the attachement in the xml file - if(substr($str, 0, 9)=='') { - $file_obj->file = $this->saveTemporaryFile($fp, $str); - continue; - } + if($val->comment) + { + $child_comment = $val->comment; + if(!is_array($child_comment)) $child_comment = array($child_comment); + foreach($child_comment as $k => $v) + { + $result = $this->insertTextyleGuestbookItem($v, $module_srl, $member_info,0,$textyle_guestbook_srl,$author_xml_id); + } + } - $buff .= $str; - } - if(!file_exists($file_obj->file)) return false; + $result = $this->insertTextyleGuestbookItem($val, $module_srl, $member_info,$textyle_guestbook_srl,0,$author_xml_id); + } + } + else + { + foreach($comment as $key => $val) + { + $obj = null; + $obj->module_srl = $guestbook_module_srl; + $obj->document_srl = getNextSequence(); + $obj->uploaded_count = 0; + $obj->is_notice = 'N'; + $obj->status = $val->secret->body=='1'?$oDocumentModel->getConfigStatus('secret'):$oDocumentModel->getConfigStatus('public'); + $obj->content = nl2br($val->content->body); - $buff .= ''; + // Extract a title form the bocy + $obj->title = cut_str(strip_tags($obj->content),20,'...'); + if ($obj->title == '') $obj->title = 'Untitled'; - $xmlDoc = $this->oXmlParser->parse($buff); + $obj->commentStatus = 'ALLOW'; + $obj->allow_trackback = 'N'; + $obj->regdate = date("YmdHis",$val->written->body); + $obj->last_update = date("YmdHis", $val->written->body); + if(!$obj->last_update) $obj->last_update = $obj->regdate; + $obj->tags = ''; + $obj->readed_count = 0; + $obj->voted_count = 0; + if($author_xml_id && $val->commenter->attrs->id == $author_xml_id) + { + $obj->password = ''; + $obj->nick_name = $member_info->nick_name; + $obj->user_name = $member_info->user_name; + $obj->user_id = $member_info->user_id; + $obj->member_srl = $member_info->member_srl; + $obj->email_address = $member_info->email_address; + $obj->homepage = $member_info->homepage; + } + else + { + $obj->password = $val->password->body; + $obj->nick_name = $val->commenter->name->body; + $obj->member_srl = 0; + $homepage = $val->commenter->homepage->body; + } + $obj->ipaddress = $val->commenter->ip->body; + $obj->list_order = $obj->update_order = $obj->document_srl*-1; + $obj->notify_message = 'N'; + $obj->trackback_count = 0; - $file_obj->source_filename = $xmlDoc->attachment->label->body; - $file_obj->download_count = $xmlDoc->attachment->downloads->body; - $name = $xmlDoc->attachment->name->body; - // Set upload path by checking if the attachement is an image or other kind of file - if(preg_match("/\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp1|mp2|mp3|mp4|asf|wav|asx|mid|midi|asf|mov|moov|qt|rm|ram|ra|rmm|m4v)$/i", $file_obj->source_filename)) { - $path = sprintf("./files/attach/images/%s/%s", $module_srl,getNumberingPath($upload_target_srl,3)); - $filename = $path.$file_obj->source_filename; - $file_obj->direct_download = 'Y'; - } else { - $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); - $filename = $path.md5(crypt(rand(1000000,900000), rand(0,100))); - $file_obj->direct_download = 'N'; - } - // Create a directory - if(!FileHandler::makeDir($path)) return; + $obj->comment_count = 0; + if($val->comment) + { + $child_comment = $val->comment; + if(!is_array($child_comment)) $child_comment = array($child_comment); + foreach($child_comment as $k => $v) + { + $result = $this->insertComment($v, $module_srl, $obj->document_srl, $member_info, 0,$author_xml_id); + if($result !== false) $obj->comment_count++; + } + } - FileHandler::rename($file_obj->file, $filename); - // Insert to the DB - unset($file_obj->file); - $file_obj->uploaded_filename = $filename; - $file_obj->file_size = filesize($filename); - $file_obj->comment = NULL; - $file_obj->member_srl = 0; - $file_obj->sid = md5(rand(rand(1111111,4444444),rand(4444445,9999999))); - $file_obj->isvalid = 'Y'; - $output = executeQuery('file.insertFile', $file_obj); - - if($output->toBool()) { - $uploaded_count++; - $tmp_obj = null; - if($file_obj->direct_download == 'Y') $files[$name]->url = $file_obj->uploaded_filename; - else $files[$name]->url = getUrl('','module','file','act','procFileDownload','file_srl',$file_obj->file_srl,'sid',$file_obj->sid); - $files[$name]->direct_download = $file_obj->direct_download; - $files[$name]->source_filename = $file_obj->source_filename; - return true; - } + // Document + $output = executeQuery('document.insertDocument', $obj); + } + } + } + FileHandler::removeFile($guestbook_file); + } - return false; - } + return $idx-1; + } - /** - * Return a filename to temporarily use - * @return string - */ - function getTmpFilename() { - $path = "./files/cache/importer"; - if(!is_dir($path)) FileHandler::makeDir($path); - $filename = sprintf("%s/%d", $path, rand(11111111,99999999)); - if(file_exists($filename)) $filename .= rand(111,999); - return $filename; - } + /** + * Insert textyle guest book + * @param object $val + * @param int $module_srl + * @param object $member_info + * @param int $textyle_guestbook_srl + * @param int $parent_srl + * @param int $author_xml_id + * @return int|bool + */ + function insertTextyleGuestbookItem($val, $module_srl, $member_info, $textyle_guestbook_srl,$parent_srl = 0, $author_xml_id=null) + { + $tobj = null; + if($textyle_guestbook_srl>0) + { + $tobj->textyle_guestbook_srl = $textyle_guestbook_srl; + } + else + { + $tobj->textyle_guestbook_srl = getNextSequence(); + } + $tobj->module_srl = $module_srl; + $tobj->is_secret = $val->secret->body=='1'?1:-1; + $tobj->content = nl2br($val->content->body); + if($author_xml_id && $val->commenter->attrs->id == $author_xml_id) + { + $tobj->password = ''; + $tobj->nick_name = $member_info->nick_name; + $tobj->user_name = $member_info->user_name; + $tobj->user_id = $member_info->user_id; + $tobj->member_srl = $member_info->member_srl; + $tobj->homepage = $member_info->homepage; + $tobj->email_address = $member_info->email_address; + } + else + { + $tobj->password = $val->password->body; + $tobj->nick_name = $val->commenter->name->body; + $tobj->homepage = $val->commenter->homepage->body; + $tobj->member_srl = 0; + } + $tobj->last_update = $tobj->regdate = date("YmdHis",$val->written->body); + $tobj->ipaddress = $val->commenter->ip->body; - /** - * Read buff until key value comes out from a specific file point - * @param resource $fp - * @param string $buff - * @return string - */ - function saveTemporaryFile($fp, $buff) { - $temp_filename = $this->getTmpFilename(); - $buff = substr($buff, 9); + if($parent_srl>0) + { + $tobj->parent_srl = $parent_srl; + $tobj->list_order = $tobj->parent_srl * -1; + } + else + { + $tobj->list_order = $tobj->textyle_guestbook_srl*-1; + } - while(!feof($fp)) { - $str = trim(fgets($fp, 1024)); - $buff .= $str; - if(substr($str, -10) == '') break; - } + $output = executeQuery('textyle.insertTextyleGuestbook', $tobj); - $buff = substr($buff, 0, -10); + if($output->toBool()) return $tobj->textyle_guestbook_srl; + return false; + } - $f = fopen($temp_filename, "w"); - fwrite($f, base64_decode($buff)); - fclose($f); - return $temp_filename; - } + /** + * Attachment + * @param resource $fp + * @param int $module_srl + * @param int $upload_target_srl + * @param array $files + * @param string $buff + * @return bool + */ + function importAttaches($fp, $module_srl, $upload_target_srl, &$files, $buff) + { + $uploaded_count = 0; - /** - * Replace img tag in the ttxml - * @param array $matches - * @return string - */ - function _replaceTTAttach($matches) { - $name = $matches[2]; - if(!$name) return $matches[0]; + $file_obj = null; + $file_obj->file_srl = getNextSequence(); + $file_obj->upload_target_srl = $upload_target_srl; + $file_obj->module_srl = $module_srl; - $obj = $this->files[$name]; - // If multimedia file is, - if($obj->direct_download == 'Y') { - // If image file is - if(preg_match('/\.(jpg|gif|jpeg|png)$/i', $obj->source_filename)) { - return sprintf('%s', $obj->url, str_replace('"','\\"',$matches[4])); - // If other multimedia file but image is, - } else { - return sprintf('', $obj->url); - } - // If binary file is - } else { - return sprintf('%s', $obj->url, $obj->source_filename); - } - } + while(!feof($fp)) + { + $str = fgets($fp, 1024); + // If it ends with , break + if(trim($str) == '') break; + // If it starts with , handle the attachement in the xml file + if(substr($str, 0, 9)=='') + { + $file_obj->file = $this->saveTemporaryFile($fp, $str); + continue; + } - /** - * Convert the video file - * @return string - */ - function _replaceTTMovie($matches) { - $key = $matches[1]; - if(!$key) return $matches[0]; + $buff .= $str; + } + if(!file_exists($file_obj->file)) return false; - return - ''. - ''. - ''. - ''. - ''. - ''. - ''; - } + $buff .= ''; - /** - * Comment - * @param object $val - * @param int $module_srl - * @param int $document_srl - * @param object $member_info - * @param int $parent_srl - * @param int $author_xml_id - * @return bool|int|object - */ - function insertComment($val, $module_srl, $document_srl, $member_info, $parent_srl = 0, $author_xml_id) { - $tobj = null; - $tobj->comment_srl = getNextSequence(); - $tobj->module_srl = $module_srl; - $tobj->document_srl = $document_srl; - $tobj->is_secret = $val->secret->body=='1'?'Y':'N'; - $tobj->notify_message = 'N'; - $tobj->content = nl2br($val->content->body); - $tobj->voted_count = 0; - if ($author_xml_id && $val->commenter->attrs->id == $author_xml_id) { - $tobj->password = ''; - $tobj->nick_name = $member_info->nick_name; - $tobj->user_name = $member_info->user_name; - $tobj->user_id = $member_info->user_id; - $tobj->member_srl = $member_info->member_srl; - $tobj->homepage = $member_info->homepage; - $tobj->email_address = $member_info->email_address; - } else { - $tobj->password = $val->password->body; - $tobj->nick_name = $val->commenter->name->body; - $tobj->homepage = $val->commenter->homepage->body; - $tobj->member_srl = 0; - } - $tobj->last_update = $tobj->regdate = date("YmdHis",$val->written->body); - $tobj->ipaddress = $val->commenter->ip->body; - $tobj->list_order = $tobj->comment_srl*-1; - $tobj->sequence = $sequence; - $tobj->parent_srl = $parent_srl; - // Comment list first - $list_args = null; - $list_args->comment_srl = $tobj->comment_srl; - $list_args->document_srl = $tobj->document_srl; - $list_args->module_srl = $tobj->module_srl; - $list_args->regdate = $tobj->regdate; - // Set data directly if parent comment doesn't exist - if(!$tobj->parent_srl) { - $list_args->head = $list_args->arrange = $tobj->comment_srl; - $list_args->depth = 0; - // Get parent_srl if parent comment exists - } else { - // Get parent_srl - $parent_args->comment_srl = $tobj->parent_srl; - $parent_output = executeQuery('comment.getCommentListItem', $parent_args); - // Return if parent comment doesn't exist - if(!$parent_output->toBool() || !$parent_output->data) return false; - $parent = $parent_output->data; + $xmlDoc = $this->oXmlParser->parse($buff); - $list_args->head = $parent->head; - $list_args->depth = $parent->depth+1; - if($list_args->depth<2) $list_args->arrange = $tobj->comment_srl; - else { - $list_args->arrange = $parent->arrange; - $output = executeQuery('comment.updateCommentListArrange', $list_args); - if(!$output->toBool()) return $output; - } - } + $file_obj->source_filename = $xmlDoc->attachment->label->body; + $file_obj->download_count = $xmlDoc->attachment->downloads->body; + $name = $xmlDoc->attachment->name->body; + // Set upload path by checking if the attachement is an image or other kind of file + if(preg_match("/\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp1|mp2|mp3|mp4|asf|wav|asx|mid|midi|asf|mov|moov|qt|rm|ram|ra|rmm|m4v)$/i", $file_obj->source_filename)) + { + $path = sprintf("./files/attach/images/%s/%s", $module_srl,getNumberingPath($upload_target_srl,3)); + $filename = $path.$file_obj->source_filename; + $file_obj->direct_download = 'Y'; + } + else + { + $path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl,3)); + $filename = $path.md5(crypt(rand(1000000,900000), rand(0,100))); + $file_obj->direct_download = 'N'; + } + // Create a directory + if(!FileHandler::makeDir($path)) return; - $output = executeQuery('comment.insertCommentList', $list_args); - if($output->toBool()) { - $output = executeQuery('comment.insertComment', $tobj); - if($output->toBool()) return $tobj->comment_srl; - } - return false; - } + FileHandler::rename($file_obj->file, $filename); + // Insert to the DB + unset($file_obj->file); + $file_obj->uploaded_filename = $filename; + $file_obj->file_size = filesize($filename); + $file_obj->comment = NULL; + $file_obj->member_srl = 0; + $file_obj->sid = md5(rand(rand(1111111,4444444),rand(4444445,9999999))); + $file_obj->isvalid = 'Y'; + $output = executeQuery('file.insertFile', $file_obj); - /** - * List category - * @param object $obj - * @param array $category - * @param int $idx - * @param int $parent - * @return void - */ - function arrangeCategory($obj, &$category, &$idx, $parent = 0) { - if(!$obj->category) return; - if(!is_array($obj->category)) $c = array($obj->category); - else $c = $obj->category; - foreach($c as $val) { - $idx++; - $priority = $val->priority->body; - $name = $val->name->body; - $obj = null; - $obj->priority = $priority; - $obj->name = $name; - $obj->sequence = $idx; - $obj->parent = $parent; + if($output->toBool()) + { + $uploaded_count++; + $tmp_obj = null; + if($file_obj->direct_download == 'Y') $files[$name]->url = $file_obj->uploaded_filename; + else $files[$name]->url = getUrl('','module','file','act','procFileDownload','file_srl',$file_obj->file_srl,'sid',$file_obj->sid); + $files[$name]->direct_download = $file_obj->direct_download; + $files[$name]->source_filename = $file_obj->source_filename; + return true; + } - $category[$idx] = $obj; + return false; + } - $this->arrangeCategory($val, $category, $idx, $idx); - } - } - } -?> + /** + * Return a filename to temporarily use + * @return string + */ + function getTmpFilename() + { + $path = "./files/cache/importer"; + if(!is_dir($path)) FileHandler::makeDir($path); + $filename = sprintf("%s/%d", $path, rand(11111111,99999999)); + if(file_exists($filename)) $filename .= rand(111,999); + return $filename; + } + + /** + * Read buff until key value comes out from a specific file point + * @param resource $fp + * @param string $buff + * @return string + */ + function saveTemporaryFile($fp, $buff) + { + $temp_filename = $this->getTmpFilename(); + $buff = substr($buff, 9); + + while(!feof($fp)) + { + $str = trim(fgets($fp, 1024)); + $buff .= $str; + if(substr($str, -10) == '') break; + } + + $buff = substr($buff, 0, -10); + + $f = fopen($temp_filename, "w"); + fwrite($f, base64_decode($buff)); + fclose($f); + return $temp_filename; + } + + /** + * Replace img tag in the ttxml + * @param array $matches + * @return string + */ + function _replaceTTAttach($matches) + { + $name = $matches[2]; + if(!$name) return $matches[0]; + + $obj = $this->files[$name]; + // If multimedia file is, + if($obj->direct_download == 'Y') + { + // If image file is + if(preg_match('/\.(jpg|gif|jpeg|png)$/i', $obj->source_filename)) + { + return sprintf('%s', $obj->url, str_replace('"','\\"',$matches[4])); + // If other multimedia file but image is, + } + else + { + return sprintf('', $obj->url); + } + // If binary file is + } + else + { + return sprintf('%s', $obj->url, $obj->source_filename); + } + } + + /** + * Convert the video file + * @return string + */ + function _replaceTTMovie($matches) + { + $key = $matches[1]; + if(!$key) return $matches[0]; + + return + ''. + ''. + ''. + ''. + ''. + ''. + ''; + } + + /** + * Comment + * @param object $val + * @param int $module_srl + * @param int $document_srl + * @param object $member_info + * @param int $parent_srl + * @param int $author_xml_id + * @return bool|int|object + */ + function insertComment($val, $module_srl, $document_srl, $member_info, $parent_srl = 0, $author_xml_id) + { + $tobj = null; + $tobj->comment_srl = getNextSequence(); + $tobj->module_srl = $module_srl; + $tobj->document_srl = $document_srl; + $tobj->is_secret = $val->secret->body=='1'?'Y':'N'; + $tobj->notify_message = 'N'; + $tobj->content = nl2br($val->content->body); + $tobj->voted_count = 0; + if($author_xml_id && $val->commenter->attrs->id == $author_xml_id) + { + $tobj->password = ''; + $tobj->nick_name = $member_info->nick_name; + $tobj->user_name = $member_info->user_name; + $tobj->user_id = $member_info->user_id; + $tobj->member_srl = $member_info->member_srl; + $tobj->homepage = $member_info->homepage; + $tobj->email_address = $member_info->email_address; + } + else + { + $tobj->password = $val->password->body; + $tobj->nick_name = $val->commenter->name->body; + $tobj->homepage = $val->commenter->homepage->body; + $tobj->member_srl = 0; + } + $tobj->last_update = $tobj->regdate = date("YmdHis",$val->written->body); + $tobj->ipaddress = $val->commenter->ip->body; + $tobj->list_order = $tobj->comment_srl*-1; + $tobj->sequence = $sequence; + $tobj->parent_srl = $parent_srl; + // Comment list first + $list_args = null; + $list_args->comment_srl = $tobj->comment_srl; + $list_args->document_srl = $tobj->document_srl; + $list_args->module_srl = $tobj->module_srl; + $list_args->regdate = $tobj->regdate; + // Set data directly if parent comment doesn't exist + if(!$tobj->parent_srl) + { + $list_args->head = $list_args->arrange = $tobj->comment_srl; + $list_args->depth = 0; + // Get parent_srl if parent comment exists + } + else + { + // Get parent_srl + $parent_args->comment_srl = $tobj->parent_srl; + $parent_output = executeQuery('comment.getCommentListItem', $parent_args); + // Return if parent comment doesn't exist + if(!$parent_output->toBool() || !$parent_output->data) return false; + $parent = $parent_output->data; + + $list_args->head = $parent->head; + $list_args->depth = $parent->depth+1; + if($list_args->depth<2) $list_args->arrange = $tobj->comment_srl; + else + { + $list_args->arrange = $parent->arrange; + $output = executeQuery('comment.updateCommentListArrange', $list_args); + if(!$output->toBool()) return $output; + } + } + + $output = executeQuery('comment.insertCommentList', $list_args); + if($output->toBool()) + { + $output = executeQuery('comment.insertComment', $tobj); + if($output->toBool()) return $tobj->comment_srl; + } + return false; + } + + /** + * List category + * @param object $obj + * @param array $category + * @param int $idx + * @param int $parent + * @return void + */ + function arrangeCategory($obj, &$category, &$idx, $parent = 0) + { + if(!$obj->category) return; + if(!is_array($obj->category)) $c = array($obj->category); + else $c = $obj->category; + foreach($c as $val) + { + $idx++; + $priority = $val->priority->body; + $name = $val->name->body; + $obj = null; + $obj->priority = $priority; + $obj->name = $name; + $obj->sequence = $idx; + $obj->parent = $parent; + + $category[$idx] = $obj; + + $this->arrangeCategory($val, $category, $idx, $idx); + } + } +} +/* End of file ttimport.class.php */ +/* Location: ./modules/importer/ttimport.class.php */