66 |
67 |
67 /** |
68 /** |
68 * Retrieve the default feed. |
69 * Retrieve the default feed. |
69 * |
70 * |
70 * The default feed is 'rss2', unless a plugin changes it through the |
71 * The default feed is 'rss2', unless a plugin changes it through the |
71 * 'default_feed' filter. |
72 * {@see 'default_feed'} filter. |
72 * |
73 * |
73 * @since 2.5.0 |
74 * @since 2.5.0 |
74 * |
75 * |
75 * @return string Default feed, or for example 'rss2', 'atom', etc. |
76 * @return string Default feed, or for example 'rss2', 'atom', etc. |
76 */ |
77 */ |
77 function get_default_feed() { |
78 function get_default_feed() { |
78 /** |
79 /** |
79 * Filter the default feed type. |
80 * Filters the default feed type. |
80 * |
81 * |
81 * @since 2.5.0 |
82 * @since 2.5.0 |
82 * |
83 * |
83 * @param string $feed_type Type of default feed. Possible values include 'rss2', 'atom'. |
84 * @param string $feed_type Type of default feed. Possible values include 'rss2', 'atom'. |
84 * Default 'rss2'. |
85 * Default 'rss2'. |
89 |
90 |
90 /** |
91 /** |
91 * Retrieve the blog title for the feed title. |
92 * Retrieve the blog title for the feed title. |
92 * |
93 * |
93 * @since 2.2.0 |
94 * @since 2.2.0 |
94 * |
95 * @since 4.4.0 The optional `$sep` parameter was deprecated and renamed to `$deprecated`. |
95 * @param string $sep Optional. How to separate the title. See wp_title() for more info. |
96 * |
96 * @return string Error message on failure or blog title on success. |
97 * @param string $deprecated Unused.. |
97 */ |
98 * @return string The document title. |
98 function get_wp_title_rss( $sep = '»' ) { |
99 */ |
99 $title = wp_title( $sep, false ); |
100 function get_wp_title_rss( $deprecated = '–' ) { |
100 |
101 if ( '–' !== $deprecated ) { |
101 if ( is_wp_error( $title ) ) { |
102 /* translators: %s: 'document_title_separator' filter name */ |
102 return $title->get_error_message(); |
103 _deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>document_title_separator</code>' ) ); |
103 } |
104 } |
104 |
105 |
105 if ( $title && $sep && ' ' !== substr( $title, 0, 1 ) ) { |
106 /** |
106 $title = " $sep " . $title; |
107 * Filters the blog title for use as the feed title. |
107 } |
|
108 |
|
109 /** |
|
110 * Filter the blog title for use as the feed title. |
|
111 * |
108 * |
112 * @since 2.2.0 |
109 * @since 2.2.0 |
113 * |
110 * @since 4.4.0 The `$sep` parameter was deprecated and renamed to `$deprecated`. |
114 * @param string $title The current blog title. |
111 * |
115 * @param string $sep Separator used by wp_title(). |
112 * @param string $title The current blog title. |
116 */ |
113 * @param string $deprecated Unused. |
117 $title = apply_filters( 'get_wp_title_rss', $title, $sep ); |
114 */ |
118 return $title; |
115 return apply_filters( 'get_wp_title_rss', wp_get_document_title(), $deprecated ); |
119 } |
116 } |
120 |
117 |
121 /** |
118 /** |
122 * Display the blog title for display of the feed title. |
119 * Display the blog title for display of the feed title. |
123 * |
120 * |
124 * @since 2.2.0 |
121 * @since 2.2.0 |
125 * @see wp_title() $sep parameter usage. |
122 * @since 4.4.0 The optional `$sep` parameter was deprecated and renamed to `$deprecated`. |
126 * |
123 * |
127 * @param string $sep Optional. |
124 * @param string $deprecated Unused. |
128 */ |
125 */ |
129 function wp_title_rss( $sep = '»' ) { |
126 function wp_title_rss( $deprecated = '–' ) { |
130 /** |
127 if ( '–' !== $deprecated ) { |
131 * Filter the blog title for display of the feed title. |
128 /* translators: %s: 'document_title_separator' filter name */ |
|
129 _deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>document_title_separator</code>' ) ); |
|
130 } |
|
131 |
|
132 /** |
|
133 * Filters the blog title for display of the feed title. |
132 * |
134 * |
133 * @since 2.2.0 |
135 * @since 2.2.0 |
|
136 * @since 4.4.0 The `$sep` parameter was deprecated and renamed to `$deprecated`. |
134 * |
137 * |
135 * @see get_wp_title_rss() |
138 * @see get_wp_title_rss() |
136 * |
139 * |
137 * @param string $wp_title The current blog title. |
140 * @param string $wp_title_rss The current blog title. |
138 * @param string $sep Separator used by wp_title(). |
141 * @param string $deprecated Unused. |
139 */ |
142 */ |
140 echo apply_filters( 'wp_title_rss', get_wp_title_rss( $sep ), $sep ); |
143 echo apply_filters( 'wp_title_rss', get_wp_title_rss(), $deprecated ); |
141 } |
144 } |
142 |
145 |
143 /** |
146 /** |
144 * Retrieve the current post title for the feed. |
147 * Retrieve the current post title for the feed. |
145 * |
148 * |
184 |
188 |
185 /** This filter is documented in wp-includes/post-template.php */ |
189 /** This filter is documented in wp-includes/post-template.php */ |
186 $content = apply_filters( 'the_content', get_the_content() ); |
190 $content = apply_filters( 'the_content', get_the_content() ); |
187 $content = str_replace(']]>', ']]>', $content); |
191 $content = str_replace(']]>', ']]>', $content); |
188 /** |
192 /** |
189 * Filter the post content for use in feeds. |
193 * Filters the post content for use in feeds. |
190 * |
194 * |
191 * @since 2.9.0 |
195 * @since 2.9.0 |
192 * |
196 * |
193 * @param string $content The current post content. |
197 * @param string $content The current post content. |
194 * @param string $feed_type Type of feed. Possible values include 'rss2', 'atom'. |
198 * @param string $feed_type Type of feed. Possible values include 'rss2', 'atom'. |
262 /** |
266 /** |
263 * Display the feed GUID for the current comment. |
267 * Display the feed GUID for the current comment. |
264 * |
268 * |
265 * @since 2.5.0 |
269 * @since 2.5.0 |
266 * |
270 * |
267 * @param int|object $comment_id Optional comment object or id. Defaults to global comment object. |
271 * @param int|WP_Comment $comment_id Optional comment object or id. Defaults to global comment object. |
268 */ |
272 */ |
269 function comment_guid($comment_id = null) { |
273 function comment_guid($comment_id = null) { |
270 echo esc_url( get_comment_guid($comment_id) ); |
274 echo esc_url( get_comment_guid($comment_id) ); |
271 } |
275 } |
272 |
276 |
273 /** |
277 /** |
274 * Retrieve the feed GUID for the current comment. |
278 * Retrieve the feed GUID for the current comment. |
275 * |
279 * |
276 * @since 2.5.0 |
280 * @since 2.5.0 |
277 * |
281 * |
278 * @param int|object $comment_id Optional comment object or id. Defaults to global comment object. |
282 * @param int|WP_Comment $comment_id Optional comment object or id. Defaults to global comment object. |
279 * @return false|string false on failure or guid for comment on success. |
283 * @return false|string false on failure or guid for comment on success. |
280 */ |
284 */ |
281 function get_comment_guid($comment_id = null) { |
285 function get_comment_guid($comment_id = null) { |
282 $comment = get_comment($comment_id); |
286 $comment = get_comment($comment_id); |
283 |
287 |
289 |
293 |
290 /** |
294 /** |
291 * Display the link to the comments. |
295 * Display the link to the comments. |
292 * |
296 * |
293 * @since 1.5.0 |
297 * @since 1.5.0 |
294 */ |
298 * @since 4.4.0 Introduced the `$comment` argument. |
295 function comment_link() { |
299 * |
296 /** |
300 * @param int|WP_Comment $comment Optional. Comment object or id. Defaults to global comment object. |
297 * Filter the current comment's permalink. |
301 */ |
|
302 function comment_link( $comment = null ) { |
|
303 /** |
|
304 * Filters the current comment's permalink. |
298 * |
305 * |
299 * @since 3.6.0 |
306 * @since 3.6.0 |
300 * |
307 * |
301 * @see get_comment_link() |
308 * @see get_comment_link() |
302 * |
309 * |
303 * @param string $comment_permalink The current comment permalink. |
310 * @param string $comment_permalink The current comment permalink. |
304 */ |
311 */ |
305 echo esc_url( apply_filters( 'comment_link', get_comment_link() ) ); |
312 echo esc_url( apply_filters( 'comment_link', get_comment_link( $comment ) ) ); |
306 } |
313 } |
307 |
314 |
308 /** |
315 /** |
309 * Retrieve the current comment author for use in the feeds. |
316 * Retrieve the current comment author for use in the feeds. |
310 * |
317 * |
394 else |
401 else |
395 $the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n"; |
402 $the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n"; |
396 } |
403 } |
397 |
404 |
398 /** |
405 /** |
399 * Filter all of the post categories for display in a feed. |
406 * Filters all of the post categories for display in a feed. |
400 * |
407 * |
401 * @since 1.2.0 |
408 * @since 1.2.0 |
402 * |
409 * |
403 * @param string $the_list All of the RSS post categories. |
410 * @param string $the_list All of the RSS post categories. |
404 * @param string $type Type of feed. Possible values include 'rss2', 'atom'. |
411 * @param string $type Type of feed. Possible values include 'rss2', 'atom'. |
461 // only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3' |
468 // only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3' |
462 $t = preg_split('/[ \t]/', trim($enclosure[2]) ); |
469 $t = preg_split('/[ \t]/', trim($enclosure[2]) ); |
463 $type = $t[0]; |
470 $type = $t[0]; |
464 |
471 |
465 /** |
472 /** |
466 * Filter the RSS enclosure HTML link tag for the current post. |
473 * Filters the RSS enclosure HTML link tag for the current post. |
467 * |
474 * |
468 * @since 2.2.0 |
475 * @since 2.2.0 |
469 * |
476 * |
470 * @param string $html_link_tag The HTML link tag with a URI and other attributes. |
477 * @param string $html_link_tag The HTML link tag with a URI and other attributes. |
471 */ |
478 */ |
472 echo apply_filters( 'rss_enclosure', '<enclosure url="' . trim( htmlspecialchars( $enclosure[0] ) ) . '" length="' . trim( $enclosure[1] ) . '" type="' . $type . '" />' . "\n" ); |
479 echo apply_filters( 'rss_enclosure', '<enclosure url="' . esc_url( trim( $enclosure[0] ) ) . '" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( $type ) . '" />' . "\n" ); |
473 } |
480 } |
474 } |
481 } |
475 } |
482 } |
476 } |
483 } |
477 |
484 |
495 foreach ( (array) get_post_custom() as $key => $val ) { |
502 foreach ( (array) get_post_custom() as $key => $val ) { |
496 if ($key == 'enclosure') { |
503 if ($key == 'enclosure') { |
497 foreach ( (array) $val as $enc ) { |
504 foreach ( (array) $val as $enc ) { |
498 $enclosure = explode("\n", $enc); |
505 $enclosure = explode("\n", $enc); |
499 /** |
506 /** |
500 * Filter the atom enclosure HTML link tag for the current post. |
507 * Filters the atom enclosure HTML link tag for the current post. |
501 * |
508 * |
502 * @since 2.2.0 |
509 * @since 2.2.0 |
503 * |
510 * |
504 * @param string $html_link_tag The HTML link tag with a URI and other attributes. |
511 * @param string $html_link_tag The HTML link tag with a URI and other attributes. |
505 */ |
512 */ |
506 echo apply_filters( 'atom_enclosure', '<link href="' . trim( htmlspecialchars( $enclosure[0] ) ) . '" rel="enclosure" length="' . trim( $enclosure[1] ) . '" type="' . trim( $enclosure[2] ) . '" />' . "\n" ); |
513 echo apply_filters( 'atom_enclosure', '<link href="' . esc_url( trim( $enclosure[0] ) ) . '" rel="enclosure" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( trim( $enclosure[2] ) ) . '" />' . "\n" ); |
507 } |
514 } |
508 } |
515 } |
509 } |
516 } |
510 } |
517 } |
511 |
518 |
527 * @return array array(type, value) |
534 * @return array array(type, value) |
528 */ |
535 */ |
529 function prep_atom_text_construct($data) { |
536 function prep_atom_text_construct($data) { |
530 if (strpos($data, '<') === false && strpos($data, '&') === false) { |
537 if (strpos($data, '<') === false && strpos($data, '&') === false) { |
531 return array('text', $data); |
538 return array('text', $data); |
|
539 } |
|
540 |
|
541 if ( ! function_exists( 'xml_parser_create' ) ) { |
|
542 trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); |
|
543 |
|
544 return array( 'html', "<![CDATA[$data]]>" ); |
532 } |
545 } |
533 |
546 |
534 $parser = xml_parser_create(); |
547 $parser = xml_parser_create(); |
535 xml_parse($parser, '<div>' . $data . '</div>', true); |
548 xml_parse($parser, '<div>' . $data . '</div>', true); |
536 $code = xml_get_error_code($parser); |
549 $code = xml_get_error_code($parser); |
543 $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>"; |
556 $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>"; |
544 return array('xhtml', $data); |
557 return array('xhtml', $data); |
545 } |
558 } |
546 } |
559 } |
547 |
560 |
548 if (strpos($data, ']]>') == false) { |
561 if (strpos($data, ']]>') === false) { |
549 return array('html', "<![CDATA[$data]]>"); |
562 return array('html', "<![CDATA[$data]]>"); |
550 } else { |
563 } else { |
551 return array('html', htmlspecialchars($data)); |
564 return array('html', htmlspecialchars($data)); |
552 } |
565 } |
553 } |
566 } |
554 |
567 |
555 /** |
568 /** |
|
569 * Displays Site Icon in atom feeds. |
|
570 * |
|
571 * @since 4.3.0 |
|
572 * |
|
573 * @see get_site_icon_url() |
|
574 */ |
|
575 function atom_site_icon() { |
|
576 $url = get_site_icon_url( 32 ); |
|
577 if ( $url ) { |
|
578 echo "<icon>$url</icon>\n"; |
|
579 } |
|
580 } |
|
581 |
|
582 /** |
|
583 * Displays Site Icon in RSS2. |
|
584 * |
|
585 * @since 4.3.0 |
|
586 */ |
|
587 function rss2_site_icon() { |
|
588 $rss_title = get_wp_title_rss(); |
|
589 if ( empty( $rss_title ) ) { |
|
590 $rss_title = get_bloginfo_rss( 'name' ); |
|
591 } |
|
592 |
|
593 $url = get_site_icon_url( 32 ); |
|
594 if ( $url ) { |
|
595 echo ' |
|
596 <image> |
|
597 <url>' . convert_chars( $url ) . '</url> |
|
598 <title>' . $rss_title . '</title> |
|
599 <link>' . get_bloginfo_rss( 'url' ) . '</link> |
|
600 <width>32</width> |
|
601 <height>32</height> |
|
602 </image> ' . "\n"; |
|
603 } |
|
604 } |
|
605 |
|
606 /** |
556 * Display the link for the currently displayed feed in a XSS safe way. |
607 * Display the link for the currently displayed feed in a XSS safe way. |
557 * |
608 * |
558 * Generate a correct link for the atom:self element. |
609 * Generate a correct link for the atom:self element. |
559 * |
610 * |
560 * @since 2.5.0 |
611 * @since 2.5.0 |
561 */ |
612 */ |
562 function self_link() { |
613 function self_link() { |
563 $host = @parse_url(home_url()); |
614 $host = @parse_url(home_url()); |
564 /** |
615 /** |
565 * Filter the current feed URL. |
616 * Filters the current feed URL. |
566 * |
617 * |
567 * @since 3.6.0 |
618 * @since 3.6.0 |
568 * |
619 * |
569 * @see set_url_scheme() |
620 * @see set_url_scheme() |
570 * @see wp_unslash() |
621 * @see wp_unslash() |
576 |
627 |
577 /** |
628 /** |
578 * Return the content type for specified feed type. |
629 * Return the content type for specified feed type. |
579 * |
630 * |
580 * @since 2.8.0 |
631 * @since 2.8.0 |
|
632 * |
|
633 * @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'. |
581 */ |
634 */ |
582 function feed_content_type( $type = '' ) { |
635 function feed_content_type( $type = '' ) { |
583 if ( empty($type) ) |
636 if ( empty($type) ) |
584 $type = get_default_feed(); |
637 $type = get_default_feed(); |
585 |
638 |
586 $types = array( |
639 $types = array( |
587 'rss' => 'application/rss+xml', |
640 'rss' => 'application/rss+xml', |
588 'rss2' => 'application/rss+xml', |
641 'rss2' => 'application/rss+xml', |
589 'rss-http' => 'text/xml', |
642 'rss-http' => 'text/xml', |
590 'atom' => 'application/atom+xml', |
643 'atom' => 'application/atom+xml', |
591 'rdf' => 'application/rdf+xml' |
644 'rdf' => 'application/rdf+xml' |
592 ); |
645 ); |
593 |
646 |
594 $content_type = ( !empty($types[$type]) ) ? $types[$type] : 'application/octet-stream'; |
647 $content_type = ( !empty($types[$type]) ) ? $types[$type] : 'application/octet-stream'; |
595 |
648 |
596 /** |
649 /** |
597 * Filter the content type for a specific feed type. |
650 * Filters the content type for a specific feed type. |
598 * |
651 * |
599 * @since 2.8.0 |
652 * @since 2.8.0 |
600 * |
653 * |
601 * @param string $content_type Content type indicating the type of data that a feed contains. |
654 * @param string $content_type Content type indicating the type of data that a feed contains. |
602 * @param string $type Type of feed. Possible values include 'rss2', 'atom'. |
655 * @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'. |
603 * Default 'rss2'. |
|
604 */ |
656 */ |
605 return apply_filters( 'feed_content_type', $content_type, $type ); |
657 return apply_filters( 'feed_content_type', $content_type, $type ); |
606 } |
658 } |
607 |
659 |
608 /** |
660 /** |
615 * See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas} |
667 * See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas} |
616 * |
668 * |
617 * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success |
669 * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success |
618 */ |
670 */ |
619 function fetch_feed( $url ) { |
671 function fetch_feed( $url ) { |
620 require_once( ABSPATH . WPINC . '/class-feed.php' ); |
672 if ( ! class_exists( 'SimplePie', false ) ) { |
|
673 require_once( ABSPATH . WPINC . '/class-simplepie.php' ); |
|
674 } |
|
675 |
|
676 require_once( ABSPATH . WPINC . '/class-wp-feed-cache.php' ); |
|
677 require_once( ABSPATH . WPINC . '/class-wp-feed-cache-transient.php' ); |
|
678 require_once( ABSPATH . WPINC . '/class-wp-simplepie-file.php' ); |
|
679 require_once( ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.php' ); |
621 |
680 |
622 $feed = new SimplePie(); |
681 $feed = new SimplePie(); |
623 |
682 |
624 $feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' ); |
683 $feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' ); |
625 // We must manually overwrite $feed->sanitize because SimplePie's |
684 // We must manually overwrite $feed->sanitize because SimplePie's |
628 |
687 |
629 $feed->set_cache_class( 'WP_Feed_Cache' ); |
688 $feed->set_cache_class( 'WP_Feed_Cache' ); |
630 $feed->set_file_class( 'WP_SimplePie_File' ); |
689 $feed->set_file_class( 'WP_SimplePie_File' ); |
631 |
690 |
632 $feed->set_feed_url( $url ); |
691 $feed->set_feed_url( $url ); |
633 /** This filter is documented in wp-includes/class-feed.php */ |
692 /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */ |
634 $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) ); |
693 $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) ); |
635 /** |
694 /** |
636 * Fires just before processing the SimplePie feed object. |
695 * Fires just before processing the SimplePie feed object. |
637 * |
696 * |
638 * @since 3.0.0 |
697 * @since 3.0.0 |
639 * |
698 * |
640 * @param object &$feed SimplePie feed object, passed by reference. |
699 * @param object $feed SimplePie feed object (passed by reference). |
641 * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged. |
700 * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged. |
642 */ |
701 */ |
643 do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) ); |
702 do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) ); |
644 $feed->init(); |
703 $feed->init(); |
645 $feed->handle_content_type(); |
704 $feed->set_output_encoding( get_option( 'blog_charset' ) ); |
646 |
705 |
647 if ( $feed->error() ) |
706 if ( $feed->error() ) |
648 return new WP_Error( 'simplepie-error', $feed->error() ); |
707 return new WP_Error( 'simplepie-error', $feed->error() ); |
649 |
708 |
650 return $feed; |
709 return $feed; |