public function document_callback($dj, $prow, $dtype, $drow) { if ($drow->docclass->load($drow)) { $dj->content_file = HotCRPDocument::filename($drow); $this->zipdoc->add_as($drow, $dj->content_file); } }
function _contentDownload($row) { global $Conf; if ($row->finalPaperStorageId != 0) { $finalsuffix = "f"; $finaltitle = "Final version"; $row->documentType = DTYPE_FINAL; } else { $finalsuffix = ""; $finaltitle = null; $row->documentType = DTYPE_SUBMISSION; } if ($row->size == 0 || !$this->contact->can_view_pdf($row)) { return ""; } if ($row->documentType == DTYPE_FINAL) { $this->any->final = true; } $this->any->paper = true; $t = " <a href=\"" . HotCRPDocument::url($row) . "\">"; if ($row->mimetype == "application/pdf") { return $t . Ht::img("pdf{$finalsuffix}.png", "[PDF]", array("title" => $finaltitle)) . "</a>"; } else { if ($row->mimetype == "application/postscript") { return $t . Ht::img("postscript{$finalsuffix}.png", "[PS]", array("title" => $finaltitle)) . "</a>"; } else { return $t . Ht::img("generic{$finalsuffix}.png", "[Download]", array("title" => $finaltitle)) . "</a>"; } } }
function documentDownload($doc, $dlimg_class = "dlimg", $text = null, $no_size = false) { global $Conf; $p = HotCRPDocument::url($doc); $finalsuffix = $doc->documentType == DTYPE_FINAL ? "f" : ""; $sp = " "; $imgsize = $dlimg_class[0] == "s" ? "" : "24"; if ($doc->mimetype == "application/postscript") { $x = "<a href=\"{$p}\" class=\"q\">" . Ht::img("postscript{$finalsuffix}{$imgsize}.png", "[PS]", $dlimg_class); } else { if ($doc->mimetype == "application/pdf") { $x = "<a href=\"{$p}\" class=\"q\">" . Ht::img("pdf{$finalsuffix}{$imgsize}.png", "[PDF]", $dlimg_class); } else { $x = "<a href=\"{$p}\" class=\"q\">" . Ht::img("generic{$finalsuffix}{$imgsize}.png", "[Download]", $dlimg_class); } } if ($text) { $x .= $sp . $text; } if (isset($doc->size) && $doc->size > 0 && !$no_size) { $x .= " <span class=\"dlsize\">" . ($text ? "(" : ""); if ($doc->size > 921) { $x .= round($doc->size / 1024); } else { $x .= max(round($doc->size / 102.4), 1) / 10; } $x .= "kB" . ($text ? ")" : "") . "</span>"; } return $x . "</a>"; }
function document_download() { global $Conf, $Me, $Opt; $documentType = HotCRPDocument::parse_dtype(@$_REQUEST["dt"]); if ($documentType === null) { $documentType = @$_REQUEST["final"] ? DTYPE_FINAL : DTYPE_SUBMISSION; } $attachment_filename = false; $docid = null; if (isset($_REQUEST["p"])) { $paperId = cvtint(@$_REQUEST["p"]); } else { if (isset($_REQUEST["paperId"])) { $paperId = cvtint(@$_REQUEST["paperId"]); } else { $s = $orig_s = preg_replace(',\\A/*,', "", Navigation::path()); $documentType = $dtname = null; if (str_starts_with($s, $Opt["downloadPrefix"])) { $s = substr($s, strlen($Opt["downloadPrefix"])); } if (preg_match(',\\Ap(?:aper)?(\\d+)/+(.*)\\z,', $s, $m)) { $paperId = intval($m[1]); if (preg_match(',\\A([^/]+)\\.[^/]+\\z,', $m[2], $mm)) { $dtname = $mm[1]; } else { if (preg_match(',\\A([^/]+)/+(.*)\\z,', $m[2], $mm)) { list($dtype, $attachment_filename) = array($m[1], $m[2]); } } } else { if (preg_match(',\\A(?:paper)?(\\d+)-?([-A-Za-z0-9_]*)(?:\\.[^/]+|/+(.*))\\z,', $s, $m)) { list($paperId, $dtname, $attachment_filename) = array(intval($m[1]), $m[2], @$m[3]); } else { if (preg_match(',\\A([A-Za-z_][-A-Za-z0-9_]*?)?-?(\\d+)(?:\\.[^/]+|/+(.*))\\z,', $s, $m)) { list($paperId, $dtname, $attachment_filename) = array(intval($m[2]), $m[1], @$m[3]); } } } if ($dtname !== null) { $documentType = HotCRPDocument::parse_dtype($dtname ?: "paper"); } if ($documentType !== null && $attachment_filename) { $o = PaperOption::find($documentType); if (!$o || $o->type != "attachments") { $documentType = null; } } } } if ($documentType === null) { document_error("404 Not Found", "Unknown document “" . htmlspecialchars($orig_s) . "”."); } $prow = $Conf->paperRow($paperId, $Me, $whyNot); if (!$prow) { document_error("404 Not Found", whyNotText($whyNot, "view")); } else { if ($whyNot = $Me->perm_view_pdf($prow)) { document_error("403 Forbidden", whyNotText($whyNot, "view")); } else { if ($documentType > 0 && !$Me->can_view_paper_option($prow, $documentType, true)) { document_error("403 Forbidden", "You don’t have permission to view this document."); } } } if ($attachment_filename) { $oa = $prow->option($documentType); foreach ($oa ? $oa->documents($prow) : array() as $doc) { if ($doc->unique_filename == $attachment_filename) { $docid = $doc; } } if (!$docid) { document_error("404 Not Found", "No such attachment “" . htmlspecialchars($orig_s) . "”."); } } // Actually download paper. session_write_close(); // to allow concurrent clicks if ($Conf->downloadPaper($prow, cvtint(@$_REQUEST["save"]) > 0, $documentType, $docid)) { exit; } document_error("500 Server Error", null); }
public function upload_document($docj, PaperOption $o) { global $Conf; // look for an existing document with same sha1; // check existing docid's sha1 $docid = get($docj, "docid"); if ($docid) { $oldj = $this->document_to_json($o->id, $docid); if (get($docj, "sha1") && get($oldj, "sha1") !== $docj->sha1) { $docid = null; } } else { if (!$docid && $this->paperid > 0 && get($docj, "sha1")) { $result = Dbl::qe("select paperStorageId from PaperStorage where paperId=? and documentType=? and sha1=?", $this->paperid, $o->id, $docj->sha1); if ($row = edb_row($result)) { $docid = $row[0]; } } } if ($docid) { $docj->docid = $docid; return; } // check filter if (get($docj, "filter") && is_int($docj->filter)) { if (is_int(get($docj, "original_id"))) { $result = Dbl::qe("select paperStorageId, timestamp, sha1 from PaperStorage where paperStorageId=?", $docj->original_id); } else { if (is_string(get($docj, "original_sha1"))) { $result = Dbl::qe("select paperStorageId, timestamp, sha1 from PaperStorage where paperId=? and sha1=?", $this->paperid, $docj->original_sha1); } else { if ($o->id == DTYPE_SUBMISSION || $o->id == DTYPE_FINAL) { $result = Dbl::qe("select PaperStorage.paperStorageId, PaperStorage.timestamp, PaperStorage.sha1 from PaperStorage join Paper on (Paper.paperId=PaperStorage.paperId and Paper." . ($o->id == DTYPE_SUBMISSION ? "paperStorageId" : "finalPaperStorageId") . "=PaperStorage.paperStorageId) where Paper.paperId=?", $this->paperid); } else { $result = null; } } } if ($row = edb_orow($result)) { $docj->original_id = (int) $row->paperStorageId; $docj->original_timestamp = (int) $row->timestamp; $docj->original_sha1 = $row->sha1; if (get($docj, "preserve_timestamp")) { $docj->timestamp = (int) $docj->original_timestamp; } } else { unset($docj->original_id); } } // if no sha1 match, upload $docclass = new HotCRPDocument($o->id); $upload = null; if ($docclass->load($docj)) { $upload = $docclass->upload($docj, (object) array("paperId" => $this->paperid)); } if ($upload && get($upload, "paperStorageId") > 1) { foreach (array("size", "sha1", "mimetype", "timestamp") as $k) { $docj->{$k} = $upload->{$k}; } $this->uploaded_documents[] = $docj->docid = $upload->paperStorageId; } else { $docj->docid = 1; $this->set_option_error_html($o, $upload ? $upload->error_html : "empty document"); } }
<?php $ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__); require_once "{$ConfSitePATH}/src/init.php"; $arg = getopt("hfn:", array("help", "force", "name:")); if (isset($arg["h"]) || isset($arg["help"])) { fwrite(STDOUT, "Usage: php batch/killinactivedoc.php [--force]\n"); exit(0); } $storageIds = $Conf->active_document_ids(); $force = isset($arg["f"]) || isset($arg["force"]); $result = $Conf->qe("select paperStorageId, paperId, timestamp, mimetype,\n compression, sha1, documentType, filename, infoJson\n from PaperStorage where paperStorageId not in (" . join(",", $storageIds) . ")\n and paper is not null and paperStorageId>1 order by timestamp"); $killable = array(); while ($doc = $Conf->document_row($result, null)) { $killable[$doc->paperStorageId] = "[" . $Conf->unparse_time_log($doc->timestamp) . "] " . HotCRPDocument::filename($doc) . " ({$doc->paperStorageId})"; } if (count($killable)) { fwrite(STDOUT, join("\n", $killable) . "\n"); if (!$force) { fwrite(STDOUT, "\nKill " . plural($killable, "document") . "? (y/n) "); $x = fread(STDIN, 100); if (!preg_match('/\\A[yY]/', $x)) { die("* Exiting\n"); } } $Conf->qe("update PaperStorage set paper=NULL where paperStorageId in (" . join(",", array_keys($killable)) . ")"); fwrite(STDOUT, count($killable) . " documents killed.\n"); } else { fwrite(STDOUT, "Nothing to do\n"); }
loadRows(); } if (isset($_REQUEST["setfollow"]) && $prow && check_post()) { PaperActions::set_follow($prow); loadRows(); } if ($prow && isset($_GET["m"]) && $_GET["m"] === "api" && isset($_GET["fn"]) && isset(SiteLoader::$api_map[$_GET["fn"]])) { $Qreq = make_qreq(); SiteLoader::call_api($Qreq->fn, $Me, $Qreq, $prow); json_exit(["ok" => false, "error" => "Internal error."]); } // check paper action if (isset($_REQUEST["checkformat"]) && $prow && $Conf->setting("sub_banal")) { $ajax = defval($_REQUEST, "ajax", 0); $cf = new CheckFormat(); $dt = HotCRPDocument::parse_dtype(@$_REQUEST["dt"]); if ($dt === null) { $dt = @$_REQUEST["final"] ? DTYPE_FINAL : DTYPE_SUBMISSION; } if ($Conf->setting("sub_banal{$dt}")) { $format = $Conf->setting_data("sub_banal{$dt}", ""); } else { $format = $Conf->setting_data("sub_banal", ""); } $status = $cf->analyzePaper($prow->paperId, $dt, $format); // chairs get a hint message about multiple checking if ($Me->privChair) { $nbanal = $Conf->session("nbanal", 0) + 1; $Conf->save_session("nbanal", $nbanal); if ($nbanal >= 3 && $nbanal <= 6) { $cf->msg("info", "To run the format checker for many papers, use Download > Format check on the <a href='" . hoturl("search", "q=") . "'>search page</a>.");
<?php $ConfSitePATH = preg_replace(',/batch/[^/]+,', '', __FILE__); require_once "{$ConfSitePATH}/src/init.php"; $arg = getopt("hn:", array("help", "name:")); if (isset($arg["h"]) || isset($arg["help"])) { fwrite(STDOUT, "Usage: php batch/s3check.php\n"); exit(0); } if (!$Conf->setting_data("s3_bucket")) { fwrite(STDERR, "* S3 is not configured for this conference\n"); exit(1); } $s3doc = HotCRPDocument::s3_document(); $args = array("marker" => null, "max-keys" => 100); $xml = null; $xmlpos = 0; while (1) { if ($xml === null || $xmlpos >= count($xml->Contents)) { $content = $s3doc->ls("doc/", $args); $xml = new SimpleXMLElement($content); $xmlpos = 0; } if (!isset($xml->Contents) || $xmlpos >= count($xml->Contents)) { break; } $node = $xml->Contents[$xmlpos]; $args["marker"] = $node->Key; if (preg_match(',/([0-9a-f]{40})(?:[.][^/]*|)\\z,', $node->Key, $m)) { echo "{$node->Key}: "; $content = $s3doc->load($node->Key);
$doc = $Conf->document_row($result, null); if ($doc->paper_null && !$doc->docclass->filestore_check($doc)) { continue; } $saved = $checked = $doc->docclass->s3_check($doc); if (!$saved) { $saved = $doc->docclass->s3_store($doc, $doc); } if (!$saved) { sleep(0.5); $saved = $doc->docclass->s3_store($doc, $doc); } $front = "[" . $Conf->unparse_time_log($doc->timestamp) . "] " . HotCRPDocument::filename($doc) . " ({$sid})"; if ($checked) { fwrite(STDOUT, "{$front}: " . HotCRPDocument::s3_filename($doc) . " exists\n"); } else { if ($saved) { fwrite(STDOUT, "{$front}: " . HotCRPDocument::s3_filename($doc) . " saved\n"); } else { fwrite(STDOUT, "{$front}: SAVE FAILED\n"); ++$failures; } } if ($saved && $kill) { $Conf->qe("update PaperStorage set paper=null where paperStorageId={$sid}"); } } if ($failures) { fwrite(STDERR, "Failed to save " . plural($failures, "document") . ".\n"); exit(1); }
} $s3doc = HotCRPDocument::s3_document(); $ok = 0; foreach ($arg["_"] as $fn) { if ($fn === "-") { $content = @stream_get_contents(STDIN); } else { $content = @file_get_contents($fn); } if ($content === false) { $error = error_get_last(); $fn = $fn === "-" ? "<stdin>" : $fn; if (!$quiet) { echo "{$fn}: " . $error["message"] . "\n"; } $ok = 2; } else { $doc = (object) array("sha1" => sha1($content, true)); if (!($extensions && preg_match('/(\\.\\w+)\\z/', $fn, $m) && ($doc->mimetype = Mimetype::lookup_extension($m[1])))) { $doc->mimetype = Mimetype::sniff($content); } $s3fn = HotCRPDocument::s3_filename($doc); if (!$s3doc->check($s3fn)) { if (!$quiet) { echo "{$fn}: {$s3fn} not found\n"; } $ok = 1; } } } exit($ok);
public function filestore_pattern($doc) { global $Opt, $ConfSitePATH; if ($this->no_filestore) { return false; } if (self::$_docstore === null) { $fdir = opt("docstore"); if (!$fdir) { return self::$_docstore = false; } $fpath = $fdir; $use_subdir = defval($Opt, "docstoreSubdir", false); if ($use_subdir && ($use_subdir === true || $use_subdir > 0)) { $fpath .= "/%" . ($use_subdir === true ? 2 : $use_subdir) . "h"; } $fpath .= "/%h%x"; self::$_docstore = array($fdir, $fpath); } return self::$_docstore; }
private function __downloadPaper($paperId, $attachment, $documentType, $docid) { global $Opt, $Me; if (is_object($docid)) { $docs = array($docid); } else { $result = $this->document_result($paperId, $documentType, $docid); if (!$result) { $this->log("Download error: " . $this->dblink->error, $Me, $paperId); return set_error_html("Database error while downloading paper."); } else { if (edb_nrows($result) == 0) { return set_error_html("No such document."); } } // Check data $docs = array(); while ($doc = $this->document_row($result, $documentType)) { if (!$doc->mimetype) { $doc->mimetype = Mimetype::PDF; } $doc->filename = HotCRPDocument::filename($doc); $docs[] = $doc; } Dbl::free($result); } if (count($docs) == 1 && $docs[0]->paperStorageId <= 1) { return set_error_html("Paper #" . $docs[0]->paperId . " hasn’t been uploaded yet."); } $downloadname = false; if (count($docs) > 1) { $name = HotCRPDocument::unparse_dtype($documentType); if ($documentType <= 0) { $name = pluralize($name); } $downloadname = $Opt["downloadPrefix"] . "{$name}.zip"; } return Filer::multidownload($docs, $downloadname, $attachment); }
if (isset($arg["h"]) || isset($arg["help"]) || !is_numeric($arg["d"]) || !is_numeric($arg["p"]) || count($arg["_"]) > 1 || count($arg["_"]) && $arg["_"][0] !== "-" && $arg["_"][0][0] === "-") { $status = isset($arg["h"]) || isset($arg["help"]) ? 0 : 1; fwrite($status ? STDERR : STDOUT, "Usage: php batch/adddoc.php [-n CONFID] [-p PID] [-m MIMETYPE] [-d DTYPE] [--no-file-storage] FILE\n"); exit($status); } $file = count($arg["_"]) ? $arg["_"][0] : "-"; if ($file === "-") { $content = stream_get_contents(STDIN); } else { $content = file_get_contents($file); } if ($content === false) { fwrite(STDERR, "{$file}: Read error\n"); exit(1); } $docclass = new HotCRPDocument((int) $arg["d"]); $docclass->set_no_database_storage(); if (isset($arg["no-file-storage"])) { $docclass->set_no_file_storage(); } $docinfo = (object) array("paperId" => (int) $arg["p"]); $doc = (object) array("content" => $content, "documentType" => (int) $arg["d"]); if (@$arg["f"]) { $doc->filename = $arg["f"]; } if (@$arg["m"]) { $doc->mimetype = $arg["m"]; } else { if ($m = Mimetype::sniff($doc->content)) { $doc->mimetype = $m; } else {
function makeDownloadPath($doc) { global $ConfSiteBase, $ConfSiteSuffix; if (!property_exists($doc, "mimetype") || !isset($doc->documentType)) { $trace = debug_backtrace(); error_log($trace[0]["file"] . ":" . $trace[0]["line"] . ": makeDownloadPath called with incomplete document"); } if ($doc->mimetype) { return $ConfSiteBase . "doc{$ConfSiteSuffix}/" . HotCRPDocument::filename($doc); } else { $x = $ConfSiteBase . "doc{$ConfSiteSuffix}?p=" . $doc->paperId; if ($doc->documentType == DTYPE_FINAL) { return $x . "&final=1"; } else { if ($doc->documentType > 0) { return $x . "&dt={$doc->documentType}"; } else { return $x; } } } }