2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2008-09-07 05:57:28 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class PrivMsgTheme extends Themelet
|
|
|
|
{
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
|
|
|
* @param PM[] $pms
|
|
|
|
*/
|
|
|
|
public function display_pms(Page $page, array $pms): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $user;
|
2010-05-28 13:26:46 +00:00
|
|
|
|
2020-10-25 17:05:36 +00:00
|
|
|
$user_cache = [];
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$html = "
|
2020-03-26 14:57:38 +00:00
|
|
|
<table id='pms' class='zebra'>
|
2013-02-09 10:35:59 +00:00
|
|
|
<thead><tr><th>R?</th><th>Subject</th><th>From</th><th>Date</th><th>Action</th></tr></thead>
|
2009-07-07 12:42:34 +00:00
|
|
|
<tbody>";
|
2019-05-28 16:59:38 +00:00
|
|
|
foreach ($pms as $pm) {
|
|
|
|
$h_subject = html_escape($pm->subject);
|
|
|
|
if (strlen(trim($h_subject)) == 0) {
|
|
|
|
$h_subject = "(No subject)";
|
|
|
|
}
|
2020-10-25 17:05:36 +00:00
|
|
|
if (!array_key_exists($pm->from_id, $user_cache)) {
|
|
|
|
$from = User::by_id($pm->from_id);
|
|
|
|
$user_cache[$pm->from_id] = $from;
|
|
|
|
} else {
|
|
|
|
$from = $user_cache[$pm->from_id];
|
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
$from_name = $from->name;
|
|
|
|
$h_from = html_escape($from_name);
|
|
|
|
$from_url = make_link("user/".url_escape($from_name));
|
|
|
|
$pm_url = make_link("pm/read/".$pm->id);
|
|
|
|
$del_url = make_link("pm/delete");
|
2020-10-25 17:05:36 +00:00
|
|
|
$h_date = substr(html_escape($pm->sent_date), 0, 16);
|
2019-05-28 16:59:38 +00:00
|
|
|
$readYN = "Y";
|
|
|
|
if (!$pm->is_read) {
|
|
|
|
$h_subject = "<b>$h_subject</b>";
|
|
|
|
$readYN = "N";
|
|
|
|
}
|
2019-07-09 14:10:21 +00:00
|
|
|
$hb = $from->can(Permissions::HELLBANNED) ? "hb" : "";
|
2019-05-28 16:59:38 +00:00
|
|
|
$html .= "<tr class='$hb'>
|
2013-02-09 10:35:59 +00:00
|
|
|
<td>$readYN</td>
|
|
|
|
<td><a href='$pm_url'>$h_subject</a></td>
|
2020-10-25 17:05:36 +00:00
|
|
|
<td><a href='$from_url'>$h_from</a></td>
|
|
|
|
<td>$h_date</td>
|
2024-02-11 11:34:09 +00:00
|
|
|
<td>".make_form($del_url)."
|
|
|
|
<input type='hidden' name='pm_id' value='{$pm->id}'>
|
2009-07-19 03:48:25 +00:00
|
|
|
<input type='submit' value='Delete'>
|
2013-02-09 10:35:59 +00:00
|
|
|
</form></td>
|
|
|
|
</tr>";
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
$html .= "
|
2009-07-07 12:42:34 +00:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
";
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->add_block(new Block("Private Messages", $html, "main", 40, "private-messages"));
|
|
|
|
}
|
2008-09-07 05:57:28 +00:00
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
public function display_composer(Page $page, User $from, User $to, string $subject = ""): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
$post_url = make_link("pm/send");
|
|
|
|
$h_subject = html_escape($subject);
|
|
|
|
$to_id = $to->id;
|
2024-02-11 11:34:09 +00:00
|
|
|
$form = make_form($post_url);
|
2019-05-28 16:59:38 +00:00
|
|
|
$html = <<<EOD
|
2024-02-11 11:34:09 +00:00
|
|
|
$form
|
2008-09-07 05:57:28 +00:00
|
|
|
<input type="hidden" name="to_id" value="$to_id">
|
2012-03-13 07:53:41 +00:00
|
|
|
<table style="width: 400px;" class="form">
|
|
|
|
<tr><th>Subject:</th><td><input type="text" name="subject" value="$h_subject"></td></tr>
|
2008-09-07 05:57:28 +00:00
|
|
|
<tr><td colspan="2"><textarea style="width: 100%" rows="6" name="message"></textarea></td></tr>
|
|
|
|
<tr><td colspan="2"><input type="submit" value="Send"></td></tr>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
EOD;
|
2019-05-28 16:59:38 +00:00
|
|
|
$page->add_block(new Block("Write a PM", $html, "main", 50));
|
|
|
|
}
|
2008-09-07 05:57:28 +00:00
|
|
|
|
2024-01-15 14:23:00 +00:00
|
|
|
public function display_message(Page $page, User $from, User $to, PM $pm): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
$page->set_title("Private Message");
|
|
|
|
$page->set_heading(html_escape($pm->subject));
|
|
|
|
$page->add_block(new NavBlock());
|
|
|
|
$page->add_block(new Block("Message from {$from->name}", format_text($pm->message), "main", 10));
|
|
|
|
}
|
2008-09-07 05:57:28 +00:00
|
|
|
}
|