Ticket #15086: 15086.003.diff

File 15086.003.diff, 4.2 KB (added by aaroncampbell, 3 years ago)
  • wp-includes/formatting.php

     
    716716} 
    717717 
    718718/** 
     719 * Remove dot segments from a path 
     720 * 
     721 * @access private 
     722 * @param string $input 
     723 * @return string 
     724 */ 
     725function remove_dot_segments($input) 
     726{ 
     727        $output = ''; 
     728        while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..') 
     729        { 
     730                // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise, 
     731                if (strpos($input, '../') === 0) 
     732                { 
     733                        $input = substr($input, 3); 
     734                } 
     735                elseif (strpos($input, './') === 0) 
     736                { 
     737                        $input = substr($input, 2); 
     738                } 
     739                // 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, 
     740                elseif (strpos($input, '/./') === 0) 
     741                { 
     742                        $input = substr_replace($input, '/', 0, 3); 
     743                } 
     744                elseif ($input === '/.') 
     745                { 
     746                        $input = '/'; 
     747                } 
     748                // 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, 
     749                elseif (strpos($input, '/../') === 0) 
     750                { 
     751                        $input = substr_replace($input, '/', 0, 4); 
     752                        $output = substr_replace($output, '', strrpos($output, '/')); 
     753                } 
     754                elseif ($input === '/..') 
     755                { 
     756                        $input = '/'; 
     757                        $output = substr_replace($output, '', strrpos($output, '/')); 
     758                } 
     759                // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise, 
     760                elseif ($input === '.' || $input === '..') 
     761                { 
     762                        $input = ''; 
     763                } 
     764                // 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 
     765                elseif (($pos = strpos($input, '/', 1)) !== false) 
     766                { 
     767                        $output .= substr($input, 0, $pos); 
     768                        $input = substr_replace($input, '', 0, $pos); 
     769                } 
     770                else 
     771                { 
     772                        $output .= $input; 
     773                        $input = ''; 
     774                } 
     775        } 
     776        return $output . $input; 
     777} 
     778 
     779/** 
    719780 * Sanitize username stripping out unsafe characters. 
    720781 * 
    721782 * If $strict is true, only alphanumeric characters (as well as _, space, ., -, 
  • 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/** 
     
    654672        if ( ! is_post_type_archive() ) 
    655673                return; 
    656674 
    657          
     675 
    658676        $post_type_obj = get_post_type_object( get_query_var( 'post_type' ) ); 
    659677        $title = apply_filters('post_type_archive_title', $post_type_obj->labels->name ); 
    660678 
     
    663681        else 
    664682                return $title; 
    665683} 
    666          
     684 
    667685/** 
    668686 * Display or retrieve page title for category archive. 
    669687 *