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

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

571 lines 20.3 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 * Base class for all chart sidebar groups.
24 *
25 * @category Visualizer
26 * @package Render
27 *
28 * @since 1.0.0
29 * @abstract
30 */
31 abstract class Visualizer_Render_Sidebar extends Visualizer_Render {
32
33 /**
34 * The array of font families accepted by visualization API.
35 *
36 * @since 1.0.0
37 *
38 * @static
39 * @access protected
40 * @var array
41 */
42 protected static $_fontFamilies = array(
43 'Arial' => 'Arial',
44 'Sans Serif' => 'Sans Serif',
45 'serif' => 'Serif',
46 'Arial black' => 'Wide',
47 'Arial Narrow' => 'Narrow',
48 'Comic Sans MS' => 'Comic Sans MS',
49 'Courier New' => 'Courier New',
50 'Garamond' => 'Garamond',
51 'Georgia' => 'Georgia',
52 'Tahoma' => 'Tahoma',
53 'Verdana' => 'Verdana',
54 );
55
56 /**
57 * The Yes/No array.
58 *
59 * @since 1.0.0
60 *
61 * @access protected
62 * @var array
63 */
64 protected $_yesno;
65
66 /**
67 * Whether this chart supports animation or not.
68 *
69 * @access protected
70 * @var bool
71 */
72 protected $_supportsAnimation = true;
73
74 /**
75 * Which library does this this chart implement?
76 *
77 * @access protected
78 * @var string
79 */
80 protected $_library = null;
81
82 /**
83 * Constructor.
84 *
85 * @since 1.0.0
86 *
87 * @access public
88 * @param array $data The data what has to be associated with this render.
89 */
90 public function __construct( $data = array() ) {
91 parent::__construct( $data );
92
93 $this->_yesno = array(
94 '' => '',
95 '1' => esc_html__( 'Yes', 'visualizer' ),
96 '0' => esc_html__( 'No', 'visualizer' ),
97 );
98
99 $this->hooks();
100 }
101
102 /**
103 * Renders chart title settings.
104 *
105 * @since 1.0.0
106 *
107 * @access protected
108 */
109 protected function _renderChartTitleSettings() {
110 self::_renderTextItem(
111 esc_html__( 'Chart Title', 'visualizer' ),
112 'title',
113 $this->title,
114 esc_html__( 'Text to display above the chart.', 'visualizer' )
115 );
116
117 self::_renderColorPickerItem(
118 esc_html__( 'Chart Title Color', 'visualizer' ),
119 'titleTextStyle[color]',
120 isset( $this->titleTextStyle['color'] ) ? $this->titleTextStyle['color'] : null,
121 '#000'
122 );
123
124 self::_renderTextAreaItem(
125 esc_html__( 'Chart Description', 'visualizer' ),
126 'description',
127 $this->description,
128 sprintf( esc_html__( 'Description to display in the structured data schema as explained %1$shere%2$s', 'visualizer' ), '<a href="https://developers.google.com/search/docs/data-types/dataset#dataset" target="_blank">', '</a>' )
129 );
130 }
131
132 /**
133 * Add the correct description for the manual configuration box.
134 */
135 protected function _renderManualConfigDescription() {
136 self::_renderSectionStart();
137 self::_renderSectionDescription( '<span class="viz-gvlink">' . sprintf( __( 'Configure the graph by providing configuration variables right from the %1$sGoogle Visualization API%2$s. You can refer to to some examples %3$shere%4$s.', 'visualizer' ), '<a href="https://developers.google.com/chart/interactive/docs/gallery/?#configuration-options" target="_blank">', '</a>', '<a href="https://docs.themeisle.com/article/728-manual-configuration" target="_blank">', '</a>' ) . '</span>' );
138 }
139
140 /**
141 * Add the correct example for the manual configuration box.
142 */
143 protected function _renderManualConfigExample() {
144 return '{
145 "vAxis": {
146 "ticks": [5, 10, 15, 20],
147 "titleTextStyle": {
148 "color": "red"
149 },
150 "textPosition": "in"
151 }
152 }';
153 }
154
155 /**
156 * Renders chart advanced settings group.
157 *
158 * @access protected
159 */
160 protected function _renderAdvancedSettings() {
161 if ( Visualizer_Module_Admin::proFeaturesLocked() ) {
162 self::_renderGroupStart( esc_html__( 'Frontend Actions', 'visualizer' ) );
163 } else {
164 self::_renderGroupStart( esc_html__( 'Frontend Actions', 'visualizer' ) . '<span class="dashicons dashicons-lock"></span>', '', apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-frontend-actions' ), 'vz-frontend-actions' );
165 echo '<div style="position: relative">';
166 }
167 self::_renderSectionStart();
168 self::_renderSectionDescription( esc_html__( 'Configure frontend actions that need to be shown.', 'visualizer' ) );
169 self::_renderSectionEnd();
170
171 $this->_renderActionSettings();
172 if ( ! Visualizer_Module_Admin::proFeaturesLocked() ) {
173 echo apply_filters( 'visualizer_pro_upsell', '', 'chart-permissions' );
174 echo '</div>';
175 }
176 self::_renderGroupEnd();
177
178 self::_renderGroupStart( esc_html__( 'Manual Configuration', 'visualizer' ) );
179 $this->_renderManualConfigDescription();
180 self::_renderTextAreaItem(
181 esc_html__( 'Configuration', 'visualizer' ),
182 'manual',
183 $this->manual,
184 sprintf(
185 esc_html__( 'One per line in valid JSON (key:value) format e.g. %s', 'visualizer' ),
186 '<br><code>' . $this->_renderManualConfigExample() . '</code>'
187 ),
188 '',
189 array( 'rows' => 5 )
190 );
191
192 self::_renderSectionEnd();
193 self::_renderGroupEnd();
194
195 }
196
197 /**
198 * Renders chart action buttons group.
199 *
200 * @access protected
201 */
202 protected function _renderActionSettings() {
203 global $wp_version;
204 $disable_actions = version_compare( $wp_version, '4.7.0', '<' );
205 // default open this section when not testing through cypress because cypress expects to click and open each section
206 // and may not like finding a section is already open.
207 self::_renderSectionStart( esc_html__( 'Actions', 'visualizer' ), ! defined( 'TI_CYPRESS_TESTING' ) );
208 self::_renderCheckboxItem(
209 esc_html__( 'Print', 'visualizer' ),
210 'actions[]',
211 isset( $this->actions ) && in_array( 'print', $this->actions, true ) ? true : false,
212 'print',
213 $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : esc_html__( 'To enable printing the chart/data.', 'visualizer' ),
214 $disable_actions
215 );
216 self::_renderCheckboxItem(
217 esc_html__( 'CSV', 'visualizer' ),
218 'actions[]',
219 isset( $this->actions ) && in_array( 'csv;application/csv', $this->actions, true ) ? true : false,
220 'csv;application/csv',
221 $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : esc_html__( 'To enable downloading the data as a CSV.', 'visualizer' ),
222 $disable_actions
223 );
224
225 $disabled = ! self::is_excel_enabled();
226 self::_renderCheckboxItem(
227 esc_html__( 'Excel', 'visualizer' ),
228 'actions[]',
229 isset( $this->actions ) && in_array( 'xls;application/vnd.ms-excel', $this->actions, true ) ? true : false,
230 'xls;application/vnd.ms-excel',
231 $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : ( $disabled ? '<span class="viz-section-error">' . esc_html__( 'Enable the ZIP and XML extensions to use this setting.', 'visualizer' ) . '</span>' : esc_html__( 'To enable downloading the data as an Excel spreadsheet.', 'visualizer' ) ),
232 $disable_actions || $disabled
233 );
234 self::_renderCheckboxItem(
235 esc_html__( 'Copy', 'visualizer' ),
236 'actions[]',
237 isset( $this->actions ) && in_array( 'copy', $this->actions, true ) ? true : false,
238 'copy',
239 $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : esc_html__( 'To enable copying the data to the clipboard.', 'visualizer' ),
240 $disable_actions
241 );
242
243 // not all charts support downloading as an image.
244 $disabled = ! $this->can_chart_have_action( 'image' );
245 self::_renderCheckboxItem(
246 esc_html__( 'Download Image', 'visualizer' ),
247 'actions[]',
248 isset( $this->actions ) && in_array( 'image', $this->actions, true ) ? true : false,
249 'image',
250 $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : ( $disabled ? '<span class="viz-section-error">' . esc_html__( 'Not supported for this chart type.', 'visualizer' ) . '</span>' : esc_html__( 'To download the chart as an image.', 'visualizer' ) ),
251 $disable_actions || $disabled
252 );
253 self::_renderSectionEnd();
254 }
255
256 /**
257 * Checks if the Excel module can be enabled.
258 */
259 private static function is_excel_enabled() {
260 $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php';
261 if ( is_readable( $vendor_file ) ) {
262 include_once( $vendor_file );
263 }
264
265 if ( version_compare( phpversion(), '5.6.0', '<' ) ) {
266 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'PHP version %s not supported', phpversion() ), 'error', __FILE__, __LINE__ );
267 return false;
268 }
269
270 return class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) && extension_loaded( 'zip' ) && extension_loaded( 'xml' ) && extension_loaded( 'fileinfo' );
271 }
272
273 /**
274 * Renders select item.
275 *
276 * @since 1.0.0
277 *
278 * @static
279 * @access public
280 * @param string $title The title of the select item.
281 * @param string $name The name of the select item.
282 * @param string $value The actual value of the select item.
283 * @param array $options The array of select options.
284 * @param string $desc The description of the select item.
285 * @param bool $multiple Is this a multiple select box.
286 * @param array $classes Any additional classes.
287 * @param array $attributes Custom attributes.
288 */
289 public static function _renderSelectItem( $title, $name, $value, array $options, $desc, $multiple = false, $classes = array(), $attributes = array() ) {
290 $atts = '';
291 if ( $attributes ) {
292 foreach ( $attributes as $k => $v ) {
293 $atts .= ' data-visualizer-' . $k . '=' . esc_attr( $v );
294 }
295 }
296 echo '<div class="viz-section-item">';
297 echo '<a class="more-info" href="javascript:;">[?]</a>';
298 echo '<b>', $title, '</b>';
299 echo '<select class="control-select ', implode( ' ', $classes ) , '" name="', $name, '" ', ( $multiple ? 'multiple' : '' ), ' ' , $atts, '>';
300 foreach ( $options as $key => $label ) {
301 // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
302 $extra = $multiple && is_array( $value ) ? ( in_array( $key, $value ) ? 'selected' : '' ) : selected( $key, $value, false );
303 echo '<option value="', $key, '"', $extra, '>';
304 echo $label;
305 echo '</option>';
306 }
307 echo '</select>';
308 echo '<p class="viz-section-description">', $desc, '</p>';
309 echo '</div>';
310 }
311
312 /**
313 * Renders color picker item.
314 *
315 * @since 1.0.0
316 *
317 * @static
318 * @access protected
319 * @param string $title The title of the select item.
320 * @param string $name The name of the select item.
321 * @param string $value The actual value of the select item.
322 * @param string $default The default value of the color picker.
323 */
324 protected static function _renderColorPickerItem( $title, $name, $value, $default ) {
325 echo '<div class="viz-section-item">';
326 echo '<b>', $title, '</b>';
327 echo '<div>';
328 echo '<input type="text" class="color-picker-hex color-picker" data-alpha-enabled="true" name="', $name, '" maxlength="7" placeholder="', esc_attr__( 'Hex Value', 'visualizer' ), '" value="', is_null( $value ) ? $default : esc_attr( $value ), '" data-default-color="', $default, '">';
329 echo '</div>';
330 echo '</div>';
331 }
332
333 /**
334 * Renders text item.
335 *
336 * @since 1.0.0
337 *
338 * @static
339 * @access protected
340 * @param string $title The title of the select item.
341 * @param string $name The name of the select item.
342 * @param string $value The actual value of the select item.
343 * @param string $desc The description of the select item.
344 * @param string $placeholder The placeholder for the input.
345 * @param string $type The type for the input (out of number, email, tel etc., default is text).
346 * @param array $custom_attributes The custom attributes.
347 */
348 protected static function _renderTextItem( $title, $name, $value, $desc, $placeholder = '', $type = 'text', $custom_attributes = array() ) {
349 $attributes = '';
350 if ( $custom_attributes ) {
351 foreach ( $custom_attributes as $k => $v ) {
352 $attributes .= ' ' . $k . '="' . esc_attr( $v ) . '"';
353 }
354 }
355 echo '<div class="viz-section-item">';
356 echo '<a class="more-info" href="javascript:;">[?]</a>';
357 echo '<b>', $title, '</b>';
358 echo '<input type="', $type, '" class="control-text" ', $attributes, ' name="', $name, '" value="', esc_attr( $value ), '" placeholder="', $placeholder, '">';
359 echo '<p class="viz-section-description">', $desc, '</p>';
360 echo '</div>';
361 }
362
363 /**
364 * Renders the beginning of a group.
365 *
366 * @since 1.0.0
367 *
368 * @static
369 * @access public
370 * @param string $title The title of this group.
371 * @param string $html Any additional HTML.
372 * @param string $class Any additional classes.
373 */
374 public static function _renderGroupStart( $title, $html = '', $class = '', $id = '' ) {
375 echo '<li id="' . $id . '" class="viz-group ' . $class . '">';
376 echo '<h3 class="viz-group-title">', $title, '</h3>';
377 echo $html;
378 echo '<ul class="viz-group-content">';
379 }
380
381 /**
382 * Renders the ending of a group.
383 *
384 * @since 1.0.0
385 *
386 * @static
387 * @access public
388 */
389 public static function _renderGroupEnd() {
390 echo '</ul>';
391 echo '</li>';
392 }
393
394 /**
395 * Renders the beginning of a section.
396 *
397 * @since 1.0.0
398 *
399 * @static
400 * @access public
401 * @param string $title The title of this section. If the title is empty, no title will be displayed.
402 * @param boolean $open Determines whether the section items block has to be expanded or collapsed.
403 */
404 public static function _renderSectionStart( $title = false, $open = true ) {
405
406 if ( ! empty( $title ) ) {
407 echo '<li class="viz-subsection">';
408 echo '<span class="viz-section-title">', $title, '</span>';
409 } else {
410 echo '<li class=" ">';
411 }
412 echo '<div class="viz-section-items section-items', $open ? ' open' : '', '">';
413 }
414
415 /**
416 * Renders the ending of a section.
417 *
418 * @since 1.0.0
419 *
420 * @public
421 * @access protected
422 * @param string $html Any addition HTML to add.
423 */
424 public static function _renderSectionEnd( $html = '' ) {
425 echo '</div>';
426 echo $html;
427 echo '</li>';
428 }
429
430 /**
431 * Renders section description block.
432 *
433 * @since 1.0.0
434 *
435 * @static
436 * @access public
437 * @param string $description The description text.
438 */
439 public static function _renderSectionDescription( $description, $classes = '' ) {
440 echo '<div class="viz-section-item">';
441 echo '<div class="viz-section-description ' . $classes . '">', $description, '</div>';
442 echo '</div>';
443 }
444
445 /**
446 * Renders format field according to series type.
447 *
448 * @since 1.3.0
449 *
450 * @access protected
451 * @param int $index The index of the series.
452 */
453 protected function _renderFormatField( $index = 0 ) {
454 switch ( $this->__series[ $index + 1 ]['type'] ) {
455 case 'number':
456 self::_renderTextItem(
457 esc_html__( 'Number Format', 'visualizer' ),
458 'series[' . $index . '][format]',
459 isset( $this->series[ $index ]['format'] ) ? $this->series[ $index ]['format'] : '',
460 sprintf( esc_html__( 'Enter custom format pattern to apply to this series value, similar to the %1$sICU pattern set%2$s. Use something like #,### to get 1,234 as output, or $# to add dollar sign before digits. Pay attention that if you use &#37; percentage format then your values will be multiplied by 100.', 'visualizer' ), '<a href="http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details" target="_blank">', '</a>' ),
461 '#,###.##'
462 );
463 break;
464 case 'date':
465 case 'datetime':
466 case 'timeofday':
467 self::_renderTextItem(
468 esc_html__( 'Date Format', 'visualizer' ),
469 'series[' . $index . '][format]',
470 isset( $this->series[ $index ]['format'] ) ? $this->series[ $index ]['format'] : '',
471 sprintf( esc_html__( 'Enter custom format pattern to apply to this series value, similar to the %1$sICU date and time format%2$s.', 'visualizer' ), '<a href="http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax" target="_blank">', '</a>' ),
472 'eeee, dd LLLL yyyy'
473 );
474 break;
475 }
476 }
477
478 /**
479 * Render a checkbox item
480 */
481 protected static function _renderCheckboxItem( $title, $name, $value, $default, $desc, $disabled = false ) {
482 echo '<div class="viz-section-item">';
483 echo '<a class="more-info" href="javascript:;">[?]</a>';
484 echo '<b>', $title, '</b>';
485 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
486 echo '<input type="checkbox" class="control-check" value="', $default, '" name="', $name, '" ', ( $value == $default ? 'checked' : '' ), ' ', ( $disabled ? 'disabled=disabled' : '' ), '>';
487 echo '<p class="viz-section-description">', $desc, '</p>';
488 echo '</div>';
489 }
490
491 /**
492 * Render a textarea item.
493 */
494 protected static function _renderTextAreaItem( $title, $name, $value, $desc, $placeholder = '', $custom_attributes = array() ) {
495 $attributes = '';
496 if ( $custom_attributes ) {
497 foreach ( $custom_attributes as $k => $v ) {
498 $attributes .= ' ' . $k . '="' . esc_attr( $v ) . '"';
499 }
500 }
501 echo '<div class="viz-section-item">';
502 echo '<a class="more-info" href="javascript:;">[?]</a>';
503 echo '<b>', $title, '</b>';
504 echo '<textarea class="control-text" ', $attributes, ' name="', $name, '" placeholder="', $placeholder, '">', $value, '</textarea>';
505 echo '<p class="viz-section-description">', $desc, '</p>';
506 echo '</div>';
507 }
508
509 /**
510 * Returns the library this chart implements.
511 */
512 public function getLibrary() {
513 return $this->_library;
514 }
515
516 /**
517 * Loads generic libraries conditionally.
518 */
519 protected function load_dependent_assets( $libs ) {
520 if ( in_array( 'moment', $libs, true ) && ! wp_script_is( 'moment', 'registered' ) ) {
521 wp_register_script( 'moment' );
522 }
523
524 if ( in_array( 'numeral', $libs, true ) && ! wp_script_is( 'numeral', 'registered' ) ) {
525 wp_register_script( 'numeral', VISUALIZER_ABSURL . 'js/lib/numeral.min.js', array(), Visualizer_Plugin::VERSION );
526 }
527
528 }
529
530 /**
531 * Renders save chart as image setting group.
532 *
533 * @access protected
534 */
535 protected function _renderChartImageSettings() {
536 // Default enable if amp is active.
537 $is_amp = function_exists( 'amp_is_enabled' ) && amp_is_enabled();
538 $this->save_chart_image = null === $this->save_chart_image && $is_amp ? true : $this->save_chart_image;
539
540 $is_create_chart = true;
541 if ( filter_input( INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN ) ) {
542 if ( filter_input( INPUT_GET, 'action' ) === Visualizer_Plugin::ACTION_EDIT_CHART ) {
543 $is_create_chart = false;
544 }
545 }
546 $this->lazy_load_chart = null === $this->lazy_load_chart && $is_create_chart ? true : $this->lazy_load_chart;
547
548 self::_renderSectionStart( esc_html__( 'Save chart as an image inside Media Library', 'visualizer' ), false );
549 self::_renderCheckboxItem(
550 esc_html__( 'Save inside media library?', 'visualizer' ),
551 'save_chart_image',
552 $this->save_chart_image ? true : false,
553 'yes',
554 esc_html__( 'To enable save the image as an inside media library.', 'visualizer' ),
555 false
556 );
557 self::_renderSectionEnd();
558
559 self::_renderSectionStart( esc_html__( 'Lazy rendering of chart', 'visualizer' ), false );
560 self::_renderCheckboxItem(
561 esc_html__( 'Enable lazy rendering of chart?', 'visualizer' ),
562 'lazy_load_chart',
563 $this->lazy_load_chart ? true : false,
564 'yes',
565 esc_html__( 'To enable lazy chart rendering.', 'visualizer' ),
566 false
567 );
568 self::_renderSectionEnd();
569 }
570 }
571