Пример #1
0
 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);
 }
Пример #2
0
 function upload($doc, $docinfo)
 {
     global $Conf;
     if (is_object($doc)) {
         $doc = clone $doc;
         if (!$this->load($doc) && !get($doc, "error_html")) {
             set_error_html($doc, "The uploaded file was empty.");
         }
     } else {
         $doc = self::file_upload_json($doc);
     }
     if (get($doc, "error")) {
         return $doc;
     }
     // Check if paper one of the allowed mimetypes.
     if (!get($doc, "mimetype")) {
         $doc->mimetype = "application/octet-stream";
     }
     // Sniff content since MacOS browsers supply bad mimetypes.
     if ($m = Mimetype::sniff(self::content($doc))) {
         $doc->mimetype = $m;
     }
     if ($m = Mimetype::lookup($doc->mimetype)) {
         $doc->mimetypeid = $m->mimetypeid;
     }
     $mimetypes = $this->mimetypes($doc, $docinfo);
     for ($i = 0; $i < count($mimetypes); ++$i) {
         if ($mimetypes[$i]->mimetype === $doc->mimetype) {
             break;
         }
     }
     if ($i >= count($mimetypes) && count($mimetypes)) {
         $e = "I only accept " . htmlspecialchars(Mimetype::description($mimetypes)) . " files.";
         $e .= " (Your file has MIME type “" . htmlspecialchars($doc->mimetype) . "” and starts with “" . htmlspecialchars(substr($doc->content, 0, 5)) . "”.)<br />Please convert your file to a supported type and try again.";
         return set_error_html($doc, $e);
     }
     if (!get($doc, "timestamp")) {
         $doc->timestamp = time();
     }
     $this->store($doc, $docinfo);
     return $doc;
 }
Пример #3
0
 private function __downloadPaper($paperId, $attachment, $documentType, $docid)
 {
     global $Opt, $Me, $zlib_output_compression;
     $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 = MIMETYPEID_PDF;
         }
         $doc->filename = HotCRPDocument::filename($doc);
         $docs[] = $doc;
     }
     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) {
         $downloadname = $Opt["downloadPrefix"] . pluralx(2, HotCRPDocument::unparse_dtype($documentType)) . ".zip";
     }
     return DocumentHelper::download($docs, $downloadname, $attachment);
 }