PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / src / chat / notification / webpush.php

webpush.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/src/chat/notification/webpush.php

80 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2026 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Chat web push notification trait.
16 *
17 * @since 1.8
18 */
19 trait VBOChatNotificationWebpush
20 {
21 /**
22 * Enqueues a new messages within the notification center.
23 *
24 * @param VBOChatMessage $message The message instance.
25 * @param VBOChatUser $user The user that sent the message.
26 *
27 * @return bool
28 */
29 public function sendWebPushNotification(VBOChatMessage $message, VBOChatUser $user)
30 {
31 // display the whole message as summary
32 $summary = (string) $message->getMessage();
33
34 if (strlen($summary) === 0) {
35 // no message provided, display the number of attached files
36 $attachmentsCount = count($message->getAttachments());
37
38 if ($attachmentsCount === 1) {
39 // only one attachment
40 $summary = JText::sprintf('VBO_CHAT_MESSAGE_WEBPUSH_NOTIFICATION_SUMMARY_N_FILES_1', $message->getSenderName());
41 } else {
42 // multiple attachments
43 $summary = JText::plural('VBO_CHAT_MESSAGE_WEBPUSH_NOTIFICATION_SUMMARY_N_FILES', $message->getSenderName(), $attachmentsCount);
44 }
45 } else {
46 // message provided
47 $summary = JText::sprintf('VBO_CHAT_MESSAGE_WEBPUSH_NOTIFICATION_SUMMARY', $message->getSenderName(), $summary);
48 }
49
50 try {
51 /** @var VBOChatContext */
52 $context = $message->getContext();
53
54 // store the notification record
55 VBOFactory::getNotificationCenter()->store([
56 [
57 'sender' => $context->getAlias() === 'session' ? 'website' : 'operators',
58 'type' => 'chat.newmessage',
59 'title' => JText::sprintf('VBO_CHAT_MESSAGE_WEBPUSH_NOTIFICATION_TITLE', $context->getSubject()),
60 'summary' => $summary,
61 'label' => JText::translate('VBO_REPLY'),
62 'avatar' => $user->getAvatar(),
63 'widget' => $context->getAlias() === 'session' ? 'inquiries_chat' : 'operators_chat',
64 'widget_options' => [
65 'context_alias' => $context->getAlias(),
66 'context_id' => $context->getID(),
67 ],
68 // always skip signature check, so that we can allow a duplicate insert
69 '_signature' => md5(time()),
70 ],
71 ]);
72 } catch (Exception $e) {
73 // silently catch the error
74 return false;
75 }
76
77 return true;
78 }
79 }
80