PluginProbe
FeedWordPress / 2011.0512
FeedWordPress v2011.0512
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / feedwordpress-content-type-sniffer.class.php

feedwordpress-content-type-sniffer.class.php in FeedWordPress 2011.0512, at feedwordpress-content-type-sniffer.class.php

59 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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