Skip to content

Commit

Permalink
Merge branch 'master' into blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
mrilyew authored Dec 13, 2024
2 parents 504f50a + 2e70a26 commit 5a57231
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 14 deletions.
53 changes: 53 additions & 0 deletions VKAPI/Handlers/Reports.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php declare(strict_types=1);
namespace openvk\VKAPI\Handlers;
use openvk\Web\Models\Entities\Report;
use openvk\Web\Models\Repositories\Reports as ReportsRepo;

final class Reports extends VKAPIRequestHandler
{
function add(int $owner_id = 0, string $comment = "", int $reason = 0, string $type = "", string $report_source = ""): int
{
$this->requireUser();
$this->willExecuteWriteAction();

$allowed_types = ["post", "photo", "video", "group", "comment", "note", "app", "user", "audio"];
if($type == "" || !in_array($type, $allowed_types)) {
$this->fail(100, "One of the parameters specified was missing or invalid: type should be ".implode(", ", $allowed_types));
}

if($owner_id <= 0) {
$this->fail(100, "One of the parameters specified was missing or invalid: Bad input");
}

if(mb_strlen($comment) === 0) {
$this->fail(100, "One of the parameters specified was missing or invalid: Comment can't be empty");
}

if($type == "user" && $owner_id == $this->getUser()->getId()) {
return 1;
}

if($this->getUser()->isBannedInSupport()) {
return 0;
}

if(sizeof(iterator_to_array((new ReportsRepo)->getDuplicates($type, $owner_id, NULL, $this->getUser()->getId()))) > 0) {
return 1;
}

try {
$report = new Report;
$report->setUser_id($this->getUser()->getId());
$report->setTarget_id($owner_id);
$report->setType($type);
$report->setReason($comment);
$report->setCreated(time());

$report->save();
} catch(\Throwable $e) {
$this->fail(-1, "Unknown error failed");
}

return 1;
}
}
2 changes: 1 addition & 1 deletion Web/Models/shell/processVideo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Move-Item $file $temp

# video stub logic was implicitly deprecated, so we start processing at once
ffmpeg -i $temp -ss 00:00:01.000 -vframes 1 "$dir$hashT/$hash.gif"
ffmpeg -i $temp -c:v libx264 -q:v 7 -c:a libmp3lame -q:a 4 -tune zerolatency -vf "scale=480:-1,setsar=1" -y $temp2
ffmpeg -i $temp -c:v libx264 -q:v 7 -c:a libmp3lame -q:a 4 -tune zerolatency -vf "scale=iw*min(1\,if(gt(iw\,ih)\,640/iw\,(640*sar)/ih)):(floor((ow/dar)/2))*2" -y $temp2

Move-Item $temp2 "$dir$hashT/$hash.mp4"
Remove-Item $temp
Expand Down
2 changes: 1 addition & 1 deletion Web/Models/shell/processVideo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tmpfile="$RANDOM-$(date +%s%N)"
cp $2 "/tmp/vid_$tmpfile.bin"

nice ffmpeg -i "/tmp/vid_$tmpfile.bin" -ss 00:00:01.000 -vframes 1 $3${4:0:2}/$4.gif
nice -n 20 ffmpeg -i "/tmp/vid_$tmpfile.bin" -c:v libx264 -q:v 7 -c:a libmp3lame -q:a 4 -tune zerolatency -vf "scale=480:-1,setsar=1" -y "/tmp/ffmOi$tmpfile.mp4"
nice -n 20 ffmpeg -i "/tmp/vid_$tmpfile.bin" -c:v libx264 -q:v 7 -c:a libmp3lame -q:a 4 -tune zerolatency -vf "scale=iw*min(1\,if(gt(iw\,ih)\,640/iw\,(640*sar)/ih)):(floor((ow/dar)/2))*2" -y "/tmp/ffmOi$tmpfile.mp4"

rm -rf $3${4:0:2}/$4.mp4
mv "/tmp/ffmOi$tmpfile.mp4" $3${4:0:2}/$4.mp4
Expand Down
3 changes: 3 additions & 0 deletions Web/Presenters/ReportPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ function renderCreate(int $id): void

if(!$id)
exit(json_encode([ "error" => tr("error_segmentation") ]));

if ($this->queryParam("type") === "user" && $id === $this->user->id)
exit(json_encode([ "error" => "You can't report yourself" ]));

