PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.0
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.0, at classes/Visualizer/Render/Page/Data.php

633 lines 30.2 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 $source_of_chart; ?>" data-chart-type="<?php echo $type; ?>" data-chart-lib="<?php echo $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 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 <?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 </div>
418 </div>
419 </li>
420 </ul>
421 </li>
422 </ul>
423 <li class="viz-group viz-group-category bottom-fixed sidebar-footer-link" id="vz-chart-settings">
424 <h2><span class="dashicons dashicons-admin-tools"></span><?php _e( 'Advanced', 'visualizer' ); ?></h2>
425 <div class="viz-group-header">
426 <button class="customize-section-back" tabindex="0"></button>
427 <h3 class="viz-group-title viz-main-group"><?php _e( 'Chart Settings', 'visualizer' ); ?></h3>
428 <h4 class="viz-group-title viz-title-small"><?php _e( 'If you have just updated/modified the chart data, you may need to save it before the new data reflects in the settings.', 'visualizer' ); ?></h4>
429 </div>
430 <ul class="viz-group-content">
431 <form id="settings-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>"
432 method="post">
433 <?php echo $this->sidebar; ?>
434 <input type="hidden" name="save" value="1">
435 </form>
436 <form id="cancel-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>" method="post">
437 <input type="hidden" name="cancel" value="1">
438 </form>
439 </ul>
440 </li>
441
442 <li class="viz-group viz-group-category bottom-fixed sidebar-footer-link" id="vz-chart-docs">
443 <h2><span class="dashicons dashicons-editor-help"></span><a href="<?php echo VISUALIZER_MAIN_DOC; ?>" target="_blank"><?php _e( 'Docs', 'visualizer' ); ?></a></h2>
444 </li>
445
446 <?php $this->getPermissionsLink( $this->chart->ID ); ?>
447
448 <li class="viz-group bottom-fixed" id="vz-chart-copyright">Visualizer &copy; <?php echo date( 'Y', current_time( 'timestamp' ) ); ?></li>
449 </ul>
450 <?php
451 // changed by Ash/Upwork
452 }
453
454 /**
455 * Generates the permissions link.
456 *
457 * @access private
458 * @param int $id The chart id.
459 */
460 private function getPermissionsLink( $id ) {
461 $permissions = apply_filters( 'visualizer_pro_get_permissions', null, $id );
462 if ( $permissions ) {
463 foreach ( $permissions as $k => $v ) {
464 $this->$k = $v;
465 }
466 }
467 ?>
468 <li class="viz-group viz-group-category bottom-fixed sidebar-footer-link" id="vz-chart-permissions">
469 <h2><span class="dashicons dashicons-admin-users"></span><?php _e( 'Permissions', 'visualizer' ); ?></h2>
470 <div class="viz-group-header">
471 <button class="customize-section-back" tabindex="0"></button>
472 <h3 class="viz-group-title viz-main-group"><?php _e( 'Chart Settings', 'visualizer' ); ?></h3>
473 </div>
474 <ul class="viz-group-content">
475 <form id="permissions-form" target="thehole" action="
476 <?php
477 echo add_query_arg(
478 array(
479 'nonce' => wp_create_nonce(),
480 'tab' => 'permissions',
481 ),
482 remove_query_arg( 'tab', $_SERVER['REQUEST_URI'] )
483 );
484 ?>
485 " method="post">
486 <?php $this->permissionsSidebar(); ?>
487 </form>
488 </ul>
489 </li>
490 <?php
491 }
492
493 /**
494 * Generates the permissions form.
495 *
496 * @access private
497 */
498 private function permissionsSidebar() {
499 // ignore for unit tests because Travis throws the error "Indirect modification of overloaded property Visualizer_Render_Page_Data::$permissions has no effect".
500 if ( defined( 'WP_TESTS_DOMAIN' ) ) {
501 return;
502 }
503 Visualizer_Render_Sidebar::_renderGroupStart(
504 esc_html__( 'Who can see this chart?', 'visualizer' ) . '<span
505 class="dashicons dashicons-lock"></span>',
506 '',
507 apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' )
508 );
509 Visualizer_Render_Sidebar::_renderSectionStart();
510 Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Select who can view the chart on the front-end.', 'visualizer' ) );
511
512 if ( ! isset( $this->permissions['read'] ) ) {
513 $this->permissions['read'] = 'all';
514 }
515
516 Visualizer_Render_Sidebar::_renderSelectItem(
517 '',
518 'permissions[read]',
519 $this->permissions['read'],
520 array(
521 'all' => esc_html__( 'All Users', 'visualizer' ),
522 'users' => esc_html__( 'Select Users', 'visualizer' ),
523 'roles' => esc_html__( 'Select Roles', 'visualizer' ),
524 ),
525 '',
526 false,
527 array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-read' ),
528 array(
529 'permission-type' => 'read',
530 )
531 );
532
533 $options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $this->permissions['read'] ) ? $this->permissions['read'] : 'roles' );
534
535 Visualizer_Render_Sidebar::_renderSelectItem(
536 '',
537 'permissions[read-specific][]',
538 isset( $this->permissions['read-specific'] ) ? $this->permissions['read-specific'] : array(),
539 $options,
540 '',
541 true,
542 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-read-specific' )
543 );
544 Visualizer_Render_Sidebar::_renderSectionEnd( apply_filters( 'visualizer_pro_upsell', 'only-pro-feature', 'chart-permissions' ) );
545 Visualizer_Render_Sidebar::_renderGroupEnd();
546
547 Visualizer_Render_Sidebar::_renderGroupStart(
548 esc_html__( 'Who can edit this chart?', 'visualizer' ) . '<span
549 class="dashicons dashicons-lock"></span>',
550 '',
551 apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' )
552 );
553 Visualizer_Render_Sidebar::_renderSectionStart();
554 Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Select who can edit the chart on the front-end.', 'visualizer' ) );
555
556 if ( ! isset( $this->permissions['edit'] ) ) {
557 $this->permissions['edit'] = 'roles';
558 $this->permissions['edit-specific'] = 'administrator';
559 }
560
561 Visualizer_Render_Sidebar::_renderSelectItem(
562 '',
563 'permissions[edit]',
564 $this->permissions['edit'],
565 array(
566 'all' => esc_html__( 'All Users', 'visualizer' ),
567 'users' => esc_html__( 'Select Users', 'visualizer' ),
568 'roles' => esc_html__( 'Select Roles', 'visualizer' ),
569 ),
570 '',
571 false,
572 array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-edit' ),
573 array(
574 'permission-type' => 'edit',
575 )
576 );
577
578 $options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $this->permissions['edit'] ) ? $this->permissions['edit'] : 'roles' );
579
580 Visualizer_Render_Sidebar::_renderSelectItem(
581 '',
582 'permissions[edit-specific][]',
583 isset( $this->permissions['edit-specific'] ) ? $this->permissions['edit-specific'] : array(),
584 $options,
585 '',
586 true,
587 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-edit-specific' )
588 );
589 Visualizer_Render_Sidebar::_renderSectionEnd( apply_filters( 'visualizer_pro_upsell', 'only-pro-feature', 'chart-permissions' ) );
590 Visualizer_Render_Sidebar::_renderGroupEnd();
591
592 }
593
594 /**
595 * Renders toolbar content.
596 *
597 * @since 1.0.0
598 *
599 * @access protected
600 */
601 protected function _renderToolbar() {
602 // don't show back button at all.
603 // 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.
604 if ( ! VISUALIZER_SKIP_CHART_TYPE_PAGE ) {
605 echo '<div class="toolbar-div">';
606 echo '<a class="button button-large" href="', add_query_arg( 'tab', 'types' ), '">';
607 esc_html_e( 'Back', 'visualizer' );
608 echo '</a>';
609 echo '</div>';
610 }
611 echo '<input type="submit" id="settings-button" class="button button-primary button-large push-right" value="', $this->button, '">';
612 if ( isset( $this->cancel_button ) ) {
613 echo '<input type="submit" id="cancel-button" class="button button-secondary button-large push-left" value="', $this->cancel_button, '">';
614 }
615 }
616
617 /**
618 * Renders the additional content.
619 *
620 * @access private
621 */
622 private function add_additional_content() {
623 $source = strtolower( get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_SOURCE, true ) );
624 $query = '';
625 if ( 'visualizer_source_query' === $source ) {
626 $query = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_DB_QUERY, true );
627 }
628 Visualizer_Render_Layout::show( 'db-query', $query );
629 Visualizer_Render_Layout::show( 'json-screen', $this->chart->ID );
630 }
631
632 }
633