public function document_to_json($dtype, $docid) { global $Conf; if (!is_object($docid)) { $dresult = $Conf->document_result($this->paperid, $dtype, $docid); $drow = $Conf->document_row($dresult, $dtype); Dbl::free($dresult); } else { $drow = $docid; $docid = $drow ? $drow->paperStorageId : null; } $d = (object) array(); if ($docid && !$this->hide_docids) { $d->docid = $docid; } if ($drow) { if ($drow->mimetype) { $d->mimetype = $drow->mimetype; } if ($drow->sha1 !== null && $drow->sha1 !== "") { $d->sha1 = bin2hex($drow->sha1); } if ($drow->timestamp) { $d->timestamp = (int) $drow->timestamp; } if (get($drow, "filename")) { $d->filename = $drow->filename; } $meta = null; if (isset($drow->infoJson) && is_object($drow->infoJson)) { $meta = $drow->infoJson; } else { if (isset($drow->infoJson) && is_string($drow->infoJson)) { $meta = json_decode($drow->infoJson); } } if ($meta) { $d->metadata = $meta; } if ($this->export_content && $drow->docclass->load($drow)) { $d->content_base64 = base64_encode(Filer::content($drow)); } } foreach ($this->document_callbacks as $cb) { call_user_func($cb, $d, $this->prow, $dtype, $drow); } if (!count(get_object_vars($d))) { $d = null; } return $d; }
function parse_request($opt_pj, $qreq, Contact $user, $pj) { $attachments = $opt_pj ?: []; $opfx = "opt{$this->id}_"; foreach ($qreq->_FILES ?: [] as $k => $v) { if (str_starts_with($k, $opfx)) { $attachments[] = Filer::file_upload_json($v); } } for ($i = 0; $i < count($attachments); ++$i) { if (isset($attachments[$i]->docid) && $qreq["remove_opt{$this->id}_{$attachments[$i]->docid}"]) { array_splice($attachments, $i, 1); --$i; } } return empty($attachments) ? null : $attachments; }
<?php // test05.php -- HotCRP paper submission tests // HotCRP is Copyright (c) 2006-2016 Eddie Kohler and Regents of the UC // Distributed under an MIT-like license; see LICENSE global $ConfSitePATH; $ConfSitePATH = preg_replace(",/[^/]+/[^/]+\$,", "", __FILE__); require_once "{$ConfSitePATH}/test/setup.php"; $Conf->save_setting("sub_open", 1); $Conf->save_setting("sub_update", $Now + 100); $Conf->save_setting("sub_sub", $Now + 100); // load users $user_estrin = Contact::find_by_email("*****@*****.**"); // pc $user_nobody = new Contact(); $ps = new PaperStatus($user_estrin); $paper1a = $ps->paper_json(1); xassert_eqq($paper1a->title, "Scalable Timers for Soft State Protocols"); $ps->save_paper_json((object) ["id" => 1, "title" => "Scalable Timers? for Soft State Protocols"]); xassert(!$ps->nerrors); $paper1b = $ps->paper_json(1); xassert_eqq($paper1b->title, "Scalable Timers? for Soft State Protocols"); $paper1b->title = $paper1a->title; $paper1b->submitted_at = $paper1a->submitted_at; xassert_eqq(json_encode($paper1b), json_encode($paper1a)); $doc = Filer::file_upload_json(["error" => UPLOAD_ERR_OK, "name" => "amazing-sample.pdf", "tmp_name" => "{$ConfSitePATH}/src/sample.pdf", "tmp_name_safe" => true, "type" => "application/pdf"]); $ps->save_paper_json((object) ["id" => 1, "submission" => $doc]); xassert(!$ps->nerrors); $paper1c = $ps->paper_json(1); xassert_eqq($paper1c->submission->sha1, "2f1bccbf1e0e98004c01ef5b26eb9619f363e38e"); xassert_exit();
public function apply(Contact $user, $pj, $opj, $qreq, $action) { global $Conf; // Title, abstract, collaborators foreach (array("title", "abstract", "collaborators") as $k) { if (isset($qreq[$k])) { $pj->{$k} = $qreq[$k]; } } // Authors $bad_author = ["name" => "Name", "email" => "Email", "aff" => "Affiliation"]; $authors = array(); foreach ($qreq as $k => $v) { if (preg_match('/\\Aau(name|email|aff)(\\d+)\\z/', $k, $m) && ($v = simplify_whitespace($v)) !== "" && $v !== $bad_author[$m[1]]) { $au = $authors[$m[2]] = get($authors, $m[2]) ?: (object) array(); $x = $m[1] == "aff" ? "affiliation" : $m[1]; $au->{$x} = $v; } } if (!empty($authors)) { ksort($authors, SORT_NUMERIC); $pj->authors = array_values($authors); } // Contacts if ($qreq->setcontacts || $qreq->has_contacts) { PaperSaver::replace_contacts($pj, $qreq); } else { if (!$opj) { $pj->contacts = array($user); } } // Status if ($action === "submit") { $pj->submitted = true; } else { if ($action === "final") { $pj->final_submitted = true; } else { $pj->submitted = false; } } // Paper upload if ($qreq->_FILES->paperUpload) { if ($action === "final") { $pj->final = Filer::file_upload_json($qreq->_FILES->paperUpload); } else { if ($action === "update" || $action === "submit") { $pj->submission = Filer::file_upload_json($qreq->_FILES->paperUpload); } } } // Blindness if ($action !== "final" && $Conf->subBlindOptional()) { $pj->nonblind = !$qreq->blind; } // Topics if ($qreq->has_topics) { $pj->topics = (object) array(); foreach ($Conf->topic_map() as $tid => $tname) { if (+$qreq["top{$tid}"] > 0) { $pj->topics->{$tname} = true; } } } // Options if (!isset($pj->options)) { $pj->options = (object) []; } foreach (PaperOption::option_list() as $o) { if ($qreq["has_opt{$o->id}"] && (!$o->final || $action === "final")) { $okey = $o->abbr; $pj->options->{$okey} = $o->parse_request(get($pj->options, $okey), $qreq, $user, $pj); } } if (!count(get_object_vars($pj->options))) { unset($pj->options); } // PC conflicts if ($Conf->setting("sub_pcconf") && ($action !== "final" || $user->privChair) && $qreq->has_pcconf) { $cmax = $user->privChair ? CONFLICT_CHAIRMARK : CONFLICT_MAXAUTHORMARK; $pj->pc_conflicts = (object) array(); foreach (pcMembers() as $pcid => $pc) { $ctype = cvtint($qreq["pcc{$pcid}"], 0); $ctype = max(min($ctype, $cmax), 0); if ($ctype) { $email = $pc->email; $pj->pc_conflicts->{$email} = Conflict::$type_names[$ctype]; } } } }
public function download() { $result = $this->create(); if (is_string($result)) { set_time_limit(180); // large zip files might download slowly $this->download_headers(); Filer::download_file($result); $result = (object) array("error" => false); } $this->clean(); return $result; }
public function s3_store($doc, $docinfo, $trust_sha1 = false) { global $Opt; if (!isset($doc->content) && !$this->load_content($doc)) { return false; } if (!$trust_sha1 && Filer::binary_sha1($doc) !== sha1($doc->content, true)) { error_log("S3 upload cancelled: data claims checksum " . Filer::text_sha1($doc) . ", has checksum " . sha1($doc->content)); return false; } $s3 = self::s3_document(); $dtype = isset($doc->documentType) ? $doc->documentType : $this->dtype; $meta = array("conf" => $Opt["dbName"], "pid" => (int) $docinfo->paperId, "dtype" => (int) $dtype); if (get($doc, "filter")) { $meta["filtertype"] = (int) $doc->filter; if (get($doc, "original_sha1")) { $meta["original_sha1"] = $doc->original_sha1; } } $filename = self::s3_filename($doc); $s3->save($filename, $doc->content, $doc->mimetype, array("hotcrp" => json_encode($meta))); if ($s3->status != 200) { error_log("S3 error: POST {$filename}: {$s3->status} {$s3->status_text} " . json_encode($s3->response_headers)); } return $s3->status == 200; }
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); }