Make excerpt stuff a filter

git-svn-id: http://svn.automattic.com/wordpress/trunk@2341 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2005-02-15 00:21:21 +00:00
parent 1d6d4c6d93
commit 067e48e161
3 changed files with 37 additions and 31 deletions

View File

@ -71,6 +71,8 @@ add_filter('the_excerpt', 'convert_smilies');
add_filter('the_excerpt', 'convert_chars');
add_filter('the_excerpt', 'wpautop');
add_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('sanitize_title', 'sanitize_title_with_dashes');
add_action('publish_post', 'generic_ping');

View File

@ -642,4 +642,28 @@ function human_time_diff( $from, $to = '' ) {
return $since;
}
function wp_trim_excerpt( $text ) { // Fakes an excerpt if needed
global $post;
if ( '' == $text ) {
$text = $post->post_content;
$text = strip_tags( $text );
$blah = explode(' ', $text);
$excerpt_length = 55;
if (count($blah) > $excerpt_length) {
$k = $excerpt_length;
$use_dotdotdot = 1;
} else {
$k = count($blah);
$use_dotdotdot = 0;
}
$excerpt = '';
for ($i=0; $i<$k; $i++) {
$excerpt .= $blah[$i].' ';
}
$excerpt .= ($use_dotdotdot) ? '[...]' : '';
$text = $excerpt;
} // end if no excerpt
return $text;
}
?>

View File

@ -104,41 +104,21 @@ function get_the_content($more_link_text = '(more...)', $stripteaser = 0, $more_
}
function the_excerpt() {
echo apply_filters('the_excerpt', get_the_excerpt());
echo apply_filters('the_excerpt', get_the_excerpt());
}
function get_the_excerpt($fakeit = true) {
global $id, $post;
$output = '';
$output = $post->post_excerpt;
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
$output = __('There is no excerpt because this is a protected post.');
return $output;
}
}
global $id, $post;
$output = '';
$output = $post->post_excerpt;
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
$output = __('There is no excerpt because this is a protected post.');
return $output;
}
}
// If we haven't got an excerpt, make one in the style of the rss ones
if (($output == '') && $fakeit) {
$output = $post->post_content;
$output = strip_tags($output);
$blah = explode(' ', $output);
$excerpt_length = 70;
if (count($blah) > $excerpt_length) {
$k = $excerpt_length;
$use_dotdotdot = 1;
} else {
$k = count($blah);
$use_dotdotdot = 0;
}
$excerpt = '';
for ($i=0; $i<$k; $i++) {
$excerpt .= $blah[$i].' ';
}
$excerpt .= ($use_dotdotdot) ? '...' : '';
$output = $excerpt;
} // end if no excerpt
return $output;
return apply_filters('get_the_excerpt', $output);
}
function wp_link_pages($args = '') {