function run(Contact $user, $qreq, $ssel)
 {
     global $Conf, $Opt;
     // maybe download preferences for someone else
     $Rev = $user;
     if (($cid = cvtint($qreq->reviewer)) > 0 && $user->privChair) {
         if (!($Rev = Contact::find_by_id($cid))) {
             return Conf::msg_error("No such reviewer");
         }
     }
     if (!$Rev->isPC) {
         return self::EPERM;
     }
     $q = $Conf->paperQuery($Rev, array("paperId" => $ssel->selection(), "topics" => 1, "reviewerPreference" => 1));
     $result = Dbl::qe_raw($q);
     $texts = array();
     while ($prow = PaperInfo::fetch($result, $Rev)) {
         $t = $prow->paperId . "," . CsvGenerator::quote($prow->title);
         if ($prow->conflictType > 0) {
             $t .= ",conflict";
         } else {
             $t .= "," . unparse_preference($prow);
         }
         $t .= "\n";
         if ($this->extended) {
             if ($Rev->can_view_authors($prow, false)) {
                 $t .= prefix_word_wrap("#  Authors: ", $prow->pretty_text_author_list(), "#           ");
             }
             $t .= prefix_word_wrap("# Abstract: ", rtrim($prow->abstract), "#           ");
             if ($prow->topicIds != "") {
                 $t .= prefix_word_wrap("#   Topics: ", $prow->unparse_topics_text(), "#           ");
             }
             $t .= "\n";
         }
         defappend($texts[$prow->paperId], $t);
     }
     downloadCSV(join("", $ssel->reorder($texts)), ["paper", "title", "preference"], "revprefs");
 }
 public function pretty_text_title($width = 75)
 {
     $l = $this->pretty_text_title_indent($width);
     return prefix_word_wrap("Paper #{$this->paperId}: ", $this->title, $l);
 }
 function expand($text, $field = null)
 {
     if (is_array($text)) {
         $a = array();
         foreach ($text as $k => $t) {
             $a[$k] = $this->expand($t, $k);
         }
         return $a;
     }
     // leave early on empty string
     if ($text == "") {
         return "";
     }
     // width, expansion type based on field
     $oldExpansionType = $this->expansionType;
     $width = 100000;
     if ($field == "to" || $field == "cc" || $field == "bcc" || $field == "reply-to") {
         $this->expansionType = self::EXPAND_EMAIL;
     } else {
         if ($field != "body" && $field != "") {
             $this->expansionType = self::EXPAND_HEADER;
         } else {
             $this->expansionType = self::EXPAND_BODY;
             $width = $this->width;
         }
     }
     // expand out %IF% and %ELSE% and %ENDIF%.  Need to do this first,
     // or we get confused with wordwrapping.
     $text = $this->_expandConditionals(cleannl($text));
     // separate text into lines
     $lines = explode("\n", $text);
     if (count($lines) && $lines[count($lines) - 1] === "") {
         array_pop($lines);
     }
     $text = "";
     $textstart = 0;
     for ($i = 0; $i < count($lines); ++$i) {
         $line = rtrim($lines[$i]);
         if ($line == "") {
             $text .= "\n";
         } else {
             if (preg_match('/^%(?:REVIEWS|COMMENTS)(?:[(].*[)])?%$/', $line)) {
                 if (($m = $this->expandvar($line, false)) != "") {
                     $text .= $m . "\n";
                 }
             } else {
                 if (preg_match('/^([ \\t][ \\t]*.*?: )(%OPT\\([\\w()]+\\)%)$/', $line, $m)) {
                     if ($yes = $this->expandvar($m[2], true)) {
                         $text .= prefix_word_wrap($m[1], $this->expandvar($m[2]), tabLength($m[1], true), $width);
                     } else {
                         if ($yes === null) {
                             $text .= $line . "\n";
                         }
                     }
                 } else {
                     if (preg_match('/^([ \\t][ \\t]*.*?: )(%\\w+(?:|\\([^\\)]*\\))%|\\S+)\\s*$/', $line, $m)) {
                         $text .= $this->_lineexpand($m[2], $m[1], tabLength($m[1], true), $width);
                     } else {
                         if (strpos($line, '%') !== false) {
                             $text .= $this->_lineexpand($line, "", 0, $width);
                         } else {
                             $text .= prefix_word_wrap("", $line, 0, $width);
                         }
                     }
                 }
             }
         }
     }
     // lose newlines on header expansion
     if ($this->expansionType != self::EXPAND_BODY) {
         $text = rtrim(preg_replace('/[\\r\\n\\f\\x0B]+/', ' ', $text));
     }
     $this->expansionType = $oldExpansionType;
     return $text;
 }
 function run(Contact $user, $qreq, $ssel)
 {
     global $Conf;
     $result = Dbl::qe_raw($Conf->paperQuery($user, array("paperId" => $ssel->selection(), "topics" => 1)));
     $texts = array();
     while ($prow = PaperInfo::fetch($result, $user)) {
         if ($whyNot = $user->perm_view_paper($prow)) {
             Conf::msg_error(whyNotText($whyNot, "view"));
         } else {
             $text = "===========================================================================\n";
             $n = "Paper #" . $prow->paperId . ": ";
             $l = max(14, (int) ((75.5 - strlen($prow->title) - strlen($n)) / 2) + strlen($n));
             $text .= prefix_word_wrap($n, $prow->title, $l);
             $text .= "---------------------------------------------------------------------------\n";
             $l = strlen($text);
             if ($user->can_view_authors($prow, $qreq->t == "a")) {
                 $text .= prefix_word_wrap("Authors: ", $prow->pretty_text_author_list(), 14);
             }
             if ($prow->topicIds != "" && ($tt = $prow->unparse_topics_text())) {
                 $text .= prefix_word_wrap("Topics: ", $tt, 14);
             }
             if ($l != strlen($text)) {
                 $text .= "---------------------------------------------------------------------------\n";
             }
             $text .= rtrim($prow->abstract) . "\n\n";
             defappend($texts[$prow->paperId], $text);
             $rfSuffix = count($texts) == 1 ? $prow->paperId : "s";
         }
     }
     if (count($texts)) {
         downloadText(join("", $ssel->reorder($texts)), "abstract{$rfSuffix}");
     }
 }
 function run(Contact $user, $qreq, $ssel)
 {
     global $Conf;
     $rf = ReviewForm::get();
     if ($ssel->is_empty()) {
         // blank form
         $text = $rf->textFormHeader("blank") . $rf->textForm(null, null, $user, null) . "\n";
         downloadText($text, "review");
         return;
     }
     $result = Dbl::qe_raw($Conf->paperQuery($user, array("paperId" => $ssel->selection(), "myReviewsOpt" => 1)));
     $texts = array();
     $errors = array();
     while ($row = PaperInfo::fetch($result, $user)) {
         $whyNot = $user->perm_review($row, null);
         if ($whyNot && !isset($whyNot["deadline"]) && !isset($whyNot["reviewNotAssigned"])) {
             $errors[whyNotText($whyNot, "review")] = true;
         } else {
             if ($whyNot) {
                 $t = whyNotText($whyNot, "review");
                 $errors[$t] = false;
                 if (!isset($whyNot["deadline"])) {
                     defappend($texts[$row->paperId], prefix_word_wrap("==-== ", strtoupper(whyNotHtmlToText($t)) . "\n\n", "==-== "));
                 }
             }
             $rrow = $row->reviewContactId ? $row : null;
             defappend($texts[$row->paperId], $rf->textForm($row, $rrow, $user, null) . "\n");
         }
     }
     $this->finish($ssel, $texts, $errors);
 }
 function pretty_text($prow, $rrow, $contact, $no_update_review_author_seen = false)
 {
     global $Conf;
     assert($prow !== null && $rrow !== null);
     $rrow_contactId = @$rrow->reviewContactId ?: (@$rrow->contactId ?: 0);
     $revViewScore = $contact->view_score_bound($prow, $rrow);
     self::check_review_author_seen($prow, $rrow, $contact, $no_update_review_author_seen);
     $x = "===========================================================================\n";
     $n = Conf::$gShortName . " Review";
     if (@$rrow->reviewOrdinal) {
         $n .= " #" . $prow->paperId . unparseReviewOrdinal($rrow->reviewOrdinal);
     }
     $x .= center_word_wrap($n);
     if ($rrow->reviewModified && $contact->can_view_review_time($prow, $rrow)) {
         $n = "Updated " . $Conf->printableTime($rrow->reviewModified);
         $x .= center_word_wrap($n);
     }
     $x .= "---------------------------------------------------------------------------\n";
     $x .= $prow->pretty_text_title();
     if ($contact->can_view_review_identity($prow, $rrow, false)) {
         if (isset($rrow->reviewFirstName)) {
             $n = Text::user_text($rrow->reviewFirstName, $rrow->reviewLastName, $rrow->reviewEmail);
         } else {
             if (isset($rrow->lastName)) {
                 $n = Text::user_text($rrow);
             } else {
                 $n = null;
             }
         }
         if ($n) {
             $x .= prefix_word_wrap("Reviewer: ", $n, $prow->pretty_text_title_indent());
         }
     }
     $x .= "---------------------------------------------------------------------------\n\n";
     $i = 0;
     $lastNumeric = null;
     foreach ($this->forder as $field => $f) {
         $i++;
         if ($f->view_score <= $revViewScore || $f->round_mask && !$f->is_round_visible($rrow)) {
             continue;
         }
         $fval = "";
         if (isset($rrow->{$field})) {
             if ($f->has_options) {
                 $fval = $f->unparse_value($rrow->{$field});
             } else {
                 $fval = rtrim(str_replace("\r\n", "\n", $rrow->{$field}));
             }
         }
         if ($fval == "") {
             continue;
         }
         if ($f->has_options) {
             $y = defval($f->options, $fval, "");
             $sn = $f->name . ":";
             /* "(1-" . count($f->options) . "):"; */
             if ($lastNumeric === false) {
                 $x .= "\n";
             }
             if (strlen($sn) > 38 + strlen($fval)) {
                 $x .= $sn . "\n" . prefix_word_wrap($fval . ". ", $y, 39 + strlen($fval));
             } else {
                 $x .= prefix_word_wrap($sn . " " . $fval . ". ", $y, 39 + strlen($fval));
             }
             $lastNumeric = true;
         } else {
             $n = "===== " . $f->name . " =====";
             if ($lastNumeric !== null) {
                 $x .= "\n";
             }
             $x .= center_word_wrap($n);
             $x .= "\n" . preg_replace("/^==\\+==/m", "\\==+==", $fval) . "\n";
             $lastNumeric = false;
         }
     }
     return $x;
 }
