Making WordPress.org


Ignore:
Timestamp:
02/07/2024 07:00:03 AM (3 years ago)
Author:
dd32
Message:

Trac: CDNise the URLs within JSON/JS as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/trac.wordpress.org/templates/update-headers.php

    r13185 r13186  
    8989         */
    9090        $html = preg_replace_callback(
    91                 '!(?P<url>https://wordpress.org/wp-(includes|content)/[^\'"]+)!i',
     91                '!(?P<url>https:[\\\/]+wordpress.org[\\\/]+wp-(includes|content)[\\\/]+[^\'"]+)!i',
    9292                function( $m ) {
    93                         $url  = str_replace( 'https://wordpress.org/', 'https://s.w.org/', $m['url'] );
    94                         $hash = md5( file_get_contents( $m['url'] ) );
    95 
    96                         if ( preg_match( '/([?&;](ver)=[^&]+)/i', $url, $m ) ) {
     93                        $url     = $m['url'];
     94                        $escaped = false !== strpos( $url, '\/' );
     95
     96                        if ( $escaped ) {
     97                                $url = stripslashes( $url );
     98                        }
     99
     100                        $url  = str_replace( 'wordpress.org', 's.w.org', $url );
     101                        $hash = md5( file_get_contents( $url ) );
     102
     103                        if ( preg_match( '/([?&;](ver|v)=[^&]+)/i', $url, $m ) ) {
    97104                                $url = str_replace( $m[0], $m[0] . '-' . $hash, $url );
    98105                        } else {
    99                                 $url .= ( str_contains( $url, '?' ) ? '&amp;' : '?' ) . 'ver=' . $hash;
     106                                $url .= ( strpos( $url, '?' ) ? '&amp;' : '?' ) . 'ver=' . $hash;
     107                        }
     108
     109                        if ( $escaped ) {
     110                                $url = addcslashes( $url, '/' );
    100111                        }
    101112
Note: See TracChangeset for help on using the changeset viewer.