]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/feed.php
Wordpress 2.5.1-scripts
[autoinstalls/wordpress.git] / wp-includes / feed.php
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), $show);
6 }
7
8 function bloginfo_rss($show = '') {
9         echo apply_filters('bloginfo_rss', get_bloginfo_rss($show), $show);
10 }
11
12 function get_default_feed() {
13         return apply_filters('default_feed', 'rss2');
14 }
15
16 function get_wp_title_rss($sep = '&#187;') {
17         $title = wp_title($sep, false);
18         if ( is_wp_error( $title ) )
19                 return $title->get_error_message();
20         $title = apply_filters('get_wp_title_rss', $title);
21         return $title;
22 }
23
24 function wp_title_rss($sep = '&#187;') {
25         echo apply_filters('wp_title_rss', get_wp_title_rss($sep));
26 }
27
28 function get_the_title_rss() {
29         $title = get_the_title();
30         $title = apply_filters('the_title_rss', $title);
31         return $title;
32 }
33
34
35 function the_title_rss() {
36         echo get_the_title_rss();
37 }
38
39
40 function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) {
41         $content = get_the_content($more_link_text, $stripteaser, $more_file);
42         $content = apply_filters('the_content_rss', $content);
43         if ( $cut && !$encode_html )
44                 $encode_html = 2;
45         if ( 1== $encode_html ) {
46                 $content = wp_specialchars($content);
47                 $cut = 0;
48         } elseif ( 0 == $encode_html ) {
49                 $content = make_url_footnote($content);
50         } elseif ( 2 == $encode_html ) {
51                 $content = strip_tags($content);
52         }
53         if ( $cut ) {
54                 $blah = explode(' ', $content);
55                 if ( count($blah) > $cut ) {
56                         $k = $cut;
57                         $use_dotdotdot = 1;
58                 } else {
59                         $k = count($blah);
60                         $use_dotdotdot = 0;
61                 }
62                 for ( $i=0; $i<$k; $i++ )
63                         $excerpt .= $blah[$i].' ';
64                 $excerpt .= ($use_dotdotdot) ? '...' : '';
65                 $content = $excerpt;
66         }
67         $content = str_replace(']]>', ']]&gt;', $content);
68         echo $content;
69 }
70
71
72 function the_excerpt_rss() {
73         $output = get_the_excerpt();
74         echo apply_filters('the_excerpt_rss', $output);
75 }
76
77 function the_permalink_rss() {
78         echo apply_filters('the_permalink_rss', get_permalink());
79
80 }
81
82 function comment_guid() {
83         echo get_comment_guid();
84 }
85
86 function get_comment_guid() {
87         global $comment;
88
89         if ( !is_object($comment) )
90                 return false;
91
92         return get_the_guid($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
93 }
94
95 function comment_link() {
96         echo get_comment_link();
97 }
98
99 function get_comment_author_rss() {
100         return apply_filters('comment_author_rss', get_comment_author() );
101 }
102
103 function comment_author_rss() {
104         echo get_comment_author_rss();
105 }
106
107 function comment_text_rss() {
108         $comment_text = get_comment_text();
109         $comment_text = apply_filters('comment_text_rss', $comment_text);
110         echo $comment_text;
111 }
112
113 function get_the_category_rss($type = 'rss') {
114         $categories = get_the_category();
115         $tags = get_the_tags();
116         $the_list = '';
117         $cat_names = array();
118
119         $filter = 'rss';
120         if ( 'atom' == $type )
121                 $filter = 'raw';
122
123         if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
124                 $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
125         }
126
127         if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
128                 $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
129         }
130
131         $cat_names = array_unique($cat_names);
132
133         foreach ( $cat_names as $cat_name ) {
134                 if ( 'rdf' == $type )
135                         $the_list .= "\n\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n";
136                 elseif ( 'atom' == $type )
137                         $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', attribute_escape( apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ) ), attribute_escape( $cat_name ) );
138                 else
139                         $the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n";
140         }
141
142         return apply_filters('the_category_rss', $the_list, $type);
143 }
144
145 function the_category_rss($type = 'rss') {
146         echo get_the_category_rss($type);
147 }
148
149 function html_type_rss() {
150         $type = get_bloginfo('html_type');
151         if (strpos($type, 'xhtml') !== false)
152                 $type = 'xhtml';
153         else
154                 $type = 'html';
155         echo $type;
156 }
157
158
159 function rss_enclosure() {
160         global $post;
161         if ( !empty($post->post_password) && (!isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
162                 return;
163
164         foreach (get_post_custom() as $key => $val) {
165                 if ($key == 'enclosure') {
166                         foreach ((array)$val as $enc) {
167                                 $enclosure = split("\n", $enc);
168                                 echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
169                         }
170                 }
171         }
172 }
173
174 function atom_enclosure() {
175         global $post;
176         if ( !empty($post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
177                 return;
178
179         foreach (get_post_custom() as $key => $val) {
180                 if ($key == 'enclosure') {
181                         foreach ((array)$val as $enc) {
182                                 $enclosure = split("\n", $enc);
183                                 echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
184                         }
185                 }
186         }
187 }
188
189 /**
190  * prep_atom_text_construct() - Determine the type of a given string of data
191  *
192  * Tell whether the type is text, html, or xhtml, per RFC 4287 section 3.1.
193  *
194  * In the case of WordPress, text is defined as containing no markup,
195  * xhtml is defined as "well formed", and html as tag soup (i.e., the rest).
196  *
197  * Container div tags are added to xhtml values, per section 3.1.1.3.
198  *
199  * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
200  *
201  * @package WordPress
202  * @subpackage Feed
203  * @since 2.5
204  *
205  * @param string $data input string
206  * @return array $result array(type, value)
207  */
208 function prep_atom_text_construct($data) {
209         if (strpos($data, '<') === false && strpos($data, '&') === false) {
210                 return array('text', $data);
211         }
212
213         $parser = xml_parser_create();
214         xml_parse($parser, '<div>' . $data . '</div>', true);
215         $code = xml_get_error_code($parser);
216         xml_parser_free($parser);
217
218         if (!$code) {
219                 if (strpos($data, '<') === false) {
220                         return array('text', $data);
221                 } else {
222                         $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
223                         return array('xhtml', $data);
224                 }
225         }
226
227         if (strpos($data, ']]>') == false) {
228                 return array('html', "<![CDATA[$data]]>");
229         } else {
230                 return array('html', htmlspecialchars($data));
231         }
232 }
233
234 /**
235  * self_link() - Generate a correct link for the atom:self elemet
236  *
237  * Echo the link for the currently displayed feed in a XSS safe way.
238  *
239  * @package WordPress
240  * @subpackage Feed
241  * @since 2.5
242  *
243  */
244 function self_link() {
245         echo 'http'
246                 . ( $_SERVER['https'] == 'on' ? 's' : '' ) . '://'
247                 . $_SERVER['HTTP_HOST']
248                 . wp_specialchars(stripslashes($_SERVER['REQUEST_URI']), 1);
249 }
250
251 ?>