Skip to content

1.0.0

Compare
Choose a tag to compare
@aaronpk aaronpk released this 09 Dec 19:29
· 34 commits to main since this release

There are breaking changes in this 1.0.0 release! Do not upgrade without planning on updating your code that uses this library.

This release simplifies the API and gives you more flexibility in how to use it, exposing more of the individual features as their own functions.

Basic Functionality

The original functionality of sending mentions to all links found on a URL is still available with the syntax:

$client = new IndieWeb\MentionClient();
$sent = $client->sendMentions($sourceURL);

echo "Sent $sent mentions\n";

However, this will now parse the source URL for microformats, and only send mentions for links found in the first item. This means you can use this method to send mentions for an entry without worrying about also sending mentions to all the URLs found in your website header and footer.

Send a mention to a specific page

There is a new function for sending a mention to a target URL. It will find the webmention or pingback endpoint advertised by the page and send the request.

$client = new IndieWeb\MentionClient();
$response = $client->sendWebmention($sourceURL, $targetURL);

Extension Support

The library now also supports webmention extensions if you are using the sendWebmention function. You can pass a third parameter which is an array of additional parameters to include in the request. For example:

$client = new IndieWeb\MentionClient();
$response = $client->sendWebmention($sourceURL, $targetURL, ['vouch'=>$vouch]);

Sending the webmention or pingback directly

If you already know the webmention or pingback endpoint, you can use this library to send the request directly:

$response = IndieWeb\MentionClient::sendWebmentionToEndpoint($endpoint, $source, $target);

More response details for webmention sending

The response of sendWebmention and sendWebmentionToEndpoint is now an array which includes the HTTP status code, HTTP headers, and response body.

{
  "code": 202,
  "headers": {
    "Content-Type: text/plain"
  },
  "body": "Webmention is processing"
}

This is useful if you want more details on what the webmention server replied.

Finding outgoing links

You can use this library to parse a source URL or HTML document to look for all outgoing links.

$client = new IndieWeb\MentionClient();
$urls = $client->findOutgoingLinks($html);

Alternately, you can pass a parsed Microformats object to the findOutgoingLinks function and it will search for URLs in any property as well as in the HTML of any e-content objects.

$client = new IndieWeb\MentionClient();
$parsed = \Mf2\parse($html, $sourceURL);
$urls = self::findOutgoingLinks($parsed);

The result is an array with duplicates removed:

[
  "http://example.com/1",
  "http://example.com/2"
]

You can then loop through this array and call sendWebmention for each target URL, or do your own checking for whether to send the mention. For example you may not want to mention your own URLs.