public static function from_rss_item_dom($dom) { $thing = new ThingiverseThing(); $d = new DOMDocument('1.0'); $b = $d->importNode($dom->cloneNode(true), true); $d->appendChild($b); $xp = new DomXpath($d); $thing->title = $xp->query("//title/text()")->item(0)->wholeText; $thing->url = $xp->query("//link/text()")->item(0)->wholeText; $thing->creator = $xp->query("//author/text()")->item(0)->wholeText; $thing->creator_url = Thingiverse::BASE_URL . "/{$thing->creator}"; // TODO: convert to some kind of timestamp object $thing->created_at = ThingiverseThing::_ago(strtotime($xp->query("//pubDate/text()")->item(0)->wholeText)); // parse description, image out of <description> field $desc_html = ThingiverseThing::nodeContent($xp->query("//description")->item(0), false); $desc_dom = new DOMDocument('1.0'); @$desc_dom->loadHTML($desc_html); $dxp = new DomXpath($desc_dom); $img_elem = $dxp->query("//img")->item(0); $thing->main_image = $img_elem ? $img_elem->getAttribute("src") : null; $desc_elem = $dxp->query("//div")->item(1); $thing->description = trim($desc_elem ? ThingiverseThing::nodeContent($desc_elem, false) : null); return $thing; }
function parse_thing_mades_from_html_dom($dom) { $xp = new DomXpath($dom); $thing_nodes = $xp->query("//div[@class=\"thing_float\"]"); foreach ($thing_nodes as $thing_node) { $thing = ThingiverseThing::from_html_made_dom($thing_node); array_push($this->things, $thing); } }