PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.4
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.4
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 3.10.4 All 148 releases
visualizer / classes / Visualizer / Render / Page / Data.php

Data.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.3.4, at classes/Visualizer/Render/Page/Data.php

639 lines 30.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // +----------------------------------------------------------------------+
3 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
4 // +----------------------------------------------------------------------+
5 // | This program is free software; you can redistribute it and/or modify |
6 // | it under the terms of the GNU General Public License, version 2, as |
7 // | published by the Free Software Foundation. |
8 // | |
9 // | This program is distributed in the hope that it will be useful, |
10 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 // | GNU General Public License for more details. |
13 // | |
14 // | You should have received a copy of the GNU General Public License |
15 // | along with this program; if not, write to the Free Software |
16 // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
17 // | MA 02110-1301 USA |
18 // +----------------------------------------------------------------------+
19 // | Author: Eugene Manuilov <eugene@manuilov.org> |
20 // +----------------------------------------------------------------------+
21 /**
22 * Renders chart data setup page.
23 *
24 * @category Visualizer
25 * @package Render
26 * @subpackage Page
27 *
28 * @since 1.0.0
29 */
30 class Visualizer_Render_Page_Data extends Visualizer_Render_Page {
31
32 /**
33 * Renders page content.
34 *
35 * @since 1.0.0
36 *
37 * @access protected
38 */
39 protected function _renderContent() {
40 // Added by Ash/Upwork
41 if ( Visualizer_Module::is_pro() ) {
42 do_action( 'visualizer_add_editor_etc', $this->chart->ID );
43
44 if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) {
45 global $Visualizer_Pro;
46 $Visualizer_Pro->_addEditor( $this->chart->ID );
47 if ( method_exists( $Visualizer_Pro, '_addFilterWizard' ) ) {
48 $Visualizer_Pro->_addFilterWizard( $this->chart->ID );
49 }
50 }
51 } else {
52 Visualizer_Render_Layout::show( 'simple-editor-screen', $this->chart->ID );
53 }
54
55 $this->add_additional_content();
56
57 // Added by Ash/Upwork
58 echo '<div id="canvas">';
59 echo '<img src="', VISUALIZER_ABSURL, 'images/ajax-loader.gif" class="loader">';
60 echo '</div>';
61 echo $this->custom_css;
62 }
63
64 /**
65 * Renders sidebar content.
66 *
67 * @since 1.0.0
68 *
69 * @access protected
70 */
71 protected function _renderSidebarContent() {
72 $upload_link = add_query_arg(
73 array(
74 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
75 'nonce' => wp_create_nonce(),
76 'chart' => $this->chart->ID,
77 ),
78 admin_url( 'admin-ajax.php' )
79 );
80
81 // this will allow us to open the correct source tab by default.
82 $source_of_chart = strtolower( get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_SOURCE, true ) );
83 // both import from wp and import from db have the same source so we need to differentiate.
84 $filter_config = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_FILTER_CONFIG, true );
85 // if filter config is present, then its import from wp.
86 if ( ! empty( $filter_config ) ) {
87 $source_of_chart .= '_wp';
88 }
89 $type = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
90 $lib = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_CHART_LIBRARY, true );
91 ?>
92 <span id="visualizer-chart-id" data-id="<?php echo $this->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>
93 <iframe id="thehole" name="thehole"></iframe>
94 <ul class="viz-group-wrapper full-height">
95 <li class="viz-group viz-group-category open" id="vz-chart-source">
96 <div class="viz-group-header">
97 <h2 class="viz-group-title viz-main-group"><?php _e( 'Chart Data', 'visualizer' ); ?></h2>
98 </div>
99 <ul class="viz-group-content">
100 <ul class="viz-group-wrapper">
101 <li class="viz-group visualizer_source_csv">
102 <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from file', 'visualizer' ); ?></h2>
103 <div class="viz-group-content">
104 <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>
105 <p class="viz-group-description"><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/' . $this->type . '.csv" target="_blank">', $this->type, '.csv</a>' ); ?></b></p>
106 <form id="vz-csv-file-form" action="<?php echo $upload_link; ?>" method="post"
107 target="thehole" enctype="multipart/form-data">
108 <input type="hidden" id="remote-data" name="remote_data">
109 <div class="">
110 <input type="file" id="csv-file" name="local_data">
111 </div>
112 <input type="button" class="button button-primary" id="vz-import-file"
113 value="<?php _e( 'Import', 'visualizer' ); ?>">
114 </form>
115 </div>
116 </li>
117 <li class="viz-group visualizer-import-url visualizer_source_csv_remote visualizer_source_json">
118 <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from URL', 'visualizer' ); ?></h2>
119 <ul class="viz-group-content">
120 <li class="viz-subsection">
121 <span class="viz-section-title"><?php _e( 'One time import', 'visualizer' ); ?></span>
122
123 <div class="viz-section-items section-items">
124 <p class="viz-group-description"><?php _e( 'You can use this to import data from a remote CSV file. 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>
125 <p class="viz-group-description"><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 have using non-English characters, please make sure you save the file in UTF-8 encoding.', 'visualizer' ), '<a href="' . VISUALIZER_ABSURL . 'samples/' . $this->type . '.csv" target="_blank">', $this->type, '.csv</a>' ); ?></b></p>
126 <p class="viz-group-description"> <?php _e( 'You can also import data from Google Spreadsheet, for more info check <a href="https://docs.themeisle.com/article/607-how-can-i-populate-data-from-google-spreadsheet" target="_blank" >this</a> tutorial', 'visualizer' ); ?></p>
127 <form id="vz-one-time-import" action="<?php echo $upload_link; ?>" method="post"
128 target="thehole" enctype="multipart/form-data">
129 <div class="remote-file-section">
130 <input type="url" id="remote-data" name="remote_data"
131 placeholder="<?php esc_html_e( 'Please enter the URL of CSV file', 'visualizer' ); ?>"
132 class="visualizer-input">
133
134 </div>
135 <input type="button" id="view-remote-file" class="button button-primary"
136 value="<?php _e( 'Import', 'visualizer' ); ?>">
137 </form>
138 </div>
139 </li>
140 <li class="viz-subsection <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'schedule-chart' ); ?>">
141 <span class="viz-section-title visualizer-import-url-schedule"><?php _e( 'Schedule Import', 'visualizer' ); ?>
142 <span
143 class="dashicons dashicons-lock"></span></span>
144 <div class="viz-section-items section-items">
145 <p class="viz-group-description"><?php _e( 'You can choose here to synchronize your chart data with a remote CSV file.', 'visualizer' ); ?> </p>
146 <p class="viz-group-description"> <?php _e( 'You can also synchronize with your Google Spreadsheet file, for more info check <a href="https://docs.themeisle.com/article/607-how-can-i-populate-data-from-google-spreadsheet" target="_blank" >this</a> tutorial', 'visualizer' ); ?></p>
147 <p class="viz-group-description"> <?php _e( 'We will update the chart data based on your time interval preference by overwriting the current data with the one from the URL.', 'visualizer' ); ?></p>
148 <form id="vz-schedule-import" action="<?php echo $upload_link; ?>" method="post"
149 target="thehole" enctype="multipart/form-data">
150 <div class="remote-file-section">
151 <input type="url" id="vz-schedule-url" name="remote_data"
152 value="<?php echo esc_url( get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_CHART_URL, true ) ); ?>"
153 placeholder="<?php esc_html_e( 'Please enter the URL of CSV file', 'visualizer' ); ?>"
154 class="visualizer-input visualizer-remote-url">
155 <p class="viz-group-description"><?php _e( 'How often do you want to check the url', 'visualizer' ); ?></p>
156 <select name="vz-import-time" id="vz-import-time"
157 class="visualizer-select">
158 <?php
159 $hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
160 $schedules = apply_filters(
161 'visualizer_chart_schedules', array(
162 '1' => __( 'Each hour', 'visualizer' ),
163 '12' => __( 'Each 12 hours', 'visualizer' ),
164 '24' => __( 'Each day', 'visualizer' ),
165 '72' => __( 'Each 3 days', 'visualizer' ),
166 ),
167 'csv',
168 $this->chart->ID
169 );
170 foreach ( $schedules as $num => $name ) {
171 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
172 $extra = $num == $hours ? 'selected' : '';
173 ?>
174 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
175 <?php
176 }
177 ?>
178 </select>
179 </div>
180 <input type="button" id="vz-save-schedule" class="button button-primary"
181 value="<?php _e( 'Save schedule', 'visualizer' ); ?>">
182
183 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'schedule-chart' ); ?>
184 </form>
185 </div>
186 </li>
187
188 <li class="viz-subsection">
189 <span class="viz-section-title visualizer_source_json"><?php _e( 'Import from JSON', 'visualizer' ); ?>
190 <span class="dashicons dashicons-lock"></span></span>
191 <div class="viz-section-items section-items">
192 <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>
193 <form id="vz-import-json" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
194 <div class="remote-file-section">
195 <?php
196 $bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
197 if ( Visualizer_Module::is_pro() ) {
198 ?>
199 <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
200 <select name="vz-json-time" id="vz-json-time" class="visualizer-select" data-chart="<?php echo $this->chart->ID; ?>">
201 <?php
202 $hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
203 $schedules = apply_filters(
204 'visualizer_chart_schedules', array(
205 '-1' => __( 'One-time', 'visualizer' ),
206 ),
207 'json',
208 $this->chart->ID
209 );
210 foreach ( $schedules as $num => $name ) {
211 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
212 $extra = $num == $hours ? 'selected' : '';
213 ?>
214 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
215 <?php
216 }
217 ?>
218 </select>
219 <?php
220 }
221 ?>
222 </div>
223
224 <input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle"
225 value="<?php echo $bttn_label; ?>" data-current="chart"
226 data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
227 data-t-chart="<?php echo $bttn_label; ?>">
228 <?php
229 if ( Visualizer_Module::is_pro() ) {
230 ?>
231 <input type="button" id="json-chart-save-button" class="button button-primary "
232 value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
233 <?php
234 }
235 ?>
236 </form>
237 </div>
238 </li>
239 </ul>
240 </li>
241 <li class="viz-group viz-import-from-other <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
242 <h2 class="viz-group-title viz-sub-group"
243 data-current="chart"><?php _e( 'Import from other chart', 'visualizer' ); ?><span
244 class="dashicons dashicons-lock"></span></h2>
245 <div class="viz-group-content edit-data-content">
246 <div>
247 <p class="viz-group-description"><?php _e( 'You can import here data from your previously created charts', 'visualizer' ); ?></p>
248 <form>
249 <select name="vz-import-from-chart" id="chart-id" class="visualizer-select">
250 <?php
251 $fetch_link = add_query_arg(
252 array(
253 'action' => Visualizer_Module::is_pro() ? Visualizer_Pro::ACTION_FETCH_DATA : '',
254 'nonce' => wp_create_nonce(),
255 ),
256 admin_url( 'admin-ajax.php' )
257 );
258 $query_args_charts = array(
259 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
260 'posts_per_page' => 300,
261 'no_found_rows' => true,
262 );
263 $charts = array();
264 $query = new WP_Query( $query_args_charts );
265 while ( $query->have_posts() ) {
266 $chart = $query->next_post();
267 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
268
269 $title = '#' . $chart->ID;
270 if ( ! empty( $settings['title'] ) ) {
271 $title = $settings['title'];
272 }
273 // for ChartJS, title is an array.
274 if ( is_array( $title ) && isset( $title['text'] ) ) {
275 $title = $title['text'];
276 }
277 if ( empty( $title ) ) {
278 $title = '#' . $chart->ID;
279 }
280
281 ?>
282 <option value="<?php echo $chart->ID; ?>"><?php echo $title; ?></option>
283 <?php
284 }
285 ?>
286
287 </select>
288 </form>
289 <input type="button" id="existing-chart" class="button button-primary"
290 value="<?php _e( 'Import Chart', 'visualizer' ); ?>"
291 data-viz-link="<?php echo $fetch_link; ?>">
292 <?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
293 </div>
294 </div>
295 </li>
296
297 <?php
298 $save_filter = add_query_arg(
299 array(
300 'action' => Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY,
301 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY . Visualizer_Plugin::VERSION ),
302 'chart' => $this->chart->ID,
303 ), admin_url( 'admin-ajax.php' )
304 );
305 ?>
306 <li class="viz-group visualizer_source_query_wp <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'schedule-chart' ); ?> ">
307 <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from WordPress', 'visualizer' ); ?><span
308 class="dashicons dashicons-lock"></span></h2>
309 <div class="viz-group-content edit-data-content">
310 <div>
311 <p class="viz-group-description"><?php _e( 'You can import data from WordPress here.', 'visualizer' ); ?></p>
312 <form id="vz-filter-wizard" action="<?php echo $save_filter; ?>" method="post" target="thehole">
313 <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from WordPress.', 'visualizer' ); ?></p>
314 <select name="refresh" id="vz-filter-import-time" class="visualizer-select">
315 <?php
316 $bttn_label = 'visualizer_source_query_wp' === $source_of_chart ? __( 'Modify Filter', 'visualizer' ) : __( 'Create Filter', 'visualizer' );
317 $hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_DB_SCHEDULE, true );
318 $schedules = apply_filters(
319 'visualizer_schedules', array(
320 '0' => __( 'Live', 'visualizer' ),
321 '1' => __( 'Each hour', 'visualizer' ),
322 '12' => __( 'Each 12 hours', 'visualizer' ),
323 '24' => __( 'Each day', 'visualizer' ),
324 '72' => __( 'Each 3 days', 'visualizer' ),
325 )
326 );
327 foreach ( $schedules as $num => $name ) {
328 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
329 $extra = $num == $hours ? 'selected' : '';
330 ?>
331 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
332 <?php
333 }
334 ?>
335 </select>
336
337 <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; ?>">
338 <input type="button" id="db-filter-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
339 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
340 </form>
341 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'schedule-chart' ); ?>
342 </div>
343 </div>
344 </li>
345
346 <?php
347 $save_query = add_query_arg(
348 array(
349 'action' => Visualizer_Plugin::ACTION_SAVE_DB_QUERY,
350 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_DB_QUERY . Visualizer_Plugin::VERSION ),
351 'chart' => $this->chart->ID,
352 ), admin_url( 'admin-ajax.php' )
353 );
354 ?>
355 <li class="viz-group visualizer_source_query <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ); ?>">
356 <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from database', 'visualizer' ); ?><span
357 class="dashicons dashicons-lock"></span></h2>
358 <div class="viz-group-content edit-data-content">
359 <div>
360 <p class="viz-group-description"><?php _e( 'You can import data from the database here.', 'visualizer' ); ?></p>
361 <form id="vz-db-wizard" action="<?php echo $save_query; ?>" method="post" target="thehole">
362 <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from the database.', 'visualizer' ); ?></p>
363 <select name="refresh" id="vz-db-import-time" class="visualizer-select">
364 <?php
365 $bttn_label = 'visualizer_source_query' === $source_of_chart ? __( 'Modify Query', 'visualizer' ) : __( 'Create Query', 'visualizer' );
366 $hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_DB_SCHEDULE, true );
367 $schedules = apply_filters(
368 'visualizer_schedules', array(
369 '0' => __( 'Live', 'visualizer' ),
370 '1' => __( 'Each hour', 'visualizer' ),
371 '12' => __( 'Each 12 hours', 'visualizer' ),
372 '24' => __( 'Each day', 'visualizer' ),
373 '72' => __( 'Each 3 days', 'visualizer' ),
374 )
375 );
376 foreach ( $schedules as $num => $name ) {
377 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
378 $extra = $num == $hours ? 'selected' : '';
379 ?>
380 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
381 <?php
382 }
383 ?>
384 </select>
385 <input type="hidden" name="params" id="viz-db-wizard-params">
386
387 <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; ?>">
388 <input type="button" id="db-chart-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
389 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
390 </form>
391 </div>
392 </div>
393 </li>
394
395 <?php
396 // we will auto-open the manual data feature only when source is empty.
397 ?>
398 <li class="viz-group <?php echo empty( $source_of_chart ) ? 'open' : ''; ?> ">
399 <h2 class="viz-group-title viz-sub-group visualizer-editor-tab"
400 data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?><span
401 class="dashicons dashicons-lock"></span></h2>
402 <form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
403 <input type="hidden" id="chart-data" name="chart_data">
404 <input type="hidden" id="chart-data-src" name="chart_data_src">
405 </form>
406
407 <div class="viz-group-content edit-data-content">
408 <div>
409 <p class="viz-group-description"><?php echo sprintf( __( 'You can manually edit the chart data using the %s editor.', 'visualizer' ), Visualizer_Module::is_pro() ? 'spreadsheet like' : 'simple' ); ?></p>
410 <?php if ( ! Visualizer_Module::is_pro() ) { ?>
411 <p class="viz-group-description simple-editor-type"><input type="checkbox" id="simple-editor-type" value="textarea"><label for="simple-editor-type"><?php _e( 'Use text area editor instead', 'visualizer' ); ?></label></p>
412 <?php } ?>
413 <input type="button" id="editor-chart-button" class="button button-primary "
414 value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart"
415 data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
416 data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>">
417
418 <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>
419 </div>
420 </div>
421 </li>
422 </ul>
423 </li>
424 </ul>
425 <li class="viz-group viz-group-category bottom-fixed sidebar-footer-link" id="vz-chart-settings">
426 <h2><span class="dashicons dashicons-admin-tools"></span><?php _e( 'Advanced', 'visualizer' ); ?></h2>
427 <div class="viz-group-header">
428 <button class="customize-section-back" tabindex="0"></button>
429 <h3 class="viz-group-title viz-main-group"><?php _e( 'Chart Settings', 'visualizer' ); ?></h3>
430 </div>
431 <ul class="viz-group-content">
432 <form id="settings-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>"
433 method="post">
434 <?php echo $this->sidebar; ?>
435 <input type="hidden" name="save" value="1">
436 </form>
437 <form id="cancel-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>" method="post">
438 <input type="hidden" name="cancel" value="1">
439 </form>
440 </ul>
441 </li>
442
443 <li class="viz-group viz-group-category bottom-fixed sidebar-footer-link" id="vz-chart-docs">
444 <h2><span class="dashicons dashicons-editor-help"></span><a href="<?php echo VISUALIZER_MAIN_DOC; ?>" target="_blank"><?php _e( 'Docs', 'visualizer' ); ?></a></h2>
445 </li>
446
447 <?php $this->getPermissionsLink( $this->chart->ID ); ?>
448
449 <li class="viz-group bottom-fixed" id="vz-chart-copyright">Visualizer &copy;
450 <?php
451 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date, WordPress.DateTime.CurrentTimeTimestamp.Requested
452 echo date( 'Y', current_time( 'timestamp' ) );
453 ?>
454 </li>
455 </ul>
456 <?php
457 // changed by Ash/Upwork
458 }
459
460 /**
461 * Generates the permissions link.
462 *
463 * @access private
464 * @param int $id The chart id.
465 */
466 private function getPermissionsLink( $id ) {
467 $permissions = apply_filters( 'visualizer_pro_get_permissions', null, $id );
468 if ( $permissions ) {
469 foreach ( $permissions as $k => $v ) {
470 $this->$k = $v;
471 }
472 }
473 ?>
474 <li class="viz-group viz-group-category bottom-fixed sidebar-footer-link" id="vz-chart-permissions">
475 <h2><span class="dashicons dashicons-admin-users"></span><?php _e( 'Permissions', 'visualizer' ); ?></h2>
476 <div class="viz-group-header">
477 <button class="customize-section-back" tabindex="0"></button>
478 <h3 class="viz-group-title viz-main-group"><?php _e( 'Chart Settings', 'visualizer' ); ?></h3>
479 </div>
480 <ul class="viz-group-content">
481 <form id="permissions-form" target="thehole" action="
482 <?php
483 echo add_query_arg(
484 array(
485 'nonce' => wp_create_nonce(),
486 'tab' => 'permissions',
487 ),
488 remove_query_arg( 'tab', $_SERVER['REQUEST_URI'] )
489 );
490 ?>
491 " method="post">
492 <?php $this->permissionsSidebar(); ?>
493 </form>
494 </ul>
495 </li>
496 <?php
497 }
498
499 /**
500 * Generates the permissions form.
501 *
502 * @access private
503 */
504 private function permissionsSidebar() {
505 // ignore for unit tests because Travis throws the error "Indirect modification of overloaded property Visualizer_Render_Page_Data::$permissions has no effect".
506 if ( defined( 'WP_TESTS_DOMAIN' ) ) {
507 return;
508 }
509 Visualizer_Render_Sidebar::_renderGroupStart(
510 esc_html__( 'Who can see this chart?', 'visualizer' ) . '<span
511 class="dashicons dashicons-lock"></span>',
512 '',
513 'viz-chart-perm-view ' . apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' )
514 );
515 Visualizer_Render_Sidebar::_renderSectionStart();
516 Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Select who can view the chart on the front-end.', 'visualizer' ) );
517
518 if ( ! isset( $this->permissions['read'] ) ) {
519 $this->permissions['read'] = 'all';
520 }
521
522 Visualizer_Render_Sidebar::_renderSelectItem(
523 '',
524 'permissions[read]',
525 $this->permissions['read'],
526 array(
527 'all' => esc_html__( 'All Users', 'visualizer' ),
528 'users' => esc_html__( 'Select Users', 'visualizer' ),
529 'roles' => esc_html__( 'Select Roles', 'visualizer' ),
530 ),
531 '',
532 false,
533 array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-read' ),
534 array(
535 'permission-type' => 'read',
536 )
537 );
538
539 $options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $this->permissions['read'] ) ? $this->permissions['read'] : 'roles' );
540
541 Visualizer_Render_Sidebar::_renderSelectItem(
542 '',
543 'permissions[read-specific][]',
544 isset( $this->permissions['read-specific'] ) ? $this->permissions['read-specific'] : array(),
545 $options,
546 '',
547 true,
548 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-read-specific' )
549 );
550 Visualizer_Render_Sidebar::_renderSectionEnd( apply_filters( 'visualizer_pro_upsell', 'only-pro-feature', 'chart-permissions' ) );
551 Visualizer_Render_Sidebar::_renderGroupEnd();
552
553 Visualizer_Render_Sidebar::_renderGroupStart(
554 esc_html__( 'Who can edit this chart?', 'visualizer' ) . '<span
555 class="dashicons dashicons-lock"></span>',
556 '',
557 'viz-chart-perm-edit ' . apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' )
558 );
559 Visualizer_Render_Sidebar::_renderSectionStart();
560 Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Select who can edit the chart on the front-end.', 'visualizer' ) );
561
562 if ( ! isset( $this->permissions['edit'] ) ) {
563 $this->permissions['edit'] = 'roles';
564 $this->permissions['edit-specific'] = 'administrator';
565 }
566
567 Visualizer_Render_Sidebar::_renderSelectItem(
568 '',
569 'permissions[edit]',
570 $this->permissions['edit'],
571 array(
572 'all' => esc_html__( 'All Users', 'visualizer' ),
573 'users' => esc_html__( 'Select Users', 'visualizer' ),
574 'roles' => esc_html__( 'Select Roles', 'visualizer' ),
575 ),
576 '',
577 false,
578 array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-edit' ),
579 array(
580 'permission-type' => 'edit',
581 )
582 );
583
584 $options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $this->permissions['edit'] ) ? $this->permissions['edit'] : 'roles' );
585
586 Visualizer_Render_Sidebar::_renderSelectItem(
587 '',
588 'permissions[edit-specific][]',
589 isset( $this->permissions['edit-specific'] ) ? $this->permissions['edit-specific'] : array(),
590 $options,
591 '',
592 true,
593 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-edit-specific' )
594 );
595 Visualizer_Render_Sidebar::_renderSectionEnd( apply_filters( 'visualizer_pro_upsell', 'only-pro-feature', 'chart-permissions' ) );
596 Visualizer_Render_Sidebar::_renderGroupEnd();
597
598 }
599
600 /**
601 * Renders toolbar content.
602 *
603 * @since 1.0.0
604 *
605 * @access protected
606 */
607 protected function _renderToolbar() {
608 // don't show back button at all.
609 // NOTE: We can't be selective on the post_status here because when a new chart reaches the settings screen, its status changes to publish.
610 if ( ! VISUALIZER_SKIP_CHART_TYPE_PAGE ) {
611 echo '<div class="toolbar-div">';
612 echo '<a class="button button-large" href="', add_query_arg( 'tab', 'types' ), '">';
613 esc_html_e( 'Back', 'visualizer' );
614 echo '</a>';
615 echo '</div>';
616 }
617 echo '<input type="submit" id="settings-button" class="button button-primary button-large push-right" value="', $this->button, '">';
618 if ( isset( $this->cancel_button ) ) {
619 echo '<input type="submit" id="cancel-button" class="button button-secondary button-large push-left" value="', $this->cancel_button, '">';
620 }
621 }
622
623 /**
624 * Renders the additional content.
625 *
626 * @access private
627 */
628 private function add_additional_content() {
629 $source = strtolower( get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_SOURCE, true ) );
630 $query = '';
631 if ( 'visualizer_source_query' === $source ) {
632 $query = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_DB_QUERY, true );
633 }
634 Visualizer_Render_Layout::show( 'db-query', $query );
635 Visualizer_Render_Layout::show( 'json-screen', $this->chart->ID );
636 }
637
638 }
639