root/tags/2.3.1/wp-includes/feed.php

Revision 6125, 6.4 kB (checked in by ryan, 1 year ago)

Add checks for WP_Error. Props filosofo. see #4809

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2
3 function get_bloginfo_rss($show = '') {
4     $info = strip_tags(get_bloginfo($show));
5     return apply_filters('get_bloginfo_rss', convert_chars($info));
6 }
7
8
9 function bloginfo_rss($show = '') {
10     echo apply_filters('bloginfo_rss', get_bloginfo_rss($show));
11 }
12
13 function get_wp_title_rss($sep = '&#187;') {
14     $title = wp_title($sep, false);
15     if ( is_wp_error( $title ) )
16         return $title->get_error_message();
17     $title = apply_filters('get_wp_title_rss', $title);
18     return $title;
19 }
20
21 function wp_title_rss($sep = '&#187;') {
22     echo apply_filters('wp_title_rss', get_wp_title_rss($sep));
23 }
24
25 function get_the_title_rss() {
26     $title = get_the_title();
27     $title = apply_filters('the_title_rss', $title);
28     return $title;
29 }
30
31
32 function the_title_rss() {
33     echo get_the_title_rss();
34 }
35
36
37 function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) {
38     $content = get_the_content($more_link_text, $stripteaser, $more_file);
39     $content = apply_filters('the_content_rss', $content);
40     if ( $cut && !$encode_html )
41         $encode_html = 2;
42     if ( 1== $encode_html ) {
43         $content = wp_specialchars($content);
44         $cut = 0;
45     } elseif ( 0 == $encode_html ) {
46         $content = make_url_footnote($content);
47     } elseif ( 2 == $encode_html ) {
48         $content = strip_tags($content);
49     }
50     if ( $cut ) {
51         $blah = explode(' ', $content);
52         if ( count($blah) > $cut ) {
53             $k = $cut;
54             $use_dotdotdot = 1;
55         } else {
56             $k = count($blah);
57             $use_dotdotdot = 0;
58         }
59         for ( $i=0; $i<$k; $i++ )
60             $excerpt .= $blah[$i].' ';
61         $excerpt .= ($use_dotdotdot) ? '...' : '';
62         $content = $excerpt;
63     }
64     $content = str_replace(']]>', ']]&gt;', $content);
65     echo $content;
66 }
67
68
69 function the_excerpt_rss() {
70     $output = get_the_excerpt();
71     echo apply_filters('the_excerpt_rss', $output);
72 }
73
74 function the_permalink_rss() {
75     echo apply_filters('the_permalink_rss', get_permalink());
76
77 }
78
79 function comment_link() {
80     echo get_comment_link();
81 }
82
83
84 function get_comment_author_rss() {
85     return apply_filters('comment_author_rss', get_comment_author() );
86 }
87
88
89 function comment_author_rss() {
90     echo get_comment_author_rss();
91 }
92
93
94 function comment_text_rss() {
95     $comment_text = get_comment_text();
96     $comment_text = apply_filters('comment_text_rss', $comment_text);
97     echo $comment_text;
98 }
99
100
101 function comments_rss_link($link_text = 'Comments RSS', $commentsrssfilename = 'nolongerused') {
102     $url = get_post_comments_feed_link();
103     echo "<a href='$url'>$link_text</a>";
104 }
105
106
107 function comments_rss($commentsrssfilename = 'nolongerused') {
108     return get_post_comments_feed_link();
109 }
110
111
112 function get_author_rss_link($echo = false, $author_id, $author_nicename) {
113     $auth_ID = (int) $author_id;
114     $permalink_structure = get_option('permalink_structure');
115
116     if ( '' == $permalink_structure ) {
117         $link = get_option('home') . '?feed=rss2&amp;author=' . $author_id;
118     } else {
119         $link = get_author_posts_url($author_id, $author_nicename);
120         $link = trailingslashit($link) . user_trailingslashit('feed', 'feed');
121     }
122
123     $link = apply_filters('author_feed_link', $link);
124
125     if ( $echo )
126         echo $link;
127     return $link;
128 }
129
130
131 function get_category_rss_link($echo = false, $cat_ID, $category_nicename) {
132     $permalink_structure = get_option('permalink_structure');
133
134     if ( '' == $permalink_structure ) {
135         $link = get_option('home') . '?feed=rss2&amp;cat=' . $cat_ID;
136     } else {
137         $link = get_category_link($cat_ID);
138         $link = trailingslashit($link) . user_trailingslashit('feed', 'feed');
139     }
140
141     $link = apply_filters('category_feed_link', $link);
142
143     if ( $echo )
144         echo $link;
145     return $link;
146 }
147
148
149 function get_the_category_rss($type = 'rss') {
150     $categories = get_the_category();
151     $tags = get_the_tags();
152     $home = get_bloginfo_rss('home');
153     $the_list = '';
154     $cat_names = array();
155
156     $filter = 'rss';
157     if ( 'atom' == $type )
158         $filter = 'raw';
159
160     if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
161         $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
162     }
163
164     if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
165         $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
166     }
167
168     $cat_names = array_unique($cat_names);
169
170     foreach ( $cat_names as $cat_name ) {
171         if ( 'rdf' == $type )
172             $the_list .= "\n\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n";
173         elseif ( 'atom' == $type )
174             $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', attribute_escape( apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ) ), attribute_escape( $cat_name ) );
175         else
176             $the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n";
177     }
178
179     return apply_filters('the_category_rss', $the_list, $type);
180 }
181
182
183 function the_category_rss($type = 'rss') {
184     echo get_the_category_rss($type);
185 }
186
187 function get_tag_feed_link($tag_id, $feed = 'rss2') {
188     $tag_id = (int) $tag_id;
189
190     $tag = get_tag($tag_id);
191
192     if ( empty($tag) || is_wp_error($tag) )
193         return false;
194
195     $permalink_structure = get_option('permalink_structure');
196
197     if ( '' == $permalink_structure ) {
198         $link = get_option('home') . "?feed=$feed&amp;tag=" . $tag->slug;
199     } else {
200         $link = get_tag_link($tag->term_id);
201         if ( 'rss2' == $feed )
202             $feed_link = 'feed';
203         else
204             $feed_link = "feed/$feed";
205         $link = $link . user_trailingslashit($feed_link, 'feed');
206     }
207
208     $link = apply_filters('tag_feed_link', $link, $feed);
209
210     return $link;
211 }
212
213 function html_type_rss() {
214     $type = get_bloginfo('html_type');
215     if (strpos($type, 'xhtml') !== false)
216         $type = 'xhtml';
217     else
218         $type = 'html';
219     echo $type;
220 }
221
222
223 function rss_enclosure() {
224     global $id, $post;
225     if ( !empty($post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
226         return;
227
228     foreach (get_post_custom() as $key => $val) {
229         if ($key == 'enclosure') {
230             foreach ((array)$val as $enc) {
231                 $enclosure = split("\n", $enc);
232                 echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
233             }
234         }
235     }
236 }
237
238 function atom_enclosure() {
239     global $id, $post;
240     if ( !empty($post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
241         return;
242
243     foreach (get_post_custom() as $key => $val) {
244         if ($key == 'enclosure') {
245             foreach ((array)$val as $enc) {
246                 $enclosure = split("\n", $enc);
247                 echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
248             }
249         }
250     }
251 }
252
253 ?>
254
Note: See TracBrowser for help on using the browser.