0.6: log goes to log, not db; archive.org trigger for target or source urls

This commit is contained in:
Peter Molnar 2016-07-09 20:23:06 +00:00
parent 3ed6606fab
commit b1957a4920
7 changed files with 55 additions and 13 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
webmentions.log

View file

@ -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
@ -33,6 +32,14 @@ Version numbering logic:
* 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*

View file

@ -273,6 +273,9 @@ class WP_Webmention_Again_Receiver extends WP_Webmention_Again {
//$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 @@ class WP_Webmention_Again_Receiver extends WP_Webmention_Again {
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 @@ class WP_Webmention_Again_Receiver extends WP_Webmention_Again {
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);

View file

@ -216,7 +216,7 @@ class WP_Webmention_Again_Sender extends WP_Webmention_Again {
// 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 @@ class WP_Webmention_Again_Sender extends WP_Webmention_Again {
//add_ping( $send->object_id, $send->target );
//}
static::queue_done ( $send->id, $s );
static::queue_del ( $send->id );
}
}
}
@ -267,7 +267,10 @@ class WP_Webmention_Again_Sender extends WP_Webmention_Again {
) {
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 );

0
vendor/mf2/mf2/bin/fetch-mf2 vendored Executable file → Normal file
View file

0
vendor/mf2/mf2/bin/parse-mf2 vendored Executable file → Normal file
View file

View file

@ -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' ) ):
@ -30,6 +29,8 @@ class WP_Webmention_Again {
// queue & history table name
const tablename = 'webmentions';
const logfile = __DIR__ . '/webmentions.log';
/**
* regular cron interval for processing incoming
*
@ -88,6 +89,8 @@ class WP_Webmention_Again {
// 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();
}
@ -266,6 +269,8 @@ class WP_Webmention_Again {
static::debug('Something went wrong: ' . $e->getMessage(), 4);
}
static::log ( $direction, $source, $target );
return $wpdb->insert_id;
}
@ -710,6 +715,30 @@ class WP_Webmention_Again {
}
/**
*/
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 );
}
}
require ( __DIR__ . '/sender.php' );