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 @@ -1,11 +1,11 @@ <?php /* 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 Free Software Foundation; either version 3 of the License, or (at your option) any later version. @@ -55,14 +55,14 @@ class Feed if (!@array_key_exists ('Content-Type', $client->headers)) $client->headers[] = ''; 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); alterXML ($client->xml); $this->cache ($client); if ($subscribe_it) @@ -70,14 +70,18 @@ class Feed } else printXmlError (null, _('XML Syntax Error. Verify the given URL')); } 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)) { recodeToUTF8 ($client->xml); alterXML ($client->xml); $this->cache ($client); @@ -368,7 +372,16 @@ function isFeedValid (&$client) $xml_parser = xml_parser_create (); $ret = @xml_parse ($xml_parser, $client->xml, true); xml_parser_free ($xml_parser); return $ret; } +function matchContentType ($h, $types=array()) +{ + $p = strpos ($h, ';'); + if ($p !== false) { + $h = substr ($h, 0, $p); + } + return in_array ($h, $types); +} + ?> |