|
@ -67,6 +67,7 @@ class Webmention { |
|
|
$payload['http_body'] = $raw; |
|
|
$payload['http_body'] = $raw; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
echo "Sending result to callback URL: $webmention->callback\n"; |
|
|
return self::$http->post($webmention->callback, $payload); |
|
|
return self::$http->post($webmention->callback, $payload); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -79,6 +80,8 @@ class Webmention { |
|
|
echo 'Webmention '.$id.' was not found'."\n"; |
|
|
echo 'Webmention '.$id.' was not found'."\n"; |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
echo "Processing webmention $id from ".$webmention->source."\n"; |
|
|
|
|
|
|
|
|
if(!$client) |
|
|
if(!$client) |
|
|
$client = new MentionClient(); |
|
|
$client = new MentionClient(); |
|
@ -88,25 +91,35 @@ class Webmention { |
|
|
|
|
|
|
|
|
self::$http = $http; |
|
|
self::$http = $http; |
|
|
|
|
|
|
|
|
|
|
|
echo "Finding webmention endpoint for $webmention->target\n"; |
|
|
|
|
|
|
|
|
// Discover the webmention or pingback endpoint
|
|
|
// Discover the webmention or pingback endpoint
|
|
|
$endpoint = $client->discoverWebmentionEndpoint($webmention->target); |
|
|
$endpoint = $client->discoverWebmentionEndpoint($webmention->target); |
|
|
|
|
|
|
|
|
if(!$endpoint) { |
|
|
if(!$endpoint) { |
|
|
|
|
|
echo "No webmention endpoint, checking for pingback\n"; |
|
|
|
|
|
|
|
|
// If no webmention endpoint found, try to send a pingback
|
|
|
// If no webmention endpoint found, try to send a pingback
|
|
|
$pingbackEndpoint = $client->discoverPingbackEndpoint($webmention->target); |
|
|
$pingbackEndpoint = $client->discoverPingbackEndpoint($webmention->target); |
|
|
|
|
|
|
|
|
// If no pingback endpoint was found, we can't do anything else
|
|
|
// If no pingback endpoint was found, we can't do anything else
|
|
|
if(!$pingbackEndpoint) { |
|
|
if(!$pingbackEndpoint) { |
|
|
|
|
|
echo "No webmention or pingback endpoint found\n"; |
|
|
return self::updateStatus($webmention, null, 'not_supported'); |
|
|
return self::updateStatus($webmention, null, 'not_supported'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
echo "Found pingback endpoint $pingbackEndpoint\n"; |
|
|
$webmention->pingback_endpoint = $pingbackEndpoint; |
|
|
$webmention->pingback_endpoint = $pingbackEndpoint; |
|
|
$webmention->save(); |
|
|
$webmention->save(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "Sending pingback now...\n"; |
|
|
$success = $client->sendPingbackToEndpoint($pingbackEndpoint, $webmention->source, $webmention->target); |
|
|
$success = $client->sendPingbackToEndpoint($pingbackEndpoint, $webmention->source, $webmention->target); |
|
|
|
|
|
echo "Result: ".($success?'accepted':'error')."\n"; |
|
|
return self::updateStatus($webmention, null, ($success ? 'accepted' : 'error')); |
|
|
return self::updateStatus($webmention, null, ($success ? 'accepted' : 'error')); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
echo "Found webmention endpoint $endpoint\n"; |
|
|
|
|
|
|
|
|
// There is a webmention endpoint, send the webmention now
|
|
|
// There is a webmention endpoint, send the webmention now
|
|
|
|
|
|
|
|
|
$webmention->webmention_endpoint = $endpoint; |
|
|
$webmention->webmention_endpoint = $endpoint; |
|
@ -121,8 +134,13 @@ class Webmention { |
|
|
if($webmention->vouch) { |
|
|
if($webmention->vouch) { |
|
|
$params['vouch'] = $webmention->vouch; |
|
|
$params['vouch'] = $webmention->vouch; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
echo "Sending webmention now...\n"; |
|
|
|
|
|
|
|
|
$response = $client->sendWebmentionToEndpoint($endpoint, $webmention->source, $webmention->target, $params); |
|
|
$response = $client->sendWebmentionToEndpoint($endpoint, $webmention->source, $webmention->target, $params); |
|
|
|
|
|
|
|
|
|
|
|
echo "Response code: ".$response['code']."\n"; |
|
|
|
|
|
|
|
|
if(in_array($response['code'], [200,201,202])) { |
|
|
if(in_array($response['code'], [200,201,202])) { |
|
|
$status = 'accepted'; |
|
|
$status = 'accepted'; |
|
|
|
|
|
|
|
@ -131,6 +149,7 @@ class Webmention { |
|
|
// Check if the endpoint returned a status URL
|
|
|
// Check if the endpoint returned a status URL
|
|
|
if(array_key_exists('Location', $response['headers'])) { |
|
|
if(array_key_exists('Location', $response['headers'])) { |
|
|
$webmention->webmention_status_url = \Mf2\resolveUrl($endpoint, $response['headers']['Location']); |
|
|
$webmention->webmention_status_url = \Mf2\resolveUrl($endpoint, $response['headers']['Location']); |
|
|
|
|
|
echo "Endpoint returned a status URL: ".$webmention->webmention_status_url."\n"; |
|
|
// TODO: queue a job to poll the endpoint for updates and deliver to the callback URL
|
|
|
// TODO: queue a job to poll the endpoint for updates and deliver to the callback URL
|
|
|
} else { |
|
|
} else { |
|
|
// No status URL was returned, so we can't follow up with this later. Mark as complete.
|
|
|
// No status URL was returned, so we can't follow up with this later. Mark as complete.
|
|
@ -145,6 +164,7 @@ class Webmention { |
|
|
$webmention->save(); |
|
|
$webmention->save(); |
|
|
|
|
|
|
|
|
$result = self::updateStatus($webmention, $response['code'], $status, $response['body']); |
|
|
$result = self::updateStatus($webmention, $response['code'], $status, $response['body']); |
|
|
|
|
|
echo "Done\n"; |
|
|
$pdo = ORM::get_db(); |
|
|
$pdo = ORM::get_db(); |
|
|
$pdo = null; |
|
|
$pdo = null; |
|
|
return $result; |
|
|
return $result; |
|
|