Make WordPress Core

Changeset 34736


Ignore:
Timestamp:
10/01/2015 05:15:05 AM (9 years ago)
Author:
dd32
Message:

Press This: Make the regular expressions for matching images easier to read by not requiring escaping.
Fixes #32878

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-press-this.php

    r33970 r34736  
    391391     * Utility method to limit image source URLs.
    392392     *
    393      * Excluded URLs include share-this type buttons, loaders, spinners, spacers, WP interface images,
    394      * tiny buttons or thumbs, mathtag.com or quantserve.com images, or the WP stats gif.
     393     * Excluded URLs include share-this type buttons, loaders, spinners, spacers, WordPress interface images,
     394     * tiny buttons or thumbs, mathtag.com or quantserve.com images, or the WordPress.com stats gif.
    395395     *
    396396     * @ignore
     
    403403        $src = $this->_limit_url( $src );
    404404
    405         if ( preg_match( '/\/ad[sx]{1}?\//', $src ) ) {
     405        if ( preg_match( '!/ad[sx]?/!i', $src ) ) {
    406406            // Ads
    407407            return '';
    408         } else if ( preg_match( '/(\/share-?this[^\.]+?\.[a-z0-9]{3,4})(\?.*)?$/', $src ) ) {
     408        } else if ( preg_match( '!(/share-?this[^.]+?\.[a-z0-9]{3,4})(\?.*)?$!i', $src ) ) {
    409409            // Share-this type button
    410410            return '';
    411         } else if ( preg_match( '/\/(spinner|loading|spacer|blank|rss)\.(gif|jpg|png)/', $src ) ) {
     411        } else if ( preg_match( '!/(spinner|loading|spacer|blank|rss)\.(gif|jpg|png)!i', $src ) ) {
    412412            // Loaders, spinners, spacers
    413413            return '';
    414         } else if ( preg_match( '/\/([^\.\/]+[-_]{1})?(spinner|loading|spacer|blank)s?([-_]{1}[^\.\/]+)?\.[a-z0-9]{3,4}/', $src ) ) {
     414        } else if ( preg_match( '!/([^./]+[-_])?(spinner|loading|spacer|blank)s?([-_][^./]+)?\.[a-z0-9]{3,4}!i', $src ) ) {
    415415            // Fancy loaders, spinners, spacers
    416416            return '';
    417         } else if ( preg_match( '/([^\.\/]+[-_]{1})?thumb[^.]*\.(gif|jpg|png)$/', $src ) ) {
     417        } else if ( preg_match( '!([^./]+[-_])?thumb[^.]*\.(gif|jpg|png)$!i', $src ) ) {
    418418            // Thumbnails, too small, usually irrelevant to context
    419419            return '';
    420         } else if ( preg_match( '/\/wp-includes\//', $src ) ) {
    421             // Classic WP interface images
     420        } else if ( false !== stripos( $src, '/wp-includes/' ) ) {
     421            // Classic WordPress interface images
    422422            return '';
    423         } else if ( preg_match( '/[^\d]{1}\d{1,2}x\d+\.(gif|jpg|png)$/', $src ) ) {
     423        } else if ( preg_match( '![^\d]\d{1,2}x\d+\.(gif|jpg|png)$!i', $src ) ) {
    424424            // Most often tiny buttons/thumbs (< 100px wide)
    425425            return '';
    426         } else if ( preg_match( '/\/pixel\.(mathtag|quantserve)\.com/', $src ) ) {
     426        } else if ( preg_match( '!/pixel\.(mathtag|quantserve)\.com!i', $src ) ) {
    427427            // See mathtag.com and https://www.quantcast.com/how-we-do-it/iab-standard-measurement/how-we-collect-data/
    428428            return '';
    429         } else if ( preg_match( '/\/[gb]\.gif(\?.+)?$/', $src ) ) {
    430             // Classic WP stats gif
     429        } else if ( preg_match( '!/[gb]\.gif(\?.+)?$!i', $src ) ) {
     430            // WordPress.com stats gif
    431431            return '';
    432432        }
     
    453453            return '';
    454454
    455         if ( preg_match( '/\/\/(m|www)\.youtube\.com\/(embed|v)\/([^\?]+)\?.+$/', $src, $src_matches ) ) {
     455        if ( preg_match( '!//(m|www)\.youtube\.com/(embed|v)/([^?]+)\?.+$!i', $src, $src_matches ) ) {
    456456            // Embedded Youtube videos (www or mobile)
    457457            $src = 'https://www.youtube.com/watch?v=' . $src_matches[3];
    458         } else if ( preg_match( '/\/\/player\.vimeo\.com\/video\/([\d]+)([\?\/]{1}.*)?$/', $src, $src_matches ) ) {
     458        } else if ( preg_match( '!//player\.vimeo\.com/video/([\d]+)([?/].*)?$!i', $src, $src_matches ) ) {
    459459            // Embedded Vimeo iframe videos
    460460            $src = 'https://vimeo.com/' . (int) $src_matches[1];
    461         } else if ( preg_match( '/\/\/vimeo\.com\/moogaloop\.swf\?clip_id=([\d]+)$/', $src, $src_matches ) ) {
     461        } else if ( preg_match( '!//vimeo\.com/moogaloop\.swf\?clip_id=([\d]+)$!i', $src, $src_matches ) ) {
    462462            // Embedded Vimeo Flash videos
    463463            $src = 'https://vimeo.com/' . (int) $src_matches[1];
    464         } else if ( preg_match( '/\/\/vine\.co\/v\/([^\/]+)\/embed/', $src, $src_matches ) ) {
     464        } else if ( preg_match( '!//vine\.co/v/([^/]+)/embed!i', $src, $src_matches ) ) {
    465465            // Embedded Vine videos
    466466            $src = 'https://vine.co/v/' . $src_matches[1];
    467         } else if ( preg_match( '/\/\/(www\.)?dailymotion\.com\/embed\/video\/([^\/\?]+)([\/\?]{1}.+)?/', $src, $src_matches ) ) {
     467        } else if ( preg_match( '!//(www\.)?dailymotion\.com/embed/video/([^/?]+)([/?].+)?!i', $src, $src_matches ) ) {
    468468            // Embedded Daily Motion videos
    469469            $src = 'https://www.dailymotion.com/video/' . $src_matches[2];
Note: See TracChangeset for help on using the changeset viewer.