0.6: log goes to log, not db; archive.org trigger for target or source urls
Peter Molnar hello@petermolnar.eu
Sat, 09 Jul 2016 20:23:06 +0000
7 files changed,
55 insertions(+),
13 deletions(-)
M
readme.txt
→
readme.txt
@@ -3,11 +3,10 @@ Contributors: cadeyrn
Donate link: https://paypal.me/petermolnar/3 Tags: webmention, pingback, indieweb Requires at least: 4.3 -Tested up to: 4.4.2 -Stable tag: 0.5.1 +Tested up to: 4.5.3 +Stable tag: 0.6 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html -Required minimum PHP version: 5.3 Alternative [Webmentions](http://indiewebcamp.com/webmention-spec) plugin for WordPress@@ -32,6 +31,14 @@
* every A. indicates BIG changes. * every .B version indicates new features. * every ..C indicates bugfixes for A.B version. + += 0.6 = +*2016-07-09* + +* converted in-database queue to real queue +* keeping incoming and outgoing webmentions in webmentions.log in the plugin directory +* trigger archive.org save of source in case of incoming and target in case of outgoing webmentions + = 0.5.1 = *2016-03-08*
M
receiver.php
→
receiver.php
@@ -273,6 +273,9 @@ // queue here, the remote check will be async
//$r = static::queue_receive( $source, $target, $post_id ); $r = static::queue_add( 'in', $source, $target, 'post', $post_id ); + // trigger archive call + wp_schedule_single_event( time() + 120, 'trigger_archive_org', array ( 'url' => $source ) ); + if ( true == $r ) { status_header( 202 ); echo 'Webmention accepted in the queue.';@@ -324,14 +327,14 @@ static::queue_inc ( $received->id );
if ( ! static::is_post( $post ) ) { static::debug( " no post found for this mention, try again later, who knows?", 6); - //static::queue_del ( $received->id ); + static::queue_del ( $received->id ); continue; } // too many retries, drop this mention and walk away if ( $received->tries >= static::retry() ) { static::debug( " this mention was tried earlier and failed too many times, drop it", 5); - //static::queue_del ( $received->id ); + static::queue_del ( $received->id ); continue; }@@ -349,12 +352,11 @@ $ins = static::insert_comment ( $post_id, $received->source, $received->target, $remote, $c );
if ( true === $ins ) { static::debug( " duplicate (or something similar): this queue element has to be ignored; deleting queue entry", 5); - //static::queue_del ( $received->id ); - static::queue_done ( $received->id ); + static::queue_del ( $received->id ); } elseif ( is_numeric( $ins ) ) { static::debug( " all went well, we have a comment id: {$ins}, deleting queue entry", 5); - static::queue_done ( $received->id ); + static::queue_del ( $received->id ); } else { static::debug( "This is unexpected. Try again.", 6);
M
sender.php
→
sender.php
@@ -216,7 +216,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", 5); - static::queue_done ( $send->id ); + static::queue_del( $send->id ); continue; }@@ -238,7 +238,7 @@ //add_post_meta ( $send->object_id, static::pung, $send->target, false );
//add_ping( $send->object_id, $send->target ); //} - static::queue_done ( $send->id, $s ); + static::queue_del ( $send->id ); } } }@@ -267,7 +267,10 @@ parse_url( $source, PHP_URL_HOST ) == parse_url( $target, PHP_URL_HOST )
) { static::debug("Refusing to selfping the self domain", 6); return false; - } + } + + // trigger archive call here + wp_schedule_single_event( time() + 120, 'trigger_archive_org', array ( 'url' => $target ) ); // discover the webmention endpoint $webmention_server_url = static::discover_endpoint( $target );
M
wp-webmention-again.php
→
wp-webmention-again.php
@@ -3,11 +3,10 @@ /*
Plugin Name: wp-webmention-again Plugin URI: https://github.com/petermolnar/wp-webmention-again Description: -Version: 0.5.1 +Version: 0.6 Author: Peter Molnar <hello@petermolnar.eu> Author URI: http://petermolnar.eu/ License: GPLv3 -Required minimum PHP version: 5.3 */ if ( ! class_exists( 'WP_Webmention_Again' ) ):@@ -29,6 +28,8 @@ // WP cache expiration seconds
const expire = 10; // queue & history table name const tablename = 'webmentions'; + + const logfile = __DIR__ . '/webmentions.log'; /** * regular cron interval for processing incoming@@ -87,6 +88,8 @@ register_deactivation_hook( __FILE__ , array( __CLASS__ , 'plugin_deactivate' ) );
// extend current cron schedules with our entry add_filter( 'cron_schedules', array(&$this, 'add_cron_schedule' ) ); + + add_action( 'trigger_archive_org', array( &$this, 'archive' ) ); static::lookfordeleted();@@ -265,6 +268,8 @@ }
catch (Exception $e) { static::debug('Something went wrong: ' . $e->getMessage(), 4); } + + static::log ( $direction, $source, $target ); return $wpdb->insert_id; }@@ -707,6 +712,30 @@ if (isset($caller['class']))
$parent = $caller['class'] . '::' . $parent; return error_log( "{$parent}: {$message}" ); + } + + + /** + */ + public static function log( $direction, $source, $target, $object, $object_id, $epoch ) { + $date = date("c"); + $logmsg = "{$date} {$direction} {$source} {$target}\n"; + + file_put_contents ( static::logfile , $logmsg, FILE_APPEND|LOCK_EX ); + } + + /** + * + */ + public static function archive( $url ) { + $args = array( + 'timeout' => 60, + 'redirection' => 5, + 'httpversion' => '1.1', + 'user-agent' => 'Lynx/2.8.9dev.1 libwww-FM/2.14 SSL-MM/1.4.1', + ); + + return wp_remote_get( 'https://web.archive.org/save/' . $url ); }