| 1 | Index: wp-includes/feed-rss2.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/feed-rss2.php (revision 13196) |
|---|
| 4 | +++ wp-includes/feed-rss2.php (working copy) |
|---|
| 5 | @@ -17,6 +17,7 @@ |
|---|
| 6 | xmlns:atom="http://www.w3.org/2005/Atom" |
|---|
| 7 | xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" |
|---|
| 8 | xmlns:slash="http://purl.org/rss/1.0/modules/slash/" |
|---|
| 9 | + xmlns:media="http://search.yahoo.com/mrss/" |
|---|
| 10 | <?php do_action('rss2_ns'); ?> |
|---|
| 11 | > |
|---|
| 12 | |
|---|
| 13 | @@ -54,6 +55,10 @@ |
|---|
| 14 | <slash:comments><?php echo get_comments_number(); ?></slash:comments> |
|---|
| 15 | <?php rss_enclosure(); ?> |
|---|
| 16 | <?php do_action('rss2_item'); ?> |
|---|
| 17 | + <?php |
|---|
| 18 | + $media_rss = apply_filters('media_rss', $media_rss = array()); |
|---|
| 19 | + media_print_rss( $media_rss ); |
|---|
| 20 | + ?> |
|---|
| 21 | </item> |
|---|
| 22 | <?php endwhile; ?> |
|---|
| 23 | </channel> |
|---|
| 24 | Index: wp-includes/feed.php |
|---|
| 25 | =================================================================== |
|---|
| 26 | --- wp-includes/feed.php (revision 13196) |
|---|
| 27 | +++ wp-includes/feed.php (working copy) |
|---|
| 28 | @@ -534,3 +534,128 @@ |
|---|
| 29 | |
|---|
| 30 | return $feed; |
|---|
| 31 | } |
|---|
| 32 | + |
|---|
| 33 | + |
|---|
| 34 | +/** |
|---|
| 35 | + * search for post content for for img tags, and add them to media_rss array |
|---|
| 36 | + * |
|---|
| 37 | + * @package WordPress |
|---|
| 38 | + * @subpackage Feed |
|---|
| 39 | + * @since 3.0 |
|---|
| 40 | + */ |
|---|
| 41 | +function wp_media_rss( $media_rss ){ |
|---|
| 42 | + |
|---|
| 43 | + global $mrss_gallery_lookup, $post; |
|---|
| 44 | + |
|---|
| 45 | + // Honor the feed settings. Don't include any media that isn't in the feed. |
|---|
| 46 | + if ( get_option( 'rss_use_excerpt' ) || !strlen( get_the_content() ) ) { |
|---|
| 47 | + $content = the_excerpt_rss(); |
|---|
| 48 | + } else { |
|---|
| 49 | + // If any galleries are processed, we need to capture the attachment IDs. |
|---|
| 50 | + add_filter( 'wp_get_attachment_link', 'media_rss_gallery_lookup', 10, 5 ); |
|---|
| 51 | + $content = apply_filters( 'the_content', get_the_content() ); |
|---|
| 52 | + remove_filter( 'wp_get_attachment_link', 'media_rss_gallery_lookup', 10, 5 ); |
|---|
| 53 | + $lookup = $mrss_gallery_lookup; |
|---|
| 54 | + unset( $mrss_gallery_lookup ); |
|---|
| 55 | + } |
|---|
| 56 | + |
|---|
| 57 | + if( !has_post_thumbnail( $post->ID ) ) |
|---|
| 58 | + return $media_rss; |
|---|
| 59 | + |
|---|
| 60 | + $image_id = get_post_thumbnail_id( $post->ID ); |
|---|
| 61 | + $image_data = wp_get_attachment_metadata( $image_id ); |
|---|
| 62 | + |
|---|
| 63 | + $item['content']['attr']['url'] = wp_get_attachment_url( $image_id ); |
|---|
| 64 | + $item['content']['attr']['medium'] = 'image'; |
|---|
| 65 | + if ( !empty( $image_data['image_meta']['title'] ) ) { |
|---|
| 66 | + $item['content']['children']['title']['attr']['type'] = 'plain'; |
|---|
| 67 | + $item['content']['children']['title']['children'][] = $image_data['image_meta']['title']; |
|---|
| 68 | + } elseif ( !empty( $image_data['image_meta']['caption'] ) ) { |
|---|
| 69 | + $item['content']['children']['title']['attr']['type'] = 'plain'; |
|---|
| 70 | + $item['content']['children']['title']['children'][] = $image_data['image_meta']['caption']; |
|---|
| 71 | + $item['content']['children']['description']['children'][] = $image_data['image_meta']['caption'] |
|---|
| 72 | + } |
|---|
| 73 | + if ( !empty( $image_data['sizes']['thumbnail ']) ) |
|---|
| 74 | + $item['content']['children']['thumbnail']['attr']['url'] = wp_get_attachment_thumb_url( $image_id ); |
|---|
| 75 | + |
|---|
| 76 | + $media_rss[] = $item; |
|---|
| 77 | + } |
|---|
| 78 | + |
|---|
| 79 | + return $media_rss; |
|---|
| 80 | +} |
|---|
| 81 | +add_filter( 'media_rss', 'wp_media_rss' ); |
|---|
| 82 | + |
|---|
| 83 | +function media_rss_url( $url ) { |
|---|
| 84 | + |
|---|
| 85 | + if ( preg_match( '!^https?://!', $url ) ) |
|---|
| 86 | + return $url; |
|---|
| 87 | + if ( $url{0} == '/' ) |
|---|
| 88 | + return rtrim( get_bloginfo('home'), '/' ) . $url; |
|---|
| 89 | + |
|---|
| 90 | + return get_bloginfo('home') . $url; |
|---|
| 91 | +} |
|---|
| 92 | + |
|---|
| 93 | +function media_rss_gallery_lookup( $link, $id, $size, $permalink, $icon ) { |
|---|
| 94 | + global $media_rss_gallery_lookup; |
|---|
| 95 | + |
|---|
| 96 | + preg_match( '/ src="(.*?)"/', $link, $matches ); |
|---|
| 97 | + $media_rss_gallery_lookup[$matches[1]] = $id; |
|---|
| 98 | + |
|---|
| 99 | + return $link; |
|---|
| 100 | +} |
|---|
| 101 | + |
|---|
| 102 | +/** |
|---|
| 103 | + * print media_rss array to generate mrss entries such as <media:content> |
|---|
| 104 | + * |
|---|
| 105 | + * @package WordPress |
|---|
| 106 | + * @subpackage Feed |
|---|
| 107 | + * @since 2.8.0 |
|---|
| 108 | + */ |
|---|
| 109 | +function media_print_rss( $media_rss ) { |
|---|
| 110 | + |
|---|
| 111 | + foreach( (array)$media_rss as $elements ) |
|---|
| 112 | + media_print_element( $elements ); |
|---|
| 113 | + |
|---|
| 114 | + echo "\n"; |
|---|
| 115 | +} |
|---|
| 116 | + |
|---|
| 117 | +function media_print_element( $elements, $indent = 2 ) { |
|---|
| 118 | + |
|---|
| 119 | + echo "\n"; |
|---|
| 120 | + foreach ( (array)$elements as $name => $data ) { |
|---|
| 121 | + |
|---|
| 122 | + echo str_repeat("\t", $indent) . "<media:$name"; |
|---|
| 123 | + if ( !empty($data['attr']) ) { |
|---|
| 124 | + foreach ( $data['attr'] as $attr => $value ) |
|---|
| 125 | + echo " $attr=\"" . ent2ncr($value) . "\""; |
|---|
| 126 | + } |
|---|
| 127 | + if ( !empty($data['children']) ) { |
|---|
| 128 | + $nl = false; |
|---|
| 129 | + echo ">"; |
|---|
| 130 | + foreach ( $data['children'] as $_name => $_data ) { |
|---|
| 131 | + |
|---|
| 132 | + if ( is_int($_name) ) { |
|---|
| 133 | + |
|---|
| 134 | + if ( !is_array( $_data ) ){ |
|---|
| 135 | + echo ent2ncr($_data); |
|---|
| 136 | + }else { |
|---|
| 137 | + //allow nested same level elements |
|---|
| 138 | + $nl = true; |
|---|
| 139 | + media_print_element( $_data, $indent + 1 ); |
|---|
| 140 | + } |
|---|
| 141 | + |
|---|
| 142 | + } else { |
|---|
| 143 | + $nl = true; |
|---|
| 144 | + media_print_element( array( $_name => $_data ), $indent + 1 ); |
|---|
| 145 | + } |
|---|
| 146 | + } |
|---|
| 147 | + |
|---|
| 148 | + if ( $nl ) |
|---|
| 149 | + echo str_repeat("\t", $indent); |
|---|
| 150 | + |
|---|
| 151 | + echo "</media:$name>\n"; |
|---|
| 152 | + } else { |
|---|
| 153 | + echo " />\n"; |
|---|
| 154 | + } |
|---|
| 155 | + } |
|---|
| 156 | +} |
|---|
| 157 | \ No newline at end of file |
|---|