PluginProbe
FeedWordPress / 2016.1211
FeedWordPress v2016.1211
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 2016.1211, at feedwordpress-content-type-sniffer.class.php

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