Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r17292 r15264  
    1313 *
    1414 * @since 0.71
     15 * @uses $id
    1516 */
    1617function the_ID() {
    17         echo get_the_ID();
     18        global $id;
     19        echo $id;
    1820}
    1921
    … …  
    2224 *
    2325 * @since 2.1.0
    24  * @uses $post
    25  *
    26  * @return int
     26 * @uses $id
     27 *
     28 * @return unknown
    2729 */
    2830function get_the_ID() {
    29         global $post;
    30         return $post->ID;
     31        global $id;
     32        return $id;
    3133}
    3234
    … …  
    180182 */
    181183function get_the_content($more_link_text = null, $stripteaser = 0) {
    182         global $post, $more, $page, $pages, $multipage, $preview;
     184        global $id, $post, $more, $page, $pages, $multipage, $preview;
    183185
    184186        if ( null === $more_link_text )
    … …  
    215217        if ( count($content) > 1 ) {
    216218                if ( $more ) {
    217                         $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
     219                        $output .= '<span id="more-' . $id . '"></span>' . $content[1];
    218220                } else {
    219221                        if ( ! empty($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 );
     222                                $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>", $more_link_text );
    221223                        $output = force_balance_tags($output);
    222224                }
    … …  
    224226        }
    225227        if ( $preview ) // preview fix for javascript bug with foreign languages
    226                 $output =       preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output);
     228                $output =       preg_replace_callback('/\%u([0-9A-F]{4})/', create_function('$match', 'return "&#" . base_convert($match[1], 16, 10) . ";";'), $output);
    227229
    228230        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  */
    239 function _convert_urlencoded_to_entities( $match ) {
    240         return '&#' . base_convert( $match[1], 16, 10 ) . ';';
    241231}
    242232
    … …  
    327317        $classes[] = $post->post_type;
    328318        $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';
    344319
    345320        // sticky for Sticky Posts
    … …  
    347322                $classes[] = 'sticky';
    348323
    349         // hentry for hAtom compliance
     324        // hentry for hAtom compliace
    350325        $classes[] = 'hentry';
    351326
    352327        // Categories
    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                 }
     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);
    359332        }
    360333
    361334        // Tags
    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                 }
     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);
    368339        }
    369340
    … …  
    432403                $classes[] = 'postid-' . $post_id;
    433404
    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 
    442405                if ( is_attachment() ) {
    443406                        $mime_type = get_post_mime_type($post_id);
    … …  
    447410                }
    448411        } elseif ( is_archive() ) {
    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() ) {
     412                if ( is_author() ) {
    453413                        $author = $wp_query->get_queried_object();
    454414                        $classes[] = 'author';
    455415                        $classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID );
    456                         $classes[] = 'author-' . $author->ID;
    457416                } elseif ( is_category() ) {
    458417                        $cat = $wp_query->get_queried_object();
    459418                        $classes[] = 'category';
    460                         $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
    461                         $classes[] = 'category-' . $cat->term_id;
     419                        $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->cat_ID );
    462420                } elseif ( is_tag() ) {
    463421                        $tags = $wp_query->get_queried_object();
    464422                        $classes[] = 'tag';
    465423                        $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;
    472424                }
    473425        } elseif ( is_page() ) {
    … …  
    500452        if ( is_user_logged_in() )
    501453                $classes[] = 'logged-in';
    502 
    503         if ( is_admin_bar_showing() )
    504                 $classes[] = 'admin-bar';
    505454
    506455        $page = $wp_query->get( 'page' );
    … …  
    526475                elseif ( is_search() )
    527476                        $classes[] = 'search-paged-' . $page;
    528                 elseif ( is_post_type_archive() )
    529                         $classes[] = 'post-type-paged-' . $page;
    530477        }
    531478
    … …  
    631578        extract( $r, EXTR_SKIP );
    632579
    633         global $page, $numpages, $multipage, $more, $pagenow;
     580        global $post, $page, $numpages, $multipage, $more, $pagenow;
    634581
    635582        $output = '';
    … …  
    641588                                $output .= ' ';
    642589                                if ( ($i != $page) || ((!$more) && ($page==1)) ) {
    643                                         $output .= _wp_link_page($i);
     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
    644601                                }
    645                                 $output .= $link_before . $j . $link_after;
     602                                $output .= $link_before;
     603                                $output .= $j;
     604                                $output .= $link_after;
    646605                                if ( ($i != $page) || ((!$more) && ($page==1)) )
    647606                                        $output .= '</a>';
    … …  
    653612                                $i = $page - 1;
    654613                                if ( $i && $more ) {
    655                                         $output .= _wp_link_page($i);
     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                                        }
    656624                                        $output .= $link_before. $previouspagelink . $link_after . '</a>';
    657625                                }
    658626                                $i = $page + 1;
    659627                                if ( $i <= $numpages && $more ) {
    660                                         $output .= _wp_link_page($i);
     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                                        }
    661638                                        $output .= $link_before. $nextpagelink . $link_after . '</a>';
    662639                                }
    … …  
    672649}
    673650
    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  */
    683 function _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 }
    699651
    700652//
    … …  
    733685                foreach ( (array) $keys as $key ) {
    734686                        $keyt = trim($key);
    735                         if ( '_' == $keyt[0] )
     687                        if ( '_' == $keyt{0} )
    736688                                continue;
    737689                        $values = array_map('trim', get_post_custom_values($key));
    … …  
    956908}
    957909
    958 /**
    959  * Create HTML list of pages.
    960  *
    961  * @package WordPress
    962  * @since 2.1.0
    963  * @uses Walker
    964  */
    965 class 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  */
    1071 class 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 
    1110910//
    1111911// Attachments
Note: See TracChangeset for help on using the changeset viewer.