|
// +----------------------------------------------------------------------+
/**
* Renders visualizer library page.
*
* @category Visualizer
* @package Render
*
* @since 1.0.0
*/
class Visualizer_Render_Library extends Visualizer_Render {
/**
* Renders library page.
*
* @since 1.0.0
*
* @access protected
*/
protected function _toHTML() {
echo '
';
echo '
';
echo '
';
$this->_renderMessages();
$this->_renderLibrary();
echo '
';
}
/**
* Renders notification messages if need be.
*
* @since 1.4.2
*
* @access private
*/
private function _renderMessages() {
if ( ! filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN ) ) {
echo '';
echo '
';
printf(
// translators: %s - the name of the option.
esc_html__( '%s option is disabled in your php.ini config. Please, enable it by change its value to 1. This option increases the speed of remote CSV uploading.', 'visualizer' ),
'allow_url_fopen '
);
echo '
';
echo '
';
}
}
/**
* Displays the search form.
*/
private function getDisplayForm() {
echo '
';
}
/**
* Renders pro charts blocker.
*
* @access private
*/
private function _renderProPopupBlocker() {
if ( Visualizer_Module::is_pro() ) {
return;
}
$license = get_option( 'visualizer_pro_license_data', 'free' );
$license_key = '';
$download_id = '';
if ( ! empty( $license ) && is_object( $license ) ) {
$license_key = $license->key;
$download_id = $license->download_id;
}
$admin_license_url = admin_url( 'options-general.php#visualizer_pro_license' );
$renew_license_url = tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' . $download_id, 'visualizer_license_block' );
echo '
';
}
/**
* Renders library content.
*
* @since 1.0.0
*
* @access private
*/
private function _renderLibrary() {
// Added by Ash/Upwork
$filterBy = ! empty( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
// Added by Ash/Upwork
echo $this->custom_css;
$this->_renderProPopupBlocker();
echo '';
echo '
';
$this->getDisplayForm();
echo '
';
echo '';
echo '
';
if ( ! empty( $this->charts ) ) {
echo '
';
$count = 0;
foreach ( $this->charts as $placeholder_id => $chart ) {
// show the sidebar after the first 3 charts.
$count++;
$enable_controls = false;
$settings = isset( $chart['settings'] ) ? $chart['settings'] : array();
if ( ! empty( $settings['controls']['controlType'] ) ) {
$column_index = $settings['controls']['filterColumnIndex'];
$column_label = $settings['controls']['filterColumnLabel'];
if ( 'false' !== $column_index || 'false' !== $column_label ) {
$enable_controls = true;
}
}
if ( 3 === $count ) {
$this->_renderSidebar();
$this->_renderChartBox( $placeholder_id, $chart['id'], $enable_controls );
} else {
$this->_renderChartBox( $placeholder_id, $chart['id'], $enable_controls );
}
}
// show the sidebar if there are less than 3 charts.
if ( $count < 3 ) {
$this->_renderSidebar();
}
echo '
';
} else {
echo '
';
echo '
';
echo '
';
echo '
', esc_html__( 'No charts found', 'visualizer' ), '
';
echo '
';
echo '';
echo '
';
$this->_renderSidebar();
echo '
';
}
echo '
';
if ( is_array( $this->pagination ) ) {
echo '';
foreach ( $this->pagination as $page ) {
echo '', $page, ' ';
}
echo ' ';
}
}
/**
* Renders chart's box block.
*
* @since 1.0.0
*
* @access private
*
* @param string $placeholder_id The placeholder's id for the chart.
* @param int $chart_id The id of the chart.
*/
private function _renderChartBox( $placeholder_id, $chart_id, $with_filter = false ) {
$settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS );
$title = '#' . $chart_id;
if ( ! empty( $settings[0]['title'] ) ) {
$title = $settings[0]['title'];
}
// for ChartJS, title is an array.
if ( is_array( $title ) && isset( $title['text'] ) ) {
$title = $title['text'];
}
if ( ! empty( $settings[0]['backend-title'] ) ) {
$title = $settings[0]['backend-title'];
}
if ( empty( $title ) ) {
$title = '#' . $chart_id;
}
$ajax_url = admin_url( 'admin-ajax.php' );
$delete_url = esc_url(
add_query_arg(
array(
'action' => Visualizer_Plugin::ACTION_DELETE_CHART,
'nonce' => wp_create_nonce(),
'chart' => $chart_id,
),
$ajax_url
)
);
$clone_url = esc_url(
add_query_arg(
array(
'action' => Visualizer_Plugin::ACTION_CLONE_CHART,
'nonce' => wp_create_nonce( Visualizer_Plugin::ACTION_CLONE_CHART ),
'chart' => $chart_id,
'type' => $this->type,
),
$ajax_url
)
);
$export_link = esc_url(
add_query_arg(
array(
'action' => Visualizer_Plugin::ACTION_EXPORT_DATA,
'chart' => $chart_id,
'security' => wp_create_nonce( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION ),
),
admin_url( 'admin-ajax.php' )
)
);
$chart_type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
$types = ['area', 'geo', 'column', 'bubble', 'scatter', 'gauge', 'candlestick', 'timeline', 'combo', 'polarArea', 'radar' ];
$pro_class = '';
if ( ! empty( $chart_type ) && in_array( $chart_type, $types, true ) ) {
$pro_class = 'viz-is-pro-chart';
}
$chart_status = array( 'date' => get_the_modified_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $chart_id ), 'error' => get_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR, true ), 'icon' => 'dashicons-yes-alt', 'title' => 'A-OK!' );
if ( ! empty( $chart_status['error'] ) ) {
$chart_status['icon'] = 'error dashicons-dismiss';
$chart_status['title'] = __( 'Click to view the error', 'visualizer' );
}
$shortcode = sprintf( '[visualizer id="%s" class=""]', $chart_id );
echo '', esc_html( $title ), '
';
if ( Visualizer_Module::is_pro() && $with_filter ) {
echo '
';
echo '
';
}
echo '
';
echo '
';
echo '
';
if ( Visualizer_Module::is_pro() && $with_filter ) {
echo '
';
}
echo '';
echo '
';
}
/**
* Render 2-col sidebar
*/
private function _renderSidebar() {
if ( ! Visualizer_Module::is_pro() ) {
echo '';
echo '
';
echo '
';
echo '';
echo '
';
echo '
';
echo '
';
}
}
}