PluginProbe
Chartify – WordPress Chart Plugin / 3.8.1
Chartify – WordPress Chart Plugin v3.8.1
3.8.1 3.8.0 3.7.9 3.7.8 3.7.7 3.7.6 3.7.5 trunk 1.0.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 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.1.4 3.1.5 All 84 releases
chart-builder / pb_templates / chart-builder-elementor.php

chart-builder-elementor.php in Chartify – WordPress Chart Plugin 3.8.1, at pb_templates/chart-builder-elementor.php

121 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4 class Widget_Chart_Builder_Elementor extends Widget_Base {
5 public function get_name() {
6 return 'chart-builder';
7 }
8 public function get_title() {
9 return __( 'Chart Builder', 'chart-builder' );
10 }
11 public function get_icon() {
12 // Icon name from the Elementor font file, as per http://dtbaker.net/web-development/creating-your-own-custom-elementor-widgets/
13 return 'chart-elementor-widget-logo';
14 }
15 public function get_categories() {
16 return array( 'wordpress' );
17 }
18 protected function register_controls() {
19 $this->start_controls_section(
20 'section_chart_builder',
21 array(
22 'label' => esc_html__( 'Chart Builder', 'chart-builder' ),
23 )
24 );
25 $this->add_control(
26 'important_note',
27 array(
28 'label' => '',
29 'type' => \Elementor\Controls_Manager::RAW_HTML,
30 'raw' => '<i class="chart-elementor-widget-logo"></i> '.esc_html__( 'Chart Builder', 'chart-builder' ),
31 'content_classes' => 'chart-elementor-widget-logo-wrap',
32 )
33 );
34 $this->add_control(
35 'chart_selector',
36 array(
37 'label' => __( 'Select chart', 'chart-builder' ),
38 'type' => Controls_Manager::SELECT,
39 'default' => $this->get_default_chart(),
40 'options' => $this->get_active_charts()
41 )
42 );
43
44 $this->end_controls_section();
45 }
46 protected function render( $instance = array() ) {
47
48 if ( ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
49 echo '<style>
50 .ays-chart-container .ays-chart-section:first-of-type {
51 display: block!important;
52 }
53
54 .ays-chart-container * {
55 pointer-events: none!important;
56 overflow: hidden!important;
57 }
58
59 div.elementor-widget-chart-builder>div.elementor-widget-container .chart-elementor-container {
60 width: 100%;
61 padding: 6px 8px;
62 font-size: 13px;
63 border: 1px solid #757575;
64 border-radius: 2px;
65 background-color: #f0f0f1;
66 color: #2c3338;
67 }
68 </style>';
69 }
70
71 $settings = $this->get_settings_for_display();
72 echo '<div class="chart-elementor-container">';
73 echo esc_html( "[ays_chart id=" . $settings['chart_selector'] . "]" );
74 echo '</div>';
75 if ( ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
76 echo ("<p style='margin:4px 0 0 3px;font-size:12px;font-style:italic;'>
77 " . esc_html__( 'Note: The chart will be visible on the front end of your website.', "chart-builder" ) . "
78 </p>");
79 }
80 }
81
82 public function get_active_charts(){
83 global $wpdb;
84 $current_user = get_current_user_id();
85 $charts_table = $wpdb->prefix . CHART_BUILDER_DB_PREFIX . 'charts';
86 $sql = "SELECT id, title FROM {$charts_table} WHERE `status` = %s";
87 $params = ['published'];
88 if (!current_user_can('manage_options')) {
89 $sql .= " AND author_id = %d";
90 $params[] = absint($current_user);
91 }
92 $sql .= " ORDER BY id DESC ";
93 // phpcs:ignore
94 $results = $wpdb->get_results($wpdb->prepare($sql, ...$params), ARRAY_A);
95 $options = array();
96 foreach ( $results as $result ){
97 $options[$result['id']] = $result['title'];
98 }
99 return $options;
100 }
101
102 public function get_default_chart(){
103 global $wpdb;
104 $current_user = get_current_user_id();
105 $charts_table = $wpdb->prefix . CHART_BUILDER_DB_PREFIX . 'charts';
106 $sql = "SELECT id FROM {$charts_table} WHERE `status` = %s";
107 $params = ['published'];
108 if (!current_user_can('manage_options')) {
109 $sql .= " AND author_id = %d";
110 $params[] = absint($current_user);
111 }
112 $sql .= " ORDER BY id DESC LIMIT 1";
113 // phpcs:ignore
114 $id = $wpdb->get_var($wpdb->prepare($sql, ...$params));
115 return intval($id);
116 }
117
118 protected function content_template() {}
119 public function render_plain_content( $instance = array() ) {}
120 }
121