diff --git a/modules/importer/importer.admin.controller.php b/modules/importer/importer.admin.controller.php index 881f4b678..31d46a248 100644 --- a/modules/importer/importer.admin.controller.php +++ b/modules/importer/importer.admin.controller.php @@ -56,9 +56,21 @@ break; case 'ttxml' : // 카테고리 정보를 먼저 구함 - $output = $oExtract->set($xml_file,'', '',''); + $output = $oExtract->set($xml_file,'','', 'toBool()) { - $oExtract->mergeItems('category'); + // ttxml 카테고리는 별도로 구함 + $started = false; + $buff = ''; + while(!feof($oExtract->fd)) { + $str = fgets($oExtract->fd, 1024); + if(substr($str,0,strlen(''))=='') $started = true; + if(substr($str,0,strlen(''; + $oExtract->closeFile(); + $category_filename = sprintf('%s/%s', $oExtract->cache_path, 'category'); + FileHandler::writeFile($category_filename, $buff); // 개별 아이템 구함 $output = $oExtract->set($xml_file,'', ''); @@ -67,7 +79,7 @@ break; default : // 카테고리 정보를 먼저 구함 - $output = $oExtract->set($xml_file,'', '', '',''); + $output = $oExtract->set($xml_file,'', '', ''); if($output->toBool()) { $oExtract->mergeItems('category'); @@ -402,14 +414,21 @@ if($categories) { if(!is_array($categories)) $categories = array($categories); $oDocumentController = &getController('document'); + $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); @@ -755,40 +774,43 @@ } } - // 이미지인지 기타 파일인지 체크하여 upload path 지정 - if(preg_match("/\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp3|asaf|wav|asx|midi|asf)$/i", $file_obj->source_filename)) { - $path = sprintf("./files/attach/images/%s/%s/", $module_srl,$upload_target_srl); - $filename = $path.$file_obj->source_filename; - $file_obj->direct_download = 'Y'; - } else { - $path = sprintf("./files/attach/binaries/%s/%s/", $module_srl, $upload_target_srl); - $filename = $path.md5(crypt(rand(1000000,900000), rand(0,100))); - $file_obj->direct_download = 'N'; - } + if(file_exists($file_obj->file)) { - // 디렉토리 생성 - if(!FileHandler::makeDir($path)) continue; + // 이미지인지 기타 파일인지 체크하여 upload path 지정 + if(preg_match("/\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp3|asaf|wav|asx|midi|asf)$/i", $file_obj->source_filename)) { + $path = sprintf("./files/attach/images/%s/%s/", $module_srl,$upload_target_srl); + $filename = $path.$file_obj->source_filename; + $file_obj->direct_download = 'Y'; + } else { + $path = sprintf("./files/attach/binaries/%s/%s/", $module_srl, $upload_target_srl); + $filename = $path.md5(crypt(rand(1000000,900000), rand(0,100))); + $file_obj->direct_download = 'N'; + } - if(preg_match('/^\.\/files\/cache\/tmp/i',$file_obj->file)) @rename($file_obj->file, $filename); - else @copy($file_obj->file, $filename); + // 디렉토리 생성 + if(!FileHandler::makeDir($path)) continue; - // 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); + if(preg_match('/^\.\/files\/cache\/tmp/i',$file_obj->file)) @rename($file_obj->file, $filename); + else @copy($file_obj->file, $filename); + + // 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); + } } } } diff --git a/modules/importer/tpl/member.html b/modules/importer/tpl/member.html index 0995a9480..72287416e 100644 --- a/modules/importer/tpl/member.html +++ b/modules/importer/tpl/member.html @@ -17,9 +17,9 @@ - + - + diff --git a/modules/importer/tpl/module.html b/modules/importer/tpl/module.html index 7cb5e6c58..1d61448b8 100644 --- a/modules/importer/tpl/module.html +++ b/modules/importer/tpl/module.html @@ -31,11 +31,11 @@ - + - + diff --git a/modules/importer/ttimport.class.php b/modules/importer/ttimport.class.php index fa7f52d4f..88b13ea7f 100644 --- a/modules/importer/ttimport.class.php +++ b/modules/importer/ttimport.class.php @@ -33,25 +33,30 @@ // xmlParser객체 생성 $xmlDoc = $this->oXmlParser->loadXmlFile($category_file); - $categories = $xmlDoc->items->category; - if($categories) { - if(!is_array($categories)) $categories = array($categories); + // 카테고리 정보를 정리 + if($xmlDoc->items->category) { + $categories = array(); + $idx = 0; + $this->arrangeCategory($xmlDoc->items, $categories, $idx, 0); $oDocumentController = &getController('document'); + + $match_sequence = array(); foreach($categories as $k => $v) { - $category = $v->name->body; + $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); + + if($output->toBool()) $match_sequence[$v->sequence] = $output->get('category_srl'); } - $oDocumentController = &getController('document'); $oDocumentController->makeCategoryFile($module_srl); } @unlink($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; @@ -111,11 +116,14 @@ $xmlDoc = $this->oXmlParser->parse(''.$buff); - $category = $xmlDoc->post->category->body; - 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->is_secret = $xmlDoc->post->visibility->body=='syndicated'?'N':'Y'; + $obj->is_secret = in_array($xmlDoc->post->visibility->body, array('public','syndicated'))?'N':'Y'; $obj->title = $xmlDoc->post->title->body; $obj->content = $xmlDoc->post->content->body; $obj->password = md5($xmlDoc->post->password->body); @@ -152,14 +160,16 @@ // content 정보 변경 (첨부파일) $obj->content = str_replace('[##_ATTACH_PATH_##]/','',$obj->content); if(count($files)) { - foreach($files as $label => $filename) { - $obj->content = preg_replace_callback('!\[##_([a-z0-9]+)\|([^\|]*)\|([^\|]*)\|(.*?)_##\]!is', array($this, '_replaceTTImgTag'), $obj->content); + 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); + if(count($files)) { - foreach($files as $key => $val) { - $obj->content = preg_replace('/(src|href)\=(["\']?)'.preg_quote($key).'(["\']?)/i','$1="'.$val.'"',$obj->content); - } + $this->files = $files; + $obj->content = preg_replace_callback('!\[##_([a-z0-9]+)\|([^\|]*)\|([^\|]*)\|(.*?)_##\]!is', array($this, '_replaceTTAttach'), $obj->content); } // 역인글 입력 @@ -262,14 +272,15 @@ $buff .= $str; } + if(!file_exists($file_obj->file)) return false; $buff .= ''; $xmlDoc = $this->oXmlParser->parse($buff); - $file_obj->source_filename = $xmlDoc->attachment->name->body; + $file_obj->source_filename = $xmlDoc->attachment->label->body; $file_obj->download_count = $xmlDoc->attachment->downloads->body; - $label = $xmlDoc->attachment->label->body; + $name = $xmlDoc->attachment->name->body; // 이미지인지 기타 파일인지 체크하여 upload path 지정 if(preg_match("/\.(jpg|jpeg|gif|png|wmv|wma|mpg|mpeg|avi|swf|flv|mp3|asaf|wav|asx|midi|asf)$/i", $file_obj->source_filename)) { @@ -300,9 +311,10 @@ 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); + 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; } @@ -344,8 +356,43 @@ /** * @brief ttxml의 자체 img 태그를 치환 **/ - function _replaceTTImgTag($matches) { - return sprintf("\"%s\"

", $matches[2], str_replace("\"","\\\"",$matches[4])); + function _replaceTTAttach($matches) { + $name = $matches[2]; + if(!$name) return $matches[0]; + + $obj = $this->files[$name]; + + // 멀티미디어성 파일의 경우 + if($obj->direct_download == 'Y') { + // 이미지의 경우 + if(preg_match('/\.(jpg|gif|jpeg|png)$/i', $obj->source_filename)) { + return sprintf('%s', $obj->url, str_replace('"','\\"',$matches[4])); + // 이미지 외의 멀티미디어성 파일의 경우 + } else { + return sprintf('', $obj->url); + } + + // binary파일일 경우 + } else { + return sprintf('%s', $obj->url, $obj->source_filename); + } + } + + /** + * @brief ttxml의 동영상 변환 + **/ + function _replaceTTMovie($matches) { + $key = $matches[1]; + if(!$key) return $matches[0]; + + return + ''. + ''. + ''. + ''. + ''. + ''. + ''; } /** @@ -409,5 +456,26 @@ } return false; } + + // 카테고리 정리 + 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[$priority] = $obj; + + $this->arrangeCategory($val, $category, $idx, $idx); + } + } } ?>