WordPress.org

Make WordPress Core

Ticket #15086: 15086.004.diff

File 15086.004.diff, 3.9 KB (added by aaroncampbell, 8 years ago)
  • wp-includes/formatting.php

     
    734734}
    735735
    736736/**
     737 * Remove dot segments from a path
     738 *
     739 * @aince 3.2
     740 *
     741 * @param string $input The string to remove dot segments from
     742 * @return string
     743 */
     744function remove_dot_segments( $input ) {
     745        $output = '';
     746        while ( false !== strpos( $input, './' ) || false !== strpos( $input, '/.' ) || '.' === $input || '..' === $input ) {
     747                // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
     748                if ( 0 === strpos( $input, '../' ) ) {
     749                        $input = substr( $input, 3 );
     750                } elseif ( 0 === strpos( $input, './' ) ) {
     751                        $input = substr( $input, 2 );
     752                }
     753                // B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise,
     754                elseif ( 0 === strpos( $input, '/./' ) ) {
     755                        $input = substr_replace( $input, '/', 0, 3 );
     756                } elseif ( '/.' === $input ) {
     757                        $input = '/';
     758                }
     759                // C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise,
     760                elseif ( 0 === strpos( $input, '/../' ) ) {
     761                        $input = substr_replace( $input, '/', 0, 4 );
     762                        $output = substr_replace( $output, '', strrpos( $output, '/' ) );
     763                } elseif ( '/..' === $input ) {
     764                        $input = '/';
     765                        $output = substr_replace( $output, '', strrpos( $output, '/' ) );
     766                }
     767                // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
     768                elseif ( '.' === $input || '..' === $input ) {
     769                        $input = '';
     770                }
     771                // E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer
     772                elseif ( false !== ( $pos = strpos( $input, '/', 1 ) ) ) {
     773                        $output .= substr( $input, 0, $pos );
     774                        $input = substr_replace( $input, '', 0, $pos );
     775                } else {
     776                        $output .= $input;
     777                        $input = '';
     778                }
     779        }
     780        return $output . $input;
     781}
     782
     783/**
    737784 * Sanitize username stripping out unsafe characters.
    738785 *
    739786 * Removes tags, octets, entities, and if strict is enabled, will only keep
  • wp-includes/general-template.php

     
    116116 * @param string $slug The slug name for the generic template.
    117117 * @param string $name The name of the specialised template.
    118118 */
    119 function get_template_part( $slug, $name = null ) {
    120         do_action( "get_template_part_{$slug}", $slug, $name );
     119function get_template_part( $slug, $name = null, $directory = null ) {
     120        if ( false !== strpos( $slug, DIRECTORY_SEPARATOR ) ) {
     121                $original_slug = $slug;
     122                $slug = substr( strrchr( $slug, DIRECTORY_SEPARATOR ), 1 );
     123                if ( empty( $directory ) ) {
     124                        $directory = substr( $original_slug, 0, strrpos( $original_slug, DIRECTORY_SEPARATOR ) );
     125                }
     126        }
     127        $slug = sanitize_file_name( $slug );
    121128
     129        $directory = rtrim( remove_dot_segments( $directory ), DIRECTORY_SEPARATOR );
     130
     131        do_action( "get_template_part_{$slug}", $slug, $name, $directory );
     132
    122133        $templates = array();
     134        if ( ! empty( $directory ) ) {
     135                if ( isset($name) )
     136                        $templates[] = $directory . DIRECTORY_SEPARATOR . "{$slug}-{$name}.php";
     137
     138                $templates[] = $directory . DIRECTORY_SEPARATOR . "{$slug}.php";
     139        }
     140
    123141        if ( isset($name) )
    124142                $templates[] = "{$slug}-{$name}.php";
    125143
    126144        $templates[] = "{$slug}.php";
    127145
    128         locate_template($templates, true, false);
     146        locate_template( $templates, true, false );
    129147}
    130148
    131149/**