PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 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 All 37 releases
← All changes | admin/helpers/src/notification/elements.php +77 -10 1.7.1 → 1.8.16 View file →
@@ -14,10 +14,11 @@
14 14 /**
15 15 * Notification elements registry to store a record for the Notification Center.
16 16 *
17 17 * @since 1.16.8 (J) - 1.6.8 (WP)
18 + * @since 1.18.3 (J) - 1.8.3 (WP) refactoring makes the class no longer "final".
18 19 */
19 -final class VBONotificationElements extends JObject
20 +class VBONotificationElements extends JObject
20 21 {
21 22 /**
22 23 * Valid notification group enumerations.
23 24 *
@@ -37,8 +38,12 @@
37 38 // notifications from (PMS) Reports
38 39 'reports',
39 40 // notifications from AI
40 41 'ai',
42 + // notifications from Door Access Control
43 + 'dac',
44 + // notifications from any Webhook event
45 + 'webhook',
41 46 ];
42 47
43 48 /**
44 49 * Default notification type.
@@ -47,8 +52,35 @@
47 52 */
48 53 private $defaultType = 'info';
49 54
50 55 /**
56 + * Constructs the proper notification elements object according to the notification type.
57 + *
58 + * @param array|object $notification The notification properties.
59 + *
60 + * @return VBONotificationElements
61 + *
62 + * @since 1.18.3 (J) - 1.8.3 (WP)
63 + */
64 + public static function getInstance($notification)
65 + {
66 + $notification = (array) $notification;
67 +
68 + // access the notification type
69 + $type = ucfirst(preg_replace('/[^a-z0-9]+/', '', strtolower((string) ($notification['type'] ?? 'null'))));
70 +
71 + // build the expected notification class name
72 + $ncn = __CLASS__ . $type;
73 +
74 + if (class_exists($ncn)) {
75 + return new $ncn($notification);
76 + }
77 +
78 + // construct a "generic" notification elements object
79 + return new static($notification);
80 + }
81 +
82 + /**
51 83 * Determines and returns the group to which the notification belongs.
52 84 *
53 85 * @return string
54 86 */
@@ -92,9 +124,9 @@
92 124 */
93 125 public function getTitle()
94 126 {
95 127 // access the notification title
96 - $title = (string) $this->get('title', '');
128 + $title = strip_tags((string) $this->get('title', ''));
97 129
98 130 // try to guess the title
99 131 if (!$title) {
100 132 // check for virtual credit card balance
@@ -117,9 +149,9 @@
117 149 */
118 150 public function getSummary()
119 151 {
120 152 // access the notification summary
121 - $summary = (string) $this->get('summary', '');
153 + $summary = strip_tags((string) $this->get('summary', ''));
122 154
123 155 // normalize the summary, if needed
124 156 if ($summary && $this->getChannel() && !strcasecmp($this->getType(), 'lvf')) {
125 157 // listing verification framework (LVF)
@@ -130,8 +162,27 @@
130 162 return $this->shortenString($summary, 256);
131 163 }
132 164
133 165 /**
166 + * Returns the notification avatar URI.
167 + *
168 + * @return string
169 + *
170 + * @since 1.18.0 (J) - 1.8.0 (WP)
171 + */
172 + public function getAvatar()
173 + {
174 + // access the notification avatar
175 + $avatar = (string) $this->get('avatar', '');
176 +
177 + // turn full internal URIs into relative URIs
178 + $avatar = str_replace(JUri::root(), '', $avatar);
179 +
180 + // ensure the maximum length of 256 chars is respected
181 + return $this->shortenString($avatar, 256);
182 + }
183 +
184 + /**
134 185 * Builds and returns the notification call-to-action data.
135 186 *
136 187 * @return null|string
137 188 */
@@ -280,19 +331,22 @@
280 331 /**
281 332 * Builds, sets and returns the notification signature.
282 333 *
283 334 * @return string
335 + *
336 + * @since 1.18.3 (J) - 1.8.3 (WP) signature also contains "idorderota".
284 337 */
285 338 public function buildSignature()
286 339 {
287 340 // build notification signature elements
288 341 $elements = [
289 - 'id' => $this->get('id', $this->get('notification_id', 0)),
290 - 'idorder' => $this->get('idorder', 0),
291 - 'sender' => $this->get('sender', ''),
292 - 'type' => $this->get('type', ''),
293 - 'title' => $this->get('title', ''),
294 - 'summary' => $this->get('summary', ''),
342 + 'id' => $this->get('id', $this->get('notification_id', 0)),
343 + 'idorder' => $this->get('idorder', 0),
344 + 'idorderota' => $this->get('idorderota', 0),
345 + 'sender' => $this->get('sender', ''),
346 + 'type' => $this->get('type', ''),
347 + 'title' => $this->get('title', ''),
348 + 'summary' => $this->get('summary', ''),
295 349 ];
296 350
297 351 // build notification signature string
298 352 $signature = md5(serialize($elements));
@@ -303,8 +357,21 @@
303 357 return $signature;
304 358 }
305 359
306 360 /**
361 + * Method invoked after storing a notification for eventually executing actions.
362 + * Specific notification (class) types should implement their own actions.
363 + *
364 + * @return void
365 + *
366 + * @since 1.18.3 (J) - 1.8.3 (WP)
367 + */
368 + public function postflight()
369 + {
370 + return;
371 + }
372 +
373 + /**
307 374 * Returns the notification error code.
308 375 *
309 376 * @return int
310 377 */
@@ -333,9 +400,9 @@
333 400 * @param string $fallback optional string to replace as fallback.
334 401 *
335 402 * @return string
336 403 */
337 - private function shortenString(string $value, int $length, string $fallback = null)
404 + private function shortenString(string $value, int $length, string $fallback = '')
338 405 {
339 406 if (strlen($value) <= $length || $length <= 0) {
340 407 // length is safe
341 408 return $value;