| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage com_vikbooking |
| 5 |
* @author Alessio Gaggii - E4J srl |
| 6 |
* @copyright Copyright (C) 2025 E4J srl. All rights reserved. |
| 7 |
* @license GNU General Public License version 2 or later; see LICENSE |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 12 |
|
| 13 |
/** |
| 14 |
* Display data attributes. |
| 15 |
* |
| 16 |
* @var VBOChatMessage $thread |
| 17 |
* @var array $options |
| 18 |
*/ |
| 19 |
extract($displayData); |
| 20 |
|
| 21 |
/** @var VBOChatContext */ |
| 22 |
$context = $thread->getContext(); |
| 23 |
|
| 24 |
/** @var VBOChatUser[] */ |
| 25 |
$recipients = array_filter($context->getRecipients(), function($user) use ($thread) { |
| 26 |
return $user->getID() == $thread->getSenderID(); |
| 27 |
}); |
| 28 |
|
| 29 |
/** @var VBOChatUser */ |
| 30 |
$user = array_shift($recipients) ?: new VBOChatUserNull($thread->getSenderID(), $thread->getSenderName()); |
| 31 |
|
| 32 |
// obtain plain contents of last message |
| 33 |
$message = strip_tags((string) $thread->getMessage()); |
| 34 |
|
| 35 |
// stringify attachments |
| 36 |
$attachments = implode(', ', array_map(function($a) { |
| 37 |
return $a->getName(); |
| 38 |
}, $thread->getAttachments())); |
| 39 |
|
| 40 |
// thread last update |
| 41 |
$lastUpdate = $thread->getCreationDate(); |
| 42 |
|
| 43 |
$dateFormat = $options['dateformat'] ?? 'Y-m-d'; |
| 44 |
|
| 45 |
?> |
| 46 |
|
| 47 |
<div |
| 48 |
class="chat-thread" |
| 49 |
data-context="<?php echo htmlspecialchars($context->getAlias()); ?>" |
| 50 |
data-id="<?php echo (int) $context->getID(); ?>" |
| 51 |
data-date="<?php echo htmlspecialchars($lastUpdate); ?>" |
| 52 |
data-read="<?php echo (int) $thread->isRead(); ?>" |
| 53 |
> |
| 54 |
|
| 55 |
<div class="chat-thread-avatar"> |
| 56 |
<?php if ($url = $user->getAvatar()): ?> |
| 57 |
<img src="<?php echo $url; ?>" decoding="async" loading="lazy" /> |
| 58 |
<?php else: |
| 59 |
$names = preg_split("/\s+/", $user->getName() ?: $thread->getSenderName()); |
| 60 |
?> |
| 61 |
<span><?php echo strtoupper(substr((string) array_shift($names), 0, 1) . substr((string) array_pop($names), 0, 1)) ?></span> |
| 62 |
<?php endif; ?> |
| 63 |
</div> |
| 64 |
|
| 65 |
<div class="chat-thread-content"> |
| 66 |
|
| 67 |
<div class="chat-thread-head"> |
| 68 |
|
| 69 |
<div class="chat-thread-context"> |
| 70 |
<strong class="context-subject"><?php echo $context->getSubject(); ?></strong> |
| 71 |
<span class="message-author"> |
| 72 |
<?php echo $user->getName() ?: $thread->getSenderName(); ?> |
| 73 |
</span> |
| 74 |
</div> |
| 75 |
|
| 76 |
<div class="chat-thread-datetime"> |
| 77 |
<span class="last-update-time"><?php echo JHtml::fetch('date', $lastUpdate, $options['timeformat'] ?? 'H:i'); ?></span> |
| 78 |
<span class="last-update-date"> |
| 79 |
<?php |
| 80 |
$date = JHtml::fetch('date', $lastUpdate, $dateFormat); |
| 81 |
|
| 82 |
if ($date === JHtml::fetch('date', 'now', $dateFormat)) { |
| 83 |
echo JText::translate('VBTODAY'); |
| 84 |
} else if ($date === JHtml::fetch('date', '-1 day', $dateFormat)) { |
| 85 |
echo JText::translate('VBOYESTERDAY'); |
| 86 |
} else { |
| 87 |
echo $date; |
| 88 |
} |
| 89 |
?> |
| 90 |
</span> |
| 91 |
</div> |
| 92 |
|
| 93 |
</div> |
| 94 |
|
| 95 |
<div class="chat-thread-message-body" data-length="<?php echo strlen((string) $message); ?>"> |
| 96 |
<?php echo JHtml::fetch('vikbooking.shorten', $message, 80); ?> |
| 97 |
</div> |
| 98 |
|
| 99 |
<div class="chat-thread-message-attachments" data-length="<?php echo strlen($attachments); ?>"> |
| 100 |
<i class="fas fa-paperclip"></i> <span> |
| 101 |
<?php echo JHtml::fetch('vikbooking.shorten', $attachments, 80); ?></span> |
| 102 |
</div> |
| 103 |
|
| 104 |
</div> |
| 105 |
|
| 106 |
</div> |
| 107 |
|