2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2023-01-10 22:44:09 +00:00
|
|
|
|
|
|
|
namespace Shimmie2;
|
|
|
|
|
2020-04-25 20:36:28 +00:00
|
|
|
use function MicroHTML\LI;
|
|
|
|
use function MicroHTML\A;
|
|
|
|
use function MicroHTML\INPUT;
|
|
|
|
use function MicroHTML\LABEL;
|
|
|
|
use function MicroHTML\rawHTML;
|
2020-04-12 11:42:37 +00:00
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
|
|
|
* @phpstan-type HistoryEntry array{image_id:int,id:int,source:string,date_set:string,user_id:string,user_ip:string,name:string}
|
|
|
|
*/
|
2019-09-29 16:37:03 +00:00
|
|
|
class SourceHistoryTheme extends Themelet
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2024-01-20 14:10:59 +00:00
|
|
|
/** @var string[] */
|
2021-03-14 23:43:50 +00:00
|
|
|
private array $messages = [];
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
|
|
|
* @param HistoryEntry[] $history
|
|
|
|
*/
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_history_page(Page $page, int $image_id, array $history): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-04-12 11:42:37 +00:00
|
|
|
$history_html = $this->history_list($history, true);
|
2013-05-18 12:52:11 +00:00
|
|
|
|
2020-10-26 15:23:49 +00:00
|
|
|
$page->set_title('Post '.$image_id.' Source History');
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->set_heading('Source History: '.$image_id);
|
|
|
|
$page->add_block(new NavBlock());
|
|
|
|
$page->add_block(new Block("Source History", $history_html, "main", 10));
|
|
|
|
}
|
2013-05-18 12:52:11 +00:00
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
|
|
|
* @param HistoryEntry[] $history
|
|
|
|
*/
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_global_page(Page $page, array $history, int $page_number): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-04-12 11:42:37 +00:00
|
|
|
$history_html = $this->history_list($history, false);
|
2013-05-18 12:52:11 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->set_title("Global Source History");
|
|
|
|
$page->set_heading("Global Source History");
|
|
|
|
$page->add_block(new Block("Source History", $history_html, "main", 10));
|
|
|
|
|
|
|
|
$h_prev = ($page_number <= 1) ? "Prev" :
|
2023-11-11 21:49:12 +00:00
|
|
|
'<a href="'.make_link('source_history/all/'.($page_number - 1)).'">Prev</a>';
|
2019-05-28 16:59:38 +00:00
|
|
|
$h_index = "<a href='".make_link()."'>Index</a>";
|
2023-11-11 21:49:12 +00:00
|
|
|
$h_next = '<a href="'.make_link('source_history/all/'.($page_number + 1)).'">Next</a>';
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
$nav = $h_prev.' | '.$h_index.' | '.$h_next;
|
|
|
|
$page->add_block(new Block("Navigation", $nav, "left"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a section to the admin page.
|
|
|
|
*/
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_admin_block(string $validation_msg = ''): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $page;
|
2020-04-12 11:42:37 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
if (!empty($validation_msg)) {
|
|
|
|
$validation_msg = '<br><b>'. $validation_msg .'</b>';
|
|
|
|
}
|
2020-04-12 11:42:37 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$html = '
|
2019-06-09 07:32:01 +00:00
|
|
|
Revert source changes by a specific IP address or username, optionally limited to recent changes.
|
2013-05-18 12:52:11 +00:00
|
|
|
'.$validation_msg.'
|
|
|
|
|
2024-02-09 11:00:18 +00:00
|
|
|
<br><br>'.make_form(make_link("source_history/bulk_revert"))."
|
2013-05-18 12:52:11 +00:00
|
|
|
<table class='form'>
|
|
|
|
<tr><th>Username</th> <td><input type='text' name='revert_name' size='15'></td></tr>
|
|
|
|
<tr><th>IP Address</th> <td><input type='text' name='revert_ip' size='15'></td></tr>
|
2019-06-09 07:32:01 +00:00
|
|
|
<tr><th>Since</th> <td><input type='date' name='revert_date' size='15'></td></tr>
|
2013-05-18 12:52:11 +00:00
|
|
|
<tr><td colspan='2'><input type='submit' value='Revert'></td></tr>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
";
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->add_block(new Block("Mass Source Revert", $html));
|
|
|
|
}
|
2020-04-12 11:42:37 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
/*
|
|
|
|
* Show a standard page for results to be put into
|
|
|
|
*/
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_revert_ip_results(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $page;
|
2021-03-14 23:43:50 +00:00
|
|
|
$html = implode("\n", $this->messages);
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->add_block(new Block("Bulk Revert Results", $html));
|
|
|
|
}
|
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
public function add_status(string $title, string $body): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$this->messages[] = '<p><b>'. $title .'</b><br>'. $body .'</p>';
|
|
|
|
}
|
2020-04-12 11:42:37 +00:00
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
|
|
|
* @param HistoryEntry[] $history
|
|
|
|
*/
|
2020-04-12 11:42:37 +00:00
|
|
|
protected function history_list(array $history, bool $select_2nd): string
|
|
|
|
{
|
|
|
|
$history_list = "";
|
|
|
|
foreach ($history as $n => $fields) {
|
|
|
|
$history_list .= $this->history_entry($fields, $select_2nd && $n == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "
|
|
|
|
<div style='text-align: left'>
|
|
|
|
" . make_form(make_link("source_history/revert")) . "
|
|
|
|
<ul style='list-style-type:none;'>
|
|
|
|
$history_list
|
|
|
|
</ul>
|
|
|
|
<input type='submit' value='Revert To'>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
|
|
|
* @param HistoryEntry $fields
|
|
|
|
*/
|
2020-04-12 11:42:37 +00:00
|
|
|
protected function history_entry(array $fields, bool $selected): string
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
$image_id = $fields['image_id'];
|
|
|
|
$current_id = $fields['id'];
|
2020-04-12 11:45:19 +00:00
|
|
|
$current_source = $fields['source'];
|
2020-04-12 11:42:37 +00:00
|
|
|
$name = $fields['name'];
|
|
|
|
$date_set = rawHTML(autodate($fields['date_set']));
|
|
|
|
$ip = $user->can(Permissions::VIEW_IP) ?
|
2020-10-09 12:47:42 +00:00
|
|
|
rawHTML(" " . show_ip($fields['user_ip'], "Sourcing >>$image_id as '$current_source'"))
|
2020-04-12 11:42:37 +00:00
|
|
|
: null;
|
2023-11-11 21:49:12 +00:00
|
|
|
$setter = A(["href" => make_link("user/" . url_escape($name))], $name);
|
2020-04-12 11:42:37 +00:00
|
|
|
|
|
|
|
return (string)LI(
|
2023-11-11 21:49:12 +00:00
|
|
|
INPUT(["type" => "radio", "name" => "revert", "id" => "$current_id", "value" => "$current_id", "checked" => $selected]),
|
|
|
|
A(["href" => make_link("post/view/$image_id")], $image_id),
|
2020-04-12 11:42:37 +00:00
|
|
|
": ",
|
|
|
|
LABEL(
|
2023-11-11 21:49:12 +00:00
|
|
|
["for" => "$current_id"],
|
2020-04-12 11:42:37 +00:00
|
|
|
$current_source,
|
|
|
|
" - ",
|
|
|
|
$setter,
|
|
|
|
$ip,
|
|
|
|
" - ",
|
|
|
|
$date_set
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2013-05-18 12:52:11 +00:00
|
|
|
}
|