Created
February 19, 2014 16:58
-
-
Save jonnybarnes/9096326 to your computer and use it in GitHub Desktop.
webmention target checking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo '<pre>'; | |
$mfJSON = '{ | |
"items": [ | |
{ | |
"type": [ | |
"h-as-note", | |
"h-entry" | |
], | |
"properties": { | |
"in-reply-to": [ | |
{ | |
"type": [ | |
"h-cite" | |
], | |
"properties": { | |
"author": [ | |
{ | |
"type": [ | |
"h-card" | |
], | |
"properties": { | |
"name": [ | |
"Ryan Barrett" | |
], | |
"photo": [ | |
"https:\/\/secure.gravatar.com\/avatar\/947b5f3f323da0ef785b6f02d9c265d6?s=96&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&r=G" | |
], | |
"url": [ | |
"http:\/\/snarfed.org\/" | |
] | |
}, | |
"value": "Ryan Barrett" | |
} | |
], | |
"summary": [ | |
"yeah, that\u2019s worked for a little while. the drawback is that twitter\u2019s API doesn\u2019t have a way to get a tweet\u2019s replies, so everyone who needs to do that currently searches for @-mentions of the author and filters the search results by the in_reply_to_status_id field. details: http:\/\/indiewebcamp.com\/backfeed#Twitter. mentionless replies break that.\r\n\r\nso, beware of mentionless replies if you want any twitter API clients (e.g. bridgy :P) to work." | |
], | |
"name": [ | |
"yeah, that\u2019s worked for a little while. the drawback is that twitter\u2019s API doesn\u2019t have a way to get a tweet\u2019s replies, so everyone who needs to do that currently searches for @-mentions of the author and filters the search results by the in_reply_to_status_id field. details: http:\/\/indiewebcamp.com\/backfeed#Twitter. mentionless replies break that.\r\n\r\nso, beware of mentionless replies if you want any twitter API clients (e.g. bridgy :P) to work." | |
], | |
"url": [ | |
"https:\/\/snarfed.org\/2014-02-16_re-barnaby-walters-%E2%80%A2-looks-like-twitter-no-longer-demands-that" | |
], | |
"in-reply-to": [ | |
"http:\/\/waterpigs.co.uk\/notes\/4UcGuo\/" | |
], | |
"published": [ | |
"2014-02-16T10:13:25-08:00" | |
], | |
"content": [ | |
{ | |
"html": "
\n\t\t\t
\n\t\t\t<div class=\"e-content\"><p>yeah, that\u2019s worked for a little while. the drawback is that twitter\u2019s API doesn\u2019t have a way to get a tweet\u2019s replies, so everyone who needs to do that currently searches for @-mentions of the author and filters the search results by the <code>in_reply_to_status_id<\/code> field. details: <a href=\"http:\/\/indiewebcamp.com\/backfeed#Twitter\">http:\/\/indiewebcamp.com\/backfeed#Twitter<\/a>. mentionless replies break that.<\/p>
\n
\n<p>so, beware of mentionless replies if you want any twitter API clients (e.g. bridgy :P) to work.<\/p>
\n
\n<p><a class=\"u-in-reply-to\" href=\"http:\/\/waterpigs.co.uk\/notes\/4UcGuo\/\"><\/a><\/p>
\n<\/div>\t\t\t\t\t\t\t", | |
"value": "yeah, that\u2019s worked for a little while. the drawback is that twitter\u2019s API doesn\u2019t have a way to get a tweet\u2019s replies, so everyone who needs to do that currently searches for @-mentions of the author and filters the search results by the in_reply_to_status_id field. details: http:\/\/indiewebcamp.com\/backfeed#Twitter. mentionless replies break that.\r\n\r\nso, beware of mentionless replies if you want any twitter API clients (e.g. bridgy :P) to work." | |
}, | |
{ | |
"html": "<p>yeah, that\u2019s worked for a little while. the drawback is that twitter\u2019s API doesn\u2019t have a way to get a tweet\u2019s replies, so everyone who needs to do that currently searches for @-mentions of the author and filters the search results by the <code>in_reply_to_status_id<\/code> field. details: <a href=\"http:\/\/indiewebcamp.com\/backfeed#Twitter\">http:\/\/indiewebcamp.com\/backfeed#Twitter<\/a>. mentionless replies break that.<\/p>
\n
\n<p>so, beware of mentionless replies if you want any twitter API clients (e.g. bridgy :P) to work.<\/p>
\n
\n<p><a class=\"u-in-reply-to\" href=\"http:\/\/waterpigs.co.uk\/notes\/4UcGuo\/\"><\/a><\/p>
\n", | |
"value": "yeah, that\u2019s worked for a little while. the drawback is that twitter\u2019s API doesn\u2019t have a way to get a tweet\u2019s replies, so everyone who needs to do that currently searches for @-mentions of the author and filters the search results by the in_reply_to_status_id field. details: http:\/\/indiewebcamp.com\/backfeed#Twitter. mentionless replies break that.\r\n\r\nso, beware of mentionless replies if you want any twitter API clients (e.g. bridgy :P) to work." | |
} | |
] | |
}, | |
"value": "2014-02-16 10:13\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t\t\t\tRyan Barrett\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t\t\r\n\t\t\tyeah, that\u2019s worked for a little while. the drawback is that twitter\u2019s API doesn\u2019t have a way to get a tweet\u2019s replies, so everyone who needs to do that currently searches for @-mentions of the author and filters the search results by the in_reply_to_status_id field. details: http:\/\/indiewebcamp.com\/backfeed#Twitter. mentionless replies break that.\r\n\r\nso, beware of mentionless replies if you want any twitter API clients (e.g. bridgy :P) to work." | |
} | |
], | |
"author": [ | |
{ | |
"type": [ | |
"h-card", | |
"h-card" | |
], | |
"properties": { | |
"name": [ | |
"Barnaby Walters" | |
], | |
"logo": [ | |
"\/photo.jpg" | |
], | |
"photo": [ | |
"\/photo.jpg" | |
], | |
"url": [ | |
"http:\/\/waterpigs.co.uk" | |
] | |
}, | |
"value": "Barnaby Walters \r\n\t\t\t\twaterpigs.co.uk" | |
} | |
], | |
"name": [ | |
"@snarfed ah, I tend to scrape twitter.com using github.com\/indieweb\/php-mf2-shim as it\u2019s forced to return results which are useful to humans :)" | |
], | |
"summary": [ | |
"@snarfed ah, I tend to scrape twitter.com using github.com\/indieweb\/php-mf2-shim as it\u2019s forced to return results which are useful to humans :)" | |
], | |
"category": [ | |
"#twitter", | |
"#api", | |
"#reply" | |
], | |
"url": [ | |
"http:\/\/waterpigs.co.uk\/notes\/4UdAkf\/" | |
], | |
"syndication": [ | |
"https:\/\/twitter.com\/BarnabyWalters\/status\/435364448917000192" | |
], | |
"published": [ | |
"2014-02-17T10:45:40" | |
], | |
"updated": [ | |
"2014-02-17T10:45:40" | |
], | |
"content": [ | |
{ | |
"html": "
\n\t\t<p><a class=\"auto-link h-x-username\" href=\"https:\/\/twitter.com\/snarfed\">@snarfed<\/a> ah, I tend to scrape <a class=\"auto-link\" href=\"http:\/\/twitter.com\">twitter.com<\/a> using <a class=\"auto-link\" href=\"http:\/\/github.com\/indieweb\/php-mf2-shim\">github.com\/indieweb\/php-mf2-shim<\/a> as it\u2019s forced to return results which are useful to humans :)<\/p>
\n\t\t", | |
"value": "@snarfed ah, I tend to scrape twitter.com using github.com\/indieweb\/php-mf2-shim as it\u2019s forced to return results which are useful to humans :)" | |
} | |
] | |
}, | |
"children": [ | |
{ | |
"type": [ | |
"h-x-username" | |
], | |
"properties": { | |
"name": [ | |
"@snarfed" | |
], | |
"url": [ | |
"https:\/\/twitter.com\/snarfed" | |
] | |
}, | |
"value": "@snarfed" | |
}, | |
{ | |
"type": [ | |
"h-card" | |
], | |
"properties": { | |
"name": [ | |
"Jovian Salak" | |
], | |
"url": [ | |
"http:\/\/byjovephotography.com" | |
] | |
}, | |
"value": "Jovian Salak" | |
} | |
] | |
} | |
], | |
"rels": { | |
"openid.delegate": [ | |
"http:\/\/waterpigs.co.uk" | |
], | |
"openid.server": [ | |
"https:\/\/www.indieauth.com\/openid" | |
], | |
"hub": [ | |
"http:\/\/pubsubhubbub.appspot.com\/" | |
], | |
"webmention": [ | |
"\/mentions\/webmention\/" | |
], | |
"http:\/\/webmention.org\/": [ | |
"\/mentions\/webmention\/" | |
], | |
"pingback": [ | |
"http:\/\/webmention.io\/webmention?forward=http:\/\/waterpigs.co.uk\/mentions\/webmention\/" | |
], | |
"shortcut": [ | |
"\/photo.jpg" | |
], | |
"icon": [ | |
"\/photo.jpg" | |
], | |
"apple-touch-icon-precomposed": [ | |
"\/photo.jpg" | |
], | |
"authorization_endpoint": [ | |
"https:\/\/indieauth.com\/auth" | |
], | |
"token_endpoint": [ | |
"http:\/\/waterpigs.co.uk\/login\/token\/" | |
], | |
"stylesheet": [ | |
"\/css\/styles.css", | |
"\/\/cdn.leafletjs.com\/leaflet-0.7.1\/leaflet.css" | |
], | |
"in-reply-to": [ | |
"https:\/\/snarfed.org\/2014-02-16_re-barnaby-walters-%E2%80%A2-looks-like-twitter-no-longer-demands-that" | |
], | |
"bookmark": [ | |
"http:\/\/waterpigs.co.uk\/notes\/4UdAkf\/" | |
], | |
"previous": [ | |
"\/notes\/4UcHfu\/" | |
], | |
"next": [ | |
"\/notes\/4UdBeU\/" | |
], | |
"tag": [ | |
"\/tags\/twitter", | |
"\/tags\/api", | |
"\/tags\/reply" | |
], | |
"syndication": [ | |
"https:\/\/twitter.com\/BarnabyWalters\/status\/435364448917000192" | |
], | |
"license": [ | |
"http:\/\/creativecommons.org\/licenses\/by-sa\/3.0\/deed.en_US" | |
], | |
"friend": [ | |
"http:\/\/byjovephotography.com" | |
], | |
"met": [ | |
"http:\/\/byjovephotography.com" | |
] | |
} | |
}'; | |
$target = 'https://snarfed.org/2014-02-16_re-barnaby-walters-%E2%80%A2-looks-like-twitter-no-longer-demands-that'; | |
function checkInReplyTo($mfJSON, $target) | |
{ | |
$mf = json_decode($mfJSON, true); | |
$items = $mf['items']; | |
foreach($items as $item) { | |
$properties = $item['properties']; | |
if(array_key_exists('in-reply-to', $properties)) { | |
if($properties['in-reply-to'][0]['properties']['url'][0] == $target) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
$isTarget = checkInReplyTo($mfJSON, $target); | |
if($isTarget) { | |
echo 'page links to target'; | |
} else { | |
echo 'no target found'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment