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

441 lines 20.0 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_PRO ) {
42 global $Visualizer_Pro;
43 $Visualizer_Pro->_addEditor( $this->chart->ID );
44 if ( method_exists( $Visualizer_Pro, '_addFilterWizard' ) ) {
45 $Visualizer_Pro->_addFilterWizard( $this->chart->ID );
46 }
47 }
48 // Added by Ash/Upwork
49 echo '<div id="canvas">';
50 echo '<img src="', VISUALIZER_ABSURL, 'images/ajax-loader.gif" class="loader">';
51 echo '</div>';
52 }
53
54 /**
55 * Renders sidebar content.
56 *
57 * @since 1.0.0
58 *
59 * @access protected
60 */
61 protected function _renderSidebarContent() {
62 $upload_link = add_query_arg(
63 array(
64 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
65 'nonce' => wp_create_nonce(),
66 'chart' => $this->chart->ID,
67 ),
68 admin_url( 'admin-ajax.php' )
69 );
70 ?>
71 <span id="visualizer-chart-id" data-id="<?php echo $this->chart->ID; ?>"></span>
72 <iframe id="thehole" name="thehole"></iframe>
73 <ul class="viz-group-wrapper full-height">
74 <li class="viz-group viz-group-category open" id="vz-chart-source">
75 <div class="viz-group-header">
76 <h2 class="viz-group-title viz-main-group"><?php _e( 'Chart Data', 'visualizer' ); ?></h2>
77 </div>
78 <ul class="viz-group-content">
79 <ul class="viz-group-wrapper">
80 <li class="viz-group">
81 <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from file', 'visualizer' ); ?></h2>
82 <div class="viz-group-content">
83 <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>
84 <p class="viz-group-description"><?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', 'visualizer' ), '<a href="' . VISUALIZER_ABSURL . 'samples/' . $this->type . '.csv" target="_blank">', $this->type, '.csv</a>' ); ?></p>
85 <form id="vz-csv-file-form" action="<?php echo $upload_link; ?>" method="post"
86 target="thehole" enctype="multipart/form-data">
87 <input type="hidden" id="remote-data" name="remote_data">
88 <div class="">
89 <input type="file" id="csv-file" name="local_data">
90 </div>
91 <input type="button" class="button button-primary" id="vz-import-file"
92 value="<?php _e( 'Import', 'visualizer' ); ?>">
93 </form>
94 </div>
95 </li>
96 <li class="viz-group visualizer-import-url">
97 <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from URL', 'visualizer' ); ?></h2>
98 <ul class="viz-group-content">
99 <li class="viz-subsection">
100 <span class="viz-section-title"><?php _e( 'One time import', 'visualizer' ); ?></span>
101
102 <div class="viz-section-items section-items">
103 <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>
104 <p class="viz-group-description"><?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', 'visualizer' ), '<a href="' . VISUALIZER_ABSURL . 'samples/' . $this->type . '.csv" target="_blank">', $this->type, '.csv</a>' ); ?></p>
105 <p class="viz-group-description"> <?php _e( 'You can also import data from Google Spreadsheet, for more info check <a href="https://github.com/Codeinwp/visualizer/wiki/How-can-I-populate-data-from-Google-Spreadsheet%3F" target="_blank" >this</a> tutorial', 'visualizer' ); ?></p>
106 <form id="vz-one-time-import" action="<?php echo $upload_link; ?>" method="post"
107 target="thehole" enctype="multipart/form-data">
108 <div class="remote-file-section">
109 <input type="url" id="remote-data" name="remote_data"
110 placeholder="<?php esc_html_e( 'Please enter the URL of CSV file', 'visualizer' ); ?>"
111 class="visualizer-input">
112
113 </div>
114 <input type="button" id="view-remote-file" class="button button-primary"
115 value="<?php _e( 'Import', 'visualizer' ); ?>">
116 </form>
117 </div>
118 </li>
119 <li class="viz-subsection <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'schedule-chart' ); ?>">
120 <span class="viz-section-title visualizer-import-url-schedule"><?php _e( 'Schedule Import', 'visualizer' ); ?>
121 <span
122 class="dashicons dashicons-lock"></span></span>
123 <div class="viz-section-items section-items">
124 <p class="viz-group-description"><?php _e( 'You can choose here to synchronize your chart data with a remote CSV file.', 'visualizer' ); ?> </p>
125 <p class="viz-group-description"> <?php _e( 'You can also synchronize with your Google Spreadsheet file, for more info check <a href="https://github.com/Codeinwp/visualizer/wiki/How-can-I-populate-data-from-Google-Spreadsheet%3F" target="_blank" >this</a> tutorial', 'visualizer' ); ?></p>
126 <p class="viz-group-description"> <?php _e( 'We will update the chart data based on your time interval preference by overwritting the current data with the one from the URL.', 'visualizer' ); ?></p>
127 <form id="vz-schedule-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="vz-schedule-url" name="remote_data"
131 value="<?php echo get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_CHART_URL, true ); ?>"
132 placeholder="<?php esc_html_e( 'Please enter the URL of CSV file', 'visualizer' ); ?>"
133 class="visualizer-input visualizer-remote-url">
134 <p class="viz-group-description"><?php _e( 'How often do you want to check the url', 'visualizer' ); ?></p>
135 <select name="vz-import-time" id="vz-import-time"
136 class="visualizer-select">
137 <?php
138 $hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
139 $schedules = apply_filters(
140 'visualizer_chart_schedules', array(
141 '1' => __( 'Each hour', 'visualizer' ),
142 '12' => __( 'Each 12 hours', 'visualizer' ),
143 '24' => __( 'Each day', 'visualizer' ),
144 '36' => __( 'Each 3 days', 'visualizer' ),
145 )
146 );
147 foreach ( $schedules as $num => $name ) {
148 $extra = $num == $hours ? 'selected' : '';
149 ?>
150 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
151 <?php
152 }
153 ?>
154 </select>
155 </div>
156 <input type="button" id="vz-save-schedule" class="button button-primary"
157 value="<?php _e( 'Save schedule', 'visualizer' ); ?>">
158
159 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'schedule-chart' ); ?>
160 </form>
161 </div>
162 </li>
163 </ul>
164 </li>
165 <li class="viz-group <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
166 <h2 class="viz-group-title viz-sub-group"
167 data-current="chart"><?php _e( 'Import from other chart', 'visualizer' ); ?><span
168 class="dashicons dashicons-lock"></span></h2>
169 <div class="viz-group-content edit-data-content">
170 <div>
171 <p class="viz-group-description"><?php _e( 'You can import here data from your previously created charts', 'visualizer' ); ?></p>
172 <form>
173 <select name="vz-import-from-chart" id="chart-id" class="visualizer-select">
174 <?php
175 $fetch_link = add_query_arg(
176 array(
177 'action' => ( VISUALIZER_PRO ) ? Visualizer_Pro::ACTION_FETCH_DATA : '',
178 'nonce' => wp_create_nonce(),
179 ),
180 admin_url( 'admin-ajax.php' )
181 );
182 $query_args_charts = array(
183 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
184 'posts_per_page' => 300,
185 'no_found_rows' => true,
186 );
187 $charts = array();
188 $query = new WP_Query( $query_args_charts );
189 while ( $query->have_posts() ) {
190 $chart = $query->next_post();
191 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
192 ?>
193 <option value="<?php echo $chart->ID; ?>"><?php echo empty( $settings['title'] ) ? '#' . $chart->ID : $settings['title']; ?></option>
194 <?php
195 }
196 ?>
197
198 </select>
199 </form>
200 <input type="button" id="existing-chart" class="button button-primary"
201 value="<?php _e( 'Import Chart', 'visualizer' ); ?>"
202 data-viz-link="<?php echo $fetch_link; ?>">
203 <?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
204 </div>
205 </div>
206 </li>
207
208 <li class="viz-group <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'schedule-chart' ); ?> ">
209 <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from WordPress', 'visualizer' ); ?><span
210 class="dashicons dashicons-lock"></span></h2>
211 <div class="viz-group-content edit-data-content">
212 <div>
213 <p class="viz-group-description"><?php _e( 'You can import here data from WordPress', 'visualizer' ); ?></p>
214 <input type="button" id="filter-chart-button" class="button button-primary "
215 value="<?php _e( 'Create Filters', 'visualizer' ); ?>" data-current="chart"
216 data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
217 data-t-chart="<?php _e( 'Create Filters', 'visualizer' ); ?>">
218 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'schedule-chart' ); ?>
219 </div>
220 </div>
221 </li>
222
223 <?php
224 // we will auto-open the manual data feature but only when pro is active.
225 $pro_class = apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' );
226 ?>
227 <li class="viz-group <?php echo $pro_class; ?> <?php echo empty( $pro_class ) ? 'open' : ''; ?> ">
228 <h2 class="viz-group-title viz-sub-group visualizer-editor-tab"
229 data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?><span
230 class="dashicons dashicons-lock"></span></h2>
231 <form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
232 <input type="hidden" id="chart-data" name="chart_data">
233 <input type="hidden" id="chart-data-src" name="chart_data_src">
234 </form>
235
236 <div class="viz-group-content edit-data-content">
237 <div>
238 <p class="viz-group-description"><?php _e( 'You can manually edit the chart data using the spreadsheet like editor.', 'visualizer' ); ?></p>
239 <input type="button" id="editor-chart-button" class="button button-primary "
240 value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart"
241 data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
242 data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>">
243
244 <?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
245 </div>
246 </div>
247 </li>
248 </ul>
249 </li>
250 </ul>
251 <li class="viz-group viz-group-category bottom-fixed sidebar-footer-link" id="vz-chart-settings">
252 <h2><span class="dashicons dashicons-admin-tools"></span><?php _e( 'Advanced', 'visualizer' ); ?></h2>
253 <div class="viz-group-header">
254 <button class="customize-section-back" tabindex="0"></button>
255 <h3 class="viz-group-title viz-main-group"><?php _e( 'Chart Settings', 'visualizer' ); ?></h3>
256 </div>
257 <ul class="viz-group-content">
258 <form id="settings-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>"
259 method="post">
260 <?php echo $this->sidebar; ?>
261 <input type="hidden" name="save" value="1">
262 </form>
263 <form id="cancel-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>" method="post">
264 <input type="hidden" name="cancel" value="1">
265 </form>
266 </ul>
267 </li>
268
269 <?php $this->getPermissionsLink( $this->chart->ID ); ?>
270
271 <li class="viz-group bottom-fixed" id="vz-chart-copyright">Visualizer &copy; <?php echo date( 'Y', current_time( 'timestamp' ) ); ?></li>
272 </ul>
273 <?php
274 // changed by Ash/Upwork
275 }
276
277 /**
278 * Generates the permissions link.
279 *
280 * @access private
281 * @param int $id The chart id.
282 */
283 private function getPermissionsLink( $id ) {
284 $permissions = apply_filters( 'visualizer_pro_get_permissions', null, $id );
285 if ( $permissions ) {
286 foreach ( $permissions as $k => $v ) {
287 $this->$k = $v;
288 }
289 }
290 ?>
291 <li class="viz-group viz-group-category bottom-fixed sidebar-footer-link" id="vz-chart-permissions">
292 <h2><span class="dashicons dashicons-admin-users"></span><?php _e( 'Permissions', 'visualizer' ); ?></h2>
293 <div class="viz-group-header">
294 <button class="customize-section-back" tabindex="0"></button>
295 <h3 class="viz-group-title viz-main-group"><?php _e( 'Chart Settings', 'visualizer' ); ?></h3>
296 </div>
297 <ul class="viz-group-content">
298 <form id="permissions-form" target="thehole" action="
299 <?php
300 echo add_query_arg(
301 array(
302 'nonce' => wp_create_nonce(),
303 'tab' => 'permissions',
304 ),
305 remove_query_arg( 'tab', $_SERVER['REQUEST_URI'] )
306 );
307 ?>
308 " method="post">
309 <?php $this->permissionsSidebar(); ?>
310 </form>
311 </ul>
312 </li>
313 <?php
314 }
315
316 /**
317 * Generates the permissions form.
318 *
319 * @access private
320 */
321 private function permissionsSidebar() {
322 // ignore for unit tests because Travis throws the error "Indirect modification of overloaded property Visualizer_Render_Page_Data::$permissions has no effect".
323 if ( defined( 'WP_TESTS_DOMAIN' ) ) {
324 return;
325 }
326 Visualizer_Render_Sidebar::_renderGroupStart(
327 esc_html__( 'Who can see this chart?', 'visualizer' ) . '<span
328 class="dashicons dashicons-lock"></span>',
329 '',
330 apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' )
331 );
332 Visualizer_Render_Sidebar::_renderSectionStart();
333 Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Select who can view the chart on the front-end.', 'visualizer' ) );
334
335 if ( ! isset( $this->permissions['read'] ) ) {
336 $this->permissions['read'] = 'all';
337 }
338
339 Visualizer_Render_Sidebar::_renderSelectItem(
340 '',
341 'permissions[read]',
342 $this->permissions['read'],
343 array(
344 'all' => esc_html__( 'All Users', 'visualizer' ),
345 'users' => esc_html__( 'Select Users', 'visualizer' ),
346 'roles' => esc_html__( 'Select Roles', 'visualizer' ),
347 ),
348 '',
349 false,
350 array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-read' ),
351 array(
352 'permission-type' => 'read',
353 )
354 );
355
356 $options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $this->permissions['read'] ) ? $this->permissions['read'] : 'roles' );
357
358 Visualizer_Render_Sidebar::_renderSelectItem(
359 '',
360 'permissions[read-specific][]',
361 isset( $this->permissions['read-specific'] ) ? $this->permissions['read-specific'] : array(),
362 $options,
363 '',
364 true,
365 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-read-specific' )
366 );
367 Visualizer_Render_Sidebar::_renderSectionEnd( apply_filters( 'visualizer_pro_upsell', 'only-pro-feature', 'chart-permissions' ) );
368 Visualizer_Render_Sidebar::_renderGroupEnd();
369
370 Visualizer_Render_Sidebar::_renderGroupStart(
371 esc_html__( 'Who can edit this chart?', 'visualizer' ) . '<span
372 class="dashicons dashicons-lock"></span>',
373 '',
374 apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' )
375 );
376 Visualizer_Render_Sidebar::_renderSectionStart();
377 Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Select who can edit the chart on the front-end.', 'visualizer' ) );
378
379 if ( ! isset( $this->permissions['edit'] ) ) {
380 $this->permissions['edit'] = 'roles';
381 $this->permissions['edit-specific'] = 'administrator';
382 }
383
384 Visualizer_Render_Sidebar::_renderSelectItem(
385 '',
386 'permissions[edit]',
387 $this->permissions['edit'],
388 array(
389 'all' => esc_html__( 'All Users', 'visualizer' ),
390 'users' => esc_html__( 'Select Users', 'visualizer' ),
391 'roles' => esc_html__( 'Select Roles', 'visualizer' ),
392 ),
393 '',
394 false,
395 array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-edit' ),
396 array(
397 'permission-type' => 'edit',
398 )
399 );
400
401 $options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $this->permissions['edit'] ) ? $this->permissions['edit'] : 'roles' );
402
403 Visualizer_Render_Sidebar::_renderSelectItem(
404 '',
405 'permissions[edit-specific][]',
406 isset( $this->permissions['edit-specific'] ) ? $this->permissions['edit-specific'] : array(),
407 $options,
408 '',
409 true,
410 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-edit-specific' )
411 );
412 Visualizer_Render_Sidebar::_renderSectionEnd( apply_filters( 'visualizer_pro_upsell', 'only-pro-feature', 'chart-permissions' ) );
413 Visualizer_Render_Sidebar::_renderGroupEnd();
414
415 }
416
417 /**
418 * Renders toolbar content.
419 *
420 * @since 1.0.0
421 *
422 * @access protected
423 */
424 protected function _renderToolbar() {
425 // don't show back button at all.
426 // 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.
427 if ( ! VISUALIZER_SKIP_CHART_TYPE_PAGE ) {
428 echo '<div class="toolbar-div">';
429 echo '<a class="button button-large" href="', add_query_arg( 'tab', 'types' ), '">';
430 esc_html_e( 'Back', 'visualizer' );
431 echo '</a>';
432 echo '</div>';
433 }
434 echo '<input type="submit" id="settings-button" class="button button-primary button-large push-right" value="', $this->button, '">';
435 if ( isset( $this->cancel_button ) ) {
436 echo '<input type="submit" id="cancel-button" class="button button-secondary button-large push-right" value="', $this->cancel_button, '">';
437 }
438 }
439
440 }
441