Skip to content

Commit

Permalink
Braces, null coalescing, remove unused.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed May 7, 2020
1 parent 8f7fe7e commit 26deb4b
Show file tree
Hide file tree
Showing 31 changed files with 596 additions and 369 deletions.
38 changes: 25 additions & 13 deletions autoassign.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
// Copyright (c) 2006-2020 Eddie Kohler; see LICENSE.

require_once("src/initweb.php");
if (!$Me->is_manager())
if (!$Me->is_manager()) {
$Me->escape();
}

// clean request

// paper selection
if (!isset($Qreq->q) || trim($Qreq->q) === "(All)")
if (!isset($Qreq->q) || trim($Qreq->q) === "(All)") {
$Qreq->q = "";
if ($Qreq->post_ok())
}
if ($Qreq->post_ok()) {
header("X-Accel-Buffering: no"); // NGINX: do not hold on to file
}

$tOpt = PaperSearch::manager_search_types($Me);
if ($Me->privChair && !isset($Qreq->t)
&& $Qreq->a === "prefconflict"
&& $Conf->can_pc_see_active_submissions())
&& $Conf->can_pc_see_active_submissions()) {
$Qreq->t = "all";
}
if (!isset($Qreq->t) || !isset($tOpt[$Qreq->t])) {
reset($tOpt);
$Qreq->t = key($tOpt);
Expand Down Expand Up @@ -50,26 +54,31 @@
$x = preg_split('/\s+/', $Conf->setting_data("autoassign_badpairs", ""), null, PREG_SPLIT_NO_EMPTY);
$pcm = $Conf->pc_members();
$bpnum = 1;
for ($i = 0; $i < count($x) - 1; $i += 2)
if (isset($pcm[$x[$i]]) && isset($pcm[$x[$i+1]])) {
for ($i = 0; $i < count($x) - 1; $i += 2) {
if (isset($pcm[(int) $x[$i]]) && isset($pcm[(int) $x[$i+1]])) {
$Qreq["bpa$bpnum"] = $pcm[$x[$i]]->email;
$Qreq["bpb$bpnum"] = $pcm[$x[$i+1]]->email;
++$bpnum;
}
if ($Conf->setting("autoassign_badpairs"))
}
if ($Conf->setting("autoassign_badpairs")) {
$Qreq->badpairs = 1;
}
} else if ($Me->privChair && isset($Qreq->assign) && $Qreq->post_ok()) {
$x = array();
for ($i = 1; isset($Qreq["bpa$i"]); ++$i)
for ($i = 1; isset($Qreq["bpa$i"]); ++$i) {
if ($Qreq["bpa$i"] && $Qreq["bpb$i"]
&& ($pca = $Conf->pc_member_by_email($Qreq["bpa$i"]))
&& ($pcb = $Conf->pc_member_by_email($Qreq["bpb$i"]))) {
$x[] = $pca->contactId;
$x[] = $pcb->contactId;
}
if (count($x) || $Conf->setting_data("autoassign_badpairs")
|| (!isset($Qreq->badpairs) != !$Conf->setting("autoassign_badpairs")))
}
if (count($x)
|| $Conf->setting_data("autoassign_badpairs")
|| (!isset($Qreq->badpairs) != !$Conf->setting("autoassign_badpairs"))) {
$Conf->q("insert into Settings (name, value, data) values ('autoassign_badpairs', ?, ?) on duplicate key update data=values(data), value=values(value)", isset($Qreq->badpairs) ? 1 : 0, join(" ", $x));
}
}
// set $badpairs array
$badpairs = array();
Expand Down Expand Up @@ -108,18 +117,21 @@
$SSel->sort_selection();

// rev_round
if (($x = $Conf->sanitize_round_name($Qreq->rev_round)) !== false)
if (($x = $Conf->sanitize_round_name($Qreq->rev_round)) !== false) {
$Qreq->rev_round = $x;
}

// score selector
$scoreselector = array("+overAllMerit" => "", "-overAllMerit" => "");
foreach ($Conf->all_review_fields() as $f)
foreach ($Conf->all_review_fields() as $f) {
if ($f->has_options) {
$scoreselector["+" . $f->id] = "high $f->name_html scores";
$scoreselector["-" . $f->id] = "low $f->name_html scores";
}
if ($scoreselector["+overAllMerit"] === "")
}
if ($scoreselector["+overAllMerit"] === "") {
unset($scoreselector["+overAllMerit"], $scoreselector["-overAllMerit"]);
}
$scoreselector["__break"] = null;
$scoreselector["x"] = "random submitted reviews";
$scoreselector["xa"] = "random reviews";
Expand Down
12 changes: 7 additions & 5 deletions batch/fakenames.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,20 @@ function new_fake_email() {
// process papers
$result = $Conf->qe("select * from Paper");
$papers = [];
while (($p = PaperInfo::fetch($result, null, $Conf)))
while (($p = PaperInfo::fetch($result, null, $Conf))) {
$papers[] = $p;
}
Dbl::free($result);

$q = $qv = [];
foreach ($papers as $p) {
$ax = [];
foreach ($p->author_list() as $a) {
if ($a->email && isset($email_map[strtolower($a->email)]))
if ($a->email && isset($email_map[strtolower($a->email)])) {
$aa = $email_map[strtolower($a->email)];
else
} else {
$aa = [$fakes->first(), $fakes->last(), new_fake_email(), $fakes->affiliation()];
}
$ax[] = join("\t", $aa) . "\n";
}
$q[] = "update Paper set authorInformation=? where paperId={$p->paperId}";
Expand All @@ -167,9 +169,9 @@ function new_fake_email() {
$nl = "";
while (preg_match('/\A(.*?)([^\s\(\)\<\>@\/]+@[^\s\(\)\]\>\/]+\.[A-Za-z]+)(.*)\z/', $l, $m)) {
$nl .= $m[1];
if (isset($email_map[strtolower($m[2])]))
if (isset($email_map[strtolower($m[2])])) {
$nl .= $email_map[strtolower($m[2])][2];
else {
} else {
$ne = new_fake_email();
$email_map[strtolower($m[2])] = [$fakes->first(), $fakes->last(), $ne, $fakes->affiliation()];
$nl .= $ne;
Expand Down
32 changes: 20 additions & 12 deletions buzzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
reset($kiosks);
}
// look for new kiosks
$kiosk_keys = array(null, null);
foreach ($kiosks as $k => $kj)
$kiosk_keys = [null, null];
foreach ($kiosks as $k => $kj) {
if ($kj->update_at >= $Now - 7200)
$kiosk_keys[$kj->show_papers ? 1 : 0] = $k;
for ($i = 0; $i <= 1; ++$i)
}
for ($i = 0; $i <= 1; ++$i) {
if (!$kiosk_keys[$i]) {
$key = hotcrp_random_password();
$kiosks[$key] = (object) array("update_at" => $Now, "show_papers" => !!$i);
$kiosks[$key] = (object) ["update_at" => $Now, "show_papers" => !!$i];
$kiosk_keys[$i] = $kchange = $key;
}
}
// save kiosks
if ($kchange)
$Conf->save_setting("__tracker_kiosk", 1, $kiosks);
Expand All @@ -45,28 +47,33 @@

function kiosk_lookup($key) {
global $Conf, $Now;
$kiosks = (array) ($Conf->setting_json("__tracker_kiosk") ? : array());
if (isset($kiosks[$key]) && $kiosks[$key]->update_at >= $Now - 604800)
$kiosks = (array) ($Conf->setting_json("__tracker_kiosk") ? : []);
if (isset($kiosks[$key]) && $kiosks[$key]->update_at >= $Now - 604800) {
return $kiosks[$key];
return null;
} else {
return null;
}
}

$kiosk = null;
if (!$Me->has_email()
&& ($key = $Qreq->path_component(0))
&& ($kiosk = kiosk_lookup($key)))
&& ($kiosk = kiosk_lookup($key))) {
$Me->set_capability("tracker_kiosk", $key);
else if (($key = $Me->capability("tracker_kiosk")))
} else if (($key = $Me->capability("tracker_kiosk"))) {
$kiosk = kiosk_lookup($key);

}
if ($kiosk) {
$Me->tracker_kiosk_state = $kiosk->show_papers ? 2 : 1;
$show_papers = $kiosk->show_papers;
} else {
$show_papers = true;
}

// user
if (!$Me->isPC && !$Me->tracker_kiosk_state)
if (!$Me->isPC && !$Me->tracker_kiosk_state) {
$Me->escape();
}


$Conf->header("Discussion status", "buzzer", ["action_bar" => false, "body_class" => "hide-tracker"]);
Expand Down Expand Up @@ -115,8 +122,9 @@ function kiosk_lookup($key) {
$Conf->hoturl_absolute("buzzer", ["__PATH__" => $kiosk_keys[0]], Conf::HOTURL_RAW),
$Conf->hoturl_absolute("buzzer", ["__PATH__" => $kiosk_keys[1]], Conf::HOTURL_RAW)
];
} else if ($kiosk)
} else if ($kiosk) {
$buzzer_status["is_kiosk"] = true;
}
$buzzer_status["no_discussion"] = $no_discussion . '</div>';
echo Ht::unstash();
echo $Conf->make_script_file("scripts/buzzer.js");
Expand Down
30 changes: 19 additions & 11 deletions checkupdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,55 @@
&& is_array($data["updates"])) {
foreach ($data["updates"] as $update) {
$ok = true;
if (isset($update["opt"]) && is_array($update["opt"]))
if (isset($update["opt"]) && is_array($update["opt"])) {
foreach ($update["opt"] as $k => $v) {
$kk = ($k[0] == "-" ? substr($k, 1) : $k);
$test = $Conf->opt($kk, null) == $v;
$ok = $ok && ($k[0] == "-" ? !$test : $test);
}
}
if (isset($update["settings"]) && is_array($update["settings"]))
foreach ($update["settings"] as $k => $v) {
if (preg_match('/\A([!<>]?)(-?\d+|now)\z/', $v, $m)) {
$setting = $Conf->setting($k, 0);
if ($m[2] == "now")
if ($m[2] == "now") {
$m[2] = time();
if ($m[1] == "!")
}
if ($m[1] == "!") {
$test = $setting != +$m[2];
else if ($m[1] == ">")
} else if ($m[1] == ">") {
$test = $setting > +$m[2];
else if ($m[1] == "<")
} else if ($m[1] == "<") {
$test = $setting < +$m[2];
else
} else {
$test = $setting == +$m[2];
}
$ok = $ok && $test;
}
}
$errid = isset($update["errid"]) && ctype_alnum("" . $update["errid"]) ? $update["errid"] : false;
if ($errid && $Conf->setting("ignoreupdate_$errid", 0) > time())
if ($errid && $Conf->setting("ignoreupdate_$errid", 0) > time()) {
$ok = false;
}
if ($ok) {
$m = "<div class=\"msg msg-error\"";
if ($errid)
if ($errid) {
$m .= " id=\"softwareupdate_$errid\"";
}
$m .= " style=\"font-size:smaller\"><div class=\"dod\"><strong>WARNING: Upgrade your HotCRP installation.</strong>";
if (isset($update["vulnid"]) && is_numeric($update["vulnid"]))
if (isset($update["vulnid"]) && is_numeric($update["vulnid"])) {
$m .= " (HotCRP-Vulnerability-" . $update["vulnid"] . ")";
}
$m .= "</div>";
if (isset($update["message"]) && is_string($update["message"]))
if (isset($update["message"]) && is_string($update["message"])) {
$m .= "<div class=\"bigid\">" . CleanHTML::clean($update["message"], $error) . "</div>";
}
if (isset($update["to"]) && is_string($update["to"])) {
$m .= "<div class=\"bigid\">First unaffected commit: " . htmlspecialchars($update["to"]);
if ($errid)
if ($errid) {
$m .= ' <span class="barsep">·</span> '
. '<a class="ui js-check-version-ignore" href="" data-version-id="' . $errid . '">Ignore for two days</a>';
}
$m .= "</div>";
}
$messages[] = $m . "</div>\n";
Expand Down
3 changes: 2 additions & 1 deletion lib/cleanhtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ function clean_all($t, &$err = null) {
}

static function basic() {
if (!self::$g)
if (!self::$g) {
self::$g = new CleanHTML;
}
return self::$g;
}

Expand Down
Loading

0 comments on commit 26deb4b

Please sign in to comment.