if(in_array($this->queryParam("type"), ["post", "photo", "video", "group", "comment", "note", "app", "user", "audio"])) {
if (count(iterator_to_array($this->reports->getDuplicates($this->queryParam("type"), $id, NULL, $this->user->id))) <= 0) {
Expand Down
6 changes: 3 additions & 3 deletions Web/Presenters/templates/Audio/Upload.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@
<tbody>
<tr>
<td width="120" valign="top"><span class="nobold">${tr('performer')}:</span></td>
<td><input value='${audio_element.info.performer}' name="performer" type="text" autocomplete="off" maxlength="80" /></td>
<td><input value='${escapeHtml(audio_element.info.performer)}' name="performer" type="text" autocomplete="off" maxlength="80" /></td>
</tr>
<tr>
<td width="120" valign="top"><span class="nobold">${tr('audio_name')}:</span></td>
<td><input type="text" value='${audio_element.info.name}' name="name" autocomplete="off" maxlength="80" /></td>
<td><input type="text" value='${escapeHtml(audio_element.info.name)}' name="name" autocomplete="off" maxlength="80" /></td>
</tr>
<tr>
<td width="120" valign="top"><span class="nobold">${tr('genre')}:</span></td>
Expand All @@ -178,7 +178,7 @@
</tr>
<tr>
<td width="120" valign="top"><span class="nobold">${tr('lyrics')}:</span></td>
<td><textarea name="lyrics" style="resize: vertical;max-height: 300px;">${audio_element.info.lyrics}</textarea></td>
<td><textarea name="lyrics" style="resize: vertical;max-height: 300px;">${escapeHtml(audio_element.info.lyrics)}</textarea></td>
</tr>
<tr>
<td width="120" valign="top"></td>
Expand Down
2 changes: 1 addition & 1 deletion Web/Presenters/templates/Report/ViewContent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{elseif $type == "group" || $type == "user"}
{include "../components/group.xml", group => $object, isUser => $type == "user"}
{elseif $type == "comment"}
{include "../components/comment.xml", comment => $object, timeOnly => true, linkWithPost => true}
{include "../components/comment.xml", comment => $object, timeOnly => true, correctLink => true}
{elseif $type == "note"}
{include "./content/note.xml", note => $object}
{elseif $type == "app"}
Expand Down
7 changes: 5 additions & 2 deletions Web/Util/DateTime.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php declare(strict_types=1);
namespace openvk\Web\Util;
use Chandler\Session\Session;

class DateTime
{
Expand All @@ -21,17 +22,19 @@ protected function zmdate(): string
$then = date_create("@" . $this->timestamp);
$now = date_create();
$diff = date_diff($now, $then);

$sessionOffset = intval(Session::i()->get("_timezoneOffset"));
if($diff->invert === 0)
return ovk_strftime_safe("%e %B %Y ", $this->timestamp) . tr("time_at_sp") . ovk_strftime_safe(" %R", $this->timestamp);

if($this->timestamp >= strtotime("midnight")) { # Today
if(($this->timestamp + $sessionOffset) >= (strtotime("midnight") + $sessionOffset)) { # Today
if($diff->h >= 1)
return tr("time_today") . tr("time_at_sp") . ovk_strftime_safe(" %R", $this->timestamp);
else if($diff->i < 2)
return tr("time_just_now");
else
return $diff->i === 5 ? tr("time_exactly_five_minutes_ago") : tr("time_minutes_ago", $diff->i);
} else if($this->timestamp >= strtotime("-1day midnight")) { # Yesterday
} else if(($this->timestamp + $sessionOffset) >= (strtotime("-1day midnight") + $sessionOffset)) { # Yesterday
return tr("time_yesterday") . tr("time_at_sp") . ovk_strftime_safe(" %R", $this->timestamp);
} else if(ovk_strftime_safe("%Y", $this->timestamp) === ovk_strftime_safe("%Y", time())) { # In this year
return ovk_strftime_safe("%e %h ", $this->timestamp) . tr("time_at_sp") . ovk_strftime_safe(" %R", $this->timestamp);
Expand Down
8 changes: 4 additions & 4 deletions Web/static/js/al_music.js
Original file line number Diff line number Diff line change
Expand Up @@ -1306,12 +1306,12 @@ u(document).on("click", ".musicIcon.edit-icon", (e) => {
MessageBox(tr("edit_audio"), `
<div>
${tr("performer")}
<input name="performer" maxlength="256" type="text" value="${performer}">
<input name="performer" maxlength="256" type="text" value="${escapeHtml(performer)}">
</div>
<div style="margin-top: 11px">
${tr("audio_name")}
<input name="name" maxlength="256" type="text" value="${name}">
<input name="name" maxlength="256" type="text" value="${escapeHtml(name)}">
</div>
<div style="margin-top: 11px">
Expand Down Expand Up @@ -1359,7 +1359,7 @@ u(document).on("click", ".musicIcon.edit-icon", (e) => {

e.target.setAttribute("data-performer", escapeHtml(response.new_info.performer))
e.target.setAttribute("data-title", escapeHtml(response.new_info.name))
e.target.setAttribute("data-lyrics", response.new_info.lyrics_unformatted)
e.target.setAttribute("data-lyrics", escapeHtml(response.new_info.lyrics_unformatted))
e.target.setAttribute("data-explicit", Number(response.new_info.explicit))
e.target.setAttribute("data-searchable", Number(!response.new_info.unlisted))
player.setAttribute("data-genre", response.new_info.genre)
Expand All @@ -1374,7 +1374,7 @@ u(document).on("click", ".musicIcon.edit-icon", (e) => {
} else {
player.insertAdjacentHTML("beforeend", `
<div class="lyrics">
${response.new_info.lyrics}
${escapeHtml(response.new_info.lyrics)}
</div>
`)

Expand Down
2 changes: 1 addition & 1 deletion Web/static/js/al_wall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2579,7 +2579,7 @@ async function changeStatus() {
document.querySelector("#page_status_text").innerHTML = `[ ${tr("change_status")} ]`;
document.querySelector("#page_status_text").className = "edit_link page_status_edit_button";
} else {
document.querySelector("#page_status_text").innerHTML = status;
document.querySelector("#page_status_text").innerHTML = escapeHtml(status);
document.querySelector("#page_status_text").className = "page_status page_status_edit_button";
}

Expand Down
6 changes: 5 additions & 1 deletion Web/static/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ window.router = new class {
}

u(document).on('click', 'a', async (e) => {
if(e.defaultPrevented) {
return
}

const target = u(e.target).closest('a')
const dom_url = target.attr('href')
const id = target.attr('id')
Expand Down Expand Up @@ -292,7 +296,7 @@ u(document).on('submit', 'form', async (e) => {
if(e.defaultPrevented) {
return
}

if(u('#ajloader').hasClass('shown')) {
e.preventDefault()
return
Expand Down

0 comments on commit 5a57231

Please sign in to comment.