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.

70 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 '../RSS1.php';
  7. date_default_timezone_set('UTC');
  8. use \FeedWriter\RSS1;
  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. //Creating an instance of RSS1 class.
  28. $TestFeed = new RSS1;
  29. //Setting the channel elements
  30. //Use wrapper functions for common elements
  31. //For other optional channel elements, use setChannelElement() function
  32. $TestFeed->setTitle('Testing the RSS writer class');
  33. $TestFeed->setLink('http://www.ajaxray.com/rss2/channel/about');
  34. $TestFeed->setDescription('This is test of creating a RSS 1.0 feed by Universal Feed Writer');
  35. //It's important for RSS 1.0
  36. $TestFeed->setChannelAbout('http://www.ajaxray.com/rss2/channel/about');
  37. //Adding a feed. Generally this portion will be in a loop and add all feeds.
  38. //Create an empty FeedItem
  39. $newItem = $TestFeed->createNewItem();
  40. //Add elements to the feed item
  41. //Use wrapper functions to add common feed elements
  42. $newItem->setTitle('The first feed');
  43. $newItem->setLink('http://www.yahoo.com');
  44. //The parameter is a timestamp for setDate() function
  45. $newItem->setDate(time());
  46. $newItem->setDescription('This is test of adding CDATA encoded description by the php <b>Universal Feed Writer</b> class');
  47. //Use core addElement() function for other supported optional elements
  48. $newItem->addElement('dc:subject', 'Nothing but test');
  49. //Now add the feed item
  50. $TestFeed->addItem($newItem);
  51. //Adding multiple elements from array
  52. //Elements which have an attribute cannot be added by this way
  53. $newItem = $TestFeed->createNewItem();
  54. $newItem->addElementArray(array('title'=>'The 2nd feed', 'link'=>'http://www.google.com', 'description'=>'This is a test of the FeedWriter class'));
  55. $TestFeed->addItem($newItem);
  56. //OK. Everything is done. Now generate the feed.
  57. $TestFeed->printFeed();