Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-template.php

    r19240 r21054  
    7979        $r = wp_parse_args($args, $defaults);
    8080        extract( $r, EXTR_SKIP );
    81 
    8281
    8382        $title = $before . $title . $after;
    … …  
    189188
    190189        // If post password required and it doesn't match the cookie.
    191         if ( post_password_required($post) ) {
    192                 $output = get_the_password_form();
    193                 return $output;
    194         }
     190        if ( post_password_required($post) )
     191                return get_the_password_form();
    195192
    196193        if ( $page > count($pages) ) // if the requested page doesn't exist
    … …  
    415412        if ( is_date() )
    416413                $classes[] = 'date';
    417         if ( is_search() )
     414        if ( is_search() ) {
    418415                $classes[] = 'search';
     416                $classes[] = $wp_query->posts ? 'search-results' : 'search-no-results';
     417        }
    419418        if ( is_paged() )
    420419                $classes[] = 'paged';
    … …  
    491490                if ( is_page_template() ) {
    492491                        $classes[] = 'page-template';
    493                         $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $page_id, '_wp_page_template', true ) ), '' );
     492                        $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_page_template_slug( $page_id ) ) );
    494493                } else {
    495494                        $classes[] = 'page-template-default';
    496495                }
    497         } elseif ( is_search() ) {
    498                 if ( !empty( $wp_query->posts ) )
    499                         $classes[] = 'search-results';
    500                 else
    501                         $classes[] = 'search-no-results';
    502496        }
    503497
    … …  
    508502                $classes[] = 'admin-bar';
    509503
    510         if ( get_background_image() || get_background_color() )
     504        if ( get_theme_mod( 'background_color' ) || get_background_image() )
    511505                $classes[] = 'custom-background';
    512506
    … …  
    556550 * @since 2.7.0
    557551 *
    558  * @param int|object $post An optional post.  Global $post used if not provided.
     552 * @param int|object $post An optional post. Global $post used if not provided.
    559553 * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
    560554 */
    561555function post_password_required( $post = null ) {
     556        global $wp_hasher;
     557
    562558        $post = get_post($post);
    563559
    564         if ( empty($post->post_password) )
     560        if ( empty( $post->post_password ) )
    565561                return false;
    566562
    567         if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) )
     563        if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
    568564                return true;
    569565
    570         if ( stripslashes( $_COOKIE['wp-postpass_' . COOKIEHASH] ) != $post->post_password )
    571                 return true;
    572 
    573         return false;
     566        if ( empty( $wp_hasher ) ) {
     567                require_once( ABSPATH . 'wp-includes/class-phpass.php');
     568                // By default, use the portable hash from phpass
     569                $wp_hasher = new PasswordHash(8, true);
     570        }
     571
     572        $hash = stripslashes( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
     573
     574        return ! $wp_hasher->CheckPassword( $post->post_password, $hash );
    574575}
    575576
    … …  
    995996         * @param int $depth Depth of page. Used for padding.
    996997         */
    997         function start_lvl(&$output, $depth) {
     998        function start_lvl( &$output, $depth = 0, $args = array() ) {
    998999                $indent = str_repeat("\t", $depth);
    9991000                $output .= "\n$indent<ul class='children'>\n";
    … …  
    10071008         * @param int $depth Depth of page. Used for padding.
    10081009         */
    1009         function end_lvl(&$output, $depth) {
     1010        function end_lvl( &$output, $depth = 0, $args = array() ) {
    10101011                $indent = str_repeat("\t", $depth);
    10111012                $output .= "$indent</ul>\n";
    … …  
    10221023         * @param array $args
    10231024         */
    1024         function start_el(&$output, $page, $depth, $args, $current_page) {
     1025        function start_el( &$output, $page, $depth, $args, $current_page = 0 ) {
    10251026                if ( $depth )
    10261027                        $indent = str_repeat("\t", $depth);
    … …  
    10651066         * @param int $depth Depth of page. Not Used.
    10661067         */
    1067         function end_el(&$output, $page, $depth) {
     1068        function end_el( &$output, $page, $depth = 0, $args = array() ) {
    10681069                $output .= "</li>\n";
    10691070        }
    … …  
    11031104         * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element.
    11041105         */
    1105         function start_el(&$output, $page, $depth, $args) {
     1106        function start_el(&$output, $page, $depth, $args, $id = 0) {
    11061107                $pad = str_repeat('&nbsp;', $depth * 3);
    11071108
    … …  
    11661167
    11671168        if ( $text )
    1168                 $link_text = esc_attr( $text );
     1169                $link_text = $text;
    11691170        elseif ( $size && 'none' != $size )
    11701171                $link_text = wp_get_attachment_image( $id, $size, $icon );
    … …  
    12161217function get_the_password_form() {
    12171218        global $post;
    1218         $label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
    1219         $output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
     1219        $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
     1220        $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
    12201221        <p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
    12211222        <p><label for="' . $label . '">' . __("Password:") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Submit") . '" /></p>
    … …  
    12381239 * @return bool False on failure, true if success.
    12391240 */
    1240 function is_page_template($template = '') {
    1241         if (!is_page()) {
     1241function is_page_template( $template = '' ) {
     1242        if ( ! is_page() )
    12421243                return false;
    1243         }
    1244 
    1245         global $wp_query;
    1246 
    1247         $page = $wp_query->get_queried_object();
    1248         $custom_fields = get_post_custom_values('_wp_page_template',$page->ID);
    1249         $page_template = $custom_fields[0];
    1250 
    1251         // We have no argument passed so just see if a page_template has been specified
    1252         if ( empty( $template ) ) {
    1253                 if ( !empty( $page_template ) and ( 'default' != $page_template ) ) {
    1254                         return true;
    1255                 }
    1256         } elseif ( $template == $page_template) {
     1244
     1245        $page_template = get_page_template_slug( get_queried_object_id() );
     1246
     1247        if ( empty( $template ) )
     1248                return (bool) $page_template;
     1249
     1250        if ( $template == $page_template )
    12571251                return true;
    1258         }
     1252
     1253        if ( 'default' == $template && ! $page_template )
     1254                return true;
    12591255
    12601256        return false;
     1257}
     1258
     1259/**
     1260 * Get the specific template name for a page.
     1261 *
     1262 * @since 3.4.0
     1263 *
     1264 * @param int $id The page ID to check. Defaults to the current post, when used in the loop.
     1265 * @return string|bool Page template filename. Returns an empty string when the default page template
     1266 *      is in use. Returns false if the post is not a page.
     1267 */
     1268function get_page_template_slug( $post_id = null ) {
     1269        $post = get_post( $post_id );
     1270        if ( 'page' != $post->post_type )
     1271                return false;
     1272        $template = get_post_meta( $post->ID, '_wp_page_template', true );
     1273        if ( ! $template || 'default' == $template )
     1274                return '';
     1275        return $template;
    12611276}
    12621277
    … …  
    13081323 * Second argument controls parameters:
    13091324 *   (bool)   parent : include the parent (the "Current Revision") in the list.
    1310  *   (string) format : 'list' or 'form-table'.  'list' outputs UL, 'form-table'
     1325 *   (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table'
    13111326 *                     outputs TABLE with UI.
    13121327 *   (int)    right  : what revision is currently being viewed - used in
Note: See TracChangeset for help on using the changeset viewer.