PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.7.7
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.7.7
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 +228 -494 4.0.83.7.7 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 ) {
@@ -174,9 +138,8 @@
174 138 admin_url( 'admin-ajax.php' )
175 139 )
176 140 );
177 141
178 - $is_wc_source = get_post_meta( $id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true );
179 142 $url = get_post_meta( $id, Visualizer_Plugin::CF_JSON_URL, true );
180 143 $root = get_post_meta( $id, Visualizer_Plugin::CF_JSON_ROOT, true );
181 144 $paging = get_post_meta( $id, Visualizer_Plugin::CF_JSON_PAGING, true );
182 145 $headers = get_post_meta( $id, Visualizer_Plugin::CF_JSON_HEADERS, true );
@@ -187,15 +150,10 @@
187 150 $headers['method'] = 'get';
188 151 }
189 152 $methods = apply_filters( 'visualizer_json_request_methods', array( 'GET', 'POST' ) );
190 153
191 - $auth = isset( $headers['auth'] ) ? $headers['auth'] : '';
192 - $auth_username = is_array( $auth ) && isset( $auth['username'] ) ? $auth['username'] : '';
193 - $auth_password = is_array( $auth ) && isset( $auth['password'] ) ? $auth['password'] : '';
194 - $auth_string = is_string( $auth ) ? $auth : '';
195 -
196 154 // open the headers by default?
197 - $headers_open = ! empty( $auth_username ) || ! empty( $auth_string );
155 + $headers_open = $headers && array_key_exists( 'auth', $headers ) && ( array_key_exists( 'username', $headers['auth'] ) && ! empty( $headers['auth']['username'] ) ) || ( ! empty( $headers['auth'] ) && is_string( $headers['auth'] ) );
198 156 ?>
199 157 <div id="visualizer-json-screen" style="display: none">
200 158 <div class="visualizer-json-form">
201 159 <h3 class="viz-step step1"><?php _e( 'STEP 1: Specify the JSON endpoint/URL', 'visualizer' ); ?></h3>
@@ -202,18 +160,9 @@
202 160 <div>
203 161 <form id="json-endpoint-form">
204 162 <div class="json-wizard-hints">
205 163 <ul class="info">
206 - <li>
207 - <?php
208 - echo sprintf(
209 - // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
210 - __( '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' ),
211 - '<a href="https://docs.themeisle.com/article/1043-visualizer-how-to-extend-rest-endpoints-with-json-response" target="_blank">',
212 - '</a>'
213 - );
214 - ?>
215 - </li>
164 + <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>
216 165 </ul>
217 166 </div>
218 167
219 168 <input
@@ -221,13 +170,11 @@
221 170 id="vz-import-json-url"
222 171 name="url"
223 172 value="<?php echo esc_url( $url ); ?>"
224 173 placeholder="<?php esc_html_e( 'Please enter the URL', 'visualizer' ); ?>"
225 - class="visualizer-input json-form-element"
226 - <?php echo $is_wc_source ? 'readonly' : ''; ?>
227 - >
174 + class="visualizer-input json-form-element">
228 175 <button class="button button-secondary button-small" id="visualizer-json-fetch"><?php esc_html_e( 'Fetch Endpoint', 'visualizer' ); ?></button>
229 -
176 +
230 177 <div class="visualizer-json-subform">
231 178 <h3 class="viz-substep <?php echo $headers_open ? 'open' : ''; ?>"><?php _e( 'Headers', 'visualizer' ); ?></h3>
232 179 <div class="json-wizard-headers">
233 180 <div class="json-wizard-header">
@@ -246,19 +193,19 @@
246 193 <input
247 194 type="text"
248 195 id="vz-import-json-username"
249 196 name="username"
250 - value="<?php echo esc_attr( $auth_username ); ?>"
197 + value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'username', $headers['auth'] ) ? $headers['auth']['username'] : '' ); ?>"
251 198 placeholder="<?php esc_html_e( 'Username/Access Key', 'visualizer' ); ?>"
252 - class="json-form-element">
199 + class="json-form-element">
253 200 &
254 201 <input
255 202 type="password"
256 203 id="vz-import-json-password"
257 204 name="password"
258 - value="<?php echo esc_attr( $auth_password ); ?>"
205 + value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'password', $headers['auth'] ) ? $headers['auth']['password'] : '' ); ?>"
259 206 placeholder="<?php esc_html_e( 'Password/Secret Key', 'visualizer' ); ?>"
260 - class="json-form-element">
207 + class="json-form-element">
261 208 </div>
262 209 </div>
263 210 <div class="json-wizard-header">
264 211 <div></div>
@@ -270,9 +217,9 @@
270 217 <input
271 218 type="text"
272 219 id="vz-import-json-auth"
273 220 name="auth"
274 - value="<?php echo esc_attr( $auth_string ); ?>"
221 + value="<?php echo ( array_key_exists( 'auth', $headers ) && is_string( $headers['auth'] ) ? $headers['auth'] : '' ); ?>"
275 222 placeholder="<?php esc_html_e( 'e.g. SharedKey <AccountName>:<Signature>', 'visualizer' ); ?>"
276 223 class="visualizer-input json-form-element">
277 224 </div>
278 225 </div>
@@ -278,9 +225,9 @@
278 225 </div>
279 226 <div class="json-wizard-header">
280 227 <div class="field-title"><?php esc_html_e( 'Additional headers', 'visualizer' ); ?></div>
281 228 <div>
282 - <textarea name="additional_headers" class="visualizer-input" placeholder="<?php esc_html_e( 'Key:Value, Key2:Value2,...', 'visualizer' ); ?>"><?php echo esc_textarea( isset( $headers['additional_headers'] ) ? $headers['additional_headers'] : '' ); ?></textarea>
229 + <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>
283 230 </div>
284 231 </div>
285 232 </div>
286 233 </div>
@@ -293,9 +240,9 @@
293 240 <select name="root" id="vz-import-json-root" class="json-form-element">
294 241 <?php
295 242 if ( ! empty( $root ) ) {
296 243 ?>
297 - <option value="<?php echo esc_attr( $root ); ?>"><?php echo esc_html( str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $root ) ); ?></option>
244 + <option value="<?php echo esc_attr( $root ); ?>"><?php echo str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $root ); ?></option>
298 245 <?php
299 246 }
300 247 ?>
301 248 </select>
@@ -311,9 +258,9 @@
311 258 <option value="0" class="static"><?php _e( 'Get results from the first page only', 'visualizer' ); ?></option>
312 259 <?php
313 260 if ( ! empty( $paging ) ) {
314 261 ?>
315 - <option value="<?php echo esc_attr( $paging ); ?>"><?php echo esc_html( sprintf( 'Get results from the first %d pages using %s', apply_filters( 'visualizer_json_fetch_pages', 5, $url ), str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $paging ) ) ); ?></option>
262 + <option value="<?php echo esc_attr( $paging ); ?>"><?php echo sprintf( 'Get results from the first %d pages using %s', apply_filters( 'visualizer_json_fetch_pages', 5, $url ), str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $paging ) ); ?></option>
316 263 <?php
317 264 }
318 265 ?>
319 266 </select>
@@ -364,9 +311,9 @@
364 311 $action = esc_url(
365 312 add_query_arg(
366 313 array(
367 314 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
368 - 'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
315 + 'nonce' => wp_create_nonce(),
369 316 'chart' => $chart_id,
370 317 ),
371 318 admin_url( 'admin-ajax.php' )
372 319 )
@@ -394,8 +341,9 @@
394 341 <?php Visualizer_Render_Layout::show( 'text-editor', $chart_id ); ?>
395 342
396 343 </div>
397 344 <?php
345 +
398 346 }
399 347
400 348 /**
401 349 * Show the text area editor.
@@ -468,9 +416,9 @@
468 416 }
469 417 ?>
470 418 </tr>
471 419 </thead>
472 - <tbody>
420 + <tbody>
473 421 <tr>
474 422 <th><?php _e( 'Data Type', 'visualizer' ); ?></th>
475 423 <?php
476 424 $index = 0;
@@ -535,9 +483,9 @@
535 483 private static function _renderPermissions( $args ) {
536 484 $chart_id = $args[1];
537 485
538 486 // ignore for unit tests because Travis throws the error "Indirect modification of overloaded property Visualizer_Render_Page_Data::$permissions has no effect".
539 - if ( defined( 'WP_TESTS_DOMAIN' ) && function_exists( 'tests_add_filter' ) ) {
487 + if ( defined( 'WP_TESTS_DOMAIN' ) ) {
540 488 return;
541 489 }
542 490
543 491 $permissions = apply_filters( 'visualizer_pro_get_permissions', null, $chart_id );
@@ -620,9 +568,9 @@
620 568 true,
621 569 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-edit-specific' )
622 570 );
623 571 Visualizer_Render_Sidebar::_renderSectionEnd();
624 - echo apply_filters( 'visualizer_pro_upsell', '', 'chart-permissions', 'https://docs.themeisle.com/article/1280-how-to-customize-permissions' );
572 + echo apply_filters( 'visualizer_pro_upsell', '', 'chart-permissions' );
625 573 echo '</div>';
626 574 Visualizer_Render_Sidebar::_renderGroupEnd();
627 575 }
628 576
@@ -631,14 +579,9 @@
631 579 *
632 580 * @access public
633 581 */
634 582 public static function _renderTabAdvanced( $args ) {
635 - $chart_id = $args[1];
636 - $sidebar = $args[2];
637 -
638 - $chart_options = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
639 - $backend_title = isset( $chart_options['backend-title'] ) && ! empty( $chart_options['backend-title'] ) ? $chart_options['backend-title'] : '';
640 -
583 + $sidebar = $args[2];
641 584 ?>
642 585 <ul class="viz-group-wrapper full-height">
643 586 <li class="viz-group open" id="vz-chart-settings">
644 587 <ul class="viz-group-content">
@@ -644,9 +587,8 @@
644 587 <ul class="viz-group-content">
645 588 <ul class="viz-group-wrapper">
646 589 <form id="settings-form" action="<?php echo esc_url( add_query_arg( 'nonce', wp_create_nonce() ) ); ?>" method="post">
647 590 <input type="hidden" id="chart-img" name="chart-img">
648 - <input type="hidden" id="backend-title" name="backend-title" value="<?php echo esc_html( $backend_title ); ?>">
649 591 <?php echo $sidebar; ?>
650 592 <?php self::_renderPermissions( $args ); ?>
651 593 <input type="hidden" name="save" value="1">
652 594 </form>
@@ -692,22 +634,12 @@
692 634 <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>
693 635 <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>
694 636 <?php
695 637 Visualizer_Render_Sidebar::_renderSectionEnd();
696 - // translators: %s - the chart type.
697 638 Visualizer_Render_Sidebar::_renderSectionStart( sprintf( __( '%s chart', 'visualizer' ), ucwords( $displayType ) ), true );
698 639 ?>
699 640 <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>
700 - <h4><span class="dashicons dashicons-search"></span><a href="<?php echo str_replace( '#', $type, VISUALIZER_DOC_COLLECTION ); ?>" target="_blank">
701 - <?php
702 - echo sprintf(
703 - // translators: %s - the chart type.
704 - __( 'Articles containing "%s"', 'visualizer' ),
705 - $displayType
706 - );
707 - ?>
708 - </a>
709 - </h4>
641 + <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>
710 642 <?php
711 643 Visualizer_Render_Sidebar::_renderSectionEnd();
712 644 Visualizer_Render_Sidebar::_renderGroupEnd();
713 645 ?>
@@ -729,9 +661,9 @@
729 661 $upload_link = esc_url(
730 662 add_query_arg(
731 663 array(
732 664 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
733 - 'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
665 + 'nonce' => wp_create_nonce(),
734 666 'chart' => $chart_id,
735 667 ),
736 668 admin_url( 'admin-ajax.php' )
737 669 )
@@ -737,14 +669,9 @@
737 669 )
738 670 );
739 671
740 672 // this will allow us to open the correct source tab by default.
741 - $source_of_chart = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
742 - // Import from woocommerce report.
743 - $is_woocommerce_source = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ) );
744 - if ( ! empty( $is_woocommerce_source ) ) {
745 - $source_of_chart .= '_wc';
746 - }
673 + $source_of_chart = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
747 674 // both import from wp and import from db have the same source so we need to differentiate.
748 675 $filter_config = get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true );
749 676 // if filter config is present, then its import from wp.
750 677 if ( ! empty( $filter_config ) ) {
@@ -750,12 +677,9 @@
750 677 if ( ! empty( $filter_config ) ) {
751 678 $source_of_chart .= '_wp';
752 679 }
753 680 $editor_type = get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR, true );
754 - if (
755 - $editor_type ||
756 - ! Visualizer_Module::is_pro() // Use Manual Source for non-pro users since it is the only unlocked source.
757 - ) {
681 + if ( $editor_type ) {
758 682 $source_of_chart = 'visualizer_source_manual';
759 683 }
760 684
761 685 $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
@@ -764,208 +688,125 @@
764 688 <ul class="viz-group-wrapper full-height">
765 689 <li class="viz-group open" id="vz-chart-source">
766 690 <ul class="viz-group-content">
767 691 <ul class="viz-group-wrapper">
768 - <!-- manual -->
769 - <li class="viz-group visualizer_source_manual">
770 - <h2 class="viz-group-title viz-sub-group visualizer-editor-tab" data-current="chart" role="button" tabindex="0"><?php _e( 'Manual Data', 'visualizer' ); ?></h2>
771 - <div class="viz-group-content edit-data-content">
772 - <form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
773 - <input type="hidden" id="chart-data" name="chart_data">
774 - <input type="hidden" id="chart-data-src" name="chart_data_src">
775 -
776 - <?php if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { ?>
777 - <div>
778 - <p class="viz-group-description viz-editor-selection">
779 - <?php _e( 'Use the', 'visualizer' ); ?>
780 - <select name="editor-type" id="viz-editor-type">
781 - <?php
782 - if ( empty( $editor_type ) ) {
783 - $editor_type = Visualizer_Module::is_pro() ? 'excel' : 'text';
784 - }
785 - foreach ( apply_filters( 'visualizer_editors', array( 'text' => __( 'Text', 'visualizer' ), 'table' => __( 'Simple', 'visualizer' ) ) ) as $e_type => $e_label ) {
786 - ?>
787 - <option value="<?php echo $e_type; ?>" <?php selected( $editor_type, $e_type ); ?> ><?php echo $e_label; ?></option>
788 - <?php } ?>
789 - </select>
790 - <?php _e( 'editor to manually edit the chart data.', 'visualizer' ); ?>
791 - </p>
792 - <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
793 - <input type="button" id="editor-button" class="button button-primary "
794 - value="<?php _e( 'Edit Data', 'visualizer' ); ?>" data-current="chart"
795 - data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
796 - data-t-chart="<?php _e( 'Edit Data', 'visualizer' ); ?>"
797 - >
798 - <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>
692 + <!-- import from file -->
693 + <li class="viz-group visualizer_source_csv">
694 + <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from file', 'visualizer' ); ?></h2>
695 + <div class="viz-group-content">
696 + <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>
697 + <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>
698 + <form id="vz-csv-file-form" action="<?php echo $upload_link; ?>" method="post"
699 + target="thehole" enctype="multipart/form-data">
700 + <input type="hidden" id="remote-data" name="remote_data">
701 + <div class="">
702 + <input type="file" id="csv-file" name="local_data">
799 703 </div>
800 - <?php } else { ?>
801 - <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
802 - <input type="button" id="editor-chart-button" class="button button-primary "
803 - value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart"
804 - data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
805 - data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>"
806 - >
807 - <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>
808 - <?php } ?>
704 + <input type="button" class="button button-primary" id="vz-import-file"
705 + value="<?php _e( 'Import', 'visualizer' ); ?>">
809 706 </form>
810 707 </div>
811 708 </li>
812 -
813 - <!-- import from file -->
814 - <li class="viz-group visualizer_source_csv <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-file' ); ?> ">
815 - <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>
816 - <div class="viz-group-content">
817 - <div>
818 - <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>
819 - <p class="viz-group-description viz-info-msg">
820 - <b>
821 - <?php
822 - echo sprintf(
823 - // translators: $s - the chart type with the link attached.
824 - __( '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' ),
825 - '<a href="' . VISUALIZER_ABSURL . 'samples/' . $type . '.csv" target="_blank">' . $type . '.csv</a>'
826 - );
827 - ?>
828 - </b>
829 - </p>
830 - <form id="vz-csv-file-form" action="<?php echo $upload_link; ?>" method="post"
831 - target="thehole" enctype="multipart/form-data">
832 - <input type="hidden" id="remote-data" name="remote_data">
833 - <div class="">
834 - <input type="file" id="csv-file" name="local_data" accept=".csv,.xlsx">
835 - </div>
836 - <input type="button" class="button button-primary" id="vz-import-file"
837 - value="<?php _e( 'Import', 'visualizer' ); ?>">
838 - </form>
839 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-file' ); ?>
840 - </div>
841 - </div>
842 - </li>
843 709 <!-- import from url -->
844 - <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' ); ?> ">
845 - <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>
710 + <li class="viz-group visualizer-import-url visualizer_source_csv_remote visualizer_source_json">
711 + <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from URL', 'visualizer' ); ?></h2>
846 712 <ul class="viz-group-content">
847 713 <!-- import from csv url -->
848 714 <li class="viz-subsection">
849 - <span class="viz-section-title" role="button" tabindex="0"><?php _e( 'Import from CSV / XLSX', 'visualizer' ); ?></span>
850 - <div class="only-pro-anchor">
851 - <div class="viz-section-items section-items">
852 - <p class="viz-group-description">
715 + <span class="viz-section-title"><?php _e( 'Import from CSV', 'visualizer' ); ?></span>
716 + <div class="viz-section-items section-items">
717 + <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>
718 + <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>
719 + <form id="vz-one-time-import" action="<?php echo $upload_link; ?>" method="post"
720 + target="thehole" enctype="multipart/form-data">
721 + <div class="remote-file-section">
722 + <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">
723 + </div>
724 + <select name="vz-import-time" id="vz-import-time" class="visualizer-select">
725 + <?php
726 + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
727 + $schedules = apply_filters(
728 + 'visualizer_chart_schedules', array(
729 + '-1' => __( 'One-time', 'visualizer' ),
730 + ),
731 + 'csv',
732 + $chart_id
733 + );
734 + foreach ( $schedules as $num => $name ) {
735 + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
736 + $extra = $num == $hours ? 'selected' : '';
737 + ?>
738 + <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
853 739 <?php
854 - echo sprintf(
855 - // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
856 - __( 'You can use this to import data from a remote CSV or Excel (XLSX) file, or %1$sGoogle Spreadsheet%2$s.', 'visualizer' ),
857 - '<a href="https://docs.themeisle.com/article/607-how-can-i-populate-data-from-google-spreadsheet" target="_blank" >',
858 - '</a>'
859 - );
740 + }
741 + do_action( 'visualizer_chart_schedules_spl', 'csv', $chart_id, 1 );
742 + ?>
743 + </select>
744 +
745 + <?php
746 + if ( ! Visualizer_Module::is_pro() ) {
860 747 ?>
861 - </p>
862 - <p class="viz-group-description viz-info-msg">
863 - <b>
864 - <?php
865 - echo sprintf(
866 - // translators: %s - the chart type with the link attached.
867 - __( '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' ),
868 - '<a href="' . VISUALIZER_ABSURL . 'samples/' . $type . '.csv" target="_blank">' . $type . '.csv</a>'
869 - );
870 - ?>
871 - </b>
872 - </p>
873 - <form id="vz-one-time-import" action="<?php echo $upload_link; ?>" method="post"
874 - target="thehole" enctype="multipart/form-data">
875 - <div class="remote-file-section">
876 - <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">
877 - </div>
878 - <select name="vz-import-time" id="vz-import-time" class="visualizer-select">
748 + <input type="button" id="view-remote-file" class="button button-primary" value="<?php _e( 'Import', 'visualizer' ); ?>">
879 749 <?php
880 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
881 - $schedules = apply_filters(
882 - 'visualizer_chart_schedules', array(
883 - '-1' => __( 'One-time', 'visualizer' ),
884 - ),
885 - 'csv',
886 - $chart_id
887 - );
888 - foreach ( $schedules as $num => $name ) {
889 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
890 - $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
891 - ?>
892 - <option value="<?php echo esc_attr( $num ); ?>" <?php echo esc_attr( $extra ); ?>><?php echo esc_html( $name ); ?></option>
893 - <?php
894 - }
895 - do_action( 'visualizer_chart_schedules_spl', 'csv', $chart_id, 1 );
750 + } else {
896 751 ?>
897 - </select>
898 -
752 + <input type="button" id="vz-save-schedule" class="button button-primary" value="<?php _e( 'Import & Save schedule', 'visualizer' ); ?>">
899 753 <?php
900 - if ( ! Visualizer_Module::is_pro() ) {
901 - ?>
902 - <input type="button" id="view-remote-file" class="button button-primary" value="<?php _e( 'Import', 'visualizer' ); ?>">
903 - <?php
904 - } else {
905 - ?>
906 - <input type="button" id="vz-save-schedule" class="button button-primary" value="<?php _e( 'Import & Save schedule', 'visualizer' ); ?>">
907 - <?php
908 - }
909 - ?>
910 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-url' ); ?>
911 - </form>
912 - </div>
754 + }
755 + ?>
756 + </form>
913 757 </div>
914 758 </li>
915 759 <!-- import from json url -->
916 760 <li class="viz-subsection">
917 - <span class="viz-section-title visualizer_source_json" role="button" tabindex="0"><?php _e( 'Import from JSON', 'visualizer' ); ?></span>
918 - <div class="only-pro-anchor">
919 - <div class="viz-section-items section-items">
920 - <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>
921 - <form id="vz-import-json" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
922 - <div class="remote-file-section">
761 + <span class="viz-section-title visualizer_source_json"><?php _e( 'Import from JSON', 'visualizer' ); ?></span>
762 + <div class="viz-section-items section-items">
763 + <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>
764 + <form id="vz-import-json" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
765 + <div class="remote-file-section">
766 + <?php
767 + $bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
768 + if ( Visualizer_Module::is_pro() ) {
769 + ?>
770 + <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
771 + <select name="time" id="vz-json-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
923 772 <?php
924 - $bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
925 - if ( Visualizer_Module::is_pro() ) {
773 + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
774 + $schedules = apply_filters(
775 + 'visualizer_chart_schedules', array(
776 + '-1' => __( 'One-time', 'visualizer' ),
777 + ),
778 + 'json',
779 + $chart_id
780 + );
781 + foreach ( $schedules as $num => $name ) {
782 + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
783 + $extra = $num == $hours ? 'selected' : '';
926 784 ?>
927 - <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
928 - <select name="time" id="vz-json-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
785 + <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
929 786 <?php
930 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
931 - $schedules = apply_filters(
932 - 'visualizer_chart_schedules', array(
933 - '-1' => __( 'One-time', 'visualizer' ),
934 - ),
935 - 'json',
936 - $chart_id
937 - );
938 - foreach ( $schedules as $num => $name ) {
939 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
940 - $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
941 - ?>
942 - <option value="<?php echo esc_attr( $num ); ?>" <?php echo esc_attr( $extra ); ?>><?php echo esc_html( $name ); ?></option>
943 - <?php
944 - }
945 - do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
946 - ?>
947 - </select>
948 - <?php
949 787 }
788 + do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
950 789 ?>
951 - </div>
790 + </select>
791 + <?php
792 + }
793 + ?>
794 + </div>
952 795
953 - <input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle"
954 - value="<?php echo $bttn_label; ?>" data-current="chart"
955 - data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
956 - data-t-chart="<?php echo $bttn_label; ?>">
796 + <input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle"
797 + value="<?php echo $bttn_label; ?>" data-current="chart"
798 + data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
799 + data-t-chart="<?php echo $bttn_label; ?>">
800 + <?php
801 + if ( Visualizer_Module::is_pro() ) {
802 + ?>
803 + <input type="button" id="json-chart-save-button" class="button button-primary "
804 + value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
957 805 <?php
958 - if ( Visualizer_Module::is_pro() ) {
959 - ?>
960 - <input type="button" id="json-chart-save-button" class="button button-primary "
961 - value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
962 - <?php
963 - }
964 - ?>
965 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-url' ); ?>
966 - </form>
967 - </div>
806 + }
807 + ?>
808 + </form>
968 809 </div>
969 810 </li>
970 811 </ul>
971 812 </li>
@@ -971,9 +812,9 @@
971 812 </li>
972 813 <!-- import from chart -->
973 814 <li class="viz-group viz-import-from-other <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
974 815 <h2 class="viz-group-title viz-sub-group"
975 - data-current="chart" role="button" tabindex="0"><?php _e( 'Import from other chart', 'visualizer' ); ?><span
816 + data-current="chart"><?php _e( 'Import from other chart', 'visualizer' ); ?><span
976 817 class="dashicons dashicons-lock"></span></h2>
977 818 <div class="viz-group-content edit-data-content">
978 819 <div>
979 820 <p class="viz-group-description"><?php _e( 'You can import here data from your previously created charts', 'visualizer' ); ?></p>
@@ -983,9 +824,9 @@
983 824 $fetch_link = esc_url(
984 825 add_query_arg(
985 826 array(
986 827 'action' => Visualizer_Module::is_pro() ? Visualizer_Pro::ACTION_FETCH_DATA : '',
987 - 'nonce' => Visualizer_Module::is_pro() ? wp_create_nonce( Visualizer_Pro::ACTION_FETCH_DATA ) : wp_create_nonce(),
828 + 'nonce' => wp_create_nonce(),
988 829 ),
989 830 admin_url( 'admin-ajax.php' )
990 831 )
991 832 );
@@ -1020,15 +861,11 @@
1020 861
1021 862 </select>
1022 863 </form>
1023 864 <input type="button" id="existing-chart" class="button button-primary"
1024 - value="<?php _e( 'Import Chart', 'visualizer' ); ?>"
1025 - data-viz-link="<?php echo $fetch_link; ?>">
1026 - <?php
1027 - if ( ! Visualizer_Module_Admin::proFeaturesEnabled() ) {
1028 - echo apply_filters( 'visualizer_pro_upsell', '', 'import-chart' );
1029 - }
1030 - ?>
865 + value="<?php _e( 'Import Chart', 'visualizer' ); ?>"
866 + data-viz-link="<?php echo $fetch_link; ?>">
867 + <?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
1031 868 </div>
1032 869 </div>
1033 870 </li>
1034 871
@@ -1043,156 +880,48 @@
1043 880 )
1044 881 );
1045 882 ?>
1046 883 <!-- import from WordPress -->
1047 - <li class="viz-group visualizer_source_query_wp <?php echo esc_attr( apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-wp' ) ); ?> ">
1048 - <h2 class="viz-group-title viz-sub-group" role="button" tabindex="0"><?php _e( 'Import from WordPress', 'visualizer' ); ?><span
884 + <li class="viz-group visualizer_source_query_wp <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-wp' ); ?> ">
885 + <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from WordPress', 'visualizer' ); ?><span
1049 886 class="dashicons dashicons-lock"></span></h2>
1050 887 <div class="viz-group-content edit-data-content">
1051 888 <div>
1052 889 <p class="viz-group-description"><?php _e( 'You can import data from WordPress here.', 'visualizer' ); ?></p>
1053 - <form id="vz-filter-wizard" action="<?php echo esc_url( $save_filter ); ?>" method="post" target="thehole">
890 + <form id="vz-filter-wizard" action="<?php echo $save_filter; ?>" method="post" target="thehole">
891 + <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from WordPress.', 'visualizer' ); ?></p>
892 + <select name="refresh" id="vz-filter-import-time" class="visualizer-select">
1054 893 <?php
1055 - $is_wp_source = 'visualizer_source_query_wp' === $source_of_chart;
1056 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
1057 - $bttn_label = $is_wp_source ? '1. ' . __( 'Modify Data Source', 'visualizer' ) : '1. ' . __( 'Choose Data Source', 'visualizer' );
894 + $bttn_label = 'visualizer_source_query_wp' === $source_of_chart ? __( 'Modify Filter', 'visualizer' ) : __( 'Create Filter', 'visualizer' );
895 + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
896 + $schedules = apply_filters(
897 + 'visualizer_chart_schedules', array(
898 + '-1' => __( 'One-time', 'visualizer' ),
899 + ),
900 + 'wp',
901 + $chart_id
902 + );
903 + foreach ( $schedules as $num => $name ) {
904 + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
905 + $extra = $num == $hours ? 'selected' : '';
906 + ?>
907 + <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
908 + <?php
909 + }
910 + do_action( 'visualizer_chart_schedules_spl', 'wp', $chart_id, 1 );
1058 911 ?>
912 + </select>
1059 913
1060 - <!-- Step 1: Choose / modify data source -->
1061 - <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 ); ?>">
1062 -
1063 - <!-- Step 2: Sync schedule toggle -->
1064 - <div id="vz-wp-sync-step">
1065 - <button type="button" id="vz-wp-sync-btn" class="vz-import-step-toggle" aria-expanded="<?php echo $is_wp_source ? 'true' : 'false'; ?>">
1066 - <?php echo '2. ' . __( 'Set Sync Schedule', 'visualizer' ); ?>
1067 - <span class="dashicons dashicons-arrow-down-alt2"></span>
1068 - </button>
1069 - <div id="vz-wp-sync-options"<?php echo $is_wp_source ? '' : ' style="display:none"'; ?>>
1070 - <select name="refresh" id="vz-filter-import-time" class="visualizer-select">
1071 - <?php
1072 - $schedules = apply_filters(
1073 - 'visualizer_chart_schedules', array(
1074 - '-1' => __( 'One-time', 'visualizer' ),
1075 - ),
1076 - 'wp',
1077 - $chart_id
1078 - );
1079 - foreach ( $schedules as $num => $name ) {
1080 - $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
1081 - ?>
1082 - <option value="<?php echo esc_attr( $num ); ?>" <?php echo esc_attr( $extra ); ?>><?php echo esc_html( $name ); ?></option>
1083 - <?php
1084 - }
1085 - do_action( 'visualizer_chart_schedules_spl', 'wp', $chart_id, 1 );
1086 - ?>
1087 - </select>
1088 - <input type="button" id="db-filter-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
1089 - </div>
1090 - </div>
914 + <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; ?>">
915 + <input type="button" id="db-filter-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
916 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
1091 917 </form>
1092 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wp', 'https://docs.themeisle.com/article/1278-how-to-import-data-from-wordpress' ); ?>
918 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wp' ); ?>
1093 919 </div>
1094 920 </div>
1095 921 </li>
1096 922
1097 - <!-- import from WooCommerce -->
1098 923 <?php
1099 - if ( class_exists( 'WooCommerce', false ) ) :
1100 - $wc_source = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE, true ) );
1101 - $wc_source_list = apply_filters(
1102 - 'visualizer_woocommerce_report_endpoints',
1103 - array(
1104 - array(
1105 - 'name' => esc_html__( 'Sales', 'visualizer' ),
1106 - 'endpoint' => esc_attr( 'sales' ),
1107 - ),
1108 - array(
1109 - 'name' => esc_html__( 'Top Sellers', 'visualizer' ),
1110 - 'endpoint' => esc_attr( 'top_sellers' ),
1111 - ),
1112 - array(
1113 - 'name' => esc_html__( 'Coupons Totals', 'visualizer' ),
1114 - 'endpoint' => esc_attr( 'coupons/totals' ),
1115 - ),
1116 - array(
1117 - 'name' => esc_html__( 'Customers Totals', 'visualizer' ),
1118 - 'endpoint' => esc_attr( 'customers/totals' ),
1119 - ),
1120 - array(
1121 - 'name' => esc_html__( 'Orders Totals', 'visualizer' ),
1122 - 'endpoint' => esc_attr( 'orders/totals' ),
1123 - ),
1124 - array(
1125 - 'name' => esc_html__( 'Products Totals', 'visualizer' ),
1126 - 'endpoint' => esc_attr( 'products/totals' ),
1127 - ),
1128 - array(
1129 - 'name' => esc_html__( 'Reviews Totals', 'visualizer' ),
1130 - 'endpoint' => esc_attr( 'reviews/totals' ),
1131 - ),
1132 - )
1133 - );
1134 - ?>
1135 - <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' ); ?> ">
1136 - <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>
1137 - <div class="viz-group-content edit-data-content">
1138 - <div>
1139 - <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>
1140 - <form id="vz-import-woo-report" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
1141 - <div class="remote-file-section">
1142 - <?php
1143 - $bttn_label = 'visualizer_source_json_wc' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
1144 - ?>
1145 - <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
1146 - <select name="time" id="vz-woo-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
1147 - <?php
1148 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
1149 - $schedules = apply_filters(
1150 - 'visualizer_chart_schedules', array(
1151 - '-1' => __( 'One-time', 'visualizer' ),
1152 - ),
1153 - 'json',
1154 - $chart_id
1155 - );
1156 - foreach ( $schedules as $num => $name ) {
1157 - $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
1158 - ?>
1159 - <option value="<?php echo esc_attr( $num ); ?>" <?php echo esc_attr( $extra ); ?>><?php echo esc_html( $name ); ?></option>
1160 - <?php
1161 - }
1162 - do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
1163 - ?>
1164 - </select>
1165 - <p class="viz-group-description"><?php _e( 'Select report endpoint', 'visualizer' ); ?></p>
1166 - <select name="vz_woo_source" id="vz-woo-source" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
1167 - <option value=""></option>
1168 - <?php
1169 - if ( ! empty( $wc_source_list ) ) {
1170 - foreach ( $wc_source_list as $api ) {
1171 - if ( isset( $api['name'] ) && $api['endpoint'] ) {
1172 - echo sprintf( '<option value="%2$s" %3$s>%1$s</option>', $api['name'], $api['endpoint'], selected( $wc_source, $api['endpoint'], false ) ); // phpcs:ignore
1173 - }
1174 - }
1175 - }
1176 - ?>
1177 - </select>
1178 - </div>
1179 -
1180 - <input type="button" id="woo-chart-button" class="button button-secondary show-chart-toggle"
1181 - value="<?php echo $bttn_label; ?>" data-current="chart"
1182 - data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
1183 - data-t-chart="<?php echo $bttn_label; ?>"
1184 - <?php empty( $wc_source ) ? 'disabled' : ''; ?>
1185 - >
1186 - <input type="button" id="woo-chart-save-button" class="button button-primary "
1187 - value="<?php _e( 'Save Schedule', 'visualizer' ); ?>" <?php empty( $wc_source ) ? 'disabled' : ''; ?>>
1188 - </form>
1189 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wc-report' ); ?>
1190 - </div>
1191 - </div>
1192 - </li>
1193 - <?php endif; ?>
1194 - <?php
1195 924 $save_query = esc_url(
1196 925 add_query_arg(
1197 926 array(
1198 927 'action' => Visualizer_Plugin::ACTION_SAVE_DB_QUERY,
@@ -1202,57 +931,97 @@
1202 931 )
1203 932 );
1204 933 ?>
1205 934 <!-- import from db -->
1206 - <li class="viz-group visualizer_source_query <?php echo esc_attr( apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ) ); ?>">
1207 - <h2 class="viz-group-title viz-sub-group" role="button" tabindex="0"><?php _e( 'Import from database', 'visualizer' ); ?><span
935 + <li class="viz-group visualizer_source_query <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ); ?>">
936 + <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from database', 'visualizer' ); ?><span
1208 937 class="dashicons dashicons-lock"></span></h2>
1209 938 <div class="viz-group-content edit-data-content">
1210 939 <div>
1211 940 <p class="viz-group-description"><?php _e( 'You can import data from the database here.', 'visualizer' ); ?></p>
1212 - <form id="vz-db-wizard" action="<?php echo esc_url( $save_query ); ?>" method="post" target="thehole">
941 + <form id="vz-db-wizard" action="<?php echo $save_query; ?>" method="post" target="thehole">
942 + <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from the database.', 'visualizer' ); ?></p>
943 + <select name="refresh" id="vz-db-import-time" class="visualizer-select">
1213 944 <?php
1214 - $is_db_source = 'visualizer_source_query' === $source_of_chart;
1215 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
1216 - $bttn_label = $is_db_source ? __( '1. Modify Data Source', 'visualizer' ) : __( '1. Choose Data Source', 'visualizer' );
945 + $bttn_label = 'visualizer_source_query' === $source_of_chart ? __( 'Modify Query', 'visualizer' ) : __( 'Create Query', 'visualizer' );
946 + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
947 + $schedules = apply_filters(
948 + 'visualizer_chart_schedules', array(
949 + '-1' => __( 'One-time', 'visualizer' ),
950 + ),
951 + 'db',
952 + $chart_id
953 + );
954 + foreach ( $schedules as $num => $name ) {
955 + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
956 + $extra = $num == $hours ? 'selected' : '';
957 + ?>
958 + <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
959 + <?php
960 + }
961 + do_action( 'visualizer_chart_schedules_spl', 'db', $chart_id, 1 );
1217 962 ?>
963 + </select>
964 + <input type="hidden" name="params" id="viz-db-wizard-params">
1218 965
1219 - <!-- Step 1: Choose / modify data source -->
1220 - <input type="hidden" name="params" id="viz-db-wizard-params">
1221 - <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 ); ?>">
966 + <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; ?>">
967 + <input type="button" id="db-chart-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
968 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
969 + </form>
970 + </div>
971 + </div>
972 + </li>
1222 973
1223 - <!-- Step 2: Sync schedule toggle -->
1224 - <div id="vz-db-sync-step">
1225 - <button type="button" id="vz-db-sync-btn" class="vz-import-step-toggle" aria-expanded="<?php echo $is_db_source ? 'true' : 'false'; ?>">
1226 - <?php echo '2. ' . __( 'Set Sync Schedule', 'visualizer' ); ?>
1227 - <span class="dashicons dashicons-arrow-down-alt2"></span>
1228 - </button>
1229 - <div id="vz-db-sync-options"<?php echo $is_db_source ? '' : ' style="display:none"'; ?>>
1230 - <select name="refresh" id="vz-db-import-time" class="visualizer-select">
974 + <!-- manual -->
975 + <li class="viz-group visualizer_source_manual <?php echo ! Visualizer_Module_Admin::proFeaturesLocked() ? apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ) : ''; ?>">
976 + <h2 class="viz-group-title viz-sub-group visualizer-editor-tab" data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?>
977 + <span class="dashicons dashicons-lock"></span>
978 + </h2>
979 + <div class="viz-group-content edit-data-content">
980 + <form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
981 + <input type="hidden" id="chart-data" name="chart_data">
982 + <input type="hidden" id="chart-data-src" name="chart_data_src">
983 +
984 + <?php if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { ?>
985 + <div>
986 + <p class="viz-group-description viz-editor-selection">
987 + <?php _e( 'Use the', 'visualizer' ); ?>
988 + <select name="editor-type" id="viz-editor-type">
989 + <?php
990 + if ( empty( $editor_type ) ) {
991 + $editor_type = Visualizer_Module::is_pro() ? 'excel' : 'text';
992 + }
993 + foreach ( apply_filters( 'visualizer_editors', array( 'text' => __( 'Text', 'visualizer' ), 'table' => __( 'Simple', 'visualizer' ) ) ) as $e_type => $e_label ) {
994 + ?>
995 + <option value="<?php echo $e_type; ?>" <?php selected( $editor_type, $e_type ); ?> ><?php echo $e_label; ?></option>
996 + <?php } ?>
997 + </select>
998 + <?php _e( 'editor to manually edit the chart data.', 'visualizer' ); ?>
999 + </p>
1000 + <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
1001 + <input type="button" id="editor-button" class="button button-primary "
1002 + value="<?php _e( 'Edit Data', 'visualizer' ); ?>" data-current="chart"
1003 + data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
1004 + data-t-chart="<?php _e( 'Edit Data', 'visualizer' ); ?>"
1005 + >
1006 + <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>
1007 + </div>
1008 + <?php } else { ?>
1009 + <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
1010 + <input type="button" id="editor-chart-button" class="button button-primary "
1011 + value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart"
1012 + data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
1013 + data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>"
1014 + >
1015 + <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>
1016 + <?php } ?>
1231 1017 <?php
1232 - $schedules = apply_filters(
1233 - 'visualizer_chart_schedules', array(
1234 - '-1' => __( 'One-time', 'visualizer' ),
1235 - ),
1236 - 'db',
1237 - $chart_id
1238 - );
1239 - foreach ( $schedules as $num => $name ) {
1240 - $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
1241 - ?>
1242 - <option value="<?php echo esc_attr( $num ); ?>" <?php echo esc_attr( $extra ); ?>><?php echo esc_html( $name ); ?></option>
1243 - <?php
1018 + if ( ! Visualizer_Module_Admin::proFeaturesLocked() ) {
1019 + echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' );
1244 1020 }
1245 - do_action( 'visualizer_chart_schedules_spl', 'db', $chart_id, 1 );
1246 1021 ?>
1247 - </select>
1248 - <input type="button" id="db-chart-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
1249 - </div>
1250 - </div>
1251 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query', 'https://docs.themeisle.com/article/1279-how-to-import-data-from-a-database' ); ?>
1252 - </form>
1253 - </div>
1254 - </div>
1022 + </form>
1023 + </div>
1255 1024 </li>
1256 1025 </ul>
1257 1026 </li>
1258 1027 </ul>
@@ -1260,41 +1029,6 @@
1260 1029
1261 1030 <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>
1262 1031 <iframe id="thehole" name="thehole"></iframe>
1263 1032 <?php
1264 - }
1265 -
1266 - /**
1267 - * Check if the given hour is selected.
1268 - *
1269 - * @param int|float|string $hour The hour.
1270 - * @param int|float|string $reference The number.
1271 - *
1272 - * @return bool
1273 - */
1274 - public static function is_hour_selected( $hour, $reference ) {
1275 -
1276 - if ( ! is_numeric( $hour ) || ! is_numeric( $reference ) ) {
1277 - return false;
1278 - }
1279 -
1280 - $hour = floatval( $hour );
1281 - $reference = floatval( $reference );
1282 -
1283 - if ( self::is_live_update_option( $reference ) ) {
1284 - $reference = self::$live_option_fallback_hour;
1285 - }
1286 -
1287 - return abs( $hour - $reference ) < 0.000001;
1288 - }
1289 -
1290 - /**
1291 - * Check if the reference option is deprecated live update option.
1292 - *
1293 - * @param float $reference_hour The reference hour.
1294 - *
1295 - * @return bool
1296 - */
1297 - public static function is_live_update_option( $reference_hour ) {
1298 - return abs( $reference_hour ) < 0.000001;
1299 1033 }
1300 1034 }