PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Modifications Since 08/www/wp-includes/feed.php

https://github.com/holsinger/openfloor
PHP | 514 lines | 184 code | 40 blank | 290 comment | 35 complexity | 2db5a27af13f5f64174c2b9047f29ddd MD5 | raw file
  1. <?php
  2. /**
  3. * WordPress Feed API
  4. *
  5. * Many of the functions used in here belong in The Loop, or The Loop for the
  6. * Feeds.
  7. *
  8. * @package WordPress
  9. * @subpackage Feed
  10. */
  11. /**
  12. * RSS container for the bloginfo function.
  13. *
  14. * You can retrieve anything that you can using the get_bloginfo() function.
  15. * Everything will be stripped of tags and characters converted, when the values
  16. * are retrieved for use in the feeds.
  17. *
  18. * @package WordPress
  19. * @subpackage Feed
  20. * @since 1.5.1
  21. * @uses apply_filters() Calls 'get_bloginfo_rss' hook with two parameters.
  22. * @see get_bloginfo() For the list of possible values to display.
  23. *
  24. * @param string $show See get_bloginfo() for possible values.
  25. * @return string
  26. */
  27. function get_bloginfo_rss($show = '') {
  28. $info = strip_tags(get_bloginfo($show));
  29. return apply_filters('get_bloginfo_rss', convert_chars($info), $show);
  30. }
  31. /**
  32. * Display RSS container for the bloginfo function.
  33. *
  34. * You can retrieve anything that you can using the get_bloginfo() function.
  35. * Everything will be stripped of tags and characters converted, when the values
  36. * are retrieved for use in the feeds.
  37. *
  38. * @package WordPress
  39. * @subpackage Feed
  40. * @since 0.71
  41. * @uses apply_filters() Calls 'bloginfo_rss' hook with two parameters.
  42. * @see get_bloginfo() For the list of possible values to display.
  43. *
  44. * @param string $show See get_bloginfo() for possible values.
  45. */
  46. function bloginfo_rss($show = '') {
  47. echo apply_filters('bloginfo_rss', get_bloginfo_rss($show), $show);
  48. }
  49. /**
  50. * Retrieve the default feed.
  51. *
  52. * The default feed is 'rss2', unless a plugin changes it through the
  53. * 'default_feed' filter.
  54. *
  55. * @package WordPress
  56. * @subpackage Feed
  57. * @since 2.5
  58. * @uses apply_filters() Calls 'default_feed' hook on the default feed string.
  59. *
  60. * @return string Default feed, or for example 'rss2', 'atom', etc.
  61. */
  62. function get_default_feed() {
  63. return apply_filters('default_feed', 'rss2');
  64. }
  65. /**
  66. * Retrieve the blog title for the feed title.
  67. *
  68. * @package WordPress
  69. * @subpackage Feed
  70. * @since 2.2.0
  71. * @uses apply_filters() Calls 'get_wp_title_rss' hook on title.
  72. * @uses wp_title() See function for $sep parameter usage.
  73. *
  74. * @param string $sep Optional.How to separate the title. See wp_title() for more info.
  75. * @return string Error message on failure or blog title on success.
  76. */
  77. function get_wp_title_rss($sep = '&#187;') {
  78. $title = wp_title($sep, false);
  79. if ( is_wp_error( $title ) )
  80. return $title->get_error_message();
  81. $title = apply_filters('get_wp_title_rss', $title);
  82. return $title;
  83. }
  84. /**
  85. * Display the blog title for display of the feed title.
  86. *
  87. * @package WordPress
  88. * @subpackage Feed
  89. * @since 2.2.0
  90. * @uses apply_filters() Calls 'wp_title_rss' on the blog title.
  91. * @see wp_title() $sep parameter usage.
  92. *
  93. * @param string $sep Optional.
  94. */
  95. function wp_title_rss($sep = '&#187;') {
  96. echo apply_filters('wp_title_rss', get_wp_title_rss($sep));
  97. }
  98. /**
  99. * Retrieve the current post title for the feed.
  100. *
  101. * @package WordPress
  102. * @subpackage Feed
  103. * @since 2.0.0
  104. * @uses apply_filters() Calls 'the_title_rss' on the post title.
  105. *
  106. * @return string Current post title.
  107. */
  108. function get_the_title_rss() {
  109. $title = get_the_title();
  110. $title = apply_filters('the_title_rss', $title);
  111. return $title;
  112. }
  113. /**
  114. * Display the post title in the feed.
  115. *
  116. * @package WordPress
  117. * @subpackage Feed
  118. * @since 0.71
  119. * @uses get_the_title_rss() Used to retrieve current post title.
  120. */
  121. function the_title_rss() {
  122. echo get_the_title_rss();
  123. }
  124. /**
  125. * Display the post content for the feed.
  126. *
  127. * For encoding the html or the $encode_html parameter, there are three possible
  128. * values. '0' will make urls footnotes and use make_url_footnote(). '1' will
  129. * encode special characters and automatically display all of the content. The
  130. * value of '2' will strip all HTML tags from the content.
  131. *
  132. * Also note that you cannot set the amount of words and not set the html
  133. * encoding. If that is the case, then the html encoding will default to 2,
  134. * which will strip all HTML tags.
  135. *
  136. * To restrict the amount of words of the content, you can use the cut
  137. * parameter. If the content is less than the amount, then there won't be any
  138. * dots added to the end. If there is content left over, then dots will be added
  139. * and the rest of the content will be removed.
  140. *
  141. * @package WordPress
  142. * @subpackage Feed
  143. * @since 0.71
  144. * @uses apply_filters() Calls 'the_content_rss' on the content before processing.
  145. * @see get_the_content() For the $more_link_text, $stripteaser, and $more_file
  146. * parameters.
  147. *
  148. * @param string $more_link_text Optional. Text to display when more content is available but not displayed.
  149. * @param int|bool $stripteaser Optional. Default is 0.
  150. * @param string $more_file Optional.
  151. * @param int $cut Optional. Amount of words to keep for the content.
  152. * @param int $encode_html Optional. How to encode the content.
  153. */
  154. function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) {
  155. $content = get_the_content($more_link_text, $stripteaser, $more_file);
  156. $content = apply_filters('the_content_rss', $content);
  157. if ( $cut && !$encode_html )
  158. $encode_html = 2;
  159. if ( 1== $encode_html ) {
  160. $content = wp_specialchars($content);
  161. $cut = 0;
  162. } elseif ( 0 == $encode_html ) {
  163. $content = make_url_footnote($content);
  164. } elseif ( 2 == $encode_html ) {
  165. $content = strip_tags($content);
  166. }
  167. if ( $cut ) {
  168. $blah = explode(' ', $content);
  169. if ( count($blah) > $cut ) {
  170. $k = $cut;
  171. $use_dotdotdot = 1;
  172. } else {
  173. $k = count($blah);
  174. $use_dotdotdot = 0;
  175. }
  176. /** @todo Check performance, might be faster to use array slice instead. */
  177. for ( $i=0; $i<$k; $i++ )
  178. $excerpt .= $blah[$i].' ';
  179. $excerpt .= ($use_dotdotdot) ? '...' : '';
  180. $content = $excerpt;
  181. }
  182. $content = str_replace(']]>', ']]&gt;', $content);
  183. echo $content;
  184. }
  185. /**
  186. * Display the post excerpt for the feed.
  187. *
  188. * @package WordPress
  189. * @subpackage Feed
  190. * @since 0.71
  191. * @uses apply_filters() Calls 'the_excerpt_rss' hook on the excerpt.
  192. */
  193. function the_excerpt_rss() {
  194. $output = get_the_excerpt();
  195. echo apply_filters('the_excerpt_rss', $output);
  196. }
  197. /**
  198. * Display the permalink to the post for use in feeds.
  199. *
  200. * @package WordPress
  201. * @subpackage Feed
  202. * @since 2.3.0
  203. * @uses apply_filters() Call 'the_permalink_rss' on the post permalink
  204. */
  205. function the_permalink_rss() {
  206. echo apply_filters('the_permalink_rss', get_permalink());
  207. }
  208. /**
  209. * Display the feed GUID for the current comment.
  210. *
  211. * @package WordPress
  212. * @subpackage Feed
  213. * @since unknown
  214. *
  215. * @param int|object $comment_id Optional comment object or id. Defaults to global comment object.
  216. */
  217. function comment_guid($comment_id = null) {
  218. echo get_comment_guid($comment_id);
  219. }
  220. /**
  221. * Retrieve the feed GUID for the current comment.
  222. *
  223. * @package WordPress
  224. * @subpackage Feed
  225. * @since unknown
  226. *
  227. * @param int|object $comment_id Optional comment object or id. Defaults to global comment object.
  228. * @return bool|string false on failure or guid for comment on success.
  229. */
  230. function get_comment_guid($comment_id = null) {
  231. $comment = get_comment($comment_id);
  232. if ( !is_object($comment) )
  233. return false;
  234. return get_the_guid($comment->comment_post_ID) . '#comment-' . $comment->comment_ID;
  235. }
  236. /**
  237. * Display the link to the comments.
  238. *
  239. * @since 1.5.0
  240. */
  241. function comment_link() {
  242. echo clean_url( get_comment_link() );
  243. }
  244. /**
  245. * Retrieve the current comment author for use in the feeds.
  246. *
  247. * @package WordPress
  248. * @subpackage Feed
  249. * @since 2.0.0
  250. * @uses apply_filters() Calls 'comment_author_rss' hook on comment author.
  251. * @uses get_comment_author()
  252. *
  253. * @return string Comment Author
  254. */
  255. function get_comment_author_rss() {
  256. return apply_filters('comment_author_rss', get_comment_author() );
  257. }
  258. /**
  259. * Display the current comment author in the feed.
  260. *
  261. * @package WordPress
  262. * @subpackage Feed
  263. * @since 1.0.0
  264. */
  265. function comment_author_rss() {
  266. echo get_comment_author_rss();
  267. }
  268. /**
  269. * Display the current comment content for use in the feeds.
  270. *
  271. * @package WordPress
  272. * @subpackage Feed
  273. * @since 1.0.0
  274. * @uses apply_filters() Calls 'comment_text_rss' filter on comment content.
  275. * @uses get_comment_text()
  276. */
  277. function comment_text_rss() {
  278. $comment_text = get_comment_text();
  279. $comment_text = apply_filters('comment_text_rss', $comment_text);
  280. echo $comment_text;
  281. }
  282. /**
  283. * Retrieve all of the post categories, formatted for use in feeds.
  284. *
  285. * All of the categories for the current post in the feed loop, will be
  286. * retrieved and have feed markup added, so that they can easily be added to the
  287. * RSS2, Atom, or RSS1 and RSS0.91 RDF feeds.
  288. *
  289. * @package WordPress
  290. * @subpackage Feed
  291. * @since 2.1.0
  292. * @uses apply_filters()
  293. *
  294. * @param string $type Optional, default is 'rss'. Either 'rss', 'atom', or 'rdf'.
  295. * @return string All of the post categories for displaying in the feed.
  296. */
  297. function get_the_category_rss($type = 'rss') {
  298. $categories = get_the_category();
  299. $tags = get_the_tags();
  300. $the_list = '';
  301. $cat_names = array();
  302. $filter = 'rss';
  303. if ( 'atom' == $type )
  304. $filter = 'raw';
  305. if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
  306. $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
  307. }
  308. if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
  309. $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
  310. }
  311. $cat_names = array_unique($cat_names);
  312. foreach ( $cat_names as $cat_name ) {
  313. if ( 'rdf' == $type )
  314. $the_list .= "\n\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n";
  315. elseif ( 'atom' == $type )
  316. $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', attribute_escape( apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ) ), attribute_escape( $cat_name ) );
  317. else
  318. $the_list .= "\n\t\t<category><![CDATA[" . html_entity_decode( $cat_name ) . "]]></category>\n";
  319. }
  320. return apply_filters('the_category_rss', $the_list, $type);
  321. }
  322. /**
  323. * Display the post categories in the feed.
  324. *
  325. * @package WordPress
  326. * @subpackage Feed
  327. * @since 0.71
  328. * @see get_the_category_rss() For better explanation.
  329. *
  330. * @param string $type Optional, default is 'rss'. Either 'rss', 'atom', or 'rdf'.
  331. */
  332. function the_category_rss($type = 'rss') {
  333. echo get_the_category_rss($type);
  334. }
  335. /**
  336. * Display the HTML type based on the blog setting.
  337. *
  338. * The two possible values are either 'xhtml' or 'html'.
  339. *
  340. * @package WordPress
  341. * @subpackage Feed
  342. * @since 2.2.0
  343. */
  344. function html_type_rss() {
  345. $type = get_bloginfo('html_type');
  346. if (strpos($type, 'xhtml') !== false)
  347. $type = 'xhtml';
  348. else
  349. $type = 'html';
  350. echo $type;
  351. }
  352. /**
  353. * Display the rss enclosure for the current post.
  354. *
  355. * Uses the global $post to check whether the post requires a password and if
  356. * the user has the password for the post. If not then it will return before
  357. * displaying.
  358. *
  359. * Also uses the function get_post_custom() to get the post's 'enclosure'
  360. * metadata field and parses the value to display the enclosure(s). The
  361. * enclosure(s) consist of enclosure HTML tag(s) with a URI and other
  362. * attributes.
  363. *
  364. * @package WordPress
  365. * @subpackage Template
  366. * @since 1.5.0
  367. * @uses apply_filters() Calls 'rss_enclosure' hook on rss enclosure.
  368. * @uses get_post_custom() To get the current post enclosure metadata.
  369. */
  370. function rss_enclosure() {
  371. if ( post_password_required() )
  372. return;
  373. foreach ( (array) get_post_custom() as $key => $val) {
  374. if ($key == 'enclosure') {
  375. foreach ( (array) $val as $enc ) {
  376. $enclosure = split("\n", $enc);
  377. //only get the the first element eg, audio/mpeg from 'audio/mpeg mpga mp2 mp3'
  378. $t = split('[ \t]', trim($enclosure[2]) );
  379. $type = $t[0];
  380. echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . $type . '" />' . "\n");
  381. }
  382. }
  383. }
  384. }
  385. /**
  386. * Display the atom enclosure for the current post.
  387. *
  388. * Uses the global $post to check whether the post requires a password and if
  389. * the user has the password for the post. If not then it will return before
  390. * displaying.
  391. *
  392. * Also uses the function get_post_custom() to get the post's 'enclosure'
  393. * metadata field and parses the value to display the enclosure(s). The
  394. * enclosure(s) consist of link HTML tag(s) with a URI and other attributes.
  395. *
  396. * @package WordPress
  397. * @subpackage Template
  398. * @since 2.2.0
  399. * @uses apply_filters() Calls 'atom_enclosure' hook on atom enclosure.
  400. * @uses get_post_custom() To get the current post enclosure metadata.
  401. */
  402. function atom_enclosure() {
  403. if ( post_password_required() )
  404. return;
  405. foreach ( (array) get_post_custom() as $key => $val ) {
  406. if ($key == 'enclosure') {
  407. foreach ( (array) $val as $enc ) {
  408. $enclosure = split("\n", $enc);
  409. echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
  410. }
  411. }
  412. }
  413. }
  414. /**
  415. * Determine the type of a string of data with the data formatted.
  416. *
  417. * Tell whether the type is text, html, or xhtml, per RFC 4287 section 3.1.
  418. *
  419. * In the case of WordPress, text is defined as containing no markup,
  420. * xhtml is defined as "well formed", and html as tag soup (i.e., the rest).
  421. *
  422. * Container div tags are added to xhtml values, per section 3.1.1.3.
  423. *
  424. * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
  425. *
  426. * @package WordPress
  427. * @subpackage Feed
  428. * @since 2.5
  429. *
  430. * @param string $data Input string
  431. * @return array array(type, value)
  432. */
  433. function prep_atom_text_construct($data) {
  434. if (strpos($data, '<') === false && strpos($data, '&') === false) {
  435. return array('text', $data);
  436. }
  437. $parser = xml_parser_create();
  438. xml_parse($parser, '<div>' . $data . '</div>', true);
  439. $code = xml_get_error_code($parser);
  440. xml_parser_free($parser);
  441. if (!$code) {
  442. if (strpos($data, '<') === false) {
  443. return array('text', $data);
  444. } else {
  445. $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
  446. return array('xhtml', $data);
  447. }
  448. }
  449. if (strpos($data, ']]>') == false) {
  450. return array('html', "<![CDATA[$data]]>");
  451. } else {
  452. return array('html', htmlspecialchars($data));
  453. }
  454. }
  455. /**
  456. * Display the link for the currently displayed feed in a XSS safe way.
  457. *
  458. * Generate a correct link for the atom:self element.
  459. *
  460. * @package WordPress
  461. * @subpackage Feed
  462. * @since 2.5
  463. */
  464. function self_link() {
  465. $host = @parse_url(get_option('home'));
  466. $host = $host['host'];
  467. echo clean_url(
  468. 'http'
  469. . ( (isset($_SERVER['https']) && $_SERVER['https'] == 'on') ? 's' : '' ) . '://'
  470. . $host
  471. . stripslashes($_SERVER['REQUEST_URI'])
  472. );
  473. }
  474. ?>