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/models/shortcode.php +27 -6 1.6.4 → 1.8.16 View file →
@@ -84,8 +84,14 @@
84 84
85 85 // obtain view title
86 86 $data->title = (string) $form->getXml()->layout->attributes()->title;
87 87
88 + // get form data
89 + $formData = $input->get('jform', [], 'array');
90 +
91 + // get input filter
92 + $inputFilter = JInputFilter::getInstance();
93 +
88 94 // iterate the layout fields
89 95 foreach ($form->getFields() as $field)
90 96 {
91 97 $attrs = $field->attributes();
@@ -99,16 +105,30 @@
99 105 {
100 106 $filter = 'string';
101 107 }
102 108
103 - // get field from request
104 - $data->json[$name] = $input->get($name, '', $filter);
109 + if (isset($formData[$name]))
110 + {
111 + // clean filter in request
112 + $value = $inputFilter->clean($formData[$name], $filter);
113 + }
114 + else
115 + {
116 + // use NULL
117 + $value = null;
118 + }
105 119
106 120 // raise an exception if a mandatory field is empty
107 - if (empty($data->json[$name]) && $req == 'true')
121 + if (empty($value) && $req == 'true')
108 122 {
109 123 throw new Exception("Missing required [$name] field.", 400);
110 124 }
125 +
126 + // save value only if not NULL
127 + if ($value !== null)
128 + {
129 + $data->json[$name] = $value;
130 + }
111 131 }
112 132
113 133 $viewData = array();
114 134 $viewData['view'] = $data->type;
@@ -153,14 +173,14 @@
153 173 * Creates or updates the specified record.
154 174 *
155 175 * @param object &$data The record to insert.
156 176 *
157 - * @return boolean True if the record has been inserted/updated, otherwise false.
177 + * @return mixed The ID of the inserted record on success, false otherwise.
158 178 */
159 179 public function save(&$data)
160 180 {
161 181 // get old item to get previous shortcode
162 - $old = $this->getItem($data->id);
182 + $old = ($data->id ?? 0) ? $this->getItem($data->id) : null;
163 183
164 184 // save shortcode
165 185 $res = parent::save($data);
166 186
@@ -232,8 +252,10 @@
232 252
233 253 // get the form
234 254 $form = parent::getForm();
235 255
256 + $form->setFormControl('jform');
257 +
236 258 // reset the vars (it will be taken later if needed)
237 259 $this->_name = null;
238 260 $this->_client = null;
239 261
@@ -285,9 +307,8 @@
285 307 }
286 308
287 309 return $ancestors;
288 310 }
289 -
290 311
291 312 /**
292 313 * Creates a page on WordPress with for each requested shortcode.
293 314 * This is useful to automatically link Shortcodes in pages with no manual actions.