public static function s3_filename($doc)
 {
     if (($sha1 = Filer::text_sha1($doc)) !== false) {
         return "doc/" . substr($sha1, 0, 2) . "/" . $sha1 . Mimetype::extension($doc->mimetype);
     } else {
         return null;
     }
 }
Example #2
0
 private function _filestore($doc)
 {
     if (!($fsinfo = $this->filestore_pattern($doc)) || get($doc, "error")) {
         return $fsinfo;
     }
     list($fdir, $fpath) = $fsinfo;
     $sha1 = false;
     $xfpath = $fdir;
     $fpath = substr($fpath, strlen($fdir));
     while (preg_match("/\\A(.*?)%(\\d*)([%hx])(.*)\\z/", $fpath, $m)) {
         $fpath = $m[4];
         $xfpath .= $m[1];
         if ($m[3] === "%") {
             $xfpath .= "%";
         } else {
             if ($m[3] === "x") {
                 $xfpath .= Mimetype::extension(self::_mimetype($doc));
             } else {
                 if ($sha1 === false) {
                     $sha1 = self::text_sha1($doc);
                 }
                 if ($sha1 === false && ($content = self::content($doc)) !== false) {
                     $sha1 = $doc->sha1 = sha1($content);
                 }
                 if ($sha1 === false) {
                     return array(null, null);
                 }
                 if ($m[2] !== "") {
                     $xfpath .= substr($sha1, 0, +$m[2]);
                 } else {
                     $xfpath .= $sha1;
                 }
             }
         }
     }
     if ($fdir && $fdir[strlen($fdir) - 1] === "/") {
         $fdir = substr($fdir, 0, strlen($fdir) - 1);
     }
     return array($fdir, $xfpath . $fpath);
 }
Example #3
0
 function downloadPaperName($paperId, $mimetype, $documentType)
 {
     global $Opt;
     $title = $Opt["downloadPrefix"];
     $dtn = HotCRPDocument::unparse_dtype($documentType);
     $title .= $dtn ? $dtn : "xxx";
     if (ctype_digit($title[strlen($title) - 1])) {
         $title .= "-";
     }
     return $title . $paperId . Mimetype::extension($mimetype);
 }