PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/rss.class.php

https://github.com/Nayruden/rhjunior
PHP | 72 lines | 61 code | 11 blank | 0 comment | 4 complexity | e6a700ab9b9fcd2c1d8347c20ca698f9 MD5 | raw file
  1. <?php
  2. class RSSFeed {
  3. var $channel_title;
  4. var $channel_url;
  5. var $channel_description;
  6. var $channel_language;
  7. var $channel_copyright;
  8. var $channel_managingEditor;
  9. var $channel_webMaster;
  10. var $channel_pubDate;
  11. var $channel_lastBuildDate;
  12. var $channel_generator;
  13. var $channel_docs;
  14. var $channel_image;
  15. var $channel_items;
  16. var $initialized;
  17. function RSSFeed() {
  18. }
  19. function setImage( $url, $title, $link, $width=NULL, $height=NULL, $description=NULL ) {
  20. $this->channel_image = array( 'url'=>$url, 'title'=>$title, 'link'=>$link, 'width'=>$width, 'height'=>$height, 'description'=>$description );
  21. }
  22. function setChannel( $title, $url, $description ) {
  23. $this->channel_title = $title;
  24. $this->channel_url = $url;
  25. $this->channel_description = $description;
  26. $this->initialized = TRUE;
  27. $this->channel_items = array();
  28. }
  29. function addItem( $title, $link, $description, $author=NULL, $comments=NULL, $guid=NULL, $pubDate=NULL ) {
  30. $this->channel_items[] = array( 'title'=>$title, 'link'=>$link, 'description'=>$description, 'author'=>$author, 'comments'=>$comments,
  31. 'guid'=>$guid, 'pubDate'=>$pubDate );
  32. }
  33. function buildRSS( $tab="\t", $nl="\n" ) {
  34. $output = '';
  35. $output .= '<?xml version="1.0"?>' . $nl;
  36. $output .= '<rss version="2.0">' . $nl;
  37. $output .= str_repeat( $tab, 1 ) . '<channel>' . $nl;
  38. $output .= str_repeat( $tab, 2 ) . '<title>' . $this->channel_title . '</title>' . $nl;
  39. $output .= str_repeat( $tab, 2 ) . '<link>' . $this->channel_url . '</link>' . $nl;
  40. $output .= str_repeat( $tab, 2 ) . '<description>' . $this->channel_description . '</description>' . $nl;
  41. foreach ( $this->channel_items as $data ) {
  42. $output .= str_repeat( $tab, 2 ) . '<item>' . $nl;
  43. $output .= str_repeat( $tab, 3 ) . '<title>' . $data[ 'title' ] . '</title>' . $nl;
  44. $output .= str_repeat( $tab, 3 ) . '<link>' . $data[ 'link' ] . '</link>' . $nl;
  45. $output .= str_repeat( $tab, 3 ) . '<description>' . $data[ 'description' ] . '</description>' . $nl;
  46. if ( !empty( $data[ 'author' ] )
  47. $output .= str_repeat( $tab, 3 ) . '<author>' . $data[ 'author' ] . '</author>' . $nl;
  48. if ( !empty( $data[ 'comments' ] )
  49. $output .= str_repeat( $tab, 3 ) . '<comments>' . $data[ 'comments' ] . '</comments>' . $nl;
  50. if ( !empty( $data[ 'guid' ] )
  51. $output .= str_repeat( $tab, 3 ) . '<guid>' . $data[ 'guid' ] . '</guid>' . $nl;
  52. if ( !empty( $data[ 'pubDate' ] )
  53. $output .= str_repeat( $tab, 3 ) . '<pubDate>' . $data[ 'pubDate' ] . '</pubDate>' . $nl;
  54. $output .= str_repeat( $tab, 2 ) . '</item>' . $nl;
  55. }
  56. $output .= str_repeat( $tab, 1 ) . '</channel>' . $nl;
  57. $output .= '</rss>' . $nl;
  58. return $output;
  59. }
  60. };
  61. ?>