Skip to content

Commit 8be2c3b

Browse files
Fix special characters decode and nofollow link issue
1 parent 8151cf8 commit 8be2c3b

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

includes/admin/feedzy-rss-feeds-actions.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -523,29 +523,37 @@ private function modify_links() {
523523
if ( ! feedzy_is_pro() ) {
524524
return $content;
525525
}
526+
// converts all special characters to utf-8.
527+
$content = mb_convert_encoding( $content, 'HTML-ENTITIES', 'UTF-8' );
526528

527-
$dom = new DOMDocument();
529+
$dom = new DOMDocument( '1.0', 'utf-8' );
528530
libxml_use_internal_errors( true );
529-
$dom->loadHTML( $content );
531+
$dom->loadHTML( $content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
530532
$xpath = new DOMXPath( $dom );
531-
libxml_clear_errors();
533+
libxml_clear_errors( true );
532534
// Get all anchors tags.
533535
$nodes = $xpath->query( '//a' );
534536

535-
if ( ! empty( $this->current_job->data->remove_links ) ) {
536-
foreach ( $nodes as $node ) {
537-
if ( ! empty( $this->current_job->data->remove_links ) ) {
538-
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
539-
$node->parentNode->removeChild( $node );
540-
continue;
541-
}
542-
if ( ! empty( $this->current_job->data->target ) ) {
543-
$node->setAttribute( 'target', $this->current_job->data->target );
544-
}
545-
if ( ! empty( $this->current_job->data->follow ) && 'yes' === $this->current_job->data->follow ) {
546-
$node->setAttribute( 'rel', 'nofollow' );
547-
}
537+
foreach ( $nodes as $node ) {
538+
if ( ! empty( $this->current_job->data->remove_links ) ) {
539+
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
540+
$node->parentNode->removeChild( $node );
541+
continue;
542+
}
543+
if ( ! empty( $this->current_job->data->target ) ) {
544+
$node->setAttribute( 'target', $this->current_job->data->target );
548545
}
546+
if ( ! empty( $this->current_job->data->follow ) && 'yes' === $this->current_job->data->follow ) {
547+
$node->setAttribute( 'rel', 'nofollow' );
548+
}
549+
}
550+
if ( ! empty( $this->current_job->data->follow ) && 'yes' === $this->current_job->data->follow ) {
551+
add_filter(
552+
'wp_targeted_link_rel',
553+
function() {
554+
return 'nofollow';
555+
}
556+
);
549557
}
550558
return $dom->saveHTML();
551559
}

0 commit comments

Comments
 (0)