Skip to content

Commit

Permalink
Fix special characters decode and nofollow link issue
Browse files Browse the repository at this point in the history
  • Loading branch information
girishpanchal30 committed Sep 2, 2024
1 parent 8151cf8 commit 8be2c3b
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions includes/admin/feedzy-rss-feeds-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,29 +523,37 @@ private function modify_links() {
if ( ! feedzy_is_pro() ) {
return $content;
}
// converts all special characters to utf-8.
$content = mb_convert_encoding( $content, 'HTML-ENTITIES', 'UTF-8' );

$dom = new DOMDocument();
$dom = new DOMDocument( '1.0', 'utf-8' );
libxml_use_internal_errors( true );
$dom->loadHTML( $content );
$dom->loadHTML( $content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
$xpath = new DOMXPath( $dom );
libxml_clear_errors();
libxml_clear_errors( true );
// Get all anchors tags.
$nodes = $xpath->query( '//a' );

if ( ! empty( $this->current_job->data->remove_links ) ) {
foreach ( $nodes as $node ) {
if ( ! empty( $this->current_job->data->remove_links ) ) {
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$node->parentNode->removeChild( $node );
continue;
}
if ( ! empty( $this->current_job->data->target ) ) {
$node->setAttribute( 'target', $this->current_job->data->target );
}
if ( ! empty( $this->current_job->data->follow ) && 'yes' === $this->current_job->data->follow ) {
$node->setAttribute( 'rel', 'nofollow' );
}
foreach ( $nodes as $node ) {
if ( ! empty( $this->current_job->data->remove_links ) ) {
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$node->parentNode->removeChild( $node );
continue;
}
if ( ! empty( $this->current_job->data->target ) ) {
$node->setAttribute( 'target', $this->current_job->data->target );
}
if ( ! empty( $this->current_job->data->follow ) && 'yes' === $this->current_job->data->follow ) {
$node->setAttribute( 'rel', 'nofollow' );
}
}
if ( ! empty( $this->current_job->data->follow ) && 'yes' === $this->current_job->data->follow ) {
add_filter(
'wp_targeted_link_rel',
function() {
return 'nofollow';
}
);
}
return $dom->saveHTML();
}
Expand Down

0 comments on commit 8be2c3b

Please sign in to comment.