mirror of
https://github.com/openvk/openvk
synced 2025-07-01 21:48:17 +03:00
Поиск по нескольким разделам
This commit is contained in:
parent
02a393b79f
commit
6f9cbdfa84
3 changed files with 239 additions and 133 deletions
|
@ -152,7 +152,13 @@ final class NoSpamPresenter extends OpenVKPresenter
|
||||||
if ($ts) $conditions[] = "`ts` < $ts";
|
if ($ts) $conditions[] = "`ts` < $ts";
|
||||||
if ($te) $conditions[] = "`ts` > $te";
|
if ($te) $conditions[] = "`ts` > $te";
|
||||||
if ($user) $conditions[] = "`user` = $user";
|
if ($user) $conditions[] = "`user` = $user";
|
||||||
$logs = $db->query("SELECT * FROM `logs` WHERE (`object_table` = '$table') AND (" . implode(" AND ", $conditions) . ") GROUP BY `object_id`");
|
|
||||||
|
$whereStart = "WHERE `object_table` = '$table'";
|
||||||
|
if ($table === "profiles") {
|
||||||
|
$whereStart .= "AND `type` = 0";
|
||||||
|
}
|
||||||
|
|
||||||
|
$logs = $db->query("SELECT * FROM `logs` $whereStart AND (" . implode(" AND ", $conditions) . ") GROUP BY `object_id`");
|
||||||
$response = [];
|
$response = [];
|
||||||
|
|
||||||
if (!$where) {
|
if (!$where) {
|
||||||
|
@ -166,6 +172,11 @@ final class NoSpamPresenter extends OpenVKPresenter
|
||||||
$object = $log->getObject()->unwrap();
|
$object = $log->getObject()->unwrap();
|
||||||
|
|
||||||
if (!$object) continue;
|
if (!$object) continue;
|
||||||
|
//exit(var_dump(substr_replace($where, "", 0, strlen(" AND"))));
|
||||||
|
if (str_starts_with($where, " AND")) {
|
||||||
|
$where = substr_replace($where, "", 0, strlen(" AND"));
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($db->query("SELECT * FROM `$table` WHERE $where")->fetchAll() as $o) {
|
foreach ($db->query("SELECT * FROM `$table` WHERE $where")->fetchAll() as $o) {
|
||||||
if ($object->id === $o["id"]) {
|
if ($object->id === $o["id"]) {
|
||||||
$response[] = $object;
|
$response[] = $object;
|
||||||
|
@ -179,6 +190,9 @@ final class NoSpamPresenter extends OpenVKPresenter
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$response = [];
|
||||||
|
$processed = 0;
|
||||||
|
|
||||||
$where = $this->postParam("where");
|
$where = $this->postParam("where");
|
||||||
$ip = $this->postParam("ip");
|
$ip = $this->postParam("ip");
|
||||||
$useragent = $this->postParam("useragent");
|
$useragent = $this->postParam("useragent");
|
||||||
|
@ -190,15 +204,20 @@ final class NoSpamPresenter extends OpenVKPresenter
|
||||||
if (!$ip && !$useragent && !$searchTerm && !$ts && !$te && !$where && !$searchTerm && !$user)
|
if (!$ip && !$useragent && !$searchTerm && !$ts && !$te && !$where && !$searchTerm && !$user)
|
||||||
$this->returnJson(["success" => false, "error" => "Нет запроса. Заполните поле \"подстрока\" или введите запрос \"WHERE\" в поле под ним."]);
|
$this->returnJson(["success" => false, "error" => "Нет запроса. Заполните поле \"подстрока\" или введите запрос \"WHERE\" в поле под ним."]);
|
||||||
|
|
||||||
$model_name = NoSpamPresenter::ENTITIES_NAMESPACE . "\\" . $this->postParam("model");
|
$models = explode(",", $this->postParam("models"));
|
||||||
if (!class_exists($model_name))
|
|
||||||
$this->returnJson(["success" => false, "error" => "Модель не найдена"]);
|
foreach ($models as $_model) {
|
||||||
|
$model_name = NoSpamPresenter::ENTITIES_NAMESPACE . "\\" . $_model;
|
||||||
|
if (!class_exists($model_name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$model = new $model_name;
|
$model = new $model_name;
|
||||||
|
|
||||||
$c = new \ReflectionClass($model_name);
|
$c = new \ReflectionClass($model_name);
|
||||||
if ($c->isAbstract() || $c->getName() == NoSpamPresenter::ENTITIES_NAMESPACE . "\\Correspondence")
|
if ($c->isAbstract() || $c->getName() == NoSpamPresenter::ENTITIES_NAMESPACE . "\\Correspondence") {
|
||||||
$this->returnJson(["success" => false, "error" => "No."]);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$db = DatabaseConnection::i()->getContext();
|
$db = DatabaseConnection::i()->getContext();
|
||||||
$table = $model->getTableName();
|
$table = $model->getTableName();
|
||||||
|
@ -216,8 +235,8 @@ final class NoSpamPresenter extends OpenVKPresenter
|
||||||
}
|
}
|
||||||
$conditions = implode(" OR ", $conditions);
|
$conditions = implode(" OR ", $conditions);
|
||||||
|
|
||||||
$where = ($where ? " AND ($conditions)" : $conditions);
|
$where = ($this->postParam("where") ? " AND ($conditions)" : "($conditions)");
|
||||||
if ($need_deleted) $where .= " AND `deleted` = 0";
|
if ($need_deleted) $where .= " AND (`deleted` = 0)";
|
||||||
}
|
}
|
||||||
|
|
||||||
$rows = [];
|
$rows = [];
|
||||||
|
@ -225,12 +244,22 @@ final class NoSpamPresenter extends OpenVKPresenter
|
||||||
$rows = searchByAdditionalParams($table, $where, $ip, $useragent, $ts, $te, $user);
|
$rows = searchByAdditionalParams($table, $where, $ip, $useragent, $ts, $te, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count($rows) === 0) {
|
||||||
|
if (!$searchTerm) {
|
||||||
|
if (str_starts_with($where, " AND")) {
|
||||||
|
if ($searchTerm && !$this->postParam("where")) {
|
||||||
|
$where = substr_replace($where, "", 0, strlen(" AND"));
|
||||||
|
} else {
|
||||||
|
$where = "(" . $this->postParam("where") . ")" . $where;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$result = $db->query("SELECT * FROM `$table` WHERE $where");
|
$result = $db->query("SELECT * FROM `$table` WHERE $where");
|
||||||
if (count($rows) === 0)
|
|
||||||
$rows = $result->fetchAll();
|
$rows = $result->fetchAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!in_array((int)$this->postParam("ban"), [1, 2, 3])) {
|
if (!in_array((int)$this->postParam("ban"), [1, 2, 3])) {
|
||||||
$response = [];
|
|
||||||
foreach ($rows as $key => $object) {
|
foreach ($rows as $key => $object) {
|
||||||
$object = (array)$object;
|
$object = (array)$object;
|
||||||
$_obj = [];
|
$_obj = [];
|
||||||
|
@ -243,11 +272,10 @@ final class NoSpamPresenter extends OpenVKPresenter
|
||||||
}
|
}
|
||||||
|
|
||||||
$_obj[$key] = $value;
|
$_obj[$key] = $value;
|
||||||
|
$_obj["__model_name"] = $_model;
|
||||||
}
|
}
|
||||||
$response[] = $_obj;
|
$response[] = $_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->returnJson(["success" => true, "count" => count($response), "list" => $response]);
|
|
||||||
} else {
|
} else {
|
||||||
$ids = [];
|
$ids = [];
|
||||||
|
|
||||||
|
@ -259,7 +287,7 @@ final class NoSpamPresenter extends OpenVKPresenter
|
||||||
|
|
||||||
$log = new NoSpamLog;
|
$log = new NoSpamLog;
|
||||||
$log->setUser($this->user->id);
|
$log->setUser($this->user->id);
|
||||||
$log->setModel($this->postParam("model"));
|
$log->setModel($_model);
|
||||||
if ($searchTerm) {
|
if ($searchTerm) {
|
||||||
$log->setRegex($searchTerm);
|
$log->setRegex($searchTerm);
|
||||||
} else {
|
} else {
|
||||||
|
@ -317,8 +345,11 @@ final class NoSpamPresenter extends OpenVKPresenter
|
||||||
$object->delete();
|
$object->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->returnJson(["success" => true]);
|
$processed++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->returnJson(["success" => true, "processed" => $processed, "count" => count($response), "list" => $response]);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->returnJson(["success" => false, "error" => $e->getMessage()]);
|
$this->returnJson(["success" => false, "error" => $e->getMessage()]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,21 +4,39 @@
|
||||||
{block header}{include title}{/block}
|
{block header}{include title}{/block}
|
||||||
|
|
||||||
{block content}
|
{block content}
|
||||||
|
<style>
|
||||||
|
.noSpamIcon {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
background: url("/assets/packages/static/openvk/img/supp_icons.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
.noSpamIcon-Add {
|
||||||
|
background-position: 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.noSpamIcon-Delete {
|
||||||
|
background-position: 0 -21px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<div class="tabs">{include "Tabs.xml", mode => "form"}</div>
|
<div class="tabs">{include "Tabs.xml", mode => "form"}</div>
|
||||||
<br/>
|
<br/>
|
||||||
<div style="display: flex; border: 1px solid #ECECEC; padding: 8px;">
|
<div style="display: flex; border: 1px solid #ECECEC; padding: 8px;">
|
||||||
<div id="noSpam-form" style="width: 50%; border-right: 1px solid #ECECEC;">
|
<div id="noSpam-form" style="width: 50%; border-right: 1px solid #ECECEC;">
|
||||||
<table cellspacing="7" cellpadding="0" width="100%" border="0">
|
<table cellspacing="7" cellpadding="0" width="100%" border="0">
|
||||||
<tbody>
|
<tbody id="models-list">
|
||||||
<tr>
|
<tr id="0-model">
|
||||||
<td width="83px">
|
<td width="83px">
|
||||||
<span class="nobold">Раздел:</span>
|
<span class="nobold">Раздел:</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<select name="model" id="model" style="margin-left: -2px;">
|
<div style="display: flex; gap: 8px; justify-content: space-between;">
|
||||||
|
<div id="add-model" class="noSpamIcon noSpamIcon-Add" style="display: none;" />
|
||||||
|
<select name="model" id="model" class="model initialModel" style="margin-left: -2px;">
|
||||||
<option selected value="none">Не выбрано</option>
|
<option selected value="none">Не выбрано</option>
|
||||||
<option n:foreach="$models as $model" value="{$model}">{$model}</option>
|
<option n:foreach="$models as $model" value="{$model}">{$model}</option>
|
||||||
</select>
|
</select>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -140,6 +158,18 @@
|
||||||
$("#noSpam-results-loader").show();
|
$("#noSpam-results-loader").show();
|
||||||
$("#noSpam-loader").show();
|
$("#noSpam-loader").show();
|
||||||
|
|
||||||
|
|
||||||
|
let models = [];
|
||||||
|
$(".model").each(function (i) {
|
||||||
|
let name = $(this).val();
|
||||||
|
if (!models.includes(name)) {
|
||||||
|
if (name.length > 0 && name !== "none") {
|
||||||
|
models.push(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
models = models.join(",");
|
||||||
|
|
||||||
let model = $("#model").val();
|
let model = $("#model").val();
|
||||||
let regex = $("#regex").val();
|
let regex = $("#regex").val();
|
||||||
let where = $("#where").val();
|
let where = $("#where").val();
|
||||||
|
@ -153,6 +183,7 @@
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/al_abuse/search",
|
url: "/al_abuse/search",
|
||||||
data: {
|
data: {
|
||||||
|
models: models,
|
||||||
model: model,
|
model: model,
|
||||||
q: regex,
|
q: regex,
|
||||||
where: where,
|
where: where,
|
||||||
|
@ -178,10 +209,10 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#noSpam-results-list").append(`<li>
|
$("#noSpam-results-list").append(`<li>
|
||||||
<a style="display: block;" onClick="$('#noSpam-result-fields-${ model}-${ item.id}').toggle()">
|
<a style="display: block;" onClick="$('#noSpam-result-fields-${ item.__model_name}-${ item.id}').toggle()">
|
||||||
<h4 style="display: inherit; padding: 8px;">${ model} #${ item.id}</h4>
|
<h4 style="display: inherit; padding: 8px;">${ item.__model_name} #${ item.id}</h4>
|
||||||
</a>
|
</a>
|
||||||
<div style="display: none;" id="noSpam-result-fields-${ model}-${ item.id}">${ fields}</div>
|
<div style="display: none;" id="noSpam-result-fields-${ item.__model_name}-${ item.id}">${ fields}</div>
|
||||||
</li>`);
|
</li>`);
|
||||||
});
|
});
|
||||||
$("#noSpam-results-block").show();
|
$("#noSpam-results-block").show();
|
||||||
|
@ -215,8 +246,10 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$("#apply").on("click", () => { search(Number($("#noSpam-ban-type").val())); })
|
$("#apply").on("click", () => { search(Number($("#noSpam-ban-type").val())); })
|
||||||
$("#model").on("change", async (e) => {
|
|
||||||
if (e.target.value !== "none") {
|
async function selectChange(value) {
|
||||||
|
console.log(value);
|
||||||
|
if (value !== "none") {
|
||||||
$("#noSpam-fields").hide();
|
$("#noSpam-fields").hide();
|
||||||
$("#noSpam-model-not-selected").show();
|
$("#noSpam-model-not-selected").show();
|
||||||
$("#noSpam-model-not-selected-text").hide();
|
$("#noSpam-model-not-selected-text").hide();
|
||||||
|
@ -224,9 +257,11 @@
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
$("#noSpam-model-not-selected").hide();
|
$("#noSpam-model-not-selected").hide();
|
||||||
$("#noSpam-fields").show();
|
$("#noSpam-fields").show();
|
||||||
|
$("#add-model").show();
|
||||||
$("#noSpam-model-not-selected-loader").hide();
|
$("#noSpam-model-not-selected-loader").hide();
|
||||||
}, 100)
|
}, 100)
|
||||||
} else {
|
} else {
|
||||||
|
if ($(".model").not(".initialModel").length === 0) {
|
||||||
$("#noSpam-fields").hide();
|
$("#noSpam-fields").hide();
|
||||||
$("#noSpam-model-not-selected").show();
|
$("#noSpam-model-not-selected").show();
|
||||||
$("#noSpam-model-not-selected-loader").show();
|
$("#noSpam-model-not-selected-loader").show();
|
||||||
|
@ -235,6 +270,46 @@
|
||||||
$("#noSpam-model-not-selected-loader").hide();
|
$("#noSpam-model-not-selected-loader").hide();
|
||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(".model").change(async (e) => {
|
||||||
|
selectChange(e.target.value);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$("#add-model").on("click", () => {
|
||||||
|
console.log($(".model").length);
|
||||||
|
$("#models-list").append(`
|
||||||
|
<tr id="${ $('.model').length}-model">
|
||||||
|
<td width="83px">
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div style="display: flex; gap: 8px; justify-content: space-between;">
|
||||||
|
<div class="noSpamIcon noSpamIcon-Delete" onClick="deleteModelSelect(${ $('.model').length});"></div>
|
||||||
|
<select name="model" class="model" style="margin-left: -2px;" onChange="selectChange($(this).val())">
|
||||||
|
<option selected value="none">Не выбрано</option>
|
||||||
|
{foreach $models as $model}
|
||||||
|
<option value={$model}>{$model|noescape}</option>
|
||||||
|
{/foreach}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>`);
|
||||||
|
});
|
||||||
|
|
||||||
|
function deleteModelSelect(id) {
|
||||||
|
$(`#${ id}-model`).remove();
|
||||||
|
if ($(".model").length === 0) {
|
||||||
|
console.log("BLYAT", $(".model"));
|
||||||
|
$("#noSpam-fields").hide();
|
||||||
|
$("#noSpam-model-not-selected").show();
|
||||||
|
$("#noSpam-model-not-selected-loader").show();
|
||||||
|
setTimeout(() => {
|
||||||
|
$("#noSpam-model-not-selected-text").show();
|
||||||
|
$("#noSpam-model-not-selected-loader").hide();
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
{/block}
|
{/block}
|
||||||
|
|
BIN
Web/static/img/supp_icons.png
Normal file
BIN
Web/static/img/supp_icons.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Loading…
Reference in a new issue