PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 4.0.8
Visualizer – Tables & Charts Manager with Built-in AI Generator v4.0.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 +381 -224 3.10.154.0.8 View file →
@@ -27,8 +27,15 @@
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 + /**
31 38 * Renders template.
32 39 *
33 40 * @since 1.0.0
34 41 *
@@ -53,9 +60,19 @@
53 60 *
54 61 * @access public
55 62 */
56 63 public static function _renderDbQuery( $args ) {
64 + global $wpdb;
57 65 $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 + }
58 75 ?>
59 76 <div id='visualizer-db-query' style="display: none">
60 77 <div class="visualizer-db-query-form">
61 78 <div>
@@ -71,10 +88,29 @@
71 88 </div>
72 89 </div>
73 90 <div class='db-wizard-hints'>
74 91 <ul>
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>
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>
77 113 <?php do_action( 'visualizer_db_query_add_hints', $args ); ?>
78 114 </ul>
79 115 </div>
80 116 <div class='db-wizard-results'></div>
@@ -151,10 +187,15 @@
151 187 $headers['method'] = 'get';
152 188 }
153 189 $methods = apply_filters( 'visualizer_json_request_methods', array( 'GET', 'POST' ) );
154 190
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 +
155 196 // open the headers by default?
156 - $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'] ) );
197 + $headers_open = ! empty( $auth_username ) || ! empty( $auth_string );
157 198 ?>
158 199 <div id="visualizer-json-screen" style="display: none">
159 200 <div class="visualizer-json-form">
160 201 <h3 class="viz-step step1"><?php _e( 'STEP 1: Specify the JSON endpoint/URL', 'visualizer' ); ?></h3>
@@ -161,9 +202,18 @@
161 202 <div>
162 203 <form id="json-endpoint-form">
163 204 <div class="json-wizard-hints">
164 205 <ul class="info">
165 - <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>
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>
166 216 </ul>
167 217 </div>
168 218
169 219 <input
@@ -196,9 +246,9 @@
196 246 <input
197 247 type="text"
198 248 id="vz-import-json-username"
199 249 name="username"
200 - value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'username', $headers['auth'] ) ? $headers['auth']['username'] : '' ); ?>"
250 + value="<?php echo esc_attr( $auth_username ); ?>"
201 251 placeholder="<?php esc_html_e( 'Username/Access Key', 'visualizer' ); ?>"
202 252 class="json-form-element">
203 253 &
204 254 <input
@@ -204,9 +254,9 @@
204 254 <input
205 255 type="password"
206 256 id="vz-import-json-password"
207 257 name="password"
208 - value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'password', $headers['auth'] ) ? $headers['auth']['password'] : '' ); ?>"
258 + value="<?php echo esc_attr( $auth_password ); ?>"
209 259 placeholder="<?php esc_html_e( 'Password/Secret Key', 'visualizer' ); ?>"
210 260 class="json-form-element">
211 261 </div>
212 262 </div>
@@ -220,9 +270,9 @@
220 270 <input
221 271 type="text"
222 272 id="vz-import-json-auth"
223 273 name="auth"
224 - value="<?php echo ( array_key_exists( 'auth', $headers ) && is_string( $headers['auth'] ) ? $headers['auth'] : '' ); ?>"
274 + value="<?php echo esc_attr( $auth_string ); ?>"
225 275 placeholder="<?php esc_html_e( 'e.g. SharedKey <AccountName>:<Signature>', 'visualizer' ); ?>"
226 276 class="visualizer-input json-form-element">
227 277 </div>
228 278 </div>
@@ -228,9 +278,9 @@
228 278 </div>
229 279 <div class="json-wizard-header">
230 280 <div class="field-title"><?php esc_html_e( 'Additional headers', 'visualizer' ); ?></div>
231 281 <div>
232 - <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>
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>
233 283 </div>
234 284 </div>
235 285 </div>
236 286 </div>
@@ -243,9 +293,9 @@
243 293 <select name="root" id="vz-import-json-root" class="json-form-element">
244 294 <?php
245 295 if ( ! empty( $root ) ) {
246 296 ?>
247 - <option value="<?php echo esc_attr( $root ); ?>"><?php echo str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $root ); ?></option>
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>
248 298 <?php
249 299 }
250 300 ?>
251 301 </select>
@@ -261,9 +311,9 @@
261 311 <option value="0" class="static"><?php _e( 'Get results from the first page only', 'visualizer' ); ?></option>
262 312 <?php
263 313 if ( ! empty( $paging ) ) {
264 314 ?>
265 - <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>
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>
266 316 <?php
267 317 }
268 318 ?>
269 319 </select>
@@ -314,9 +364,9 @@
314 364 $action = esc_url(
315 365 add_query_arg(
316 366 array(
317 367 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
318 - 'nonce' => wp_create_nonce(),
368 + 'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
319 369 'chart' => $chart_id,
320 370 ),
321 371 admin_url( 'admin-ajax.php' )
322 372 )
@@ -344,9 +394,8 @@
344 394 <?php Visualizer_Render_Layout::show( 'text-editor', $chart_id ); ?>
345 395
346 396 </div>
347 397 <?php
348 -
349 398 }
350 399
351 400 /**
352 401 * Show the text area editor.
@@ -486,9 +535,9 @@
486 535 private static function _renderPermissions( $args ) {
487 536 $chart_id = $args[1];
488 537
489 538 // ignore for unit tests because Travis throws the error "Indirect modification of overloaded property Visualizer_Render_Page_Data::$permissions has no effect".
490 - if ( defined( 'WP_TESTS_DOMAIN' ) ) {
539 + if ( defined( 'WP_TESTS_DOMAIN' ) && function_exists( 'tests_add_filter' ) ) {
491 540 return;
492 541 }
493 542
494 543 $permissions = apply_filters( 'visualizer_pro_get_permissions', null, $chart_id );
@@ -571,9 +620,9 @@
571 620 true,
572 621 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-edit-specific' )
573 622 );
574 623 Visualizer_Render_Sidebar::_renderSectionEnd();
575 - echo apply_filters( 'visualizer_pro_upsell', '', 'chart-permissions' );
624 + echo apply_filters( 'visualizer_pro_upsell', '', 'chart-permissions', 'https://docs.themeisle.com/article/1280-how-to-customize-permissions' );
576 625 echo '</div>';
577 626 Visualizer_Render_Sidebar::_renderGroupEnd();
578 627 }
579 628
@@ -582,9 +631,14 @@
582 631 *
583 632 * @access public
584 633 */
585 634 public static function _renderTabAdvanced( $args ) {
586 - $sidebar = $args[2];
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 +
587 641 ?>
588 642 <ul class="viz-group-wrapper full-height">
589 643 <li class="viz-group open" id="vz-chart-settings">
590 644 <ul class="viz-group-content">
@@ -590,8 +644,9 @@
590 644 <ul class="viz-group-content">
591 645 <ul class="viz-group-wrapper">
592 646 <form id="settings-form" action="<?php echo esc_url( add_query_arg( 'nonce', wp_create_nonce() ) ); ?>" method="post">
593 647 <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 ); ?>">
594 649 <?php echo $sidebar; ?>
595 650 <?php self::_renderPermissions( $args ); ?>
596 651 <input type="hidden" name="save" value="1">
597 652 </form>
@@ -637,12 +692,22 @@
637 692 <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>
638 693 <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>
639 694 <?php
640 695 Visualizer_Render_Sidebar::_renderSectionEnd();
696 + // translators: %s - the chart type.
641 697 Visualizer_Render_Sidebar::_renderSectionStart( sprintf( __( '%s chart', 'visualizer' ), ucwords( $displayType ) ), true );
642 698 ?>
643 699 <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>
644 - <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>
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>
645 710 <?php
646 711 Visualizer_Render_Sidebar::_renderSectionEnd();
647 712 Visualizer_Render_Sidebar::_renderGroupEnd();
648 713 ?>
@@ -664,9 +729,9 @@
664 729 $upload_link = esc_url(
665 730 add_query_arg(
666 731 array(
667 732 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
668 - 'nonce' => wp_create_nonce(),
733 + 'nonce' => wp_create_nonce( 'visualizer-upload-data' ),
669 734 'chart' => $chart_id,
670 735 ),
671 736 admin_url( 'admin-ajax.php' )
672 737 )
@@ -685,9 +750,12 @@
685 750 if ( ! empty( $filter_config ) ) {
686 751 $source_of_chart .= '_wp';
687 752 }
688 753 $editor_type = get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR, true );
689 - if ( $editor_type ) {
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 + ) {
690 758 $source_of_chart = 'visualizer_source_manual';
691 759 }
692 760
693 761 $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
@@ -696,125 +764,208 @@
696 764 <ul class="viz-group-wrapper full-height">
697 765 <li class="viz-group open" id="vz-chart-source">
698 766 <ul class="viz-group-content">
699 767 <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>
799 + </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 } ?>
809 + </form>
810 + </div>
811 + </li>
812 +
700 813 <!-- import from file -->
701 - <li class="viz-group visualizer_source_csv">
702 - <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from file', 'visualizer' ); ?></h2>
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>
703 816 <div class="viz-group-content">
704 - <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>
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-csv-file-form" action="<?php echo $upload_link; ?>" method="post"
707 - target="thehole" enctype="multipart/form-data">
708 - <input type="hidden" id="remote-data" name="remote_data">
709 - <div class="">
710 - <input type="file" id="csv-file" name="local_data">
711 - </div>
712 - <input type="button" class="button button-primary" id="vz-import-file"
713 - value="<?php _e( 'Import', 'visualizer' ); ?>">
714 - </form>
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>
715 841 </div>
716 842 </li>
717 843 <!-- import from url -->
718 - <li class="viz-group visualizer-import-url visualizer_source_csv_remote visualizer_source_json">
719 - <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from URL', 'visualizer' ); ?></h2>
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>
720 846 <ul class="viz-group-content">
721 847 <!-- import from csv url -->
722 848 <li class="viz-subsection">
723 - <span class="viz-section-title"><?php _e( 'Import from CSV', 'visualizer' ); ?></span>
724 - <div class="viz-section-items section-items">
725 - <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>
726 - <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>
727 - <form id="vz-one-time-import" action="<?php echo $upload_link; ?>" method="post"
728 - target="thehole" enctype="multipart/form-data">
729 - <div class="remote-file-section">
730 - <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">
731 - </div>
732 - <select name="vz-import-time" id="vz-import-time" class="visualizer-select">
733 - <?php
734 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
735 - $schedules = apply_filters(
736 - 'visualizer_chart_schedules', array(
737 - '-1' => __( 'One-time', 'visualizer' ),
738 - ),
739 - 'csv',
740 - $chart_id
741 - );
742 - foreach ( $schedules as $num => $name ) {
743 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
744 - $extra = $num == $hours ? 'selected' : '';
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">
853 + <?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 + );
745 860 ?>
746 - <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
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">
747 879 <?php
748 - }
749 - do_action( 'visualizer_chart_schedules_spl', 'csv', $chart_id, 1 );
750 - ?>
751 - </select>
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 );
896 + ?>
897 + </select>
752 898
753 - <?php
754 - if ( ! Visualizer_Module::is_pro() ) {
755 - ?>
756 - <input type="button" id="view-remote-file" class="button button-primary" value="<?php _e( 'Import', 'visualizer' ); ?>">
757 899 <?php
758 - } else {
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 + }
759 909 ?>
760 - <input type="button" id="vz-save-schedule" class="button button-primary" value="<?php _e( 'Import & Save schedule', 'visualizer' ); ?>">
761 - <?php
762 - }
763 - ?>
764 - </form>
910 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-url' ); ?>
911 + </form>
912 + </div>
765 913 </div>
766 914 </li>
767 915 <!-- import from json url -->
768 916 <li class="viz-subsection">
769 - <span class="viz-section-title visualizer_source_json"><?php _e( 'Import from JSON', 'visualizer' ); ?></span>
770 - <div class="viz-section-items section-items">
771 - <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>
772 - <form id="vz-import-json" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
773 - <div class="remote-file-section">
774 - <?php
775 - $bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
776 - if ( Visualizer_Module::is_pro() ) {
777 - ?>
778 - <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
779 - <select name="time" id="vz-json-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
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">
780 923 <?php
781 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
782 - $schedules = apply_filters(
783 - 'visualizer_chart_schedules', array(
784 - '-1' => __( 'One-time', 'visualizer' ),
785 - ),
786 - 'json',
787 - $chart_id
788 - );
789 - foreach ( $schedules as $num => $name ) {
790 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
791 - $extra = $num == $hours ? 'selected' : '';
924 + $bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
925 + if ( Visualizer_Module::is_pro() ) {
792 926 ?>
793 - <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
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; ?>">
794 929 <?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
795 949 }
796 - do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
797 950 ?>
798 - </select>
799 - <?php
800 - }
951 + </div>
952 +
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; ?>">
957 + <?php
958 + if ( Visualizer_Module::is_pro() ) {
801 959 ?>
802 - </div>
803 -
804 - <input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle"
805 - value="<?php echo $bttn_label; ?>" data-current="chart"
806 - data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
807 - data-t-chart="<?php echo $bttn_label; ?>">
808 - <?php
809 - if ( Visualizer_Module::is_pro() ) {
960 + <input type="button" id="json-chart-save-button" class="button button-primary "
961 + value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
962 + <?php
963 + }
810 964 ?>
811 - <input type="button" id="json-chart-save-button" class="button button-primary "
812 - value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
813 - <?php
814 - }
815 - ?>
816 - </form>
965 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-url' ); ?>
966 + </form>
967 + </div>
817 968 </div>
818 969 </li>
819 970 </ul>
820 971 </li>
@@ -820,9 +971,9 @@
820 971 </li>
821 972 <!-- import from chart -->
822 973 <li class="viz-group viz-import-from-other <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
823 974 <h2 class="viz-group-title viz-sub-group"
824 - data-current="chart"><?php _e( 'Import from other chart', 'visualizer' ); ?><span
975 + data-current="chart" role="button" tabindex="0"><?php _e( 'Import from other chart', 'visualizer' ); ?><span
825 976 class="dashicons dashicons-lock"></span></h2>
826 977 <div class="viz-group-content edit-data-content">
827 978 <div>
828 979 <p class="viz-group-description"><?php _e( 'You can import here data from your previously created charts', 'visualizer' ); ?></p>
@@ -832,9 +983,9 @@
832 983 $fetch_link = esc_url(
833 984 add_query_arg(
834 985 array(
835 986 'action' => Visualizer_Module::is_pro() ? Visualizer_Pro::ACTION_FETCH_DATA : '',
836 - 'nonce' => wp_create_nonce(),
987 + 'nonce' => Visualizer_Module::is_pro() ? wp_create_nonce( Visualizer_Pro::ACTION_FETCH_DATA ) : wp_create_nonce(),
837 988 ),
838 989 admin_url( 'admin-ajax.php' )
839 990 )
840 991 );
@@ -869,12 +1020,12 @@
869 1020
870 1021 </select>
871 1022 </form>
872 1023 <input type="button" id="existing-chart" class="button button-primary"
873 - value="<?php _e( 'Import Chart', 'visualizer' ); ?>"
874 - data-viz-link="<?php echo $fetch_link; ?>">
1024 + value="<?php _e( 'Import Chart', 'visualizer' ); ?>"
1025 + data-viz-link="<?php echo $fetch_link; ?>">
875 1026 <?php
876 - if ( ! Visualizer_Module_Admin::proFeaturesLocked() ) {
1027 + if ( ! Visualizer_Module_Admin::proFeaturesEnabled() ) {
877 1028 echo apply_filters( 'visualizer_pro_upsell', '', 'import-chart' );
878 1029 }
879 1030 ?>
880 1031 </div>
@@ -892,42 +1043,54 @@
892 1043 )
893 1044 );
894 1045 ?>
895 1046 <!-- import from WordPress -->
896 - <li class="viz-group visualizer_source_query_wp <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-wp' ); ?> ">
897 - <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from WordPress', 'visualizer' ); ?><span
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
898 1049 class="dashicons dashicons-lock"></span></h2>
899 1050 <div class="viz-group-content edit-data-content">
900 1051 <div>
901 1052 <p class="viz-group-description"><?php _e( 'You can import data from WordPress here.', 'visualizer' ); ?></p>
902 - <form id="vz-filter-wizard" action="<?php echo $save_filter; ?>" method="post" target="thehole">
903 - <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from WordPress.', 'visualizer' ); ?></p>
904 - <select name="refresh" id="vz-filter-import-time" class="visualizer-select">
1053 + <form id="vz-filter-wizard" action="<?php echo esc_url( $save_filter ); ?>" method="post" target="thehole">
905 1054 <?php
906 - $bttn_label = 'visualizer_source_query_wp' === $source_of_chart ? __( 'Modify Filter', 'visualizer' ) : __( 'Create Filter', 'visualizer' );
907 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
908 - $schedules = apply_filters(
909 - 'visualizer_chart_schedules', array(
910 - '-1' => __( 'One-time', 'visualizer' ),
911 - ),
912 - 'wp',
913 - $chart_id
914 - );
915 - foreach ( $schedules as $num => $name ) {
916 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
917 - $extra = $num == $hours ? 'selected' : '';
918 - ?>
919 - <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
920 - <?php
921 - }
922 - do_action( 'visualizer_chart_schedules_spl', 'wp', $chart_id, 1 );
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' );
923 1058 ?>
924 - </select>
925 1059
926 - <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; ?>">
927 - <input type="button" id="db-filter-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
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>
928 1091 </form>
929 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wp' ); ?>
1092 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wp', 'https://docs.themeisle.com/article/1278-how-to-import-data-from-wordpress' ); ?>
930 1093 </div>
931 1094 </div>
932 1095 </li>
933 1096
@@ -969,9 +1132,9 @@
969 1132 )
970 1133 );
971 1134 ?>
972 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' ); ?> ">
973 - <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from WooCommerce Reports', 'visualizer' ); ?><span class="dashicons dashicons-lock"></span></h2>
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>
974 1137 <div class="viz-group-content edit-data-content">
975 1138 <div>
976 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>
977 1140 <form id="vz-import-woo-report" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
@@ -990,12 +1153,11 @@
990 1153 'json',
991 1154 $chart_id
992 1155 );
993 1156 foreach ( $schedules as $num => $name ) {
994 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
995 - $extra = $num == $hours ? 'selected' : '';
1157 + $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
996 1158 ?>
997 - <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
1159 + <option value="<?php echo esc_attr( $num ); ?>" <?php echo esc_attr( $extra ); ?>><?php echo esc_html( $name ); ?></option>
998 1160 <?php
999 1161 }
1000 1162 do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
1001 1163 ?>
@@ -1040,98 +1202,58 @@
1040 1202 )
1041 1203 );
1042 1204 ?>
1043 1205 <!-- import from db -->
1044 - <li class="viz-group visualizer_source_query <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ); ?>">
1045 - <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from database', 'visualizer' ); ?><span
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
1046 1208 class="dashicons dashicons-lock"></span></h2>
1047 1209 <div class="viz-group-content edit-data-content">
1048 1210 <div>
1049 1211 <p class="viz-group-description"><?php _e( 'You can import data from the database here.', 'visualizer' ); ?></p>
1050 - <form id="vz-db-wizard" action="<?php echo $save_query; ?>" method="post" target="thehole">
1051 - <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from the database.', 'visualizer' ); ?></p>
1052 - <select name="refresh" id="vz-db-import-time" class="visualizer-select">
1212 + <form id="vz-db-wizard" action="<?php echo esc_url( $save_query ); ?>" method="post" target="thehole">
1053 1213 <?php
1054 - $bttn_label = 'visualizer_source_query' === $source_of_chart ? __( 'Modify Query', 'visualizer' ) : __( 'Create Query', 'visualizer' );
1055 - $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
1056 - $schedules = apply_filters(
1057 - 'visualizer_chart_schedules', array(
1058 - '-1' => __( 'One-time', 'visualizer' ),
1059 - ),
1060 - 'db',
1061 - $chart_id
1062 - );
1063 - foreach ( $schedules as $num => $name ) {
1064 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1065 - $extra = $num == $hours ? 'selected' : '';
1066 - ?>
1067 - <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
1068 - <?php
1069 - }
1070 - do_action( 'visualizer_chart_schedules_spl', 'db', $chart_id, 1 );
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' );
1071 1217 ?>
1072 - </select>
1218 +
1219 + <!-- Step 1: Choose / modify data source -->
1073 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 ); ?>">
1074 1222
1075 - <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; ?>">
1076 - <input type="button" id="db-chart-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
1077 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
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">
1231 + <?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
1244 + }
1245 + do_action( 'visualizer_chart_schedules_spl', 'db', $chart_id, 1 );
1246 + ?>
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' ); ?>
1078 1252 </form>
1079 1253 </div>
1080 1254 </div>
1081 1255 </li>
1082 -
1083 - <!-- manual -->
1084 - <li class="viz-group visualizer_source_manual <?php echo ! Visualizer_Module_Admin::proFeaturesLocked() ? apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ) : ''; ?>">
1085 - <h2 class="viz-group-title viz-sub-group visualizer-editor-tab" data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?>
1086 - <span class="dashicons dashicons-lock"></span>
1087 - </h2>
1088 - <div class="viz-group-content edit-data-content">
1089 - <form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
1090 - <input type="hidden" id="chart-data" name="chart_data">
1091 - <input type="hidden" id="chart-data-src" name="chart_data_src">
1092 -
1093 - <?php if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { ?>
1094 - <div>
1095 - <p class="viz-group-description viz-editor-selection">
1096 - <?php _e( 'Use the', 'visualizer' ); ?>
1097 - <select name="editor-type" id="viz-editor-type">
1098 - <?php
1099 - if ( empty( $editor_type ) ) {
1100 - $editor_type = Visualizer_Module::is_pro() ? 'excel' : 'text';
1101 - }
1102 - foreach ( apply_filters( 'visualizer_editors', array( 'text' => __( 'Text', 'visualizer' ), 'table' => __( 'Simple', 'visualizer' ) ) ) as $e_type => $e_label ) {
1103 - ?>
1104 - <option value="<?php echo $e_type; ?>" <?php selected( $editor_type, $e_type ); ?> ><?php echo $e_label; ?></option>
1105 - <?php } ?>
1106 - </select>
1107 - <?php _e( 'editor to manually edit the chart data.', 'visualizer' ); ?>
1108 - </p>
1109 - <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
1110 - <input type="button" id="editor-button" class="button button-primary "
1111 - value="<?php _e( 'Edit Data', 'visualizer' ); ?>" data-current="chart"
1112 - data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
1113 - data-t-chart="<?php _e( 'Edit Data', 'visualizer' ); ?>"
1114 - >
1115 - <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>
1116 - </div>
1117 - <?php } else { ?>
1118 - <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
1119 - <input type="button" id="editor-chart-button" class="button button-primary "
1120 - value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart"
1121 - data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
1122 - data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>"
1123 - >
1124 - <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>
1125 - <?php } ?>
1126 - <?php
1127 - if ( ! Visualizer_Module_Admin::proFeaturesLocked() ) {
1128 - echo apply_filters( 'visualizer_pro_upsell', '', 'manual-data' );
1129 - }
1130 - ?>
1131 - </form>
1132 - </div>
1133 - </li>
1134 1256 </ul>
1135 1257 </li>
1136 1258 </ul>
1137 1259 </ul>
@@ -1138,6 +1260,41 @@
1138 1260
1139 1261 <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>
1140 1262 <iframe id="thehole" name="thehole"></iframe>
1141 1263 <?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;
1142 1299 }
1143 1300 }