disabling same-url-pings; cleaning up inconsistencies; fixing bug of never marking mention as done
Peter Molnar hello@petermolnar.eu
Wed, 27 Jan 2016 13:24:46 +0000
3 files changed,
67 insertions(+),
39 deletions(-)
M
receiver.php
→
receiver.php
@@ -26,7 +26,7 @@ * @return int posts per batch
* */ protected static function per_batch () { - return apply_filters( 'wp-webmention-again-receiver_per_batch', 10 ); + return apply_filters( 'wp-webmention-again-receiver_per_batch', 42 ); } /**@@ -63,35 +63,6 @@ *
*/ protected static function endpoint() { return apply_filters( 'wp-webmention-again-receiver_endpoint', 'webmention' ); - } - - /** - * mapping for comment types -> mf2 names - * - * use 'wp-webmention-again_mftypes' to filter this array - * - * @return array array of comment_type => mf2_name entries - * - */ - protected static function mftypes () { - $map = array ( - // http://indiewebcamp.com/reply - 'reply' => 'in-reply-to', - // http://indiewebcamp.com/repost - 'repost' => 'repost-of', - // http://indiewebcamp.com/like - 'like' => 'like-of', - // http://indiewebcamp.com/favorite - 'favorite' => 'favorite-of', - // http://indiewebcamp.com/bookmark - 'bookmark' => 'bookmark-of', - // http://indiewebcamp.com/rsvp - 'rsvp' => 'rsvp', - // http://indiewebcamp.com/tag - 'tag' => 'tag-of', - ); - - return apply_filters( 'wp-webmention-again_mftypes', $map ); } public function __construct() {@@ -498,8 +469,9 @@ );
return $c; } + $author_url = $source; // process author - $author_name = $author_url = $avatar = $a = false; + $author_name = $avatar = $a = false; if ( isset( $item['properties']['author'] ) ) { $a = $item['properties']['author'];@@ -525,6 +497,9 @@ break;
} } } + + if ( isset($a['url']) && ! empty( $a['url'] ) ) + $author_url = $a['url']; } // process type@@ -540,7 +515,9 @@ $c = '';
if ( isset( $item['properties']['content'] ) && isset( $item['properties']['content']['html'] ) ) $c = $item['properties']['content']['html']; if ( isset( $item['properties']['content'] ) && isset( $item['properties']['content']['value'] ) ) - $c = wp_filter_kses( $item['properties']['content']['value'] ); + $c = $item['properties']['content']['value']; + + $c = wp_filter_kses ( $c ); // REACJI $emoji = EmojiRecognizer::isSingleEmoji( $c );@@ -563,8 +540,8 @@ $name = empty( $author_name ) ? $source : $author_name;
$c = array ( 'comment_author' => $name, - 'comment_author_url' => $source, - 'comment_author_email' => '', + 'comment_author_url' => $author_url, + 'comment_author_email' => static::try_get_author_email ( $author_url ), 'comment_post_ID' => $post_id, 'comment_type' => $type, 'comment_date' => date( "Y-m-d H:i:s", $date ),@@ -667,8 +644,8 @@
// full raw response for the vote, just in case update_comment_meta( $comment_id, 'webmention_source_mf2', $raw ); - // original request - update_comment_meta( $comment_id, 'webmention_original', array( 'target' => $target, 'source' => $source) ); + update_comment_meta( $comment_id, 'webmention_source', $source ); + update_comment_meta( $comment_id, 'webmention_target', $target ); // info $r = "new comment inserted for {$post_id} as #{$comment_id}";@@ -713,6 +690,19 @@ else
$safe_alt = esc_attr( $alt ); return sprintf( '<img alt="%s" src="%s" class="avatar photo u-photo" style="width: %dpx; height: %dpx;" />', $safe_alt, $c_avatar, $size, $size ); + } + + /** + * + * + */ + public static function try_get_author_email ( $author_url ) { + $mail = ''; + + if ( stristr ( $author_url, 'facebook' ) ) + $mail = parse_url ( rtrim ( $author_url, '/'), PHP_URL_PATH ) . '@facebook.com'; + + return $mail; } }
M
sender.php
→
sender.php
@@ -26,7 +26,7 @@ * @return int posts per batch
* */ protected static function per_batch () { - return apply_filters( 'wp-webmention-again-sender_per_batch', 10 ); + return apply_filters( 'wp-webmention-again-sender_per_batch', 42 ); } /**@@ -146,6 +146,14 @@ $pung = get_pung( $post->ID );
$urls = array_diff ( $urls, $pung ); foreach ( $urls as $target ) { + + $s_domain = parse_url( $source, PHP_URL_HOST); + $t_domain = parse_url( $target, PHP_URL_HOST); + + // skip self-pings + if ( $s_domain == $t_domain ) + continue; + $r = static::queue_add ( 'out', $source, $target, $post->post_type, $post->ID ); if ( !$r )@@ -184,7 +192,7 @@
// too many retries, drop this mention and walk away if ( $send->tries >= static::retry() ) { static::debug( " this mention was tried earlier and failed too many times, drop it" ); - static::queue_del ( $send->id ); + static::queue_done ( $send->id ); continue; }
M
wp-webmention-again.php
→
wp-webmention-again.php
@@ -42,6 +42,36 @@ protected static function remote_timeout () {
return apply_filters( 'wp-webmention-again_remote_timeout', 100 ); } + + /** + * mapping for comment types -> mf2 names + * + * use 'wp-webmention-again_mftypes' to filter this array + * + * @return array array of comment_type => mf2_name entries + * + */ + protected static function mftypes () { + $map = array ( + // http://indiewebcamp.com/reply + 'reply' => 'in-reply-to', + // http://indiewebcamp.com/repost + 'repost' => 'repost-of', + // http://indiewebcamp.com/like + 'like' => 'like-of', + // http://indiewebcamp.com/favorite + 'favorite' => 'favorite-of', + // http://indiewebcamp.com/bookmark + 'bookmark' => 'bookmark-of', + // http://indiewebcamp.com/rsvp + 'rsvp' => 'rsvp', + // http://indiewebcamp.com/tag + 'tag' => 'tag-of', + ); + + return apply_filters( 'wp-webmention-again_mftypes', $map ); + } + /** * runs on plugin load */@@ -293,7 +323,7 @@
if ( empty( $note ) ) $q = $wpdb->prepare( "UPDATE `{$dbname}` SET `status` = 1 WHERE `id` = '%s'; ", $id ); else - $q = $wpdb->prepare( "UPDATE `{$dbname}` SET `status` = 1, `note`='%s' WHERE `id` = '%s'; ", $id, $node ); + $q = $wpdb->prepare( "UPDATE `{$dbname}` SET `status` = 1, `note`='%s' WHERE `id` = '%s'; ", $note, $id ); try { $req = $wpdb->query( $q );