diff options
author | Wojciech Polak <polak@gnu.org> | 2010-04-13 20:42:15 +0200 |
---|---|---|
committer | Wojciech Polak <polak@gnu.org> | 2010-04-13 20:42:15 +0200 |
commit | 873ffc3b102e6129e42891ff9630ca2f73ae68bb (patch) | |
tree | 6054646e9050a53bd09ad7e3a7c5702ec3c5d2c8 | |
parent | 89b1872daa13f05f07b3c792ea6da6c9d5a86b23 (diff) | |
download | cheetah-873ffc3b102e6129e42891ff9630ca2f73ae68bb.tar.gz cheetah-873ffc3b102e6129e42891ff9630ca2f73ae68bb.tar.bz2 |
Improve feed detection.
-rw-r--r-- | frontend/lib/feed.class.php | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/frontend/lib/feed.class.php b/frontend/lib/feed.class.php index 5b075b4..8348170 100644 --- a/frontend/lib/feed.class.php +++ b/frontend/lib/feed.class.php @@ -2,7 +2,7 @@ /* Cheetah News lib/feed.class.php - Copyright (C) 2005, 2006, 2008 Wojciech Polak. + Copyright (C) 2005, 2006, 2008, 2010 Wojciech Polak. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -58,8 +58,8 @@ class Feed if ($client->status == 200) { if (preg_match ('/<\?xml version=[\'"].*?[\'"].*?\?>/m', $client->xml) && - !preg_match ('|text/html|', $client->headers['Content-Type']) && - !preg_match ('|application/xhtml\+xml|', $client->headers['Content-Type'])) + !matchContentType ($client->headers['Content-Type'], + array ('text/html', 'application/xhtml+xml'))) { if (isFeedValid ($client)) { recodeToUTF8 ($client->xml); @@ -73,8 +73,12 @@ class Feed } else if ((preg_match ('/^<rss version=".*?".*?>/im', $client->xml) || preg_match ('|^<feed xmlns="http://www.w3.org/2005/Atom".*?>|im', $client->xml)) && - (preg_match ('|application/xml|', $client->headers['Content-Type']) || - preg_match ('|text/xml|', $client->headers['Content-Type']))) + matchContentType ($client->headers['Content-Type'], + array ('text/xml', + 'application/xml', + 'application/rss+xml', + 'application/rdf+xml', + 'application/atom+xml'))) { /* invalid xml type, but this is common */ if (isFeedValid ($client)) { @@ -371,4 +375,13 @@ function isFeedValid (&$client) return $ret; } +function matchContentType ($h, $types=array()) +{ + $p = strpos ($h, ';'); + if ($p !== false) { + $h = substr ($h, 0, $p); + } + return in_array ($h, $types); +} + ?> |