/** * * export index tree XML to file * @param $fp file handle * @param $index_id integer index id to export * @param $recursive bool true if recursive export * */ function xoonips_export_index_xml($fp, $index_id, $recursive) { return fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") && fwrite($fp, "<indexes>\n") && xnpExportIndex($fp, $index_id, $recursive) && fwrite($fp, "</indexes>\n"); }
/** * export index * * @param fhdl file handle that indexes are exported to. * @param index_id id of index to display * @param recurse true:export recursively index that hangs under index_id. * @return true:success, false:failure */ function xnpExportIndex($fhdl, $index_id, $recurse) { if (!$fhdl) { return false; } $myts =& MyTextSanitizer::getInstance(); $xnpsid = $_SESSION['XNPSID']; $index = array(); $child = array(); $res = xnp_get_index($xnpsid, $index_id, $index); if ($res != RES_OK) { return false; } $res = xnp_get_indexes($xnpsid, $index_id, array(), $child); if ($res != RES_OK) { return false; } if (!fwrite($fhdl, "<index parent_id=\"{$index['parent_index_id']}\" id=\"{$index_id}\">\n" . '<title>' . $myts->htmlSpecialChars($index['titles'][DEFAULT_INDEX_TITLE_OFFSET]) . "</title>\n" . "</index>\n")) { return false; } $xml = array(); if ($recurse) { $res = xnp_get_indexes($xnpsid, $index_id, array('orders' => array(array('sort_number', 0))), $child); if ($res == RES_OK) { foreach ($child as $i) { if (!xnpExportIndex($fhdl, $i['item_id'], $recurse)) { return false; } } } } return true; }