Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r15264 r17292  
    1313 *
    1414 * @since 0.71
    15  * @uses $id
    1615 */
    1716function the_ID() {
    18     global $id;
    19     echo $id;
     17    echo get_the_ID();
    2018}
    2119
     
    2422 *
    2523 * @since 2.1.0
    26  * @uses $id
    27  *
    28  * @return unknown
     24 * @uses $post
     25 *
     26 * @return int
    2927 */
    3028function get_the_ID() {
    31     global $id;
    32     return $id;
     29    global $post;
     30    return $post->ID;
    3331}
    3432
     
    182180 */
    183181function get_the_content($more_link_text = null, $stripteaser = 0) {
    184     global $id, $post, $more, $page, $pages, $multipage, $preview;
     182    global $post, $more, $page, $pages, $multipage, $preview;
    185183
    186184    if ( null === $more_link_text )
     
    217215    if ( count($content) > 1 ) {
    218216        if ( $more ) {
    219             $output .= '<span id="more-' . $id . '"></span>' . $content[1];
     217            $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
    220218        } else {
    221219            if ( ! empty($more_link_text) )
    222                 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>", $more_link_text );
     220                $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
    223221            $output = force_balance_tags($output);
    224222        }
     
    226224    }
    227225    if ( $preview ) // preview fix for javascript bug with foreign languages
    228         $output =   preg_replace_callback('/\%u([0-9A-F]{4})/', create_function('$match', 'return "&#" . base_convert($match[1], 16, 10) . ";";'), $output);
     226        $output =   preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output);
    229227
    230228    return $output;
     229}
     230
     231/**
     232 * Preview fix for javascript bug with foreign languages
     233 *
     234 * @since 3.1.0
     235 * @access private
     236 * @param array $match Match array from preg_replace_callback
     237 * @returns string
     238 */
     239function _convert_urlencoded_to_entities( $match ) {
     240    return '&#' . base_convert( $match[1], 16, 10 ) . ';';
    231241}
    232242
     
    317327    $classes[] = $post->post_type;
    318328    $classes[] = 'type-' . $post->post_type;
     329    $classes[] = 'status-' . $post->post_status;
     330
     331    // Post Format
     332    $post_format = get_post_format( $post->ID );
     333
     334    if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
     335        if ( $post_format && !is_wp_error($post_format) )
     336            $classes[] = 'format-' . sanitize_html_class( $post_format );
     337        else
     338            $classes[] = 'format-standard';
     339    }
     340
     341    // post requires password
     342    if ( post_password_required($post->ID) )
     343        $classes[] = 'post-password-required';
    319344
    320345    // sticky for Sticky Posts
     
    322347        $classes[] = 'sticky';
    323348
    324     // hentry for hAtom compliace
     349    // hentry for hAtom compliance
    325350    $classes[] = 'hentry';
    326351
    327352    // Categories
    328     foreach ( (array) get_the_category($post->ID) as $cat ) {
    329         if ( empty($cat->slug ) )
    330             continue;
    331         $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID);
     353    if ( is_object_in_taxonomy( $post->post_type, 'category' ) ) {
     354        foreach ( (array) get_the_category($post->ID) as $cat ) {
     355            if ( empty($cat->slug ) )
     356                continue;
     357            $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id);
     358        }
    332359    }
    333360
    334361    // Tags
    335     foreach ( (array) get_the_tags($post->ID) as $tag ) {
    336         if ( empty($tag->slug ) )
    337             continue;
    338         $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
     362    if ( is_object_in_taxonomy( $post->post_type, 'post_tag' ) ) {
     363        foreach ( (array) get_the_tags($post->ID) as $tag ) {
     364            if ( empty($tag->slug ) )
     365                continue;
     366            $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
     367        }
    339368    }
    340369
     
    403432        $classes[] = 'postid-' . $post_id;
    404433
     434        // Post Format
     435        $post_format = get_post_format( $post->ID );
     436
     437        if ( $post_format && !is_wp_error($post_format) )
     438            $classes[] = 'single-format-' . sanitize_html_class( $post_format );
     439        else
     440            $classes[] = 'single-format-standard';
     441
    405442        if ( is_attachment() ) {
    406443            $mime_type = get_post_mime_type($post_id);
     
    410447        }
    411448    } elseif ( is_archive() ) {
    412         if ( is_author() ) {
     449        if ( is_post_type_archive() ) {
     450            $classes[] = 'post-type-archive';
     451            $classes[] = 'post-type-archive-' . sanitize_html_class( get_query_var( 'post_type' ) );
     452        } else if ( is_author() ) {
    413453            $author = $wp_query->get_queried_object();
    414454            $classes[] = 'author';
    415455            $classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID );
     456            $classes[] = 'author-' . $author->ID;
    416457        } elseif ( is_category() ) {
    417458            $cat = $wp_query->get_queried_object();
    418459            $classes[] = 'category';
    419             $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->cat_ID );
     460            $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
     461            $classes[] = 'category-' . $cat->term_id;
    420462        } elseif ( is_tag() ) {
    421463            $tags = $wp_query->get_queried_object();
    422464            $classes[] = 'tag';
    423465            $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
     466            $classes[] = 'tag-' . $tags->term_id;
     467        } elseif ( is_tax() ) {
     468            $term = $wp_query->get_queried_object();
     469            $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
     470            $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
     471            $classes[] = 'term-' . $term->term_id;
    424472        }
    425473    } elseif ( is_page() ) {
     
    452500    if ( is_user_logged_in() )
    453501        $classes[] = 'logged-in';
     502
     503    if ( is_admin_bar_showing() )
     504        $classes[] = 'admin-bar';
    454505
    455506    $page = $wp_query->get( 'page' );
     
    475526        elseif ( is_search() )
    476527            $classes[] = 'search-paged-' . $page;
     528        elseif ( is_post_type_archive() )
     529            $classes[] = 'post-type-paged-' . $page;
    477530    }
    478531
     
    578631    extract( $r, EXTR_SKIP );
    579632
    580     global $post, $page, $numpages, $multipage, $more, $pagenow;
     633    global $page, $numpages, $multipage, $more, $pagenow;
    581634
    582635    $output = '';
     
    588641                $output .= ' ';
    589642                if ( ($i != $page) || ((!$more) && ($page==1)) ) {
    590                     if ( 1 == $i ) {
    591                         $output .= '<a href="' . get_permalink() . '">';
    592                     } else {
    593                         if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
    594                             $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">';
    595                         elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
    596                             $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
    597                         else
    598                             $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
    599                     }
    600 
     643                    $output .= _wp_link_page($i);
    601644                }
    602                 $output .= $link_before;
    603                 $output .= $j;
    604                 $output .= $link_after;
     645                $output .= $link_before . $j . $link_after;
    605646                if ( ($i != $page) || ((!$more) && ($page==1)) )
    606647                    $output .= '</a>';
     
    612653                $i = $page - 1;
    613654                if ( $i && $more ) {
    614                     if ( 1 == $i ) {
    615                         $output .= '<a href="' . get_permalink() . '">';
    616                     } else {
    617                         if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
    618                             $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">';
    619                         elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
    620                             $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
    621                         else
    622                             $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
    623                     }
     655                    $output .= _wp_link_page($i);
    624656                    $output .= $link_before. $previouspagelink . $link_after . '</a>';
    625657                }
    626658                $i = $page + 1;
    627659                if ( $i <= $numpages && $more ) {
    628                     if ( 1 == $i ) {
    629                         $output .= '<a href="' . get_permalink() . '">';
    630                     } else {
    631                         if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
    632                             $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">';
    633                         elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
    634                             $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
    635                         else
    636                             $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
    637                     }
     660                    $output .= _wp_link_page($i);
    638661                    $output .= $link_before. $nextpagelink . $link_after . '</a>';
    639662                }
     
    649672}
    650673
     674/**
     675 * Helper function for wp_link_pages().
     676 *
     677 * @since 3.1.0
     678 * @access private
     679 *
     680 * @param int $i Page number.
     681 * @return string Link.
     682 */
     683function _wp_link_page( $i ) {
     684    global $post, $wp_rewrite;
     685
     686    if ( 1 == $i ) {
     687        $url = get_permalink();
     688    } else {
     689        if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
     690            $url = add_query_arg( 'page', $i, get_permalink() );
     691        elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
     692            $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged');
     693        else
     694            $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged');
     695    }
     696
     697    return '<a href="' . esc_url( $url ) . '">';
     698}
    651699
    652700//
     
    685733        foreach ( (array) $keys as $key ) {
    686734            $keyt = trim($key);
    687             if ( '_' == $keyt{0} )
     735            if ( '_' == $keyt[0] )
    688736                continue;
    689737            $values = array_map('trim', get_post_custom_values($key));
     
    908956}
    909957
     958/**
     959 * Create HTML list of pages.
     960 *
     961 * @package WordPress
     962 * @since 2.1.0
     963 * @uses Walker
     964 */
     965class Walker_Page extends Walker {
     966    /**
     967     * @see Walker::$tree_type
     968     * @since 2.1.0
     969     * @var string
     970     */
     971    var $tree_type = 'page';
     972
     973    /**
     974     * @see Walker::$db_fields
     975     * @since 2.1.0
     976     * @todo Decouple this.
     977     * @var array
     978     */
     979    var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
     980
     981    /**
     982     * @see Walker::start_lvl()
     983     * @since 2.1.0
     984     *
     985     * @param string $output Passed by reference. Used to append additional content.
     986     * @param int $depth Depth of page. Used for padding.
     987     */
     988    function start_lvl(&$output, $depth) {
     989        $indent = str_repeat("\t", $depth);
     990        $output .= "\n$indent<ul class='children'>\n";
     991    }
     992
     993    /**
     994     * @see Walker::end_lvl()
     995     * @since 2.1.0
     996     *
     997     * @param string $output Passed by reference. Used to append additional content.
     998     * @param int $depth Depth of page. Used for padding.
     999     */
     1000    function end_lvl(&$output, $depth) {
     1001        $indent = str_repeat("\t", $depth);
     1002        $output .= "$indent</ul>\n";
     1003    }
     1004
     1005    /**
     1006     * @see Walker::start_el()
     1007     * @since 2.1.0
     1008     *
     1009     * @param string $output Passed by reference. Used to append additional content.
     1010     * @param object $page Page data object.
     1011     * @param int $depth Depth of page. Used for padding.
     1012     * @param int $current_page Page ID.
     1013     * @param array $args
     1014     */
     1015    function start_el(&$output, $page, $depth, $args, $current_page) {
     1016        if ( $depth )
     1017            $indent = str_repeat("\t", $depth);
     1018        else
     1019            $indent = '';
     1020
     1021        extract($args, EXTR_SKIP);
     1022        $css_class = array('page_item', 'page-item-'.$page->ID);
     1023        if ( !empty($current_page) ) {
     1024            $_current_page = get_page( $current_page );
     1025            _get_post_ancestors($_current_page);
     1026            if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) )
     1027                $css_class[] = 'current_page_ancestor';
     1028            if ( $page->ID == $current_page )
     1029                $css_class[] = 'current_page_item';
     1030            elseif ( $_current_page && $page->ID == $_current_page->post_parent )
     1031                $css_class[] = 'current_page_parent';
     1032        } elseif ( $page->ID == get_option('page_for_posts') ) {
     1033            $css_class[] = 'current_page_parent';
     1034        }
     1035
     1036        $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page));
     1037
     1038        $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '" title="' . esc_attr( wp_strip_all_tags( apply_filters( 'the_title', $page->post_title, $page->ID ) ) ) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>';
     1039
     1040        if ( !empty($show_date) ) {
     1041            if ( 'modified' == $show_date )
     1042                $time = $page->post_modified;
     1043            else
     1044                $time = $page->post_date;
     1045
     1046            $output .= " " . mysql2date($date_format, $time);
     1047        }
     1048    }
     1049
     1050    /**
     1051     * @see Walker::end_el()
     1052     * @since 2.1.0
     1053     *
     1054     * @param string $output Passed by reference. Used to append additional content.
     1055     * @param object $page Page data object. Not used.
     1056     * @param int $depth Depth of page. Not Used.
     1057     */
     1058    function end_el(&$output, $page, $depth) {
     1059        $output .= "</li>\n";
     1060    }
     1061
     1062}
     1063
     1064/**
     1065 * Create HTML dropdown list of pages.
     1066 *
     1067 * @package WordPress
     1068 * @since 2.1.0
     1069 * @uses Walker
     1070 */
     1071class Walker_PageDropdown extends Walker {
     1072    /**
     1073     * @see Walker::$tree_type
     1074     * @since 2.1.0
     1075     * @var string
     1076     */
     1077    var $tree_type = 'page';
     1078
     1079    /**
     1080     * @see Walker::$db_fields
     1081     * @since 2.1.0
     1082     * @todo Decouple this
     1083     * @var array
     1084     */
     1085    var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
     1086
     1087    /**
     1088     * @see Walker::start_el()
     1089     * @since 2.1.0
     1090     *
     1091     * @param string $output Passed by reference. Used to append additional content.
     1092     * @param object $page Page data object.
     1093     * @param int $depth Depth of page in reference to parent pages. Used for padding.
     1094     * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element.
     1095     */
     1096    function start_el(&$output, $page, $depth, $args) {
     1097        $pad = str_repeat('&nbsp;', $depth * 3);
     1098
     1099        $output .= "\t<option class=\"level-$depth\" value=\"$page->ID\"";
     1100        if ( $page->ID == $args['selected'] )
     1101            $output .= ' selected="selected"';
     1102        $output .= '>';
     1103        $title = esc_html($page->post_title);
     1104        $title = apply_filters( 'list_pages', $page->post_title );
     1105        $output .= "$pad$title";
     1106        $output .= "</option>\n";
     1107    }
     1108}
     1109
    9101110//
    9111111// Attachments
Note: See TracChangeset for help on using the changeset viewer.