show404(); // Grab the format switch option from the URL parameters. $format = isset($_GET['format']) ? $_GET['format'] : ''; if ($driver->store->isCollection($key)) { // Fetch the resource collection list from the store. $items = $driver->store->listCollection($key); switch($format) { case 'json': echo $driver->echoJSON($items); return; default: $driver->tpl->assign('items', $items); $driver->tpl->display('collection_view.tpl.php'); return; } } elseif ($driver->store->isResource($key)) { // Attempt to fetch an existing document at this key. list($orig_doc, $orig_root_node) = fetchOutlineWithSelector($key, $selector); if (!$orig_doc) return $driver->show404(); $etag = buildEtagForOutlineNode($orig_doc, $orig_root_node); header("Etag: $etag"); if ($selector && (!$orig_root_node->getAttribute('xmlns') == $XHTML_NS) ) $orig_root_node->setAttribute('xmlns', $XHTML_NS); switch($format) { case 'raw': case 'xoxo': // Spit out the raw document source. // header("Content-Type: text/xml; charset=utf8"); header("Content-Type: application/xhtml+xml; charset=utf8"); echo $orig_doc->saveXML($orig_root_node); return; case 'json': header("Content-Type: application/javascript; charset=utf8"); $bf = new BadgerFish(); echo $bf->encode($orig_doc); return; case 'opml': header("Content-Type: text/x-opml; charset=utf8"); # HACK: Serializing to XML, just to be re-parsed in applyXSLT() sucks. echo $driver->applyXSLT('xoxo-to-opml.xsl', $orig_doc->saveXML($orig_root_node), array( "key" => $key, "selector" => $selector, "etag" => $etag )); return; case 'noop': /* */ echo $driver->applyXSLT('noop.xsl', $orig_doc, array( )); return; $xml = $orig_doc; // file_get_contents($xml_url); $xsl = file_get_contents('xsl/noop.xsl'); $xslt = new xsltProcessor; $xslt->importStyleSheet(DomDocument::loadXML($xsl)); foreach ($_GET as $param => $value) { $xslt->setParameter('', $param, $value); } $xslt_result = $xslt->transformToXML($xml); $result = $xslt_result; echo $result; return; default: // Default format includes a variety of UI modes. $mode = isset($_GET['mode']) ? $_GET['mode'] : ''; switch($mode) { case 'append': // TODO: Should this even be in xoxoio.php? $driver->tpl->assign('key', $key); $driver->tpl->assign('selector', $selector); $driver->tpl->display('append-item-form.tpl.php'); return; default: // Output the document instrumented with outliner // machinery via XSL. header("Content-Type: text/html; charset=utf8"); # HACK: Serializing to XML, just to be re-parsed in applyXSLT() sucks. echo $driver->applyXSLT('inject-outliner.xsl', $orig_doc->saveXML($orig_root_node), array( "key" => $key , "selector" => $selector, "etag" => $etag )); return; } } } else { // Report that this key was not found in the store. return $driver->show404(); } ?>