-
+ 79671CE00F8C01FBF7FC04EBD6DE47721CD3DAE43E8F89ECA12F543B4D7A94E24AF5BBDD719B37777352DB779389BCA8102C3C0CC38489A25142522EDDE4869A
mp-wp/wp-includes/post-template.php
(0 . 0)(1 . 1199)
139934 <?php
139935 /**
139936 * WordPress Post Template Functions.
139937 *
139938 * Gets content for the current post in the loop.
139939 *
139940 * @package WordPress
139941 * @subpackage Template
139942 */
139943
139944 /**
139945 * Display the ID of the current item in the WordPress Loop.
139946 *
139947 * @since 0.71
139948 * @uses $id
139949 */
139950 function the_ID() {
139951 global $id;
139952 echo $id;
139953 }
139954
139955 /**
139956 * Retrieve the ID of the current item in the WordPress Loop.
139957 *
139958 * @since 2.1.0
139959 * @uses $id
139960 *
139961 * @return unknown
139962 */
139963 function get_the_ID() {
139964 global $id;
139965 return $id;
139966 }
139967
139968 /**
139969 * Display or retrieve the current post title with optional content.
139970 *
139971 * @since 0.71
139972 *
139973 * @param string $before Optional. Content to prepend to the title.
139974 * @param string $after Optional. Content to append to the title.
139975 * @param bool $echo Optional, default to true.Whether to display or return.
139976 * @return null|string Null on no title. String if $echo parameter is false.
139977 */
139978 function the_title($before = '', $after = '', $echo = true) {
139979 $title = get_the_title();
139980
139981 if ( strlen($title) == 0 )
139982 return;
139983
139984 $title = $before . $title . $after;
139985
139986 if ( $echo )
139987 echo $title;
139988 else
139989 return $title;
139990 }
139991
139992 /**
139993 * Sanitize the current title when retrieving or displaying.
139994 *
139995 * Works like {@link the_title()}, except the parameters can be in a string or
139996 * an array. See the function for what can be override in the $args parameter.
139997 *
139998 * The title before it is displayed will have the tags stripped and {@link
139999 * attribute_escape()} before it is passed to the user or displayed. The default
140000 * as with {@link the_title()}, is to display the title.
140001 *
140002 * @since 2.3.0
140003 *
140004 * @param string|array $args Optional. Override the defaults.
140005 * @return string|null Null on failure or display. String when echo is false.
140006 */
140007 function the_title_attribute( $args = '' ) {
140008 $title = get_the_title();
140009
140010 if ( strlen($title) == 0 )
140011 return;
140012
140013 $defaults = array('before' => '', 'after' => '', 'echo' => true);
140014 $r = wp_parse_args($args, $defaults);
140015 extract( $r, EXTR_SKIP );
140016
140017
140018 $title = $before . $title . $after;
140019 $title = attribute_escape(strip_tags($title));
140020
140021 if ( $echo )
140022 echo $title;
140023 else
140024 return $title;
140025 }
140026
140027 /**
140028 * Retrieve post title.
140029 *
140030 * If the post is protected and the visitor is not an admin, then "Protected"
140031 * will be displayed before the post title. If the post is private, then
140032 * "Private" will be located before the post title.
140033 *
140034 * @since 0.71
140035 *
140036 * @param int $id Optional. Post ID.
140037 * @return string
140038 */
140039 function get_the_title( $id = 0 ) {
140040 $post = &get_post($id);
140041
140042 $title = $post->post_title;
140043
140044 if ( !is_admin() ) {
140045 if ( !empty($post->post_password) )
140046 $title = sprintf(__('Protected: %s'), $title);
140047 else if ( isset($post->post_status) && 'private' == $post->post_status )
140048 $title = sprintf(__('Private: %s'), $title);
140049 }
140050 return apply_filters( 'the_title', $title );
140051 }
140052
140053 /**
140054 * Display the Post Global Unique Identifier (guid).
140055 *
140056 * The guid will appear to be a link, but should not be used as an link to the
140057 * post. The reason you should not use it as a link, is because of moving the
140058 * blog across domains.
140059 *
140060 * @since 1.5.0
140061 *
140062 * @param int $id Optional. Post ID.
140063 */
140064 function the_guid( $id = 0 ) {
140065 echo get_the_guid($id);
140066 }
140067
140068 /**
140069 * Retrieve the Post Global Unique Identifier (guid).
140070 *
140071 * The guid will appear to be a link, but should not be used as an link to the
140072 * post. The reason you should not use it as a link, is because of moving the
140073 * blog across domains.
140074 *
140075 * @since 1.5.0
140076 *
140077 * @param int $id Optional. Post ID.
140078 * @return string
140079 */
140080 function get_the_guid( $id = 0 ) {
140081 $post = &get_post($id);
140082
140083 return apply_filters('get_the_guid', $post->guid);
140084 }
140085
140086 /**
140087 * Display the post content.
140088 *
140089 * @since 0.71
140090 *
140091 * @param string $more_link_text Optional. Content for when there is more text.
140092 * @param string $stripteaser Optional. Teaser content before the more text.
140093 * @param string $more_file Optional. Not used.
140094 */
140095 function the_content($more_link_text = null, $stripteaser = 0, $more_file = '') {
140096 $content = get_the_content($more_link_text, $stripteaser, $more_file);
140097 $content = apply_filters('the_content', $content);
140098 $content = str_replace(']]>', ']]>', $content);
140099 echo $content;
140100 }
140101
140102 /**
140103 * Retrieve the post content.
140104 *
140105 * @since 0.71
140106 *
140107 * @param string $more_link_text Optional. Content for when there is more text.
140108 * @param string $stripteaser Optional. Teaser content before the more text.
140109 * @param string $more_file Optional. Not used.
140110 * @return string
140111 */
140112 function get_the_content($more_link_text = null, $stripteaser = 0, $more_file = '') {
140113 global $id, $post, $more, $page, $pages, $multipage, $preview, $pagenow;
140114
140115 if ( null === $more_link_text )
140116 $more_link_text = __( '(more...)' );
140117
140118 $output = '';
140119
140120 // If post password required and it doesn't match the cookie.
140121 if ( post_password_required($post) ) {
140122 $output = get_the_password_form();
140123 return $output;
140124 }
140125
140126 if ( $more_file != '' )
140127 $file = $more_file;
140128 else
140129 $file = $pagenow; //$_SERVER['PHP_SELF'];
140130
140131 if ( $page > count($pages) ) // if the requested page doesn't exist
140132 $page = count($pages); // give them the highest numbered page that DOES exist
140133
140134 $content = $pages[$page-1];
140135 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
140136 $content = explode($matches[0], $content, 2);
140137 if ( !empty($matches[1]) && !empty($more_link_text) )
140138 $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
140139 } else {
140140 $content = array($content);
140141 }
140142 if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
140143 $stripteaser = 1;
140144 $teaser = $content[0];
140145 if ( ($more) && ($stripteaser) )
140146 $teaser = '';
140147 $output .= $teaser;
140148 if ( count($content) > 1 ) {
140149 if ( $more ) {
140150 $output .= '<span id="more-'.$id.'"></span>'.$content[1];
140151 } else {
140152 $output = balanceTags($output);
140153 if ( ! empty($more_link_text) )
140154 $output .= ' <a href="'. get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>";
140155 }
140156
140157 }
140158 if ( $preview ) // preview fix for javascript bug with foreign languages
140159 $output = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $output);
140160
140161 return $output;
140162 }
140163
140164 /**
140165 * Display the post excerpt.
140166 *
140167 * @since 0.71
140168 * @uses apply_filters() Calls 'the_excerpt' hook on post excerpt.
140169 */
140170 function the_excerpt() {
140171 echo apply_filters('the_excerpt', get_the_excerpt());
140172 }
140173
140174 /**
140175 * Retrieve the post excerpt.
140176 *
140177 * @since 0.71
140178 *
140179 * @param mixed $deprecated Not used.
140180 * @return string
140181 */
140182 function get_the_excerpt($deprecated = '') {
140183 global $post;
140184 $output = '';
140185 $output = $post->post_excerpt;
140186 if ( post_password_required($post) ) {
140187 $output = __('There is no excerpt because this is a protected post.');
140188 return $output;
140189 }
140190
140191 return apply_filters('get_the_excerpt', $output);
140192 }
140193
140194 /**
140195 * Whether post has excerpt.
140196 *
140197 * @since 2.3.0
140198 *
140199 * @param int $id Optional. Post ID.
140200 * @return bool
140201 */
140202 function has_excerpt( $id = 0 ) {
140203 $post = &get_post( $id );
140204 return ( !empty( $post->post_excerpt ) );
140205 }
140206
140207 /**
140208 * Display the classes for the post div.
140209 *
140210 * @since 2.7.0
140211 *
140212 * @param string|array $class One or more classes to add to the class list.
140213 * @param int $post_id An optional post ID.
140214 */
140215 function post_class( $class = '', $post_id = null ) {
140216 // Separates classes with a single space, collates classes for post DIV
140217 echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
140218 }
140219
140220 /**
140221 * Retrieve the classes for the post div as an array.
140222 *
140223 * The class names are add are many. If the post is a sticky, then the 'sticky'
140224 * class name. The class 'hentry' is always added to each post. For each
140225 * category, the class will be added with 'category-' with category slug is
140226 * added. The tags are the same way as the categories with 'tag-' before the tag
140227 * slug. All classes are passed through the filter, 'post_class' with the list
140228 * of classes, followed by $class parameter value, with the post ID as the last
140229 * parameter.
140230 *
140231 * @since 2.7.0
140232 *
140233 * @param string|array $class One or more classes to add to the class list.
140234 * @param int $post_id An optional post ID.
140235 * @return array Array of classes.
140236 */
140237 function get_post_class( $class = '', $post_id = null ) {
140238 $post = get_post($post_id);
140239
140240 $classes = array();
140241
140242 $classes[] = $post->post_type;
140243
140244 // sticky for Sticky Posts
140245 if ( is_sticky($post->ID) && is_home())
140246 $classes[] = 'sticky';
140247
140248 // hentry for hAtom compliace
140249 $classes[] = 'hentry';
140250
140251 // Categories
140252 foreach ( (array) get_the_category($post->ID) as $cat ) {
140253 if ( empty($cat->slug ) )
140254 continue;
140255 $classes[] = 'category-' . $cat->slug;
140256 }
140257
140258 // Tags
140259 foreach ( (array) get_the_tags($post->ID) as $tag ) {
140260 if ( empty($tag->slug ) )
140261 continue;
140262 $classes[] = 'tag-' . $tag->slug;
140263 }
140264
140265 if ( !empty($class) ) {
140266 if ( !is_array( $class ) )
140267 $class = preg_split('#\s+#', $class);
140268 $classes = array_merge($classes, $class);
140269 }
140270
140271 return apply_filters('post_class', $classes, $class, $post_id);
140272 }
140273
140274 /**
140275 * Whether post requires password and correct password has been provided.
140276 *
140277 * @since 2.7.0
140278 *
140279 * @param int|object $post An optional post. Global $post used if not provided.
140280 * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
140281 */
140282 function post_password_required( $post = null ) {
140283 $post = get_post($post);
140284
140285 if ( empty($post->post_password) )
140286 return false;
140287
140288 if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) )
140289 return true;
140290
140291 if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password )
140292 return true;
140293
140294 return false;
140295 }
140296
140297 /**
140298 * Display "sticky" CSS class, if a post is sticky.
140299 *
140300 * @since 2.7.0
140301 *
140302 * @param int $post_id An optional post ID.
140303 */
140304 function sticky_class( $post_id = null ) {
140305 if ( !is_sticky($post_id) )
140306 return;
140307
140308 echo " sticky";
140309 }
140310
140311 /**
140312 * Page Template Functions for usage in Themes
140313 *
140314 * @package WordPress
140315 * @subpackage Template
140316 */
140317
140318 /**
140319 * The formatted output of a list of pages.
140320 *
140321 * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
140322 * Quicktag one or more times). This tag must be within The Loop.
140323 *
140324 * The defaults for overwriting are:
140325 * 'next_or_number' - Default is 'number' (string). Indicates whether page
140326 * numbers should be used. Valid values are number and next.
140327 * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
140328 * of the bookmark.
140329 * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
140330 * previous page, if available.
140331 * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
140332 * the parameter string will be replaced with the page number, so Page %
140333 * generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
140334 * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
140335 * each bookmarks.
140336 * 'after' - Default is '</p>' (string). The html or text to append to each
140337 * bookmarks.
140338 * 'more_file' - Default is '' (string) Page the links should point to. Defaults
140339 * to the current page.
140340 * 'link_before' - Default is '' (string). The html or text to prepend to each
140341 * Pages link inside the <a> tag.
140342 * 'link_after' - Default is '' (string). The html or text to append to each
140343 * Pages link inside the <a> tag.
140344 *
140345 * @since 1.2.0
140346 * @access private
140347 *
140348 * @param string|array $args Optional. Overwrite the defaults.
140349 * @return string Formatted output in HTML.
140350 */
140351 function wp_link_pages($args = '') {
140352 $defaults = array(
140353 'before' => '<p>' . __('Pages:'), 'after' => '</p>',
140354 'link_before' => '', 'link_after' => '',
140355 'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
140356 'previouspagelink' => __('Previous page'), 'pagelink' => '%',
140357 'more_file' => '', 'echo' => 1
140358 );
140359
140360 $r = wp_parse_args( $args, $defaults );
140361 extract( $r, EXTR_SKIP );
140362
140363 global $post, $page, $numpages, $multipage, $more, $pagenow;
140364 if ( $more_file != '' )
140365 $file = $more_file;
140366 else
140367 $file = $pagenow;
140368
140369 $output = '';
140370 if ( $multipage ) {
140371 if ( 'number' == $next_or_number ) {
140372 $output .= $before;
140373 for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
140374 $j = str_replace('%',"$i",$pagelink);
140375 $output .= ' ';
140376 if ( ($i != $page) || ((!$more) && ($page==1)) ) {
140377 if ( 1 == $i ) {
140378 $output .= '<a href="' . get_permalink() . '">';
140379 } else {
140380 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
140381 $output .= '<a href="' . get_permalink() . '&page=' . $i . '">';
140382 else
140383 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
140384 }
140385
140386 }
140387 $output .= $link_before;
140388 $output .= $j;
140389 $output .= $link_after;
140390 if ( ($i != $page) || ((!$more) && ($page==1)) )
140391 $output .= '</a>';
140392 }
140393 $output .= $after;
140394 } else {
140395 if ( $more ) {
140396 $output .= $before;
140397 $i = $page - 1;
140398 if ( $i && $more ) {
140399 if ( 1 == $i ) {
140400 $output .= '<a href="' . get_permalink() . '">' . $link_before. $previouspagelink . $link_after . '</a>';
140401 } else {
140402 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
140403 $output .= '<a href="' . get_permalink() . '&page=' . $i . '">' . $link_before. $previouspagelink . $link_after . '</a>';
140404 else
140405 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $link_before. $previouspagelink . $link_after . '</a>';
140406 }
140407 }
140408 $i = $page + 1;
140409 if ( $i <= $numpages && $more ) {
140410 if ( 1 == $i ) {
140411 $output .= '<a href="' . get_permalink() . '">' . $link_before. $nextpagelink . $link_after . '</a>';
140412 } else {
140413 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
140414 $output .= '<a href="' . get_permalink() . '&page=' . $i . '">' . $link_before. $nextpagelink . $link_after . '</a>';
140415 else
140416 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $link_before. $nextpagelink . $link_after . '</a>';
140417 }
140418 }
140419 $output .= $after;
140420 }
140421 }
140422 }
140423
140424 if ( $echo )
140425 echo $output;
140426
140427 return $output;
140428 }
140429
140430
140431 //
140432 // Post-meta: Custom per-post fields.
140433 //
140434
140435 /**
140436 * Retrieve post custom meta data field.
140437 *
140438 * @since 1.5.0
140439 *
140440 * @param string $key Meta data key name.
140441 * @return string|array Array of values or single value, if only one element exists.
140442 */
140443 function post_custom( $key = '' ) {
140444 $custom = get_post_custom();
140445
140446 if ( 1 == count($custom[$key]) )
140447 return $custom[$key][0];
140448 else
140449 return $custom[$key];
140450 }
140451
140452 /**
140453 * Display list of post custom fields.
140454 *
140455 * @internal This will probably change at some point...
140456 * @since 1.2.0
140457 * @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters.
140458 */
140459 function the_meta() {
140460 if ( $keys = get_post_custom_keys() ) {
140461 echo "<ul class='post-meta'>\n";
140462 foreach ( (array) $keys as $key ) {
140463 $keyt = trim($key);
140464 if ( '_' == $keyt{0} )
140465 continue;
140466 $values = array_map('trim', get_post_custom_values($key));
140467 $value = implode($values,', ');
140468 echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
140469 }
140470 echo "</ul>\n";
140471 }
140472 }
140473
140474 //
140475 // Pages
140476 //
140477
140478 /**
140479 * Retrieve or display list of pages as a dropdown (select list).
140480 *
140481 * @since 2.1.0
140482 *
140483 * @param array|string $args Optional. Override default arguments.
140484 * @return string HTML content, if not displaying.
140485 */
140486 function wp_dropdown_pages($args = '') {
140487 $defaults = array(
140488 'depth' => 0, 'child_of' => 0,
140489 'selected' => 0, 'echo' => 1,
140490 'name' => 'page_id', 'show_option_none' => '', 'show_option_no_change' => '',
140491 'option_none_value' => ''
140492 );
140493
140494 $r = wp_parse_args( $args, $defaults );
140495 extract( $r, EXTR_SKIP );
140496
140497 $pages = get_pages($r);
140498 $output = '';
140499
140500 if ( ! empty($pages) ) {
140501 $output = "<select name=\"$name\" id=\"$name\">\n";
140502 if ( $show_option_no_change )
140503 $output .= "\t<option value=\"-1\">$show_option_no_change</option>";
140504 if ( $show_option_none )
140505 $output .= "\t<option value=\"$option_none_value\">$show_option_none</option>\n";
140506 $output .= walk_page_dropdown_tree($pages, $depth, $r);
140507 $output .= "</select>\n";
140508 }
140509
140510 $output = apply_filters('wp_dropdown_pages', $output);
140511
140512 if ( $echo )
140513 echo $output;
140514
140515 return $output;
140516 }
140517
140518 /**
140519 * Retrieve or display list of pages in list (li) format.
140520 *
140521 * @since 1.5.0
140522 *
140523 * @param array|string $args Optional. Override default arguments.
140524 * @return string HTML content, if not displaying.
140525 */
140526 function wp_list_pages($args = '') {
140527 $defaults = array(
140528 'depth' => 0, 'show_date' => '',
140529 'date_format' => get_option('date_format'),
140530 'child_of' => 0, 'exclude' => '',
140531 'title_li' => __('Pages'), 'echo' => 1,
140532 'authors' => '', 'sort_column' => 'menu_order, post_title',
140533 'link_before' => '', 'link_after' => ''
140534 );
140535
140536 $r = wp_parse_args( $args, $defaults );
140537 extract( $r, EXTR_SKIP );
140538
140539 $output = '';
140540 $current_page = 0;
140541
140542 // sanitize, mostly to keep spaces out
140543 $r['exclude'] = preg_replace('[^0-9,]', '', $r['exclude']);
140544
140545 // Allow plugins to filter an array of excluded pages
140546 $r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
140547
140548 // Query pages.
140549 $r['hierarchical'] = 0;
140550 $pages = get_pages($r);
140551
140552 if ( !empty($pages) ) {
140553 if ( $r['title_li'] )
140554 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
140555
140556 global $wp_query;
140557 if ( is_page() || $wp_query->is_posts_page )
140558 $current_page = $wp_query->get_queried_object_id();
140559 $output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
140560
140561 if ( $r['title_li'] )
140562 $output .= '</ul></li>';
140563 }
140564
140565 $output = apply_filters('wp_list_pages', $output);
140566
140567 if ( $r['echo'] )
140568 echo $output;
140569 else
140570 return $output;
140571 }
140572
140573 /**
140574 * Display or retrieve list of pages with optional home link.
140575 *
140576 * The arguments are listed below and part of the arguments are for {@link
140577 * wp_list_pages()} function. Check that function for more info on those
140578 * arguments.
140579 *
140580 * <ul>
140581 * <li><strong>sort_column</strong> - How to sort the list of pages. Defaults
140582 * to page title. Use column for posts table.</li>
140583 * <li><strong>menu_class</strong> - Class to use for the div ID which contains
140584 * the page list. Defaults to 'menu'.</li>
140585 * <li><strong>echo</strong> - Whether to echo list or return it. Defaults to
140586 * echo.</li>
140587 * <li><strong>link_before</strong> - Text before show_home argument text.</li>
140588 * <li><strong>link_after</strong> - Text after show_home argument text.</li>
140589 * <li><strong>show_home</strong> - If you set this argument, then it will
140590 * display the link to the home page. The show_home argument really just needs
140591 * to be set to the value of the text of the link.</li>
140592 * </ul>
140593 *
140594 * @since 2.7.0
140595 *
140596 * @param array|string $args
140597 */
140598 function wp_page_menu( $args = array() ) {
140599 $defaults = array('sort_column' => 'post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
140600 $args = wp_parse_args( $args, $defaults );
140601 $args = apply_filters( 'wp_page_menu_args', $args );
140602
140603 $menu = '';
140604
140605 $list_args = $args;
140606
140607 // Show Home in the menu
140608 if ( isset($args['show_home']) && ! empty($args['show_home']) ) {
140609 if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
140610 $text = __('Home');
140611 else
140612 $text = $args['show_home'];
140613 $class = '';
140614 if ( is_front_page() && !is_paged() )
140615 $class = 'class="current_page_item"';
140616 $menu .= '<li ' . $class . '><a href="' . get_option('home') . '">' . $link_before . $text . $link_after . '</a></li>';
140617 // If the front page is a page, add it to the exclude list
140618 if (get_option('show_on_front') == 'page') {
140619 if ( !empty( $list_args['exclude'] ) ) {
140620 $list_args['exclude'] .= ',';
140621 } else {
140622 $list_args['exclude'] = '';
140623 }
140624 $list_args['exclude'] .= get_option('page_on_front');
140625 }
140626 }
140627
140628 $list_args['echo'] = false;
140629 $list_args['title_li'] = '';
140630 $menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
140631
140632 if ( $menu )
140633 $menu = '<ul>' . $menu . '</ul>';
140634
140635 $menu = '<div class="' . $args['menu_class'] . '">' . $menu . "</div>\n";
140636 $menu = apply_filters( 'wp_page_menu', $menu, $args );
140637 if ( $args['echo'] )
140638 echo $menu;
140639 else
140640 return $menu;
140641 }
140642
140643 //
140644 // Page helpers
140645 //
140646
140647 /**
140648 * Retrieve HTML list content for page list.
140649 *
140650 * @uses Walker_Page to create HTML list content.
140651 * @since 2.1.0
140652 * @see Walker_Page::walk() for parameters and return description.
140653 */
140654 function walk_page_tree($pages, $depth, $current_page, $r) {
140655 $walker = new Walker_Page;
140656 $args = array($pages, $depth, $r, $current_page);
140657 return call_user_func_array(array(&$walker, 'walk'), $args);
140658 }
140659
140660 /**
140661 * Retrieve HTML dropdown (select) content for page list.
140662 *
140663 * @uses Walker_PageDropdown to create HTML dropdown content.
140664 * @since 2.1.0
140665 * @see Walker_PageDropdown::walk() for parameters and return description.
140666 */
140667 function walk_page_dropdown_tree() {
140668 $walker = new Walker_PageDropdown;
140669 $args = func_get_args();
140670 return call_user_func_array(array(&$walker, 'walk'), $args);
140671 }
140672
140673 //
140674 // Attachments
140675 //
140676
140677 /**
140678 * Display an attachment page link using an image or icon.
140679 *
140680 * @since 2.0.0
140681 *
140682 * @param int $id Optional. Post ID.
140683 * @param bool $fullsize Optional, default is false. Whether to use full size.
140684 * @param bool $deprecated Deprecated. Not used.
140685 * @param bool $permalink Optional, default is false. Whether to include permalink.
140686 */
140687 function the_attachment_link($id = 0, $fullsize = false, $deprecated = false, $permalink = false) {
140688 if ( $fullsize )
140689 echo wp_get_attachment_link($id, 'full', $permalink);
140690 else
140691 echo wp_get_attachment_link($id, 'thumbnail', $permalink);
140692 }
140693
140694 /**
140695 * Retrieve an attachment page link using an image or icon, if possible.
140696 *
140697 * @since 2.5.0
140698 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
140699 *
140700 * @param int $id Optional. Post ID.
140701 * @param string $size Optional. Image size.
140702 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
140703 * @param bool $icon Optional, default is false. Whether to include icon.
140704 * @return string HTML content.
140705 */
140706 function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false) {
140707 $id = intval($id);
140708 $_post = & get_post( $id );
140709
140710 if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
140711 return __('Missing Attachment');
140712
140713 if ( $permalink )
140714 $url = get_attachment_link($_post->ID);
140715
140716 $post_title = attribute_escape($_post->post_title);
140717
140718 $link_text = wp_get_attachment_image($id, $size, $icon);
140719 if ( !$link_text )
140720 $link_text = $_post->post_title;
140721
140722 return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon );
140723 }
140724
140725 /**
140726 * Retrieve HTML content of attachment image with link.
140727 *
140728 * @since 2.0.0
140729 * @deprecated Use {@link wp_get_attachment_link()}
140730 * @see wp_get_attachment_link() Use instead.
140731 *
140732 * @param int $id Optional. Post ID.
140733 * @param bool $fullsize Optional, default is false. Whether to use full size image.
140734 * @param array $max_dims Optional. Max image dimensions.
140735 * @param bool $permalink Optional, default is false. Whether to include permalink to image.
140736 * @return string
140737 */
140738 function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false) {
140739 $id = (int) $id;
140740 $_post = & get_post($id);
140741
140742 if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
140743 return __('Missing Attachment');
140744
140745 if ( $permalink )
140746 $url = get_attachment_link($_post->ID);
140747
140748 $post_title = attribute_escape($_post->post_title);
140749
140750 $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
140751 return "<a href='$url' title='$post_title'>$innerHTML</a>";
140752 }
140753
140754 /**
140755 * Retrieve icon URL and Path.
140756 *
140757 * @since 2.1.0
140758 * @deprecated Use {@link wp_get_attachment_image_src()}
140759 * @see wp_get_attachment_image_src() Use instead.
140760 *
140761 * @param int $id Optional. Post ID.
140762 * @param bool $fullsize Optional, default to false. Whether to have full image.
140763 * @return array Icon URL and full path to file, respectively.
140764 */
140765 function get_attachment_icon_src( $id = 0, $fullsize = false ) {
140766 $id = (int) $id;
140767 if ( !$post = & get_post($id) )
140768 return false;
140769
140770 $file = get_attached_file( $post->ID );
140771
140772 if ( !$fullsize && $src = wp_get_attachment_thumb_url( $post->ID ) ) {
140773 // We have a thumbnail desired, specified and existing
140774
140775 $src_file = basename($src);
140776 $class = 'attachmentthumb';
140777 } elseif ( wp_attachment_is_image( $post->ID ) ) {
140778 // We have an image without a thumbnail
140779
140780 $src = wp_get_attachment_url( $post->ID );
140781 $src_file = & $file;
140782 $class = 'attachmentimage';
140783 } elseif ( $src = wp_mime_type_icon( $post->ID ) ) {
140784 // No thumb, no image. We'll look for a mime-related icon instead.
140785
140786 $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
140787 $src_file = $icon_dir . '/' . basename($src);
140788 }
140789
140790 if ( !isset($src) || !$src )
140791 return false;
140792
140793 return array($src, $src_file);
140794 }
140795
140796 /**
140797 * Retrieve HTML content of icon attachment image element.
140798 *
140799 * @since 2.0.0
140800 * @deprecated Use {@link wp_get_attachment_image()}
140801 * @see wp_get_attachment_image() Use instead of.
140802 *
140803 * @param int $id Optional. Post ID.
140804 * @param bool $fullsize Optional, default to false. Whether to have full size image.
140805 * @param array $max_dims Optional. Dimensions of image.
140806 * @return string HTML content.
140807 */
140808 function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) {
140809 $id = (int) $id;
140810 if ( !$post = & get_post($id) )
140811 return false;
140812
140813 if ( !$src = get_attachment_icon_src( $post->ID, $fullsize ) )
140814 return false;
140815
140816 list($src, $src_file) = $src;
140817
140818 // Do we need to constrain the image?
140819 if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {
140820
140821 $imagesize = getimagesize($src_file);
140822
140823 if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {
140824 $actual_aspect = $imagesize[0] / $imagesize[1];
140825 $desired_aspect = $max_dims[0] / $max_dims[1];
140826
140827 if ( $actual_aspect >= $desired_aspect ) {
140828 $height = $actual_aspect * $max_dims[0];
140829 $constraint = "width='{$max_dims[0]}' ";
140830 $post->iconsize = array($max_dims[0], $height);
140831 } else {
140832 $width = $max_dims[1] / $actual_aspect;
140833 $constraint = "height='{$max_dims[1]}' ";
140834 $post->iconsize = array($width, $max_dims[1]);
140835 }
140836 } else {
140837 $post->iconsize = array($imagesize[0], $imagesize[1]);
140838 $constraint = '';
140839 }
140840 } else {
140841 $constraint = '';
140842 }
140843
140844 $post_title = attribute_escape($post->post_title);
140845
140846 $icon = "<img src='$src' title='$post_title' alt='$post_title' $constraint/>";
140847
140848 return apply_filters( 'attachment_icon', $icon, $post->ID );
140849 }
140850
140851 /**
140852 * Retrieve HTML content of image element.
140853 *
140854 * @since 2.0.0
140855 * @deprecated Use {@link wp_get_attachment_image()}
140856 * @see wp_get_attachment_image() Use instead.
140857 *
140858 * @param int $id Optional. Post ID.
140859 * @param bool $fullsize Optional, default to false. Whether to have full size image.
140860 * @param array $max_dims Optional. Dimensions of image.
140861 * @return string
140862 */
140863 function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) {
140864 $id = (int) $id;
140865 if ( !$post = & get_post($id) )
140866 return false;
140867
140868 if ( $innerHTML = get_attachment_icon($post->ID, $fullsize, $max_dims))
140869 return $innerHTML;
140870
140871
140872 $innerHTML = attribute_escape($post->post_title);
140873
140874 return apply_filters('attachment_innerHTML', $innerHTML, $post->ID);
140875 }
140876
140877 /**
140878 * Wrap attachment in <<p>> element before content.
140879 *
140880 * @since 2.0.0
140881 * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content.
140882 *
140883 * @param string $content
140884 * @return string
140885 */
140886 function prepend_attachment($content) {
140887 global $post;
140888
140889 if ( empty($post->post_type) || $post->post_type != 'attachment' )
140890 return $content;
140891
140892 $p = '<p class="attachment">';
140893 // show the medium sized image representation of the attachment if available, and link to the raw file
140894 $p .= wp_get_attachment_link(0, 'medium', false);
140895 $p .= '</p>';
140896 $p = apply_filters('prepend_attachment', $p);
140897
140898 return "$p\n$content";
140899 }
140900
140901 //
140902 // Misc
140903 //
140904
140905 /**
140906 * Retrieve protected post password form content.
140907 *
140908 * @since 1.0.0
140909 * @uses apply_filters() Calls 'the_password_form' filter on output.
140910 *
140911 * @return string HTML content for password form for password protected post.
140912 */
140913 function get_the_password_form() {
140914 global $post;
140915 $label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
140916 $output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
140917 <p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
140918 <p><label for="' . $label . '">' . __("Password:") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . __("Submit") . '" /></p>
140919 </form>
140920 ';
140921 return apply_filters('the_password_form', $output);
140922 }
140923
140924 /**
140925 * Whether currently in a page template.
140926 *
140927 * This template tag allows you to determine whether or not you are in a page
140928 * template. You can optional provide a template name and then the check will be
140929 * specific to that template.
140930 *
140931 * @since 2.5.0
140932 * @uses $wp_query
140933 *
140934 * @param string $template The specific template name if specific matching is required.
140935 * @return bool False on failure, true if success.
140936 */
140937 function is_page_template($template = '') {
140938 if (!is_page()) {
140939 return false;
140940 }
140941
140942 global $wp_query;
140943
140944 $page = $wp_query->get_queried_object();
140945 $custom_fields = get_post_custom_values('_wp_page_template',$page->ID);
140946 $page_template = $custom_fields[0];
140947
140948 // We have no argument passed so just see if a page_template has been specified
140949 if ( empty( $template ) ) {
140950 if (!empty( $page_template ) ) {
140951 return true;
140952 }
140953 } elseif ( $template == $page_template) {
140954 return true;
140955 }
140956
140957 return false;
140958 }
140959
140960 /**
140961 * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
140962 *
140963 * @package WordPress
140964 * @subpackage Post_Revisions
140965 * @since 2.6.0
140966 *
140967 * @uses date_i18n()
140968 *
140969 * @param int|object $revision Revision ID or revision object.
140970 * @param bool $link Optional, default is true. Link to revisions's page?
140971 * @return string i18n formatted datetimestamp or localized 'Current Revision'.
140972 */
140973 function wp_post_revision_title( $revision, $link = true ) {
140974 if ( !$revision = get_post( $revision ) )
140975 return $revision;
140976
140977 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
140978 return false;
140979
140980 $datef = _c( 'j F, Y @ G:i|revision date format');
140981 $autosavef = __( '%s [Autosave]' );
140982 $currentf = __( '%s [Current Revision]' );
140983
140984 $date = date_i18n( $datef, strtotime( $revision->post_modified_gmt . ' +0000' ) );
140985 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
140986 $date = "<a href='$link'>$date</a>";
140987
140988 if ( !wp_is_post_revision( $revision ) )
140989 $date = sprintf( $currentf, $date );
140990 elseif ( wp_is_post_autosave( $revision ) )
140991 $date = sprintf( $autosavef, $date );
140992
140993 return $date;
140994 }
140995
140996 /**
140997 * Display list of a post's revisions.
140998 *
140999 * Can output either a UL with edit links or a TABLE with diff interface, and
141000 * restore action links.
141001 *
141002 * Second argument controls parameters:
141003 * (bool) parent : include the parent (the "Current Revision") in the list.
141004 * (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table'
141005 * outputs TABLE with UI.
141006 * (int) right : what revision is currently being viewed - used in
141007 * form-table format.
141008 * (int) left : what revision is currently being diffed against right -
141009 * used in form-table format.
141010 *
141011 * @package WordPress
141012 * @subpackage Post_Revisions
141013 * @since 2.6.0
141014 *
141015 * @uses wp_get_post_revisions()
141016 * @uses wp_post_revision_title()
141017 * @uses get_edit_post_link()
141018 * @uses get_author_name()
141019 *
141020 * @todo split into two functions (list, form-table) ?
141021 *
141022 * @param int|object $post_id Post ID or post object.
141023 * @param string|array $args See description {@link wp_parse_args()}.
141024 * @return null
141025 */
141026 function wp_list_post_revisions( $post_id = 0, $args = null ) {
141027 if ( !$post = get_post( $post_id ) )
141028 return;
141029
141030 $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );
141031 extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
141032
141033 switch ( $type ) {
141034 case 'autosave' :
141035 if ( !$autosave = wp_get_post_autosave( $post->ID ) )
141036 return;
141037 $revisions = array( $autosave );
141038 break;
141039 case 'revision' : // just revisions - remove autosave later
141040 case 'all' :
141041 default :
141042 if ( !$revisions = wp_get_post_revisions( $post->ID ) )
141043 return;
141044 break;
141045 }
141046
141047 $titlef = _c( '%1$s by %2$s|post revision 1:datetime, 2:name' );
141048
141049 if ( $parent )
141050 array_unshift( $revisions, $post );
141051
141052 $rows = '';
141053 $class = false;
141054 $can_edit_post = current_user_can( 'edit_post', $post->ID );
141055 foreach ( $revisions as $revision ) {
141056 if ( !current_user_can( 'read_post', $revision->ID ) )
141057 continue;
141058 if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
141059 continue;
141060
141061 $date = wp_post_revision_title( $revision );
141062 $name = get_author_name( $revision->post_author );
141063
141064 if ( 'form-table' == $format ) {
141065 if ( $left )
141066 $left_checked = $left == $revision->ID ? ' checked="checked"' : '';
141067 else
141068 $left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
141069 $right_checked = $right == $revision->ID ? ' checked="checked"' : '';
141070
141071 $class = $class ? '' : " class='alternate'";
141072
141073 if ( $post->ID != $revision->ID && $can_edit_post )
141074 $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'diff' => false, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
141075 else
141076 $actions = '';
141077
141078 $rows .= "<tr$class>\n";
141079 $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
141080 $rows .= "\t<td>$date</td>\n";
141081 $rows .= "\t<td>$name</td>\n";
141082 $rows .= "\t<td class='action-links'>$actions</td>\n";
141083 $rows .= "</tr>\n";
141084 } else {
141085 $title = sprintf( $titlef, $date, $name );
141086 $rows .= "\t<li>$title</li>\n";
141087 }
141088 }
141089
141090 if ( 'form-table' == $format ) : ?>
141091
141092 <form action="revision.php" method="get">
141093
141094 <div class="tablenav">
141095 <div class="alignleft">
141096 <input type="submit" class="button-secondary" value="<?php _e( 'Compare Revisions' ); ?>" />
141097 <input type="hidden" name="action" value="diff" />
141098 </div>
141099 </div>
141100
141101 <br class="clear" />
141102
141103 <table class="widefat post-revisions" cellspacing="0">
141104 <col />
141105 <col style="width: 33%" />
141106 <col style="width: 33%" />
141107 <col style="width: 33%" />
141108 <thead>
141109 <tr>
141110 <th scope="col"></th>
141111 <th scope="col"><?php _e( 'Date Created' ); ?></th>
141112 <th scope="col"><?php _e( 'Author' ); ?></th>
141113 <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
141114 </tr>
141115 </thead>
141116 <tbody>
141117
141118 <?php echo $rows; ?>
141119
141120 </tbody>
141121 </table>
141122
141123 </form>
141124
141125 <?php
141126 else :
141127 echo "<ul class='post-revisions'>\n";
141128 echo $rows;
141129 echo "</ul>";
141130 endif;
141131
141132 }