rss.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 clean($id->nodeValue);
  7. } else {
  8. return clean($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 clean(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 clean(trim($link->nodeValue));
  34. }
  35. $link = $this->elem->getElementsByTagName("link")->item(0);
  36. if ($link) {
  37. return clean(trim($link->nodeValue));
  38. }
  39. }
  40. function get_title() {
  41. $title = $this->xpath->query("title", $this->elem)->item(0);
  42. if ($title) {
  43. return clean(trim($title->nodeValue));
  44. }
  45. // if the document has a default namespace then querying for
  46. // title would fail because of reasons so let's try the old way
  47. $title = $this->elem->getElementsByTagName("title")->item(0);
  48. if ($title) {
  49. return clean(trim($title->nodeValue));
  50. }
  51. }
  52. function get_content() {
  53. $contentA = $this->xpath->query("content:encoded", $this->elem)->item(0);
  54. $contentB = $this->elem->getElementsByTagName("description")->item(0);
  55. if ($contentA && !$contentB) {
  56. return $this->subtree_or_text($contentA);
  57. }
  58. if ($contentB && !$contentA) {
  59. return $this->subtree_or_text($contentB);
  60. }
  61. if ($contentA && $contentB) {
  62. $resultA = $this->subtree_or_text($contentA);
  63. $resultB = $this->subtree_or_text($contentB);
  64. return mb_strlen($resultA) > mb_strlen($resultB) ? $resultA : $resultB;
  65. }
  66. }
  67. function get_description() {
  68. $summary = $this->elem->getElementsByTagName("description")->item(0);
  69. if ($summary) {
  70. return $summary->nodeValue;
  71. }
  72. }
  73. function get_categories() {
  74. $categories = $this->elem->getElementsByTagName("category");
  75. $cats = [];
  76. foreach ($categories as $cat) {
  77. array_push($cats, $cat->nodeValue);
  78. }
  79. $categories = $this->xpath->query("dc:subject", $this->elem);
  80. foreach ($categories as $cat) {
  81. array_push($cats, $cat->nodeValue);
  82. }
  83. return $this->normalize_categories($cats);
  84. }
  85. function get_enclosures() {
  86. $enclosures = $this->elem->getElementsByTagName("enclosure");
  87. $encs = array();
  88. foreach ($enclosures as $enclosure) {
  89. $enc = new FeedEnclosure();
  90. $enc->type = clean($enclosure->getAttribute("type"));
  91. $enc->link = clean($enclosure->getAttribute("url"));
  92. $enc->length = clean($enclosure->getAttribute("length"));
  93. $enc->height = clean($enclosure->getAttribute("height"));
  94. $enc->width = clean($enclosure->getAttribute("width"));
  95. array_push($encs, $enc);
  96. }
  97. $encs = array_merge($encs, parent::get_enclosures());
  98. return $encs;
  99. }
  100. function get_language() {
  101. $languages = $this->doc->getElementsByTagName('language');
  102. if (count($languages) == 0) {
  103. return "";
  104. }
  105. return clean($languages[0]->textContent);
  106. }
  107. }