rss.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 trim($link->getAttribute("href"));
  29. }
  30. }
  31. $link = $this->elem->getElementsByTagName("guid")->item(0);
  32. if ($link && $link->hasAttributes() && $link->getAttribute("isPermaLink") == "true") {
  33. return trim($link->nodeValue);
  34. }
  35. $link = $this->elem->getElementsByTagName("link")->item(0);
  36. if ($link) {
  37. return trim($link->nodeValue);
  38. }
  39. }
  40. function get_title() {
  41. $title = $this->elem->getElementsByTagName("title")->item(0);
  42. if ($title) {
  43. return trim($title->nodeValue);
  44. }
  45. }
  46. function get_content() {
  47. $contentA = $this->xpath->query("content:encoded", $this->elem)->item(0);
  48. $contentB = $this->elem->getElementsByTagName("description")->item(0);
  49. if ($contentA && !$contentB) {
  50. return $contentA->nodeValue;
  51. }
  52. if ($contentB && !$contentA) {
  53. return $contentB->nodeValue;
  54. }
  55. if ($contentA && $contentB) {
  56. return mb_strlen($contentA->nodeValue) > mb_strlen($contentB->nodeValue) ?
  57. $contentA->nodeValue : $contentB->nodeValue;
  58. }
  59. }
  60. function get_description() {
  61. $summary = $this->elem->getElementsByTagName("description")->item(0);
  62. if ($summary) {
  63. return $summary->nodeValue;
  64. }
  65. }
  66. function get_categories() {
  67. $categories = $this->elem->getElementsByTagName("category");
  68. $cats = array();
  69. foreach ($categories as $cat) {
  70. array_push($cats, trim($cat->nodeValue));
  71. }
  72. $categories = $this->xpath->query("dc:subject", $this->elem);
  73. foreach ($categories as $cat) {
  74. array_push($cats, trim($cat->nodeValue));
  75. }
  76. return $cats;
  77. }
  78. function get_enclosures() {
  79. $enclosures = $this->elem->getElementsByTagName("enclosure");
  80. $encs = array();
  81. foreach ($enclosures as $enclosure) {
  82. $enc = new FeedEnclosure();
  83. $enc->type = $enclosure->getAttribute("type");
  84. $enc->link = $enclosure->getAttribute("url");
  85. $enc->length = $enclosure->getAttribute("length");
  86. array_push($encs, $enc);
  87. }
  88. $enclosures = $this->xpath->query("media:content", $this->elem);
  89. foreach ($enclosures as $enclosure) {
  90. $enc = new FeedEnclosure();
  91. $enc->type = $enclosure->getAttribute("type");
  92. $enc->link = $enclosure->getAttribute("url");
  93. $enc->length = $enclosure->getAttribute("length");
  94. $desc = $this->xpath->query("media:description", $enclosure)->item(0);
  95. if ($desc) $enc->title = strip_tags($desc->nodeValue);
  96. array_push($encs, $enc);
  97. }
  98. $enclosures = $this->xpath->query("media:group", $this->elem);
  99. foreach ($enclosures as $enclosure) {
  100. $enc = new FeedEnclosure();
  101. $content = $this->xpath->query("media:content", $enclosure)->item(0);
  102. if ($content) {
  103. $enc->type = $content->getAttribute("type");
  104. $enc->link = $content->getAttribute("url");
  105. $enc->length = $content->getAttribute("length");
  106. $desc = $this->xpath->query("media:description", $content)->item(0);
  107. if ($desc) {
  108. $enc->title = strip_tags($desc->nodeValue);
  109. } else {
  110. $desc = $this->xpath->query("media:description", $enclosure)->item(0);
  111. if ($desc) $enc->title = strip_tags($desc->nodeValue);
  112. }
  113. array_push($encs, $enc);
  114. }
  115. }
  116. $enclosures = $this->xpath->query("media:thumbnail", $this->elem);
  117. foreach ($enclosures as $enclosure) {
  118. $enc = new FeedEnclosure();
  119. $enc->type = "image/generic";
  120. $enc->link = $enclosure->getAttribute("url");
  121. array_push($encs, $enc);
  122. }
  123. return $encs;
  124. }
  125. }
  126. ?>