2012-04-21 8 views
5

पर डिस्कस एक्सएमएल निर्यात की गई टिप्पणियों को कैसे आयात करें मैं वर्तमान में अपनी टिप्पणियां सिस्टम को डिफ़ॉल्ट वर्डप्रेस टिप्पणियों पर वापस ले जा रहा हूं। मैं पहले Disqus का उपयोग कर रहा था, लेकिन मैं वापस जाने का फैसला किया। Disqus एक उपकरण प्रदान करता है कि आप अपनी सभी टिप्पणियों को निर्यात कर सकते हैं लेकिन दुर्भाग्यवश, वे आपको एक्सएमएल प्रारूप प्रदान करेंगे। सबसे बुरी बात यह है कि वर्डप्रेस केवल डब्ल्यूएक्सआर फ़ाइल प्रारूप पढ़ता है।वर्डप्रेस डब्ल्यूएक्सआर

मेरा समाधान यह है कि मुझे मैन्युअल रूप से लिखना चाहिए कि मुझे Disqus ने मुझे क्या लिखा (मेरा मतलब है कि एक्सएमएल फ़ाइल जिसे मैं Disqus से निर्यात किया गया था) वर्डप्रेस डब्ल्यूएक्सआर फ़ाइल प्रारूप में। मेरी समस्या यह है कि मुझे नहीं पता कि वर्डप्रेस टिप्पणियों की मूल संरचना क्या है।

You can view the Disqus Exported XML file here! मेरी एकमात्र चिंता यह है कि मुझे केवल एक टेम्पलेट या प्रारूप की आवश्यकता है जिसे मैं सही WXR फ़ाइल टिप्पणियों को लिखने के तरीके पर अनुसरण कर सकता हूं ताकि मैं इसे आयात टूल का उपयोग करके सीधे अपने वर्डप्रेस में आयात कर सकूं। वैसे, जब मैं वर्डप्रेस के लिए एक्सएमएल फ़ाइल अपलोड करने की कोशिश, मैं इस त्रुटि मिलती है:

Invalid file. Please upload a valid Disqus export file."

उत्तर

1

आप इस प्लगइन पर एक नज़र था?
http://wordpress.org/extend/plugins/disqus-comments-importer/

यह सीमित दिखता है लेकिन शायद एक अच्छा प्रारंभिक बिंदु है।

+0

धन्यवाद मिहाई, लेकिन मैंने पहले ही इसकी कोशिश की है। यही वह जगह है जहां मुझे त्रुटि मिलती है। –

4

Disqus वर्डप्रेस प्लगइन में एक सिंक सुविधा शामिल है जो आपकी टिप्पणियों को Disqus से वापस अपने वर्डप्रेस इंस्टॉलेशन में सिंक करेगा। यह प्लगइन के अंदर उन्नत विकल्प टैब पर स्थित हो सकता है।

+0

यदि आपको सिंकिंग सुविधा का उपयोग करने में कठिनाई का सामना करना पड़ रहा है, तो इस आधिकारिक मार्गदर्शिका के माध्यम से पढ़ें: https://help.disqus.com/customer/portal/articles/960360-syncing-with-wordpress –

3

WXR फ़ाइल प्रारूप उत्पन्न करने का प्रयास करने के बजाय Disqus XML फ़ाइल को पार्स करना आसान हो सकता है और आपके वर्डप्रेस डेटाबेस में सीधे wp_comments तालिका में आपके द्वारा निकाली गई टिप्पणियां डालना आसान हो सकता है। कम से कम इस तरह से आप प्रक्रिया का बेहतर नियंत्रण है।

उपरोक्त प्लग-इन काम नहीं कर सकता क्योंकि Disqus निर्यात प्रारूप समय-समय पर बदलता है (अजीब बात यह है कि आप निर्यातित फ़ाइल का उपयोग भी अपनी टिप्पणियों को फिर से Disqus पर आयात करने के लिए नहीं कर सकते हैं)।

For my service मैं Disqus एक्सएमएल

1

के छोटे लेकिन कष्टप्रद विविधताओं मैं अपने नई वेबसाइट पर Disqus टिप्पणी आयात करने के साथ एक ही समस्या है करने के लिए यह अनुकूल करने के लिए पहले से ही दो बार पार्सर के पुनर्लेखन के लिए किया था। हाल ही में मैं किसी तरह पार्स करते हैं और वर्डप्रेस डेटाबेस में टिप्पणी डालने के लिए पता लगा, सभी केवल पीएचपी कृपया इस this link का उल्लेख में लिखा है, किसी भी प्रतिक्रिया का स्वागत करते

यहाँ कोड

// 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; 

}