Skip to content

Commit

Permalink
Merge pull request #459 from pfefferle/458-php-fatal-error-uncaught-t…
Browse files Browse the repository at this point in the history
…ypeerror-cannot-access-offset-of-type-string

fix fatal error
  • Loading branch information
pfefferle authored Feb 20, 2024
2 parents 8299a62 + 837570d commit 0019ed7
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions includes/Handler/class-mf2.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,20 @@ public function find_representative_item( $mf_array, $target ) {
}
// Make sure this is a numeric array before checking this.
if ( wp_is_numeric_array( $obj_values ) ) {
$obj_value = current( $obj_values );
// check content for the link
if ( 'content' === $obj_key &&
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $obj_values[0]['html'], $context ) ) {
if (
'content' === $obj_key &&
! empty( $obj_value['html'] ) &&
is_string( $obj_value['html'] ) &&
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $obj_value['html'], $context )
) {
return $item;
} elseif ( 'summary' === $obj_key &&
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $obj_values[0], $context ) ) {
} elseif (
'summary' === $obj_key &&
is_string( $obj_value ) &&
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $obj_value, $context )
) {
return $item;
}
}
Expand All @@ -444,13 +452,23 @@ public function find_representative_item( $mf_array, $target ) {

// check properties if target urls was mentioned
foreach ( $item['properties'] as $key => $values ) {
// check content for the link
if ( 'content' === $key &&
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $values[0]['html'], $context ) ) {
return $item;
} elseif ( 'summary' === $key &&
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $values[0], $context ) ) {
return $item;
if ( wp_is_numeric_array( $values ) ) {
$value = current( $values );
// check content for the link
if (
'content' === $key &&
! empty( $value['html'] ) &&
is_string( $value['html'] ) &&
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $value['html'], $context )
) {
return $item;
} elseif (
'summary' === $key &&
is_string( $value ) &&
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $value, $context )
) {
return $item;
}
}
}
}
Expand Down

0 comments on commit 0019ed7

Please sign in to comment.