Ticket #10337: 10337.9.patch
| File 10337.9.patch, 5.8 KB (added by Viper007Bond, 3 years ago) |
|---|
-
wp-includes/class-oembed.php
47 47 'http://revision3.com/*' => array( 'http://revision3.com/api/oembed/', false ), 48 48 'http://i*.photobucket.com/albums/*' => array( 'http://photobucket.com/oembed', false ), 49 49 'http://gi*.photobucket.com/groups/*' => array( 'http://photobucket.com/oembed', false ), 50 '#http://(www\.)?scribd.com/.*#i' => array( 'http://www.scribd.com/services/oembed', true )50 '#http://(www\.)?scribd.com/.*#i' => array( 'http://www.scribd.com/services/oembed', true ), 51 51 ) ); 52 53 // Fix Scribd embeds. They contain new lines in the middle of the HTML which breaks wpautop(). 54 add_filter( 'oembed_dataparse', array(&$this, 'strip_scribd_newlines'), 10, 3 ); 52 55 } 53 56 54 57 /** … … 87 90 if ( !$provider || false === $data = $this->fetch( $provider, $url, $args ) ) 88 91 return false; 89 92 90 return apply_filters( 'oembed_ output', $this->data2html( $data, $url ), $url, $args );93 return apply_filters( 'oembed_result', $this->data2html( $data, $url ), $url, $args ); 91 94 } 92 95 93 96 /** … … 206 209 return false; 207 210 208 211 $title = ( !empty($data->title) ) ? $data->title : ''; 209 return '<img src="' . esc_attr( clean_url( $data->url ) ) . '" alt="' . esc_attr($title) . '" width="' . esc_attr($data->width) . '" height="' . esc_attr($data->height) . '" />'; 212 $return = '<img src="' . esc_attr( clean_url( $data->url ) ) . '" alt="' . esc_attr($title) . '" width="' . esc_attr($data->width) . '" height="' . esc_attr($data->height) . '" />'; 213 break; 210 214 211 215 case 'video': 212 216 case 'rich': 213 return ( !empty($data->html) ) ? $data->html : false; 217 $return = ( !empty($data->html) ) ? $data->html : false; 218 break; 214 219 215 220 case 'link': 216 return ( !empty($data->title) ) ? '<a href="' . clean_url($url) . '">' . esc_html($data->title) . '</a>' : false; 221 $return = ( !empty($data->title) ) ? '<a href="' . clean_url($url) . '">' . esc_html($data->title) . '</a>' : false; 222 break; 223 224 default; 225 $return = false; 217 226 } 218 227 219 return false; 228 // You can use this filter to add support for custom data types or to filter the result 229 return apply_filters( 'oembed_dataparse', $return, $data, $url ); 220 230 } 231 232 /** 233 * Strip new lines from the HTML if it's a Scribd embed. 234 * 235 * @param string $html Existing HTML. 236 * @param object $data Data object from WP_oEmbed::data2html() 237 * @param string $url The original URL passed to oEmbed. 238 * @return string Possibly modified $html 239 */ 240 function strip_scribd_newlines( $html, $data, $url ) { 241 if ( preg_match( '#http://(www\.)?scribd.com/.*#i', $url ) ) 242 $html = str_replace( array( "\r\n", "\n" ), '', $html ); 243 244 return $html; 245 } 221 246 } 222 247 223 248 /** -
wp-includes/media.php
927 927 if ( get_option('embed_autourls') ) 928 928 add_filter( 'the_content', array(&$this, 'autoembed'), 8 ); 929 929 930 // After a post is saved, invalidate the oEmbed cache 931 add_action( 'save_post', array(&$this, 'delete_oembed_caches') ); 932 930 933 // After a post is saved, cache oEmbed items via AJAX 931 934 add_action( 'edit_form_advanced', array(&$this, 'maybe_run_ajax_cache') ); 932 935 } … … 1048 1051 foreach ( $handlers as $id => $handler ) { 1049 1052 if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) { 1050 1053 if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) 1051 return $return;1054 return apply_filters( 'embed_handler_html', $return, $url, $attr ); 1052 1055 } 1053 1056 } 1054 1057 } … … 1070 1073 return $this->maybe_make_link( $url ); 1071 1074 1072 1075 if ( !empty($cache) ) 1073 return $cache;1076 return apply_filters( 'embed_oembed_html', $cache, $url, $attr ); 1074 1077 } 1075 1078 1076 1079 // Use oEmbed to get the HTML … … 1086 1089 1087 1090 // If there was a result, return it 1088 1091 if ( $html ) 1089 return $html;1092 return apply_filters( 'embed_oembed_html', $html, $url, $attr ); 1090 1093 } 1091 1094 1092 1095 // Still unknown … … 1094 1097 } 1095 1098 1096 1099 /** 1100 * Delete all oEmbed caches. 1101 * 1102 * @param int $post_ID Post ID to delete the caches for. 1103 */ 1104 function delete_oembed_caches( $post_ID ) { 1105 $post_metas = get_post_custom_keys( $post_ID ); 1106 foreach( $post_metas as $post_meta_key ) { 1107 if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) ) 1108 delete_post_meta( $post_ID, $post_meta_key ); 1109 } 1110 } 1111 1112 /** 1097 1113 * Triggers a caching of all oEmbed results. 1098 1114 * 1099 1115 * @param int $post_ID Post ID to do the caching for. … … 1101 1117 function cache_oembed( $post_ID ) { 1102 1118 $post = get_post( $post_ID ); 1103 1119 1104 // post_type check is incase of "save_post" usage1105 1120 if ( empty($post->ID) || !in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', array( 'post', 'page' ) ) ) ) 1106 1121 return; 1107 1122 1108 // Dump existing caches1109 $post_metas = get_post_custom_keys( $post->ID );1110 foreach( $post_metas as $post_meta_key ) {1111 if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) )1112 delete_post_meta( $post->ID, $post_meta_key );1113 }1114 1115 1123 // Trigger a caching 1116 1124 if ( !empty($post->post_content) ) { 1117 1125 $this->post_ID = $post->ID; … … 1161 1169 * @return string Linked URL or the original URL. 1162 1170 */ 1163 1171 function maybe_make_link( $url ) { 1164 return ( $this->linkifunknown ) ? '<a href="' . esc_attr($url) . '">' . esc_html($url) . '</a>' : $url; 1172 $output = ( $this->linkifunknown ) ? '<a href="' . esc_attr($url) . '">' . esc_html($url) . '</a>' : $url; 1173 return apply_filters( 'embed_maybe_make_link', $output, $url ); 1165 1174 } 1166 1175 } 1167 1176 $wp_embed = new WP_Embed();
