rss.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. class FeedItem_RSS extends FeedItem_Common {
  3. function get_id() {
  4. $id = $this->elem->getElementsByTagName("guid")->item(0);
  5. if ($id) {
  6. return $id->nodeValue;
  7. } else {
  8. return $this->get_link();
  9. }
  10. }
  11. function get_date() {
  12. $pubDate = $this->elem->getElementsByTagName("pubDate")->item(0);
  13. if ($pubDate) {
  14. return strtotime($pubDate->nodeValue);
  15. }
  16. $date = $this->xpath->query("dc:date", $this->elem)->item(0);
  17. if ($date) {
  18. return strtotime($date->nodeValue);
  19. }
  20. }
  21. function get_link() {
  22. $links = $this->xpath->query("atom:link", $this->elem);
  23. foreach ($links as $link) {
  24. if ($link && $link->hasAttribute("href") &&
  25. (!$link->hasAttribute("rel")
  26. || $link->getAttribute("rel") == "alternate"
  27. || $link->getAttribute("rel") == "standout")) {
  28. return $link->getAttribute("href");
  29. }
  30. }
  31. $link = $this->elem->getElementsByTagName("guid")->item(0);
  32. if ($link && $link->hasAttributes() && $link->getAttribute("isPermaLink") == "true") {
  33. return $link->nodeValue;
  34. }
  35. $link = $this->elem->getElementsByTagName("link")->item(0);
  36. if ($link) {
  37. return $link->nodeValue;
  38. }
  39. }
  40. function get_title() {
  41. $title = $this->elem->getElementsByTagName("title")->item(0);
  42. if ($title) {
  43. return $title->nodeValue;
  44. }
  45. }
  46. function get_content() {
  47. $content = $this->xpath->query("content:encoded", $this->elem)->item(0);
  48. if ($content) {
  49. return $content->nodeValue;
  50. }
  51. $content = $this->elem->getElementsByTagName("description")->item(0);
  52. if ($content) {
  53. return $content->nodeValue;
  54. }
  55. }
  56. function get_description() {
  57. $summary = $this->elem->getElementsByTagName("description")->item(0);
  58. if ($summary) {
  59. return $summary->nodeValue;
  60. }
  61. }
  62. function get_categories() {
  63. $categories = $this->elem->getElementsByTagName("category");
  64. $cats = array();
  65. foreach ($categories as $cat) {
  66. array_push($cats, $cat->nodeValue);
  67. }
  68. $categories = $this->xpath->query("dc:subject", $this->elem);
  69. foreach ($categories as $cat) {
  70. array_push($cats, $cat->nodeValue);
  71. }
  72. return $cats;
  73. }
  74. function get_enclosures() {
  75. $enclosures = $this->elem->getElementsByTagName("enclosure");
  76. $encs = array();
  77. foreach ($enclosures as $enclosure) {
  78. $enc = new FeedEnclosure();
  79. $enc->type = $enclosure->getAttribute("type");
  80. $enc->link = $enclosure->getAttribute("url");
  81. $enc->length = $enclosure->getAttribute("length");
  82. array_push($encs, $enc);
  83. }
  84. $enclosures = $this->xpath->query("media:content", $this->elem);
  85. foreach ($enclosures as $enclosure) {
  86. $enc = new FeedEnclosure();
  87. $enc->type = $enclosure->getAttribute("type");
  88. $enc->link = $enclosure->getAttribute("url");
  89. $enc->length = $enclosure->getAttribute("length");
  90. $desc = $this->xpath->query("media:description", $enclosure)->item(0);
  91. if ($desc) $enc->title = strip_tags($desc->nodeValue);
  92. array_push($encs, $enc);
  93. }
  94. $enclosures = $this->xpath->query("media:group", $this->elem);
  95. foreach ($enclosures as $enclosure) {
  96. $enc = new FeedEnclosure();
  97. $content = $this->xpath->query("media:content", $enclosure)->item(0);
  98. $enc->type = $content->getAttribute("type");
  99. $enc->link = $content->getAttribute("url");
  100. $enc->length = $content->getAttribute("length");
  101. $desc = $this->xpath->query("media:description", $content)->item(0);
  102. if ($desc) {
  103. $enc->title = strip_tags($desc->nodeValue);
  104. } else {
  105. $desc = $this->xpath->query("media:description", $enclosure)->item(0);
  106. if ($desc) $enc->title = strip_tags($desc->nodeValue);
  107. }
  108. array_push($encs, $enc);
  109. }
  110. $enclosures = $this->xpath->query("media:thumbnail", $this->elem);
  111. foreach ($enclosures as $enclosure) {
  112. $enc = new FeedEnclosure();
  113. $enc->type = "image/generic";
  114. $enc->link = $enclosure->getAttribute("url");
  115. array_push($encs, $enc);
  116. }
  117. return $encs;
  118. }
  119. }
  120. ?>