PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.4
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.4
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 3.10.4 All 148 releases
← All changes | classes/Visualizer/Source.php +45 -15 3.1.33.3.4 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;
@@ -220,8 +227,15 @@
220 227 0,
221 228 );
222 229 }
223 230 break;
231 + case 'datetime':
232 + // let's check if the date is a Unix epoch
233 + $value = DateTime::createFromFormat( 'U', $data[ $i ] );
234 + if ( $value !== false && ! is_wp_error( $value ) ) {
235 + $data[ $i ] = $value->format( 'Y-m-d H:i:s' );
236 + }
237 + break;
224 238 case 'string':
225 239 $data[ $i ] = $this->toUTF8( $data[ $i ] );
226 240 break;
227 241 }
@@ -226,10 +240,9 @@
226 240 break;
227 241 }
228 242 }
229 243
230 - // error_log(print_r($data,true));
231 - return $data;
244 + return apply_filters( 'visualizer_format_data', $data, $this->_series );
232 245 }
233 246
234 247
235 248 /**
@@ -262,9 +275,9 @@
262 275 $date_formats = array();
263 276 $types = array();
264 277 $index = 0;
265 278 foreach ( $series as $column ) {
266 - if ( in_array( $column['type'], array( 'date', 'datetime', 'timeofday' ) ) ) {
279 + if ( in_array( $column['type'], array( 'date', 'datetime', 'timeofday' ), true ) ) {
267 280 $types[] = array( 'index' => $index, 'type' => $column['type'] );
268 281 }
269 282 $index++;
270 283 }
@@ -277,9 +290,9 @@
277 290 // let's randomly pick 5 data points instead of cycling through the entire data set.
278 291 if ( count( $data ) > 5 ) {
279 292 $random = array();
280 293 for ( $x = 0; $x < 5; $x++ ) {
281 - $random = $data[ rand( 0, count( $data ) - 1 ) ];
294 + $random[] = $data[ rand( 0, count( $data ) - 1 ) ];
282 295 }
283 296 }
284 297
285 298 foreach ( $types as $type ) {
@@ -315,8 +328,9 @@
315 328 * @return string|null
316 329 */
317 330 private static final function determine_date_format( $value, $type ) {
318 331 if ( version_compare( phpversion(), '5.3.0', '<' ) ) {
332 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'PHP version %s not supported', phpversion() ), 'error', __FILE__, __LINE__ );
319 333 return null;
320 334 }
321 335
322 336 $formats = array(
@@ -329,19 +343,24 @@
329 343 );
330 344
331 345 switch ( $type ) {
332 346 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',
347 + $formats = array_merge(
348 + $formats, array(
349 + 'U',
350 + 'Y/m/d H:i:s',
351 + 'Y-m-d H:i:s',
352 + 'm/d/Y H:i:s',
353 + 'm-d-Y H:i:s',
354 + )
338 355 );
339 356 break;
340 357 case 'timeofday':
341 - $formats += array(
342 - 'H:i:s',
343 - 'H:i',
358 + $formats = array_merge(
359 + $formats, array(
360 + 'H:i:s',
361 + 'H:i',
362 + )
344 363 );
345 364 break;
346 365 }
347 366
@@ -348,9 +367,9 @@
348 367 $formats = apply_filters( 'visualizer_date_formats', $formats, $type );
349 368
350 369 foreach ( $formats as $format ) {
351 370 $return = DateTime::createFromFormat( $format, $value );
352 - if ( $return !== false ) {
371 + if ( $return !== false && ! is_wp_error( $return ) ) {
353 372 return $format;
354 373 }
355 374 }
356 375 // invalid format
@@ -355,6 +374,17 @@
355 374 }
356 375 // invalid format
357 376 return null;
358 377 }
378 +
379 + /**
380 + * Returns the error, if any.
381 + *
382 + * @access public
383 + * @return string
384 + */
385 + public function get_error() {
386 + return $this->_error;
387 + }
388 +
359 389
360 390 }