@@ -400,13 +400,18 @@ public function find_representative_hcard( $mf_array, $url ) {
400
400
*
401
401
* @return array the h-entry node or false
402
402
*/
403
- public function find_representative_item ( $ mf_array , $ target ) {
403
+ public function find_representative_item ( $ mf_array , $ target, $ ignore_hcards = true ) {
404
404
$ items = $ this ->get_items ( $ mf_array );
405
405
if ( ! is_array ( $ items ) || empty ( $ items ) ) {
406
406
return false ;
407
407
}
408
408
409
409
foreach ( $ items as $ item ) {
410
+ // we do not want to check h-cards as main items as they are not the content
411
+ if ( $ this ->is_type ( $ item , 'h-card ' ) && $ ignore_hcards ) {
412
+ continue ;
413
+ }
414
+
410
415
// check properties
411
416
if ( isset ( $ item ['properties ' ] ) ) {
412
417
// check properties if target urls was mentioned
@@ -468,13 +473,13 @@ public function find_representative_item( $mf_array, $target ) {
468
473
'content ' === $ key &&
469
474
! empty ( $ value ['html ' ] ) &&
470
475
is_string ( $ value ['html ' ] ) &&
471
- preg_match_all ( '/<a[^>]+ ? ' . preg_quote ( $ target , '/ ' ) . '[^>]*>([^>]+?)<\/a> /i ' , $ value ['html ' ], $ context )
476
+ preg_match_all ( '/<a\b [^>]*href\s*=\s*[" \' ] ? ' . preg_quote ( $ target , '/ ' ) . '[" \' ] /i ' , $ value ['html ' ], $ context )
472
477
) {
473
478
return $ item ;
474
479
} elseif (
475
480
'summary ' === $ key &&
476
481
is_string ( $ value ) &&
477
- preg_match_all ( '/<a[^>]+ ? ' . preg_quote ( $ target , '/ ' ) . '[^>]*>([^>]+?)<\/a> /i ' , $ value , $ context )
482
+ preg_match_all ( '/<a\b [^>]*href\s*=\s*[" \' ] ? ' . preg_quote ( $ target , '/ ' ) . '[" \' ] /i ' , $ value , $ context )
478
483
) {
479
484
return $ item ;
480
485
}
@@ -497,6 +502,10 @@ public function find_representative_item( $mf_array, $target ) {
497
502
*/
498
503
protected function get_representative_item ( $ mf_array , $ url ) {
499
504
$ item = $ this ->find_representative_item ( $ mf_array , $ url );
505
+ if ( empty ( $ item ) || ! is_array ( $ item ) ) {
506
+ $ item = $ this ->find_representative_item ( $ mf_array , $ url , false );
507
+ }
508
+
500
509
if ( empty ( $ item ) || ! is_array ( $ item ) ) {
501
510
return array ();
502
511
}
0 commit comments