xassert_eqq(UnicodeHelper::utf8_prefix("áááááááá", 7), "ááááááá");
xassert_eqq(UnicodeHelper::utf8_prefix("áááááááá", 8), "áááááááá");
xassert_eqq(UnicodeHelper::utf8_prefix("áááááááá", 9), "áááááááá");
xassert_eqq(UnicodeHelper::utf8_prefix("a̓a̓a̓a̓a̓a̓a̓a̓", 7), "a̓a̓a̓a̓a̓a̓a̓");
xassert_eqq(UnicodeHelper::utf8_prefix("a̓a̓a̓a̓a̓a̓a̓a̓", 8), "a̓a̓a̓a̓a̓a̓a̓a̓");
xassert_eqq(UnicodeHelper::utf8_prefix("a̓a̓a̓a̓a̓a̓a̓a̓", 9), "a̓a̓a̓a̓a̓a̓a̓a̓");
xassert_eqq(UnicodeHelper::utf8_word_prefix("aaaaaaaa bbb", 7), "aaaaaaaa");
xassert_eqq(UnicodeHelper::utf8_word_prefix("aaaaaaaa bbb", 8), "aaaaaaaa");
xassert_eqq(UnicodeHelper::utf8_word_prefix("aaaaaaaa bbb", 9), "aaaaaaaa");
xassert_eqq(UnicodeHelper::utf8_word_prefix("aaaaaaaa bbb", 10), "aaaaaaaa");
xassert_eqq(UnicodeHelper::utf8_glyphlen("aaaaaaaa"), 8);
xassert_eqq(UnicodeHelper::utf8_glyphlen("áááááááá"), 8);
xassert_eqq(UnicodeHelper::utf8_glyphlen("a̓a̓a̓a̓a̓a̓a̓a̓"), 8);
xassert_eqq(prefix_word_wrap("+ ", "This is a thing to be wrapped.", "- ", 10), "+ This is\n- a thing\n- to be\n- wrapped.\n");
xassert_eqq(prefix_word_wrap("+ ", "This is a thing to be wrapped.", "- ", 9), "+ This is\n- a thing\n- to be\n- wrapped.\n");
xassert_eqq(prefix_word_wrap("+ ", "This\nis\na thing\nto\nbe wrapped.", "- ", 9), "+ This\n- is\n- a thing\n- to\n- be\n- wrapped.\n");
xassert_eqq(!!preg_match('/\\A\\pZ\\z/u', ' '), true);
// deaccent tests
xassert_eqq(UnicodeHelper::deaccent("Á é î ç ø U"), "A e i c o U");
$do = UnicodeHelper::deaccent_offsets("Á é î ç ø U .K");
xassert_eqq($do[0], "A e i c o U .K");
xassert_eqq(json_encode($do[1]), "[[0,0],[1,2],[3,5],[5,8],[7,11],[9,14],[14,21]]");
$regex = (object) ["preg_raw" => Text::word_regex("foo"), "preg_utf8" => Text::utf8_word_regex("foo")];
xassert_eqq(Text::highlight("Is foo bar føo bar fóó bar highlit right? foö", $regex), "Is <span class=\"match\">foo</span> bar <span class=\"match\">føo</span> bar <span class=\"match\">fóó</span> bar highlit right? <span class=\"match\">foö</span>");
// Qobject tests
$q = new Qobject(["a" => 1, "b" => 2]);
xassert_eqq($q->a, 1);
xassert_eqq($q->b, 2);
xassert_eqq(count($q), 2);
xassert_eqq($q->c, null);
xassert_eqq(count($q), 2);