You are here

function _disqus_migrate_export_wxr in Disqus 6

Calls function to gather comments to export, then builds the appropriate XML file and presents it to the user for download.

1 string reference to '_disqus_migrate_export_wxr'
disqus_migrate_admin_export in include/disqus_migrate.export.inc
Menu callback for the export actions

File

include/disqus_migrate.export.inc, line 223

Code

function _disqus_migrate_export_wxr($form, &$form_state) {

  // Gather ALL of the comments
  $thread_data = _disqus_migrate_export_gather(TRUE);
  $status_change = variable_get('disqus_migrate_export_status_alter', '--');
  if (!empty($thread_data)) {

    // Pass the data to a function that generates the XML
    $output = '';

    // Print header
    $output .= '<?xml version="1.0" encoding="UTF-8"?>';
    $output .= '<rss version="2.0"';
    $output .= '  xmlns:content="http://purl.org/rss/1.0/modules/content/"';
    $output .= '  xmlns:dsq="http://www.disqus.com/"';
    $output .= '  xmlns:dc="http://purl.org/dc/elements/1.1/"';
    $output .= '  xmlns:wp="http://wordpress.org/export/1.0/"';
    $output .= '>';
    $output .= '  <channel>';
    foreach ($thread_data as $nid => $thread) {

      // Skip thread if there were no comments attached to it. This would only happen if
      // an export is created and there are no published comments on a node (also depends
      // on what user selects in checkbox)
      if (empty($thread['comments'])) {
        continue;
      }
      $output .= '<item>';
      $output .= '<title>' . _disqus_migrate_cleanse_xml($thread['title']) . '</title>';
      $output .= '<link>' . $thread['link'] . '</link>';
      $output .= '<content:encoded></content:encoded>';
      $output .= '<dsq:thread_identifier>' . $thread['identifier'] . '</dsq:thread_identifier>';
      $output .= '<wp:post_date_gmt>' . $thread['post_date_gmt'] . '</wp:post_date_gmt>';
      $output .= '<wp:comment_status>open</wp:comment_status>';
      foreach ($thread['comments'] as $comment) {
        $output .= '<wp:comment>';
        $output .= '<wp:comment_id>' . $comment['id'] . '</wp:comment_id>';
        $output .= '<wp:comment_author>' . $comment['author'] . '</wp:comment_author>';
        $output .= '<wp:comment_author_email>' . $comment['author_email'] . '</wp:comment_author_email>';
        $output .= '<wp:comment_author_url>' . $comment['author_url'] . '</wp:comment_author_url>';
        $output .= '<wp:comment_author_IP>' . $comment['author_IP'] . '</wp:comment_author_IP>';
        $output .= '<wp:comment_date_gmt>' . $comment['date_gmt'] . '</wp:comment_date_gmt>';
        $output .= '<wp:comment_content><![CDATA[' . $comment['content'] . ']]></wp:comment_content>';
        $output .= '<wp:comment_approved>' . $comment['approved'] . '</wp:comment_approved>';
        $output .= '<wp:comment_parent>' . $comment['parent'] . '</wp:comment_parent>';
        $output .= '</wp:comment>';
      }
      $output .= '</item>';

      // Should change the comment status for the node?
      if ($status_change != '--') {
        $update = db_query("UPDATE {node} SET comment = %d WHERE nid = %d", $status_change, $nid);
      }
    }

    // Footer
    $output .= '  </channel>';
    $output .= '</rss>';

    // Output the XML file
    header("Content-disposition: attachment; filename=drupalcomments.xml");
    header("Content-Type: text/xml; charset=utf-8");
    print $output;
    exit;
  }
  else {
    drupal_set_message(t('No comments to export.'), 'error');
  }
}