mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
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:
parent
5203229e9e
commit
0e22d1866f
3 changed files with 11 additions and 10 deletions
|
@ -236,7 +236,7 @@ class Poll extends Attachable
|
|||
if(!is_null($this->getRecord()))
|
||||
throw new PollLockedException;
|
||||
|
||||
$this->stateChanges("can_revote", true);
|
||||
$this->stateChanges("can_revote", $canReVote);
|
||||
}
|
||||
|
||||
function setAnonymity(bool $anonymous): void
|
||||
|
@ -256,8 +256,8 @@ class Poll extends Attachable
|
|||
$this->setTitle($xml["title"] ?? "Untitled");
|
||||
$this->setMultipleChoice(($xml["multiple"] ?? "no") == "yes");
|
||||
$this->setAnonymity(($xml["anonymous"] ?? "no") == "yes");
|
||||
$this->setRevotability(($xml["locked"] ?? "no") == "yes");
|
||||
if(ctype_digit($xml["duration"] ?? ""))
|
||||
$this->setRevotability(($xml["locked"] ?? "no") == "no");
|
||||
if(ctype_digit((string) ($xml["duration"] ?? "")))
|
||||
$this->setEndDate(time() + ((86400 * (int) $xml["duration"])));
|
||||
|
||||
$options = [];
|
||||
|
|
|
@ -21,7 +21,8 @@ class DateTime
|
|||
$then = date_create("@" . $this->timestamp);
|
||||
$now = date_create();
|
||||
$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($diff->h >= 1)
|
||||
|
@ -52,13 +53,10 @@ class DateTime
|
|||
switch($type) {
|
||||
case static::RELATIVE_FORMAT_NORMAL:
|
||||
return mb_convert_case($this->zmdate(), MB_CASE_TITLE_SIMPLE);
|
||||
break;
|
||||
case static::RELATIVE_FORMAT_LOWER:
|
||||
return $this->zmdate();
|
||||
break;
|
||||
case static::RELATIVE_FORMAT_SHORT:
|
||||
return "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
function escapeXML(text) {
|
||||
return $("<span/>").text(text).html();
|
||||
}
|
||||
|
||||
async function pollRetractVote(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="multi" /> ${tr("poll_multiple")}</label><br/>
|
||||
<label><input type="checkbox" name="locked" /> ${tr("poll_locked")}</label><br/>
|
||||
<label style="display: none;">
|
||||
<label>
|
||||
<input type="checkbox" name="expires" />
|
||||
${tr("poll_edit_expires")}
|
||||
<select name="expires_in" style="width: unset;">
|
||||
|
@ -101,7 +105,7 @@ function initPoll(id) {
|
|||
if($(this).val().length === 0)
|
||||
return;
|
||||
|
||||
options += `<option>${$(this).val()}</option>`;
|
||||
options += `<option>${escapeXML($(this).val())}</option>`;
|
||||
});
|
||||
|
||||
let xml = `
|
||||
|
@ -111,7 +115,6 @@ function initPoll(id) {
|
|||
`;
|
||||
$("input[name=poll]", form).val(xml);
|
||||
$(".post-has-poll", form).show();
|
||||
console.log(xml);
|
||||
},
|
||||
function() {
|
||||
$("input", $(this.$dialog().nodes[0])).unbind();
|
||||
|
|
Loading…
Reference in a new issue