Skip to content

Commit 90ff2ec

Browse files
authored
test is_loopback, comment:depends on cassis
Added comment:depends on cassis.js, noted a few example function dependencies Added new function is_loopback Update first_linknode_href to skip hrefs with loopback host URLs Tested with live deployment in Falcon.
1 parent 054425f commit 90ff2ec

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/IndieWeb/get_rel_webmention.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,45 @@
44
/*
55
first_linknode_href, get_rel_webmention by Tantek Çelik http://tantek.com/
66
license: http://creativecommons.org/publicdomain/zero/1.0/
7+
depends on: link_rel_parser.php (e.g. head_http_rels,
8+
depends on: https://github.com/tantek/cassis/cassis.js (e.g. contains, get_absolute_uri, is_html_type, xphasrel, strcat)
79
*/
810

11+
// Could move this function to cassis.js if more broadly useful
12+
function is_loopback($href) {
13+
// in: $href URL
14+
// out: boolean whether host of URL is a loopback address
15+
$host = hostname_of_uri($href);
16+
$host = explode('.', $host);
17+
return ($host.length == 4 &&
18+
$host[0] == 127 &&
19+
ctype_digit($host[1]) &&
20+
ctype_digit($host[2]) &&
21+
ctype_digit($host[3]));
22+
}
23+
924
function first_linknode_href($links, $spacedtagnames='a area link') {
1025
// in: DOMNodeList $links
1126
// $spacedtagnames - space separated tag names, null for any
1227
// out: href attribute as string
13-
// return first DOMNode in $links that is an a, area, link with href
28+
// return href of first DOMNode in $links that is an a, area, link
29+
// with href that is not a loopback address
1430
// else return null
1531
if ($spacedtagnames) {
1632
$spacedtagnames = strcat(' ', $spacedtagnames, ' ');
1733
}
18-
foreach ($links as $link) {
19-
if (!$spacedtagnames ||
20-
contains($spacedtagnames,
21-
strcat(' ', $link->nodeName, ' '))) {
22-
return $link->getAttribute('href');
23-
}
24-
}
25-
return null;
34+
foreach ($links as $link) {
35+
if (!$spacedtagnames ||
36+
contains($spacedtagnames,
37+
strcat(' ', $link->nodeName, ' '))) {
38+
$href = $link->getAttribute('href');
39+
if (!is_loopback($href))
40+
{
41+
return $href;
42+
}
43+
}
44+
}
45+
return null;
2646
}
2747

2848
// in: $url of page that may or may not have a webmention endpoint

0 commit comments

Comments
 (0)