git.cweiske.de
/
tt-rss-micropub.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f0ffcf4
)
Handle HTTP errors when extracting links
master
github/master
author
Christian Weiske
<cweiske@cweiske.de>
Wed, 31 May 2017 12:20:00 +0000
(14:20 +0200)
committer
Christian Weiske
<cweiske@cweiske.de>
Wed, 31 May 2017 12:20:00 +0000
(14:20 +0200)
init.php
patch
|
blob
|
history
diff --git
a/init.php
b/init.php
index d561aa5421b561d2fe81269786625afdfb2bcf24..3d8008fe4dd1ecb87810b42c79c4e4faf22d332d 100644
(file)
--- a/
init.php
+++ b/
init.php
@@
-225,6
+225,9
@@
class Micropub extends Plugin implements IHandler
$links = $this->getLinks($me);
$links = $this->getLinks($me);
+ if ($links === false) {
+ return $this->errorOut('Error fetching URL: ' . $me);
+ }
if (!count($links)) {
return $this->errorOut('No links found');
}
if (!count($links)) {
return $this->errorOut('No links found');
}
@@
-325,6
+328,9
@@
class Micropub extends Plugin implements IHandler
//step 1: micropub discovery
$links = $this->getLinks($url);
//step 1: micropub discovery
$links = $this->getLinks($url);
+ if ($links === false) {
+ return $this->errorOut('Error fetching URL: ' . $url);
+ }
if (!count($links)) {
return $this->errorOut('No links found');
}
if (!count($links)) {
return $this->errorOut('No links found');
}
@@
-365,6
+371,9
@@
class Micropub extends Plugin implements IHandler
}
$links = $this->getLinks($_GET['me']);
}
$links = $this->getLinks($_GET['me']);
+ if ($links === false) {
+ return $this->errorOut('Error fetching URL: ' . $_GET['me']);
+ }
if (!isset($links['token_endpoint'])) {
return $this->errorOut('No token endpoint found');
}
if (!isset($links['token_endpoint'])) {
return $this->errorOut('No token endpoint found');
}
@@
-539,6
+548,10
@@
class Micropub extends Plugin implements IHandler
/**
* Extract link relations from a given URL
/**
* Extract link relations from a given URL
+ *
+ * @param string $url URL to extract links from
+ *
+ * @return bool|array Array of links, or false on HTTP error
*/
protected function getLinks($url)
{
*/
protected function getLinks($url)
{
@@
-548,6
+561,10
@@
class Micropub extends Plugin implements IHandler
'url' => $url,
]
);
'url' => $url,
]
);
+ if ($html === false) {
+ return false;
+ }
+
//Loading invalid HTML is tedious.
// quick hack with regex. yay!
preg_match_all('#<link[^>]+?>#', $html, $matches);
//Loading invalid HTML is tedious.
// quick hack with regex. yay!
preg_match_all('#<link[^>]+?>#', $html, $matches);