Releases: indieweb/mention-client-php
PHP 8 compatibility
PHP 8 compatibility
Fixes parameter issues that prevented the client from working in PHP 8.
Uses php-mf2 to parse rel values
Significantly improves the parsing of rel values by using a real HTML parser instead of regex.
Note that if you haven't loaded this through composer, and don't load the php-mf2 library yourself, this will fall back to parsing the HTML with regex.
Fix to ignore HTML comments
Now the library correctly does not find a webmention endpoint that may have been commented out in HTML.
Fix for parsing HTTP headers
- Fix parsing HTTP Link headers with unquoted rel values.
- Drops requirement on
xmlrpc_decode
for Pingbacks
Update php-mf2 dependency
- Update php-mf2 to require at least version 0.3.0
- Drops support for PHP 5.3
1.0.0
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.