private function exportData($aaExportPageGroups) { $oDoc = new DOMDocument("1.0", "UTF-8"); //put information as comment $sComment = ""; $sComment .= $this->t_("xmlcomment_info") . "\n"; $sComment .= ANWIKI_WEBSITE . "\n\n"; $sComment .= $this->t_("xmlcomment_time", array("time" => Anwi18n::dateTime(time()))) . "\n"; $sComment .= $this->t_("xmlcomment_version", array("version" => ANWIKI_VERSION_NAME)) . "\n"; $sComment .= $this->t_("xmlcomment_user", array("user" => AnwCurrentSession::getUser()->getLogin())) . "\n"; $sComment .= $this->t_("xmlcomment_from", array("url" => self::globalCfgUrlRoot())) . "\n\n"; $sComment .= $this->t_("xmlcomment_contents") . "\n"; //list exported contents as comment foreach ($aaExportPageGroups as $amPageGroup) { foreach ($amPageGroup['PAGES'] as $oPage) { $sPageTime = Anwi18n::dateTime($oPage->getTime()); $sComment .= ' * ' . $oPage->getName() . " (" . $oPage->getLang() . ") (" . $sPageTime . ")\n"; } } $sCommentSeparator = "\n**************************************************\n"; $sComment = " " . $sCommentSeparator . $sComment . $sCommentSeparator . " "; $oCommentNode = $oDoc->createComment($sComment); $oDoc->appendChild($oCommentNode); //end comment //<anwexport time="" origin=""> $oRootNode = $oDoc->createElement(self::XMLTAG_ROOT); $oRootNode->setAttribute("time", time()); $oRootNode->setAttribute("from", AnwXml::xmlFileAttributeEncode(self::globalCfgUrlRoot())); $oRootNode->setAttribute("version_id", ANWIKI_VERSION_ID); $oRootNode->setAttribute("version_name", AnwXml::xmlFileAttributeEncode(ANWIKI_VERSION_NAME)); $oDoc->appendChild($oRootNode); foreach ($aaExportPageGroups as $amPageGroup) { $oPageGroup = $amPageGroup['GROUP']; $sContentClassName = $oPageGroup->getContentClass()->getName(); //<anwpagegroup> $oPageGroupNode = $oDoc->createElement(self::XMLTAG_PAGEGROUP); $oPageGroupNode->setAttribute("contentclass", AnwXml::xmlFileAttributeEncode($sContentClassName)); foreach ($amPageGroup['PAGES'] as $oPage) { //add comment $sPageTime = Anwi18n::dateTime($oPage->getTime()); $sComment = $oPage->getName() . " (" . $oPage->getLang() . ") (" . $sPageTime . ") (" . $oPageGroup->getContentClass()->getLabel() . "/" . $sContentClassName . ")"; //$sComment = " \n*\n* ".$sComment."\n*\n "; $sCommentSeparator = "\n**************************************************\n"; $sComment = " \n\n" . $sCommentSeparator . $sComment . $sCommentSeparator . " "; $oCommentNode = $oDoc->createComment($sComment); $oPageGroupNode->appendChild($oCommentNode); //end comment //using a CDATA node to preserve source breaklines :-) //$sPageContent = $oPage->getContent()->toXml(); //$oPageContentNode = $oDoc->createCDATASection($sPageContent); $oContentNodeDoc = $oPage->getContent()->toXml()->documentElement; //here we got a <doc> node $oPageContentNodeDoc = $oDoc->importNode($oContentNodeDoc, true); //<anwpage name="" lang="" time=""> $oPageNode = $oDoc->createElement(self::XMLTAG_PAGE); $oPageNode->setAttribute("name", AnwXml::xmlFileAttributeEncode($oPage->getName())); $oPageNode->setAttribute("lang", AnwXml::xmlFileAttributeEncode($oPage->getLang())); $oPageNode->setAttribute("time", $oPage->getTime()); //we need to do this to squeeze the unwanted <doc> node in //WARNING - special loop ! childs are getting modified... while ($oChildNode = $oPageContentNodeDoc->childNodes->item(0)) { $oPageNode->appendChild($oChildNode); } $oPageGroupNode->appendChild($oPageNode); } $oRootNode->appendChild($oPageGroupNode); } $sReturn = AnwUtils::xmlDumpNode($oRootNode); // even if final XML structure may be broken due to undeclared namespaces used in content, // we let raw content as it is for better compatibility in later versions. // $sReturn = AnwXml::prepareXmlValueToXml($sReturn); return $sReturn; }