simple-feed.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. use Suin\RSSWriter\Channel;
  3. use Suin\RSSWriter\Feed;
  4. use Suin\RSSWriter\Item;
  5. // Load test target classes
  6. spl_autoload_register(function ($c) {
  7. @include_once strtr($c, '\\_', '//') . '.php';
  8. });
  9. set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__DIR__) . '/src');
  10. $feed = new Feed();
  11. $channel = new Channel();
  12. $channel
  13. ->title('Channel Title')
  14. ->description('Channel Description')
  15. ->url('http://blog.example.com')
  16. ->feedUrl('http://blog.example.com/rss')
  17. ->language('en-US')
  18. ->copyright('Copyright 2012, Foo Bar')
  19. ->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
  20. ->lastBuildDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
  21. ->ttl(60)
  22. ->pubsubhubbub('http://example.com/feed.xml', 'http://pubsubhubbub.appspot.com') // This is optional. Specify PubSubHubbub discovery if you want.
  23. ->appendTo($feed);
  24. // Blog item
  25. $item = new Item();
  26. $item
  27. ->title('Blog Entry Title')
  28. ->description('<div>Blog body</div>')
  29. ->contentEncoded('<div>Blog body</div>')
  30. ->url('http://blog.example.com/2012/08/21/blog-entry/')
  31. ->author('john@smith.com')
  32. ->creator('John Smith')
  33. ->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))
  34. ->guid('http://blog.example.com/2012/08/21/blog-entry/', true)
  35. ->preferCdata(true) // By this, title and description become CDATA wrapped HTML.
  36. ->appendTo($channel);
  37. // Podcast item
  38. $item = new Item();
  39. $item
  40. ->title('Some Podcast Entry')
  41. ->description('<div>Podcast body</div>')
  42. ->url('http://podcast.example.com/2012/08/21/podcast-entry/')
  43. ->enclosure('http://podcast.example.com/2012/08/21/podcast.mp3', 4889, 'audio/mpeg')
  44. ->appendTo($channel);
  45. echo $feed; // or echo $feed->render();