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/multitask/parser.php +88 -0 1.6.4 → 1.8.16 View file →
@@ -64,8 +64,67 @@
64 64 return static::$instance;
65 65 }
66 66
67 67 /**
68 + * Those pages capable of receiving data for a clicked Push notification through
69 + * query string can use this method to quickly validate and parse the admin widget
70 + * to load and the multitask data + options to set for rendering the information.
71 + *
72 + * @param array $data associative list of multitask data.
73 + * @param mixed $payload JSON-encoded string or decoded object payload.
74 + *
75 + * @return array numeric list of widget ID, data and options.
76 + *
77 + * @since 1.16.5 (J) - 1.6.5 (WP)
78 + */
79 + public static function queryPushData(array $data, $payload)
80 + {
81 + $parsed = [
82 + 'widget_id' => '',
83 + 'multitask_data' => $data,
84 + 'multitask_options' => [],
85 + ];
86 +
87 + if (empty($payload)) {
88 + // do not proceed
89 + return array_values($parsed);
90 + }
91 +
92 + if (is_string($payload)) {
93 + // attempt to JSON-decode the payload encoded string
94 + $decoded_payload = json_decode($payload);
95 +
96 + /**
97 + * Payloads may have been previously encoded in base64, which expects binary data as its input.
98 + * In case of titles or messages in the Push notification payload with multi-byte characters,
99 + * JSON-decoding the string that was base64-decoded, may result into malformed UTF-8 characters.
100 + * In this case, we will try to convert any character to ASCII by ignoring what's not UTF-8.
101 + */
102 + if (json_last_error() && json_last_error() === JSON_ERROR_UTF8) {
103 + // try to convert the encoding from UTF-8 to any ASCII
104 + $payload = json_decode(@iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", $payload));
105 + } else {
106 + // assign the properly decoded value
107 + $payload = $decoded_payload;
108 + }
109 + }
110 +
111 + if (is_object($payload) && isset($payload->type) && (isset($payload->title) || isset($payload->message))) {
112 + // determine the type of widget that should handle the notification data
113 + $parsed['widget_id'] = $payload->type == 'Chat' ? 'guest_messages' : 'booking_details';
114 +
115 + // extract and remove raw content from payload
116 + $raw_content = isset($payload->content) ? (array)$payload->content : [];
117 + unset($payload->content);
118 +
119 + // build multitask options
120 + $parsed['multitask_options'] = array_merge(['_push' => 1], (array)$payload, $raw_content);
121 + }
122 +
123 + return array_values($parsed);
124 + }
125 +
126 + /**
68 127 * Class constructor.
69 128 *
70 129 * @param string $page the name of the view/task.
71 130 * @param string $uri the page URI to parse.
@@ -93,8 +152,18 @@
93 152 * @since 1.16.0 (J) - 1.6.0 (WP)
94 153 */
95 154 $injected_data = JFactory::getApplication()->input->get('multitask_data', [], 'array');
96 155
156 + // extra the options for multitask data, if any
157 + $data_options = [];
158 + if (isset($injected_data['_options'])) {
159 + // access the options received
160 + $data_options = (array)$injected_data['_options'];
161 +
162 + // separate options layer from regular data
163 + unset($injected_data['_options']);
164 + }
165 +
97 166 // get a new multitask data object instance
98 167 $multitask_data = new VBOMultitaskData($injected_data);
99 168
100 169 // inject current page values
@@ -107,10 +176,29 @@
107 176 if ($page_booking_id) {
108 177 $multitask_data->setBookingId($page_booking_id);
109 178 }
110 179
180 + /**
181 + * Register a separate layer of data that will serve as multitask options.
182 + *
183 + * @since 1.16.5 (J) - 1.6.5 (WP)
184 + */
185 + $multitask_data->registerDataOptions($data_options);
186 +
111 187 // return the data object for the admin widget
112 188 return $multitask_data;
189 + }
190 +
191 + /**
192 + * Binds data to the multitask options object and returns it.
193 + *
194 + * @return VBOMultitaskOptions
195 + *
196 + * @since 1.16.5 (J) - 1.6.5 (WP)
197 + */
198 + public function getOptions()
199 + {
200 + return VBOMultitaskOptions::getInstance(JFactory::getApplication()->input->get('_options', [], 'array'));
113 201 }
114 202
115 203 /**
116 204 * Gets the current name of the view/task.