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 | function bloginfo_rss($show = '') { |
---|
9 | echo apply_filters('bloginfo_rss', get_bloginfo_rss($show)); |
---|
10 | } |
---|
11 | |
---|
12 | function get_default_feed() { |
---|
13 | return apply_filters('default_feed', 'rss2'); |
---|
14 | } |
---|
15 | |
---|
16 | function get_wp_title_rss($sep = '»') { |
---|
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 = '»') { |
---|
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(']]>', ']]>', $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_link() { |
---|
83 | echo get_comment_link(); |
---|
84 | } |
---|
85 | |
---|
86 | function get_comment_author_rss() { |
---|
87 | return apply_filters('comment_author_rss', get_comment_author() ); |
---|
88 | } |
---|
89 | |
---|
90 | function comment_author_rss() { |
---|
91 | echo get_comment_author_rss(); |
---|
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 | function get_the_category_rss($type = 'rss') { |
---|
101 | $categories = get_the_category(); |
---|
102 | $tags = get_the_tags(); |
---|
103 | $the_list = ''; |
---|
104 | $cat_names = array(); |
---|
105 | |
---|
106 | $filter = 'rss'; |
---|
107 | if ( 'atom' == $type ) |
---|
108 | $filter = 'raw'; |
---|
109 | |
---|
110 | if ( !empty($categories) ) foreach ( (array) $categories as $category ) { |
---|
111 | $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); |
---|
112 | } |
---|
113 | |
---|
114 | if ( !empty($tags) ) foreach ( (array) $tags as $tag ) { |
---|
115 | $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); |
---|
116 | } |
---|
117 | |
---|
118 | $cat_names = array_unique($cat_names); |
---|
119 | |
---|
120 | foreach ( $cat_names as $cat_name ) { |
---|
121 | if ( 'rdf' == $type ) |
---|
122 | $the_list .= "\n\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n"; |
---|
123 | elseif ( 'atom' == $type ) |
---|
124 | $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', attribute_escape( apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ) ), attribute_escape( $cat_name ) ); |
---|
125 | else |
---|
126 | $the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n"; |
---|
127 | } |
---|
128 | |
---|
129 | return apply_filters('the_category_rss', $the_list, $type); |
---|
130 | } |
---|
131 | |
---|
132 | function the_category_rss($type = 'rss') { |
---|
133 | echo get_the_category_rss($type); |
---|
134 | } |
---|
135 | |
---|
136 | function html_type_rss() { |
---|
137 | $type = get_bloginfo('html_type'); |
---|
138 | if (strpos($type, 'xhtml') !== false) |
---|
139 | $type = 'xhtml'; |
---|
140 | else |
---|
141 | $type = 'html'; |
---|
142 | echo $type; |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | function rss_enclosure() { |
---|
147 | global $post; |
---|
148 | if ( !empty($post->post_password) && (!isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) ) |
---|
149 | return; |
---|
150 | |
---|
151 | foreach (get_post_custom() as $key => $val) { |
---|
152 | if ($key == 'enclosure') { |
---|
153 | foreach ((array)$val as $enc) { |
---|
154 | $enclosure = split("\n", $enc); |
---|
155 | echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n"); |
---|
156 | } |
---|
157 | } |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | function atom_enclosure() { |
---|
162 | global $post; |
---|
163 | if ( !empty($post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) ) |
---|
164 | return; |
---|
165 | |
---|
166 | foreach (get_post_custom() as $key => $val) { |
---|
167 | if ($key == 'enclosure') { |
---|
168 | foreach ((array)$val as $enc) { |
---|
169 | $enclosure = split("\n", $enc); |
---|
170 | echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n"); |
---|
171 | } |
---|
172 | } |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | /** |
---|
177 | * prep_atom_text_construct() - Determine the type of a given string of data |
---|
178 | * |
---|
179 | * Tell whether the type is text, html, or xhtml, per RFC 4287 section 3.1. |
---|
180 | * |
---|
181 | * In the case of WordPress, text is defined as containing no markup, |
---|
182 | * xhtml is defined as "well formed", and html as tag soup (i.e., the rest). |
---|
183 | * |
---|
184 | * Container div tags are added to xhtml values, per section 3.1.1.3. |
---|
185 | * |
---|
186 | * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1 |
---|
187 | * |
---|
188 | * @package WordPress |
---|
189 | * @subpackage Feed |
---|
190 | * @since 2.4 |
---|
191 | * |
---|
192 | * @param string $data input string |
---|
193 | * @return array $result array(type, value) |
---|
194 | */ |
---|
195 | function prep_atom_text_construct($data) { |
---|
196 | if (strpos($data, '<') === false && strpos($data, '&') === false) { |
---|
197 | return array('text', $data); |
---|
198 | } |
---|
199 | |
---|
200 | $parser = xml_parser_create(); |
---|
201 | xml_parse($parser, '<div>' . $data . '</div>', true); |
---|
202 | $code = xml_get_error_code($parser); |
---|
203 | xml_parser_free($parser); |
---|
204 | |
---|
205 | if (!$code) { |
---|
206 | if (strpos($data, '<') === false) { |
---|
207 | return array('text', $data); |
---|
208 | } else { |
---|
209 | $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>"; |
---|
210 | return array('xhtml', $data); |
---|
211 | } |
---|
212 | } |
---|
213 | |
---|
214 | if (strpos($data, ']]>') == false) { |
---|
215 | return array('html', "<![CDATA[$data]]>"); |
---|
216 | } else { |
---|
217 | return array('html', htmlspecialchars($data)); |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | ?> |
---|