워드프레스 WXR로 디스크 XML 내보내기 주석을 가져오는 방법
현재 댓글 시스템을 기본 워드프레스 댓글로 다시 이동 중입니다.예전에 디스커스를 사용하고 있었는데 다시 이동하기로 했습니다.디스크는 모든 주석을 내보낼 수 있는 도구를 제공하지만 안타깝게도 XML 형식을 제공합니다.가장 나쁜 것은 워드프레스가 WXR 파일 형식만 읽는다는 것입니다.
이에 대한 제 해결책은 디스커스가 준 것(즉, 디스커스에서 내보낸 XML 파일을 의미함)을 워드프레스 WXR 파일 형식으로 수동으로 다시 작성하는 것입니다.저의 문제는 워드프레스 댓글의 기본 구조가 무엇인지 모른다는 것입니다.
여기서 디스크 내보내기 XML 파일을 볼 수 있습니다!여기서 내 유일한 관심사는 가져오기 도구를 사용하여 워드프레스에 직접 가져올 수 있도록 올바른 WXR 파일 주석을 작성하는 방법에 대해 따를 수 있는 템플릿이나 형식이 필요하다는 것입니다.그런데 워드프레스에 XML 파일을 업로드하려고 하면 다음과 같은 오류가 발생합니다.
파일이 잘못되었습니다.유효한 디스커스 내보내기 파일을 업로드해 주십시오."
Disqus WordPress 플러그인에는 사용자의 코멘트를 Disqus에서 WordPress 설치로 다시 동기화하는 동기화 기능이 포함되어 있습니다.플러그인 내부의 Advanced Options(고급 옵션)
WXR 파일 형식을 생성하려고 시도하는 대신 디스크커스 XML 파일을 구문 분석하고 거기서 추출한 주석을 워드프레스 데이터베이스의 wp_comments 테이블에 직접 삽입하는 것이 더 쉬울 수 있습니다.적어도 이렇게 하면 공정을 더 잘 관리할 수 있습니다.
Disqus가 내보내기 형식이 수시로 변경되기 때문에 위 플러그인이 작동하지 않을 수 있습니다(이상하게 내보낸 파일을 사용하여 주석을 다시 Disqus로 가져올 수도 없음).
제 서비스를 위해 Disqus XML의 작지만 성가신 변형에 적응하기 위해 파서를 이미 두 배로 다시 써야 했습니다.
이 플러그인을 보셨습니까?
http://wordpress.org/extend/plugins/disqus-comments-importer/
제한적으로 보이지만 어쩌면 좋은 출발점일지도 모릅니다.
제 새 웹사이트로 디스커스 코멘트를 가져오는 것과 같은 문제가 있습니다.최근에 파싱을 하고 워드프레스 데이터베이스에 코멘트를 삽입하는 방법을 찾았습니다. 모든 것이 PHP로만 작성되어 있습니다. 이 링크를 참조하십시오. 어떤 피드백이라도 환영합니다.
코드는 여기 있습니다.
// start to count the timer
$start = microtime( true );
$max_duration = ”;
// get content of file and parse the xml
$xml = simplexml_load_file( ‘yourmxlfilesource.xml’ );
// initiate database connection
$database_info[ 'hostname' ] = “”; // database hostname
$database_info[ 'database' ] = “”; // database name
$database_info[ 'username' ] = “”; // database username
$database_info[ 'password' ] = “”; // database password
$database_connect = mysql_pconnect( $database_info[ 'hostname' ], $database_info[ 'username' ], $database_info[ 'password' ] ) or trigger_error( mysql_error(), E_USER_ERROR );
mysql_select_db( $database_info[ 'database' ], $database_connect );
$i = 0;
// get all the comment from xml file
$comments = get_post();
// get all the post title array from xml file
$post_title = get_post_title_array();
$comment_result = array( );
$temp = array( );
// create loop to convert from xml comment into wordpress-format comment
foreach ( $comments as $comment ) {
$start_sub = microtime( true );
$comment_result[ 'comment_post_ID' ] = get_post_id( $comment->thread->attributes( ‘dsq’, TRUE )->id );
$comment_result[ 'comment_author' ] = $comment->author->name;
$comment_result[ 'comment_author_email' ] = $comment->author->email;
$comment_result[ 'comment_author_url' ] = ”;
$comment_result[ 'comment_author_IP' ] = $comment->ipAddress;
$comment_result[ 'comment_date' ] = sanitize_date( $comment->createdAt );
$comment_result[ 'comment_date_gmt' ] = sanitize_date( $comment->createdAt );
$comment_result[ 'comment_content' ] = strip_tags( mysql_real_escape_string( $comment->message ), ‘<br><img><a>’ );
$comment_result[ 'comment_karma' ] = 1;
// check if comment is spam, deleted or approved
if ( $comment->isSpam == ‘true’ ) {
$comment_approved = ‘spam’;
} else if ( $comment->isDeleted == ‘true’ ) {
$comment_approved = ‘trash’;
} else {
$comment_approved = 1;
}
$comment_result[ 'comment_approved' ] = $comment_approved;
$comment_result[ 'comment_agent' ] = ”;
$comment_result[ 'comment_type' ] = ”;
$comment_result[ 'comment_parent' ] = ”;
$comment_result[ 'user_id' ] = ”;
// store the wordpress format comment into temporary variable
$temp[ $i ] = $comment_result;
// insert the wordpress format comment into wp database
insert_comment( $temp[ $i ] );
$duration[ $i ] = microtime( true ) – $start_sub;
$i++;
}
echo ‘max duration : ‘ . max( $duration ) . ‘<br/>’;
echo ‘min duration : ‘ . min( $duration ) . ‘<br/>’;
echo ‘average duration : ‘ . ( array_sum( $duration ) / count( $duration ) ) . ‘<br/>’;
// show the total duration of process
echo ‘total duration : ‘ . ( microtime( true ) – $start );
///////// define function here
function insert_comment( $comment )
{
global $database_connect;
// function to insert the comment into wp database
$field = ”;
$values = ”;
foreach ( $comment as $key => $value ) {
// create sql query to insert the comment
$field .= ‘`’ . $key . ‘`’ . ‘,’;
$values .= ‘”‘ . $value . ‘”‘ . ‘,’;
}
$field = rtrim( $field, ‘,’ );
$values = rtrim( $values, ‘,’ );
// insert the comment into the database
$query = “INSERT INTO `wp_comments` ($field) VALUES ($values)”;
$query_result = mysql_query( $query, $database_connect ) or die( mysql_error() );
}
function sanitize_date( $date )
{
// remove the additional string from the date
$date = str_replace( ‘T’, ‘ ‘, $date );
$date = str_replace( ‘Z’, ‘ ‘, $date );
return $date;
}
function get_post_id( $thread )
{
global $post_title, $database_connect;
// get wordpress post id from disqus thread id
$thread_title = find_thread( ‘id’, $thread, ‘title’ ); // get the title of the post
$thread_title = explode( ‘/’, $thread_title );
$thread_title = $thread_title[ count( $thread_title ) - 1 ];
$thread_title = str_replace( ‘-’, ‘ ‘, $thread_title );
$thread_title = str_replace( ‘.html’, ”, $thread_title );
$post_title_closest = get_closest_post_title( $thread_title, $post_title );
// get the wordpress post id from the title of the post
$query = “SELECT `ID` FROM `wp_posts` WHERE `post_title` = ‘$post_title_closest’ LIMIT 1″;
$query_result = mysql_query( $query, $database_connect ) or die( mysql_error() );
$query_result_row = mysql_fetch_assoc( $query_result );
return $query_result_row[ 'ID' ];
}
function get_closest_post_title( $input, $words )
{
// no shortest distance found, yet
$shortest = -1;
// loop through words to find the closest
foreach ( $words as $word ) {
// calculate the distance between the input word,
// and the current word
$lev = levenshtein( $input, $word );
// check for an exact match
if ( $lev == 0 ) {
// closest word is this one (exact match)
$closest = $word;
$shortest = 0;
// break out of the loop; we’ve found an exact match
break;
}
// if this distance is less than the next found shortest
// distance, OR if a next shortest word has not yet been found
if ( $lev <= $shortest || $shortest < 0 ) {
// set the closest match, and shortest distance
$closest = $word;
$shortest = $lev;
}
}
return $closest;
}
function get_post_title_array( )
{
// get wordpress post id from disqus thread id
global $database_connect;
// get the wordpress post id from the title of the post
$query = “SELECT DISTINCT(`post_title`) FROM `wp_posts`”;
$query_result = mysql_query( $query, $database_connect ) or die( mysql_error() );
$query_result_row = mysql_fetch_assoc( $query_result );
$i = 0;
do {
$result[ $i ] = $query_result_row[ 'post_title' ];
$i++;
} while ( $query_result_row = mysql_fetch_assoc( $query_result ) );
return $result;
}
function find_thread( $category, $source_value, $return_category )
{
// function to get thread information
global $xml;
foreach ( $xml->children() as $row ) {
if ( (int) $row->attributes( ‘dsq’, TRUE )->id == (int) $source_value ) {
return $row->$return_category;
}
}
}
function get_post( )
{
// function to get all post from xml data
global $xml;
$i = 0;
foreach ( $xml->children() as $key => $value ) {
if ( $key == ‘post’ ) {
$result[ $i ] = $value;
$i++;
}
}
return $result;
}
언급URL : https://stackoverflow.com/questions/10258433/how-to-import-the-disqus-xml-exported-comments-to-wordpress-wxr
'programing' 카테고리의 다른 글
자바스크립트는 1년 중 하루를 계산합니다 (1 - 366) (0) | 2023.10.09 |
---|---|
CSS로 긴 문자열 잘라내기: 아직 실현 가능합니까? (0) | 2023.10.09 |
유효한 XML 파일에 XML 선언이 필요합니까? (0) | 2023.10.09 |
XML을 java.util로 변환하는 방법지도와 그 반대? (0) | 2023.10.09 |
MySql은 선택한 결과를 삽입합니다. (0) | 2023.10.09 |