PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.2
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | classes/Visualizer/Source.php +125 -16 3.1.33.4.2 View file →
@@ -57,8 +57,16 @@
57 57 */
58 58 protected $_series = array();
59 59
60 60 /**
61 + * The error message.
62 + *
63 + * @access protected
64 + * @var string
65 + */
66 + protected $_error;
67 +
68 + /**
61 69 * Return allowed types
62 70 *
63 71 * @since 1.0.1
64 72 *
@@ -83,9 +91,9 @@
83 91 * @return boolean TRUE if sereis types are valid, otherwise FALSE.
84 92 */
85 93 protected static function _validateTypes( $types ) {
86 94 foreach ( $types as $type ) {
87 - if ( ! in_array( $type, self::$allowed_types ) ) {
95 + if ( ! in_array( $type, self::$allowed_types, true ) ) {
88 96 return false;
89 97 }
90 98 }
91 99
@@ -193,9 +201,8 @@
193 201 * @return array Normalized row of data.
194 202 */
195 203 protected function _normalizeData( $data ) {
196 204 // normalize values
197 - // error_log(print_r($data,true));
198 205 foreach ( $this->_series as $i => $series ) {
199 206 // if no value exists for the seires, then add null
200 207 if ( ! isset( $data[ $i ] ) ) {
201 208 $data[ $i ] = null;
@@ -207,9 +214,10 @@
207 214 case 'number':
208 215 $data[ $i ] = ( is_numeric( $data[ $i ] ) ) ? floatval( $data[ $i ] ) : ( is_numeric( str_replace( ',', '', $data[ $i ] ) ) ? floatval( str_replace( ',', '', $data[ $i ] ) ) : null );
209 216 break;
210 217 case 'boolean':
211 - $data[ $i ] = ! empty( $data[ $i ] ) ? filter_var( $data[ $i ], FILTER_VALIDATE_BOOLEAN ) : null;
218 + $datum = trim( strval( $data[ $i ] ) );
219 + $data[ $i ] = in_array( $datum, array( 'true', 'yes', '1' ), true ) ? 'true' : 'false';
212 220 break;
213 221 case 'timeofday':
214 222 $date = new DateTime( '1984-03-16T' . $data[ $i ] );
215 223 if ( $date ) {
@@ -220,8 +228,15 @@
220 228 0,
221 229 );
222 230 }
223 231 break;
232 + case 'datetime':
233 + // let's check if the date is a Unix epoch
234 + $value = DateTime::createFromFormat( 'U', $data[ $i ] );
235 + if ( $value !== false && ! is_wp_error( $value ) ) {
236 + $data[ $i ] = $value->format( 'Y-m-d H:i:s' );
237 + }
238 + break;
224 239 case 'string':
225 240 $data[ $i ] = $this->toUTF8( $data[ $i ] );
226 241 break;
227 242 }
@@ -226,10 +241,9 @@
226 241 break;
227 242 }
228 243 }
229 244
230 - // error_log(print_r($data,true));
231 - return $data;
245 + return apply_filters( 'visualizer_format_data', $data, $this->_series );
232 246 }
233 247
234 248
235 249 /**
@@ -262,9 +276,9 @@
262 276 $date_formats = array();
263 277 $types = array();
264 278 $index = 0;
265 279 foreach ( $series as $column ) {
266 - if ( in_array( $column['type'], array( 'date', 'datetime', 'timeofday' ) ) ) {
280 + if ( in_array( $column['type'], array( 'date', 'datetime', 'timeofday' ), true ) ) {
267 281 $types[] = array( 'index' => $index, 'type' => $column['type'] );
268 282 }
269 283 $index++;
270 284 }
@@ -277,9 +291,9 @@
277 291 // let's randomly pick 5 data points instead of cycling through the entire data set.
278 292 if ( count( $data ) > 5 ) {
279 293 $random = array();
280 294 for ( $x = 0; $x < 5; $x++ ) {
281 - $random = $data[ rand( 0, count( $data ) - 1 ) ];
295 + $random[] = $data[ rand( 0, count( $data ) - 1 ) ];
282 296 }
283 297 }
284 298
285 299 foreach ( $types as $type ) {
@@ -315,8 +329,9 @@
315 329 * @return string|null
316 330 */
317 331 private static final function determine_date_format( $value, $type ) {
318 332 if ( version_compare( phpversion(), '5.3.0', '<' ) ) {
333 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'PHP version %s not supported', phpversion() ), 'error', __FILE__, __LINE__ );
319 334 return null;
320 335 }
321 336
322 337 $formats = array(
@@ -329,19 +344,24 @@
329 344 );
330 345
331 346 switch ( $type ) {
332 347 case 'datetime':
333 - $formats += array(
334 - 'Y/m/d H:i:s',
335 - 'Y-m-d H:i:s',
336 - 'm/d/Y H:i:s',
337 - 'm-d-Y H:i:s',
348 + $formats = array_merge(
349 + $formats, array(
350 + 'U',
351 + 'Y/m/d H:i:s',
352 + 'Y-m-d H:i:s',
353 + 'm/d/Y H:i:s',
354 + 'm-d-Y H:i:s',
355 + )
338 356 );
339 357 break;
340 358 case 'timeofday':
341 - $formats += array(
342 - 'H:i:s',
343 - 'H:i',
359 + $formats = array_merge(
360 + $formats, array(
361 + 'H:i:s',
362 + 'H:i',
363 + )
344 364 );
345 365 break;
346 366 }
347 367
@@ -348,9 +368,9 @@
348 368 $formats = apply_filters( 'visualizer_date_formats', $formats, $type );
349 369
350 370 foreach ( $formats as $format ) {
351 371 $return = DateTime::createFromFormat( $format, $value );
352 - if ( $return !== false ) {
372 + if ( $return !== false && ! is_wp_error( $return ) ) {
353 373 return $format;
354 374 }
355 375 }
356 376 // invalid format
@@ -355,6 +375,95 @@
355 375 }
356 376 // invalid format
357 377 return null;
358 378 }
379 +
380 + /**
381 + * Returns the error, if any.
382 + *
383 + * @access public
384 + * @return string
385 + */
386 + public function get_error() {
387 + return $this->_error;
388 + }
389 +
390 + /**
391 + * Fetches information from the editable table and parses it to build series and data arrays.
392 + *
393 + * @since ?
394 + *
395 + * @access public
396 + * @return boolean TRUE on success, otherwise FALSE.
397 + */
398 + public function fetchFromEditableTable() {
399 + if ( empty( $this->_args ) ) {
400 + return false;
401 + }
402 +
403 + $this->_fetchSeriesFromEditableTable();
404 + $this->_fetchDataFromEditableTable();
405 + return true;
406 + }
407 +
408 + /**
409 + * Fetches series information from the editable table. This is fetched only through the UI and not while refreshing the chart data.
410 + *
411 + * @since 1.0.0
412 + *
413 + * @access private
414 + */
415 + private function _fetchSeriesFromEditableTable() {
416 + $params = $this->_args;
417 + $headers = array_filter( $params['header'] );
418 + $types = array_filter( $params['type'] );
419 + $header_row = $type_row = array();
420 + if ( $headers ) {
421 + foreach ( $headers as $header ) {
422 + if ( ! empty( $types[ $header ] ) ) {
423 + $this->_series[] = array(
424 + 'label' => $header,
425 + 'type' => $types[ $header ],
426 + );
427 + }
428 + }
429 + }
430 +
431 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Series found for %s = %s', print_r( $this->_args, true ), print_r( $this->_series, true ) ), 'debug', __FILE__, __LINE__ );
432 +
433 + return true;
434 + }
435 +
436 +
437 + /**
438 + * Fetches data information from the editable table.
439 + *
440 + * @since 1.0.0
441 + *
442 + * @access private
443 + */
444 + private function _fetchDataFromEditableTable() {
445 + $params = $this->_args;
446 + $headers = wp_list_pluck( $this->_series, 'label' );
447 + $this->fetch();
448 +
449 + $data = $this->_data;
450 + $this->_data = array();
451 +
452 + foreach ( $data as $line ) {
453 + $data_row = array();
454 + foreach ( $line as $header => $value ) {
455 + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
456 + if ( in_array( $header, $headers ) ) {
457 + $data_row[] = $value;
458 + }
459 + }
460 + $this->_data[] = $this->_normalizeData( $data_row );
461 + }
462 +
463 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Data found for %s = %s', print_r( $this->_args, true ), print_r( $this->_data, true ) ), 'debug', __FILE__, __LINE__ );
464 +
465 + return true;
466 + }
467 +
359 468
360 469 }