PluginProbe
Chartify – WordPress Chart Plugin / 3.2.7
Chartify – WordPress Chart Plugin v3.2.7
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 3.1.6 All 83 releases
chart-builder / chart / chart-builder-block.php

chart-builder-block.php in Chartify – WordPress Chart Plugin 3.2.7, at chart/chart-builder-block.php

154 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Enqueue front end and editor JavaScript
4 */
5
6 function ays_chart_gutenberg_scripts() {
7 global $current_screen;
8 global $wp_version;
9 $version1 = $wp_version;
10 $operator = '>=';
11 $version2 = '5.3.12';
12 $versionCompare = aysChartBuilderVersionCompare($version1, $operator, $version2);
13 if( ! $current_screen ){
14 return null;
15 }
16
17 if( ! $current_screen->is_block_editor ){
18 return null;
19 }
20
21 // wp_enqueue_script( CHART_BUILDER_NAME . "-plugin", CHART_BUILDER_PUBLIC_URL . '/js/chart-builder-public-plugin.js', array('jquery'), CHART_BUILDER_VERSION, true);
22
23 // Enqueue the bundled block JS file
24 if($versionCompare){
25 wp_enqueue_script(
26 'chart-builder-block-js',
27 CHART_BUILDER_BASE_URL ."/chart/chart-builder-block-new.js",
28 array( 'jquery', 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor' ),
29 CHART_BUILDER_VERSION, true
30 );
31 }
32 else{
33 wp_enqueue_script(
34 'chart-builder-block-js',
35 CHART_BUILDER_BASE_URL ."/chart/chart-builder-block.js",
36 array( 'jquery', 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor' ),
37 CHART_BUILDER_VERSION, true
38 );
39 }
40
41 wp_enqueue_style( CHART_BUILDER_NAME, CHART_BUILDER_PUBLIC_URL . '/css/chart-builder-public.css', array(), CHART_BUILDER_VERSION, 'all');
42
43 // Enqueue the bundled block CSS file
44 if($versionCompare){
45 wp_enqueue_style(
46 'chart-builder-block-css',
47 CHART_BUILDER_BASE_URL ."/chart/chart-builder-block-new.css",
48 array(),
49 CHART_BUILDER_VERSION, 'all'
50 );
51 }
52 else{
53 wp_enqueue_style(
54 'chart-builder-block-css',
55 CHART_BUILDER_BASE_URL ."/chart/chart-builder-block.css",
56 array(),
57 CHART_BUILDER_VERSION, 'all'
58 );
59 }
60 }
61
62 function ays_chart_gutenberg_block_register() {
63
64 global $wpdb;
65 $block_name = 'chart';
66 $block_namespace = 'chart-builder/' . $block_name;
67
68 $current_user = get_current_user_id();
69
70
71 $sql = "SELECT * FROM ". $wpdb->prefix . CHART_BUILDER_DB_PREFIX . "charts WHERE status = 'published'";
72 if( ! current_user_can( 'manage_options' ) ){
73 $sql .= " AND author_id = ". absint( $current_user ) ." ";
74 }
75 $results = $wpdb->get_results($sql, "ARRAY_A");
76
77 register_block_type(
78 $block_namespace,
79 array(
80 'render_callback' => 'chart_builder_render_callback',
81 'editor_script' => 'chart-builder-block-js',
82 'style' => 'chart-builder-block-css',
83 'category' => 'media',
84 'keywords' => array(
85 'Chart',
86 'Visual Data',
87 'Graph',
88 'Chart Maker',
89 'Data Charts',
90 'Dynamic Charts'
91 ),
92 'attributes' => array(
93 'idner' => $results,
94 'metaFieldValue' => array(
95 'type' => 'integer',
96 ),
97 'shortcode' => array(
98 'type' => 'string',
99 ),
100 'className' => array(
101 'type' => 'string',
102 )
103 ),
104 )
105 );
106 }
107
108 function chart_builder_render_callback( $attributes ) {
109 global $current_screen;
110 $is_front = true;
111
112 if( ! empty( $current_screen ) ){
113 if( isset( $current_screen->is_block_editor ) && $current_screen->is_block_editor === true ){
114 $is_front = false;
115 }
116 }elseif ( wp_is_json_request() ) {
117 $is_front = false;
118 }
119
120 $ays_html = "<div></div>";
121
122 if( ! empty( $attributes["shortcode"] ) ) {
123 $ays_html = $attributes["shortcode"];
124 }else{
125 if( $is_front === true ){
126 $ays_html = '';
127 }
128 }
129
130 return $ays_html;
131 }
132
133 if(function_exists("register_block_type")){
134 // Hook scripts function into block editor hook
135 add_action( 'enqueue_block_editor_assets', 'ays_chart_gutenberg_scripts' );
136 add_action( 'init', 'ays_chart_gutenberg_block_register' );
137 }
138
139 function aysChartBuilderVersionCompare($version1, $operator, $version2) {
140
141 $_fv = intval ( trim ( str_replace ( '.', '', $version1 ) ) );
142 $_sv = intval ( trim ( str_replace ( '.', '', $version2 ) ) );
143
144 if (strlen ( $_fv ) > strlen ( $_sv )) {
145 $_sv = str_pad ( $_sv, strlen ( $_fv ), 0 );
146 }
147
148 if (strlen ( $_fv ) < strlen ( $_sv )) {
149 $_fv = str_pad ( $_fv, strlen ( $_sv ), 0 );
150 }
151
152 return version_compare ( ( string ) $_fv, ( string ) $_sv, $operator );
153 }
154