common.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. abstract class FeedItem_Common extends FeedItem {
  3. protected $elem;
  4. protected $xpath;
  5. protected $doc;
  6. function __construct($elem, $doc, $xpath) {
  7. $this->elem = $elem;
  8. $this->xpath = $xpath;
  9. $this->doc = $doc;
  10. try {
  11. $source = $elem->getElementsByTagName("source")->item(0);
  12. // we don't need <source> element
  13. if ($source)
  14. $elem->removeChild($source);
  15. } catch (DOMException $e) {
  16. //
  17. }
  18. }
  19. function get_author() {
  20. $author = $this->elem->getElementsByTagName("author")->item(0);
  21. if ($author) {
  22. $name = $author->getElementsByTagName("name")->item(0);
  23. if ($name) return $name->nodeValue;
  24. $email = $author->getElementsByTagName("email")->item(0);
  25. if ($email) return $email->nodeValue;
  26. if ($author->nodeValue)
  27. return $author->nodeValue;
  28. }
  29. $author = $this->xpath->query("dc:creator", $this->elem)->item(0);
  30. if ($author) {
  31. return $author->nodeValue;
  32. }
  33. }
  34. // todo
  35. function get_comments_url() {
  36. }
  37. function get_comments_count() {
  38. $comments = $this->xpath->query("slash:comments", $this->elem)->item(0);
  39. if ($comments) {
  40. return $comments->nodeValue;
  41. }
  42. }
  43. }
  44. ?>