2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2008-05-16 20:38:30 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class CustomCommentListTheme extends CommentListTheme
|
|
|
|
{
|
2021-03-14 23:43:50 +00:00
|
|
|
public int $inner_id = 0;
|
2024-02-20 00:54:36 +00:00
|
|
|
public bool $post_page = true;
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
|
|
|
* @param array<array{0: Image, 1: Comment[]}> $images
|
|
|
|
*/
|
2021-03-14 23:43:50 +00:00
|
|
|
public function display_comment_list(array $images, int $page_number, int $total_pages, bool $can_post): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $config, $page;
|
|
|
|
|
|
|
|
//$prev = $page_number - 1;
|
|
|
|
//$next = $page_number + 1;
|
|
|
|
|
2019-08-02 19:40:03 +00:00
|
|
|
$page_title = $config->get_string(SetupConfig::TITLE);
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->set_title($page_title);
|
|
|
|
$page->set_heading($page_title);
|
|
|
|
$page->disable_left();
|
|
|
|
$page->add_block(new Block(null, $this->build_upload_box(), "main", 0));
|
|
|
|
$page->add_block(new Block(null, "<hr>", "main", 80));
|
|
|
|
$this->display_paginator($page, "comment/list", null, $page_number, $total_pages);
|
2024-02-20 00:54:36 +00:00
|
|
|
$this->post_page = false;
|
2019-05-28 16:59:38 +00:00
|
|
|
|
|
|
|
// parts for each image
|
|
|
|
$position = 10;
|
|
|
|
foreach ($images as $pair) {
|
|
|
|
$image = $pair[0];
|
|
|
|
$comments = $pair[1];
|
|
|
|
|
|
|
|
$h_filename = html_escape($image->filename);
|
|
|
|
$h_filesize = to_shorthand_int($image->filesize);
|
|
|
|
$w = $image->width;
|
|
|
|
$h = $image->height;
|
|
|
|
|
|
|
|
$comment_html = "";
|
|
|
|
$comment_id = 0;
|
|
|
|
foreach ($comments as $comment) {
|
|
|
|
$this->inner_id = $comment_id++;
|
|
|
|
$comment_html .= $this->comment_to_html($comment, false);
|
|
|
|
}
|
|
|
|
|
2020-03-13 09:23:54 +00:00
|
|
|
$html = "<p style='clear:both'> </p><hr >";
|
2019-05-28 16:59:38 +00:00
|
|
|
$html .= "File: <a href=\"".make_link("post/view/{$image->id}")."\">$h_filename</a> - ($h_filesize, {$w}x{$h}) - ";
|
|
|
|
$html .= html_escape($image->get_tag_list());
|
|
|
|
$html .= "<div style='text-align: left'>";
|
|
|
|
$html .= "<div style='float: left;'>" . $this->build_thumb_html($image) . "</div>";
|
|
|
|
$html .= "<div class='commentset'>$comment_html</div>";
|
|
|
|
$html .= "</div>";
|
|
|
|
|
|
|
|
$page->add_block(new Block(null, $html, "main", $position++));
|
|
|
|
}
|
|
|
|
}
|
2020-03-13 09:23:54 +00:00
|
|
|
|
2021-03-14 23:43:50 +00:00
|
|
|
public function display_recent_comments(array $comments): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2024-02-20 00:54:36 +00:00
|
|
|
$this->post_page = false;
|
|
|
|
parent::display_recent_comments($comments);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
2021-03-14 23:43:50 +00:00
|
|
|
public function build_upload_box(): string
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
return "[[ insert upload-and-comment extension here ]]";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-11 21:49:12 +00:00
|
|
|
protected function comment_to_html(Comment $comment, bool $trim = false): string
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2024-02-20 00:54:36 +00:00
|
|
|
// because custom themes can't add params, because PHP
|
|
|
|
$post_page = $this->post_page;
|
|
|
|
$inner_id = $this->inner_id;
|
2019-05-28 16:59:38 +00:00
|
|
|
global $user;
|
|
|
|
|
2023-02-04 20:50:26 +00:00
|
|
|
$tfe = send_event(new TextFormattingEvent($comment->comment));
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2020-01-26 18:47:30 +00:00
|
|
|
//$i_uid = $comment->owner_id;
|
2019-05-28 16:59:38 +00:00
|
|
|
$h_name = html_escape($comment->owner_name);
|
|
|
|
//$h_poster_ip = html_escape($comment->poster_ip);
|
2024-02-20 03:02:43 +00:00
|
|
|
if ($trim) {
|
2024-02-20 11:21:24 +00:00
|
|
|
$h_comment = truncate($tfe->stripped, 50);
|
2024-02-20 03:02:43 +00:00
|
|
|
} else {
|
|
|
|
$h_comment = $tfe->formatted;
|
|
|
|
}
|
2024-08-31 18:53:07 +00:00
|
|
|
$h_comment = preg_replace_ex("/(^|>)(>[^<\n]*)(<|\n|$)/", '${1}<span class=\'greentext\'>${2}</span>${3}', $h_comment);
|
2024-02-23 11:30:51 +00:00
|
|
|
// handles discrepency in comment page and homepage
|
|
|
|
$h_comment = str_replace("<br>", "", $h_comment);
|
|
|
|
$h_comment = str_replace("\n", "<br>", $h_comment);
|
2020-01-26 18:47:30 +00:00
|
|
|
$i_comment_id = $comment->comment_id;
|
|
|
|
$i_image_id = $comment->image_id;
|
2019-05-28 16:59:38 +00:00
|
|
|
|
2024-06-21 23:45:24 +00:00
|
|
|
$h_userlink = "<a class='username' href='".make_link("user/$h_name")."'>$h_name</a>";
|
2019-05-28 16:59:38 +00:00
|
|
|
$h_date = $comment->posted;
|
|
|
|
$h_del = "";
|
2019-07-09 14:10:21 +00:00
|
|
|
if ($user->can(Permissions::DELETE_COMMENT)) {
|
2024-02-20 00:54:36 +00:00
|
|
|
$comment_preview = substr(html_unescape($tfe->stripped), 0, 50);
|
|
|
|
$j_delete_confirm_message = json_encode("Delete comment by {$comment->owner_name}:\n$comment_preview");
|
|
|
|
$h_delete_script = html_escape("return confirm($j_delete_confirm_message);");
|
|
|
|
$h_delete_link = make_link("comment/delete/$i_comment_id/$i_image_id");
|
|
|
|
$h_del = " - [<a onclick='$h_delete_script' href='$h_delete_link'>Delete</a>]";
|
|
|
|
}
|
|
|
|
if ($this->post_page) {
|
|
|
|
$h_reply = "[<a href='javascript: replyTo($i_image_id, $i_comment_id, \"$h_name\")'>Reply</a>]";
|
|
|
|
} else {
|
|
|
|
$h_reply = "[<a href='".make_link("post/view/$i_image_id")."'>Reply</a>]";
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($inner_id == 0) {
|
|
|
|
return "<div class='comment' style='margin-top: 8px;'>$h_userlink$h_del $h_date No.$i_comment_id $h_reply<p>$h_comment</p></div>";
|
|
|
|
} else {
|
|
|
|
return "<table><tr><td nowrap class='doubledash'>>></td><td>".
|
2024-02-20 00:54:36 +00:00
|
|
|
"<div class='reply'>$h_userlink$h_del $h_date No.$i_comment_id<p>$h_comment</p></div>" .
|
2019-05-28 16:59:38 +00:00
|
|
|
"</td></tr></table>";
|
|
|
|
}
|
|
|
|
}
|
2008-05-16 20:38:30 +00:00
|
|
|
}
|