PHP Universal Feed Generator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.6 KiB

  1. <?php
  2. // You should use an autoloader instead of including the files directly.
  3. // This is done here only to make the examples work out of the box.
  4. include '../Item.php';
  5. include '../Feed.php';
  6. include '../ATOM.php';
  7. date_default_timezone_set('UTC');
  8. use \FeedWriter\ATOM;
  9. /*
  10. * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
  11. *
  12. * This file is part of the "Universal Feed Writer" project.
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. */
  27. // IMPORTANT : No need to add id for feed or channel. It will be automatically created from link.
  28. //Creating an instance of ATOM class.
  29. $TestFeed = new ATOM;
  30. //Setting the channel elements
  31. //Use wrapper functions for common elements
  32. $TestFeed->setTitle('Testing the RSS writer class');
  33. $TestFeed->setLink('http://www.ajaxray.com/rss2/channel/about');
  34. $TestFeed->setDate(new DateTime());
  35. //For other channel elements, use setChannelElement() function
  36. $TestFeed->setChannelElement('author', array('name'=>'Anis uddin Ahmad'));
  37. //You can add additional link elements, e.g. to a PubSubHubbub server with custom relations.
  38. $TestFeed->setSelfLink('http://example.com/myfeed');
  39. $TestFeed->setAtomLink('http://pubsubhubbub.appspot.com', 'hub');
  40. //Adding a feed. Generally this portion will be in a loop and add all feeds.
  41. //Create an empty Item
  42. $newItem = $TestFeed->createNewItem();
  43. //Add elements to the feed item
  44. //Use wrapper functions to add common feed elements
  45. $newItem->setTitle('The first feed');
  46. $newItem->setLink('http://www.yahoo.com');
  47. $newItem->setDate(time());
  48. $newItem->setAuthor('Anis uddin Ahmad', 'anis@example.invalid');
  49. $newItem->setEnclosure('http://upload.wikimedia.org/wikipedia/commons/4/49/En-us-hello-1.ogg', 11779, 'audio/ogg');
  50. //Internally changed to "summary" tag for ATOM feed
  51. $newItem->setDescription('This is a test of adding CDATA encoded description by the php <b>Universal Feed Writer</b> class');
  52. $newItem->setContent('<h1>hi.</h1> <p>This is the content for the entry.</p>');
  53. //Now add the feed item
  54. $TestFeed->addItem($newItem);
  55. //OK. Everything is done. Now generate the feed.
  56. $TestFeed->printFeed();