From 7f98c031a781b48b2dbbf76c6a030515c622abf7 Mon Sep 17 00:00:00 2001 From: saxmatt Date: Fri, 7 Jan 2005 22:01:59 +0000 Subject: [PATCH] Some feed template function cleanup. git-svn-id: http://svn.automattic.com/wordpress/trunk@2068 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-atom.php | 14 +- wp-includes/comment-functions.php | 32 ---- wp-includes/feed-functions.php | 154 ++++++++++++++++++++ wp-includes/template-functions-author.php | 17 --- wp-includes/template-functions-category.php | 31 ---- wp-includes/template-functions-general.php | 43 +++--- wp-includes/template-functions-links.php | 4 - wp-includes/template-functions-post.php | 91 ++---------- wp-includes/template-functions.php | 2 + wp-includes/vars.php | 1 + wp-rdf.php | 2 +- wp-rss.php | 2 +- wp-rss2.php | 36 ++--- 13 files changed, 210 insertions(+), 219 deletions(-) create mode 100644 wp-includes/feed-functions.php diff --git a/wp-atom.php b/wp-atom.php index 6d2ea65d6f..4a23c35c98 100644 --- a/wp-atom.php +++ b/wp-atom.php @@ -15,11 +15,11 @@ $more = 1; xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> <?php bloginfo_rss('name') ?> - + Copyright - WordPress + WordPress @@ -28,11 +28,11 @@ $more = 1; <?php the_title_rss() ?> - ?p= - post_modified_gmt); ?> - post_date_gmt); ?> + + + - + post_content ) ) : ?> ]]> @@ -40,7 +40,7 @@ $more = 1; ]]> - ]]> + ]]> diff --git a/wp-includes/comment-functions.php b/wp-includes/comment-functions.php index 4df4329bb5..f8bca5eca5 100644 --- a/wp-includes/comment-functions.php +++ b/wp-includes/comment-functions.php @@ -60,10 +60,6 @@ function comments_link( $file = '', $echo = true ) { echo get_comments_link(); } -function comment_link_rss() { - echo get_comments_link(); -} - function comments_popup_script($width=400, $height=400, $file='') { global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript; @@ -145,11 +141,6 @@ function comment_author() { echo $author; } -function comment_author_rss() { - $author = apply_filters('comment_author_rss', get_comment_author() ); - echo $author; -} - function get_comment_author_email() { global $comment; return apply_filters('get_comment_author_email', $comment->comment_author_email); @@ -244,12 +235,6 @@ function comment_text() { echo apply_filters('comment_text', get_comment_text() ); } -function comment_text_rss() { - $comment_text = get_comment_text(); - $comment_text = apply_filters('comment_text_rss', $comment_text); - echo $comment_text; -} - function get_comment_excerpt() { global $comment; $comment_text = strip_tags($comment->comment_content); @@ -299,23 +284,6 @@ function comment_time( $d = '' ) { echo get_comment_time(); } -function comments_rss_link($link_text = 'Comments RSS', $commentsrssfilename = 'wp-commentsrss2.php') { - $url = comments_rss($commentsrssfilename); - echo "$link_text"; -} - -function comments_rss($commentsrssfilename = 'wp-commentsrss2.php') { - global $id; - global $querystring_start, $querystring_equal, $querystring_separator; - - if ('' != get_settings('permalink_structure')) - $url = trailingslashit( get_permalink() ) . 'feed/'; - else - $url = get_settings('siteurl') . "/$commentsrssfilename?p=$id"; - - return $url; -} - function get_trackback_url() { global $id; $tb_url = get_settings('siteurl') . '/wp-trackback.php/' . $id; diff --git a/wp-includes/feed-functions.php b/wp-includes/feed-functions.php new file mode 100644 index 0000000000..842a8b94a6 --- /dev/null +++ b/wp-includes/feed-functions.php @@ -0,0 +1,154 @@ + $cut) { + $k = $cut; + $use_dotdotdot = 1; + } else { + $k = count($blah); + $use_dotdotdot = 0; + } + for ($i=0; $i<$k; $i++) { + $excerpt .= $blah[$i].' '; + } + $excerpt .= ($use_dotdotdot) ? '...' : ''; + $content = $excerpt; + } + $content = str_replace(']]>', ']]>', $content); + echo $content; +} + +function the_excerpt_rss() { + $output = get_the_excerpt(true); + echo apply_filters('the_excerpt_rss', $output); +} + +function permalink_single_rss($file = '') { + echo get_permalink(); +} + +function comment_link_rss() { + echo get_comments_link(); +} + +function comment_author_rss() { + $author = apply_filters('comment_author_rss', get_comment_author() ); + echo $author; +} + +function comment_text_rss() { + $comment_text = get_comment_text(); + $comment_text = apply_filters('comment_text_rss', $comment_text); + echo $comment_text; +} + +function comments_rss_link($link_text = 'Comments RSS', $commentsrssfilename = 'wp-commentsrss2.php') { + $url = comments_rss($commentsrssfilename); + echo "$link_text"; +} + +function comments_rss($commentsrssfilename = 'wp-commentsrss2.php') { + global $id; + global $querystring_start, $querystring_equal, $querystring_separator; + + if ('' != get_settings('permalink_structure')) + $url = trailingslashit( get_permalink() ) . 'feed/'; + else + $url = get_settings('siteurl') . "/$commentsrssfilename?p=$id"; + + return $url; +} + +function get_author_rss_link($echo = false, $author_id, $author_nicename) { + global $querystring_start, $querystring_equal; + $auth_ID = $author_id; + $permalink_structure = get_settings('permalink_structure'); + + if ('' == $permalink_structure) { + $file = get_settings('siteurl') . '/wp-rss2.php'; + $link = $file . $querystring_start . 'author' . $querystring_equal . $author_id; + } else { + $link = get_author_link(0, $author_id, $author_nicename); + $link = $link . "feed/"; + } + + if ($echo) echo $link; + return $link; +} + +function get_category_rss_link($echo = false, $category_id, $category_nicename) { + global $querystring_start, $querystring_equal; + $cat_ID = $category_id; + $permalink_structure = get_settings('permalink_structure'); + + if ('' == $permalink_structure) { + $file = get_settings('siteurl') . '/wp-rss2.php'; + $link = $file . $querystring_start . 'cat' . $querystring_equal . $category_id; + } else { + $link = get_category_link(0, $category_id, $category_nicename); + $link = $link . "feed/"; + } + + if ($echo) echo $link; + return $link; +} + +function the_category_rss($type = 'rss') { + $categories = get_the_category(); + $the_list = ''; + foreach ($categories as $category) { + $category->cat_name = convert_chars($category->cat_name); + if ('rdf' == $type) { + $the_list .= "\n\t$category->cat_name"; + } else { + $the_list .= "\n\t$category->cat_name"; + } + } + echo apply_filters('the_category_rss', $the_list); +} + +function rss_enclosure() { + global $id; + $custom_fields = get_post_custom(); + if( is_array( $custom_fields ) ) { + while( list( $key, $val ) = each( $custom_fields ) ) { + if( $key == 'enclosure' ) { + if (is_array($val)) { + foreach($val as $enc) { + $enclosure = split( "\n", $enc ); + print "\n"; + } + } + } + } + } +} + +?> \ No newline at end of file diff --git a/wp-includes/template-functions-author.php b/wp-includes/template-functions-author.php index fc3e1906e7..1e83d9aca0 100644 --- a/wp-includes/template-functions-author.php +++ b/wp-includes/template-functions-author.php @@ -140,23 +140,6 @@ function get_author_link($echo = false, $author_id, $author_nicename) { return $link; } -function get_author_rss_link($echo = false, $author_id, $author_nicename) { - global $querystring_start, $querystring_equal; - $auth_ID = $author_id; - $permalink_structure = get_settings('permalink_structure'); - - if ('' == $permalink_structure) { - $file = get_settings('siteurl') . '/wp-rss2.php'; - $link = $file . $querystring_start . 'author' . $querystring_equal . $author_id; - } else { - $link = get_author_link(0, $author_id, $author_nicename); - $link = $link . "feed/"; - } - - if ($echo) echo $link; - return $link; -} - function wp_list_authors($args = '') { parse_str($args, $r); if (!isset($r['optioncount'])) $r['optioncount'] = false; diff --git a/wp-includes/template-functions-category.php b/wp-includes/template-functions-category.php index 7a90262d56..e42dcf5c67 100644 --- a/wp-includes/template-functions-category.php +++ b/wp-includes/template-functions-category.php @@ -43,23 +43,6 @@ function get_category_link($echo = false, $category_id, $category_nicename) { return $catlink; } -function get_category_rss_link($echo = false, $category_id, $category_nicename) { - global $querystring_start, $querystring_equal; - $cat_ID = $category_id; - $permalink_structure = get_settings('permalink_structure'); - - if ('' == $permalink_structure) { - $file = get_settings('siteurl') . '/wp-rss2.php'; - $link = $file . $querystring_start . 'cat' . $querystring_equal . $category_id; - } else { - $link = get_category_link(0, $category_id, $category_nicename); - $link = $link . "feed/"; - } - - if ($echo) echo $link; - return $link; -} - function the_category($separator = '', $parents='') { $categories = get_the_category(); if (empty($categories)) { @@ -118,20 +101,6 @@ function the_category($separator = '', $parents='') { echo apply_filters('the_category', $thelist); } -function the_category_rss($type = 'rss') { - $categories = get_the_category(); - $the_list = ''; - foreach ($categories as $category) { - $category->cat_name = convert_chars($category->cat_name); - if ('rdf' == $type) { - $the_list .= "\n\t$category->cat_name"; - } else { - $the_list .= "\n\t$category->cat_name"; - } - } - echo apply_filters('the_category_rss', $the_list); -} - function get_the_category_by_ID($cat_ID) { global $cache_categories, $wpdb; if ( !$cache_categories[$cat_ID] ) { diff --git a/wp-includes/template-functions-general.php b/wp-includes/template-functions-general.php index e214bf8683..af09ee6086 100644 --- a/wp-includes/template-functions-general.php +++ b/wp-includes/template-functions-general.php @@ -61,16 +61,6 @@ function bloginfo($show='') { echo convert_chars($info); } -function bloginfo_rss($show='') { - $info = strip_tags(get_bloginfo($show)); - echo convert_chars($info); -} - -function bloginfo_unicode($show='') { - $info = get_bloginfo($show); - echo convert_chars($info); -} - function get_bloginfo($show='') { switch($show) { @@ -611,19 +601,26 @@ function the_date($d='', $before='', $after='', $echo = true) { } } -function the_time($d='', $echo = true) { - global $id, $post; - if ($d=='') { - $the_time = mysql2date(get_settings('time_format'), $post->post_date); - } else { - $the_time = mysql2date($d, $post->post_date); - } - $the_time = apply_filters('the_time', $the_time); - if ($echo) { - echo $the_time; - } else { - return $the_time; - } +function the_time( $d = '' ) { + echo apply_filters('the_time', get_the_time( $d ) ); +} + +function get_the_time( $d = '' ) { + global $id, $post; + if ( '' == $d ) + $the_time = date( get_settings('time_format'), get_post_time() ); + else + $the_time = mysql2date( $d, get_post_time() ); + return apply_filters('get_the_time', $the_time); +} + +function get_post_time( $gmt = false ) { // returns timestamp + global $post; + if ( $gmt ) + $time = mysql2date('U', $post->post_date_gmt); + else + $time = mysql2date('U', $post->post_date); + return apply_filters('get_the_time', $time); } function the_weekday() { diff --git a/wp-includes/template-functions-links.php b/wp-includes/template-functions-links.php index a63010ff0a..032f01af3d 100644 --- a/wp-includes/template-functions-links.php +++ b/wp-includes/template-functions-links.php @@ -22,10 +22,6 @@ function permalink_anchor($mode = 'id') { } } -function permalink_single_rss($file = '') { - echo get_permalink(); -} - function get_permalink($id = false) { global $post, $wpdb; diff --git a/wp-includes/template-functions-post.php b/wp-includes/template-functions-post.php index 7df01fbad6..c5e7cda6fb 100644 --- a/wp-includes/template-functions-post.php +++ b/wp-includes/template-functions-post.php @@ -39,13 +39,6 @@ function the_title($before = '', $after = '', $echo = true) { } } -function the_title_rss() { - $title = get_the_title(); - $title = apply_filters('the_title', $title); - $title = apply_filters('the_title_rss', $title); - echo $title; -} - function get_the_title($id = 0) { global $post, $wpdb; $title = $post->post_title; @@ -59,6 +52,21 @@ function get_the_title($id = 0) { return $title; } +function get_the_guid( $id = 0 ) { + global $post, $wpdb; + $guid = $post->guid; + + if ( 0 != $id ) + $title = $wpdb->get_var("SELECT guid FROM $wpdb->posts WHERE ID = $id"); + $guid = apply_filters('get_the_guid', $guid); + return $guid; +} + +function the_guid( $id = 0 ) { + echo get_the_guid(); +} + + function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') { $content = get_the_content($more_link_text, $stripteaser, $more_file); $content = apply_filters('the_content', $content); @@ -66,39 +74,6 @@ function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file echo $content; } -function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) { - $content = get_the_content($more_link_text, $stripteaser, $more_file); - $content = apply_filters('the_content', $content); - if ($cut && !$encode_html) { - $encode_html = 2; - } - if ($encode_html == 1) { - $content = wp_specialchars($content); - $cut = 0; - } elseif ($encode_html == 0) { - $content = make_url_footnote($content); - } elseif ($encode_html == 2) { - $content = strip_tags($content); - } - if ($cut) { - $blah = explode(' ', $content); - if (count($blah) > $cut) { - $k = $cut; - $use_dotdotdot = 1; - } else { - $k = count($blah); - $use_dotdotdot = 0; - } - for ($i=0; $i<$k; $i++) { - $excerpt .= $blah[$i].' '; - } - $excerpt .= ($use_dotdotdot) ? '...' : ''; - $content = $excerpt; - } - $content = str_replace(']]>', ']]>', $content); - 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; @@ -142,42 +117,6 @@ function the_excerpt() { echo apply_filters('the_excerpt', get_the_excerpt()); } -function the_excerpt_rss($cut = 0, $encode_html = FALSE) { - $output = get_the_excerpt(true); - - $output = convert_chars($output); - if ($cut && !$encode_html) { - $encode_html = 2; - } - if ($encode_html == 1) { - $output = wp_specialchars($output); - $cut = 0; - } elseif ($encode_html === 0) { - $output = make_url_footnote($output); - } elseif ($encode_html == 2) { - $output = strip_tags($output); - $output = str_replace('&', '&', $output); - } - if ($cut) { - $excerpt = ''; - $blah = explode(' ', $output); - if (count($blah) > $cut) { - $k = $cut; - $use_dotdotdot = 1; - } else { - $k = count($blah); - $use_dotdotdot = 0; - } - for ($i=0; $i<$k; $i++) { - $excerpt .= $blah[$i].' '; - } - $excerpt .= ($use_dotdotdot) ? '...' : ''; - $output = $excerpt; - } - $output = str_replace(']]>', ']]>', $output); - echo apply_filters('the_excerpt_rss', $output); -} - function get_the_excerpt($fakeit = true) { global $id, $post; $output = ''; diff --git a/wp-includes/template-functions.php b/wp-includes/template-functions.php index 43e27f38a9..45e5e8a713 100644 --- a/wp-includes/template-functions.php +++ b/wp-includes/template-functions.php @@ -19,4 +19,6 @@ require($curpath . 'template-functions-category.php'); /***** Comment tags *****/ require($curpath . 'comment-functions.php'); +require($curpath . 'feed-functions.php'); + ?> \ No newline at end of file diff --git a/wp-includes/vars.php b/wp-includes/vars.php index fe30b7dc15..0659b5a2a2 100644 --- a/wp-includes/vars.php +++ b/wp-includes/vars.php @@ -158,6 +158,7 @@ add_filter('comment_text', 'convert_smilies', 20); add_filter('comment_text_rss', 'htmlspecialchars'); add_filter('comment_excerpt', 'convert_chars'); +add_filter('the_excerpt_rss', 'convert_chars'); // Places to balance tags on input add_filter('content_save_pre', 'balanceTags', 50); diff --git a/wp-rdf.php b/wp-rdf.php index a1a2d828e1..11cbfc6e4c 100644 --- a/wp-rdf.php +++ b/wp-rdf.php @@ -46,7 +46,7 @@ add_filter('the_content', 'trim'); (mailto:) - + ]]> diff --git a/wp-rss.php b/wp-rss.php index ce82905f34..4d42ba4462 100644 --- a/wp-rss.php +++ b/wp-rss.php @@ -26,7 +26,7 @@ $more = 1; - + diff --git a/wp-rss2.php b/wp-rss2.php index 581e10193b..5d28543dbd 100644 --- a/wp-rss2.php +++ b/wp-rss2.php @@ -12,55 +12,37 @@ $more = 1; ?> '; ?> - + - <?php bloginfo_rss('name') ?> + <?php bloginfo_rss('name'); ?> - Copyright - http://wordpress.org/?v= + http://wordpress.org/?v= <?php the_title_rss() ?> - post_date_gmt, 0); ?> + + - + - - post_content ) ) : ?> + ]]> - - ]]> - -\n"; - } - } - } - } -} -?> + - + \ No newline at end of file