diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/feed.php --- a/wp/wp-includes/feed.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/feed.php Mon Oct 14 18:28:13 2019 +0200 @@ -23,8 +23,8 @@ * @param string $show See get_bloginfo() for possible values. * @return string */ -function get_bloginfo_rss($show = '') { - $info = strip_tags(get_bloginfo($show)); +function get_bloginfo_rss( $show = '' ) { + $info = strip_tags( get_bloginfo( $show ) ); /** * Filters the bloginfo for use in RSS feeds. * @@ -51,7 +51,7 @@ * * @param string $show See get_bloginfo() for possible values. */ -function bloginfo_rss($show = '') { +function bloginfo_rss( $show = '' ) { /** * Filters the bloginfo for display in RSS feeds. * @@ -182,13 +182,14 @@ * @param string $feed_type The type of feed. rss2 | atom | rss | rdf * @return string The filtered content. */ -function get_the_content_feed($feed_type = null) { - if ( !$feed_type ) +function get_the_content_feed( $feed_type = null ) { + if ( ! $feed_type ) { $feed_type = get_default_feed(); + } /** This filter is documented in wp-includes/post-template.php */ $content = apply_filters( 'the_content', get_the_content() ); - $content = str_replace(']]>', ']]>', $content); + $content = str_replace( ']]>', ']]>', $content ); /** * Filters the post content for use in feeds. * @@ -208,8 +209,8 @@ * * @param string $feed_type The type of feed. rss2 | atom | rss | rdf */ -function the_content_feed($feed_type = null) { - echo get_the_content_feed($feed_type); +function the_content_feed( $feed_type = null ) { + echo get_the_content_feed( $feed_type ); } /** @@ -270,8 +271,8 @@ * * @param int|WP_Comment $comment_id Optional comment object or id. Defaults to global comment object. */ -function comment_guid($comment_id = null) { - echo esc_url( get_comment_guid($comment_id) ); +function comment_guid( $comment_id = null ) { + echo esc_url( get_comment_guid( $comment_id ) ); } /** @@ -282,13 +283,14 @@ * @param int|WP_Comment $comment_id Optional comment object or id. Defaults to global comment object. * @return false|string false on failure or guid for comment on success. */ -function get_comment_guid($comment_id = null) { - $comment = get_comment($comment_id); +function get_comment_guid( $comment_id = null ) { + $comment = get_comment( $comment_id ); - if ( !is_object($comment) ) + if ( ! is_object( $comment ) ) { return false; + } - return get_the_guid($comment->comment_post_ID) . '#comment-' . $comment->comment_ID; + return get_the_guid( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; } /** @@ -371,35 +373,42 @@ * @param string $type Optional, default is the type returned by get_default_feed(). * @return string All of the post categories for displaying in the feed. */ -function get_the_category_rss($type = null) { - if ( empty($type) ) +function get_the_category_rss( $type = null ) { + if ( empty( $type ) ) { $type = get_default_feed(); + } $categories = get_the_category(); - $tags = get_the_tags(); - $the_list = ''; - $cat_names = array(); + $tags = get_the_tags(); + $the_list = ''; + $cat_names = array(); $filter = 'rss'; - if ( 'atom' == $type ) + if ( 'atom' == $type ) { $filter = 'raw'; + } - if ( !empty($categories) ) foreach ( (array) $categories as $category ) { - $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); + if ( ! empty( $categories ) ) { + foreach ( (array) $categories as $category ) { + $cat_names[] = sanitize_term_field( 'name', $category->name, $category->term_id, 'category', $filter ); + } } - if ( !empty($tags) ) foreach ( (array) $tags as $tag ) { - $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); + if ( ! empty( $tags ) ) { + foreach ( (array) $tags as $tag ) { + $cat_names[] = sanitize_term_field( 'name', $tag->name, $tag->term_id, 'post_tag', $filter ); + } } - $cat_names = array_unique($cat_names); + $cat_names = array_unique( $cat_names ); foreach ( $cat_names as $cat_name ) { - if ( 'rdf' == $type ) + if ( 'rdf' == $type ) { $the_list .= "\t\t\n"; - elseif ( 'atom' == $type ) + } elseif ( 'atom' == $type ) { $the_list .= sprintf( '', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) ); - else - $the_list .= "\t\t\n"; + } else { + $the_list .= "\t\t\n"; + } } /** @@ -422,8 +431,8 @@ * * @param string $type Optional, default is the type returned by get_default_feed(). */ -function the_category_rss($type = null) { - echo get_the_category_rss($type); +function the_category_rss( $type = null ) { + echo get_the_category_rss( $type ); } /** @@ -434,11 +443,12 @@ * @since 2.2.0 */ function html_type_rss() { - $type = get_bloginfo('html_type'); - if (strpos($type, 'xhtml') !== false) + $type = get_bloginfo( 'html_type' ); + if ( strpos( $type, 'xhtml' ) !== false ) { $type = 'xhtml'; - else + } else { $type = 'html'; + } echo $type; } @@ -457,16 +467,17 @@ * @since 1.5.0 */ function rss_enclosure() { - if ( post_password_required() ) + if ( post_password_required() ) { return; + } - foreach ( (array) get_post_custom() as $key => $val) { - if ($key == 'enclosure') { + foreach ( (array) get_post_custom() as $key => $val ) { + if ( $key == 'enclosure' ) { foreach ( (array) $val as $enc ) { - $enclosure = explode("\n", $enc); + $enclosure = explode( "\n", $enc ); // only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3' - $t = preg_split('/[ \t]/', trim($enclosure[2]) ); + $t = preg_split( '/[ \t]/', trim( $enclosure[2] ) ); $type = $t[0]; /** @@ -496,13 +507,14 @@ * @since 2.2.0 */ function atom_enclosure() { - if ( post_password_required() ) + if ( post_password_required() ) { return; + } foreach ( (array) get_post_custom() as $key => $val ) { - if ($key == 'enclosure') { + if ( $key == 'enclosure' ) { foreach ( (array) $val as $enc ) { - $enclosure = explode("\n", $enc); + $enclosure = explode( "\n", $enc ); /** * Filters the atom enclosure HTML link tag for the current post. * @@ -533,9 +545,9 @@ * @param string $data Input string * @return array array(type, value) */ -function prep_atom_text_construct($data) { - if (strpos($data, '<') === false && strpos($data, '&') === false) { - return array('text', $data); +function prep_atom_text_construct( $data ) { + if ( strpos( $data, '<' ) === false && strpos( $data, '&' ) === false ) { + return array( 'text', $data ); } if ( ! function_exists( 'xml_parser_create' ) ) { @@ -545,23 +557,23 @@ } $parser = xml_parser_create(); - xml_parse($parser, '
' . $data . '
', true); - $code = xml_get_error_code($parser); - xml_parser_free($parser); + xml_parse( $parser, '
' . $data . '
', true ); + $code = xml_get_error_code( $parser ); + xml_parser_free( $parser ); - if (!$code) { - if (strpos($data, '<') === false) { - return array('text', $data); + if ( ! $code ) { + if ( strpos( $data, '<' ) === false ) { + return array( 'text', $data ); } else { $data = "
$data
"; - return array('xhtml', $data); + return array( 'xhtml', $data ); } } - if (strpos($data, ']]>') === false) { - return array('html', ""); + if ( strpos( $data, ']]>' ) === false ) { + return array( 'html', "" ); } else { - return array('html', htmlspecialchars($data)); + return array( 'html', htmlspecialchars( $data ) ); } } @@ -611,7 +623,7 @@ * @since 2.5.0 */ function self_link() { - $host = @parse_url(home_url()); + $host = @parse_url( home_url() ); /** * Filters the current feed URL. * @@ -625,6 +637,54 @@ echo esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); } +/* + * Get the timestamp of the most recently modified post from WP_Query. + * + * If viewing a comment feed, the timestamp of the most recently modified + * comment will be returned. + * + * @global WP_Query $wp_query The global WP_Query object. + * + * @since 5.2.0 + * + * @param string $format Format of the timestamp to return, passed to mysql2date. + * + * @return string The timestamp. + */ +function get_feed_build_date( $format ) { + global $wp_query; + + if ( empty( $wp_query ) || ! $wp_query->have_posts() ) { + // Fallback to last time any post was modified or published. + return get_lastpostmodified( 'GMT' ); + } + + // Extract the post modified times from the posts. + $modified_times = wp_list_pluck( $wp_query->posts, 'post_modified_gmt' ); + + // If this is a comment feed, check those objects too. + if ( $wp_query->is_comment_feed() && $wp_query->comment_count ) { + // Extract the comment modified times from the comments. + $comment_times = wp_list_pluck( $wp_query->comments, 'comment_date_gmt' ); + + // Add the comment times to the post times for comparison. + $modified_times = array_merge( $modified_times, $comment_times ); + } + + // Determine the maximum modified time. + $max_modified_time = mysql2date( $format, max( $modified_times ), false ); + + /** + * Filters the date the last post or comment in the query was modified. + * + * @since 5.2.0 + * + * @param string $max_modified_time Date the last post or comment was modified in the query. + * @param string $format The date format requested in get_feed_build_date. + */ + return apply_filters( 'get_feed_build_date', $max_modified_time, $format ); +} + /** * Return the content type for specified feed type. * @@ -633,18 +693,19 @@ * @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'. */ function feed_content_type( $type = '' ) { - if ( empty($type) ) + if ( empty( $type ) ) { $type = get_default_feed(); + } $types = array( 'rss' => 'application/rss+xml', 'rss2' => 'application/rss+xml', 'rss-http' => 'text/xml', 'atom' => 'application/atom+xml', - 'rdf' => 'application/rdf+xml' + 'rdf' => 'application/rdf+xml', ); - $content_type = ( !empty($types[$type]) ) ? $types[$type] : 'application/octet-stream'; + $content_type = ( ! empty( $types[ $type ] ) ) ? $types[ $type ] : 'application/octet-stream'; /** * Filters the content type for a specific feed type. @@ -664,7 +725,7 @@ * * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged * using SimplePie's multifeed feature. - * See also {@link ​http://simplepie.org/wiki/faq/typical_multifeed_gotchas} + * See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas} * * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success */ @@ -703,8 +764,9 @@ $feed->init(); $feed->set_output_encoding( get_option( 'blog_charset' ) ); - if ( $feed->error() ) + if ( $feed->error() ) { return new WP_Error( 'simplepie-error', $feed->error() ); + } return $feed; }