Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 5717197

Browse files
authored
Merge pull request #80 from dshanske/master
Use Passed Along Target and Minor Fixes
2 parents 1d065dd + e74918f commit 5717197

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

includes/class-linkbacks-handler.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,20 @@ public static function enhance( $commentdata, $comment = array(), $commentarr =
101101
$commentdata['comment_meta'] = array();
102102
}
103103

104-
// generate target
105-
$target = get_permalink( $commentdata['comment_post_ID'] );
106-
104+
// If target is not set then set based on permalink
105+
if ( ! isset( $commentdata['target'] ) ) {
106+
$commentdata['target'] = get_permalink( $commentdata['comment_post_ID'] );
107+
}
107108
// add replytocom if present
108109
if ( isset( $commentdata['comment_parent'] ) && ! empty( $commentdata['comment_parent'] ) ) {
109-
$target = add_query_arg( array( 'replytocom' => $commentdata['comment_parent'] ), $target );
110+
$commentdata['target'] = add_query_arg( array( 'replytocom' => $commentdata['comment_parent'] ), $commentdata['target'] );
110111
}
111112

112113
// add source url as comment-meta
113114
$commentdata['comment_meta']['semantic_linkbacks_source'] = esc_url_raw( $commentdata['comment_author_url'] );
114115

115116
// adds a hook to enable some other semantic handlers for example schema.org
116-
$commentdata = apply_filters( 'semantic_linkbacks_commentdata', $commentdata, $target );
117+
$commentdata = apply_filters( 'semantic_linkbacks_commentdata', $commentdata );
117118

118119
// remove "webmention" comment-type if $type is "reply"
119120
if ( isset( $commentdata['comment_meta']['semantic_linkbacks_type'] ) ) {
@@ -479,7 +480,7 @@ public static function get_avatar_comment_types( $types ) {
479480
$types[] = 'trackback';
480481
$types[] = 'webmention';
481482

482-
return $types;
483+
return array_unique( $types );
483484
}
484485

485486
}

includes/class-linkbacks-mf2-handler.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,10 @@ public static function get_rel_mapper() {
100100
* generate the comment data from the microformatted content
101101
*
102102
* @param WP_Comment $commentdata the comment object
103-
* @param string $target the target url
104103
*
105104
* @return array
106105
*/
107-
public static function generate_commentdata( $commentdata, $target ) {
106+
public static function generate_commentdata( $commentdata ) {
108107
global $wpdb;
109108

110109
// add source
@@ -122,7 +121,7 @@ public static function generate_commentdata( $commentdata, $target ) {
122121
}
123122

124123
// get the entry of interest
125-
$entry = self::get_representative_entry( $entries, $target );
124+
$entry = self::get_representative_entry( $entries, $commentdata['target'] );
126125

127126
if ( empty( $entry ) ) {
128127
return array();
@@ -191,7 +190,7 @@ public static function generate_commentdata( $commentdata, $target ) {
191190
$commentdata['comment_meta']['semantic_linkbacks_type'] = wp_slash( 'rsvp:' . $properties['rsvp'][0] );
192191
} else {
193192
// get post type
194-
$commentdata['comment_meta']['semantic_linkbacks_type'] = wp_slash( self::get_entry_type( $target, $entry, $mf_array ) );
193+
$commentdata['comment_meta']['semantic_linkbacks_type'] = wp_slash( self::get_entry_type( $commentdata['target'], $entry, $mf_array ) );
195194
}
196195

197196
return $commentdata;
@@ -406,6 +405,9 @@ public static function check_mf_attr( $key, $node ) {
406405
* @return boolean
407406
*/
408407
public static function compare_urls( $needle, $haystack, $schemeless = true ) {
408+
if ( ! is_string( $needle ) || ! is_array( $haystack ) ) {
409+
return false;
410+
}
409411
if ( true === $schemeless ) {
410412
// remove url-scheme
411413
$schemeless_target = preg_replace( '/^https?:\/\//i', '', $needle );

0 commit comments

Comments
 (0)