opml.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. class opml
  3. {
  4. private $data;
  5. private $writer;
  6. public function __construct($data)
  7. {
  8. $this->data = $data;
  9. $this->writer = new XMLWriter();
  10. $this->writer->openMemory();
  11. }
  12. public function render()
  13. {
  14. $this->writer->startDocument('1.0', 'UTF-8');
  15. $this->writer->startElement('opml');
  16. $this->writer->writeAttribute('version', '2.0');
  17. // Header
  18. $this->writer->startElement('head');
  19. foreach ($this->data['head'] as $key => $value) {
  20. $this->writer->writeElement($key, $value);
  21. }
  22. $this->writer->writeElement('dateModified', date("D, d M Y H:i:s T"));
  23. $this->writer->endElement();
  24. // Body
  25. $this->writer->startElement('body');
  26. foreach ($this->data['body'] as $outlines) {
  27. $this->writer->startElement('outline');
  28. foreach ($outlines as $key => $value) {
  29. $this->writer->writeAttribute($key, $value);
  30. }
  31. $this->writer->endElement();
  32. }
  33. $this->writer->endElement();
  34. $this->writer->endElement();
  35. $this->writer->endDocument();
  36. return $this->writer->outputMemory();
  37. }
  38. }