Revert "Merge tag 'v2.10.6'"
This reverts commit122ea4ab9e
, reversing changes made toc54a11e250
.
This commit is contained in:
@@ -9,12 +9,7 @@ class Notes extends Extension
|
||||
/** @var NotesTheme */
|
||||
protected Themelet $theme;
|
||||
|
||||
public function onInitExt(InitExtEvent $event): void
|
||||
{
|
||||
Image::$prop_types["notes"] = ImagePropType::INT;
|
||||
}
|
||||
|
||||
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void
|
||||
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event)
|
||||
{
|
||||
global $config, $database;
|
||||
|
||||
@@ -75,7 +70,7 @@ class Notes extends Extension
|
||||
}
|
||||
}
|
||||
|
||||
public function onPageRequest(PageRequestEvent $event): void
|
||||
public function onPageRequest(PageRequestEvent $event)
|
||||
{
|
||||
global $page, $user;
|
||||
if ($event->page_matches("note")) {
|
||||
@@ -103,48 +98,25 @@ class Notes extends Extension
|
||||
if (!$user->is_anonymous()) {
|
||||
$this->revert_history($noteID, $reviewID);
|
||||
}
|
||||
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("note/updated"));
|
||||
break;
|
||||
case "add_note":
|
||||
if (!$user->is_anonymous()) {
|
||||
$this->add_new_note();
|
||||
}
|
||||
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("post/view/".$_POST["image_id"]));
|
||||
break;
|
||||
case "add_request":
|
||||
if (!$user->is_anonymous()) {
|
||||
$this->add_note_request();
|
||||
}
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("post/view/".$_POST["image_id"]));
|
||||
break;
|
||||
case "nuke_requests":
|
||||
if ($user->can(Permissions::NOTES_ADMIN)) {
|
||||
$this->nuke_requests();
|
||||
}
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("post/view/".$_POST["image_id"]));
|
||||
break;
|
||||
|
||||
case "create_note":
|
||||
$page->set_mode(PageMode::DATA);
|
||||
if (!$user->is_anonymous()) {
|
||||
$note_id = $this->add_new_note();
|
||||
$page->set_data(json_encode_ex([
|
||||
'status' => 'success',
|
||||
'note_id' => $note_id,
|
||||
]));
|
||||
}
|
||||
break;
|
||||
case "update_note":
|
||||
$page->set_mode(PageMode::DATA);
|
||||
if (!$user->is_anonymous()) {
|
||||
$this->update_note();
|
||||
$page->set_data(json_encode_ex(['status' => 'success']));
|
||||
}
|
||||
break;
|
||||
case "delete_note":
|
||||
$page->set_mode(PageMode::DATA);
|
||||
if ($user->can(Permissions::NOTES_ADMIN)) {
|
||||
$this->delete_note();
|
||||
$page->set_data(json_encode_ex(['status' => 'success']));
|
||||
}
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("post/view/".$_POST["image_id"]));
|
||||
break;
|
||||
case "nuke_notes":
|
||||
if ($user->can(Permissions::NOTES_ADMIN)) {
|
||||
@@ -154,7 +126,28 @@ class Notes extends Extension
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("post/view/".$_POST["image_id"]));
|
||||
break;
|
||||
case "nuke_requests":
|
||||
if ($user->can(Permissions::NOTES_ADMIN)) {
|
||||
$this->nuke_requests();
|
||||
}
|
||||
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("post/view/".$_POST["image_id"]));
|
||||
break;
|
||||
case "edit_note":
|
||||
if (!$user->is_anonymous()) {
|
||||
$this->update_note();
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("post/view/" . $_POST["image_id"]));
|
||||
}
|
||||
break;
|
||||
case "delete_note":
|
||||
if ($user->can(Permissions::NOTES_ADMIN)) {
|
||||
$this->delete_note();
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("post/view/".$_POST["image_id"]));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("note/list"));
|
||||
@@ -167,7 +160,7 @@ class Notes extends Extension
|
||||
/*
|
||||
* HERE WE LOAD THE NOTES IN THE IMAGE
|
||||
*/
|
||||
public function onDisplayingImage(DisplayingImageEvent $event): void
|
||||
public function onDisplayingImage(DisplayingImageEvent $event)
|
||||
{
|
||||
global $page, $user;
|
||||
|
||||
@@ -180,7 +173,7 @@ class Notes extends Extension
|
||||
/*
|
||||
* HERE WE ADD THE BUTTONS ON SIDEBAR
|
||||
*/
|
||||
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event): void
|
||||
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
|
||||
{
|
||||
global $user;
|
||||
if (!$user->is_anonymous()) {
|
||||
@@ -197,7 +190,7 @@ class Notes extends Extension
|
||||
/*
|
||||
* HERE WE ADD QUERYLETS TO ADD SEARCH SYSTEM
|
||||
*/
|
||||
public function onSearchTermParse(SearchTermParseEvent $event): void
|
||||
public function onSearchTermParse(SearchTermParseEvent $event)
|
||||
{
|
||||
if (is_null($event->term)) {
|
||||
return;
|
||||
@@ -220,9 +213,9 @@ class Notes extends Extension
|
||||
}
|
||||
}
|
||||
|
||||
public function onHelpPageBuilding(HelpPageBuildingEvent $event): void
|
||||
public function onHelpPageBuilding(HelpPageBuildingEvent $event)
|
||||
{
|
||||
if ($event->key === HelpPages::SEARCH) {
|
||||
if ($event->key===HelpPages::SEARCH) {
|
||||
$block = new Block();
|
||||
$block->header = "Notes";
|
||||
$block->body = $this->theme->get_help_html();
|
||||
@@ -233,8 +226,6 @@ class Notes extends Extension
|
||||
|
||||
/**
|
||||
* HERE WE GET ALL NOTES FOR DISPLAYED IMAGE.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function get_notes(int $imageID): array
|
||||
{
|
||||
@@ -245,57 +236,42 @@ class Notes extends Extension
|
||||
FROM notes
|
||||
WHERE enable = :enable AND image_id = :image_id
|
||||
ORDER BY date ASC
|
||||
", ['enable' => '1', 'image_id' => $imageID]);
|
||||
", ['enable'=>'1', 'image_id'=>$imageID]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* HERE WE ADD A NOTE TO DATABASE
|
||||
*/
|
||||
private function add_new_note(): int
|
||||
private function add_new_note()
|
||||
{
|
||||
global $database, $user;
|
||||
|
||||
$note = json_decode(file_get_contents_ex('php://input'), true);
|
||||
$imageID = int_escape($_POST["image_id"]);
|
||||
$user_id = $user->id;
|
||||
$noteX1 = int_escape($_POST["note_x1"]);
|
||||
$noteY1 = int_escape($_POST["note_y1"]);
|
||||
$noteHeight = int_escape($_POST["note_height"]);
|
||||
$noteWidth = int_escape($_POST["note_width"]);
|
||||
$noteText = html_escape($_POST["note_text"]);
|
||||
|
||||
$database->execute(
|
||||
"
|
||||
INSERT INTO notes (enable, image_id, user_id, user_ip, date, x1, y1, height, width, note)
|
||||
VALUES (:enable, :image_id, :user_id, :user_ip, now(), :x1, :y1, :height, :width, :note)",
|
||||
[
|
||||
'enable' => 1,
|
||||
'image_id' => $note['image_id'],
|
||||
'user_id' => $user->id,
|
||||
'user_ip' => get_real_ip(),
|
||||
'x1' => $note['x1'],
|
||||
'y1' => $note['y1'],
|
||||
'height' => $note['height'],
|
||||
'width' => $note['width'],
|
||||
'note' => $note['note'],
|
||||
]
|
||||
['enable'=>1, 'image_id'=>$imageID, 'user_id'=>$user_id, 'user_ip'=>get_real_ip(), 'x1'=>$noteX1, 'y1'=>$noteY1, 'height'=>$noteHeight, 'width'=>$noteWidth, 'note'=>$noteText]
|
||||
);
|
||||
|
||||
$noteID = $database->get_last_insert_id('notes_id_seq');
|
||||
|
||||
log_info("notes", "Note added {$noteID} by {$user->name}");
|
||||
|
||||
$database->execute("UPDATE images SET notes=(SELECT COUNT(*) FROM notes WHERE image_id=:id) WHERE id=:id", ['id' => $note['image_id']]);
|
||||
$database->execute("UPDATE images SET notes=(SELECT COUNT(*) FROM notes WHERE image_id=:id1) WHERE id=:id2", ['id1'=>$imageID, 'id2'=>$imageID]);
|
||||
|
||||
$this->add_history(
|
||||
1,
|
||||
$noteID,
|
||||
$note['image_id'],
|
||||
$note['x1'],
|
||||
$note['y1'],
|
||||
$note['height'],
|
||||
$note['width'],
|
||||
$note['note']
|
||||
);
|
||||
|
||||
return $noteID;
|
||||
$this->add_history(1, $noteID, $imageID, $noteX1, $noteY1, $noteHeight, $noteWidth, $noteText);
|
||||
}
|
||||
|
||||
private function add_note_request(): void
|
||||
private function add_note_request()
|
||||
{
|
||||
global $database, $user;
|
||||
|
||||
@@ -306,7 +282,7 @@ class Notes extends Extension
|
||||
"
|
||||
INSERT INTO note_request (image_id, user_id, date)
|
||||
VALUES (:image_id, :user_id, now())",
|
||||
['image_id' => $image_id, 'user_id' => $user_id]
|
||||
['image_id'=>$image_id, 'user_id'=>$user_id]
|
||||
);
|
||||
|
||||
$resultID = $database->get_last_insert_id('note_request_id_seq');
|
||||
@@ -314,11 +290,19 @@ class Notes extends Extension
|
||||
log_info("notes", "Note requested {$resultID} by {$user->name}");
|
||||
}
|
||||
|
||||
private function update_note(): void
|
||||
private function update_note()
|
||||
{
|
||||
global $database;
|
||||
|
||||
$note = json_decode(file_get_contents_ex('php://input'), true);
|
||||
$note = [
|
||||
"x1" => int_escape($_POST["note_x1"]),
|
||||
"y1" => int_escape($_POST["note_y1"]),
|
||||
"height" => int_escape($_POST["note_height"]),
|
||||
"width" => int_escape($_POST["note_width"]),
|
||||
"note" => $_POST["note_text"],
|
||||
"image_id" => int_escape($_POST["image_id"]),
|
||||
"id" => int_escape($_POST["note_id"])
|
||||
];
|
||||
|
||||
// validate parameters
|
||||
if (empty($note['note'])) {
|
||||
@@ -328,69 +312,78 @@ class Notes extends Extension
|
||||
$database->execute("
|
||||
UPDATE notes
|
||||
SET x1 = :x1, y1 = :y1, height = :height, width = :width, note = :note
|
||||
WHERE image_id = :image_id AND id = :note_id", $note);
|
||||
WHERE image_id = :image_id AND id = :id", $note);
|
||||
|
||||
$this->add_history(1, $note['note_id'], $note['image_id'], $note['x1'], $note['y1'], $note['height'], $note['width'], $note['note']);
|
||||
$this->add_history(1, $note['id'], $note['image_id'], $note['x1'], $note['y1'], $note['height'], $note['width'], $note['note']);
|
||||
}
|
||||
|
||||
private function delete_note(): void
|
||||
private function delete_note()
|
||||
{
|
||||
global $user, $database;
|
||||
|
||||
$note = json_decode(file_get_contents_ex('php://input'), true);
|
||||
$imageID = int_escape($_POST["image_id"]);
|
||||
$noteID = int_escape($_POST["note_id"]);
|
||||
|
||||
// validate parameters
|
||||
if (is_null($imageID) || !is_numeric($imageID) || is_null($noteID) || !is_numeric($noteID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$database->execute("
|
||||
UPDATE notes SET enable = :enable
|
||||
WHERE image_id = :image_id AND id = :id
|
||||
", ['enable' => 0, 'image_id' => $note["image_id"], 'id' => $note["note_id"]]);
|
||||
", ['enable'=>0, 'image_id'=>$imageID, 'id'=>$noteID]);
|
||||
|
||||
log_info("notes", "Note deleted {$note["note_id"]} by {$user->name}");
|
||||
log_info("notes", "Note deleted {$noteID} by {$user->name}");
|
||||
}
|
||||
|
||||
private function nuke_notes(): void
|
||||
private function nuke_notes()
|
||||
{
|
||||
global $database, $user;
|
||||
$image_id = int_escape($_POST["image_id"]);
|
||||
$database->execute("DELETE FROM notes WHERE image_id = :image_id", ['image_id' => $image_id]);
|
||||
$database->execute("DELETE FROM notes WHERE image_id = :image_id", ['image_id'=>$image_id]);
|
||||
log_info("notes", "Notes deleted from {$image_id} by {$user->name}");
|
||||
}
|
||||
|
||||
private function nuke_requests(): void
|
||||
private function nuke_requests()
|
||||
{
|
||||
global $database, $user;
|
||||
$image_id = int_escape($_POST["image_id"]);
|
||||
|
||||
$database->execute("DELETE FROM note_request WHERE image_id = :image_id", ['image_id' => $image_id]);
|
||||
$database->execute("DELETE FROM note_request WHERE image_id = :image_id", ['image_id'=>$image_id]);
|
||||
|
||||
log_info("notes", "Requests deleted from {$image_id} by {$user->name}");
|
||||
}
|
||||
|
||||
private function get_notes_list(PageRequestEvent $event): void
|
||||
private function get_notes_list(PageRequestEvent $event)
|
||||
{
|
||||
global $database, $config;
|
||||
|
||||
$pageNumber = $event->try_page_num(1);
|
||||
|
||||
$notesPerPage = $config->get_int('notesNotesPerPage');
|
||||
$totalPages = (int)ceil($database->get_one("SELECT COUNT(DISTINCT image_id) FROM notes") / $notesPerPage);
|
||||
|
||||
//$result = $database->get_all("SELECT * FROM pool_images WHERE pool_id=:pool_id", ['pool_id'=>$poolID]);
|
||||
$image_ids = $database->get_col(
|
||||
$result = $database->execute(
|
||||
"
|
||||
SELECT DISTINCT image_id
|
||||
FROM notes
|
||||
WHERE enable = :enable
|
||||
ORDER BY date DESC LIMIT :limit OFFSET :offset",
|
||||
['enable' => 1, 'offset' => $pageNumber * $notesPerPage, 'limit' => $notesPerPage]
|
||||
['enable'=>1, 'offset'=>$pageNumber * $notesPerPage, 'limit'=>$notesPerPage]
|
||||
);
|
||||
|
||||
$totalPages = ceil($database->get_one("SELECT COUNT(DISTINCT image_id) FROM notes") / $notesPerPage);
|
||||
|
||||
$images = [];
|
||||
foreach($image_ids as $id) {
|
||||
$images[] = Image::by_id($id);
|
||||
while ($row = $result->fetch()) {
|
||||
$images[] = [Image::by_id($row["image_id"])];
|
||||
}
|
||||
|
||||
$this->theme->display_note_list($images, $pageNumber + 1, $totalPages);
|
||||
}
|
||||
|
||||
private function get_notes_requests(PageRequestEvent $event): void
|
||||
private function get_notes_requests(PageRequestEvent $event)
|
||||
{
|
||||
global $config, $database;
|
||||
|
||||
@@ -398,31 +391,33 @@ class Notes extends Extension
|
||||
|
||||
$requestsPerPage = $config->get_int('notesRequestsPerPage');
|
||||
|
||||
|
||||
//$result = $database->get_all("SELECT * FROM pool_images WHERE pool_id=:pool_id", ['pool_id'=>$poolID]);
|
||||
|
||||
|
||||
$result = $database->execute(
|
||||
"
|
||||
SELECT DISTINCT image_id
|
||||
FROM note_request
|
||||
ORDER BY date DESC LIMIT :limit OFFSET :offset",
|
||||
["offset" => $pageNumber * $requestsPerPage, "limit" => $requestsPerPage]
|
||||
["offset"=>$pageNumber * $requestsPerPage, "limit"=>$requestsPerPage]
|
||||
);
|
||||
|
||||
$totalPages = (int)ceil($database->get_one("SELECT COUNT(*) FROM note_request") / $requestsPerPage);
|
||||
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM note_request") / $requestsPerPage);
|
||||
|
||||
$images = [];
|
||||
while ($row = $result->fetch()) {
|
||||
$images[] = Image::by_id($row["image_id"]);
|
||||
$images[] = [Image::by_id($row["image_id"])];
|
||||
}
|
||||
|
||||
$this->theme->display_note_requests($images, $pageNumber + 1, $totalPages);
|
||||
}
|
||||
|
||||
private function add_history(int $noteEnable, int $noteID, int $imageID, int $noteX1, int $noteY1, int $noteHeight, int $noteWidth, string $noteText): void
|
||||
private function add_history($noteEnable, $noteID, $imageID, $noteX1, $noteY1, $noteHeight, $noteWidth, $noteText)
|
||||
{
|
||||
global $user, $database;
|
||||
|
||||
$reviewID = $database->get_one("SELECT COUNT(*) FROM note_histories WHERE note_id = :note_id", ['note_id' => $noteID]);
|
||||
$reviewID = $database->get_one("SELECT COUNT(*) FROM note_histories WHERE note_id = :note_id", ['note_id'=>$noteID]);
|
||||
$reviewID = $reviewID + 1;
|
||||
|
||||
$database->execute(
|
||||
@@ -430,12 +425,12 @@ class Notes extends Extension
|
||||
INSERT INTO note_histories (note_enable, note_id, review_id, image_id, user_id, user_ip, date, x1, y1, height, width, note)
|
||||
VALUES (:note_enable, :note_id, :review_id, :image_id, :user_id, :user_ip, now(), :x1, :y1, :height, :width, :note)
|
||||
",
|
||||
['note_enable' => $noteEnable, 'note_id' => $noteID, 'review_id' => $reviewID, 'image_id' => $imageID, 'user_id' => $user->id, 'user_ip' => get_real_ip(),
|
||||
'x1' => $noteX1, 'y1' => $noteY1, 'height' => $noteHeight, 'width' => $noteWidth, 'note' => $noteText]
|
||||
['note_enable'=>$noteEnable, 'note_id'=>$noteID, 'review_id'=>$reviewID, 'image_id'=>$imageID, 'user_id'=>$user->id, 'user_ip'=>get_real_ip(),
|
||||
'x1'=>$noteX1, 'y1'=>$noteY1, 'height'=>$noteHeight, 'width'=>$noteWidth, 'note'=>$noteText]
|
||||
);
|
||||
}
|
||||
|
||||
private function get_histories(PageRequestEvent $event): void
|
||||
private function get_histories(PageRequestEvent $event)
|
||||
{
|
||||
global $config, $database;
|
||||
|
||||
@@ -450,15 +445,15 @@ class Notes extends Extension
|
||||
"INNER JOIN users AS u ".
|
||||
"ON u.id = h.user_id ".
|
||||
"ORDER BY date DESC LIMIT :limit OFFSET :offset",
|
||||
['offset' => $pageNumber * $historiesPerPage, 'limit' => $historiesPerPage]
|
||||
['offset'=>$pageNumber * $historiesPerPage, 'limit'=>$historiesPerPage]
|
||||
);
|
||||
|
||||
$totalPages = (int)ceil($database->get_one("SELECT COUNT(*) FROM note_histories") / $historiesPerPage);
|
||||
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM note_histories") / $historiesPerPage);
|
||||
|
||||
$this->theme->display_histories($histories, $pageNumber + 1, $totalPages);
|
||||
}
|
||||
|
||||
private function get_history(PageRequestEvent $event): void
|
||||
private function get_history(PageRequestEvent $event)
|
||||
{
|
||||
global $config, $database;
|
||||
|
||||
@@ -474,10 +469,10 @@ class Notes extends Extension
|
||||
"ON u.id = h.user_id ".
|
||||
"WHERE note_id = :note_id ".
|
||||
"ORDER BY date DESC LIMIT :limit OFFSET :offset",
|
||||
['note_id' => $noteID, 'offset' => $pageNumber * $historiesPerPage, 'limit' => $historiesPerPage]
|
||||
['note_id'=>$noteID, 'offset'=>$pageNumber * $historiesPerPage, 'limit'=>$historiesPerPage]
|
||||
);
|
||||
|
||||
$totalPages = (int)ceil($database->get_one("SELECT COUNT(*) FROM note_histories WHERE note_id = :note_id", ['note_id' => $noteID]) / $historiesPerPage);
|
||||
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM note_histories WHERE note_id = :note_id", ['note_id'=>$noteID]) / $historiesPerPage);
|
||||
|
||||
$this->theme->display_history($histories, $pageNumber + 1, $totalPages);
|
||||
}
|
||||
@@ -485,11 +480,11 @@ class Notes extends Extension
|
||||
/**
|
||||
* HERE GO BACK IN HISTORY AND SET THE OLD NOTE. IF WAS REMOVED WE RE-ADD IT.
|
||||
*/
|
||||
private function revert_history(int $noteID, int $reviewID): void
|
||||
private function revert_history(int $noteID, int $reviewID)
|
||||
{
|
||||
global $database;
|
||||
|
||||
$history = $database->get_row("SELECT * FROM note_histories WHERE note_id = :note_id AND review_id = :review_id", ['note_id' => $noteID, 'review_id' => $reviewID]);
|
||||
$history = $database->get_row("SELECT * FROM note_histories WHERE note_id = :note_id AND review_id = :review_id", ['note_id'=>$noteID, 'review_id'=>$reviewID]);
|
||||
|
||||
$noteEnable = $history['note_enable'];
|
||||
$noteID = $history['note_id'];
|
||||
@@ -504,7 +499,7 @@ class Notes extends Extension
|
||||
UPDATE notes
|
||||
SET enable = :enable, x1 = :x1, y1 = :y1, height = :height, width = :width, note = :note
|
||||
WHERE image_id = :image_id AND id = :id
|
||||
", ['enable' => 1, 'x1' => $noteX1, 'y1' => $noteY1, 'height' => $noteHeight, 'width' => $noteWidth, 'note' => $noteText, 'image_id' => $imageID, 'id' => $noteID]);
|
||||
", ['enable'=>1, 'x1'=>$noteX1, 'y1'=>$noteY1, 'height'=>$noteHeight, 'width'=>$noteWidth, 'note'=>$noteText, 'image_id'=>$imageID, 'id'=>$noteID]);
|
||||
|
||||
$this->add_history($noteEnable, $noteID, $imageID, $noteX1, $noteY1, $noteHeight, $noteWidth, $noteText);
|
||||
}
|
||||
|
Reference in New Issue
Block a user