Skip to content

Commit

Permalink
Use DOMDocument's CDATA generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanvalentin committed Jan 8, 2018
1 parent dffca0a commit 6a6e49c
Showing 1 changed file with 21 additions and 48 deletions.
69 changes: 21 additions & 48 deletions disqus/rest-api/class-disqus-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,24 +737,6 @@ private function log_sync_message( $message ) {
update_option( 'disqus_last_sync_message', $message . ': ' . date( 'Y-m-d g:i a', time() ) );
}

/**
* Outputs a string in a CDATA tag.
*
* @since 3.0
* @access private
* @param string $str The string to wrap in CDATA tags.
* @return string The wrapped CDATA string.
*/
private function format_wxr_cdata( $str ) {
if ( seems_utf8( $str ) === false ) {
$str = utf8_encode( $str );
}

$str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';

return $str;
}

/**
* Outputs a list of comments to a WXR file for uploading to the Disqus importer.
*
Expand Down Expand Up @@ -836,30 +818,25 @@ private function generate_export_wxr( $post, $comments ) {
mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true, $post ), false )
)
);
$item->appendChild(
$xml->createElement(
'dc:creator',
$this->format_wxr_cdata( $post_author->display_name )
)
);

$author_name_cdata = $xml->createCDATASection( $post_author->display_name );
$author_name_element = $xml->createElement( 'dc:creator' );
$author_name_element->appendChild( $author_name_cdata );
$item->appendChild( $author_name_element );

$guid = $xml->createElement( 'guid', $post->guid );
$guid->setAttribute( 'isPermalink', 'false' );
$item->appendChild( $guid );

$item->appendChild(
$xml->createElement(
'content:encoded',
$this->format_wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) )
)
);
$post_content_cdata = $xml->createCDATASection( apply_filters( 'the_content_export', $post->post_content ) );
$post_content_element = $xml->createElement( 'content:encoded' );
$post_content_element->appendChild( $post_content_cdata );
$item->appendChild($post_content_element);

$item->appendChild(
$xml->createElement(
'dsq:thread_identifier',
$this->format_wxr_cdata( $post->ID . ' ' . $post->guid )
)
);
$identifier_cdata = $xml->createCDATASection( $post->ID . ' ' . $post->guid );
$identifier_element = $xml->createElement( 'dsq:thread_identifier' );
$identifier_element->appendChild( $identifier_cdata );
$item->appendChild( $identifier_element );

$item->appendChild(
$xml->createElement(
Expand Down Expand Up @@ -893,12 +870,10 @@ private function generate_export_wxr( $post, $comments ) {
)
);

$wpcomment->appendChild(
$xml->createElement(
'wp:comment_author',
$this->format_wxr_cdata( $c->comment_author )
)
);
$comment_author_name_cdata = $xml->createCDATASection( $c->comment_author );
$comment_author_name_element = $xml->createElement( 'wp:comment_author' );
$comment_author_name_element->appendChild( $comment_author_name_cdata );
$wpcomment->appendChild( $comment_author_name_element );

$wpcomment->appendChild(
$xml->createElement(
Expand Down Expand Up @@ -935,12 +910,10 @@ private function generate_export_wxr( $post, $comments ) {
)
);

$wpcomment->appendChild(
$xml->createElement(
'wp:comment_content',
$this->format_wxr_cdata( $c->comment_content )
)
);
$comment_content_cdata = $xml->createCDATASection( $c->comment_content );
$comment_content_element = $xml->createElement( 'wp:comment_content' );
$comment_content_element->appendChild( $comment_content_cdata );
$wpcomment->appendChild( $comment_content_element );

$wpcomment->appendChild(
$xml->createElement(
Expand Down

0 comments on commit 6a6e49c

Please sign in to comment.