Rss.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ 0vX3WdTWaMIF5VPrBseG/pjAApJ81sZcqQiILXoKu/g=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2014 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.0
  11. */
  12. /**
  13. * rss 2.0 feed class
  14. */
  15. namespace Cube\Feed;
  16. class Rss extends AbstractFeed
  17. {
  18. /**
  19. *
  20. * generate feed based on entries
  21. *
  22. * @return string
  23. */
  24. public function generateFeed()
  25. {
  26. // header
  27. $output = '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL
  28. . '<rss version="2.0">' . PHP_EOL
  29. . '<channel>' . PHP_EOL
  30. . $this->_renderArray($this->_channels);
  31. if ($this->_entries) {
  32. /** @var \Cube\Feed\Entry $entry */
  33. foreach ($this->_entries as $entry) {
  34. $output .= '<item>' . PHP_EOL;
  35. $elements = $entry->getElements();
  36. foreach ($elements as $key => $value) {
  37. $output .= "<$key>$value</$key>" . PHP_EOL;
  38. }
  39. $output .= '</item>' . PHP_EOL;
  40. }
  41. }
  42. $output .= '</channel>' . PHP_EOL
  43. . '</rss>';
  44. return $output;
  45. }
  46. }