atom.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. class FeedItem_Atom extends FeedItem_Common {
  3. function get_id() {
  4. $id = $this->elem->getElementsByTagName("id")->item(0);
  5. if ($id) {
  6. return $id->nodeValue;
  7. } else {
  8. return $this->get_link();
  9. }
  10. }
  11. function get_date() {
  12. $updated = $this->elem->getElementsByTagName("updated")->item(0);
  13. if ($updated) {
  14. return strtotime($updated->nodeValue);
  15. }
  16. $published = $this->elem->getElementsByTagName("published")->item(0);
  17. if ($published) {
  18. return strtotime($published->nodeValue);
  19. }
  20. $date = $this->xpath->query("dc:date", $this->elem)->item(0);
  21. if ($date) {
  22. return strtotime($date->nodeValue);
  23. }
  24. }
  25. function get_link() {
  26. $links = $this->elem->getElementsByTagName("link");
  27. foreach ($links as $link) {
  28. if ($link && $link->hasAttribute("href") &&
  29. (!$link->hasAttribute("rel")
  30. || $link->getAttribute("rel") == "alternate"
  31. || $link->getAttribute("rel") == "standout")) {
  32. $base = $this->xpath->evaluate("string(ancestor-or-self::*[@xml:base][1]/@xml:base)", $link);
  33. return rewrite_relative_url($base, $link->getAttribute("href"));
  34. }
  35. }
  36. }
  37. function get_title() {
  38. $title = $this->elem->getElementsByTagName("title")->item(0);
  39. if ($title) {
  40. return $title->nodeValue;
  41. }
  42. }
  43. function get_content() {
  44. $content = $this->elem->getElementsByTagName("content")->item(0);
  45. if ($content) {
  46. if ($content->hasAttribute('type')) {
  47. if ($content->getAttribute('type') == 'xhtml') {
  48. for ($i = 0; $i < $content->childNodes->length; $i++) {
  49. $child = $content->childNodes->item($i);
  50. if ($child->hasChildNodes()) {
  51. return $this->doc->saveXML($child);
  52. }
  53. }
  54. }
  55. }
  56. return $content->nodeValue;
  57. }
  58. }
  59. function get_description() {
  60. $content = $this->elem->getElementsByTagName("summary")->item(0);
  61. if ($content) {
  62. if ($content->hasAttribute('type')) {
  63. if ($content->getAttribute('type') == 'xhtml') {
  64. for ($i = 0; $i < $content->childNodes->length; $i++) {
  65. $child = $content->childNodes->item($i);
  66. if ($child->hasChildNodes()) {
  67. return $this->doc->saveXML($child);
  68. }
  69. }
  70. }
  71. }
  72. return $content->nodeValue;
  73. }
  74. }
  75. function get_categories() {
  76. $categories = $this->elem->getElementsByTagName("category");
  77. $cats = array();
  78. foreach ($categories as $cat) {
  79. if ($cat->hasAttribute("term"))
  80. array_push($cats, $cat->getAttribute("term"));
  81. }
  82. $categories = $this->xpath->query("dc:subject", $this->elem);
  83. foreach ($categories as $cat) {
  84. array_push($cats, $cat->nodeValue);
  85. }
  86. return $cats;
  87. }
  88. function get_enclosures() {
  89. $links = $this->elem->getElementsByTagName("link");
  90. $encs = array();
  91. foreach ($links as $link) {
  92. if ($link && $link->hasAttribute("href") && $link->hasAttribute("rel")) {
  93. if ($link->getAttribute("rel") == "enclosure") {
  94. $enc = new FeedEnclosure();
  95. $enc->type = $link->getAttribute("type");
  96. $enc->link = $link->getAttribute("href");
  97. $enc->length = $link->getAttribute("length");
  98. array_push($encs, $enc);
  99. }
  100. }
  101. }
  102. $enclosures = $this->xpath->query("media:content", $this->elem);
  103. foreach ($enclosures as $enclosure) {
  104. $enc = new FeedEnclosure();
  105. $enc->type = $enclosure->getAttribute("type");
  106. $enc->link = $enclosure->getAttribute("url");
  107. $enc->length = $enclosure->getAttribute("length");
  108. array_push($encs, $enc);
  109. }
  110. return $encs;
  111. }
  112. }
  113. ?>