Skip to content

Commit

Permalink
Braces.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Oct 29, 2019
1 parent c1b4abd commit 634ba01
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions doc.php
Expand Up @@ -27,10 +27,12 @@ function document_error($status, $msg) {


function document_history_element(DocumentInfo $doc) { function document_history_element(DocumentInfo $doc) {
$pj = ["hash" => $doc->text_hash(), "at" => $doc->timestamp, "mimetype" => $doc->mimetype]; $pj = ["hash" => $doc->text_hash(), "at" => $doc->timestamp, "mimetype" => $doc->mimetype];
if ($doc->size) if ($doc->size) {
$pj["size"] = $doc->size; $pj["size"] = $doc->size;
if ($doc->filename) }
if ($doc->filename) {
$pj["filename"] = $doc->filename; $pj["filename"] = $doc->filename;
}
return (object) $pj; return (object) $pj;
} }


Expand Down Expand Up @@ -74,59 +76,69 @@ function document_download($qreq) {
$want_docid = $request_docid = (int) $dr->docid; $want_docid = $request_docid = (int) $dr->docid;


// history // history
if ($qreq->fn === "history") if ($qreq->fn === "history") {
json_exit(["ok" => true, "result" => document_history($prow, $dr->dtype)]); json_exit(["ok" => true, "result" => document_history($prow, $dr->dtype)]);
}


if (!isset($qreq->version) && isset($qreq->hash)) if (!isset($qreq->version) && isset($qreq->hash)) {
$qreq->version = $qreq->hash; $qreq->version = $qreq->hash;
}


// time // time
if (isset($qreq->at) && !isset($qreq->version) && $dr->dtype >= DTYPE_FINAL) { if (isset($qreq->at) && !isset($qreq->version) && $dr->dtype >= DTYPE_FINAL) {
if (ctype_digit($qreq->at)) if (ctype_digit($qreq->at)) {
$time = intval($qreq->at); $time = intval($qreq->at);
else if (!($time = $Conf->parse_time($qreq->at))) } else if (!($time = $Conf->parse_time($qreq->at))) {
$time = $Now; $time = $Now;
}
$want_pj = null; $want_pj = null;
foreach (document_history($prow, $dr->dtype) as $pj) { foreach (document_history($prow, $dr->dtype) as $pj) {
if ($want_pj && $want_pj->at <= $time && $pj->at < $want_pj->at) if ($want_pj && $want_pj->at <= $time && $pj->at < $want_pj->at) {
break; break;
else } else {
$want_pj = $pj; $want_pj = $pj;
}
} }
if ($want_pj) if ($want_pj) {
$qreq->version = $want_pj->hash; $qreq->version = $want_pj->hash;
}
} }


// version // version
if (isset($qreq->version) && $dr->dtype >= DTYPE_FINAL) { if (isset($qreq->version) && $dr->dtype >= DTYPE_FINAL) {
$version_hash = Filer::hash_as_binary(trim($qreq->version)); $version_hash = Filer::hash_as_binary(trim($qreq->version));
if (!$version_hash) if (!$version_hash) {
document_error("404 Not Found", "No such version."); document_error("404 Not Found", "No such version.");
}
$want_docid = $Conf->fetch_ivalue("select max(paperStorageId) from PaperStorage where paperId=? and documentType=? and sha1=? and filterType is null", $dr->paperId, $dr->dtype, $version_hash); $want_docid = $Conf->fetch_ivalue("select max(paperStorageId) from PaperStorage where paperId=? and documentType=? and sha1=? and filterType is null", $dr->paperId, $dr->dtype, $version_hash);
if ($want_docid !== null && $Me->can_view_document_history($prow)) if ($want_docid !== null && $Me->can_view_document_history($prow)) {
$request_docid = $want_docid; $request_docid = $want_docid;
}
} }


if ($dr->attachment && !$request_docid) if ($dr->attachment && !$request_docid) {
$doc = $prow->attachment($dr->dtype, $dr->attachment); $doc = $prow->attachment($dr->dtype, $dr->attachment);
else } else {
$doc = $prow->document($dr->dtype, $request_docid); $doc = $prow->document($dr->dtype, $request_docid);
if ($want_docid !== 0 && (!$doc || $doc->paperStorageId != $want_docid)) }
if ($want_docid !== 0 && (!$doc || $doc->paperStorageId != $want_docid)) {
document_error("404 Not Found", "No such version."); document_error("404 Not Found", "No such version.");
else if (!$doc) } else if (!$doc) {
document_error("404 Not Found", "No such " . ($dr->attachment ? "attachment" : "document") . "" . htmlspecialchars($dr->req_filename) . "”."); document_error("404 Not Found", "No such " . ($dr->attachment ? "attachment" : "document") . "" . htmlspecialchars($dr->req_filename) . "”.");
}


// pass through filters // pass through filters
foreach ($dr->filters as $filter) foreach ($dr->filters as $filter) {
$doc = $filter->apply($doc, $prow) ? : $doc; $doc = $filter->apply($doc, $prow) ? : $doc;
}


// check for contents request // check for contents request
if ($qreq->fn === "listing" || $qreq->fn === "consolidatedlisting") { if ($qreq->fn === "listing" || $qreq->fn === "consolidatedlisting") {
if (!$doc->is_archive()) if (!$doc->is_archive()) {
json_exit(["ok" => false, "error" => "That file is not an archive."]); json_exit(["ok" => false, "error" => "That file is not an archive."]);
else if (($listing = $doc->archive_listing(65536)) === false) } else if (($listing = $doc->archive_listing(65536)) === false) {
json_exit(["ok" => false, "error" => $doc->error ? $doc->error_html : "Internal error."]); json_exit(["ok" => false, "error" => $doc->error ? $doc->error_html : "Internal error."]);
else { } else {
$listing = ArchiveInfo::clean_archive_listing($listing); $listing = ArchiveInfo::clean_archive_listing($listing);
if ($qreq->fn === "consolidatedlisting") if ($qreq->fn === "consolidatedlisting")
$listing = join(", ", ArchiveInfo::consolidate_archive_listing($listing)); $listing = join(", ", ArchiveInfo::consolidate_archive_listing($listing));
Expand Down

0 comments on commit 634ba01

Please sign in to comment.