Esempio n. 1
0
 static function multidownload($doc, $downloadname = null, $attachment = null)
 {
     global $zlib_output_compression;
     if (is_array($doc) && count($doc) == 1) {
         $doc = $doc[0];
         $downloadname = null;
     }
     if (!$doc || is_object($doc) && isset($doc->size) && $doc->size == 0) {
         return set_error_html("Empty file.");
     }
     if (is_array($doc)) {
         $z = new ZipDocument($downloadname);
         foreach ($doc as $d) {
             $z->add($d);
         }
         return $z->download();
     }
     if (!self::has_content($doc) && (!get($doc, "docclass") || !$doc->docclass->load($doc))) {
         $error_html = "Don’t know how to download.";
         if (get($doc, "error") && isset($doc->error_html)) {
             $error_html = $doc->error_html;
         } else {
             if (get($doc, "error") && isset($doc->error_text)) {
                 $error_html = htmlspecialchars($doc->error_text);
             }
         }
         return set_error_html($error_html);
     }
     // Print paper
     $doc_mimetype = self::_mimetype($doc);
     header("Content-Type: " . Mimetype::type($doc_mimetype));
     if ($attachment === null) {
         $attachment = !Mimetype::disposition_inline($doc_mimetype);
     }
     if (!$downloadname) {
         $downloadname = $doc->filename;
         if (($slash = strrpos($downloadname, "/")) !== false) {
             $downloadname = substr($downloadname, $slash + 1);
         }
     }
     header("Content-Disposition: " . ($attachment ? "attachment" : "inline") . "; filename=" . mime_quote_string($downloadname));
     // reduce likelihood of XSS attacks in IE
     header("X-Content-Type-Options: nosniff");
     if ($filename = self::content_filename($doc)) {
         self::download_file($filename, get($doc, "no_cache") || get($doc, "no_accel"));
     } else {
         $content = self::content($doc);
         if (!$zlib_output_compression) {
             header("Content-Length: " . strlen($content));
         }
         echo $content;
     }
     return (object) array("error" => false);
 }
 protected function finish($ssel, $texts, $errors)
 {
     global $Conf, $Opt;
     $texts = $ssel->reorder($texts);
     if (empty($texts)) {
         if (empty($errors)) {
             Conf::msg_error("No papers selected.");
         } else {
             Conf::msg_error(join("<br />\n", array_keys($errors)) . "<br />\nNothing to download.");
         }
         return;
     }
     $warnings = array();
     $nerrors = 0;
     foreach ($errors as $ee => $iserror) {
         $warnings[] = whyNotHtmlToText($ee);
         if ($iserror) {
             $nerrors++;
         }
     }
     if ($nerrors) {
         array_unshift($warnings, "Some " . ($this->isform ? "review forms" : "reviews") . " are missing:");
     }
     if ($this->isform && (count($texts) == 1 || $this->iszip)) {
         $rfname = "review";
     } else {
         $rfname = "reviews";
     }
     if (count($texts) == 1 && !$this->iszip) {
         $rfname .= key($texts);
     }
     if ($this->isform) {
         $header = ReviewForm::textFormHeader(count($texts) > 1 && !$this->iszip);
     } else {
         $header = "";
     }
     if (!$this->iszip) {
         $text = $header;
         if (!empty($warnings) && $this->isform) {
             foreach ($warnings as $w) {
                 $text .= prefix_word_wrap("==-== ", whyNotHtmlToText($w), "==-== ");
             }
             $text .= "\n";
         } else {
             if (!empty($warnings)) {
                 $text .= join("\n", $warnings) . "\n\n";
             }
         }
         $text .= join("", $texts);
         downloadText($text, $rfname);
     } else {
         $zip = new ZipDocument($Opt["downloadPrefix"] . "reviews.zip");
         $zip->warnings = $warnings;
         foreach ($texts as $pid => $text) {
             $zip->add($header . $text, $Opt["downloadPrefix"] . $rfname . $pid . ".txt");
         }
         $result = $zip->download();
         if (!$result->error) {
             exit;
         }
     }
 }