<?php
class FeedItem_Atom {
private $elem;
+ private $xpath;
function __construct($elem, $doc, $xpath) {
$this->elem = $elem;
+ $this->xpath = $xpath;
}
function get_id() {
}
- // todo
function get_comments_count() {
+ $comments = $this->xpath->query("slash:comments", $this->elem)->item(0);
+ if ($comments) {
+ return $comments->nodeValue;
+ }
}
function get_categories() {
array_push($cats, $cat->getAttribute("term"));
}
+ $categories = $this->xpath->query("dc:subject", $this->elem);
+
+ foreach ($categories as $cat) {
+ array_push($cats, $cat->nodeValue);
+ }
return $cats;
}
}
}
+ $enclosures = $this->xpath->query("media:content", $this->elem);
+
+ foreach ($enclosures as $enclosure) {
+ $enc = new FeedEnclosure();
+
+ $enc->type = $enclosure->getAttribute("type");
+ $enc->link = $enclosure->getAttribute("url");
+ $enc->length = $enclosure->getAttribute("length");
+
+ array_push($encs, $enc);
+ }
+
return $encs;
}
}
- // todo
function get_comments_count() {
+ $comments = $this->xpath->query("slash:comments", $this->elem)->item(0);
+ if ($comments) {
+ return $comments->nodeValue;
+ }
}
function get_categories() {
array_push($cats, $cat->nodeValue);
}
+ $categories = $this->xpath->query("dc:subject", $this->elem);
+
+ foreach ($categories as $cat) {
+ array_push($cats, $cat->nodeValue);
+ }
+
return $cats;
}
$enclosures = $this->xpath->query("media:content", $this->elem);
- $encs = array();
-
foreach ($enclosures as $enclosure) {
$enc = new FeedEnclosure();
$xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
$xpath->registerNamespace('media', 'http://search.yahoo.com/mrss/');
$xpath->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
+ $xpath->registerNamespace('slash', 'http://purl.org/rss/1.0/modules/slash/');
+ $xpath->registerNamespace('dc', 'http://purl.org/dc/elements/1.1/');
+
$this->xpath = $xpath;
$root = $xpath->query("(//atom:feed|//channel|//rdf:rdf|//rdf:RDF)")->item(0);
$entry_comments = db_escape_string(mb_substr(trim($entry_comments), 0, 245));
$entry_author = db_escape_string(mb_substr(trim($entry_author), 0, 245));
- $num_comments = $item->get_comments_count();
-
- if (is_array($num_comments) && is_array($num_comments[0])) {
- $num_comments = (int) $num_comments[0]["data"];
- } else {
- $num_comments = 0;
- }
+ $num_comments = (int) $item->get_comments_count();
_debug("author $entry_author", $debug_enabled);
_debug("num_comments: $num_comments", $debug_enabled);