indieweb / mention-client-php Goto Github PK
View Code? Open in Web Editor NEWClient library for sending webmention and pingback notifications
Home Page: https://indieweb.org/webmention
Client library for sending webmention and pingback notifications
Home Page: https://indieweb.org/webmention
The code currently checks the HTTP headers for X-Pingback
, but the spec says to look for a generic Link
header with a rel
of webmention
.
I had a look at your tests where you use something like:
Link: <http://aaronparecki.com/webmention.php>; rel=\"http://webmention.org/\"\r
Link: <http://aaronparecki.com/>; rel=\"me\"";
...but as far as I know, headers will be sent like this:
Link: <http://aaronparecki.com/webmention.php>; rel=\"http://webmention.org/\",<http://aaronparecki.com/>; rel=\"me\""
The parser is incorrectly finding a webmention endpoint that is commented out in HTML:
<!--
<a rel="webmention" href="http://webmention.example/wrong"></a>
-->
<a rel="webmention" href="http://webmention.example/correct"></a>
_findWebmentionEndpoint needs support for rel=webmention
Currently the findOutgoingLinks
function naively looks only at the first mf2 object in items
.
Here is the proposed solution:
Add a parameter to findOutgoingLinks
that accepts the source URL of the page. For each item in the mf2 items
, look for the item with a url
property that matches the URL given. If none is found, defaulting to the first item is fine.
This works under the assumption that this function will only be used for sending webmentions for post permalinks, as this will not work for feed pages that contain multiple h-entrys (although it will work for a feed page that uses h-feed).
Currently the findOutgoingLinks
method will return any mf2 property that is a URL, regardless of the element the value came from. For example, <data class="u-in-reply-to" value="http://example.com/">
will be considered a link, even though according to HTML it is not a link. This is a problem because sending a webmention to that URL will fail when its webmention endpoint tries to look for a link back.
I have my posts marked up with microformats2:
<article class="h-entry">
<div>
<div>
<p class="title">
<i class="fa-solid fa-reply"></i> replied to
<a class="u-in-reply-to" href="https://micro.geheimesite.nl/post/626f9d9c0e367">https://micro.geheimesite.nl/post/626f9d9c0e367</a>
</p>
<div class="p-summary e-content">
<p>The only thing I still need to do now is add support for webmention comments (which I'm testing now) and add a media endpoint for photo posts. I think the comments should be working now; this is a test :)</p>
</div>
</div>
<a class="no-underline u-url" href="https://micro.geheimesite.nl/post/626fca88eb951">
<time class="dt-published">2022-05-02 14:11:52</time>
</a>
</div>
<div class="p-author h-card">
<img src="/assets/me.jpeg" class="u-photo">
<p hidden=""><a class="u-url p-name" href="https://micro.geheimesite.nl">Robijntje</a></p>
</div>
</article>
They include an h-card. Currently findOutgoingLinks
doesn't work with this setup, because it only checks the first element in the array returned by the mf2 parser, which is the h-card. I think a possible solution is using a foreach loop and just checking all elements in the array and picking the one with type=h-entry.
I'm pretty sure my mf2 markup is fine, but if it isn't, let me know :)
This is easier to do before there are many contributors.
IMO, the best would be if libs like this one eventually became bundled in FLOSS PHP apps and this is easier with the MIT license than the Apache license. I was part of a group that worked hard to change the Bootstrap license from Apache to MIT for easy inclusion in GPL/LGPL apps: twbs/bootstrap#2054
In my case, it's to include in Tiki Wiki CMS Groupware, in the context of WikiSuite, for which IndieWeb is an inspiration.
https://tiki.org/ -> Tiki is the Free/Libre/Open Source Web Application with the most built-in features
https://tiki.org/License
http://wikisuite.org/ -> WikiSuite is the most comprehensive and integrated Free / Libre / Open Source software suite ever developed.
http://wikisuite.org/Component-criteria#IndieWeb
Thanks!
Explicitly this fails from http://waterpigs.co.uk/notes/4Xu9i0/:
<link rel="webmention http://webmention.org/" href="/mentions/webmention/" />
On PHP 7.4 and up, the implode()
arguments should probably be presented in the same order as they would for explode()
. Earlier PHP versions accept either order, so the change would be backward compatible.
PHP Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in [...]/IndieWeb/MentionClient.php on line 224
The call to xmlrpc_decode failed on vanilla Ubuntu because I did not have the php5-xmlrpc
module installed (Debian-derived distros at least seem to break less common stdlib functions into separate modules)
I think it would be worthwhile to make this a soft requirement (check for existence of the function before calling it) or remove it altogether and verify the response manually, since pingback is kind of secondary and we're not doing much with the response anyway.
I'm using the 'sendMentions()' method (using PHP 8.1), and while it does seem to be sending the Webmentions, it terminates in a 500 error:
CRITICAL - 2023-10-13 17:09:19 --> mb_convert_encoding(): Argument #3 ($from_encoding) must specify at least one encoding in VENDORPATH/mf2/mf2/Mf2/Parser.php on line 96. 1 VENDORPATH/mf2/mf2/Mf2/Parser.php(96): mb_convert_encoding() 2 VENDORPATH/mf2/mf2/Mf2/Parser.php(365): Mf2\unicodeToHtmlEntities() 3 VENDORPATH/indieweb/mention-client/src/IndieWeb/MentionClient.php(156): Mf2\Parser->__construct() 4 VENDORPATH/indieweb/mention-client/src/IndieWeb/MentionClient.php(240): IndieWeb\MentionClient->_parseBody() 5 VENDORPATH/indieweb/mention-client/src/IndieWeb/MentionClient.php(418): IndieWeb\MentionClient->discoverWebmentionEndpoint() 6 VENDORPATH/indieweb/mention-client/src/IndieWeb/MentionClient.php(400): IndieWeb\MentionClient->sendFirstSupportedMention() 7 APPPATH/Controllers/Blogpost.php(24): IndieWeb\MentionClient->sendMentions() ...
Am I doing something wrong, or is this a bug?
Currently does not pass https://webmention.rocks/test/23
use some defaults and allow overriding
I've got this case where an endpoint ( <link rel=webmention href=[URL]>
in the page's HTML) is not discovered if not explicitly wrapped in (double?) quotes.
Not yet sure if an issue with this library (although it seems like it could improve in this regard, too) or the mf2/mf2 parser, which I'm including, too ...
Basically, curl does some odd things in many hosted environments where basedir or safe mode are set - namely, CURLOPT_FOLLOWLOCATION is disabled... for some reason.
This causes problems on a number of hosts where this is enabled by default.
@benwerd's solution was to implement this in code, but that's not pretty in a library context. Perhaps having the ability to pass a send function to hand off to might be a way to go? I can of course just subclass...
(Refs idno/known#629)
(I think, maybe.. aaronpk.com -> aaronparecki.com didn't get a webmention)
Maybe mention webemtnion.io as an alternative to pingback.me, particularly as pingback -> webmention proxy service.
xmlrpc_decode returns null in php 5.5.11 when the pingback response is a string which indicates a successful pingback response. I looked at the xlmrpc_decode method at php.net and realized that this method cannot be trusted: http://us1.php.net/manual/en/function.xmlrpc-decode.php
In the sendPingback() method we have:
if(@$decoded=xmlrpc_decode($response)) {
if(is_string($decoded))
return true; // pingback returns a string like "Pingback was successful" when it works
else
return false; // otherwise returns an array like array('faultCode'=>48,'faultString'=>'The pingback has already been registered')
} else {
return false;
}
Since $decoded is null on a successful pingback, the method will return false even though we got a successful response from the pingback target.
The following conditional block which replaces the block of code above solves the problem for everyone I believe:
if(is_array(xmlrpc_decode($response))):
return false;
elseif(is_string($response) && !empty($response)):
return true;
endif;
Pretty much it checks if xmlrpc_decode returns an array signifying we got an xml response which means you have an error, else if you get a non empty string then it's a success.
I hope this helped. Thanks for this library by the way. I'm in the middle of making my own blog for my website and this saved a lot of time.
When I send a webmention from http://django.bnvk.me/notes/19
(varied availability) which links to http://waterpigs.co.uk/notes/4QbH5C/
it fails with this 301 error
Checking http://django.bnvk.me/ Fetching headers... No webmention server found in header, looking in the body now Fetching body... webmention server: http://webmention.io/brennannovak.com/webmention Sending webmention now! Sending to webmention server: http://webmention.io/brennannovak.com/webmention
301 Moved Permanently
Barnaby manually submitted my comment on his site and it worked just fine so wesathinks is has something do with the regex in the client
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.