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 / Layout.php

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

398 lines 14.1 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 <textarea name='query' class='visualizer-db-query' placeholder="<?php _e( 'Your query goes here', 'visualizer' ); ?>"><?php echo $query; ?></textarea>
64 </form>
65 <div class='db-wizard-error'></div>
66 </div>
67 <div>
68 <input type="button" class="button button-primary" id='visualizer-query-fetch' value='<?php _e( 'Show Results', 'visualizer' ); ?>'>
69 </div>
70 </div>
71 <div class='db-wizard-hints'>
72 <ul>
73 <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>
74 <li><?php echo sprintf( __( 'Use %1$sControl+Space%2$s for autocompleting keywords or table names.', 'visualizer' ), '<span class="visualizer-emboss">', '</span>' ); ?></li>
75 </ul>
76 </div>
77 <div class='db-wizard-results'></div>
78
79 </div>
80 <?php
81 }
82
83 /**
84 * Show the DB wizard's results table.
85 *
86 * @access public
87 */
88 public static function _renderDbWizardResults( $args ) {
89 $headers = $args[1];
90 $results = $args[2];
91 ob_start();
92 ?>
93 <table cellspacing="0" width="100%" id="results">
94 <thead>
95 <tr>
96 <?php
97 foreach ( $headers as $header ) {
98 echo '<th>' . $header['label'] . '</th>';
99 }
100 ?>
101 </tr>
102 </thead>
103 <tfoot>
104 </tfoot>
105 <tbody>
106 <?php
107 foreach ( $results as $result ) {
108 echo '<tr>';
109 foreach ( $result as $r ) {
110 echo '<td>' . $r . '</td>';
111 }
112 echo '</tr>';
113 }
114 ?>
115 </tbody>
116 </table>
117 <?php
118 return ob_get_clean();
119 }
120
121 /**
122 * Show the JSON/REST parameters boxes.
123 *
124 * @access public
125 */
126 public static function _renderJsonScreen( $args ) {
127 $id = $args[1];
128 $action = add_query_arg(
129 array(
130 'action' => Visualizer_Plugin::ACTION_JSON_SET_DATA,
131 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_SET_DATA . Visualizer_Plugin::VERSION ),
132 'chart' => $id,
133 ),
134 admin_url( 'admin-ajax.php' )
135 );
136
137 $url = get_post_meta( $id, Visualizer_Plugin::CF_JSON_URL, true );
138 $root = get_post_meta( $id, Visualizer_Plugin::CF_JSON_ROOT, true );
139 $paging = get_post_meta( $id, Visualizer_Plugin::CF_JSON_PAGING, true );
140
141 ?>
142 <div id="visualizer-json-screen" style="display: none">
143 <div class="visualizer-json-form">
144 <h3 class="viz-step step1"><?php _e( 'STEP 1: Specify the JSON endpoint/URL', 'visualizer' ); ?></h3>
145 <div>
146 <form id="json-endpoint-form">
147 <div class="json-wizard-hints">
148 <ul class="info">
149 <li><?php echo sprintf( __( 'If you want to add authentication, add 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>
150 </ul>
151 </div>
152
153 <input
154 type="url"
155 id="vz-import-json-url"
156 name="url"
157 value="<?php echo $url; ?>"
158 placeholder="<?php esc_html_e( 'Please enter the URL', 'visualizer' ); ?>"
159 class="visualizer-input">
160 <button class="button button-secondary button-small" id="visualizer-json-fetch"><?php esc_html_e( 'Fetch Endpoint', 'visualizer' ); ?></button>
161 </form>
162 </div>
163 <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>
164 <div>
165 <form id="json-root-form">
166 <input type="hidden" name="chart" value="<?php echo $id; ?>">
167 <select name="root" id="vz-import-json-root">
168 <?php
169 if ( ! empty( $root ) ) {
170 ?>
171 <option value="<?php echo $root; ?>"><?php echo str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $root ); ?></option>
172 <?php
173 }
174 ?>
175 </select>
176 <input type="hidden" name="url" value="<?php echo $url; ?>">
177 <button class="button button-secondary button-small" id="visualizer-json-parse"><?php esc_html_e( 'Parse Endpoint', 'visualizer' ); ?></button>
178 </form>
179 </div>
180 <h3 class="viz-step step3 <?php echo empty( $root ) ? 'ui-state-disabled' : ''; ?>"><?php _e( 'STEP 3: Specify miscellaneous parameters', 'visualizer' ); ?></h3>
181 <div>
182 <form id="json-conclude-form-helper">
183 <div class="<?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
184 <div class="json-pagination">
185 <select name="paging" id="vz-import-json-paging" class="json-form-element" data-template='<?php echo sprintf( 'Get first %d pages using %s', apply_filters( 'visualizer_json_fetch_pages', 5, $url ), '?' ); ?>'>
186 <option value="0" class="static"><?php _e( 'Don\'t use pagination', 'visualizer' ); ?></option>
187 <?php
188 if ( ! empty( $paging ) ) {
189 ?>
190 <option value="<?php echo $paging; ?>"><?php echo sprintf( 'Get 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>
191 <?php
192 }
193 ?>
194 </select>
195 <?php
196 if ( ! Visualizer_Module::is_pro() ) {
197 ?>
198 <br/>
199 <br/>
200 <br/>
201 <br/>
202 <?php
203 }
204 ?>
205 <?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
206 </div>
207 </div>
208 </form>
209 </div>
210 <h3 class="viz-step step4 ui-state-disabled"><?php _e( 'STEP 4: Select the data to display in the chart', 'visualizer' ); ?></h3>
211 <div>
212 <form id="json-conclude-form" action="<?php echo $action; ?>" method="post" target="thehole">
213 <input type="hidden" name="url">
214 <input type="hidden" name="root">
215 <input type="hidden" name="chart" value="<?php echo $id; ?>">
216
217 <div class="json-wizard-hints html-table-editor-hints">
218 <ul class="info">
219 <li><?php _e( 'Select whether to include the data in the chart. Each column selected will form one series.', 'visualizer' ); ?></li>
220 <li><?php _e( 'If a column is selected to be included, specify its data type.', 'visualizer' ); ?></li>
221 <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>
222 <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>
223 </ul>
224 </div>
225 <div class="json-table"></div>
226 <button class="button button-primary" id="visualizer-json-conclude"><?php esc_html_e( 'Save &amp; Show Chart', 'visualizer' ); ?></button>
227 </form>
228 </div>
229 </div>
230 </div>
231 <?php
232 }
233
234 /**
235 * Show the simple editor(s).
236 *
237 * @access public
238 */
239 public static function _renderSimpleEditorScreen( $args ) {
240 $chart_id = $args[1];
241 $action = add_query_arg(
242 array(
243 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
244 'nonce' => wp_create_nonce(),
245 'chart' => $chart_id,
246 ),
247 admin_url( 'admin-ajax.php' )
248 );
249 ?>
250 <div class="viz-simple-editor">
251 <div class="viz-simple-editor-type viz-table-editor">
252 <form id="table-editor-form" action="<?php echo $action; ?>" method="post" target="thehole">
253 <div class="html-table-editor-hints">
254 <ul class="info">
255 <li><?php _e( 'Select whether to include the data in the chart. Each column selected will form one series.', 'visualizer' ); ?></li>
256 <li><?php _e( 'If a column is selected to be included, specify its data type.', 'visualizer' ); ?></li>
257 <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>
258 <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>
259 </ul>
260 </div>
261 <div class="viz-html-table">
262 <?php Visualizer_Render_Layout::show( 'editor-table', null, $chart_id, 'viz-html-table', true, true ); ?>
263 </div>
264 <input type="hidden" name="table_data" value="yes">
265 <button class="button button-primary" id="visualizer-save-html-table"><?php esc_html_e( 'Save &amp; Show Chart', 'visualizer' ); ?></button>
266 </form>
267 </div>
268
269 <?php Visualizer_Render_Layout::show( 'text-editor', $chart_id ); ?>
270
271 </div>
272 <?php
273
274 }
275
276 /**
277 * Show the text area editor.
278 *
279 * @access public
280 */
281 public static function _renderTextEditor( $args ) {
282 $chart_id = $args[1];
283 $csv = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, array(), $chart_id, 'csv' );
284 $data = '';
285 if ( ! empty( $csv ) && isset( $csv['string'] ) ) {
286 $data = str_replace( PHP_EOL, "\n", $csv['string'] );
287 }
288 ?>
289 <div class="viz-simple-editor-type viz-text-editor">
290 <textarea id="edited_text"><?php echo $data; ?></textarea>
291 <button id="viz-text-editor-button" class="button button-primary"><?php _e( 'Save &amp; Show Chart', 'visualizer' ); ?></button>
292 </div>
293 <?php
294 }
295
296 /**
297 * Show the JSON endpoint's parsed table.
298 *
299 * @access public
300 */
301 public static function _renderEditorTable( $args ) {
302 $data = $args[1];
303 $chart_id = $args[2];
304 $class = $args[3];
305 $echo = $args[4];
306 $editable_data = $args[5];
307 $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true );
308 $headers = array();
309
310 if ( is_null( $data ) ) {
311 foreach ( $series as $column ) {
312 $headers[] = $column['label'];
313 }
314 $chart = get_post( $chart_id );
315 $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
316 $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $type );
317 } else {
318 $headers = array_keys( $data[0] );
319 }
320
321 $classes = implode( ' ', array( 'viz-editor-table', $class ) );
322
323 if ( $series ) {
324 $temp = $series;
325 $series = array();
326 foreach ( $temp as $array ) {
327 $series[ $array['label'] ] = $array['type'];
328 }
329 }
330 if ( ! $echo ) {
331 ob_start();
332 }
333 ?>
334 <table cellspacing="0" width="100%" class="results cell-border stripe <?php echo $classes; ?>">
335 <thead>
336 <tr>
337 <th><?php _e( 'Label', 'visualizer' ); ?></th>
338 <?php
339 foreach ( $headers as $header ) {
340 if ( $editable_data ) {
341 echo '<th><input type="text" name="header[]" value="' . esc_attr( $header ) . '"></th>';
342 } else {
343 echo '<th>' . $header . '</th>';
344 }
345 }
346 ?>
347 </tr>
348 </thead>
349 <tbody>
350 <tr>
351 <th><?php _e( 'Data Type', 'visualizer' ); ?></th>
352 <?php
353 $index = 0;
354 foreach ( $headers as $header ) {
355 echo '<td>';
356 if ( $editable_data ) {
357 echo '<select name="type[]">';
358 } else {
359 echo '<input name="header[]" type="hidden" value="' . $header . '">';
360 echo '<select name="type[' . $header . ']">';
361 }
362 echo '<option value="" title="' . __( 'Exclude from chart', 'visualizer' ) . '">' . __( 'Exclude', 'visualizer' ) . '</option>';
363 echo '<option value="0" disabled title="' . __( 'Include in chart and select data type', 'visualizer' ) . '">--' . __( 'OR', 'visualizer' ) . '--</option>';
364
365 foreach ( Visualizer_Source::getAllowedTypes() as $type ) {
366 $selected = array_key_exists( $header, $series ) && $type === $series[ $header ] ? 'selected' : '';
367 echo '<option value="' . $type . '" ' . $selected . '>' . $type . '</option>';
368 }
369
370 echo '</select></td>';
371 }
372 ?>
373 </tr>
374 <?php
375 foreach ( $data as $row ) {
376 echo '<tr>';
377 echo '<th>' . __( 'Value', 'visualizer' ) . '</th>';
378 $index = 0;
379 foreach ( array_values( $row ) as $value ) {
380 if ( $editable_data ) {
381 echo '<td><input type="text" name="data' . $index++ . '[]" value="' . esc_attr( $value ) . '"></td>';
382 } else {
383 echo '<td>' . $value . '</td>';
384 }
385 }
386
387 echo '</tr>';
388 }
389 ?>
390 </tbody>
391 </table>
392 <?php
393 if ( ! $echo ) {
394 return ob_get_clean();
395 }
396 }
397 }
398