14 */ |
14 */ |
15 |
15 |
16 /** |
16 /** |
17 * Deprecated. Use SimplePie (class-simplepie.php) instead. |
17 * Deprecated. Use SimplePie (class-simplepie.php) instead. |
18 */ |
18 */ |
19 _deprecated_file( basename( __FILE__ ), '3.0', WPINC . '/class-simplepie.php' ); |
19 _deprecated_file( basename( __FILE__ ), '3.0.0', WPINC . '/class-simplepie.php' ); |
20 |
20 |
21 /** |
21 /** |
22 * Fires before MagpieRSS is loaded, to optionally replace it. |
22 * Fires before MagpieRSS is loaded, to optionally replace it. |
23 * |
23 * |
24 * @since 2.3.0 |
24 * @since 2.3.0 |
53 |
53 |
54 //var $ERROR = ""; |
54 //var $ERROR = ""; |
55 |
55 |
56 var $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright'); |
56 var $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright'); |
57 |
57 |
58 function MagpieRSS ($source) { |
58 /** |
59 |
59 * PHP5 constructor. |
60 # if PHP xml isn't compiled in, die |
60 */ |
|
61 function __construct( $source ) { |
|
62 |
|
63 # Check if PHP xml isn't compiled |
61 # |
64 # |
62 if ( !function_exists('xml_parser_create') ) |
65 if ( ! function_exists('xml_parser_create') ) { |
63 trigger_error( "Failed to load PHP's XML Extension. http://www.php.net/manual/en/ref.xml.php" ); |
66 return trigger_error( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ); |
64 |
67 } |
65 $parser = @xml_parser_create(); |
68 |
66 |
69 $parser = xml_parser_create(); |
67 if ( !is_resource($parser) ) |
|
68 trigger_error( "Failed to create an instance of PHP's XML parser. http://www.php.net/manual/en/ref.xml.php"); |
|
69 |
70 |
70 $this->parser = $parser; |
71 $this->parser = $parser; |
71 |
72 |
72 # pass in parser, and a reference to this object |
73 # pass in parser, and a reference to this object |
73 # set up handlers |
74 # set up handlers |
95 xml_parser_free( $this->parser ); |
96 xml_parser_free( $this->parser ); |
96 |
97 |
97 $this->normalize(); |
98 $this->normalize(); |
98 } |
99 } |
99 |
100 |
|
101 /** |
|
102 * PHP4 constructor. |
|
103 */ |
|
104 public function MagpieRSS( $source ) { |
|
105 self::__construct( $source ); |
|
106 } |
|
107 |
100 function feed_start_element($p, $element, &$attrs) { |
108 function feed_start_element($p, $element, &$attrs) { |
101 $el = $element = strtolower($element); |
109 $el = $element = strtolower($element); |
102 $attrs = array_change_key_case($attrs, CASE_LOWER); |
110 $attrs = array_change_key_case($attrs, CASE_LOWER); |
103 |
111 |
104 // check for a namespace, and split if found |
112 // check for a namespace, and split if found |
105 $ns = false; |
113 $ns = false; |
106 if ( strpos( $element, ':' ) ) { |
114 if ( strpos( $element, ':' ) ) { |
107 list($ns, $el) = split( ':', $element, 2); |
115 list($ns, $el) = explode( ':', $element, 2); |
108 } |
116 } |
109 if ( $ns and $ns != 'rdf' ) { |
117 if ( $ns and $ns != 'rdf' ) { |
110 $this->current_namespace = $ns; |
118 $this->current_namespace = $ns; |
111 } |
119 } |
112 |
120 |
587 |
595 |
588 // if RSS parsed successfully |
596 // if RSS parsed successfully |
589 if ( $rss && (!isset($rss->ERROR) || !$rss->ERROR) ) { |
597 if ( $rss && (!isset($rss->ERROR) || !$rss->ERROR) ) { |
590 |
598 |
591 // find Etag, and Last-Modified |
599 // find Etag, and Last-Modified |
592 foreach( (array) $resp->headers as $h) { |
600 foreach ( (array) $resp->headers as $h) { |
593 // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1" |
601 // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1" |
594 if (strpos($h, ": ")) { |
602 if (strpos($h, ": ")) { |
595 list($field, $val) = explode(": ", $h, 2); |
603 list($field, $val) = explode(": ", $h, 2); |
596 } |
604 } |
597 else { |
605 else { |
707 class RSSCache { |
715 class RSSCache { |
708 var $BASE_CACHE; // where the cache files are stored |
716 var $BASE_CACHE; // where the cache files are stored |
709 var $MAX_AGE = 43200; // when are files stale, default twelve hours |
717 var $MAX_AGE = 43200; // when are files stale, default twelve hours |
710 var $ERROR = ''; // accumulate error messages |
718 var $ERROR = ''; // accumulate error messages |
711 |
719 |
712 function RSSCache ($base='', $age='') { |
720 /** |
|
721 * PHP5 constructor. |
|
722 */ |
|
723 function __construct( $base = '', $age = '' ) { |
713 $this->BASE_CACHE = WP_CONTENT_DIR . '/cache'; |
724 $this->BASE_CACHE = WP_CONTENT_DIR . '/cache'; |
714 if ( $base ) { |
725 if ( $base ) { |
715 $this->BASE_CACHE = $base; |
726 $this->BASE_CACHE = $base; |
716 } |
727 } |
717 if ( $age ) { |
728 if ( $age ) { |
718 $this->MAX_AGE = $age; |
729 $this->MAX_AGE = $age; |
719 } |
730 } |
720 |
731 |
721 } |
732 } |
722 |
733 |
|
734 /** |
|
735 * PHP4 constructor. |
|
736 */ |
|
737 public function RSSCache( $base = '', $age = '' ) { |
|
738 self::__construct( $base, $age ); |
|
739 } |
|
740 |
723 /*=======================================================================*\ |
741 /*=======================================================================*\ |
724 Function: set |
742 Function: set |
725 Purpose: add an item to the cache, keyed on url |
743 Purpose: add an item to the cache, keyed on url |
726 Input: url from wich the rss file was fetched |
744 Input: url from which the rss file was fetched |
727 Output: true on success |
745 Output: true on success |
728 \*=======================================================================*/ |
746 \*=======================================================================*/ |
729 function set ($url, $rss) { |
747 function set ($url, $rss) { |
730 $cache_option = 'rss_' . $this->file_name( $url ); |
748 $cache_option = 'rss_' . $this->file_name( $url ); |
731 |
749 |
735 } |
753 } |
736 |
754 |
737 /*=======================================================================*\ |
755 /*=======================================================================*\ |
738 Function: get |
756 Function: get |
739 Purpose: fetch an item from the cache |
757 Purpose: fetch an item from the cache |
740 Input: url from wich the rss file was fetched |
758 Input: url from which the rss file was fetched |
741 Output: cached object on HIT, false on MISS |
759 Output: cached object on HIT, false on MISS |
742 \*=======================================================================*/ |
760 \*=======================================================================*/ |
743 function get ($url) { |
761 function get ($url) { |
744 $this->ERROR = ""; |
762 $this->ERROR = ""; |
745 $cache_option = 'rss_' . $this->file_name( $url ); |
763 $cache_option = 'rss_' . $this->file_name( $url ); |
756 |
774 |
757 /*=======================================================================*\ |
775 /*=======================================================================*\ |
758 Function: check_cache |
776 Function: check_cache |
759 Purpose: check a url for membership in the cache |
777 Purpose: check a url for membership in the cache |
760 and whether the object is older then MAX_AGE (ie. STALE) |
778 and whether the object is older then MAX_AGE (ie. STALE) |
761 Input: url from wich the rss file was fetched |
779 Input: url from which the rss file was fetched |
762 Output: cached object on HIT, false on MISS |
780 Output: cached object on HIT, false on MISS |
763 \*=======================================================================*/ |
781 \*=======================================================================*/ |
764 function check_cache ( $url ) { |
782 function check_cache ( $url ) { |
765 $this->ERROR = ""; |
783 $this->ERROR = ""; |
766 $cache_option = 'rss_' . $this->file_name( $url ); |
784 $cache_option = 'rss_' . $this->file_name( $url ); |
789 } |
807 } |
790 |
808 |
791 /*=======================================================================*\ |
809 /*=======================================================================*\ |
792 Function: file_name |
810 Function: file_name |
793 Purpose: map url to location in cache |
811 Purpose: map url to location in cache |
794 Input: url from wich the rss file was fetched |
812 Input: url from which the rss file was fetched |
795 Output: a file name |
813 Output: a file name |
796 \*=======================================================================*/ |
814 \*=======================================================================*/ |
797 function file_name ($url) { |
815 function file_name ($url) { |
798 return md5( $url ); |
816 return md5( $url ); |
799 } |
817 } |