store->isCollection($key)) {
// TODO: Post a new document to a collection
return $driver->showErrorTextResponse(501,
"Posting to a collection not yet supported.");
} else {
// Attempt to fetch an existing document at this key.
list($orig_doc, $orig_root_node) = fetchOutlineWithSelector($key, $selector);
// The mode parameter specifies a variety of UI actions.
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
switch($mode) {
case 'append':
// TODO: Should this even be in xoxoio.php?
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : '';
switch($type) {
case 'xml':
$data = $_POST['data'];
// HACK: Ensure that the submitted XML is wrapped with an
if (!startsWith($data, '$data";
list($raw_doc, $new_root_node) = fetchRequestDataAsOutline($data);
$new_item = $orig_doc->importNode($new_root_node, TRUE);
break;
case 'text':
default:
$new_item = $orig_doc->createElementNS($XHTML_NS, 'li');
$new_span = $orig_doc->createElementNS($XHTML_NS, 'div');
$new_span->appendChild($orig_doc->createTextNode($_POST['data']));
$new_item->appendChild($new_span);
break;
}
$ol_parent = getOutlineItemContainerNode($orig_doc, $orig_root_node);
$ol_parent->appendChild($new_item);
break;
default:
if (!$selector) {
// TODO: Posting to root of outline, not sure what to do yet.
return $driver->showErrorTextResponse(501,
"Posting to outline root not yet supported.");
} else {
// Parse and sanitize new incoming data, grab the root node.
list($raw_doc, $new_root_node) = fetchRequestDataAsOutline();
// New document data without selector must be 'html'.
if ($new_root_node->tagName != 'li') {
return $driver->showErrorTextResponse(415, "Outline node type must be 'li'.");
}
$new_import_node = $orig_doc->importNode($new_root_node, TRUE);
$ol_parent = getOutlineItemContainerNode($orig_doc, $orig_root_node);
$ol_parent->appendChild($new_import_node);
}
break;
}
// Attempt to store the modified document.
if (FALSE !== $driver->store->put($key, $orig_doc->saveXML())) {
header("Location: ".$driver->config['BASE_URL'].'/outlines'.$key.";".$selector);
return;
} else {
return $driver->showErrorTextResponse(403, "Outline save failed.");
}
return;
}
?>