PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.7
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.7
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 / Layout.php

Layout.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.4.7, at classes/Visualizer/Render/Layout.php

1,011 lines 43.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // +----------------------------------------------------------------------+
4 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
5 // +----------------------------------------------------------------------+
6 // | This program is free software; you can redistribute it and/or modify |
7 // | it under the terms of the GNU General Public License, version 2, as |
8 // | published by the Free Software Foundation. |
9 // | |
10 // | This program is distributed in the hope that it will be useful, |
11 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 // | GNU General Public License for more details. |
14 // | |
15 // | You should have received a copy of the GNU General Public License |
16 // | along with this program; if not, write to the Free Software |
17 // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
18 // | MA 02110-1301 USA |
19 // +----------------------------------------------------------------------+
20 // | Author: Eugene Manuilov <eugene@manuilov.org> |
21 // +----------------------------------------------------------------------+
22 /**
23 * Layout rendering class.
24 *
25 * @category Visualizer
26 * @package Render
27 */
28 class Visualizer_Render_Layout extends Visualizer_Render {
29
30 /**
31 * Renders template.
32 *
33 * @since 1.0.0
34 *
35 * @abstract
36 * @access protected
37 */
38 protected function _toHTML() {
39 // empty.
40 }
41
42 /**
43 * Show the layout by delegating the call to the layout-specific method with the params.
44 *
45 * @access public
46 */
47 public static function show( $layout ) {
48 return call_user_func( array( __CLASS__, '_render' . str_replace( ' ', '', ucwords( str_replace( '-', ' ', $layout ) ) ) ), func_get_args() );
49 }
50
51 /**
52 * Show the DB query box.
53 *
54 * @access public
55 */
56 public static function _renderDbQuery( $args ) {
57 $query = $args[1];
58 ?>
59 <div id='visualizer-db-query' style="display: none">
60 <div class="visualizer-db-query-form">
61 <div>
62 <form id='db-query-form'>
63 <input type="hidden" name="chart_id" value="<?php echo $args[2]; ?>">
64 <?php do_action( 'visualizer_db_query_add_layout', $args ); ?>
65 <textarea name='query' class='visualizer-db-query' placeholder="<?php _e( 'Your query goes here', 'visualizer' ); ?>"><?php echo $query; ?></textarea>
66 </form>
67 <div class='db-wizard-error'></div>
68 </div>
69 <div>
70 <input type="button" class="button button-primary" id='visualizer-query-fetch' value='<?php _e( 'Show Results', 'visualizer' ); ?>'>
71 </div>
72 </div>
73 <div class='db-wizard-hints'>
74 <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>
77 <?php do_action( 'visualizer_db_query_add_hints', $args ); ?>
78 </ul>
79 </div>
80 <div class='db-wizard-results'></div>
81
82 </div>
83 <?php
84 }
85
86 /**
87 * Show the DB wizard's results table.
88 *
89 * @access public
90 */
91 public static function _renderDbWizardResults( $args ) {
92 $headers = $args[1];
93 $results = $args[2];
94 ob_start();
95 ?>
96 <table cellspacing="0" width="100%" id="results">
97 <thead>
98 <tr>
99 <?php
100 foreach ( $headers as $header ) {
101 echo '<th>' . $header['label'] . '</th>';
102 }
103 ?>
104 </tr>
105 </thead>
106 <tfoot>
107 </tfoot>
108 <tbody>
109 <?php
110 foreach ( $results as $result ) {
111 echo '<tr>';
112 foreach ( $result as $r ) {
113 echo '<td>' . $r . '</td>';
114 }
115 echo '</tr>';
116 }
117 ?>
118 </tbody>
119 </table>
120 <?php
121 return ob_get_clean();
122 }
123
124 /**
125 * Show the JSON/REST parameters boxes.
126 *
127 * @access public
128 */
129 public static function _renderJsonScreen( $args ) {
130 $id = $args[1];
131 $action = add_query_arg(
132 array(
133 'action' => Visualizer_Plugin::ACTION_JSON_SET_DATA,
134 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_SET_DATA . Visualizer_Plugin::VERSION ),
135 'chart' => $id,
136 ),
137 admin_url( 'admin-ajax.php' )
138 );
139
140 $url = get_post_meta( $id, Visualizer_Plugin::CF_JSON_URL, true );
141 $root = get_post_meta( $id, Visualizer_Plugin::CF_JSON_ROOT, true );
142 $paging = get_post_meta( $id, Visualizer_Plugin::CF_JSON_PAGING, true );
143 $headers = get_post_meta( $id, Visualizer_Plugin::CF_JSON_HEADERS, true );
144 if ( empty( $headers ) ) {
145 $headers = array();
146 }
147 if ( $headers && empty( $headers['method'] ) ) {
148 $headers['method'] = 'get';
149 }
150 $methods = apply_filters( 'visualizer_json_request_methods', array( 'GET', 'POST' ) );
151
152 // open the headers by default?
153 $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'] ) );
154 ?>
155 <div id="visualizer-json-screen" style="display: none">
156 <div class="visualizer-json-form">
157 <h3 class="viz-step step1"><?php _e( 'STEP 1: Specify the JSON endpoint/URL', 'visualizer' ); ?></h3>
158 <div>
159 <form id="json-endpoint-form">
160 <div class="json-wizard-hints">
161 <ul class="info">
162 <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>
163 </ul>
164 </div>
165
166 <input
167 type="url"
168 id="vz-import-json-url"
169 name="url"
170 value="<?php echo esc_url( $url ); ?>"
171 placeholder="<?php esc_html_e( 'Please enter the URL', 'visualizer' ); ?>"
172 class="visualizer-input json-form-element">
173 <button class="button button-secondary button-small" id="visualizer-json-fetch"><?php esc_html_e( 'Fetch Endpoint', 'visualizer' ); ?></button>
174
175 <div class="visualizer-json-subform">
176 <h3 class="viz-substep <?php echo $headers_open ? 'open' : ''; ?>"><?php _e( 'Headers', 'visualizer' ); ?></h3>
177 <div class="json-wizard-headers">
178 <div class="json-wizard-header">
179 <div><?php _e( 'Request Type', 'visualizer' ); ?></div>
180 <div>
181 <select name="method" class="json-form-element">
182 <?php foreach ( $methods as $method ) { ?>
183 <option value="<?php echo $method; ?>" <?php $headers && selected( $headers['method'], $method ); ?>><?php echo $method; ?></option>
184 <?php } ?>
185 </select>
186 </div>
187 </div>
188 <div class="json-wizard-header">
189 <div><?php _e( 'Credentials', 'visualizer' ); ?></div>
190 <div>
191 <input
192 type="text"
193 id="vz-import-json-username"
194 name="username"
195 value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'username', $headers['auth'] ) ? $headers['auth']['username'] : '' ); ?>"
196 placeholder="<?php esc_html_e( 'Username/Access Key', 'visualizer' ); ?>"
197 class="json-form-element">
198 &
199 <input
200 type="password"
201 id="vz-import-json-password"
202 name="password"
203 value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'password', $headers['auth'] ) ? $headers['auth']['password'] : '' ); ?>"
204 placeholder="<?php esc_html_e( 'Password/Secret Key', 'visualizer' ); ?>"
205 class="json-form-element">
206 </div>
207 </div>
208 <div class="json-wizard-header">
209 <div></div>
210 <div><?php esc_html_e( 'OR', 'visualizer' ); ?></div>
211 </div>
212 <div class="json-wizard-header">
213 <div><?php esc_html_e( 'Authorization', 'visualizer' ); ?></div>
214 <div>
215 <input
216 type="text"
217 id="vz-import-json-auth"
218 name="auth"
219 value="<?php echo ( array_key_exists( 'auth', $headers ) && is_string( $headers['auth'] ) ? $headers['auth'] : '' ); ?>"
220 placeholder="<?php esc_html_e( 'e.g. SharedKey <AccountName>:<Signature>', 'visualizer' ); ?>"
221 class="visualizer-input json-form-element">
222 </div>
223 </div>
224 </div>
225 </div>
226 </form>
227 </div>
228 <h3 class="viz-step step2 <?php echo empty( $url ) ? 'ui-state-disabled' : ''; ?> json-root-form"><?php _e( 'STEP 2: Choose the JSON root', 'visualizer' ); ?></h3>
229 <div>
230 <form id="json-root-form">
231 <input type="hidden" name="chart" value="<?php echo $id; ?>">
232 <select name="root" id="vz-import-json-root" class="json-form-element">
233 <?php
234 if ( ! empty( $root ) ) {
235 ?>
236 <option value="<?php echo esc_attr( $root ); ?>"><?php echo str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $root ); ?></option>
237 <?php
238 }
239 ?>
240 </select>
241 <button class="button button-secondary button-small" id="visualizer-json-parse"><?php esc_html_e( 'Parse Endpoint', 'visualizer' ); ?></button>
242 </form>
243 </div>
244 <h3 class="viz-step step3 <?php echo empty( $root ) ? 'ui-state-disabled' : ''; ?>"><?php _e( 'STEP 3: Specify miscellaneous parameters', 'visualizer' ); ?></h3>
245 <div>
246 <form id="json-conclude-form-helper">
247 <div class="<?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
248 <div class="json-pagination">
249 <select name="paging" id="vz-import-json-paging" class="json-form-element" data-template='<?php echo sprintf( 'Get results from the first %d pages using %s', apply_filters( 'visualizer_json_fetch_pages', 5, $url ), '?' ); ?>'>
250 <option value="0" class="static"><?php _e( 'Get results from the first page only', 'visualizer' ); ?></option>
251 <?php
252 if ( ! empty( $paging ) ) {
253 ?>
254 <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>
255 <?php
256 }
257 ?>
258 </select>
259 <?php
260 if ( ! Visualizer_Module::is_pro() ) {
261 ?>
262 <br/>
263 <br/>
264 <br/>
265 <br/>
266 <?php
267 }
268 ?>
269 <?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
270 </div>
271 </div>
272 </form>
273 </div>
274 <h3 class="viz-step step4 ui-state-disabled"><?php _e( 'STEP 4: Select the data to display in the chart', 'visualizer' ); ?></h3>
275 <div>
276 <form id="json-conclude-form" action="<?php echo $action; ?>" method="post" target="thehole">
277 <div class="json-wizard-hints html-table-editor-hints">
278 <ul class="info">
279 <li><?php _e( 'If you see Invalid Data in the table, you may have selected the wrong root to fetch data from. Please select an alternative from the JSON root dropdown.', 'visualizer' ); ?></li>
280 <li><?php _e( 'Select whether to include the data in the chart. Each column selected will form one series.', 'visualizer' ); ?></li>
281 <li><?php _e( 'If a column is selected to be included, specify its data type.', 'visualizer' ); ?></li>
282 <li><?php _e( 'You can use drag/drop to reorder the columns but this column position is not saved. So when you reload the table, you may have to reorder again.', 'visualizer' ); ?></li>
283 <li><?php _e( 'You can select any number of columns but the chart type selected will determine how many will display in the chart.', 'visualizer' ); ?></li>
284 <li><?php _e( 'Once you have made your selection, click \'Show Chart\' on the right to view the chart.', 'visualizer' ); ?></li>
285 </ul>
286 </div>
287 <div class="json-table"></div>
288 <button class="button button-primary" style="display: none" id="visualizer-json-conclude"></button>
289 </form>
290 </div>
291 </div>
292 </div>
293 <?php
294 }
295
296 /**
297 * Show the simple editor(s).
298 *
299 * @access public
300 */
301 public static function _renderSimpleEditorScreen( $args ) {
302 $chart_id = $args[1];
303 $action = add_query_arg(
304 array(
305 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
306 'nonce' => wp_create_nonce(),
307 'chart' => $chart_id,
308 ),
309 admin_url( 'admin-ajax.php' )
310 );
311 ?>
312 <div class="viz-simple-editor">
313 <div class="viz-simple-editor-type viz-table-editor">
314 <form id="table-editor-form" action="<?php echo $action; ?>" method="post" target="thehole">
315 <div class="html-table-editor-hints">
316 <ul class="info">
317 <li><?php _e( 'Select whether to include the data in the chart. Each column selected will form one series.', 'visualizer' ); ?></li>
318 <li><?php _e( 'If a column is selected to be included, specify its data type.', 'visualizer' ); ?></li>
319 <li><?php _e( 'You can use drag/drop to reorder the columns but this column position is not saved. So when you reload the table, you may have to reorder again.', 'visualizer' ); ?></li>
320 <li><?php _e( 'You can select any number of columns but the chart type selected will determine how many will display in the chart.', 'visualizer' ); ?></li>
321 </ul>
322 </div>
323 <div class="viz-html-table">
324 <?php Visualizer_Render_Layout::show( 'editor-table', null, $chart_id, 'viz-html-table', true, true ); ?>
325 </div>
326 <input type="hidden" name="table_data" value="yes">
327 <input type="hidden" name="editor-type" value="table">
328 </form>
329 </div>
330
331 <?php Visualizer_Render_Layout::show( 'text-editor', $chart_id ); ?>
332
333 </div>
334 <?php
335
336 }
337
338 /**
339 * Show the text area editor.
340 *
341 * @access public
342 */
343 public static function _renderTextEditor( $args ) {
344 $chart_id = $args[1];
345 $csv = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, array(), $chart_id, 'csv-display' );
346 $data = '';
347 if ( ! empty( $csv ) && isset( $csv['string'] ) ) {
348 $data = str_replace( PHP_EOL, "\n", stripslashes( $csv['string'] ) );
349 }
350 ?>
351 <div class="viz-simple-editor-type viz-text-editor">
352 <textarea id="edited_text"><?php echo $data; ?></textarea>
353 </div>
354 <?php
355 }
356
357 /**
358 * Show the JSON endpoint's parsed table.
359 *
360 * @access public
361 */
362 public static function _renderEditorTable( $args ) {
363 $data = $args[1];
364 $chart_id = $args[2];
365 $class = $args[3];
366 $echo = $args[4];
367 $editable_data = $args[5];
368 $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true );
369 $headers = array();
370
371 if ( is_null( $data ) ) {
372 foreach ( $series as $column ) {
373 $headers[] = $column['label'];
374 }
375 $chart = get_post( $chart_id );
376 $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
377 $data = Visualizer_Module::get_chart_data( $chart, $type );
378 } else {
379 $headers = array_keys( $data[0] );
380 }
381
382 $classes = implode( ' ', array( 'viz-editor-table', $class ) );
383
384 if ( $series ) {
385 $temp = $series;
386 $series = array();
387 foreach ( $temp as $array ) {
388 $series[ $array['label'] ] = $array['type'];
389 }
390 }
391 if ( ! $echo ) {
392 ob_start();
393 }
394 ?>
395 <table cellspacing="0" width="100%" class="results cell-border stripe <?php echo $classes; ?>">
396 <thead>
397 <tr>
398 <th><?php _e( 'Label', 'visualizer' ); ?></th>
399 <?php
400 foreach ( $headers as $header ) {
401 if ( $editable_data ) {
402 echo '<th><input type="text" name="header[]" value="' . esc_attr( $header ) . '"></th>';
403 } else {
404 echo '<th>' . $header . '</th>';
405 }
406 }
407 ?>
408 </tr>
409 </thead>
410 <tbody>
411 <tr>
412 <th><?php _e( 'Data Type', 'visualizer' ); ?></th>
413 <?php
414 $index = 0;
415 foreach ( $headers as $header ) {
416 echo '<td>';
417 if ( $editable_data ) {
418 echo '<select name="type[]">';
419 } else {
420 echo '<input name="header[]" type="hidden" value="' . $header . '">';
421 echo '<select name="type[' . $header . ']" class="viz-select-data-type">';
422 }
423 echo '<option value="" title="' . __( 'Exclude from chart', 'visualizer' ) . '">' . __( 'Exclude', 'visualizer' ) . '</option>';
424 echo '<option value="0" disabled title="' . __( 'Include in chart and select data type', 'visualizer' ) . '">--' . __( 'OR', 'visualizer' ) . '--</option>';
425
426 foreach ( Visualizer_Source::getAllowedTypes() as $type ) {
427 $selected = array_key_exists( $header, $series ) && $type === $series[ $header ] ? 'selected' : '';
428 echo '<option value="' . $type . '" ' . $selected . '>' . $type . '</option>';
429 }
430
431 echo '</select></td>';
432 }
433 ?>
434 </tr>
435 <?php
436 // for remote sources, the data exists inside 'data'.
437 if ( array_key_exists( 'data', $data ) ) {
438 $data = $data['data'];
439 }
440
441 foreach ( $data as $row ) {
442 echo '<tr>';
443 echo '<th>' . __( 'Value', 'visualizer' ) . '</th>';
444 $index = 0;
445 if ( empty( $row ) ) {
446 echo '<td></td>';
447 continue;
448 }
449 foreach ( array_values( $row ) as $value ) {
450 if ( $editable_data ) {
451 echo '<td><input type="text" name="data' . $index++ . '[]" value="' . esc_attr( stripslashes( $value ) ) . '"></td>';
452 } else {
453 echo '<td>' . ( is_array( $value ) ? __( 'Invalid Data', 'visualizer' ) : $value ) . '</td>';
454 }
455 }
456
457 echo '</tr>';
458 }
459 ?>
460 </tbody>
461 </table>
462 <?php
463 if ( ! $echo ) {
464 return ob_get_clean();
465 }
466 }
467
468 /**
469 * Generates the permissions tab.
470 *
471 * @access private
472 */
473 private static function _renderPermissions( $args ) {
474 $chart_id = $args[1];
475
476 // ignore for unit tests because Travis throws the error "Indirect modification of overloaded property Visualizer_Render_Page_Data::$permissions has no effect".
477 if ( defined( 'WP_TESTS_DOMAIN' ) ) {
478 return;
479 }
480
481 $permissions = apply_filters( 'visualizer_pro_get_permissions', null, $chart_id );
482 if ( is_array( $permissions ) ) {
483 $permissions = $permissions['permissions'];
484 } else {
485 $permissions = array();
486 }
487 if ( ! isset( $permissions['read'] ) ) {
488 $permissions['read'] = 'all';
489 }
490 if ( ! isset( $permissions['edit'] ) ) {
491 $permissions['edit'] = 'roles';
492 $permissions['edit-specific'] = 'administrator';
493 }
494
495 Visualizer_Render_Sidebar::_renderGroupStart( esc_html__( 'Permissions', 'visualizer' ) . '<span class="dashicons dashicons-lock"></span>', '', apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' ), 'vz-permissions' );
496 echo '<div style="position: relative">';
497 Visualizer_Render_Sidebar::_renderSectionStart();
498 Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Configure permissions for the chart.', 'visualizer' ) );
499 Visualizer_Render_Sidebar::_renderSectionEnd();
500
501 Visualizer_Render_Sidebar::_renderSectionStart( esc_html__( 'Who can see this chart?', 'visualizer' ), false );
502 Visualizer_Render_Sidebar::_renderSelectItem(
503 '',
504 'permissions[read]',
505 $permissions['read'],
506 array(
507 'all' => esc_html__( 'All Users', 'visualizer' ),
508 'users' => esc_html__( 'Select Users', 'visualizer' ),
509 'roles' => esc_html__( 'Select Roles', 'visualizer' ),
510 ),
511 '',
512 false,
513 array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-read' ),
514 array(
515 'permission-type' => 'read',
516 )
517 );
518
519 $options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $permissions['read'] ) ? $permissions['read'] : 'roles' );
520
521 Visualizer_Render_Sidebar::_renderSelectItem(
522 '',
523 'permissions[read-specific][]',
524 isset( $permissions['read-specific'] ) ? $permissions['read-specific'] : array(),
525 $options,
526 '',
527 true,
528 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-read-specific' )
529 );
530 Visualizer_Render_Sidebar::_renderSectionEnd();
531
532 Visualizer_Render_Sidebar::_renderSectionStart( esc_html__( 'Who can edit this chart?', 'visualizer' ), false );
533 Visualizer_Render_Sidebar::_renderSelectItem(
534 '',
535 'permissions[edit]',
536 $permissions['edit'],
537 array(
538 'all' => esc_html__( 'All Users', 'visualizer' ),
539 'users' => esc_html__( 'Select Users', 'visualizer' ),
540 'roles' => esc_html__( 'Select Roles', 'visualizer' ),
541 ),
542 '',
543 false,
544 array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-edit' ),
545 array(
546 'permission-type' => 'edit',
547 )
548 );
549
550 $options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $permissions['edit'] ) ? $permissions['edit'] : 'roles' );
551
552 Visualizer_Render_Sidebar::_renderSelectItem(
553 '',
554 'permissions[edit-specific][]',
555 isset( $permissions['edit-specific'] ) ? $permissions['edit-specific'] : array(),
556 $options,
557 '',
558 true,
559 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-edit-specific' )
560 );
561 Visualizer_Render_Sidebar::_renderSectionEnd();
562 echo apply_filters( 'visualizer_pro_upsell', '', 'chart-permissions' );
563 echo '</div>';
564 Visualizer_Render_Sidebar::_renderGroupEnd();
565 }
566
567 /**
568 * Show the Settings tab for this chart.
569 *
570 * @access public
571 */
572 public static function _renderTabAdvanced( $args ) {
573 $sidebar = $args[2];
574 ?>
575 <ul class="viz-group-wrapper full-height">
576 <li class="viz-group open" id="vz-chart-settings">
577 <ul class="viz-group-content">
578 <ul class="viz-group-wrapper">
579 <form id="settings-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>" method="post">
580 <?php echo $sidebar; ?>
581 <?php self::_renderPermissions( $args ); ?>
582 <input type="hidden" name="save" value="1">
583 </form>
584 <form id="cancel-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>" method="post">
585 <input type="hidden" name="cancel" value="1">
586 </form>
587 </ul>
588 </ul>
589 </li>
590 <?php
591 }
592
593 /**
594 * Show the Docs tab for this chart.
595 *
596 * @access public
597 */
598 public static function _renderTabHelp( $args ) {
599 $chart_id = $args[1];
600 $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
601 switch ( $type ) {
602 case 'tabular':
603 $type = 'table';
604 break;
605 case 'polarArea':
606 $type = 'polar-area';
607 break;
608 case 'radar':
609 $type = 'radar-spider';
610 break;
611 }
612
613 $displayType = str_replace( '-', '/', $type );
614 ?>
615 <ul class="viz-group-wrapper full-height">
616 <li class="viz-group open" id="vz-chart-help">
617 <ul class="viz-group-wrapper">
618 <?php
619 // open this tab by default.
620 Visualizer_Render_Sidebar::_renderGroupStart( esc_html__( 'Documentation', 'visualizer' ), '', 'open' );
621 Visualizer_Render_Sidebar::_renderSectionStart( esc_html__( 'General', 'visualizer' ), true );
622 ?>
623 <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>
624 <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>
625 <?php
626 Visualizer_Render_Sidebar::_renderSectionEnd();
627 Visualizer_Render_Sidebar::_renderSectionStart( sprintf( __( '%s chart', 'visualizer' ), ucwords( $displayType ) ), true );
628 ?>
629 <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>
630 <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>
631 <?php
632 Visualizer_Render_Sidebar::_renderSectionEnd();
633 Visualizer_Render_Sidebar::_renderGroupEnd();
634 ?>
635 </ul>
636 </li>
637 </ul>
638
639 <?php
640 }
641
642 /**
643 * Show the Data Source tab for this chart.
644 *
645 * @access public
646 */
647 public static function _renderTabBasic( $args ) {
648 $chart_id = $args[1];
649
650 $upload_link = add_query_arg(
651 array(
652 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
653 'nonce' => wp_create_nonce(),
654 'chart' => $chart_id,
655 ),
656 admin_url( 'admin-ajax.php' )
657 );
658
659 // this will allow us to open the correct source tab by default.
660 $source_of_chart = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
661 // both import from wp and import from db have the same source so we need to differentiate.
662 $filter_config = get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true );
663 // if filter config is present, then its import from wp.
664 if ( ! empty( $filter_config ) ) {
665 $source_of_chart .= '_wp';
666 }
667 $editor_type = get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR, true );
668 if ( $editor_type ) {
669 $source_of_chart = 'visualizer_source_manual';
670 }
671
672 $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
673 $lib = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, true );
674 ?>
675 <ul class="viz-group-wrapper full-height">
676 <li class="viz-group open" id="vz-chart-source">
677 <ul class="viz-group-content">
678 <ul class="viz-group-wrapper">
679 <!-- import from file -->
680 <li class="viz-group visualizer_source_csv">
681 <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from file', 'visualizer' ); ?></h2>
682 <div class="viz-group-content">
683 <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>
684 <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>
685 <form id="vz-csv-file-form" action="<?php echo $upload_link; ?>" method="post"
686 target="thehole" enctype="multipart/form-data">
687 <input type="hidden" id="remote-data" name="remote_data">
688 <div class="">
689 <input type="file" id="csv-file" name="local_data">
690 </div>
691 <input type="button" class="button button-primary" id="vz-import-file"
692 value="<?php _e( 'Import', 'visualizer' ); ?>">
693 </form>
694 </div>
695 </li>
696 <!-- import from url -->
697 <li class="viz-group visualizer-import-url visualizer_source_csv_remote visualizer_source_json">
698 <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from URL', 'visualizer' ); ?></h2>
699 <ul class="viz-group-content">
700 <!-- import from csv url -->
701 <li class="viz-subsection">
702 <span class="viz-section-title"><?php _e( 'Import from CSV', 'visualizer' ); ?></span>
703 <div class="viz-section-items section-items">
704 <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>
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-one-time-import" action="<?php echo $upload_link; ?>" method="post"
707 target="thehole" enctype="multipart/form-data">
708 <div class="remote-file-section">
709 <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">
710 </div>
711 <select name="vz-import-time" id="vz-import-time" class="visualizer-select">
712 <?php
713 $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
714 $schedules = apply_filters(
715 'visualizer_chart_schedules', array(
716 '-1' => __( 'One-time', 'visualizer' ),
717 ),
718 'csv',
719 $chart_id
720 );
721 foreach ( $schedules as $num => $name ) {
722 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
723 $extra = $num == $hours ? 'selected' : '';
724 ?>
725 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
726 <?php
727 }
728 do_action( 'visualizer_chart_schedules_spl', 'csv', $chart_id, 1 );
729 ?>
730 </select>
731
732 <?php
733 if ( ! Visualizer_Module::is_pro() ) {
734 ?>
735 <input type="button" id="view-remote-file" class="button button-primary" value="<?php _e( 'Import', 'visualizer' ); ?>">
736 <?php
737 } else {
738 ?>
739 <input type="button" id="vz-save-schedule" class="button button-primary" value="<?php _e( 'Import & Save schedule', 'visualizer' ); ?>">
740 <?php
741 }
742 ?>
743 </form>
744 </div>
745 </li>
746 <!-- import from json url -->
747 <li class="viz-subsection">
748 <span class="viz-section-title visualizer_source_json"><?php _e( 'Import from JSON', 'visualizer' ); ?></span>
749 <div class="viz-section-items section-items">
750 <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>
751 <form id="vz-import-json" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
752 <div class="remote-file-section">
753 <?php
754 $bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
755 if ( Visualizer_Module::is_pro() ) {
756 ?>
757 <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
758 <select name="time" id="vz-json-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
759 <?php
760 $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
761 $schedules = apply_filters(
762 'visualizer_chart_schedules', array(
763 '-1' => __( 'One-time', 'visualizer' ),
764 ),
765 'json',
766 $chart_id
767 );
768 foreach ( $schedules as $num => $name ) {
769 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
770 $extra = $num == $hours ? 'selected' : '';
771 ?>
772 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
773 <?php
774 }
775 do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
776 ?>
777 </select>
778 <?php
779 }
780 ?>
781 </div>
782
783 <input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle"
784 value="<?php echo $bttn_label; ?>" data-current="chart"
785 data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
786 data-t-chart="<?php echo $bttn_label; ?>">
787 <?php
788 if ( Visualizer_Module::is_pro() ) {
789 ?>
790 <input type="button" id="json-chart-save-button" class="button button-primary "
791 value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
792 <?php
793 }
794 ?>
795 </form>
796 </div>
797 </li>
798 </ul>
799 </li>
800 <!-- import from chart -->
801 <li class="viz-group viz-import-from-other <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
802 <h2 class="viz-group-title viz-sub-group"
803 data-current="chart"><?php _e( 'Import from other chart', 'visualizer' ); ?><span
804 class="dashicons dashicons-lock"></span></h2>
805 <div class="viz-group-content edit-data-content">
806 <div>
807 <p class="viz-group-description"><?php _e( 'You can import here data from your previously created charts', 'visualizer' ); ?></p>
808 <form>
809 <select name="vz-import-from-chart" id="chart-id" class="visualizer-select">
810 <?php
811 $fetch_link = add_query_arg(
812 array(
813 'action' => Visualizer_Module::is_pro() ? Visualizer_Pro::ACTION_FETCH_DATA : '',
814 'nonce' => wp_create_nonce(),
815 ),
816 admin_url( 'admin-ajax.php' )
817 );
818 $query_args_charts = array(
819 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
820 'posts_per_page' => 300,
821 'no_found_rows' => true,
822 );
823 $charts = array();
824 $query = new WP_Query( $query_args_charts );
825 while ( $query->have_posts() ) {
826 $chart = $query->next_post();
827 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
828
829 $title = '#' . $chart->ID;
830 if ( ! empty( $settings['title'] ) ) {
831 $title = $settings['title'];
832 }
833 // for ChartJS, title is an array.
834 if ( is_array( $title ) && isset( $title['text'] ) ) {
835 $title = $title['text'];
836 }
837 if ( empty( $title ) ) {
838 $title = '#' . $chart->ID;
839 }
840
841 ?>
842 <option value="<?php echo $chart->ID; ?>"><?php echo $title; ?></option>
843 <?php
844 }
845 ?>
846
847 </select>
848 </form>
849 <input type="button" id="existing-chart" class="button button-primary"
850 value="<?php _e( 'Import Chart', 'visualizer' ); ?>"
851 data-viz-link="<?php echo $fetch_link; ?>">
852 <?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
853 </div>
854 </div>
855 </li>
856
857 <?php
858 $save_filter = add_query_arg(
859 array(
860 'action' => Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY,
861 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY . Visualizer_Plugin::VERSION ),
862 'chart' => $chart_id,
863 ), admin_url( 'admin-ajax.php' )
864 );
865 ?>
866 <!-- import from WordPress -->
867 <li class="viz-group visualizer_source_query_wp <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-wp' ); ?> ">
868 <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from WordPress', 'visualizer' ); ?><span
869 class="dashicons dashicons-lock"></span></h2>
870 <div class="viz-group-content edit-data-content">
871 <div>
872 <p class="viz-group-description"><?php _e( 'You can import data from WordPress here.', 'visualizer' ); ?></p>
873 <form id="vz-filter-wizard" action="<?php echo $save_filter; ?>" method="post" target="thehole">
874 <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from WordPress.', 'visualizer' ); ?></p>
875 <select name="refresh" id="vz-filter-import-time" class="visualizer-select">
876 <?php
877 $bttn_label = 'visualizer_source_query_wp' === $source_of_chart ? __( 'Modify Filter', 'visualizer' ) : __( 'Create Filter', 'visualizer' );
878 $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
879 $schedules = apply_filters(
880 'visualizer_chart_schedules', array(
881 '-1' => __( 'One-time', 'visualizer' ),
882 ),
883 'wp',
884 $chart_id
885 );
886 foreach ( $schedules as $num => $name ) {
887 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
888 $extra = $num == $hours ? 'selected' : '';
889 ?>
890 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
891 <?php
892 }
893 do_action( 'visualizer_chart_schedules_spl', 'wp', $chart_id, 1 );
894 ?>
895 </select>
896
897 <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; ?>">
898 <input type="button" id="db-filter-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
899 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
900 </form>
901 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wp' ); ?>
902 </div>
903 </div>
904 </li>
905
906 <?php
907 $save_query = add_query_arg(
908 array(
909 'action' => Visualizer_Plugin::ACTION_SAVE_DB_QUERY,
910 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_DB_QUERY . Visualizer_Plugin::VERSION ),
911 'chart' => $chart_id,
912 ), admin_url( 'admin-ajax.php' )
913 );
914 ?>
915 <!-- import from db -->
916 <li class="viz-group visualizer_source_query <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ); ?>">
917 <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from database', 'visualizer' ); ?><span
918 class="dashicons dashicons-lock"></span></h2>
919 <div class="viz-group-content edit-data-content">
920 <div>
921 <p class="viz-group-description"><?php _e( 'You can import data from the database here.', 'visualizer' ); ?></p>
922 <form id="vz-db-wizard" action="<?php echo $save_query; ?>" method="post" target="thehole">
923 <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from the database.', 'visualizer' ); ?></p>
924 <select name="refresh" id="vz-db-import-time" class="visualizer-select">
925 <?php
926 $bttn_label = 'visualizer_source_query' === $source_of_chart ? __( 'Modify Query', 'visualizer' ) : __( 'Create Query', 'visualizer' );
927 $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
928 $schedules = apply_filters(
929 'visualizer_chart_schedules', array(
930 '-1' => __( 'One-time', 'visualizer' ),
931 ),
932 'db',
933 $chart_id
934 );
935 foreach ( $schedules as $num => $name ) {
936 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
937 $extra = $num == $hours ? 'selected' : '';
938 ?>
939 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
940 <?php
941 }
942 do_action( 'visualizer_chart_schedules_spl', 'db', $chart_id, 1 );
943 ?>
944 </select>
945 <input type="hidden" name="params" id="viz-db-wizard-params">
946
947 <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; ?>">
948 <input type="button" id="db-chart-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
949 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
950 </form>
951 </div>
952 </div>
953 </li>
954
955 <!-- manual -->
956 <li class="viz-group visualizer_source_manual">
957 <h2 class="viz-group-title viz-sub-group visualizer-editor-tab" data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?>
958 <span class="dashicons dashicons-lock"></span>
959 </h2>
960 <div class="viz-group-content edit-data-content">
961 <form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
962 <input type="hidden" id="chart-data" name="chart_data">
963 <input type="hidden" id="chart-data-src" name="chart_data_src">
964
965 <?php if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { ?>
966 <div>
967 <p class="viz-group-description viz-editor-selection">
968 <?php _e( 'Use the', 'visualizer' ); ?>
969 <select name="editor-type" id="viz-editor-type">
970 <?php
971 if ( empty( $editor_type ) ) {
972 $editor_type = Visualizer_Module::is_pro() ? 'excel' : 'text';
973 }
974 foreach ( apply_filters( 'visualizer_editors', array( 'text' => __( 'Text', 'visualizer' ), 'table' => __( 'Simple', 'visualizer' ) ) ) as $e_type => $e_label ) {
975 ?>
976 <option value="<?php echo $e_type; ?>" <?php selected( $editor_type, $e_type ); ?> ><?php echo $e_label; ?></option>
977 <?php } ?>
978 </select>
979 <?php _e( 'editor to manually edit the chart data.', 'visualizer' ); ?>
980 </p>
981 <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
982 <input type="button" id="editor-button" class="button button-primary "
983 value="<?php _e( 'Edit Data', 'visualizer' ); ?>" data-current="chart"
984 data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
985 data-t-chart="<?php _e( 'Edit Data', 'visualizer' ); ?>"
986 >
987 <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>
988 </div>
989 <?php } else { ?>
990 <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
991 <input type="button" id="editor-chart-button" class="button button-primary "
992 value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart"
993 data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
994 data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>"
995 >
996 <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>
997 <?php } ?>
998 </form>
999 </div>
1000 </li>
1001 </ul>
1002 </li>
1003 </ul>
1004 </ul>
1005
1006 <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>
1007 <iframe id="thehole" name="thehole"></iframe>
1008 <?php
1009 }
1010 }
1011