public static function filename($doc) { global $Opt; $fn = $Opt["downloadPrefix"]; if ($doc->documentType == DTYPE_SUBMISSION) { $fn .= "paper" . $doc->paperId; } else { if ($doc->documentType == DTYPE_FINAL) { $fn .= "final" . $doc->paperId; } else { $o = PaperOption::find($doc->documentType); if ($o && $o->type == "attachments" && ($afn = get($doc, "unique_filename") ?: $doc->filename)) { // do not decorate with MIME type suffix return $fn . "paper" . $doc->paperId . "-" . $o->abbr . "/" . $afn; } else { if ($o && $o->is_document()) { $fn .= "paper" . $doc->paperId . "-" . $o->abbr; } else { $fn .= "paper" . $doc->paperId . "-unknown"; } } } } return $fn . Mimetype::extension($doc->mimetype); }
function list_actions(Contact $user, $qreq, PaperList $pl, &$actions) { $xactions = SearchAction::list_subactions("get", $user, $qreq, $pl); foreach (PaperOption::option_ids() as $oid) { if ($pl->any["opt{$oid}"] && ($o = PaperOption::find($oid)) && $o->is_document()) { $xactions[] = GetDocument_SearchAction::make_option_action($o); } } usort($xactions, function ($a, $b) { return $a[0] - $b[0]; }); $sel_opt = array(); $last_group = null; foreach ($xactions as $xact) { if ($xact[2] !== $last_group) { $sel_opt[] = ["optgroup", $xact[2]]; $last_group = $xact[2]; } $sel_opt[] = ["value" => $xact[1], "label" => $xact[3]]; } if (!empty($sel_opt)) { $actions[] = [0, "get", "Download", "<b>:</b> " . Ht::select("getfn", $sel_opt, $qreq->getfn, ["tabindex" => 6, "class" => "wantcrpfocus", "style" => "max-width:10em"]) . " " . Ht::submit("fn", "Go", ["value" => "get", "tabindex" => 6, "onclick" => "return plist_submit.call(this)", "data-plist-submit-all" => 1])]; } }
static function parse_paper_options(PaperInfo $prow, $all) { $optionIds = get($prow, "optionIds"); if ($optionIds === "") { return []; } $optsel = array(); if ($optionIds !== null) { preg_match_all('/(\\d+)#(\\d+)/', $optionIds, $m); for ($i = 0; $i < count($m[1]); ++$i) { arrayappend($optsel[$m[1][$i]], (int) $m[2][$i]); } $optdata = null; } else { $optdata = self::load_optdata($prow->paperId); foreach ($optdata as $k => $v) { $dot = strpos($k, "."); arrayappend($optsel[substr($k, 0, $dot)], (int) substr($k, $dot + 1)); } } $option_array = array(); foreach ($optsel as $oid => $ovalues) { $o = PaperOption::find($oid); if (!$o && !$all) { continue; } $needs_data = !$o || $o->needs_data(); if ($needs_data && !$optdata) { $optdata = self::load_optdata($prow->paperId); } $odata = []; if ($needs_data) { foreach ($ovalues as $v) { $odata[] = $optdata[$oid . "." . $v]; } } $option_array[$oid] = new PaperOptionValue($oid, $o, $ovalues, $odata); } uasort($option_array, function ($a, $b) { if ($a->option && $b->option) { return PaperOption::compare($a->option, $b->option); } else { if ($a->option || $b->option) { return $a->option ? -1 : 1; } else { return $a->id - $b->id; } } }); return $option_array; }
function perm_view_paper_option(PaperInfo $prow, $opt, $forceShow = null) { global $Conf; if ($this->can_view_paper_option($prow, $opt, $forceShow)) { return null; } if (is_object($opt) && ($opt = PaperOption::find($opt)) && ($whyNot = $this->perm_view_paper($prow, $opt->has_document()))) { return $whyNot; } return array_merge($prow->initial_whynot(), ["permission" => 1]); }
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); }