| // +----------------------------------------------------------------------+ /** * Base class for all chart sidebar groups. * * @category Visualizer * @package Render * * @since 1.0.0 * @abstract */ abstract class Visualizer_Render_Sidebar extends Visualizer_Render { /** * The array of font families accepted by visualization API. * * @since 1.0.0 * * @static * @access protected * @var array */ protected static $_fontFamilies = array( 'Arial' => 'Arial', 'Sans Serif' => 'Sans Serif', 'serif' => 'Serif', 'Arial black' => 'Wide', 'Arial Narrow' => 'Narrow', 'Comic Sans MS' => 'Comic Sans MS', 'Courier New' => 'Courier New', 'Garamond' => 'Garamond', 'Georgia' => 'Georgia', 'Tahoma' => 'Tahoma', 'Verdana' => 'Verdana', ); /** * The Yes/No array. * * @since 1.0.0 * * @access protected * @var array */ protected $_yesno; /** * Whether this chart supports animation or not. * * @access protected * @var bool */ protected $_supportsAnimation = true; /** * Which library does this this chart implement? * * @access protected * @var string */ protected $_library = null; /** * Constructor. * * @since 1.0.0 * * @access public * @param array $data The data what has to be associated with this render. */ public function __construct( $data = array() ) { parent::__construct( $data ); $this->_yesno = array( '' => '', '1' => esc_html__( 'Yes', 'visualizer' ), '0' => esc_html__( 'No', 'visualizer' ), ); $this->hooks(); } /** * Renders chart title settings. * * @since 1.0.0 * * @access protected */ protected function _renderChartTitleSettings() { self::_renderTextItem( esc_html__( 'Chart Title', 'visualizer' ), 'title', $this->title, esc_html__( 'Text to display above the chart.', 'visualizer' ) ); self::_renderColorPickerItem( esc_html__( 'Chart Title Color', 'visualizer' ), 'titleTextStyle[color]', isset( $this->titleTextStyle['color'] ) ? $this->titleTextStyle['color'] : null, '#000' ); self::_renderTextAreaItem( esc_html__( 'Chart Description', 'visualizer' ), 'description', $this->description, sprintf( esc_html__( 'Description to display in the structured data schema as explained %1$shere%2$s', 'visualizer' ), '', '' ) ); } /** * Add the correct description for the manual configuration box. */ protected function _renderManualConfigDescription() { self::_renderSectionStart(); self::_renderSectionDescription( '' . 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' ), '', '', '', '' ) . '' ); } /** * Add the correct example for the manual configuration box. */ protected function _renderManualConfigExample() { return '{ "vAxis": { "ticks": [5, 10, 15, 20], "titleTextStyle": { "color": "red" }, "textPosition": "in" } }'; } /** * Renders chart advanced settings group. * * @access protected */ protected function _renderAdvancedSettings() { if ( Visualizer_Module_Admin::proFeaturesLocked() ) { self::_renderGroupStart( esc_html__( 'Frontend Actions', 'visualizer' ) ); } else { self::_renderGroupStart( esc_html__( 'Frontend Actions', 'visualizer' ) . '', '', apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-frontend-actions' ), 'vz-frontend-actions' ); echo '
' . $this->_renderManualConfigExample() . ''
),
'',
array( 'rows' => 5 )
);
self::_renderSectionEnd();
self::_renderGroupEnd();
}
/**
* Renders chart action buttons group.
*
* @access protected
*/
protected function _renderActionSettings() {
global $wp_version;
$disable_actions = version_compare( $wp_version, '4.7.0', '<' );
// default open this section when not testing through cypress because cypress expects to click and open each section
// and may not like finding a section is already open.
self::_renderSectionStart( esc_html__( 'Actions', 'visualizer' ), ! defined( 'TI_CYPRESS_TESTING' ) );
self::_renderCheckboxItem(
esc_html__( 'Print', 'visualizer' ),
'actions[]',
isset( $this->actions ) && in_array( 'print', $this->actions, true ) ? true : false,
'print',
$disable_actions ? '' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '' : esc_html__( 'To enable printing the chart/data.', 'visualizer' ),
$disable_actions
);
self::_renderCheckboxItem(
esc_html__( 'CSV', 'visualizer' ),
'actions[]',
isset( $this->actions ) && in_array( 'csv;application/csv', $this->actions, true ) ? true : false,
'csv;application/csv',
$disable_actions ? '' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '' : esc_html__( 'To enable downloading the data as a CSV.', 'visualizer' ),
$disable_actions
);
$disabled = ! self::is_excel_enabled();
self::_renderCheckboxItem(
esc_html__( 'Excel', 'visualizer' ),
'actions[]',
isset( $this->actions ) && in_array( 'xls;application/vnd.ms-excel', $this->actions, true ) ? true : false,
'xls;application/vnd.ms-excel',
$disable_actions ? '' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '' : ( $disabled ? '' . esc_html__( 'Enable the ZIP and XML extensions to use this setting.', 'visualizer' ) . '' : esc_html__( 'To enable downloading the data as an Excel spreadsheet.', 'visualizer' ) ),
$disable_actions || $disabled
);
self::_renderCheckboxItem(
esc_html__( 'Copy', 'visualizer' ),
'actions[]',
isset( $this->actions ) && in_array( 'copy', $this->actions, true ) ? true : false,
'copy',
$disable_actions ? '' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '' : esc_html__( 'To enable copying the data to the clipboard.', 'visualizer' ),
$disable_actions
);
// not all charts support downloading as an image.
$disabled = ! $this->can_chart_have_action( 'image' );
self::_renderCheckboxItem(
esc_html__( 'Download Image', 'visualizer' ),
'actions[]',
isset( $this->actions ) && in_array( 'image', $this->actions, true ) ? true : false,
'image',
$disable_actions ? '' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '' : ( $disabled ? '' . esc_html__( 'Not supported for this chart type.', 'visualizer' ) . '' : esc_html__( 'To download the chart as an image.', 'visualizer' ) ),
$disable_actions || $disabled
);
self::_renderSectionEnd();
}
/**
* Checks if the Excel module can be enabled.
*/
private static function is_excel_enabled() {
$vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php';
if ( is_readable( $vendor_file ) ) {
include_once( $vendor_file );
}
if ( version_compare( phpversion(), '5.6.0', '<' ) ) {
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'PHP version %s not supported', phpversion() ), 'error', __FILE__, __LINE__ );
return false;
}
return class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) && extension_loaded( 'zip' ) && extension_loaded( 'xml' ) && extension_loaded( 'fileinfo' );
}
/**
* Renders select item.
*
* @since 1.0.0
*
* @static
* @access public
* @param string $title The title of the select item.
* @param string $name The name of the select item.
* @param string $value The actual value of the select item.
* @param array $options The array of select options.
* @param string $desc The description of the select item.
* @param bool $multiple Is this a multiple select box.
* @param array $classes Any additional classes.
* @param array $attributes Custom attributes.
*/
public static function _renderSelectItem( $title, $name, $value, array $options, $desc, $multiple = false, $classes = array(), $attributes = array() ) {
$atts = '';
if ( $attributes ) {
foreach ( $attributes as $k => $v ) {
$atts .= ' data-visualizer-' . $k . '=' . esc_attr( $v );
}
}
echo '', $desc, '
'; echo '', $desc, '
'; echo '', $desc, '
'; echo '', $desc, '
'; echo '