More massive code cleanups from Mark Jaquith. fixes #1772
git-svn-id: http://svn.automattic.com/wordpress/trunk@2955 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
751a663f3c
commit
ab8cf86716
|
@ -9,11 +9,13 @@ function get_the_password_form() {
|
|||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function the_ID() {
|
||||
global $id;
|
||||
echo $id;
|
||||
}
|
||||
|
||||
|
||||
function the_title($before = '', $after = '', $echo = true) {
|
||||
$title = get_the_title();
|
||||
if ( strlen($title) > 0 ) {
|
||||
|
@ -25,6 +27,7 @@ function the_title($before = '', $after = '', $echo = true) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function get_the_title($id = 0) {
|
||||
$post = &get_post($id);
|
||||
|
||||
|
@ -35,12 +38,14 @@ function get_the_title($id = 0) {
|
|||
return $title;
|
||||
}
|
||||
|
||||
|
||||
function get_the_guid( $id = 0 ) {
|
||||
$post = &get_post($id);
|
||||
|
||||
return apply_filters('get_the_guid', $post->guid);
|
||||
}
|
||||
|
||||
|
||||
function the_guid( $id = 0 ) {
|
||||
echo get_the_guid($id);
|
||||
}
|
||||
|
@ -53,6 +58,7 @@ function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file
|
|||
echo $content;
|
||||
}
|
||||
|
||||
|
||||
function get_the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
|
||||
global $id, $post, $more, $single, $withcomments, $page, $pages, $multipage, $numpages;
|
||||
global $preview;
|
||||
|
@ -66,11 +72,11 @@ function get_the_content($more_link_text = '(more...)', $stripteaser = 0, $more_
|
|||
}
|
||||
}
|
||||
|
||||
if ($more_file != '') {
|
||||
if ( $more_file != '' )
|
||||
$file = $more_file;
|
||||
} else {
|
||||
else
|
||||
$file = $pagenow; //$_SERVER['PHP_SELF'];
|
||||
}
|
||||
|
||||
$content = $pages[$page-1];
|
||||
$content = explode('<!--more-->', $content, 2);
|
||||
if ( (preg_match('/<!--noteaser-->/', $post->post_content) && ((!$multipage) || ($page==1))) )
|
||||
|
@ -80,22 +86,23 @@ function get_the_content($more_link_text = '(more...)', $stripteaser = 0, $more_
|
|||
$teaser = '';
|
||||
$output .= $teaser;
|
||||
if ( count($content) > 1 ) {
|
||||
if ($more) {
|
||||
if ( $more )
|
||||
$output .= '<a id="more-'.$id.'"></a>'.$content[1];
|
||||
} else {
|
||||
else
|
||||
$output .= ' <a href="'. get_permalink() . "#more-$id\">$more_link_text</a>";
|
||||
}
|
||||
}
|
||||
if ($preview) { // preview fix for javascript bug with foreign languages
|
||||
if ( $preview ) // preview fix for javascript bug with foreign languages
|
||||
$output = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function the_excerpt() {
|
||||
echo apply_filters('the_excerpt', get_the_excerpt());
|
||||
}
|
||||
|
||||
|
||||
function get_the_excerpt($fakeit = true) {
|
||||
global $id, $post;
|
||||
$output = '';
|
||||
|
@ -110,39 +117,46 @@ function get_the_excerpt($fakeit = true) {
|
|||
return apply_filters('get_the_excerpt', $output);
|
||||
}
|
||||
|
||||
|
||||
function wp_link_pages($args = '') {
|
||||
parse_str($args, $r);
|
||||
if (!isset($r['before'])) $r['before'] = '<p>' . __('Pages:');
|
||||
if (!isset($r['after'])) $r['after'] = '</p>';
|
||||
if (!isset($r['next_or_number'])) $r['next_or_number'] = 'number';
|
||||
if (!isset($r['nextpagelink'])) $r['nextpagelink'] = 'Next page';
|
||||
if (!isset($r['previouspagelink'])) $r['previouspagelink'] = 'Previous page';
|
||||
if (!isset($r['pagelink'])) $r['pagelink'] = '%';
|
||||
if (!isset($r['more_file'])) $r['more_file'] = '';
|
||||
if ( !isset($r['before']) )
|
||||
$r['before'] = '<p>' . __('Pages:');
|
||||
if ( !isset($r['after']) )
|
||||
$r['after'] = '</p>';
|
||||
if ( !isset($r['next_or_number']) )
|
||||
$r['next_or_number'] = 'number';
|
||||
if ( !isset($r['nextpagelink']) )
|
||||
$r['nextpagelink'] = 'Next page';
|
||||
if ( !isset($r['previouspagelink']) )
|
||||
$r['previouspagelink'] = 'Previous page';
|
||||
if ( !isset($r['pagelink']) )
|
||||
$r['pagelink'] = '%';
|
||||
if ( !isset($r['more_file']) )
|
||||
$r['more_file'] = '';
|
||||
|
||||
link_pages($r['before'], $r['after'], $r['next_or_number'], $r['nextpagelink'], $r['previouspagelink'], $r['pagelink'], $r['more_file']);
|
||||
}
|
||||
|
||||
|
||||
function link_pages($before='<br />', $after='<br />', $next_or_number='number', $nextpagelink='next page', $previouspagelink='previous page', $pagelink='%', $more_file='') {
|
||||
global $id, $page, $numpages, $multipage, $more;
|
||||
global $pagenow;
|
||||
if ($more_file != '') {
|
||||
global $id, $page, $numpages, $multipage, $more, $pagenow;
|
||||
if ( $more_file != '' )
|
||||
$file = $more_file;
|
||||
} else {
|
||||
else
|
||||
$file = $pagenow;
|
||||
}
|
||||
if (($multipage)) {
|
||||
if ($next_or_number=='number') {
|
||||
if ( $multipage ) {
|
||||
if ( 'number' == $next_or_number ) {
|
||||
echo $before;
|
||||
for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
|
||||
$j = str_replace('%',"$i",$pagelink);
|
||||
echo ' ';
|
||||
if ( ($i != $page) || ((!$more) && ($page==1)) ) {
|
||||
if ('' == get_settings('permalink_structure')) {
|
||||
if ( '' == get_settings('permalink_structure') )
|
||||
echo '<a href="' . get_permalink() . '&page=' . $i . '">';
|
||||
} else {
|
||||
else
|
||||
echo '<a href="' . trailingslashit( get_permalink() ) . $i . '/">';
|
||||
}
|
||||
}
|
||||
echo $j;
|
||||
if ( ($i != $page) || ((!$more) && ($page==1)) )
|
||||
echo '</a>';
|
||||
|
@ -153,30 +167,30 @@ function link_pages($before='<br />', $after='<br />', $next_or_number='number',
|
|||
echo $before;
|
||||
$i = $page - 1;
|
||||
if ( $i && $more ) {
|
||||
if ('' == get_settings('permalink_structure')) {
|
||||
if ( '' == get_settings('permalink_structure') )
|
||||
echo '<a href="' . get_permalink() . '&page=' . $i . '">'.$previouspagelink.'</a>';
|
||||
} else {
|
||||
else
|
||||
echo '<a href="' . get_permalink() . $i . '/">'.$previouspagelink.'</a>';
|
||||
}
|
||||
}
|
||||
$i = $page + 1;
|
||||
if ( $i <= $numpages && $more ) {
|
||||
if ('' == get_settings('permalink_structure')) {
|
||||
if ( '' == get_settings('permalink_structure') )
|
||||
echo '<a href="'.get_permalink() . '&page=' . $i . '">'.$nextpagelink.'</a>';
|
||||
} else {
|
||||
else
|
||||
echo '<a href="'.get_permalink().$i.'/">'.$nextpagelink.'</a>';
|
||||
}
|
||||
}
|
||||
echo $after;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Post-meta: Custom per-post fields.
|
||||
Post-meta: Custom per-post fields.
|
||||
*/
|
||||
|
||||
|
||||
function get_post_custom( $post_id = 0 ) {
|
||||
global $id, $post_meta_cache, $wpdb;
|
||||
if ( $post_id )
|
||||
|
@ -185,7 +199,6 @@ function get_post_custom( $post_id = 0 ) {
|
|||
return $post_meta_cache[$id];
|
||||
} else {
|
||||
if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = '$id' ORDER BY post_id, meta_key", ARRAY_A) ) {
|
||||
|
||||
// Change from flat structure to hierarchical:
|
||||
$post_meta_cache = array();
|
||||
foreach ( $meta_list as $metarow ) {
|
||||
|
@ -207,6 +220,7 @@ function get_post_custom( $post_id = 0 ) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function get_post_custom_keys() {
|
||||
global $id, $post_meta_cache;
|
||||
|
||||
|
@ -216,19 +230,24 @@ function get_post_custom_keys() {
|
|||
return $keys;
|
||||
}
|
||||
|
||||
|
||||
function get_post_custom_values($key='') {
|
||||
global $id, $post_meta_cache;
|
||||
|
||||
return $post_meta_cache[$id][$key];
|
||||
}
|
||||
|
||||
|
||||
function post_custom( $key = '' ) {
|
||||
global $id, $post_meta_cache;
|
||||
|
||||
if ( 1 == count($post_meta_cache[$id][$key]) ) return $post_meta_cache[$id][$key][0];
|
||||
else return $post_meta_cache[$id][$key];
|
||||
if ( 1 == count($post_meta_cache[$id][$key]) )
|
||||
return $post_meta_cache[$id][$key][0];
|
||||
else
|
||||
return $post_meta_cache[$id][$key];
|
||||
}
|
||||
|
||||
|
||||
// this will probably change at some point...
|
||||
function the_meta() {
|
||||
global $id, $post_meta_cache;
|
||||
|
@ -238,7 +257,6 @@ function the_meta() {
|
|||
foreach ( $keys as $key ) {
|
||||
$values = array_map('trim',$post_meta_cache[$id][$key]);
|
||||
$value = implode($values,', ');
|
||||
|
||||
echo "<li><span class='post-meta-key'>$key:</span> $value</li>\n";
|
||||
}
|
||||
echo "</ul>\n";
|
||||
|
@ -246,9 +264,10 @@ function the_meta() {
|
|||
}
|
||||
|
||||
|
||||
//
|
||||
// Pages
|
||||
//
|
||||
/*
|
||||
Pages
|
||||
*/
|
||||
|
||||
|
||||
function &get_page_children($page_id, $pages) {
|
||||
global $page_cache;
|
||||
|
@ -260,23 +279,26 @@ function &get_page_children($page_id, $pages) {
|
|||
foreach ( $pages as $page ) {
|
||||
if ( $page->post_parent == $page_id ) {
|
||||
$page_list[] = $page;
|
||||
if ( $children = get_page_children($page->ID, $pages)) {
|
||||
if ( $children = get_page_children($page->ID, $pages) )
|
||||
$page_list = array_merge($page_list, $children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $page_list;
|
||||
}
|
||||
|
||||
|
||||
function &get_pages($args = '') {
|
||||
global $wpdb;
|
||||
|
||||
parse_str($args, $r);
|
||||
|
||||
if (!isset($r['child_of'])) $r['child_of'] = 0;
|
||||
if (!isset($r['sort_column'])) $r['sort_column'] = 'post_title';
|
||||
if (!isset($r['sort_order'])) $r['sort_order'] = 'ASC';
|
||||
if ( !isset($r['child_of']) )
|
||||
$r['child_of'] = 0;
|
||||
if ( !isset($r['sort_column']) )
|
||||
$r['sort_column'] = 'post_title';
|
||||
if ( !isset($r['sort_order']) )
|
||||
$r['sort_order'] = 'ASC';
|
||||
|
||||
$exclusions = '';
|
||||
if ( !empty($r['exclude']) ) {
|
||||
|
@ -306,22 +328,29 @@ function &get_pages($args = '') {
|
|||
return $pages;
|
||||
}
|
||||
|
||||
|
||||
function wp_list_pages($args = '') {
|
||||
parse_str($args, $r);
|
||||
if ( !isset($r['depth']) ) $r['depth'] = 0;
|
||||
if ( !isset($r['show_date']) ) $r['show_date'] = '';
|
||||
if ( !isset($r['child_of']) ) $r['child_of'] = 0;
|
||||
if ( !isset($r['title_li']) ) $r['title_li'] = __('Pages');
|
||||
if ( !isset($r['echo']) ) $r['echo'] = 1;
|
||||
if ( !isset($r['depth']) )
|
||||
$r['depth'] = 0;
|
||||
if ( !isset($r['show_date']) )
|
||||
$r['show_date'] = '';
|
||||
if ( !isset($r['child_of']) )
|
||||
$r['child_of'] = 0;
|
||||
if ( !isset($r['title_li']) )
|
||||
$r['title_li'] = __('Pages');
|
||||
if ( !isset($r['echo']) )
|
||||
$r['echo'] = 1;
|
||||
|
||||
$output = '';
|
||||
|
||||
// Query pages.
|
||||
$pages = & get_pages($args);
|
||||
if ( $pages ) :
|
||||
if ( $pages ) {
|
||||
|
||||
if ( $r['title_li'] )
|
||||
$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
|
||||
|
||||
// Now loop over all pages that were selected
|
||||
$page_tree = Array();
|
||||
foreach ( $pages as $page ) {
|
||||
|
@ -354,7 +383,7 @@ function wp_list_pages($args = '') {
|
|||
$output .= _page_level_out($r['child_of'],$page_tree, $r, 0, false);
|
||||
if ( $r['title_li'] )
|
||||
$output .= '</ul></li>';
|
||||
endif;
|
||||
}
|
||||
|
||||
$output = apply_filters('wp_list_pages', $output);
|
||||
|
||||
|
@ -364,11 +393,10 @@ function wp_list_pages($args = '') {
|
|||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function _page_level_out($parent, $page_tree, $args, $depth = 0, $echo = true) {
|
||||
global $wp_query;
|
||||
|
||||
$queried_obj = $wp_query->get_queried_object();
|
||||
|
||||
$output = '';
|
||||
|
||||
if ( $depth )
|
||||
|
@ -380,9 +408,8 @@ function _page_level_out($parent, $page_tree, $args, $depth = 0, $echo = true) {
|
|||
$title = $cur_page['title'];
|
||||
|
||||
$css_class = 'page_item';
|
||||
if( $page_id == $queried_obj->ID) {
|
||||
if ( $page_id == $queried_obj->ID )
|
||||
$css_class .= ' current_page_item';
|
||||
}
|
||||
|
||||
$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page_id) . '" title="' . wp_specialchars($title) . '">' . $title . '</a>';
|
||||
|
||||
|
|
Loading…
Reference in New Issue