strtotime($b["updated"]) ? -1 : 1); } $XML_OPTIONS = LIBXML_COMPACT | LIBXML_NOBLANKS | LIBXML_NOCDATA | LIBXML_NSCLEAN | LIBXML_XINCLUDE; function pregen_atom($feed, $feedDest, $newsDest) { $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; if (!$dom->load($feed, $GLOBALS["XML_OPTIONS"])) { trigger_error("News feed b0rked!", E_USER_WARNING); return; } if (!$dom->xinclude()) { trigger_error("News items b0rked!", E_USER_WARNING); return; } $timestamps = []; foreach ($dom->getElementsByTagName("updated") as $node) { $timestamps[] = strtotime($node->nodeValue, $_SERVER["REQUEST_TIME"]); } $updated = max($timestamps); $upnode = $dom->createElement("updated", date(DATE_ATOM, $updated)); $dom->documentElement->insertBefore($upnode, $dom->getElementsByTagName("link")->item(0)); $feed = $dom->saveXML(); $entries = format_atom_feed($feed); $write = 'XML($filename, "UTF-8"); $entries = []; while($r->read()) { if ($r->nodeType === XMLReader::ELEMENT && $r->name === "entry") { $entries[] = $current = format_atom_entry($r); } } return $entries; } // {{{ Parse the entry into array(element => value) function format_atom_entry($r) { $retval = []; while($r->read()) { if ($r->nodeType !== XMLReader::ELEMENT) { if ($r->nodeType === XMLReader::END_ELEMENT && $r->name === "entry") { return $retval; } continue; } $name = $r->localName; if ($r->namespaceURI === XMLNS_ATOM) { switch($name) { case "title": case "id": case "published": case "updated": $retval[$name] = $r->readString(); $retval[$name] = $r->readString(); break; case "link": case "category": $retval[$name][] = format_attributes($r); break; case "content": if ($r->hasAttributes) { switch($r->getAttribute("type")) { case "html": case "xhtml": $str = ltrim($r->readInnerXML()); // Remove the xmlns attribute $search = ' xmlns="'.XMLNS_XHTML.'"'; if (($pos = strpos($str, $search)) !== false && $pos < 10) { $str = substr_replace($str, "", $pos, strlen($search)); } $retval[$name] = $str; break; case "text": $retval[$name] = $r->readString(); break; } } else { $retval[$name] = $r->readString(); } $dom = new DOMDocument(); @$dom->loadHTML($retval[$name]); $xpath = new DomXPath($dom); $nodes = $xpath->query('//body/div/*'); if ($nodes !== FALSE) { $content = '