public function createFromUrl($url) { $dom = new DOMDocument(); $dom->preserveWhitespace = false; $success = $dom->load($url); if (!$success) { new mb_exception(__FILE__ . ": createFromUrl(): Could not load " . $url); return null; } $nodeList = $dom->getElementsByTagName("rss"); if ($nodeList->length > 0) { $node = $nodeList->item(0); if ($node->hasAttribute("xmlns:georss")) { $geoRssFactory = new GeoRssFactory(); return $geoRssFactory->createFromUrl($url); } } $rssFactory = new RssFactory(); return $rssFactory->createFromUrl($url); }
protected function parseItem($node, $item) { $item = parent::parseItem($node, $item); foreach ($node->childNodes as $childNode) { switch ($childNode->tagName) { case "georss:box": $coordinateString = trim($childNode->nodeValue); $coordinateArray = explode(" ", $coordinateString); if (count($coordinateArray) === 4) { $bbox = new Mapbender_bbox(floatval($coordinateArray[0]), floatval($coordinateArray[1]), floatval($coordinateArray[2]), floatval($coordinateArray[3]), "EPSG:4326"); $item->setBbox($bbox); } break; } } return $item; }
$success = true; echo "<br><br>"; echo "Bounding box of item #3 should be: " . BBOX . "<br>"; $box = $geoRss->getItem(2)->getBbox(); $boxString = $box->min->x . " " . $box->min->y . " " . $box->max->x . " " . $box->max->y; echo "Bounding box of item #3 is: " . $boxString . "<br>"; if ($boxString !== BBOX) { $success = false; echo "FAIL :-("; die; } echo "OK :-)"; // create RSS at $success = true; echo "<br><br>"; $aSecondRssFactory = new RssFactory(); $randomRss = str_replace(".xml", "_" . rand() . ".xml", RANDOM_GEORSS); echo "Create random GeoRSS at: " . $randomRss . "<br>"; $anotherRss = $aSecondRssFactory->createAt($randomRss); if (is_null($anotherRss)) { $success = false; echo "FAIL :-("; die; } echo "OK :-)"; // create RSS from URL $success = true; echo "<br><br>"; $yetAnotherRss = $someRssFactory->createFromUrl($randomRss); echo "Random RSS should be of type: Rss<br>"; echo "Random RSS is of type: " . get_class($yetAnotherRss) . "<br>";