PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.14
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.14
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 +292 -162 3.10.23.11.14 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>
@@ -104,9 +140,9 @@
104 140 </tr>
105 141 </thead>
106 142 <tfoot>
107 143 </tfoot>
108 - <tbody>
144 + <tbody>
109 145 <?php
110 146 foreach ( $results as $result ) {
111 147 echo '<tr>';
112 148 foreach ( $result as $r ) {
@@ -161,9 +197,18 @@
161 197 <div>
162 198 <form id="json-endpoint-form">
163 199 <div class="json-wizard-hints">
164 200 <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>
201 + <li>
202 + <?php
203 + echo sprintf(
204 + // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
205 + __( 'If you want to add authentication or headers to the endpoint or change the request in any way, please refer to our document %1$shere%2$s.', 'visualizer' ),
206 + '<a href="https://docs.themeisle.com/article/1043-visualizer-how-to-extend-rest-endpoints-with-json-response" target="_blank">',
207 + '</a>'
208 + );
209 + ?>
210 + </li>
166 211 </ul>
167 212 </div>
168 213
169 214 <input
@@ -198,9 +243,9 @@
198 243 id="vz-import-json-username"
199 244 name="username"
200 245 value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'username', $headers['auth'] ) ? $headers['auth']['username'] : '' ); ?>"
201 246 placeholder="<?php esc_html_e( 'Username/Access Key', 'visualizer' ); ?>"
202 - class="json-form-element">
247 + class="json-form-element">
203 248 &
204 249 <input
205 250 type="password"
206 251 id="vz-import-json-password"
@@ -206,9 +251,9 @@
206 251 id="vz-import-json-password"
207 252 name="password"
208 253 value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'password', $headers['auth'] ) ? $headers['auth']['password'] : '' ); ?>"
209 254 placeholder="<?php esc_html_e( 'Password/Secret Key', 'visualizer' ); ?>"
210 - class="json-form-element">
255 + class="json-form-element">
211 256 </div>
212 257 </div>
213 258 <div class="json-wizard-header">
214 259 <div></div>
@@ -419,9 +464,9 @@
419 464 }
420 465 ?>
421 466 </tr>
422 467 </thead>
423 - <tbody>
468 + <tbody>
424 469 <tr>
425 470 <th><?php _e( 'Data Type', 'visualizer' ); ?></th>
426 471 <?php
427 472 $index = 0;
@@ -582,9 +627,14 @@
582 627 *
583 628 * @access public
584 629 */
585 630 public static function _renderTabAdvanced( $args ) {
586 - $sidebar = $args[2];
631 + $chart_id = $args[1];
632 + $sidebar = $args[2];
633 +
634 + $chart_options = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
635 + $backend_title = isset( $chart_options['backend-title'] ) && ! empty( $chart_options['backend-title'] ) ? $chart_options['backend-title'] : '';
636 +
587 637 ?>
588 638 <ul class="viz-group-wrapper full-height">
589 639 <li class="viz-group open" id="vz-chart-settings">
590 640 <ul class="viz-group-content">
@@ -590,8 +640,9 @@
590 640 <ul class="viz-group-content">
591 641 <ul class="viz-group-wrapper">
592 642 <form id="settings-form" action="<?php echo esc_url( add_query_arg( 'nonce', wp_create_nonce() ) ); ?>" method="post">
593 643 <input type="hidden" id="chart-img" name="chart-img">
644 + <input type="hidden" id="backend-title" name="backend-title" value="<?php echo esc_html( $backend_title ); ?>">
594 645 <?php echo $sidebar; ?>
595 646 <?php self::_renderPermissions( $args ); ?>
596 647 <input type="hidden" name="save" value="1">
597 648 </form>
@@ -637,12 +688,22 @@
637 688 <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 689 <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 690 <?php
640 691 Visualizer_Render_Sidebar::_renderSectionEnd();
692 + // translators: %s - the chart type.
641 693 Visualizer_Render_Sidebar::_renderSectionStart( sprintf( __( '%s chart', 'visualizer' ), ucwords( $displayType ) ), true );
642 694 ?>
643 695 <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>
696 + <h4><span class="dashicons dashicons-search"></span><a href="<?php echo str_replace( '#', $type, VISUALIZER_DOC_COLLECTION ); ?>" target="_blank">
697 + <?php
698 + echo sprintf(
699 + // translators: %s - the chart type.
700 + __( 'Articles containing "%s"', 'visualizer' ),
701 + $displayType
702 + );
703 + ?>
704 + </a>
705 + </h4>
645 706 <?php
646 707 Visualizer_Render_Sidebar::_renderSectionEnd();
647 708 Visualizer_Render_Sidebar::_renderGroupEnd();
648 709 ?>
@@ -685,9 +746,12 @@
685 746 if ( ! empty( $filter_config ) ) {
686 747 $source_of_chart .= '_wp';
687 748 }
688 749 $editor_type = get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR, true );
689 - if ( $editor_type ) {
750 + if (
751 + $editor_type ||
752 + ! Visualizer_Module::is_pro() // Use Manual Source for non-pro users since it is the only unlocked source.
753 + ) {
690 754 $source_of_chart = 'visualizer_source_manual';
691 755 }
692 756
693 757 $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
@@ -696,125 +760,208 @@
696 760 <ul class="viz-group-wrapper full-height">
697 761 <li class="viz-group open" id="vz-chart-source">
698 762 <ul class="viz-group-content">
699 763 <ul class="viz-group-wrapper">
764 + <!-- manual -->
765 + <li class="viz-group visualizer_source_manual">
766 + <h2 class="viz-group-title viz-sub-group visualizer-editor-tab" data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?></h2>
767 + <div class="viz-group-content edit-data-content">
768 + <form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
769 + <input type="hidden" id="chart-data" name="chart_data">
770 + <input type="hidden" id="chart-data-src" name="chart_data_src">
771 +
772 + <?php if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { ?>
773 + <div>
774 + <p class="viz-group-description viz-editor-selection">
775 + <?php _e( 'Use the', 'visualizer' ); ?>
776 + <select name="editor-type" id="viz-editor-type">
777 + <?php
778 + if ( empty( $editor_type ) ) {
779 + $editor_type = Visualizer_Module::is_pro() ? 'excel' : 'text';
780 + }
781 + foreach ( apply_filters( 'visualizer_editors', array( 'text' => __( 'Text', 'visualizer' ), 'table' => __( 'Simple', 'visualizer' ) ) ) as $e_type => $e_label ) {
782 + ?>
783 + <option value="<?php echo $e_type; ?>" <?php selected( $editor_type, $e_type ); ?> ><?php echo $e_label; ?></option>
784 + <?php } ?>
785 + </select>
786 + <?php _e( 'editor to manually edit the chart data.', 'visualizer' ); ?>
787 + </p>
788 + <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
789 + <input type="button" id="editor-button" class="button button-primary "
790 + value="<?php _e( 'Edit Data', 'visualizer' ); ?>" data-current="chart"
791 + data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
792 + data-t-chart="<?php _e( 'Edit Data', 'visualizer' ); ?>"
793 + >
794 + <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>
795 + </div>
796 + <?php } else { ?>
797 + <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
798 + <input type="button" id="editor-chart-button" class="button button-primary "
799 + value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart"
800 + data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
801 + data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>"
802 + >
803 + <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>
804 + <?php } ?>
805 + </form>
806 + </div>
807 + </li>
808 +
700 809 <!-- 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>
810 + <li class="viz-group visualizer_source_csv <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-file' ); ?> ">
811 + <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from file', 'visualizer' ); ?><span class="dashicons dashicons-lock"></span></h2>
703 812 <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>
813 + <div>
814 + <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>
815 + <p class="viz-group-description viz-info-msg">
816 + <b>
817 + <?php
818 + echo sprintf(
819 + // translators: $s - the chart type with the link attached.
820 + __( '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' ),
821 + '<a href="' . VISUALIZER_ABSURL . 'samples/' . $type . '.csv" target="_blank">' . $type . '.csv</a>'
822 + );
823 + ?>
824 + </b>
825 + </p>
826 + <form id="vz-csv-file-form" action="<?php echo $upload_link; ?>" method="post"
827 + target="thehole" enctype="multipart/form-data">
828 + <input type="hidden" id="remote-data" name="remote_data">
829 + <div class="">
830 + <input type="file" id="csv-file" name="local_data">
831 + </div>
832 + <input type="button" class="button button-primary" id="vz-import-file"
833 + value="<?php _e( 'Import', 'visualizer' ); ?>">
834 + </form>
835 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-file' ); ?>
836 + </div>
715 837 </div>
716 838 </li>
717 839 <!-- 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>
840 + <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' ); ?> ">
841 + <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from URL', 'visualizer' ); ?><span class="dashicons dashicons-lock"></span></h2>
720 842 <ul class="viz-group-content">
721 843 <!-- import from csv url -->
722 844 <li class="viz-subsection">
723 845 <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' : '';
846 + <div class="only-pro-anchor">
847 + <div class="viz-section-items section-items">
848 + <p class="viz-group-description">
849 + <?php
850 + echo sprintf(
851 + // translators: %1$s - HTML link tag, %2$s - HTML closing link tag.
852 + __( 'You can use this to import data from a remote CSV file or %1$sGoogle Spreadsheet%2$s.', 'visualizer' ),
853 + '<a href="https://docs.themeisle.com/article/607-how-can-i-populate-data-from-google-spreadsheet" target="_blank" >',
854 + '</a>'
855 + );
745 856 ?>
746 - <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
857 + </p>
858 + <p class="viz-group-description viz-info-msg">
859 + <b>
860 + <?php
861 + echo sprintf(
862 + // translators: %s - the chart type with the link attached.
863 + __( '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' ),
864 + '<a href="' . VISUALIZER_ABSURL . 'samples/' . $type . '.csv" target="_blank">' . $type . '.csv</a>'
865 + );
866 + ?>
867 + </b>
868 + </p>
869 + <form id="vz-one-time-import" action="<?php echo $upload_link; ?>" method="post"
870 + target="thehole" enctype="multipart/form-data">
871 + <div class="remote-file-section">
872 + <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">
873 + </div>
874 + <select name="vz-import-time" id="vz-import-time" class="visualizer-select">
747 875 <?php
748 - }
749 - do_action( 'visualizer_chart_schedules_spl', 'csv', $chart_id, 1 );
750 - ?>
751 - </select>
876 + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
877 + $schedules = apply_filters(
878 + 'visualizer_chart_schedules', array(
879 + '-1' => __( 'One-time', 'visualizer' ),
880 + ),
881 + 'csv',
882 + $chart_id
883 + );
884 + foreach ( $schedules as $num => $name ) {
885 + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
886 + $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
887 + ?>
888 + <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
889 + <?php
890 + }
891 + do_action( 'visualizer_chart_schedules_spl', 'csv', $chart_id, 1 );
892 + ?>
893 + </select>
752 894
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 895 <?php
758 - } else {
896 + if ( ! Visualizer_Module::is_pro() ) {
897 + ?>
898 + <input type="button" id="view-remote-file" class="button button-primary" value="<?php _e( 'Import', 'visualizer' ); ?>">
899 + <?php
900 + } else {
901 + ?>
902 + <input type="button" id="vz-save-schedule" class="button button-primary" value="<?php _e( 'Import & Save schedule', 'visualizer' ); ?>">
903 + <?php
904 + }
759 905 ?>
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>
906 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-url' ); ?>
907 + </form>
908 + </div>
765 909 </div>
766 910 </li>
767 911 <!-- import from json url -->
768 912 <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; ?>">
913 + <span class="viz-section-title visualizer_source_json"><?php _e( 'Import from JSON', 'visualizer' ); ?></span>
914 + <div class="only-pro-anchor">
915 + <div class="viz-section-items section-items">
916 + <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>
917 + <form id="vz-import-json" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
918 + <div class="remote-file-section">
780 919 <?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' : '';
920 + $bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
921 + if ( Visualizer_Module::is_pro() ) {
792 922 ?>
793 - <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
923 + <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
924 + <select name="time" id="vz-json-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
794 925 <?php
926 + $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
927 + $schedules = apply_filters(
928 + 'visualizer_chart_schedules', array(
929 + '-1' => __( 'One-time', 'visualizer' ),
930 + ),
931 + 'json',
932 + $chart_id
933 + );
934 + foreach ( $schedules as $num => $name ) {
935 + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
936 + $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
937 + ?>
938 + <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
939 + <?php
940 + }
941 + do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
942 + ?>
943 + </select>
944 + <?php
795 945 }
796 - do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
797 946 ?>
798 - </select>
799 - <?php
800 - }
947 + </div>
948 +
949 + <input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle"
950 + value="<?php echo $bttn_label; ?>" data-current="chart"
951 + data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
952 + data-t-chart="<?php echo $bttn_label; ?>">
953 + <?php
954 + if ( Visualizer_Module::is_pro() ) {
801 955 ?>
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() ) {
956 + <input type="button" id="json-chart-save-button" class="button button-primary "
957 + value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
958 + <?php
959 + }
810 960 ?>
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>
961 + <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-url' ); ?>
962 + </form>
963 + </div>
817 964 </div>
818 965 </li>
819 966 </ul>
820 967 </li>
@@ -871,9 +1018,13 @@
871 1018 </form>
872 1019 <input type="button" id="existing-chart" class="button button-primary"
873 1020 value="<?php _e( 'Import Chart', 'visualizer' ); ?>"
874 1021 data-viz-link="<?php echo $fetch_link; ?>">
875 - <?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
1022 + <?php
1023 + if ( ! Visualizer_Module_Admin::proFeaturesLocked() ) {
1024 + echo apply_filters( 'visualizer_pro_upsell', '', 'import-chart' );
1025 + }
1026 + ?>
876 1027 </div>
877 1028 </div>
878 1029 </li>
879 1030
@@ -908,10 +1059,9 @@
908 1059 'wp',
909 1060 $chart_id
910 1061 );
911 1062 foreach ( $schedules as $num => $name ) {
912 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
913 - $extra = $num == $hours ? 'selected' : '';
1063 + $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
914 1064 ?>
915 1065 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
916 1066 <?php
917 1067 }
@@ -920,9 +1070,8 @@
920 1070 </select>
921 1071
922 1072 <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; ?>">
923 1073 <input type="button" id="db-filter-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
924 - <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
925 1074 </form>
926 1075 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wp' ); ?>
927 1076 </div>
928 1077 </div>
@@ -987,10 +1136,9 @@
987 1136 'json',
988 1137 $chart_id
989 1138 );
990 1139 foreach ( $schedules as $num => $name ) {
991 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
992 - $extra = $num == $hours ? 'selected' : '';
1140 + $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
993 1141 ?>
994 1142 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
995 1143 <?php
996 1144 }
@@ -1057,10 +1205,9 @@
1057 1205 'db',
1058 1206 $chart_id
1059 1207 );
1060 1208 foreach ( $schedules as $num => $name ) {
1061 - // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1062 - $extra = $num == $hours ? 'selected' : '';
1209 + $extra = self::is_hour_selected( $hours, $num ) ? 'selected' : '';
1063 1210 ?>
1064 1211 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
1065 1212 <?php
1066 1213 }
@@ -1075,60 +1222,8 @@
1075 1222 </form>
1076 1223 </div>
1077 1224 </div>
1078 1225 </li>
1079 -
1080 - <!-- manual -->
1081 - <li class="viz-group visualizer_source_manual <?php echo ! Visualizer_Module_Admin::proFeaturesLocked() ? apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ) : ''; ?>">
1082 - <h2 class="viz-group-title viz-sub-group visualizer-editor-tab" data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?>
1083 - <span class="dashicons dashicons-lock"></span>
1084 - </h2>
1085 - <div class="viz-group-content edit-data-content">
1086 - <form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
1087 - <input type="hidden" id="chart-data" name="chart_data">
1088 - <input type="hidden" id="chart-data-src" name="chart_data_src">
1089 -
1090 - <?php if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { ?>
1091 - <div>
1092 - <p class="viz-group-description viz-editor-selection">
1093 - <?php _e( 'Use the', 'visualizer' ); ?>
1094 - <select name="editor-type" id="viz-editor-type">
1095 - <?php
1096 - if ( empty( $editor_type ) ) {
1097 - $editor_type = Visualizer_Module::is_pro() ? 'excel' : 'text';
1098 - }
1099 - foreach ( apply_filters( 'visualizer_editors', array( 'text' => __( 'Text', 'visualizer' ), 'table' => __( 'Simple', 'visualizer' ) ) ) as $e_type => $e_label ) {
1100 - ?>
1101 - <option value="<?php echo $e_type; ?>" <?php selected( $editor_type, $e_type ); ?> ><?php echo $e_label; ?></option>
1102 - <?php } ?>
1103 - </select>
1104 - <?php _e( 'editor to manually edit the chart data.', 'visualizer' ); ?>
1105 - </p>
1106 - <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
1107 - <input type="button" id="editor-button" class="button button-primary "
1108 - value="<?php _e( 'Edit Data', 'visualizer' ); ?>" data-current="chart"
1109 - data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
1110 - data-t-chart="<?php _e( 'Edit Data', 'visualizer' ); ?>"
1111 - >
1112 - <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>
1113 - </div>
1114 - <?php } else { ?>
1115 - <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
1116 - <input type="button" id="editor-chart-button" class="button button-primary "
1117 - value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart"
1118 - data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
1119 - data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>"
1120 - >
1121 - <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>
1122 - <?php } ?>
1123 - <?php
1124 - if ( ! Visualizer_Module_Admin::proFeaturesLocked() ) {
1125 - echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' );
1126 - }
1127 - ?>
1128 - </form>
1129 - </div>
1130 - </li>
1131 1226 </ul>
1132 1227 </li>
1133 1228 </ul>
1134 1229 </ul>
@@ -1135,6 +1230,41 @@
1135 1230
1136 1231 <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>
1137 1232 <iframe id="thehole" name="thehole"></iframe>
1138 1233 <?php
1234 + }
1235 +
1236 + /**
1237 + * Check if the given hour is selected.
1238 + *
1239 + * @param int|float|string $hour The hour.
1240 + * @param int|float|string $reference The number.
1241 + *
1242 + * @return bool
1243 + */
1244 + public static function is_hour_selected( $hour, $reference ) {
1245 +
1246 + if ( ! is_numeric( $hour ) || ! is_numeric( $reference ) ) {
1247 + return false;
1248 + }
1249 +
1250 + $hour = floatval( $hour );
1251 + $reference = floatval( $reference );
1252 +
1253 + if ( self::is_live_update_option( $reference ) ) {
1254 + $reference = self::$live_option_fallback_hour;
1255 + }
1256 +
1257 + return abs( $hour - $reference ) < 0.000001;
1258 + }
1259 +
1260 + /**
1261 + * Check if the reference option is deprecated live update option.
1262 + *
1263 + * @param float $reference_hour The reference hour.
1264 + *
1265 + * @return bool
1266 + */
1267 + public static function is_live_update_option( $reference_hour ) {
1268 + return abs( $reference_hour ) < 0.000001;
1139 1269 }
1140 1270 }