-
+ D4128084A1994B43576CE887D235E162E7682D997B51840BD0878A986DA42A539681C3D9DE7D795FEA12D454D1F4E974D300F13843B285282BC4F626A8E2BF03
mp-wp/wp-includes/feed.php
(0 . 0)(1 . 511)
88943 <?php
88944 /**
88945 * WordPress Feed API
88946 *
88947 * Many of the functions used in here belong in The Loop, or The Loop for the
88948 * Feeds.
88949 *
88950 * @package WordPress
88951 * @subpackage Feed
88952 */
88953
88954 /**
88955 * RSS container for the bloginfo function.
88956 *
88957 * You can retrieve anything that you can using the get_bloginfo() function.
88958 * Everything will be stripped of tags and characters converted, when the values
88959 * are retrieved for use in the feeds.
88960 *
88961 * @package WordPress
88962 * @subpackage Feed
88963 * @since 1.5.1
88964 * @uses apply_filters() Calls 'get_bloginfo_rss' hook with two parameters.
88965 * @see get_bloginfo() For the list of possible values to display.
88966 *
88967 * @param string $show See get_bloginfo() for possible values.
88968 * @return string
88969 */
88970 function get_bloginfo_rss($show = '') {
88971 $info = strip_tags(get_bloginfo($show));
88972 return apply_filters('get_bloginfo_rss', convert_chars($info), $show);
88973 }
88974
88975 /**
88976 * Display RSS container for the bloginfo function.
88977 *
88978 * You can retrieve anything that you can using the get_bloginfo() function.
88979 * Everything will be stripped of tags and characters converted, when the values
88980 * are retrieved for use in the feeds.
88981 *
88982 * @package WordPress
88983 * @subpackage Feed
88984 * @since 0.71
88985 * @uses apply_filters() Calls 'bloginfo_rss' hook with two parameters.
88986 * @see get_bloginfo() For the list of possible values to display.
88987 *
88988 * @param string $show See get_bloginfo() for possible values.
88989 */
88990 function bloginfo_rss($show = '') {
88991 echo apply_filters('bloginfo_rss', get_bloginfo_rss($show), $show);
88992 }
88993
88994 /**
88995 * Retrieve the default feed.
88996 *
88997 * The default feed is 'rss2', unless a plugin changes it through the
88998 * 'default_feed' filter.
88999 *
89000 * @package WordPress
89001 * @subpackage Feed
89002 * @since 2.5
89003 * @uses apply_filters() Calls 'default_feed' hook on the default feed string.
89004 *
89005 * @return string Default feed, or for example 'rss2', 'atom', etc.
89006 */
89007 function get_default_feed() {
89008 return apply_filters('default_feed', 'rss2');
89009 }
89010
89011 /**
89012 * Retrieve the blog title for the feed title.
89013 *
89014 * @package WordPress
89015 * @subpackage Feed
89016 * @since 2.2.0
89017 * @uses apply_filters() Calls 'get_wp_title_rss' hook on title.
89018 * @uses wp_title() See function for $sep parameter usage.
89019 *
89020 * @param string $sep Optional.How to separate the title. See wp_title() for more info.
89021 * @return string Error message on failure or blog title on success.
89022 */
89023 function get_wp_title_rss($sep = '»') {
89024 $title = wp_title($sep, false);
89025 if ( is_wp_error( $title ) )
89026 return $title->get_error_message();
89027 $title = apply_filters('get_wp_title_rss', $title);
89028 return $title;
89029 }
89030
89031 /**
89032 * Display the blog title for display of the feed title.
89033 *
89034 * @package WordPress
89035 * @subpackage Feed
89036 * @since 2.2.0
89037 * @uses apply_filters() Calls 'wp_title_rss' on the blog title.
89038 * @see wp_title() $sep parameter usage.
89039 *
89040 * @param string $sep Optional.
89041 */
89042 function wp_title_rss($sep = '»') {
89043 echo apply_filters('wp_title_rss', get_wp_title_rss($sep));
89044 }
89045
89046 /**
89047 * Retrieve the current post title for the feed.
89048 *
89049 * @package WordPress
89050 * @subpackage Feed
89051 * @since 2.0.0
89052 * @uses apply_filters() Calls 'the_title_rss' on the post title.
89053 *
89054 * @return string Current post title.
89055 */
89056 function get_the_title_rss() {
89057 $title = get_the_title();
89058 $title = apply_filters('the_title_rss', $title);
89059 return $title;
89060 }
89061
89062 /**
89063 * Display the post title in the feed.
89064 *
89065 * @package WordPress
89066 * @subpackage Feed
89067 * @since 0.71
89068 * @uses get_the_title_rss() Used to retrieve current post title.
89069 */
89070 function the_title_rss() {
89071 echo get_the_title_rss();
89072 }
89073
89074 /**
89075 * Display the post content for the feed.
89076 *
89077 * For encoding the html or the $encode_html parameter, there are three possible
89078 * values. '0' will make urls footnotes and use make_url_footnote(). '1' will
89079 * encode special characters and automatically display all of the content. The
89080 * value of '2' will strip all HTML tags from the content.
89081 *
89082 * Also note that you cannot set the amount of words and not set the html
89083 * encoding. If that is the case, then the html encoding will default to 2,
89084 * which will strip all HTML tags.
89085 *
89086 * To restrict the amount of words of the content, you can use the cut
89087 * parameter. If the content is less than the amount, then there won't be any
89088 * dots added to the end. If there is content left over, then dots will be added
89089 * and the rest of the content will be removed.
89090 *
89091 * @package WordPress
89092 * @subpackage Feed
89093 * @since 0.71
89094 * @uses apply_filters() Calls 'the_content_rss' on the content before processing.
89095 * @see get_the_content() For the $more_link_text, $stripteaser, and $more_file
89096 * parameters.
89097 *
89098 * @param string $more_link_text Optional. Text to display when more content is available but not displayed.
89099 * @param int|bool $stripteaser Optional. Default is 0.
89100 * @param string $more_file Optional.
89101 * @param int $cut Optional. Amount of words to keep for the content.
89102 * @param int $encode_html Optional. How to encode the content.
89103 */
89104 function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) {
89105 $content = get_the_content($more_link_text, $stripteaser, $more_file);
89106 $content = apply_filters('the_content_rss', $content);
89107 if ( $cut && !$encode_html )
89108 $encode_html = 2;
89109 if ( 1== $encode_html ) {
89110 $content = wp_specialchars($content);
89111 $cut = 0;
89112 } elseif ( 0 == $encode_html ) {
89113 $content = make_url_footnote($content);
89114 } elseif ( 2 == $encode_html ) {
89115 $content = strip_tags($content);
89116 }
89117 if ( $cut ) {
89118 $blah = explode(' ', $content);
89119 if ( count($blah) > $cut ) {
89120 $k = $cut;
89121 $use_dotdotdot = 1;
89122 } else {
89123 $k = count($blah);
89124 $use_dotdotdot = 0;
89125 }
89126
89127 /** @todo Check performance, might be faster to use array slice instead. */
89128 for ( $i=0; $i<$k; $i++ )
89129 $excerpt .= $blah[$i].' ';
89130 $excerpt .= ($use_dotdotdot) ? '...' : '';
89131 $content = $excerpt;
89132 }
89133 $content = str_replace(']]>', ']]>', $content);
89134 echo $content;
89135 }
89136
89137 /**
89138 * Display the post excerpt for the feed.
89139 *
89140 * @package WordPress
89141 * @subpackage Feed
89142 * @since 0.71
89143 * @uses apply_filters() Calls 'the_excerpt_rss' hook on the excerpt.
89144 */
89145 function the_excerpt_rss() {
89146 $output = get_the_excerpt();
89147 echo apply_filters('the_excerpt_rss', $output);
89148 }
89149
89150 /**
89151 * Display the permalink to the post for use in feeds.
89152 *
89153 * @package WordPress
89154 * @subpackage Feed
89155 * @since 2.3.0
89156 * @uses apply_filters() Call 'the_permalink_rss' on the post permalink
89157 */
89158 function the_permalink_rss() {
89159 echo apply_filters('the_permalink_rss', get_permalink());
89160 }
89161
89162 /**
89163 * Display the feed GUID for the current comment.
89164 *
89165 * @package WordPress
89166 * @subpackage Feed
89167 * @since unknown
89168 */
89169 function comment_guid() {
89170 echo get_comment_guid();
89171 }
89172
89173 /**
89174 * Retrieve the feed GUID for the current comment.
89175 *
89176 * @package WordPress
89177 * @subpackage Feed
89178 * @since unknown
89179 *
89180 * @return bool|string false on failure or guid for comment on success.
89181 */
89182 function get_comment_guid() {
89183 global $comment;
89184
89185 if ( !is_object($comment) )
89186 return false;
89187
89188 return get_the_guid($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
89189 }
89190
89191 /**
89192 * Display the link to the comments.
89193 *
89194 * @since 1.5.0
89195 */
89196 function comment_link() {
89197 echo get_comment_link();
89198 }
89199
89200 /**
89201 * Retrieve the current comment author for use in the feeds.
89202 *
89203 * @package WordPress
89204 * @subpackage Feed
89205 * @since 2.0.0
89206 * @uses apply_filters() Calls 'comment_author_rss' hook on comment author.
89207 * @uses get_comment_author()
89208 *
89209 * @return string Comment Author
89210 */
89211 function get_comment_author_rss() {
89212 return apply_filters('comment_author_rss', get_comment_author() );
89213 }
89214
89215 /**
89216 * Display the current comment author in the feed.
89217 *
89218 * @package WordPress
89219 * @subpackage Feed
89220 * @since 1.0.0
89221 */
89222 function comment_author_rss() {
89223 echo get_comment_author_rss();
89224 }
89225
89226 /**
89227 * Display the current comment content for use in the feeds.
89228 *
89229 * @package WordPress
89230 * @subpackage Feed
89231 * @since 1.0.0
89232 * @uses apply_filters() Calls 'comment_text_rss' filter on comment content.
89233 * @uses get_comment_text()
89234 */
89235 function comment_text_rss() {
89236 $comment_text = get_comment_text();
89237 $comment_text = apply_filters('comment_text_rss', $comment_text);
89238 echo $comment_text;
89239 }
89240
89241 /**
89242 * Retrieve all of the post categories, formatted for use in feeds.
89243 *
89244 * All of the categories for the current post in the feed loop, will be
89245 * retrieved and have feed markup added, so that they can easily be added to the
89246 * RSS2, Atom, or RSS1 and RSS0.91 RDF feeds.
89247 *
89248 * @package WordPress
89249 * @subpackage Feed
89250 * @since 2.1.0
89251 * @uses apply_filters()
89252 *
89253 * @param string $type Optional, default is 'rss'. Either 'rss', 'atom', or 'rdf'.
89254 * @return string All of the post categories for displaying in the feed.
89255 */
89256 function get_the_category_rss($type = 'rss') {
89257 $categories = get_the_category();
89258 $tags = get_the_tags();
89259 $the_list = '';
89260 $cat_names = array();
89261
89262 $filter = 'rss';
89263 if ( 'atom' == $type )
89264 $filter = 'raw';
89265
89266 if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
89267 $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
89268 }
89269
89270 if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
89271 $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
89272 }
89273
89274 $cat_names = array_unique($cat_names);
89275
89276 foreach ( $cat_names as $cat_name ) {
89277 if ( 'rdf' == $type )
89278 $the_list .= "\n\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n";
89279 elseif ( 'atom' == $type )
89280 $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', attribute_escape( apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ) ), attribute_escape( $cat_name ) );
89281 else
89282 $the_list .= "\n\t\t<category><![CDATA[" . html_entity_decode( $cat_name ) . "]]></category>\n";
89283 }
89284
89285 return apply_filters('the_category_rss', $the_list, $type);
89286 }
89287
89288 /**
89289 * Display the post categories in the feed.
89290 *
89291 * @package WordPress
89292 * @subpackage Feed
89293 * @since 0.71
89294 * @see get_the_category_rss() For better explanation.
89295 *
89296 * @param string $type Optional, default is 'rss'. Either 'rss', 'atom', or 'rdf'.
89297 */
89298 function the_category_rss($type = 'rss') {
89299 echo get_the_category_rss($type);
89300 }
89301
89302 /**
89303 * Display the HTML type based on the blog setting.
89304 *
89305 * The two possible values are either 'xhtml' or 'html'.
89306 *
89307 * @package WordPress
89308 * @subpackage Feed
89309 * @since 2.2.0
89310 */
89311 function html_type_rss() {
89312 $type = get_bloginfo('html_type');
89313 if (strpos($type, 'xhtml') !== false)
89314 $type = 'xhtml';
89315 else
89316 $type = 'html';
89317 echo $type;
89318 }
89319
89320 /**
89321 * Display the rss enclosure for the current post.
89322 *
89323 * Uses the global $post to check whether the post requires a password and if
89324 * the user has the password for the post. If not then it will return before
89325 * displaying.
89326 *
89327 * Also uses the function get_post_custom() to get the post's 'enclosure'
89328 * metadata field and parses the value to display the enclosure(s). The
89329 * enclosure(s) consist of enclosure HTML tag(s) with a URI and other
89330 * attributes.
89331 *
89332 * @package WordPress
89333 * @subpackage Template
89334 * @since 1.5.0
89335 * @uses apply_filters() Calls 'rss_enclosure' hook on rss enclosure.
89336 * @uses get_post_custom() To get the current post enclosure metadata.
89337 */
89338 function rss_enclosure() {
89339 if ( post_password_required() )
89340 return;
89341
89342 foreach ( (array) get_post_custom() as $key => $val) {
89343 if ($key == 'enclosure') {
89344 foreach ( (array) $val as $enc ) {
89345 $enclosure = split("\n", $enc);
89346
89347 //only get the the first element eg, audio/mpeg from 'audio/mpeg mpga mp2 mp3'
89348 $t = split('[ \t]', trim($enclosure[2]) );
89349 $type = $t[0];
89350
89351 echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . $type . '" />' . "\n");
89352 }
89353 }
89354 }
89355 }
89356
89357 /**
89358 * Display the atom enclosure for the current post.
89359 *
89360 * Uses the global $post to check whether the post requires a password and if
89361 * the user has the password for the post. If not then it will return before
89362 * displaying.
89363 *
89364 * Also uses the function get_post_custom() to get the post's 'enclosure'
89365 * metadata field and parses the value to display the enclosure(s). The
89366 * enclosure(s) consist of link HTML tag(s) with a URI and other attributes.
89367 *
89368 * @package WordPress
89369 * @subpackage Template
89370 * @since 2.2.0
89371 * @uses apply_filters() Calls 'atom_enclosure' hook on atom enclosure.
89372 * @uses get_post_custom() To get the current post enclosure metadata.
89373 */
89374 function atom_enclosure() {
89375 if ( post_password_required() )
89376 return;
89377
89378 foreach ( (array) get_post_custom() as $key => $val ) {
89379 if ($key == 'enclosure') {
89380 foreach ( (array) $val as $enc ) {
89381 $enclosure = split("\n", $enc);
89382 echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
89383 }
89384 }
89385 }
89386 }
89387
89388 /**
89389 * Determine the type of a string of data with the data formatted.
89390 *
89391 * Tell whether the type is text, html, or xhtml, per RFC 4287 section 3.1.
89392 *
89393 * In the case of WordPress, text is defined as containing no markup,
89394 * xhtml is defined as "well formed", and html as tag soup (i.e., the rest).
89395 *
89396 * Container div tags are added to xhtml values, per section 3.1.1.3.
89397 *
89398 * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
89399 *
89400 * @package WordPress
89401 * @subpackage Feed
89402 * @since 2.5
89403 *
89404 * @param string $data Input string
89405 * @return array array(type, value)
89406 */
89407 function prep_atom_text_construct($data) {
89408 if (strpos($data, '<') === false && strpos($data, '&') === false) {
89409 return array('text', $data);
89410 }
89411
89412 $parser = xml_parser_create();
89413 xml_parse($parser, '<div>' . $data . '</div>', true);
89414 $code = xml_get_error_code($parser);
89415 xml_parser_free($parser);
89416
89417 if (!$code) {
89418 if (strpos($data, '<') === false) {
89419 return array('text', $data);
89420 } else {
89421 $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
89422 return array('xhtml', $data);
89423 }
89424 }
89425
89426 if (strpos($data, ']]>') == false) {
89427 return array('html', "<![CDATA[$data]]>");
89428 } else {
89429 return array('html', htmlspecialchars($data));
89430 }
89431 }
89432
89433 /**
89434 * Display the link for the currently displayed feed in a XSS safe way.
89435 *
89436 * Generate a correct link for the atom:self element.
89437 *
89438 * @package WordPress
89439 * @subpackage Feed
89440 * @since 2.5
89441 */
89442 function self_link() {
89443 $host = @parse_url(get_option('home'));
89444 $host = $host['host'];
89445 echo clean_url(
89446 'http'
89447 . ( (isset($_SERVER['https']) && $_SERVER['https'] == 'on') ? 's' : '' ) . '://'
89448 . $host
89449 . stripslashes($_SERVER['REQUEST_URI'])
89450 );
89451 }
89452
89453 ?>