delete queue element on ok or semi-ok

This commit is contained in:
Peter Molnar 2016-01-11 16:08:41 +00:00
parent e99ec82a76
commit 960615080b

View file

@ -381,6 +381,17 @@ class WP_WEBMENTION_AGAIN {
//add_post_meta($post->ID, static::meta_received, $m, false); //add_post_meta($post->ID, static::meta_received, $m, false);
continue; continue;
} }
elseif ($parsed === true) {
static::debug(" duplicate or something else, but this queue element has to be ignored; deleting queue entry");
delete_post_meta($post_id, static::meta_received, $m);
}
elseif (is_numeric($parsed)) {
static::debug(" all went well, we have a comment id: {$parsed}, deleting queue entry");
delete_post_meta($post_id, static::meta_received, $m);
}
else {
die("This is unexpected.");
}
static::debug(" it looks like we're done, and this webmention was added as a comment"); static::debug(" it looks like we're done, and this webmention was added as a comment");
} }
@ -454,8 +465,9 @@ class WP_WEBMENTION_AGAIN {
} }
} }
if (!empty($content)) if (!empty($content)) {
$c = static::try_parse_comment( $post_id, $source, $target, $content ); return static::try_parse_comment( $post_id, $source, $target, $content );
}
return false; return false;
} }
@ -478,10 +490,6 @@ class WP_WEBMENTION_AGAIN {
// un-arrayed // un-arrayed
if (isset($content['items']['properties']) && isset($content['items']['type'])) { if (isset($content['items']['properties']) && isset($content['items']['type'])) {
$item = $content['items']; $item = $content['items'];
if (!isset($item['type']) || ($item['type'] != 'h-entry')) {
static::debug(' no parseable h-entry found, saving as standard mention comment');
return true;
}
} }
elseif (is_array($content['items']) && !empty($content['items']['type'])) { elseif (is_array($content['items']) && !empty($content['items']['type'])) {
foreach ($content['items'] as $i) { foreach ($content['items'] as $i) {
@ -496,7 +504,19 @@ class WP_WEBMENTION_AGAIN {
if (!$item || empty($item)) { if (!$item || empty($item)) {
static::debug(' no parseable h-entry found, saving as standard mention comment'); static::debug(' no parseable h-entry found, saving as standard mention comment');
return true; $c = array (
'comment_author' => $source,
'comment_author_url' => $source,
'comment_author_email' => '',
'comment_post_ID' => $post_id,
'comment_type' => 'webmention',
'comment_date' => date("Y-m-d H:i:s"),
'comment_date_gmt' => date("Y-m-d H:i:s"),
'comment_agent' => __CLASS__,
'comment_approved' => 0,
'comment_content' => sprintf(__('This entry was webmentioned on <a href="%s">%s</a>.'), $source, $source)
);
return static::insert_comment ($post_id, $source, $target, $c, $raw );
} }
// process author // process author
@ -527,18 +547,16 @@ class WP_WEBMENTION_AGAIN {
} }
} }
if (isset($a['url']) && !empty($a['url'])) { //if (isset($a['url']) && !empty($a['url'])) {
if (is_array($a['url'])) //if (is_array($a['url']))
$author_url = array_pop($a['url']); //$author_url = array_pop($a['url']);
else //else
$author_url = $a['url']; //$author_url = $a['url'];
} //}
$author = $a;
} }
// process type // process type
$type = 'comment'; $type = 'webmention';
foreach ( static::mftypes() as $k => $mapped) { foreach ( static::mftypes() as $k => $mapped) {
if (is_array($item['properties']) && isset($item['properties'][$mapped])) if (is_array($item['properties']) && isset($item['properties'][$mapped]))
@ -570,11 +588,11 @@ class WP_WEBMENTION_AGAIN {
$date = time(); $date = time();
$name = empty($author_name) ? $source : $author_name; $name = empty($author_name) ? $source : $author_name;
$url = empty($author_url) ? $source : $author_url; //$url = empty($author_url) ? $source : $author_url;
$c = array ( $c = array (
'comment_author' => $name, 'comment_author' => $name,
'comment_author_url' => $url, 'comment_author_url' => $source,
'comment_author_email' => '', 'comment_author_email' => '',
'comment_post_ID' => $post_id, 'comment_post_ID' => $post_id,
'comment_type' => $type, 'comment_type' => $type,
@ -673,6 +691,10 @@ class WP_WEBMENTION_AGAIN {
// full raw response for the vote, just in case // full raw response for the vote, just in case
update_comment_meta( $comment_id, 'webmention_source_mf2', $raw ); update_comment_meta( $comment_id, 'webmention_source_mf2', $raw );
// full raw response for the vote, just in case
//update_comment_meta( $comment_id, 'webmention_source', $ );
// info // info
$r = "new comment inserted for {$post_id} as #{$comment_id}"; $r = "new comment inserted for {$post_id} as #{$comment_id}";
@ -753,18 +775,6 @@ class WP_WEBMENTION_AGAIN {
/** /**
* *
*/ */
public static function mfmap ( $mf2 ) {
$map = static::mftypes();
foreach ($map as $k => $mapped) {
if (is_array( $mf2) && isset($mf2[$mapped]))
return $k;
}
// fallback
return 'comment';
}
public static function mftypes () { public static function mftypes () {
$map = array ( $map = array (
// http://indiewebcamp.com/reply // http://indiewebcamp.com/reply
@ -803,16 +813,6 @@ class WP_WEBMENTION_AGAIN {
return $mf2; return $mf2;
} }
/**
*
*/
//public static function extract_urls( &$text ) {
//$matches = array();
//preg_match_all("/\b(?:http|https)\:\/\/?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.[a-zA-Z0-9\.\/\?\:@\-_=#]*/i", $text, $matches);
//$matches = $matches[0];
//return $matches;
//}
/** /**
* validates a post object if it really is a post * validates a post object if it really is a post