PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.8
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.8
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/Render/Layout.php +253 -538 4.0.53.4.8 View file →
@@ -27,15 +27,8 @@
27 27 */
28 28 class Visualizer_Render_Layout extends Visualizer_Render {
29 29
30 30 /**
31 - * Fallback time for live update option.
32 - *
33 - * @var float
34 - */
35 - public static $live_option_fallback_hour = 0.16; // 10 minutes
36 -
37 - /**
38 31 * Renders template.
39 32 *
40 33 * @since 1.0.0
41 34 *
@@ -60,19 +53,9 @@
60 53 *
61 54 * @access public
62 55 */
63 56 public static function _renderDbQuery( $args ) {
64 - global $wpdb;
65 57 $query = $args[1];
66 - if ( ! $query ) {
67 - $query = '
68 -/* List Posts published per. month */
69 -SELECT CONCAT( YEAR(post_date), "/", MONTH(post_date) ) as date, COUNT(*) AS post_count
70 -FROM ' . $wpdb->prefix . 'posts
71 -WHERE post_type = "post" AND post_status = "publish"
72 -GROUP BY YEAR(post_date), MONTH(post_date)
73 -ORDER BY YEAR(post_date) DESC, MONTH(post_date) DESC;';
74 - }
75 58 ?>
76 59 <div id='visualizer-db-query' style="display: none">
77 60 <div class="visualizer-db-query-form">
78 61 <div>
@@ -88,29 +71,10 @@
88 71 </div>
89 72 </div>
90 73 <div class='db-wizard-hints'>
91 74 <ul>
92 - <li><?php echo __( 'Your database prefix is:', 'visualizer' ); ?> <span class="visualizer-emboss"><?php echo $wpdb->prefix; ?></span></li>
93 - <li>
94 - <?php
95 - echo sprintf(
96 - // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
97 - __( 'For examples of queries and links to resources that you can use with this feature, please click %1$shere%2$s', 'visualizer' ),
98 - '<a href="' . VISUALIZER_DB_QUERY_DOC_URL . '" target="_blank">',
99 - '</a>'
100 - );
101 - ?>
102 - </li>
103 - <li>
104 - <?php
105 - echo sprintf(
106 - // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
107 - __( 'Use %1$sShift+Space%2$s for autocompleting keywords or table names.', 'visualizer' ),
108 - '<span class="visualizer-emboss">',
109 - '</span>'
110 - );
111 - ?>
112 - </li>
75 + <li><?php echo sprintf( __( 'For examples of queries and links to resources that you can use with this feature, please click %1$shere%2$s', 'visualizer' ), '<a href="' . VISUALIZER_DB_QUERY_DOC_URL . '" target="_blank">', '</a>' ); ?></li>
76 + <li><?php echo sprintf( __( 'Use %1$sControl+Space%2$s for autocompleting keywords or table names.', 'visualizer' ), '<span class="visualizer-emboss">', '</span>' ); ?></li>
113 77 <?php do_action( 'visualizer_db_query_add_hints', $args ); ?>
114 78 </ul>
115 79 </div>
116 80 <div class='db-wizard-results'></div>
@@ -140,9 +104,9 @@
140 104 </tr>
141 105 </thead>
142 106 <tfoot>
143 107 </tfoot>
144 - <tbody>
108 + <tbody>
145 109 <?php
146 110 foreach ( $results as $result ) {
147 111 echo '<tr>';
148 112 foreach ( $result as $r ) {
@@ -163,20 +127,17 @@
163 127 * @access public
164 128 */
165 129 public static function _renderJsonScreen( $args ) {
166 130 $id = $args[1];
167 - $action = esc_url(
168 - add_query_arg(
169 - array(
170 - 'action' => Visualizer_Plugin::ACTION_JSON_SET_DATA,
171 - 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_SET_DATA . Visualizer_Plugin::VERSION ),
172 - 'chart' => $id,
173 - ),
174 - admin_url( 'admin-ajax.php' )
175 - )
131 + $action = add_query_arg(
132 + array(
133 + 'action' => Visualizer_Plugin::ACTION_JSON_SET_DATA,
134 + 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_SET_DATA . Visualizer_Plugin::VERSION ),
135 + 'chart' => $id,
136 + ),
137 + admin_url( 'admin-ajax.php' )
176 138 );
177 139
178 - $is_wc_source = get_post_meta( $id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true );
179 140 $url = get_post_meta( $id, Visualizer_Plugin::CF_JSON_URL, true );
180 141 $root = get_post_meta( $id, Visualizer_Plugin::CF_JSON_ROOT, true );
181 142 $paging = get_post_meta( $id, Visualizer_Plugin::CF_JSON_PAGING, true );
182 143 $headers = get_post_meta( $id, Visualizer_Plugin::CF_JSON_HEADERS, true );
@@ -197,18 +158,9 @@
197 158 <div>
198 159 <form id="json-endpoint-form">
199 160 <div class="json-wizard-hints">
200 161 <ul class="info">
201 - <li>
202 - <?php
203 - echo sprintf(
204 - // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
205 - __( 'If you want to add authentication or headers to the endpoint or change the request in any way, please refer to our document %1$shere%2$s.', 'visualizer' ),
206 - '<a href="https://docs.themeisle.com/article/1043-visualizer-how-to-extend-rest-endpoints-with-json-response" target="_blank">',
207 - '</a>'
208 - );
209 - ?>
210 - </li>
162 + <li><?php echo sprintf( __( 'If you want to add authentication or headers to the endpoint or change the request in any way, please refer to our document %1$shere%2$s.', 'visualizer' ), '<a href="https://docs.themeisle.com/article/1043-visualizer-how-to-extend-rest-endpoints-with-json-response" target="_blank">', '</a>' ); ?></li>
211 163 </ul>
212 164 </div>
213 165
214 166 <input
@@ -216,13 +168,11 @@
216 168 id="vz-import-json-url"
217 169 name="url"
218 170 value="<?php echo esc_url( $url ); ?>"
219 171 placeholder="<?php esc_html_e( 'Please enter the URL', 'visualizer' ); ?>"
220 - class="visualizer-input json-form-element"
221 - <?php echo $is_wc_source ? 'readonly' : ''; ?>
222 - >
172 + class="visualizer-input json-form-element">
223 173 <button class="button button-secondary button-small" id="visualizer-json-fetch"><?php esc_html_e( 'Fetch Endpoint', 'visualizer' ); ?></button>
224 -
174 +
225 175 <div class="visualizer-json-subform">
226 176 <h3 class="viz-substep <?php echo $headers_open ? 'open' : ''; ?>"><?php _e( 'Headers', 'visualizer' ); ?></h3>
227 177 <div class="json-wizard-headers">
228 178 <div class="json-wizard-header">
@@ -243,9 +193,9 @@
243 193 id="vz-import-json-username"
244 194 name="username"
245 195 value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'username', $headers['auth'] ) ? $headers['auth']['username'] : '' ); ?>"
246 196 placeholder="<?php esc_html_e( 'Username/Access Key', 'visualizer' ); ?>"
247 - class="json-form-element">
197 + class="json-form-element">
248 198 &
249 199 <input
250 200 type="password"
251 201 id="vz-import-json-password"
@@ -251,9 +201,9 @@
251 201 id="vz-import-json-password"
252 202 name="password"
253 203 value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'password', $headers['auth'] ) ? $headers['auth']['password'] : '' ); ?>"
254 204 placeholder="<?php esc_html_e( 'Password/Secret Key', 'visualizer' ); ?>"
255 - class="json-form-element">
205 + class="json-form-element">
256 206 </div>
257 207 </div>
258 208 <div class="json-wizard-header">
259 209 <div></div>
@@ -270,14 +220,8 @@
270 220 placeholder="<?php esc_html_e( 'e.g. SharedKey <AccountName>:<Signature>', 'visualizer' ); ?>"
271 221 class="visualizer-input json-form-element">
272 222 </div>
273 223 </div>
274 - <div class="json-wizard-header">
275 - <div class="field-title"><?php esc_html_e( 'Additional headers', 'visualizer' ); ?></div>
276 - <div>
277 - <textarea name="additional_headers" class="visualizer-input" placeholder="<?php esc_html_e( 'Key:Value, Key2:Value2,...', 'visualizer' ); ?>"><?php echo isset( $headers['additional_headers'] ) ? $headers['additional_headers'] : ''; ?></textarea>
278 - </div>
279 - </div>
280 224 </div>
281 225 </div>
282 226 </form>
283 227 </div>
@@ -355,17 +299,15 @@
355 299 * @access public
356 300 */
357 301 public static function _renderSimpleEditorScreen( $args ) {
358 302 $chart_id = $args[1];
359 - $action = esc_url(
360 - add_query_arg(
361 - array(
362 - 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
363 - 'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
364 - 'chart' => $chart_id,
365 - ),
366 - admin_url( 'admin-ajax.php' )
367 - )
303 + $action = add_query_arg(
304 + array(
305 + 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
306 + 'nonce' => wp_create_nonce(),
307 + 'chart' => $chart_id,
308 + ),
309 + admin_url( 'admin-ajax.php' )
368 310 );
369 311 ?>
370 312 <div class="viz-simple-editor">
371 313 <div class="viz-simple-editor-type viz-table-editor">
@@ -389,8 +331,9 @@
389 331 <?php Visualizer_Render_Layout::show( 'text-editor', $chart_id ); ?>
390 332
391 333 </div>
392 334 <?php
335 +
393 336 }
394 337
395 338 /**
396 339 * Show the text area editor.
@@ -463,9 +406,9 @@
463 406 }
464 407 ?>
465 408 </tr>
466 409 </thead>
467 - <tbody>
410 + <tbody>
468 411 <tr>
469 412 <th><?php _e( 'Data Type', 'visualizer' ); ?></th>
470 413 <?php
471 414 $index = 0;
@@ -530,9 +473,9 @@
530 473 private static function _renderPermissions( $args ) {
531 474 $chart_id = $args[1];
532 475
533 476 // ignore for unit tests because Travis throws the error "Indirect modification of overloaded property Visualizer_Render_Page_Data::$permissions has no effect".
534 - if ( defined( 'WP_TESTS_DOMAIN' ) && function_exists( 'tests_add_filter' ) ) {
477 + if ( defined( 'WP_TESTS_DOMAIN' ) ) {
535 478 return;
536 479 }
537 480
538 481 $permissions = apply_filters( 'visualizer_pro_get_permissions', null, $chart_id );
@@ -615,9 +558,9 @@
615 558 true,
616 559 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-edit-specific' )
617 560 );
618 561 Visualizer_Render_Sidebar::_renderSectionEnd();
619 - echo apply_filters( 'visualizer_pro_upsell', '', 'chart-permissions', 'https://docs.themeisle.com/article/1280-how-to-customize-permissions' );
562 + echo apply_filters( 'visualizer_pro_upsell', '', 'chart-permissions' );
620 563 echo '</div>';
621 564 Visualizer_Render_Sidebar::_renderGroupEnd();
622 565 }
623 566
@@ -626,27 +569,20 @@
626 569 *
627 570 * @access public
628 571 */
629 572 public static function _renderTabAdvanced( $args ) {
630 - $chart_id = $args[1];
631 - $sidebar = $args[2];
632 -
633 - $chart_options = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
634 - $backend_title = isset( $chart_options['backend-title'] ) && ! empty( $chart_options['backend-title'] ) ? $chart_options['backend-title'] : '';
635 -
573 + $sidebar = $args[2];
636 574 ?>
637 575 <ul class="viz-group-wrapper full-height">
638 576 <li class="viz-group open" id="vz-chart-settings">
639 577 <ul class="viz-group-content">
640 578 <ul class="viz-group-wrapper">
641 - <form id="settings-form" action="<?php echo esc_url( add_query_arg( 'nonce', wp_create_nonce() ) ); ?>" method="post">
642 - <input type="hidden" id="chart-img" name="chart-img">
643 - <input type="hidden" id="backend-title" name="backend-title" value="<?php echo esc_html( $backend_title ); ?>">
579 + <form id="settings-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>" method="post">
644 580 <?php echo $sidebar; ?>
645 581 <?php self::_renderPermissions( $args ); ?>
646 582 <input type="hidden" name="save" value="1">
647 583 </form>
648 - <form id="cancel-form" action="<?php echo esc_url( add_query_arg( 'nonce', wp_create_nonce() ) ); ?>" method="post">
584 + <form id="cancel-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>" method="post">
649 585 <input type="hidden" name="cancel" value="1">
650 586 </form>
651 587 </ul>
652 588 </ul>
@@ -687,22 +623,12 @@
687 623 <h4><span class="dashicons dashicons-editor-help"></span><a href="<?php echo VISUALIZER_MAIN_DOC; ?>" target="_blank"><?php _e( 'Main documentation page', 'visualizer' ); ?></a></h4>
688 624 <h4><span class="dashicons dashicons-media-code"></span><a href="<?php echo VISUALIZER_CODE_SNIPPETS_URL; ?>" target="_blank"><?php _e( 'Custom code snippets', 'visualizer' ); ?></a></h4>
689 625 <?php
690 626 Visualizer_Render_Sidebar::_renderSectionEnd();
691 - // translators: %s - the chart type.
692 627 Visualizer_Render_Sidebar::_renderSectionStart( sprintf( __( '%s chart', 'visualizer' ), ucwords( $displayType ) ), true );
693 628 ?>
694 629 <h4><span class="dashicons dashicons-video-alt2"></span>&nbsp;<a href="<?php echo str_replace( '#', "$type-chart", VISUALIZER_DEMO_URL ); ?>" target="_blank"><?php _e( 'View demo', 'visualizer' ); ?></a></h4>
695 - <h4><span class="dashicons dashicons-search"></span><a href="<?php echo str_replace( '#', $type, VISUALIZER_DOC_COLLECTION ); ?>" target="_blank">
696 - <?php
697 - echo sprintf(
698 - // translators: %s - the chart type.
699 - __( 'Articles containing "%s"', 'visualizer' ),
700 - $displayType
701 - );
702 - ?>
703 - </a>
704 - </h4>
630 + <h4><span class="dashicons dashicons-search"></span><a href="<?php echo str_replace( '#', $type, VISUALIZER_DOC_COLLECTION ); ?>" target="_blank"><?php echo sprintf( __( 'Articles containing "%s"', 'visualizer' ), $displayType ); ?></a></h4>
705 631 <?php
706 632 Visualizer_Render_Sidebar::_renderSectionEnd();
707 633 Visualizer_Render_Sidebar::_renderGroupEnd();
708 634 ?>
@@ -720,26 +646,19 @@
720 646 */
721 647 public static function _renderTabBasic( $args ) {
722 648 $chart_id = $args[1];
723 649
724 - $upload_link = esc_url(
725 - add_query_arg(
726 - array(
727 - 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
728 - 'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
729 - 'chart' => $chart_id,
730 - ),
731 - admin_url( 'admin-ajax.php' )
732 - )
650 + $upload_link = add_query_arg(
651 + array(
652 + 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
653 + 'nonce' => wp_create_nonce(),
654 + 'chart' => $chart_id,
655 + ),
656 + admin_url( 'admin-ajax.php' )
733 657 );
734 658
735 659 // this will allow us to open the correct source tab by default.
736 - $source_of_chart = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
737 - // Import from woocommerce report.
738 - $is_woocommerce_source = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ) );
739 - if ( ! empty( $is_woocommerce_source ) ) {
740 - $source_of_chart .= '_wc';
741 - }
660 + $source_of_chart = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
742 661 // both import from wp and import from db have the same source so we need to differentiate.
743 662 $filter_config = get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true );
744 663 // if filter config is present, then its import from wp.
745 664 if ( ! empty( $filter_config ) ) {
@@ -745,12 +664,9 @@
745 664 if ( ! empty( $filter_config ) ) {
746 665 $source_of_chart .= '_wp';
747 666 }
748 667 $editor_type = get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR, true );
749 - if (
750 - $editor_type ||
751 - ! Visualizer_Module::is_pro() // Use Manual Source for non-pro users since it is the only unlocked source.
752 - ) {
668 + if ( $editor_type ) {
753 669 $source_of_chart = 'visualizer_source_manual';
754 670 }
755 671
756 672 $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
@@ -759,208 +675,125 @@
759 675 <ul class="viz-group-wrapper full-height">
760 676 <li class="viz-group open" id="vz-chart-source">
761 677 <ul class="viz-group-content">
762 678 <ul class="viz-group-wrapper">
763 - <!-- manual -->
764 - <li class="viz-group visualizer_source_manual">
765 - <h2 class="viz-group-title viz-sub-group visualizer-editor-tab" data-current="chart" role="button" tabindex="0"><?php _e( 'Manual Data', 'visualizer' ); ?></h2>
766 - <div class="viz-group-content edit-data-content">
767 - <form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
768 - <input type="hidden" id="chart-data" name="chart_data">
769 - <input type="hidden" id="chart-data-src" name="chart_data_src">
770 -
771 - <?php if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { ?>
772 - <div>
773 - <p class="viz-group-description viz-editor-selection">
774 - <?php _e( 'Use the', 'visualizer' ); ?>
775 - <select name="editor-type" id="viz-editor-type">
776 - <?php
777 - if ( empty( $editor_type ) ) {
778 - $editor_type = Visualizer_Module::is_pro() ? 'excel' : 'text';
779 - }
780 - foreach ( apply_filters( 'visualizer_editors', array( 'text' => __( 'Text', 'visualizer' ), 'table' => __( 'Simple', 'visualizer' ) ) ) as $e_type => $e_label ) {
781 - ?>
782 - <option value="<?php echo $e_type; ?>" <?php selected( $editor_type, $e_type ); ?> ><?php echo $e_label; ?></option>
783 - <?php } ?>
784 - </select>
785 - <?php _e( 'editor to manually edit the chart data.', 'visualizer' ); ?>
786 - </p>
787 - <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
788 - <input type="button" id="editor-button" class="button button-primary "
789 - value="<?php _e( 'Edit Data', 'visualizer' ); ?>" data-current="chart"
790 - data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
791 - data-t-chart="<?php _e( 'Edit Data', 'visualizer' ); ?>"
792 - >
793 - <p class="viz-group-description viz-info-msg" style="display:none"><?php echo sprintf( __( 'Please make sure you click \'Show Chart\' before you save the chart.', 'visualizer' ) ); ?></p>
679 + <!-- import from file -->
680 + <li class="viz-group visualizer_source_csv">
681 + <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from file', 'visualizer' ); ?></h2>
682 + <div class="viz-group-content">
683 + <p class="viz-group-description"><?php esc_html_e( 'Select and upload your data CSV file here. The first row of the CSV file should contain the column headings. The second one should contain series type (string, number, boolean, date, datetime, timeofday).', 'visualizer' ); ?></p>
684 + <p class="viz-group-description viz-info-msg"><b><?php echo sprintf( __( 'If you are unsure about how to format your data CSV then please take a look at this sample: %1$s %2$s%3$s. If you are using non-English characters, please make sure you save the file in UTF-8 encoding.', 'visualizer' ), '<a href="' . VISUALIZER_ABSURL . 'samples/' . $type . '.csv" target="_blank">', $type, '.csv</a>' ); ?></b></p>
685 + <form id="vz-csv-file-form" action="<?php echo $upload_link; ?>" method="post"
686 + target="thehole" enctype="multipart/form-data">
687 + <input type="hidden" id="remote-data" name="remote_data">
688 + <div class="">
689 + <input type="file" id="csv-file" name="local_data">
794 690 </div>
795 - <?php } else { ?>
796 - <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
797 - <input type="button" id="editor-chart-button" class="button button-primary "
798 - value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart"
799 - data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
800 - data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>"
801 - >
802 - <p class="viz-group-description viz-info-msg" style="display:none"><?php echo sprintf( __( 'Please make sure you click \'Show Chart\' before you save the chart.', 'visualizer' ) ); ?></p>
803 - <?php } ?>
691 + <input type="button" class="button button-primary" id="vz-import-file"
692 + value="<?php _e( 'Import', 'visualizer' ); ?>">
804 693 </form>
805 694 </div>
806 695 </li>
807 -
808 - <!-- import from file -->
809 - <li class="viz-group visualizer_source_csv <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-file' ); ?> ">
810 - <h2 class="viz-group-title viz-sub-group visualizer-src-tab" role="button" tabindex="0"><?php _e( 'Import data from file', 'visualizer' ); ?><span class="dashicons dashicons-lock"></span></h2>
811 - <div class="viz-group-content">
812 - <div>
813 - <p class="viz-group-description"><?php esc_html_e( 'Select and upload your data file here. Supported formats: CSV, XLSX. The first row should contain the column headings. The second row should contain the series type (string, number, boolean, date, datetime, timeofday).', 'visualizer' ); ?></p>
814 - <p class="viz-group-description viz-info-msg">
815 - <b>
816 - <?php
817 - echo sprintf(
818 - // translators: $s - the chart type with the link attached.
819 - __( 'If you are unsure about how to format your data CSV then please take a look at this sample: %s. If you are using non-English characters, please make sure you save the file in UTF-8 encoding.', 'visualizer' ),
820 - '<a href="' . VISUALIZER_ABSURL . 'samples/' . $type . '.csv" target="_blank">' . $type . '.csv</a>'
821 - );
822 - ?>
823 - </b>
824 - </p>
825 - <form id="vz-csv-file-form" action="<?php echo $upload_link; ?>" method="post"
826 - target="thehole" enctype="multipart/form-data">
827 - <input type="hidden" id="remote-data" name="remote_data">
828 - <div class="">
829 - <input type="file" id="csv-file" name="local_data" accept=".csv,.xlsx">
830 - </div>
831 - <input type="button" class="button button-primary" id="vz-import-file"
832 - value="<?php _e( 'Import', 'visualizer' ); ?>">
833 - </form>
834 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-file' ); ?>
835 - </div>
836 - </div>
837 - </li>
838 696 <!-- import from url -->
839 - <li class="viz-group visualizer-import-url visualizer_source_csv_remote visualizer_source_json <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-url' ); ?> ">
840 - <h2 class="viz-group-title viz-sub-group visualizer-src-tab" role="button" tabindex="0"><?php _e( 'Import data from URL', 'visualizer' ); ?><span class="dashicons dashicons-lock"></span></h2>
697 + <li class="viz-group visualizer-import-url visualizer_source_csv_remote visualizer_source_json">
698 + <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from URL', 'visualizer' ); ?></h2>
841 699 <ul class="viz-group-content">
842 700 <!-- import from csv url -->
843 701 <li class="viz-subsection">
844 - <span class="viz-section-title" role="button" tabindex="0"><?php _e( 'Import from CSV / XLSX', 'visualizer' ); ?></span>
845 - <div class="only-pro-anchor">
846 - <div class="viz-section-items section-items">
847 - <p class="viz-group-description">
702 + <span class="viz-section-title"><?php _e( 'Import from CSV', 'visualizer' ); ?></span>
703 + <div class="viz-section-items section-items">
704 + <p class="viz-group-description"><?php echo sprintf( __( 'You can use this to import data from a remote CSV file or %1$sGoogle Spreadsheet%2$s.', 'visualizer' ), '<a href="https://docs.themeisle.com/article/607-how-can-i-populate-data-from-google-spreadsheet" target="_blank" >', '</a>' ); ?> </p>
705 + <p class="viz-group-description viz-info-msg"><b><?php echo sprintf( __( 'If you are unsure about how to format your data CSV then please take a look at this sample: %1$s %2$s%3$s. If you are using non-English characters, please make sure you save the file in UTF-8 encoding.', 'visualizer' ), '<a href="' . VISUALIZER_ABSURL . 'samples/' . $type . '.csv" target="_blank">', $type, '.csv</a>' ); ?></b></p>
706 + <form id="vz-one-time-import" action="<?php echo $upload_link; ?>" method="post"
707 + target="thehole" enctype="multipart/form-data">
708 + <div class="remote-file-section">
709 + <input type="url" id="vz-schedule-url" name="remote_data" value="<?php echo esc_attr( get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_URL, true ) ); ?>" placeholder="<?php esc_html_e( 'Please enter the URL of CSV file', 'visualizer' ); ?>" class="visualizer-input visualizer-remote-url">
710 + </div>
711 + <select name="vz-import-time" id="vz-import-time" class="visualizer-select">
712 + <?php
713 + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
714 + $schedules = apply_filters(
715 + 'visualizer_chart_schedules', array(
716 + '-1' => __( 'One-time', 'visualizer' ),
717 + ),
718 + 'csv',
719 + $chart_id
720 + );
721 + foreach ( $schedules as $num => $name ) {
722 + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
723 + $extra = $num == $hours ? 'selected' : '';
724 + ?>
725 + <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
848 726 <?php
849 - echo sprintf(
850 - // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
851 - __( 'You can use this to import data from a remote CSV or Excel (XLSX) file, or %1$sGoogle Spreadsheet%2$s.', 'visualizer' ),
852 - '<a href="https://docs.themeisle.com/article/607-how-can-i-populate-data-from-google-spreadsheet" target="_blank" >',
853 - '</a>'
854 - );
727 + }
728 + do_action( 'visualizer_chart_schedules_spl', 'csv', $chart_id, 1 );
729 + ?>
730 + </select>
731 +
732 + <?php
733 + if ( ! Visualizer_Module::is_pro() ) {
855 734 ?>
856 - </p>
857 - <p class="viz-group-description viz-info-msg">
858 - <b>
859 - <?php
860 - echo sprintf(
861 - // translators: %s - the chart type with the link attached.
862 - __( 'If you are unsure about how to format your data CSV then please take a look at this sample: %s. If you are using non-English characters, please make sure you save the file in UTF-8 encoding.', 'visualizer' ),
863 - '<a href="' . VISUALIZER_ABSURL . 'samples/' . $type . '.csv" target="_blank">' . $type . '.csv</a>'
864 - );
865 - ?>
866 - </b>
867 - </p>
868 - <form id="vz-one-time-import" action="<?php echo $upload_link; ?>" method="post"
869 - target="thehole" enctype="multipart/form-data">
870 - <div class="remote-file-section">
871 - <input type="url" id="vz-schedule-url" name="remote_data" value="<?php echo esc_attr( get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_URL, true ) ); ?>" placeholder="<?php esc_html_e( 'Please enter the URL of a CSV or XLSX file', 'visualizer' ); ?>" class="visualizer-input visualizer-remote-url">
872 - </div>
873 - <select name="vz-import-time" id="vz-import-time" class="visualizer-select">
735 + <input type="button" id="view-remote-file" class="button button-primary" value="<?php _e( 'Import', 'visualizer' ); ?>">
874 736 <?php
875 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
876 - $schedules = apply_filters(
877 - 'visualizer_chart_schedules', array(
878 - '-1' => __( 'One-time', 'visualizer' ),
879 - ),
880 - 'csv',
881 - $chart_id
882 - );
883 - foreach ( $schedules as $num => $name ) {
884 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
885 - $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
886 - ?>
887 - <option value="<?php echo esc_attr( $num ); ?>" <?php echo esc_attr( $extra ); ?>><?php echo esc_html( $name ); ?></option>
888 - <?php
889 - }
890 - do_action( 'visualizer_chart_schedules_spl', 'csv', $chart_id, 1 );
737 + } else {
891 738 ?>
892 - </select>
893 -
739 + <input type="button" id="vz-save-schedule" class="button button-primary" value="<?php _e( 'Import & Save schedule', 'visualizer' ); ?>">
894 740 <?php
895 - if ( ! Visualizer_Module::is_pro() ) {
896 - ?>
897 - <input type="button" id="view-remote-file" class="button button-primary" value="<?php _e( 'Import', 'visualizer' ); ?>">
898 - <?php
899 - } else {
900 - ?>
901 - <input type="button" id="vz-save-schedule" class="button button-primary" value="<?php _e( 'Import & Save schedule', 'visualizer' ); ?>">
902 - <?php
903 - }
904 - ?>
905 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-url' ); ?>
906 - </form>
907 - </div>
741 + }
742 + ?>
743 + </form>
908 744 </div>
909 745 </li>
910 746 <!-- import from json url -->
911 747 <li class="viz-subsection">
912 - <span class="viz-section-title visualizer_source_json" role="button" tabindex="0"><?php _e( 'Import from JSON', 'visualizer' ); ?></span>
913 - <div class="only-pro-anchor">
914 - <div class="viz-section-items section-items">
915 - <p class="viz-group-description"><?php _e( 'You can choose here to import/synchronize your chart data with a remote JSON source. For more info check <a href="https://docs.themeisle.com/article/1052-how-to-generate-charts-from-json-data-rest-endpoints" target="_blank" >this</a> tutorial', 'visualizer' ); ?></p>
916 - <form id="vz-import-json" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
917 - <div class="remote-file-section">
748 + <span class="viz-section-title visualizer_source_json"><?php _e( 'Import from JSON', 'visualizer' ); ?></span>
749 + <div class="viz-section-items section-items">
750 + <p class="viz-group-description"><?php _e( 'You can choose here to import/synchronize your chart data with a remote JSON source. For more info check <a href="https://docs.themeisle.com/article/1052-how-to-generate-charts-from-json-data-rest-endpoints" target="_blank" >this</a> tutorial', 'visualizer' ); ?></p>
751 + <form id="vz-import-json" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
752 + <div class="remote-file-section">
753 + <?php
754 + $bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
755 + if ( Visualizer_Module::is_pro() ) {
756 + ?>
757 + <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
758 + <select name="time" id="vz-json-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
918 759 <?php
919 - $bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
920 - if ( Visualizer_Module::is_pro() ) {
760 + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
761 + $schedules = apply_filters(
762 + 'visualizer_chart_schedules', array(
763 + '-1' => __( 'One-time', 'visualizer' ),
764 + ),
765 + 'json',
766 + $chart_id
767 + );
768 + foreach ( $schedules as $num => $name ) {
769 + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
770 + $extra = $num == $hours ? 'selected' : '';
921 771 ?>
922 - <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
923 - <select name="time" id="vz-json-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
772 + <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
924 773 <?php
925 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
926 - $schedules = apply_filters(
927 - 'visualizer_chart_schedules', array(
928 - '-1' => __( 'One-time', 'visualizer' ),
929 - ),
930 - 'json',
931 - $chart_id
932 - );
933 - foreach ( $schedules as $num => $name ) {
934 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
935 - $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
936 - ?>
937 - <option value="<?php echo esc_attr( $num ); ?>" <?php echo esc_attr( $extra ); ?>><?php echo esc_html( $name ); ?></option>
938 - <?php
939 - }
940 - do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
941 - ?>
942 - </select>
943 - <?php
944 774 }
775 + do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
945 776 ?>
946 - </div>
777 + </select>
778 + <?php
779 + }
780 + ?>
781 + </div>
947 782
948 - <input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle"
949 - value="<?php echo $bttn_label; ?>" data-current="chart"
950 - data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
951 - data-t-chart="<?php echo $bttn_label; ?>">
783 + <input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle"
784 + value="<?php echo $bttn_label; ?>" data-current="chart"
785 + data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
786 + data-t-chart="<?php echo $bttn_label; ?>">
787 + <?php
788 + if ( Visualizer_Module::is_pro() ) {
789 + ?>
790 + <input type="button" id="json-chart-save-button" class="button button-primary "
791 + value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
952 792 <?php
953 - if ( Visualizer_Module::is_pro() ) {
954 - ?>
955 - <input type="button" id="json-chart-save-button" class="button button-primary "
956 - value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
957 - <?php
958 - }
959 - ?>
960 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-url' ); ?>
961 - </form>
962 - </div>
793 + }
794 + ?>
795 + </form>
963 796 </div>
964 797 </li>
965 798 </ul>
966 799 </li>
@@ -966,9 +799,9 @@
966 799 </li>
967 800 <!-- import from chart -->
968 801 <li class="viz-group viz-import-from-other <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
969 802 <h2 class="viz-group-title viz-sub-group"
970 - data-current="chart" role="button" tabindex="0"><?php _e( 'Import from other chart', 'visualizer' ); ?><span
803 + data-current="chart"><?php _e( 'Import from other chart', 'visualizer' ); ?><span
971 804 class="dashicons dashicons-lock"></span></h2>
972 805 <div class="viz-group-content edit-data-content">
973 806 <div>
974 807 <p class="viz-group-description"><?php _e( 'You can import here data from your previously created charts', 'visualizer' ); ?></p>
@@ -974,16 +807,14 @@
974 807 <p class="viz-group-description"><?php _e( 'You can import here data from your previously created charts', 'visualizer' ); ?></p>
975 808 <form>
976 809 <select name="vz-import-from-chart" id="chart-id" class="visualizer-select">
977 810 <?php
978 - $fetch_link = esc_url(
979 - add_query_arg(
980 - array(
981 - 'action' => Visualizer_Module::is_pro() ? Visualizer_Pro::ACTION_FETCH_DATA : '',
982 - 'nonce' => Visualizer_Module::is_pro() ? wp_create_nonce( Visualizer_Pro::ACTION_FETCH_DATA ) : wp_create_nonce(),
983 - ),
984 - admin_url( 'admin-ajax.php' )
985 - )
811 + $fetch_link = add_query_arg(
812 + array(
813 + 'action' => Visualizer_Module::is_pro() ? Visualizer_Pro::ACTION_FETCH_DATA : '',
814 + 'nonce' => wp_create_nonce(),
815 + ),
816 + admin_url( 'admin-ajax.php' )
986 817 );
987 818 $query_args_charts = array(
988 819 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
989 820 'posts_per_page' => 300,
@@ -1015,240 +846,159 @@
1015 846
1016 847 </select>
1017 848 </form>
1018 849 <input type="button" id="existing-chart" class="button button-primary"
1019 - value="<?php _e( 'Import Chart', 'visualizer' ); ?>"
1020 - data-viz-link="<?php echo $fetch_link; ?>">
1021 - <?php
1022 - if ( ! Visualizer_Module_Admin::proFeaturesEnabled() ) {
1023 - echo apply_filters( 'visualizer_pro_upsell', '', 'import-chart' );
1024 - }
1025 - ?>
850 + value="<?php _e( 'Import Chart', 'visualizer' ); ?>"
851 + data-viz-link="<?php echo $fetch_link; ?>">
852 + <?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
1026 853 </div>
1027 854 </div>
1028 855 </li>
1029 856
1030 857 <?php
1031 - $save_filter = esc_url(
1032 - add_query_arg(
1033 - array(
1034 - 'action' => Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY,
1035 - 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY . Visualizer_Plugin::VERSION ),
1036 - 'chart' => $chart_id,
1037 - ), admin_url( 'admin-ajax.php' )
1038 - )
858 + $save_filter = add_query_arg(
859 + array(
860 + 'action' => Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY,
861 + 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY . Visualizer_Plugin::VERSION ),
862 + 'chart' => $chart_id,
863 + ), admin_url( 'admin-ajax.php' )
1039 864 );
1040 865 ?>
1041 866 <!-- import from WordPress -->
1042 - <li class="viz-group visualizer_source_query_wp <?php echo esc_attr( apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-wp' ) ); ?> ">
1043 - <h2 class="viz-group-title viz-sub-group" role="button" tabindex="0"><?php _e( 'Import from WordPress', 'visualizer' ); ?><span
867 + <li class="viz-group visualizer_source_query_wp <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-wp' ); ?> ">
868 + <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from WordPress', 'visualizer' ); ?><span
1044 869 class="dashicons dashicons-lock"></span></h2>
1045 870 <div class="viz-group-content edit-data-content">
1046 871 <div>
1047 872 <p class="viz-group-description"><?php _e( 'You can import data from WordPress here.', 'visualizer' ); ?></p>
1048 - <form id="vz-filter-wizard" action="<?php echo esc_url( $save_filter ); ?>" method="post" target="thehole">
873 + <form id="vz-filter-wizard" action="<?php echo $save_filter; ?>" method="post" target="thehole">
874 + <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from WordPress.', 'visualizer' ); ?></p>
875 + <select name="refresh" id="vz-filter-import-time" class="visualizer-select">
1049 876 <?php
1050 - $is_wp_source = 'visualizer_source_query_wp' === $source_of_chart;
1051 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
1052 - $bttn_label = $is_wp_source ? '1. ' . __( 'Modify Data Source', 'visualizer' ) : '1. ' . __( 'Choose Data Source', 'visualizer' );
877 + $bttn_label = 'visualizer_source_query_wp' === $source_of_chart ? __( 'Modify Filter', 'visualizer' ) : __( 'Create Filter', 'visualizer' );
878 + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
879 + $schedules = apply_filters(
880 + 'visualizer_chart_schedules', array(
881 + '-1' => __( 'One-time', 'visualizer' ),
882 + ),
883 + 'wp',
884 + $chart_id
885 + );
886 + foreach ( $schedules as $num => $name ) {
887 + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
888 + $extra = $num == $hours ? 'selected' : '';
889 + ?>
890 + <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
891 + <?php
892 + }
893 + do_action( 'visualizer_chart_schedules_spl', 'wp', $chart_id, 1 );
1053 894 ?>
895 + </select>
1054 896
1055 - <!-- Step 1: Choose / modify data source -->
1056 - <input type="button" id="filter-chart-button" class="button button-secondary show-chart-toggle vz-import-step-btn" value="<?php echo esc_attr( $bttn_label ); ?>" data-current="chart" data-t-filter="<?php esc_attr_e( 'Show Chart', 'visualizer' ); ?>" data-t-chart="<?php echo esc_attr( $bttn_label ); ?>">
1057 -
1058 - <!-- Step 2: Sync schedule toggle -->
1059 - <div id="vz-wp-sync-step">
1060 - <button type="button" id="vz-wp-sync-btn" class="vz-import-step-toggle" aria-expanded="<?php echo $is_wp_source ? 'true' : 'false'; ?>">
1061 - <?php echo '2. ' . __( 'Set Sync Schedule', 'visualizer' ); ?>
1062 - <span class="dashicons dashicons-arrow-down-alt2"></span>
1063 - </button>
1064 - <div id="vz-wp-sync-options"<?php echo $is_wp_source ? '' : ' style="display:none"'; ?>>
1065 - <select name="refresh" id="vz-filter-import-time" class="visualizer-select">
1066 - <?php
1067 - $schedules = apply_filters(
1068 - 'visualizer_chart_schedules', array(
1069 - '-1' => __( 'One-time', 'visualizer' ),
1070 - ),
1071 - 'wp',
1072 - $chart_id
1073 - );
1074 - foreach ( $schedules as $num => $name ) {
1075 - $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
1076 - ?>
1077 - <option value="<?php echo esc_attr( $num ); ?>" <?php echo esc_attr( $extra ); ?>><?php echo esc_html( $name ); ?></option>
1078 - <?php
1079 - }
1080 - do_action( 'visualizer_chart_schedules_spl', 'wp', $chart_id, 1 );
1081 - ?>
1082 - </select>
1083 - <input type="button" id="db-filter-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
1084 - </div>
1085 - </div>
897 + <input type="button" id="filter-chart-button" class="button button-secondary show-chart-toggle" value="<?php echo $bttn_label; ?>" data-current="chart" data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>" data-t-chart="<?php echo $bttn_label; ?>">
898 + <input type="button" id="db-filter-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
899 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
1086 900 </form>
1087 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wp', 'https://docs.themeisle.com/article/1278-how-to-import-data-from-wordpress' ); ?>
901 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wp' ); ?>
1088 902 </div>
1089 903 </div>
1090 904 </li>
1091 905
1092 - <!-- import from WooCommerce -->
1093 906 <?php
1094 - if ( class_exists( 'WooCommerce', false ) ) :
1095 - $wc_source = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE, true ) );
1096 - $wc_source_list = apply_filters(
1097 - 'visualizer_woocommerce_report_endpoints',
907 + $save_query = add_query_arg(
1098 908 array(
1099 - array(
1100 - 'name' => esc_html__( 'Sales', 'visualizer' ),
1101 - 'endpoint' => esc_attr( 'sales' ),
1102 - ),
1103 - array(
1104 - 'name' => esc_html__( 'Top Sellers', 'visualizer' ),
1105 - 'endpoint' => esc_attr( 'top_sellers' ),
1106 - ),
1107 - array(
1108 - 'name' => esc_html__( 'Coupons Totals', 'visualizer' ),
1109 - 'endpoint' => esc_attr( 'coupons/totals' ),
1110 - ),
1111 - array(
1112 - 'name' => esc_html__( 'Customers Totals', 'visualizer' ),
1113 - 'endpoint' => esc_attr( 'customers/totals' ),
1114 - ),
1115 - array(
1116 - 'name' => esc_html__( 'Orders Totals', 'visualizer' ),
1117 - 'endpoint' => esc_attr( 'orders/totals' ),
1118 - ),
1119 - array(
1120 - 'name' => esc_html__( 'Products Totals', 'visualizer' ),
1121 - 'endpoint' => esc_attr( 'products/totals' ),
1122 - ),
1123 - array(
1124 - 'name' => esc_html__( 'Reviews Totals', 'visualizer' ),
1125 - 'endpoint' => esc_attr( 'reviews/totals' ),
1126 - ),
1127 - )
909 + 'action' => Visualizer_Plugin::ACTION_SAVE_DB_QUERY,
910 + 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_DB_QUERY . Visualizer_Plugin::VERSION ),
911 + 'chart' => $chart_id,
912 + ), admin_url( 'admin-ajax.php' )
1128 913 );
1129 - ?>
1130 - <li class="viz-group visualizer_woocommerce_source<?php echo 'visualizer_source_json_wc' === $source_of_chart ? ' open' : ''; ?> <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-wc-report' ); ?> ">
1131 - <h2 class="viz-group-title viz-sub-group" role="button" tabindex="0"><?php _e( 'Import from WooCommerce Reports', 'visualizer' ); ?><span class="dashicons dashicons-lock"></span></h2>
1132 - <div class="viz-group-content edit-data-content">
1133 - <div>
1134 - <p class="viz-group-description"><?php _e( 'You can choose here to import/synchronize your chart data with a WooCommerce report API. For more info check <a href="https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#reports" target="_blank" >this</a> tutorial', 'visualizer' ); ?></p>
1135 - <form id="vz-import-woo-report" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
1136 - <div class="remote-file-section">
1137 - <?php
1138 - $bttn_label = 'visualizer_source_json_wc' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
1139 - ?>
1140 - <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
1141 - <select name="time" id="vz-woo-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
1142 - <?php
1143 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
1144 - $schedules = apply_filters(
1145 - 'visualizer_chart_schedules', array(
1146 - '-1' => __( 'One-time', 'visualizer' ),
1147 - ),
1148 - 'json',
1149 - $chart_id
1150 - );
1151 - foreach ( $schedules as $num => $name ) {
1152 - $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
1153 - ?>
1154 - <option value="<?php echo esc_attr( $num ); ?>" <?php echo esc_attr( $extra ); ?>><?php echo esc_html( $name ); ?></option>
1155 - <?php
1156 - }
1157 - do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
1158 - ?>
1159 - </select>
1160 - <p class="viz-group-description"><?php _e( 'Select report endpoint', 'visualizer' ); ?></p>
1161 - <select name="vz_woo_source" id="vz-woo-source" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
1162 - <option value=""></option>
1163 - <?php
1164 - if ( ! empty( $wc_source_list ) ) {
1165 - foreach ( $wc_source_list as $api ) {
1166 - if ( isset( $api['name'] ) && $api['endpoint'] ) {
1167 - echo sprintf( '<option value="%2$s" %3$s>%1$s</option>', $api['name'], $api['endpoint'], selected( $wc_source, $api['endpoint'], false ) ); // phpcs:ignore
1168 - }
1169 - }
1170 - }
1171 - ?>
1172 - </select>
1173 - </div>
1174 -
1175 - <input type="button" id="woo-chart-button" class="button button-secondary show-chart-toggle"
1176 - value="<?php echo $bttn_label; ?>" data-current="chart"
1177 - data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
1178 - data-t-chart="<?php echo $bttn_label; ?>"
1179 - <?php empty( $wc_source ) ? 'disabled' : ''; ?>
1180 - >
1181 - <input type="button" id="woo-chart-save-button" class="button button-primary "
1182 - value="<?php _e( 'Save Schedule', 'visualizer' ); ?>" <?php empty( $wc_source ) ? 'disabled' : ''; ?>>
1183 - </form>
1184 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wc-report' ); ?>
1185 - </div>
1186 - </div>
1187 - </li>
1188 - <?php endif; ?>
1189 - <?php
1190 - $save_query = esc_url(
1191 - add_query_arg(
1192 - array(
1193 - 'action' => Visualizer_Plugin::ACTION_SAVE_DB_QUERY,
1194 - 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_DB_QUERY . Visualizer_Plugin::VERSION ),
1195 - 'chart' => $chart_id,
1196 - ), admin_url( 'admin-ajax.php' )
1197 - )
1198 - );
1199 914 ?>
1200 915 <!-- import from db -->
1201 - <li class="viz-group visualizer_source_query <?php echo esc_attr( apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ) ); ?>">
1202 - <h2 class="viz-group-title viz-sub-group" role="button" tabindex="0"><?php _e( 'Import from database', 'visualizer' ); ?><span
916 + <li class="viz-group visualizer_source_query <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ); ?>">
917 + <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from database', 'visualizer' ); ?><span
1203 918 class="dashicons dashicons-lock"></span></h2>
1204 919 <div class="viz-group-content edit-data-content">
1205 920 <div>
1206 921 <p class="viz-group-description"><?php _e( 'You can import data from the database here.', 'visualizer' ); ?></p>
1207 - <form id="vz-db-wizard" action="<?php echo esc_url( $save_query ); ?>" method="post" target="thehole">
922 + <form id="vz-db-wizard" action="<?php echo $save_query; ?>" method="post" target="thehole">
923 + <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from the database.', 'visualizer' ); ?></p>
924 + <select name="refresh" id="vz-db-import-time" class="visualizer-select">
1208 925 <?php
1209 - $is_db_source = 'visualizer_source_query' === $source_of_chart;
1210 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
1211 - $bttn_label = $is_db_source ? __( '1. Modify Data Source', 'visualizer' ) : __( '1. Choose Data Source', 'visualizer' );
926 + $bttn_label = 'visualizer_source_query' === $source_of_chart ? __( 'Modify Query', 'visualizer' ) : __( 'Create Query', 'visualizer' );
927 + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
928 + $schedules = apply_filters(
929 + 'visualizer_chart_schedules', array(
930 + '-1' => __( 'One-time', 'visualizer' ),
931 + ),
932 + 'db',
933 + $chart_id
934 + );
935 + foreach ( $schedules as $num => $name ) {
936 + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
937 + $extra = $num == $hours ? 'selected' : '';
938 + ?>
939 + <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
940 + <?php
941 + }
942 + do_action( 'visualizer_chart_schedules_spl', 'db', $chart_id, 1 );
1212 943 ?>
1213 -
1214 - <!-- Step 1: Choose / modify data source -->
944 + </select>
1215 945 <input type="hidden" name="params" id="viz-db-wizard-params">
1216 - <input type="button" id="db-chart-button" class="button button-secondary show-chart-toggle vz-import-step-btn" value="<?php echo esc_attr( $bttn_label ); ?>" data-current="chart" data-t-filter="<?php esc_attr_e( 'Show Chart', 'visualizer' ); ?>" data-t-chart="<?php echo esc_attr( $bttn_label ); ?>">
1217 946
1218 - <!-- Step 2: Sync schedule toggle -->
1219 - <div id="vz-db-sync-step">
1220 - <button type="button" id="vz-db-sync-btn" class="vz-import-step-toggle" aria-expanded="<?php echo $is_db_source ? 'true' : 'false'; ?>">
1221 - <?php echo '2. ' . __( 'Set Sync Schedule', 'visualizer' ); ?>
1222 - <span class="dashicons dashicons-arrow-down-alt2"></span>
1223 - </button>
1224 - <div id="vz-db-sync-options"<?php echo $is_db_source ? '' : ' style="display:none"'; ?>>
1225 - <select name="refresh" id="vz-db-import-time" class="visualizer-select">
1226 - <?php
1227 - $schedules = apply_filters(
1228 - 'visualizer_chart_schedules', array(
1229 - '-1' => __( 'One-time', 'visualizer' ),
1230 - ),
1231 - 'db',
1232 - $chart_id
1233 - );
1234 - foreach ( $schedules as $num => $name ) {
1235 - $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
1236 - ?>
1237 - <option value="<?php echo esc_attr( $num ); ?>" <?php echo esc_attr( $extra ); ?>><?php echo esc_html( $name ); ?></option>
1238 - <?php
1239 - }
1240 - do_action( 'visualizer_chart_schedules_spl', 'db', $chart_id, 1 );
1241 - ?>
1242 - </select>
1243 - <input type="button" id="db-chart-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
1244 - </div>
1245 - </div>
1246 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query', 'https://docs.themeisle.com/article/1279-how-to-import-data-from-a-database' ); ?>
947 + <input type="button" id="db-chart-button" class="button button-secondary show-chart-toggle" value="<?php echo $bttn_label; ?>" data-current="chart" data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>" data-t-chart="<?php echo $bttn_label; ?>">
948 + <input type="button" id="db-chart-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
949 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
1247 950 </form>
1248 951 </div>
1249 952 </div>
1250 953 </li>
954 +
955 + <!-- manual -->
956 + <li class="viz-group visualizer_source_manual">
957 + <h2 class="viz-group-title viz-sub-group visualizer-editor-tab" data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?>
958 + <span class="dashicons dashicons-lock"></span>
959 + </h2>
960 + <div class="viz-group-content edit-data-content">
961 + <form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
962 + <input type="hidden" id="chart-data" name="chart_data">
963 + <input type="hidden" id="chart-data-src" name="chart_data_src">
964 +
965 + <?php if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { ?>
966 + <div>
967 + <p class="viz-group-description viz-editor-selection">
968 + <?php _e( 'Use the', 'visualizer' ); ?>
969 + <select name="editor-type" id="viz-editor-type">
970 + <?php
971 + if ( empty( $editor_type ) ) {
972 + $editor_type = Visualizer_Module::is_pro() ? 'excel' : 'text';
973 + }
974 + foreach ( apply_filters( 'visualizer_editors', array( 'text' => __( 'Text', 'visualizer' ), 'table' => __( 'Simple', 'visualizer' ) ) ) as $e_type => $e_label ) {
975 + ?>
976 + <option value="<?php echo $e_type; ?>" <?php selected( $editor_type, $e_type ); ?> ><?php echo $e_label; ?></option>
977 + <?php } ?>
978 + </select>
979 + <?php _e( 'editor to manually edit the chart data.', 'visualizer' ); ?>
980 + </p>
981 + <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
982 + <input type="button" id="editor-button" class="button button-primary "
983 + value="<?php _e( 'Edit Data', 'visualizer' ); ?>" data-current="chart"
984 + data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
985 + data-t-chart="<?php _e( 'Edit Data', 'visualizer' ); ?>"
986 + >
987 + <p class="viz-group-description viz-info-msg"><?php echo sprintf( __( 'Please make sure you click \'Show Chart\' before you save the chart.', 'visualizer' ) ); ?></p>
988 + </div>
989 + <?php } else { ?>
990 + <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
991 + <input type="button" id="editor-chart-button" class="button button-primary "
992 + value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart"
993 + data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
994 + data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>"
995 + >
996 + <p class="viz-group-description viz-info-msg"><?php echo sprintf( __( 'Please make sure you click \'Show Chart\' before you save the chart.', 'visualizer' ) ); ?></p>
997 + <?php } ?>
998 + </form>
999 + </div>
1000 + </li>
1251 1001 </ul>
1252 1002 </li>
1253 1003 </ul>
1254 1004 </ul>
@@ -1255,41 +1005,6 @@
1255 1005
1256 1006 <span id="visualizer-chart-id" data-id="<?php echo $chart_id; ?>" data-chart-source="<?php echo esc_attr( $source_of_chart ); ?>" data-chart-type="<?php echo esc_attr( $type ); ?>" data-chart-lib="<?php echo esc_attr( $lib ); ?>"></span>
1257 1007 <iframe id="thehole" name="thehole"></iframe>
1258 1008 <?php
1259 - }
1260 -
1261 - /**
1262 - * Check if the given hour is selected.
1263 - *
1264 - * @param int|float|string $hour The hour.
1265 - * @param int|float|string $reference The number.
1266 - *
1267 - * @return bool
1268 - */
1269 - public static function is_hour_selected( $hour, $reference ) {
1270 -
1271 - if ( ! is_numeric( $hour ) || ! is_numeric( $reference ) ) {
1272 - return false;
1273 - }
1274 -
1275 - $hour = floatval( $hour );
1276 - $reference = floatval( $reference );
1277 -
1278 - if ( self::is_live_update_option( $reference ) ) {
1279 - $reference = self::$live_option_fallback_hour;
1280 - }
1281 -
1282 - return abs( $hour - $reference ) < 0.000001;
1283 - }
1284 -
1285 - /**
1286 - * Check if the reference option is deprecated live update option.
1287 - *
1288 - * @param float $reference_hour The reference hour.
1289 - *
1290 - * @return bool
1291 - */
1292 - public static function is_live_update_option( $reference_hour ) {
1293 - return abs( $reference_hour ) < 0.000001;
1294 1009 }
1295 1010 }