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

Commit 08d330f

Browse files
authored
Merge branch 'master' into issue/99
2 parents b0519b5 + dba357c commit 08d330f

File tree

7 files changed

+128
-64
lines changed

7 files changed

+128
-64
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
**Contributors:** pfefferle, dshanske
33
**Donate link:** http://14101978.de
44
**Tags:** webmention, pingback, trackback, linkback, microformats, comments, indieweb
5-
**Requires at least:** 4.7
5+
**Requires at least:** 4.7.1
66
**Tested up to:** 4.8
7-
**Stable tag:** 3.4.0
7+
**Stable tag:** 3.4.1
88
**License:** MIT
99
**License URI:** http://opensource.org/licenses/MIT
1010

@@ -53,6 +53,13 @@ The Webmention and Pingback logos are made by [Aaron Parecki](http://aaronpareck
5353

5454
Project actively developed on Github at [pfefferle/wordpress-semantic-linkbacks](https://github.com/pfefferle/wordpress-semantic-linkbacks). Please file support issues there.
5555

56+
### 3.4.1 ###
57+
* Abstract out linkback retrieval functions to allow for easier changes in future
58+
* Fix retrieval issue
59+
* Remove merge and compatibility function creating double slashing due update in 4.7.1
60+
* Replace blacklist for properties with whitelist for select properties
61+
* Update avatar function to not override if user_id is set on assumption local overrides remote
62+
5663
### 3.4.0 ###
5764

5865
* Fix Tests and Error in Authorship

includes/class-linkbacks-handler.php

Lines changed: 83 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ public static function register_meta() {
8181
* Update an Enhanced Comment
8282
*/
8383
public static function enhance( $commentdata, $comment = array(), $commentarr = array() ) {
84-
if ( ! empty( $commentarr ) ) {
85-
// add pre-processed data from, for example the Webmention plugin
86-
$commentdata = array_merge( $commentdata, $commentarr );
87-
}
88-
8984
// check if comment is a linkback
9085
if ( ! in_array( $commentdata['comment_type'], array( 'webmention', 'pingback', 'trackback' ) ) ) {
9186
return $commentdata;
@@ -239,11 +234,14 @@ public static function get_post_format_strings() {
239234
/**
240235
* Return correct URL
241236
*
242-
* @param WP_Comment $comment the comment object
237+
* @param WP_Comment|int $comment the comment object or comment ID
243238
*
244239
* @return string the URL
245240
*/
246-
public static function get_url( $comment = null ) {
241+
public static function get_url( $comment ) {
242+
if ( is_numeric( $comment ) ) {
243+
$comment = get_comment( $comment );
244+
}
247245
// get canonical url...
248246
$semantic_linkbacks_canonical = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_canonical', true );
249247
// ...or fall back to source
@@ -258,6 +256,52 @@ public static function get_url( $comment = null ) {
258256
return $semantic_linkbacks_canonical;
259257
}
260258

259+
/**
260+
* Return canonical URL
261+
*
262+
* @param int|WP_Comment $comment Comment
263+
*
264+
* @return string the URL
265+
*/
266+
public static function get_canonical_url( $comment ) {
267+
if ( is_numeric( $comment ) ) {
268+
$comment = get_comment( $comment );
269+
}
270+
// get canonical url...
271+
return get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_canonical', true );
272+
}
273+
274+
/**
275+
* Return type
276+
*
277+
* @param int|WP_Comment $comment Comment
278+
*
279+
* @return string the type
280+
*/
281+
public static function get_type( $comment ) {
282+
if ( is_numeric( $comment ) ) {
283+
$comment = get_comment( $comment );
284+
}
285+
// get type...
286+
return get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_type', true );
287+
}
288+
289+
290+
/**
291+
* Return author URL
292+
*
293+
* @param int|WP_Comment $comment Comment
294+
*
295+
* @return string the URL
296+
*/
297+
public static function get_author_url( $comment ) {
298+
if ( is_numeric( $comment ) ) {
299+
$comment = get_comment( $comment );
300+
}
301+
// get author URL...
302+
return get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_author_url', true );
303+
}
304+
261305
/**
262306
* Add cite to "reply"s
263307
*
@@ -314,7 +358,7 @@ public static function comment_text_excerpt( $text, $comment = null, $args = arr
314358
return $text;
315359
}
316360

317-
$semantic_linkbacks_type = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_type', true );
361+
$semantic_linkbacks_type = self::get_type( $comment );
318362

319363
// only change text for pingbacks/trackbacks/webmentions
320364
if ( '' == $comment->comment_type ||
@@ -350,7 +394,7 @@ public static function comment_text_excerpt( $text, $comment = null, $args = arr
350394
$url = self::get_url( $comment );
351395

352396
// parse host
353-
$host = parse_url( $url, PHP_URL_HOST );
397+
$host = wp_parse_url( $url, PHP_URL_HOST );
354398
// strip leading www, if any
355399
$host = preg_replace( '/^www\./', '', $host );
356400

@@ -362,6 +406,21 @@ public static function comment_text_excerpt( $text, $comment = null, $args = arr
362406
return apply_filters( 'semantic_linkbacks_excerpt', $text );
363407
}
364408

409+
/**
410+
* Function to retrieve Avatar URL if stored in meta
411+
*
412+
*
413+
* @param int|WP_Comment $comment
414+
*
415+
* @return string $url
416+
*/
417+
public static function get_avatar_url( $comment ) {
418+
if ( is_numeric( $comment ) ) {
419+
$comment = get_comment( $comment );
420+
}
421+
return get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_avatar', true );
422+
}
423+
365424
/**
366425
* Replaces the default avatar with the WebMention uf2 photo
367426
*
@@ -371,26 +430,25 @@ public static function comment_text_excerpt( $text, $comment = null, $args = arr
371430
* @return array $args
372431
*/
373432
public static function pre_get_avatar_data( $args, $id_or_email ) {
374-
if ( ! isset( $args['class'] ) ) {
375-
$args['class'] = array( 'u-photo' );
376-
} else {
377-
$args['class'][] = 'u-photo';
378-
}
379-
380-
if ( ! is_object( $id_or_email ) ||
433+
if ( ! $id_or_email instanceof WP_Comment ||
381434
! isset( $id_or_email->comment_type ) ||
382-
! get_comment_meta( $id_or_email->comment_ID, 'semantic_linkbacks_avatar', true ) ) {
383-
return $args;
435+
$id_or_email->user_id ) {
436+
return $args;
384437
}
385438

386439
// check if comment has an avatar
387-
$avatar = get_comment_meta( $id_or_email->comment_ID, 'semantic_linkbacks_avatar', true );
440+
$avatar = self::get_avatar_url( $id_or_email->comment_ID );
388441

389442
if ( $avatar ) {
443+
if ( ! isset( $args['class'] ) ) {
444+
$args['class'] = array( 'u-photo' );
445+
} else {
446+
$args['class'][] = 'u-photo';
447+
$args['class'] = array_unique( $args['class'] );
448+
}
390449
$args['url'] = $avatar;
391450
$args['class'][] = 'avatar-semantic-linkbacks';
392451
}
393-
394452
return $args;
395453
}
396454

@@ -404,7 +462,7 @@ public static function pre_get_avatar_data( $args, $id_or_email ) {
404462
* @return string the linkback source or the original comment link
405463
*/
406464
public static function get_comment_link( $link, $comment, $args ) {
407-
$semantic_linkbacks_canonical = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_canonical', true );
465+
$semantic_linkbacks_canonical = self::get_canonical_url( $comment );
408466

409467
if ( is_singular() && $semantic_linkbacks_canonical ) {
410468
return $semantic_linkbacks_canonical;
@@ -423,7 +481,9 @@ public static function get_comment_link( $link, $comment, $args ) {
423481
* @return string the replaced/parsed author url or the original comment link
424482
*/
425483
public static function get_comment_author_url( $url, $id, $comment ) {
426-
if ( $author_url = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_author_url', true ) ) {
484+
$author_url = self::get_author_url( $comment );
485+
486+
if ( $author_url ) {
427487
return $author_url;
428488
}
429489

@@ -456,7 +516,7 @@ public static function comment_class( $classes, $class, $comment_id, $post_id )
456516
'rsvp:tracking' => array( 'h-as-rsvp' ),
457517
);
458518

459-
$semantic_linkbacks_type = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_type', true );
519+
$semantic_linkbacks_type = self::get_type( $comment );
460520

461521
// check the comment type
462522
if ( $semantic_linkbacks_type && isset( $class_mapping[ $semantic_linkbacks_type ] ) ) {

includes/class-linkbacks-mf2-handler.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public static function generate_commentdata( $commentdata ) {
151151
} elseif ( isset( $properties['updated'] ) ) {
152152
$commentdata['comment_date'] = self::convert_time( $properties['updated'] );
153153
}
154+
$commentdata['comment_date_gmt'] = get_gmt_from_date( $commentdata['comment_date'] );
154155

155156
$author = null;
156157

@@ -246,10 +247,29 @@ public static function generate_commentdata( $commentdata ) {
246247
// get post type
247248
$commentdata['comment_meta']['semantic_linkbacks_type'] = wp_slash( self::get_entry_type( $commentdata['target'], $entry, $mf_array ) );
248249
}
249-
$blacklist = array( 'name', 'content', 'summary', 'published', 'updated', 'type', 'url', 'comment', 'bridgy-omit-link' );
250-
$blacklist = apply_filters( 'semantic_linkbacks_mf2_props_blacklist', $blacklist );
250+
251+
$whitelist = array(
252+
'author',
253+
'location',
254+
'syndication',
255+
'uid',
256+
'video',
257+
'audio',
258+
'photo',
259+
'featured',
260+
);
261+
262+
// Add in supported properties
263+
$whitelist = array_merge( $whitelist, array_keys( self::get_class_mapper() ) );
264+
$whitelist = apply_filters( 'semantic_linkbacks_mf2_props_whitelist', $whitelist );
251265
foreach ( $properties as $key => $value ) {
252-
if ( ! in_array( $key, $blacklist ) ) {
266+
if ( in_array( $key, $whitelist ) ) {
267+
if ( self::is_url( $value ) ) {
268+
$value = esc_url_raw( $value );
269+
}
270+
if ( is_string( $value ) ) {
271+
$value = wp_kses_post( $value );
272+
}
253273
$commentdata['comment_meta'][ 'mf2_' . $key ] = $value;
254274
}
255275
}

includes/compatibility.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1 @@
11
<?php
2-
/**
3-
* A compatibility function to slice the comment array
4-
*
5-
* @see https://github.com/pfefferle/wordpress-semantic-linkbacks/pull/73#discussion_r94093790
6-
*
7-
* @param array $commentdata the enriched comment array
8-
*
9-
* @return array the sliced comment array
10-
*/
11-
function semantic_linkbacks_slice_comments_array( $commentdata ) {
12-
$keys = array(
13-
'comment_post_ID',
14-
'comment_content',
15-
'comment_author',
16-
'comment_author_email',
17-
'comment_approved',
18-
'comment_karma',
19-
'comment_author_url',
20-
'comment_date',
21-
'comment_date_gmt',
22-
'comment_type',
23-
'comment_parent',
24-
'user_id',
25-
'comment_agent',
26-
'comment_author_IP',
27-
);
28-
29-
$commentdata = wp_array_slice_assoc( $commentdata, $keys );
30-
31-
return wp_unslash( $commentdata );
32-
}
33-
add_filter( 'wp_update_comment_data', 'semantic_linkbacks_slice_comments_array', 99, 1 );

includes/functions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ function get_linkbacks_number( $type = null, $post_id = 0 ) {
3434
*
3535
* @param string $type the comment type
3636
* @param int $post_id the id of the post
37+
* @param string $order the order of the retrieved comments, ASC or DESC (default)
3738
*
3839
* @return the matching linkback "comments"
3940
*/
40-
function get_linkbacks( $type = null, $post_id = 0 ) {
41+
function get_linkbacks( $type = null, $post_id = 0, $order = 'DESC' ) {
4142
$args = array(
4243
'post_id' => $post_id,
4344
'status' => 'approve',
45+
'order' => $order,
4446
);
4547

4648
if ( $type ) { // use type if set

readme.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
Contributors: pfefferle, dshanske
33
Donate link: http://14101978.de
44
Tags: webmention, pingback, trackback, linkback, microformats, comments, indieweb
5-
Requires at least: 4.7
5+
Requires at least: 4.7.1
66
Tested up to: 4.8
7-
Stable tag: 3.4.0
7+
Stable tag: 3.4.1
88
License: MIT
99
License URI: http://opensource.org/licenses/MIT
1010

@@ -53,6 +53,13 @@ The Webmention and Pingback logos are made by [Aaron Parecki](http://aaronpareck
5353

5454
Project actively developed on Github at [pfefferle/wordpress-semantic-linkbacks](https://github.com/pfefferle/wordpress-semantic-linkbacks). Please file support issues there.
5555

56+
= 3.4.1 =
57+
* Abstract out linkback retrieval functions to allow for easier changes in future
58+
* Fix retrieval issue
59+
* Remove merge and compatibility function creating double slashing due update in 4.7.1
60+
* Replace blacklist for properties with whitelist for select properties
61+
* Update avatar function to not override if user_id is set on assumption local overrides remote
62+
5663
= 3.4.0 =
5764

5865
* Fix Tests and Error in Authorship

semantic-linkbacks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Semantic Linkbacks for WebMentions, Trackbacks and Pingbacks
66
* Author: Matthias Pfefferle
77
* Author URI: https://notiz.blog/
8-
* Version: 3.4.0
8+
* Version: 3.4.1
99
* License: MIT
1010
* License URI: http://opensource.org/licenses/MIT
1111
* Text Domain: semantic-linkbacks

0 commit comments

Comments
 (0)