Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* - Send a Pingback.
* - Discover if a URL provides Pingback, and look up the XML-RPC endpoint.
*/

class VinculumPingbackHandler {

// User-agent to use when querying remote sites.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* - Send a trackback.
* - Discover if a URL provides trackback, and look up the endpoint URL.
*/

class VinculumTrackbackHandler {

// User-agent to use when querying remote sites.
Expand Down Expand Up @@ -322,9 +321,9 @@ class VinculumTrackbackHandler {

$mime_type = (isset($result->headers['content-type'])) ? $result->headers['content-type'] : NULL;
$is_valid = substr_count($mime_type, 'text/html')
|| substr_count($mime_type, 'application/xhtml+xml')
|| substr_count($mime_type, 'application/xml')
|| substr_count($mime_type, 'text/xml');
|| substr_count($mime_type, 'application/xhtml+xml')
|| substr_count($mime_type, 'application/xml')
|| substr_count($mime_type, 'text/xml');
return $is_valid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*
* @see http://webmention.org
*/

class VinculumWebmentionHandler {

// User-agent to use when querying remote sites.
Expand Down Expand Up @@ -89,8 +88,8 @@ class VinculumWebmentionHandler {
preg_match('/<(?:link|a)[ ]+rel="webmention"[ ]+href="([^"]+)"[ ]*\/?>/i', $response->data, $match)) {
return self::absoluteURL($target, array_pop($match));
}
elseif (preg_match('/<(?:link|a)[ ]+href="([^"]+)"[ ]+rel="http:\/\/webmention\.org\/?"[ ]*\/?>/i', $body, $match) ||
preg_match('/<(?:link|a)[ ]+rel="http:\/\/webmention\.org\/?"[ ]+href="([^"]+)"[ ]*\/?>/i', $body, $match)) {
elseif (preg_match('/<(?:link|a)[ ]+href="([^"]+)"[ ]+rel="http:\/\/webmention\.org\/?"[ ]*\/?>/i', $response->data, $match) ||
preg_match('/<(?:link|a)[ ]+rel="http:\/\/webmention\.org\/?"[ ]+href="([^"]+)"[ ]*\/?>/i', $response->data, $match)) {
return self::absoluteURL($target, array_pop($match));
}

Expand Down Expand Up @@ -145,7 +144,7 @@ class VinculumWebmentionHandler {
*/
public static function debug($message, $params = array(), $error_level = WATCHDOG_NOTICE) {
if ($error_level <= self::$watchdog_reporting_level) {
watchdog('Pingback', $message, $params, $error_level);
watchdog('WebMention', $message, $params, $error_level);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @file
* Provide the Webmention protocol to the Vinculum module.
*
* @see Specification document: http://archive.cweiske.de/trackback/trackback-1.2.html
* @see http://webmention.org/
*/

/**
Expand Down Expand Up @@ -66,23 +66,32 @@ function vinculum_webmention_node_view($node, $view_mode, $langcode) {
function vinculum_webmention_receive() {
$success = TRUE;

//Will check later #TODO will fight DDOS better https://github.com/converspace/webmention/blob/master/README.md#sender-notifies-receiver
if (variable_get('vinculum_webmention_receive_async', FALSE)) {
drupal_add_http_header('Status', '202 Accepted');
echo check_plain($_POST['target']) . '/webmention_in_queue';
// Perform end-of-request tasks.
drupal_page_footer();
return;
}

// Verify Webmention
$source = $_POST['source'];
$target = $_POST['target'];
$source = check_plain($_POST['source']);
$target = check_plain($_POST['target']);

// 1. The receiver SHOULD check that target is a valid resource belonging to
// it and that it accepts webmentions.
$nid = vinculum_webmention_validate_resource_exists($target);
$node = node_load($nid);
if (!$node->nid) {
$success = FALSE;
drupal_add_http_header('Status', '404 Bad Request');
drupal_add_http_header('Status', '400 Bad Request');
echo t('No valid resource.');
}

if (!vinculum_webmention_validate_resource_accepts_webmentions($node)) {
$success = FALSE;
drupal_add_http_header('Status', '404 Bad Request');
drupal_add_http_header('Status', '400 Bad Request');
echo t('Resource does not accept Webmentions.');
}

Expand All @@ -92,19 +101,35 @@ function vinculum_webmention_receive() {
// response).
if (!vinculum_webmention_validate_source_exists($source)) {
$success = FALSE;
drupal_add_http_header('Status', '404 Bad Request');
drupal_add_http_header('Status', '400 Bad Request');
echo t('Source does not exist or is not accessible.');
}

if (!vinculum_webmention_validate_source_contains_target($source, $target)) {
$success = FALSE;
drupal_add_http_header('Status', '404 Bad Request');
drupal_add_http_header('Status', '400 Bad Request');
echo t('Source does not contain target.');
}

//@TODO Add / update / delete Webmention

if (FALSE) {
// Attempt to create a Vinculum entity.
$vinculum = new VinculumReceived(array(
'handler' => 'vinculum_webmention',
'localUrl' => $target,
'url' => $source,
'nid' => $node->nid,
));
if ($result = $vinculum->save()) {
// Successful: provide a meaningful response.
if ($result == SAVED_NEW) {
$message = t('WebMention from @source to @target registered.', array('@source' => $source, '@target' => $target));
}
elseif ($result == SAVED_UPDATED) {
$message = t('WebMention from @source to @target updated.', array('@source' => $source, '@target' => $target));
}
return $message;
}
else {
$success = FALSE;

// Something went wrong.
Expand All @@ -117,6 +142,7 @@ function vinculum_webmention_receive() {
drupal_add_http_header('Status', '200 OK');
print 'OK';
}
vinculum_dbg($success, TRUE, 'webmentionthread');

// Perform end-of-request tasks.
drupal_page_footer();
Expand All @@ -132,6 +158,7 @@ function vinculum_webmention_receive() {
* Return a node id or FALSE
*/
function vinculum_webmention_validate_resource_exists($target) {
return vinculum_lookup_nid($target);
$parts = parse_url($target);

// Non clean URL.
Expand Down
Loading