1 | <?php |
2 | if ( !class_exists( 'SimplePie' ) ) : |
3 | /** |
4 | * SimplePie |
5 | * |
6 | * A PHP-Based RSS and Atom Feed Framework. |
7 | * Takes the hard work out of managing a complete RSS/Atom solution. |
8 | * |
9 | * Copyright (c) 2004-2009, Ryan Parman and Geoffrey Sneddon |
10 | * All rights reserved. |
11 | * |
12 | * Redistribution and use in source and binary forms, with or without modification, are |
13 | * permitted provided that the following conditions are met: |
14 | * |
15 | * * Redistributions of source code must retain the above copyright notice, this list of |
16 | * conditions and the following disclaimer. |
17 | * |
18 | * * Redistributions in binary form must reproduce the above copyright notice, this list |
19 | * of conditions and the following disclaimer in the documentation and/or other materials |
20 | * provided with the distribution. |
21 | * |
22 | * * Neither the name of the SimplePie Team nor the names of its contributors may be used |
23 | * to endorse or promote products derived from this software without specific prior |
24 | * written permission. |
25 | * |
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS |
27 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
28 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS |
29 | * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
33 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
34 | * POSSIBILITY OF SUCH DAMAGE. |
35 | * |
36 | * @package SimplePie |
37 | * @version 1.2 |
38 | * @copyright 2004-2009 Ryan Parman, Geoffrey Sneddon |
39 | * @author Ryan Parman |
40 | * @author Geoffrey Sneddon |
41 | * @link http://simplepie.org/ SimplePie |
42 | * @link http://simplepie.org/support/ Please submit all bug reports and feature requests to the SimplePie forums |
43 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
44 | * @todo phpDoc comments |
45 | */ |
46 | |
47 | /** |
48 | * SimplePie Name |
49 | */ |
50 | define('SIMPLEPIE_NAME', 'SimplePie'); |
51 | |
52 | /** |
53 | * SimplePie Version |
54 | */ |
55 | define('SIMPLEPIE_VERSION', '1.2'); |
56 | |
57 | /** |
58 | * SimplePie Build |
59 | */ |
60 | define('SIMPLEPIE_BUILD', '20090627192103'); |
61 | |
62 | /** |
63 | * SimplePie Website URL |
64 | */ |
65 | define('SIMPLEPIE_URL', 'http://simplepie.org'); |
66 | |
67 | /** |
68 | * SimplePie Useragent |
69 | * @see SimplePie::set_useragent() |
70 | */ |
71 | define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD); |
72 | |
73 | /** |
74 | * SimplePie Linkback |
75 | */ |
76 | define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>'); |
77 | |
78 | /** |
79 | * No Autodiscovery |
80 | * @see SimplePie::set_autodiscovery_level() |
81 | */ |
82 | define('SIMPLEPIE_LOCATOR_NONE', 0); |
83 | |
84 | /** |
85 | * Feed Link Element Autodiscovery |
86 | * @see SimplePie::set_autodiscovery_level() |
87 | */ |
88 | define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1); |
89 | |
90 | /** |
91 | * Local Feed Extension Autodiscovery |
92 | * @see SimplePie::set_autodiscovery_level() |
93 | */ |
94 | define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2); |
95 | |
96 | /** |
97 | * Local Feed Body Autodiscovery |
98 | * @see SimplePie::set_autodiscovery_level() |
99 | */ |
100 | define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4); |
101 | |
102 | /** |
103 | * Remote Feed Extension Autodiscovery |
104 | * @see SimplePie::set_autodiscovery_level() |
105 | */ |
106 | define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8); |
107 | |
108 | /** |
109 | * Remote Feed Body Autodiscovery |
110 | * @see SimplePie::set_autodiscovery_level() |
111 | */ |
112 | define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16); |
113 | |
114 | /** |
115 | * All Feed Autodiscovery |
116 | * @see SimplePie::set_autodiscovery_level() |
117 | */ |
118 | define('SIMPLEPIE_LOCATOR_ALL', 31); |
119 | |
120 | /** |
121 | * No known feed type |
122 | */ |
123 | define('SIMPLEPIE_TYPE_NONE', 0); |
124 | |
125 | /** |
126 | * RSS 0.90 |
127 | */ |
128 | define('SIMPLEPIE_TYPE_RSS_090', 1); |
129 | |
130 | /** |
131 | * RSS 0.91 (Netscape) |
132 | */ |
133 | define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2); |
134 | |
135 | /** |
136 | * RSS 0.91 (Userland) |
137 | */ |
138 | define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4); |
139 | |
140 | /** |
141 | * RSS 0.91 (both Netscape and Userland) |
142 | */ |
143 | define('SIMPLEPIE_TYPE_RSS_091', 6); |
144 | |
145 | /** |
146 | * RSS 0.92 |
147 | */ |
148 | define('SIMPLEPIE_TYPE_RSS_092', 8); |
149 | |
150 | /** |
151 | * RSS 0.93 |
152 | */ |
153 | define('SIMPLEPIE_TYPE_RSS_093', 16); |
154 | |
155 | /** |
156 | * RSS 0.94 |
157 | */ |
158 | define('SIMPLEPIE_TYPE_RSS_094', 32); |
159 | |
160 | /** |
161 | * RSS 1.0 |
162 | */ |
163 | define('SIMPLEPIE_TYPE_RSS_10', 64); |
164 | |
165 | /** |
166 | * RSS 2.0 |
167 | */ |
168 | define('SIMPLEPIE_TYPE_RSS_20', 128); |
169 | |
170 | /** |
171 | * RDF-based RSS |
172 | */ |
173 | define('SIMPLEPIE_TYPE_RSS_RDF', 65); |
174 | |
175 | /** |
176 | * Non-RDF-based RSS (truly intended as syndication format) |
177 | */ |
178 | define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190); |
179 | |
180 | /** |
181 | * All RSS |
182 | */ |
183 | define('SIMPLEPIE_TYPE_RSS_ALL', 255); |
184 | |
185 | /** |
186 | * Atom 0.3 |
187 | */ |
188 | define('SIMPLEPIE_TYPE_ATOM_03', 256); |
189 | |
190 | /** |
191 | * Atom 1.0 |
192 | */ |
193 | define('SIMPLEPIE_TYPE_ATOM_10', 512); |
194 | |
195 | /** |
196 | * All Atom |
197 | */ |
198 | define('SIMPLEPIE_TYPE_ATOM_ALL', 768); |
199 | |
200 | /** |
201 | * All feed types |
202 | */ |
203 | define('SIMPLEPIE_TYPE_ALL', 1023); |
204 | |
205 | /** |
206 | * No construct |
207 | */ |
208 | define('SIMPLEPIE_CONSTRUCT_NONE', 0); |
209 | |
210 | /** |
211 | * Text construct |
212 | */ |
213 | define('SIMPLEPIE_CONSTRUCT_TEXT', 1); |
214 | |
215 | /** |
216 | * HTML construct |
217 | */ |
218 | define('SIMPLEPIE_CONSTRUCT_HTML', 2); |
219 | |
220 | /** |
221 | * XHTML construct |
222 | */ |
223 | define('SIMPLEPIE_CONSTRUCT_XHTML', 4); |
224 | |
225 | /** |
226 | * base64-encoded construct |
227 | */ |
228 | define('SIMPLEPIE_CONSTRUCT_BASE64', 8); |
229 | |
230 | /** |
231 | * IRI construct |
232 | */ |
233 | define('SIMPLEPIE_CONSTRUCT_IRI', 16); |
234 | |
235 | /** |
236 | * A construct that might be HTML |
237 | */ |
238 | define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32); |
239 | |
240 | /** |
241 | * All constructs |
242 | */ |
243 | define('SIMPLEPIE_CONSTRUCT_ALL', 63); |
244 | |
245 | /** |
246 | * Don't change case |
247 | */ |
248 | define('SIMPLEPIE_SAME_CASE', 1); |
249 | |
250 | /** |
251 | * Change to lowercase |
252 | */ |
253 | define('SIMPLEPIE_LOWERCASE', 2); |
254 | |
255 | /** |
256 | * Change to uppercase |
257 | */ |
258 | define('SIMPLEPIE_UPPERCASE', 4); |
259 | |
260 | /** |
261 | * PCRE for HTML attributes |
262 | */ |
263 | define('SIMPLEPIE_PCRE_HTML_ATTRIBUTE', '((?:[\x09\x0A\x0B\x0C\x0D\x20]+[^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?)*)[\x09\x0A\x0B\x0C\x0D\x20]*'); |
264 | |
265 | /** |
266 | * PCRE for XML attributes |
267 | */ |
268 | define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*'); |
269 | |
270 | /** |
271 | * XML Namespace |
272 | */ |
273 | define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace'); |
274 | |
275 | /** |
276 | * Atom 1.0 Namespace |
277 | */ |
278 | define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom'); |
279 | |
280 | /** |
281 | * Atom 0.3 Namespace |
282 | */ |
283 | define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#'); |
284 | |
285 | /** |
286 | * RDF Namespace |
287 | */ |
288 | define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); |
289 | |
290 | /** |
291 | * RSS 0.90 Namespace |
292 | */ |
293 | define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/'); |
294 | |
295 | /** |
296 | * RSS 1.0 Namespace |
297 | */ |
298 | define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/'); |
299 | |
300 | /** |
301 | * RSS 1.0 Content Module Namespace |
302 | */ |
303 | define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/'); |
304 | |
305 | /** |
306 | * RSS 2.0 Namespace |
307 | * (Stupid, I know, but I'm certain it will confuse people less with support.) |
308 | */ |
309 | define('SIMPLEPIE_NAMESPACE_RSS_20', ''); |
310 | |
311 | /** |
312 | * DC 1.0 Namespace |
313 | */ |
314 | define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/'); |
315 | |
316 | /** |
317 | * DC 1.1 Namespace |
318 | */ |
319 | define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/'); |
320 | |
321 | /** |
322 | * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace |
323 | */ |
324 | define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#'); |
325 | |
326 | /** |
327 | * GeoRSS Namespace |
328 | */ |
329 | define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss'); |
330 | |
331 | /** |
332 | * Media RSS Namespace |
333 | */ |
334 | define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/'); |
335 | |
336 | /** |
337 | * Wrong Media RSS Namespace |
338 | */ |
339 | define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss'); |
340 | |
341 | /** |
342 | * iTunes RSS Namespace |
343 | */ |
344 | define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd'); |
345 | |
346 | /** |
347 | * XHTML Namespace |
348 | */ |
349 | define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml'); |
350 | |
351 | /** |
352 | * IANA Link Relations Registry |
353 | */ |
354 | define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/'); |
355 | |
356 | /** |
357 | * Whether we're running on PHP5 |
358 | */ |
359 | define('SIMPLEPIE_PHP5', version_compare(PHP_VERSION, '5.0.0', '>=')); |
360 | |
361 | /** |
362 | * No file source |
363 | */ |
364 | define('SIMPLEPIE_FILE_SOURCE_NONE', 0); |
365 | |
366 | /** |
367 | * Remote file source |
368 | */ |
369 | define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1); |
370 | |
371 | /** |
372 | * Local file source |
373 | */ |
374 | define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2); |
375 | |
376 | /** |
377 | * fsockopen() file source |
378 | */ |
379 | define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4); |
380 | |
381 | /** |
382 | * cURL file source |
383 | */ |
384 | define('SIMPLEPIE_FILE_SOURCE_CURL', 8); |
385 | |
386 | /** |
387 | * file_get_contents() file source |
388 | */ |
389 | define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16); |
390 | |
391 | /** |
392 | * SimplePie |
393 | * |
394 | * @package SimplePie |
395 | */ |
396 | class SimplePie |
397 | { |
398 | /** |
399 | * @var array Raw data |
400 | * @access private |
401 | */ |
402 | var $data = array(); |
403 | |
404 | /** |
405 | * @var mixed Error string |
406 | * @access private |
407 | */ |
408 | var $error; |
409 | |
410 | /** |
411 | * @var object Instance of SimplePie_Sanitize (or other class) |
412 | * @see SimplePie::set_sanitize_class() |
413 | * @access private |
414 | */ |
415 | var $sanitize; |
416 | |
417 | /** |
418 | * @var string SimplePie Useragent |
419 | * @see SimplePie::set_useragent() |
420 | * @access private |
421 | */ |
422 | var $useragent = SIMPLEPIE_USERAGENT; |
423 | |
424 | /** |
425 | * @var string Feed URL |
426 | * @see SimplePie::set_feed_url() |
427 | * @access private |
428 | */ |
429 | var $feed_url; |
430 | |
431 | /** |
432 | * @var object Instance of SimplePie_File to use as a feed |
433 | * @see SimplePie::set_file() |
434 | * @access private |
435 | */ |
436 | var $file; |
437 | |
438 | /** |
439 | * @var string Raw feed data |
440 | * @see SimplePie::set_raw_data() |
441 | * @access private |
442 | */ |
443 | var $raw_data; |
444 | |
445 | /** |
446 | * @var int Timeout for fetching remote files |
447 | * @see SimplePie::set_timeout() |
448 | * @access private |
449 | */ |
450 | var $timeout = 10; |
451 | |
452 | /** |
453 | * @var bool Forces fsockopen() to be used for remote files instead |
454 | * of cURL, even if a new enough version is installed |
455 | * @see SimplePie::force_fsockopen() |
456 | * @access private |
457 | */ |
458 | var $force_fsockopen = false; |
459 | |
460 | /** |
461 | * @var bool Force the given data/URL to be treated as a feed no matter what |
462 | * it appears like |
463 | * @see SimplePie::force_feed() |
464 | * @access private |
465 | */ |
466 | var $force_feed = false; |
467 | |
468 | /** |
469 | * @var bool Enable/Disable XML dump |
470 | * @see SimplePie::enable_xml_dump() |
471 | * @access private |
472 | */ |
473 | var $xml_dump = false; |
474 | |
475 | /** |
476 | * @var bool Enable/Disable Caching |
477 | * @see SimplePie::enable_cache() |
478 | * @access private |
479 | */ |
480 | var $cache = true; |
481 | |
482 | /** |
483 | * @var int Cache duration (in seconds) |
484 | * @see SimplePie::set_cache_duration() |
485 | * @access private |
486 | */ |
487 | var $cache_duration = 3600; |
488 | |
489 | /** |
490 | * @var int Auto-discovery cache duration (in seconds) |
491 | * @see SimplePie::set_autodiscovery_cache_duration() |
492 | * @access private |
493 | */ |
494 | var $autodiscovery_cache_duration = 604800; // 7 Days. |
495 | |
496 | /** |
497 | * @var string Cache location (relative to executing script) |
498 | * @see SimplePie::set_cache_location() |
499 | * @access private |
500 | */ |
501 | var $cache_location = './cache'; |
502 | |
503 | /** |
504 | * @var string Function that creates the cache filename |
505 | * @see SimplePie::set_cache_name_function() |
506 | * @access private |
507 | */ |
508 | var $cache_name_function = 'md5'; |
509 | |
510 | /** |
511 | * @var bool Reorder feed by date descending |
512 | * @see SimplePie::enable_order_by_date() |
513 | * @access private |
514 | */ |
515 | var $order_by_date = true; |
516 | |
517 | /** |
518 | * @var mixed Force input encoding to be set to the follow value |
519 | * (false, or anything type-cast to false, disables this feature) |
520 | * @see SimplePie::set_input_encoding() |
521 | * @access private |
522 | */ |
523 | var $input_encoding = false; |
524 | |
525 | /** |
526 | * @var int Feed Autodiscovery Level |
527 | * @see SimplePie::set_autodiscovery_level() |
528 | * @access private |
529 | */ |
530 | var $autodiscovery = SIMPLEPIE_LOCATOR_ALL; |
531 | |
532 | /** |
533 | * @var string Class used for caching feeds |
534 | * @see SimplePie::set_cache_class() |
535 | * @access private |
536 | */ |
537 | var $cache_class = 'SimplePie_Cache'; |
538 | |
539 | /** |
540 | * @var string Class used for locating feeds |
541 | * @see SimplePie::set_locator_class() |
542 | * @access private |
543 | */ |
544 | var $locator_class = 'SimplePie_Locator'; |
545 | |
546 | /** |
547 | * @var string Class used for parsing feeds |
548 | * @see SimplePie::set_parser_class() |
549 | * @access private |
550 | */ |
551 | var $parser_class = 'SimplePie_Parser'; |
552 | |
553 | /** |
554 | * @var string Class used for fetching feeds |
555 | * @see SimplePie::set_file_class() |
556 | * @access private |
557 | */ |
558 | var $file_class = 'SimplePie_File'; |
559 | |
560 | /** |
561 | * @var string Class used for items |
562 | * @see SimplePie::set_item_class() |
563 | * @access private |
564 | */ |
565 | var $item_class = 'SimplePie_Item'; |
566 | |
567 | /** |
568 | * @var string Class used for authors |
569 | * @see SimplePie::set_author_class() |
570 | * @access private |
571 | */ |
572 | var $author_class = 'SimplePie_Author'; |
573 | |
574 | /** |
575 | * @var string Class used for categories |
576 | * @see SimplePie::set_category_class() |
577 | * @access private |
578 | */ |
579 | var $category_class = 'SimplePie_Category'; |
580 | |
581 | /** |
582 | * @var string Class used for enclosures |
583 | * @see SimplePie::set_enclosures_class() |
584 | * @access private |
585 | */ |
586 | var $enclosure_class = 'SimplePie_Enclosure'; |
587 | |
588 | /** |
589 | * @var string Class used for Media RSS <media:text> captions |
590 | * @see SimplePie::set_caption_class() |
591 | * @access private |
592 | */ |
593 | var $caption_class = 'SimplePie_Caption'; |
594 | |
595 | /** |
596 | * @var string Class used for Media RSS <media:copyright> |
597 | * @see SimplePie::set_copyright_class() |
598 | * @access private |
599 | */ |
600 | var $copyright_class = 'SimplePie_Copyright'; |
601 | |
602 | /** |
603 | * @var string Class used for Media RSS <media:credit> |
604 | * @see SimplePie::set_credit_class() |
605 | * @access private |
606 | */ |
607 | var $credit_class = 'SimplePie_Credit'; |
608 | |
609 | /** |
610 | * @var string Class used for Media RSS <media:rating> |
611 | * @see SimplePie::set_rating_class() |
612 | * @access private |
613 | */ |
614 | var $rating_class = 'SimplePie_Rating'; |
615 | |
616 | /** |
617 | * @var string Class used for Media RSS <media:restriction> |
618 | * @see SimplePie::set_restriction_class() |
619 | * @access private |
620 | */ |
621 | var $restriction_class = 'SimplePie_Restriction'; |
622 | |
623 | /** |
624 | * @var string Class used for content-type sniffing |
625 | * @see SimplePie::set_content_type_sniffer_class() |
626 | * @access private |
627 | */ |
628 | var $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer'; |
629 | |
630 | /** |
631 | * @var string Class used for item sources. |
632 | * @see SimplePie::set_source_class() |
633 | * @access private |
634 | */ |
635 | var $source_class = 'SimplePie_Source'; |
636 | |
637 | /** |
638 | * @var mixed Set javascript query string parameter (false, or |
639 | * anything type-cast to false, disables this feature) |
640 | * @see SimplePie::set_javascript() |
641 | * @access private |
642 | */ |
643 | var $javascript = 'js'; |
644 | |
645 | /** |
646 | * @var int Maximum number of feeds to check with autodiscovery |
647 | * @see SimplePie::set_max_checked_feeds() |
648 | * @access private |
649 | */ |
650 | var $max_checked_feeds = 10; |
651 | |
652 | /** |
653 | * @var array All the feeds found during the autodiscovery process |
654 | * @see SimplePie::get_all_discovered_feeds() |
655 | * @access private |
656 | */ |
657 | var $all_discovered_feeds = array(); |
658 | |
659 | /** |
660 | * @var string Web-accessible path to the handler_favicon.php file. |
661 | * @see SimplePie::set_favicon_handler() |
662 | * @access private |
663 | */ |
664 | var $favicon_handler = ''; |
665 | |
666 | /** |
667 | * @var string Web-accessible path to the handler_image.php file. |
668 | * @see SimplePie::set_image_handler() |
669 | * @access private |
670 | */ |
671 | var $image_handler = ''; |
672 | |
673 | /** |
674 | * @var array Stores the URLs when multiple feeds are being initialized. |
675 | * @see SimplePie::set_feed_url() |
676 | * @access private |
677 | */ |
678 | var $multifeed_url = array(); |
679 | |
680 | /** |
681 | * @var array Stores SimplePie objects when multiple feeds initialized. |
682 | * @access private |
683 | */ |
684 | var $multifeed_objects = array(); |
685 | |
686 | /** |
687 | * @var array Stores the get_object_vars() array for use with multifeeds. |
688 | * @see SimplePie::set_feed_url() |
689 | * @access private |
690 | */ |
691 | var $config_settings = null; |
692 | |
693 | /** |
694 | * @var integer Stores the number of items to return per-feed with multifeeds. |
695 | * @see SimplePie::set_item_limit() |
696 | * @access private |
697 | */ |
698 | var $item_limit = 0; |
699 | |
700 | /** |
701 | * @var array Stores the default attributes to be stripped by strip_attributes(). |
702 | * @see SimplePie::strip_attributes() |
703 | * @access private |
704 | */ |
705 | var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'); |
706 | |
707 | /** |
708 | * @var array Stores the default tags to be stripped by strip_htmltags(). |
709 | * @see SimplePie::strip_htmltags() |
710 | * @access private |
711 | */ |
712 | var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'); |
713 | |
714 | /** |
715 | * The SimplePie class contains feed level data and options |
716 | * |
717 | * There are two ways that you can create a new SimplePie object. The first |
718 | * is by passing a feed URL as a parameter to the SimplePie constructor |
719 | * (as well as optionally setting the cache location and cache expiry). This |
720 | * will initialise the whole feed with all of the default settings, and you |
721 | * can begin accessing methods and properties immediately. |
722 | * |
723 | * The second way is to create the SimplePie object with no parameters |
724 | * at all. This will enable you to set configuration options. After setting |
725 | * them, you must initialise the feed using $feed->init(). At that point the |
726 | * object's methods and properties will be available to you. This format is |
727 | * what is used throughout this documentation. |
728 | * |
729 | * @access public |
730 | * @since 1.0 Preview Release |
731 | * @param string $feed_url This is the URL you want to parse. |
732 | * @param string $cache_location This is where you want the cache to be stored. |
733 | * @param int $cache_duration This is the number of seconds that you want to store the cache file for. |
734 | */ |
735 | function SimplePie($feed_url = null, $cache_location = null, $cache_duration = null) |
736 | { |
737 | // Other objects, instances created here so we can set options on them |
738 | $this->sanitize =& new SimplePie_Sanitize; |
739 | |
740 | // Set options if they're passed to the constructor |
741 | if ($cache_location !== null) |
742 | { |
743 | $this->set_cache_location($cache_location); |
744 | } |
745 | |
746 | if ($cache_duration !== null) |
747 | { |
748 | $this->set_cache_duration($cache_duration); |
749 | } |
750 | |
751 | // Only init the script if we're passed a feed URL |
752 | if ($feed_url !== null) |
753 | { |
754 | $this->set_feed_url($feed_url); |
755 | $this->init(); |
756 | } |
757 | } |
758 | |
759 | /** |
760 | * Used for converting object to a string |
761 | */ |
762 | function __toString() |
763 | { |
764 | return md5(serialize($this->data)); |
765 | } |
766 | |
767 | /** |
768 | * Remove items that link back to this before destroying this object |
769 | */ |
770 | function __destruct() |
771 | { |
772 | if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode')) |
773 | { |
774 | if (!empty($this->data['items'])) |
775 | { |
776 | foreach ($this->data['items'] as $item) |
777 | { |
778 | $item->__destruct(); |
779 | } |
780 | unset($item, $this->data['items']); |
781 | } |
782 | if (!empty($this->data['ordered_items'])) |
783 | { |
784 | foreach ($this->data['ordered_items'] as $item) |
785 | { |
786 | $item->__destruct(); |
787 | } |
788 | unset($item, $this->data['ordered_items']); |
789 | } |
790 | } |
791 | } |
792 | |
793 | /** |
794 | * Force the given data/URL to be treated as a feed no matter what it |
795 | * appears like |
796 | * |
797 | * @access public |
798 | * @since 1.1 |
799 | * @param bool $enable Force the given data/URL to be treated as a feed |
800 | */ |
801 | function force_feed($enable = false) |
802 | { |
803 | $this->force_feed = (bool) $enable; |
804 | } |
805 | |
806 | /** |
807 | * This is the URL of the feed you want to parse. |
808 | * |
809 | * This allows you to enter the URL of the feed you want to parse, or the |
810 | * website you want to try to use auto-discovery on. This takes priority |
811 | * over any set raw data. |
812 | * |
813 | * You can set multiple feeds to mash together by passing an array instead |
814 | * of a string for the $url. Remember that with each additional feed comes |
815 | * additional processing and resources. |
816 | * |
817 | * @access public |
818 | * @since 1.0 Preview Release |
819 | * @param mixed $url This is the URL (or array of URLs) that you want to parse. |
820 | * @see SimplePie::set_raw_data() |
821 | */ |
822 | function set_feed_url($url) |
823 | { |
824 | if (is_array($url)) |
825 | { |
826 | $this->multifeed_url = array(); |
827 | foreach ($url as $value) |
828 | { |
829 | $this->multifeed_url[] = SimplePie_Misc::fix_protocol($value, 1); |
830 | } |
831 | } |
832 | else |
833 | { |
834 | $this->feed_url = SimplePie_Misc::fix_protocol($url, 1); |
835 | } |
836 | } |
837 | |
838 | /** |
839 | * Provides an instance of SimplePie_File to use as a feed |
840 | * |
841 | * @access public |
842 | * @param object &$file Instance of SimplePie_File (or subclass) |
843 | * @return bool True on success, false on failure |
844 | */ |
845 | function set_file(&$file) |
846 | { |
847 | if (is_a($file, 'SimplePie_File')) |
848 | { |
849 | $this->feed_url = $file->url; |
850 | $this->file =& $file; | //Arbitrary file disclosing
|
851 | return true; |
852 | } |
853 | return false; |
854 | } |
855 | |
856 | /** |
857 | * Allows you to use a string of RSS/Atom data instead of a remote feed. |
858 | * |
859 | * If you have a feed available as a string in PHP, you can tell SimplePie |
860 | * to parse that data string instead of a remote feed. Any set feed URL |
861 | * takes precedence. |
862 | * |
863 | * @access public |
864 | * @since 1.0 Beta 3 |
865 | * @param string $data RSS or Atom data as a string. |
866 | * @see SimplePie::set_feed_url() |
867 | */ |
868 | function set_raw_data($data) |
869 | { |
870 | $this->raw_data = $data; |
871 | } |
872 | |
873 | /** |
874 | * Allows you to override the default timeout for fetching remote feeds. |
875 | * |
876 | * This allows you to change the maximum time the feed's server to respond |
877 | * and send the feed back. |
878 | * |
879 | * @access public |
880 | * @since 1.0 Beta 3 |
881 | * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed. |
882 | */ |
883 | function set_timeout($timeout = 10) |
884 | { |
885 | $this->timeout = (int) $timeout; |
886 | } |
887 | |
888 | /** |
889 | * Forces SimplePie to use fsockopen() instead of the preferred cURL |
890 | * functions. |
891 | * |
892 | * @access public |
893 | * @since 1.0 Beta 3 |
894 | * @param bool $enable Force fsockopen() to be used |
895 | */ |
896 | function force_fsockopen($enable = false) |
897 | { |
898 | $this->force_fsockopen = (bool) $enable; |
899 | } |
900 | |
901 | /** |
902 | * Outputs the raw XML content of the feed, after it has gone through |
903 | * SimplePie's filters. |
904 | * |
905 | * Used only for debugging, this function will output the XML content as |
906 | * text/xml. When SimplePie reads in a feed, it does a bit of cleaning up |
907 | * before trying to parse it. Many parts of the feed are re-written in |
908 | * memory, and in the end, you have a parsable feed. XML dump shows you the |
909 | * actual XML that SimplePie tries to parse, which may or may not be very |
910 | * different from the original feed. |
911 | * |
912 | * @access public |
913 | * @since 1.0 Preview Release |
914 | * @param bool $enable Enable XML dump |
915 | */ |
916 | function enable_xml_dump($enable = false) |
917 | { |
918 | $this->xml_dump = (bool) $enable; |
919 | } |
920 | |
921 | /** |
922 | * Enables/disables caching in SimplePie. |
923 | * |
924 | * This option allows you to disable caching all-together in SimplePie. |
925 | * However, disabling the cache can lead to longer load times. |
926 | * |
927 | * @access public |
928 | * @since 1.0 Preview Release |
929 | * @param bool $enable Enable caching |
930 | */ |
931 | function enable_cache($enable = true) |
932 | { |
933 | $this->cache = (bool) $enable; |
934 | } |
935 | |
936 | /** |
937 | * Set the length of time (in seconds) that the contents of a feed |
938 | * will be cached. |
939 | * |
940 | * @access public |
941 | * @param int $seconds The feed content cache duration. |
942 | */ |
943 | function set_cache_duration($seconds = 3600) |
944 | { |
945 | $this->cache_duration = (int) $seconds; |
946 | } |
947 | |
948 | /** |
949 | * Set the length of time (in seconds) that the autodiscovered feed |
950 | * URL will be cached. |
951 | * |
952 | * @access public |
953 | * @param int $seconds The autodiscovered feed URL cache duration. |
954 | */ |
955 | function set_autodiscovery_cache_duration($seconds = 604800) |
956 | { |
957 | $this->autodiscovery_cache_duration = (int) $seconds; |
958 | } |
959 | |
960 | /** |
961 | * Set the file system location where the cached files should be stored. |
962 | * |
963 | * @access public |
964 | * @param string $location The file system location. |
965 | */ |
966 | function set_cache_location($location = './cache') |
967 | { |
968 | $this->cache_location = (string) $location; |
969 | } |
970 | |
971 | /** |
972 | * Determines whether feed items should be sorted into reverse chronological order. |
973 | * |
974 | * @access public |
975 | * @param bool $enable Sort as reverse chronological order. |
976 | */ |
977 | function enable_order_by_date($enable = true) |
978 | { |
979 | $this->order_by_date = (bool) $enable; |
980 | } |
981 | |
982 | /** |
983 | * Allows you to override the character encoding reported by the feed. |
984 | * |
985 | * @access public |
986 | * @param string $encoding Character encoding. |
987 | */ |
988 | function set_input_encoding($encoding = false) |
989 | { |
990 | if ($encoding) |
991 | { |
992 | $this->input_encoding = (string) $encoding; |
993 | } |
994 | else |
995 | { |
996 | $this->input_encoding = false; |
997 | } |
998 | } |
999 | |
1000 | /** |