PressThis: when server-side parsing, filter small images by the width and height attributes if set.

See #31373.

git-svn-id: https://develop.svn.wordpress.org/trunk@31637 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2015-03-06 02:02:03 +00:00
parent e6fcf316b3
commit 1080a903fc
1 changed files with 10 additions and 2 deletions

View File

@ -285,10 +285,12 @@ class WP_Press_This {
// Get the content of the source page from the tmp file.. // Get the content of the source page from the tmp file..
$source_content = wp_kses( $source_content = wp_kses(
file_get_contents( $source_tmp_file ), @file_get_contents( $source_tmp_file ),
array( array(
'img' => array( 'img' => array(
'src' => array(), 'src' => array(),
'width' => array(),
'height' => array(),
), ),
'iframe' => array( 'iframe' => array(
'src' => array(), 'src' => array(),
@ -529,7 +531,13 @@ class WP_Press_This {
$items = $this->_limit_array( $matches[0] ); $items = $this->_limit_array( $matches[0] );
foreach ( $items as $value ) { foreach ( $items as $value ) {
if ( preg_match( '/src=(\'|")([^\'"]+)\\1/', $value, $new_matches ) ) { if ( ( preg_match( '/width=(\'|")(\d+)\\1/i', $value, $new_matches ) && $new_matches[2] < 256 ) ||
( preg_match( '/height=(\'|")(\d+)\\1/i', $value, $new_matches ) && $new_matches[2] < 128 ) ) {
continue;
}
if ( preg_match( '/src=(\'|")([^\'"]+)\\1/i', $value, $new_matches ) ) {
$src = $this->_limit_img( $new_matches[2] ); $src = $this->_limit_img( $new_matches[2] );
if ( ! empty( $src ) && ! in_array( $src, $data['_img'] ) ) { if ( ! empty( $src ) && ! in_array( $src, $data['_img'] ) ) {
$data['_img'][] = $src; $data['_img'][] = $src;