Fix certain poll functions

Polls can now be set to quiz mode correctly, weird characters in options no longer crash OpenVK
This commit is contained in:
celestora 2022-10-11 20:24:34 +03:00
parent 5203229e9e
commit 0e22d1866f
3 changed files with 11 additions and 10 deletions

View file

@ -236,7 +236,7 @@ class Poll extends Attachable
if(!is_null($this->getRecord())) if(!is_null($this->getRecord()))
throw new PollLockedException; throw new PollLockedException;
$this->stateChanges("can_revote", true); $this->stateChanges("can_revote", $canReVote);
} }
function setAnonymity(bool $anonymous): void function setAnonymity(bool $anonymous): void
@ -256,8 +256,8 @@ class Poll extends Attachable
$this->setTitle($xml["title"] ?? "Untitled"); $this->setTitle($xml["title"] ?? "Untitled");
$this->setMultipleChoice(($xml["multiple"] ?? "no") == "yes"); $this->setMultipleChoice(($xml["multiple"] ?? "no") == "yes");
$this->setAnonymity(($xml["anonymous"] ?? "no") == "yes"); $this->setAnonymity(($xml["anonymous"] ?? "no") == "yes");
$this->setRevotability(($xml["locked"] ?? "no") == "yes"); $this->setRevotability(($xml["locked"] ?? "no") == "no");
if(ctype_digit($xml["duration"] ?? "")) if(ctype_digit((string) ($xml["duration"] ?? "")))
$this->setEndDate(time() + ((86400 * (int) $xml["duration"]))); $this->setEndDate(time() + ((86400 * (int) $xml["duration"])));
$options = []; $options = [];

View file

@ -21,7 +21,8 @@ class DateTime
$then = date_create("@" . $this->timestamp); $then = date_create("@" . $this->timestamp);
$now = date_create(); $now = date_create();
$diff = date_diff($now, $then); $diff = date_diff($now, $then);
if($diff->invert === 0) return __OPENVK_ERROR_CLOCK_IN_FUTURE; if($diff->invert === 0)
return ovk_strftime_safe("%e %B %Y ", $this->timestamp) . tr("time_at_sp") . ovk_strftime_safe(" %R %p", $this->timestamp);
if($this->timestamp >= strtotime("midnight")) { # Today if($this->timestamp >= strtotime("midnight")) { # Today
if($diff->h >= 1) if($diff->h >= 1)
@ -52,13 +53,10 @@ class DateTime
switch($type) { switch($type) {
case static::RELATIVE_FORMAT_NORMAL: case static::RELATIVE_FORMAT_NORMAL:
return mb_convert_case($this->zmdate(), MB_CASE_TITLE_SIMPLE); return mb_convert_case($this->zmdate(), MB_CASE_TITLE_SIMPLE);
break;
case static::RELATIVE_FORMAT_LOWER: case static::RELATIVE_FORMAT_LOWER:
return $this->zmdate(); return $this->zmdate();
break;
case static::RELATIVE_FORMAT_SHORT: case static::RELATIVE_FORMAT_SHORT:
return ""; return "";
break;
} }
} }

View file

@ -1,3 +1,7 @@
function escapeXML(text) {
return $("<span/>").text(text).html();
}
async function pollRetractVote(id) { async function pollRetractVote(id) {
let poll = $(`.poll[data-id=${id}]`); let poll = $(`.poll[data-id=${id}]`);
@ -72,7 +76,7 @@ function initPoll(id) {
<label><input type="checkbox" name="anon" /> ${tr("poll_anonymous")}</label><br/> <label><input type="checkbox" name="anon" /> ${tr("poll_anonymous")}</label><br/>
<label><input type="checkbox" name="multi" /> ${tr("poll_multiple")}</label><br/> <label><input type="checkbox" name="multi" /> ${tr("poll_multiple")}</label><br/>
<label><input type="checkbox" name="locked" /> ${tr("poll_locked")}</label><br/> <label><input type="checkbox" name="locked" /> ${tr("poll_locked")}</label><br/>
<label style="display: none;"> <label>
<input type="checkbox" name="expires" /> <input type="checkbox" name="expires" />
${tr("poll_edit_expires")} ${tr("poll_edit_expires")}
<select name="expires_in" style="width: unset;"> <select name="expires_in" style="width: unset;">
@ -101,7 +105,7 @@ function initPoll(id) {
if($(this).val().length === 0) if($(this).val().length === 0)
return; return;
options += `<option>${$(this).val()}</option>`; options += `<option>${escapeXML($(this).val())}</option>`;
}); });
let xml = ` let xml = `
@ -111,7 +115,6 @@ function initPoll(id) {
`; `;
$("input[name=poll]", form).val(xml); $("input[name=poll]", form).val(xml);
$(".post-has-poll", form).show(); $(".post-has-poll", form).show();
console.log(xml);
}, },
function() { function() {
$("input", $(this.$dialog().nodes[0])).unbind(); $("input", $(this.$dialog().nodes[0])).unbind();