function run(Contact $user, $qreq, $ssel)
 {
     global $Conf, $Opt;
     $q = $Conf->paperQuery($user, ["paperId" => $ssel->selection(), "topics" => true, "options" => true]);
     $result = Dbl::qe_raw($q);
     $pj = [];
     $ps = new PaperStatus($user, ["forceShow" => true, "hide_docids" => true]);
     if ($this->iszip) {
         $this->zipdoc = new ZipDocument($Opt["downloadPrefix"] . "data.zip");
         $ps->add_document_callback([$this, "document_callback"]);
     }
     while ($prow = PaperInfo::fetch($result, $user)) {
         if ($user->can_administer($prow, true)) {
             $pj[$prow->paperId] = $ps->paper_json($prow);
         } else {
             $pj[$prow->paperId] = (object) ["pid" => $prow->paperId, "error" => "You don’t have permission to administer this paper."];
             if ($this->iszip) {
                 $this->zipdoc->warnings[] = "#{$prow->paperId}: You don’t have permission to administer this paper.";
             }
         }
     }
     $pj = array_values($ssel->reorder($pj));
     if (count($pj) == 1) {
         $pj = $pj[0];
         $pj_filename = $Opt["downloadPrefix"] . "paper" . $ssel->selection_at(0) . "-data.json";
     } else {
         $pj_filename = $Opt["downloadPrefix"] . "data.json";
     }
     if ($this->iszip) {
         $this->zipdoc->add(json_encode($pj, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n", $pj_filename);
         $this->zipdoc->download();
     } else {
         header("Content-Type: application/json");
         header("Content-Disposition: attachment; filename=" . mime_quote_string($pj_filename));
         echo json_encode($pj, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
     }
     exit;
 }
Example #2
0
function rfc2822_words_quote($words)
{
    if (preg_match(':\\A[-A-Za-z0-9!#$%&\'*+/=?^_`{|}~ \\t]*\\z:', $words)) {
        return $words;
    } else {
        return mime_quote_string($words);
    }
}
Example #3
0
function downloadCSV($info, $header, $filename, $description, $opt = array())
{
    global $Conf, $Opt, $zlib_output_compression;
    $iscsv = defval($opt, "type", "csv") == "csv" && !isset($Opt["disableCSV"]);
    if (is_array($info)) {
        $text = __downloadCSV($info, $iscsv);
    } else {
        $text = $info;
    }
    if ($header && $iscsv) {
        $headertext = __downloadCSV($header, $iscsv);
    } else {
        if ($header) {
            $headertext = "#" . __downloadCSV($header, $iscsv);
        } else {
            $headertext = "";
        }
    }
    header("Content-Description: " . $Opt["shortName"] . " {$description}, PHP generated data");
    header("Content-Disposition: " . (defval($opt, "inline") ? "inline" : "attachment") . "; filename=" . mime_quote_string($Opt["downloadPrefix"] . $filename . ($iscsv ? ".csv" : ".txt")));
    if ($iscsv) {
        header("Content-Type: text/csv; charset=utf-8; header=" . ($headertext ? "present" : "absent"));
    } else {
        header("Content-Type: text/plain; charset=utf-8");
    }
    if (!defval($opt, "nolength") && !$zlib_output_compression) {
        header("Content-Length: " . (strlen($headertext) + strlen($text)));
    }
    echo $headertext, $text;
}
Example #4
0
 function download_headers($downloadname = null, $attachment = null)
 {
     if ($this->is_csv()) {
         header("Content-Type: text/csv; charset=utf-8; header=" . ($this->headerline !== "" ? "present" : "absent"));
     } else {
         header("Content-Type: text/plain; charset=utf-8");
     }
     if ($attachment === null) {
         $attachment = !Mimetype::disposition_inline($this->is_csv() ? "text/csv" : "text/plain");
     }
     if (!$downloadname) {
         $downloadname = "data" . $this->extension();
     }
     header("Content-Disposition: " . ($attachment ? "attachment" : "inline") . "; filename=" . mime_quote_string($downloadname));
     // reduce likelihood of XSS attacks in IE
     header("X-Content-Type-Options: nosniff");
 }
Example #5
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);
 }