summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2012-09-23 13:38:58 +0400
committerAndrew Dolgov <[email protected]>2012-09-23 13:38:58 +0400
commit759e5132a1311a1b56787b97e82ddad4b5348aa1 (patch)
treeedb3c7a6661206eea9c29b59ec9dd752f7d9807a /include
parent386c4ce63c95a687f4358839d6703a02b20ebe50 (diff)
subscribe_to_feed: stop fetching URL multiple times while subscribing, various other speedups
Diffstat (limited to 'include')
-rw-r--r--include/functions.php44
1 files changed, 14 insertions, 30 deletions
diff --git a/include/functions.php b/include/functions.php
index ba7cb75a8..cca02837e 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1810,15 +1810,19 @@
$update_method = 0;
- if (!fetch_file_contents($url, false, $auth_login, $auth_pass))
+ $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass);
+
+ if (!$contents) {
return array("code" => 5, "message" => $fetch_last_error);
+ }
+
+ if (is_html($contents)) {
+ $feedUrls = get_feeds_from_html($url, $contents);
- if (url_is_html($url, $auth_login, $auth_pass)) {
- $feedUrls = get_feeds_from_html($url, $auth_login, $auth_pass);
if (count($feedUrls) == 0) {
return array("code" => 3);
} else if (count($feedUrls) > 1) {
- return array("code" => 4);
+ return array("code" => 4, "feeds" => $feedUrls);
}
//use feed url as new URL
$url = key($feedUrls);
@@ -4758,22 +4762,13 @@
return false;
}
- /**
- * Extracts RSS/Atom feed URLs from the given HTML URL.
- *
- * @param string $url HTML page URL
- *
- * @return array Array of feeds. Key is the full URL, value the title
- */
- function get_feeds_from_html($url, $login = false, $pass = false)
+ function get_feeds_from_html($url, $content)
{
$url = fix_url($url);
$baseUrl = substr($url, 0, strrpos($url, '/') + 1);
libxml_use_internal_errors(true);
- $content = @fetch_file_contents($url, false, $login, $pass);
-
$doc = new DOMDocument();
$doc->loadHTML($content);
$xpath = new DOMXPath($doc);
@@ -4794,23 +4789,12 @@
return $feedUrls;
}
- /**
- * Checks if the content behind the given URL is a HTML file
- *
- * @param string $url URL to check
- *
- * @return boolean True if the URL contains HTML content
- */
- function url_is_html($url, $login = false, $pass = false) {
- $content = substr(fetch_file_contents($url, false, $login, $pass), 0, 1000);
-
- if (stripos($content, '<html>') === false
- && stripos($content, '<html ') === false
- ) {
- return false;
- }
+ function is_html($content) {
+ return preg_match("/<html|DOCTYPE html/i", $content) !== 0;
+ }
- return true;
+ function url_is_html($url, $login = false, $pass = false) {
+ return is_html(fetch_file_contents($url, false, $login, $pass));
}
function print_label_select($link, $name, $value, $attributes = "") {