| 1 |
<?php |
| 2 |
require_once(ABSPATH . WPINC . '/class-feed.php'); |
| 3 |
|
| 4 |
class FeedWordPress_Content_Type_Sniffer extends SimplePie_Content_Type_Sniffer { |
| 5 |
/** |
| 6 |
* Get the Content-Type of the specified file |
| 7 |
* |
| 8 |
* @access public |
| 9 |
* @return string Filtered content type |
| 10 |
*/ |
| 11 |
function get_type () { |
| 12 |
$contentType = null; |
| 13 |
$charset = null; |
| 14 |
if (isset($this->file->headers['content-type'])) : |
| 15 |
if (!is_array($this->file->headers['content-type'])) : |
| 16 |
$this->file->headers['content-type'] = array($this->file->headers['content-type']); |
| 17 |
endif; |
| 18 |
|
| 19 |
foreach ($this->file->headers['content-type'] as $type) : |
| 20 |
$parts = array_map('trim', split(";", $type, 2)); |
| 21 |
if (isset($parts[1])) : |
| 22 |
$type = $parts[0]; |
| 23 |
$charset = $parts[1]; |
| 24 |
endif; |
| 25 |
|
| 26 |
if (preg_match( |
| 27 |
'!(application|text)/((atom|rss|rdf)\+)?xml!', |
| 28 |
$type, |
| 29 |
$ref |
| 30 |
)) : |
| 31 |
$contentType = $ref[0]; |
| 32 |
endif; |
| 33 |
endforeach; |
| 34 |
|
| 35 |
$outHeader = array(); |
| 36 |
if (!is_null($contentType)) : |
| 37 |
$outHeader[] = $contentType; |
| 38 |
else : |
| 39 |
$outHeader[] = 'text/xml'; // Generic |
| 40 |
endif; |
| 41 |
if (!is_null($charset)) : |
| 42 |
$outHeader[] = $charset; |
| 43 |
endif; |
| 44 |
|
| 45 |
$this->file->headers['content-type'] = implode("; ", $outHeader); |
| 46 |
else : |
| 47 |
// The default SimplePie behavior seems to be to return |
| 48 |
// text/plain if it can't find a Content-Type header. |
| 49 |
// The default SimplePie behavior sucks. Particularly |
| 50 |
// since SimplePie gets so draconian about Content-Type. |
| 51 |
// And since the WP SimplePie seems to drop Content-Type |
| 52 |
// from cached copies for some unfortunate reason. |
| 53 |
$this->file->headers['content-type'] = 'text/xml'; // Generic |
| 54 |
endif; |
| 55 |
return parent::get_type(); |
| 56 |
} /* FeedWordPress_Content_Type_Sniffer::get_type() */ |
| 57 |
} /* class FeedWordPress_Content_Type_Sniffer */ |
| 58 |
|
| 59 |
|