function http_request_find_feeds in Feeds 7.2
Same name and namespace in other branches
- 8.2 libraries/http_request.inc \http_request_find_feeds()
- 6 libraries/http_request.inc \http_request_find_feeds()
- 7 libraries/http_request.inc \http_request_find_feeds()
Finds potential feed tags in the HTML document.
Parameters
string $html: The html string to search.
Return value
array An array of href to feeds.
2 calls to http_request_find_feeds()
- FeedsHTTPRequestTestCase::testHTTPRequestFindFeeds in tests/
http_request.test - Tests http_request_find_feeds().
- http_request_get_common_syndication in libraries/
http_request.inc - Discovers RSS or atom feeds at the given URL.
File
- libraries/
http_request.inc, line 513 - Download via HTTP.
Code
function http_request_find_feeds($html) {
$matches = array();
preg_match_all(HTTP_REQUEST_PCRE_LINK_TAG, $html, $matches);
$links = $matches[1];
$valid_links = array();
// Build up all the links information.
foreach ($links as $link_tag) {
$attributes = array();
$candidate = array();
preg_match_all(HTTP_REQUEST_PCRE_TAG_ATTRIBUTES, $link_tag, $attributes, PREG_SET_ORDER);
foreach ($attributes as $attribute) {
// Find the key value pairs, attribute[1] is key and attribute[2] is the
// value. However, if the link tag used single quotes, the value might
// be in attribute[3] instead.
if (empty($attribute[2])) {
$attribute[2] = $attribute[3];
}
if (!empty($attribute[1]) && !empty($attribute[2])) {
$candidate[drupal_strtolower($attribute[1])] = drupal_strtolower(decode_entities($attribute[2]));
}
}
// Examine candidate to see if it s a feed.
// @TODO: could/should use http_request_is_feed ??
if (isset($candidate['rel']) && $candidate['rel'] == 'alternate') {
if (isset($candidate['href']) && isset($candidate['type']) && strpos($candidate['type'], 'xml') !== FALSE) {
// All tests pass, its a valid candidate.
$valid_links[] = $candidate['href'];
}
}
}
return $valid_links;
}