@@ -523,29 +523,37 @@ private function modify_links() {
523
523
if ( ! feedzy_is_pro () ) {
524
524
return $ content ;
525
525
}
526
+ // converts all special characters to utf-8.
527
+ $ content = mb_convert_encoding ( $ content , 'HTML-ENTITIES ' , 'UTF-8 ' );
526
528
527
- $ dom = new DOMDocument ();
529
+ $ dom = new DOMDocument ( ' 1.0 ' , ' utf-8 ' );
528
530
libxml_use_internal_errors ( true );
529
- $ dom ->loadHTML ( $ content );
531
+ $ dom ->loadHTML ( $ content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
530
532
$ xpath = new DOMXPath ( $ dom );
531
- libxml_clear_errors ();
533
+ libxml_clear_errors ( true );
532
534
// Get all anchors tags.
533
535
$ nodes = $ xpath ->query ( '//a ' );
534
536
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 );
548
545
}
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
+ );
549
557
}
550
558
return $ dom ->saveHTML ();
551
559
}
0 commit comments