PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 4.0.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v4.0.1
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/Json.php +66 -12 3.10.104.0.1 View file →
@@ -320,9 +320,8 @@
320 320 $rows[] = $row;
321 321 }
322 322
323 323 return $rows;
324 -
325 324 }
326 325
327 326 /**
328 327 * Get the next page URL.
@@ -330,9 +329,9 @@
330 329 * @since ?
331 330 *
332 331 * @access private
333 332 */
334 - private function getNextPage( $array ) {
333 + private function getNextPage( $data ) {
335 334 if ( empty( $this->_paging ) ) {
336 335 return null;
337 336 }
338 337
@@ -338,12 +337,12 @@
338 337
339 338 $root = explode( self::TAG_SEPARATOR, $this->_paging );
340 339 // get rid of the first element as that is the faux root element indicator
341 340 array_shift( $root );
342 - $leaf = $array;
341 + $leaf = $data;
343 342 foreach ( $root as $tag ) {
344 343 if ( array_key_exists( $tag, $leaf ) ) {
345 - $leaf = $array[ $tag ];
344 + $leaf = $leaf[ $tag ];
346 345 } else {
347 346 // if the tag does not exist, we assume it is present in the 0th element of the current array.
348 347 // TODO: we may want to change this to a filter later.
349 348 $leaf = $leaf[0][ $tag ];
@@ -361,21 +360,21 @@
361 360 * @since ?
362 361 *
363 362 * @access private
364 363 */
365 - private function getRootElements( $parent, $now, $root, $array ) {
366 - if ( is_null( $array ) ) {
364 + private function getRootElements( $parent_key, $now, $root, $data ) {
365 + if ( is_null( $data ) ) {
367 366 return null;
368 367 }
369 368
370 - $root[] = $parent;
371 - foreach ( $array as $key => $value ) {
369 + $root[] = $parent_key;
370 + foreach ( $data as $key => $value ) {
372 371 if ( is_array( $value ) && ! empty( $value ) ) {
373 372 if ( ! is_numeric( $key ) ) {
374 - $now = sprintf( '%s%s%s', $parent, self::TAG_SEPARATOR, $key );
373 + $now = sprintf( '%s%s%s', $parent_key, self::TAG_SEPARATOR, $key );
375 374 $root[] = $now;
376 375 } else {
377 - $now = $parent;
376 + $now = $parent_key;
378 377 }
379 378 $root = $this->getRootElements( $now, $key, $root, $value );
380 379 }
381 380 }
@@ -441,9 +440,9 @@
441 440 $this->_additional_headers = explode( ',', $this->_additional_headers );
442 441 $this->_additional_headers = array_filter( $this->_additional_headers );
443 442 if ( ! empty( $this->_additional_headers ) ) {
444 443 $this->_additional_headers = array_map(
445 - function( $headers ) {
444 + function ( $headers ) {
446 445 $headers = explode( ':', $headers );
447 446 $headers = array_map( 'trim', $headers );
448 447 return $headers;
449 448 },
@@ -456,8 +455,19 @@
456 455 }
457 456 }
458 457 }
459 458
459 + // Check if this is a WooCommerce endpoint request and add verification token.
460 + if ( $this->is_woocommerce_request( $url ) ) {
461 + // Generate a unique token for this specific request.
462 + $token = wp_generate_password( 32, false );
463 + set_transient( 'visualizer_wc_token_' . $token, time(), 60 );
464 + if ( ! isset( $args['headers'] ) ) {
465 + $args['headers'] = array();
466 + }
467 + $args['headers']['X-Visualizer-Token'] = $token;
468 + }
469 +
460 470 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Connecting to %s with args = %s ', $url, print_r( $args, true ) ), 'debug', __FILE__, __LINE__ );
461 471 return wp_remote_request( $url, $args );
462 472 }
463 473
@@ -488,8 +498,53 @@
488 498 return true;
489 499 }
490 500
491 501 /**
502 + * Check if the URL is a WooCommerce endpoint request.
503 + *
504 + * @access private
505 + * @param string $url The URL to check.
506 + * @return bool True if it's a WooCommerce request, false otherwise.
507 + */
508 + private function is_woocommerce_request( $url ) {
509 + if ( empty( $url ) ) {
510 + return false;
511 + }
512 +
513 + $parsed_url = function_exists( 'wp_parse_url' ) ? wp_parse_url( $url ) : parse_url( $url );
514 + if ( empty( $parsed_url ) || empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) ) {
515 + return false;
516 + }
517 +
518 + $site_url = function_exists( 'home_url' ) ? home_url() : ( function_exists( 'site_url' ) ? site_url() : '' );
519 + $site_parts = $site_url ? ( function_exists( 'wp_parse_url' ) ? wp_parse_url( $site_url ) : parse_url( $site_url ) ) : array();
520 + if ( empty( $site_parts['host'] ) ) {
521 + return false;
522 + }
523 +
524 + $target_host = strtolower( $parsed_url['host'] );
525 + $site_host = strtolower( $site_parts['host'] );
526 + if ( $target_host !== $site_host ) {
527 + return false;
528 + }
529 +
530 + $path = '/' . ltrim( $parsed_url['path'], '/' );
531 + $wc_patterns = array(
532 + '/wp-json/wc/',
533 + '/wp-json/wc-analytics/',
534 + '/wc-analytics/',
535 + );
536 +
537 + foreach ( $wc_patterns as $pattern ) {
538 + if ( strpos( $path, $pattern ) !== false ) {
539 + return true;
540 + }
541 + }
542 +
543 + return false;
544 + }
545 +
546 + /**
492 547 * Returns source name.
493 548 *
494 549 * @since 1.0.0
495 550 *
@@ -498,6 +553,5 @@
498 553 */
499 554 public function getSourceName() {
500 555 return __CLASS__;
501 556 }
502 -
503 557 }