PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/atombuilder/www_root/atom_sample_script.php

http://flaimo-php.googlecode.com/
PHP | 104 lines | 52 code | 14 blank | 38 comment | 0 complexity | b5abbea67b22c913ebda502b47382d27 MD5 | raw file
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. //+----------------------------------------------------------------------+
  4. //| WAMP (XP-SP2/2.2/5.2/5.3.0) |
  5. //+----------------------------------------------------------------------+
  6. //| Copyright(c) 2001-2009 Michael Wimmer |
  7. //+----------------------------------------------------------------------+
  8. //| Licence: GNU General Public License v3 |
  9. //+----------------------------------------------------------------------+
  10. //| Authors: Michael Wimmer <flaimo@gmail.com> |
  11. //+----------------------------------------------------------------------+
  12. //
  13. // $Id$
  14. /**
  15. * @package AtomBuilder
  16. * @category flaimo-php
  17. * @filesource
  18. */
  19. error_reporting(E_ALL);
  20. ob_start();
  21. include_once '../inc/class.AtomBuilder.inc.php';
  22. /* create new feed object with the required informations: title, url to feed, id of the feed */
  23. $atom = new AtomBuilder('Example.com fake news - feed title', 'http://example.com/linktofeedhomepage', 'tag:flaimo@flaimo.com,2004-12-31:linktofeedhomepage');
  24. $atom->setEncoding('UTF-8'); // only needed if NOT utf-8
  25. $atom->setLanguage('en'); // recommended, but not required
  26. $atom->setSubtitle('The subtitle of the feed'); //optional
  27. $atom->setRights('2005-2006 Š Example.com'); //optional
  28. $atom->setUpdated('2005-10-20T10:04:00Z'); // required !! last time the feed or one of it's entries was last modified/updated; in php5 you can use date('c', $timestamp) to generate a valid date
  29. $atom->setAuthor('Flaimo', 'flaimo@example.com', 'http://example.com'); // name required, email and url are optional
  30. $atom->setIcon('http://example.com/16x16_icon.png'); // optional
  31. $atom->setLogo('http://example.com/100x50_logo.png'); // optional
  32. $atom->addContributor('Jörg', 'joerg@example.com'); // optional
  33. $atom->addContributor('Joe', 'joe@example.com', 'http://joespage.com');
  34. /* you can add a lot of different links to the feed and it's entries, see intertwingly.net/wiki/pie/ for more infos */
  35. $atom->addLink('http://php.net/', 'Official PHP homepage', 'related', 'text/html', 'en');
  36. $atom->addLink('http://example.com/', 'Example.com – HTML Homepage', 'alternate', 'text/html', 'en');
  37. $atom->addCategory('Webdesign', 'http://www.example.com/tags', 'Web 2.0 Webdesign'); // optional
  38. $atom->addCategory('PHP'); // optional
  39. /* now start adding entries... */
  40. $entry_1 = $atom->newEntry('The title of the first news item', 'http://example.com/linktofeedhomepage/permalink_to_the_first_news_item', 'tag:flaimo@flaimo.com,2004-12-31:linktofeedhomepage/detail/1'); // required infos: title, link, id
  41. $entry_1->setUpdated('2005-10-29T14:44:00Z'); // required (last modified/updated)
  42. $entry_1->setPublished('2005-10-29T14:34:00.25Z'); // optional
  43. $entry_1->setAuthor('Flaimo', 'flaimo@example.com', 'http://example.com/'); // name required, email and url are optional
  44. $entry_1->addContributor('Matt', 'matt@example.com'); // optional
  45. $entry_1->addContributor('Joe');
  46. $entry_1->setRights('2005-2009 Š Example.com'); // optional
  47. /* optional links */
  48. $entry_1->addLink('http://www.meyerweb.com/', 'meyerweb.com', 'via', 'text/html', 'en'); // for example if you post your plog entry in reply to someone elses plog entry
  49. $entry_1->addLink('http://orf.at/', 'ORF ON', 'related', 'text/html', 'de'); // related links for that entry
  50. $entry_1->addLink('http://feedvalidator.org/', 'Feed Validator for RSS and ATOM', 'related', 'text/html', 'en');
  51. $entry_1->addCategory('Webdesign', 'http://www.flaimo.com/tags', 'Web 2.0 Webdesign'); // optional
  52. $entry_1->setSummary('A <b>short</b> summary of the entry', 'html'); // both summary and content can contain plain text, html and xhtml
  53. $entry_1->setContent('The whole content of the entry. This <b>and</b> the summary <big>can contain HTML</big>', 'html');
  54. //$entry_1->setContent('dgwgtgfgg897dfg87fdgd876gdf86g…', 'image/png'); // you can also use other mime types
  55. $atom->addEntry($entry_1); // add the created entry to the feed
  56. /* add another entry... */
  57. $entry_2 = $atom->newEntry('The title of the second news item', 'http://example.com/linktofeedhomepage/permalink_to_the_second_news_item', 'tag:flaimo@flaimo.com,2004-12-31:linktofeedhomepage/detail/2');
  58. $entry_2->setUpdated('2005-10-29T15:54:00+01:00');
  59. $entry_2->setPublished('2005-10-29T15:34:00.11+01:00');
  60. $entry_2->setAuthor('Marcus', 'marcus@example.com', 'http://example.com/');
  61. $entry_2->addContributor('Matt', 'matt@example.com');
  62. $entry_2->addContributor('Joe', '', 'http://joespage.com');
  63. $entry_2->setRights('2003 Š Slashdot');
  64. $entry_2->addLink('http://slashdot.org/', 'slashdot.org', 'via', 'text/html');
  65. $entry_2->addLink('http://www.validome.org/', 'HTML / XHTML / WML / XML Validator', 'related', 'text/html');
  66. $entry_2->addLink('http://thisweekintech.com/twit31.mp3', 'This week in tech Potcast Nr. 31', 'related', 'audio/mp3');
  67. $entry_2->addLink('http://flaimo.com/'); // only the url is required, the rest is optional
  68. $entry_2->addCategory('PHP', 'http://www.example.com/tags', 'PHP-Scripting'); // optional
  69. $entry_2->setSummary('A short summary of the entry');
  70. // content can also be declared xhtml. but then your xhtml code has to be valid. invalid xhtml (xml) code will show an error message in the feed
  71. $entry_2->setContent('<p>The whole content of the entry. This <b>and</b> the summary <big>can contain XHTML</big></p>', 'xhtml');
  72. /*
  73. // you could also just link to the content
  74. $entry_2->setContent('', 'application/pdf', 'http://flaimo.com/sample.pdf');
  75. */
  76. $atom->addEntry($entry_2);
  77. $version = '1.0.0'; // 1.0 is the only version so far
  78. $atom->outputAtom($version);
  79. /*
  80. // if you don't want to directly output the content, but instead work with the string (for example write it to a cache file) use
  81. $foo = $atom->getAtomOutput($version);
  82. */
  83. /*
  84. // saves the xml file to the given path and returns the path + filename as a string; if no filename is given it will automatically be created
  85. $path = '';
  86. $filename = 'myfeed.xml';
  87. echo $atom->saveAtom($version, $path, $filename);
  88. */
  89. ob_end_flush();
  90. ?>