PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 5.6.2
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v5.6.2
6.5.0 6.4.9 6.4.8 6.4.7 6.4.6 6.4.5 6.4.4 6.4.3 6.4.2 6.4.1 6.4.0 6.3.9 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 All 153 releases
poll-maker / poll / poll-maker-block.php

poll-maker-block.php in Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls 5.6.2, at poll/poll-maker-block.php

150 lines 6.0 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 function ays_poll_gutenberg_scripts() {
6 global $current_screen;
7 global $wp_version;
8 $version1 = $wp_version;
9 $operator = '>=';
10 $version2 = '5.3.12';
11 $versionCompare = aysPollMakerVersionCompare($version1, $operator, $version2);
12
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("jquery-effects-core");
22 wp_enqueue_script('ays_block_select2js', POLL_MAKER_AYS_ADMIN_URL . '/js/select2.min.js', array('jquery'), '4.0.6', true);
23 wp_enqueue_script(POLL_MAKER_AYS_NAME . '-autosize', POLL_MAKER_AYS_PUBLIC_URL . '/js/poll-maker-autosize.js', array( 'jquery' ), POLL_MAKER_AYS_VERSION, false );
24 wp_enqueue_script(POLL_MAKER_AYS_NAME, POLL_MAKER_AYS_PUBLIC_URL . '/js/poll-maker-ays-public.js', array('jquery'), POLL_MAKER_AYS_VERSION, false);
25 wp_localize_script(POLL_MAKER_AYS_NAME . '-ajax-public', 'poll_maker_ajax_public', array('ajax_url' => admin_url('admin-ajax.php')));
26
27 // Enqueue the bundled block JS file
28 if( $versionCompare ){
29 wp_enqueue_script(
30 'poll-maker-block-js',
31 POLL_MAKER_AYS_BASE_URL ."/poll/poll-maker-block-new.js",
32 array( 'jquery', 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor' ),
33 POLL_MAKER_AYS_VERSION, true
34 );
35 }
36 else{
37 wp_enqueue_script(
38 'poll-maker-block-js',
39 POLL_MAKER_AYS_BASE_URL ."/poll/poll-maker-block.js",
40 array( 'jquery', 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor' ),
41 POLL_MAKER_AYS_VERSION, true
42 );
43 }
44 wp_localize_script('ays-poll-gutenberg-block-js', 'ays_poll_block_ajax', array('aysDoShortCode' => admin_url('admin-ajax.php')));
45
46 wp_enqueue_style( POLL_MAKER_AYS_NAME . '-font-awesome', POLL_MAKER_AYS_ADMIN_URL . '/css/poll-maker-font-awesome-all.css', array(), POLL_MAKER_AYS_VERSION, 'all');
47 wp_enqueue_style('ays-block-animate', POLL_MAKER_AYS_ADMIN_URL . '/css/animate.min.css', array(), '2.0.6', 'all');
48 wp_enqueue_style('ays-block-select2', POLL_MAKER_AYS_ADMIN_URL . '/css/select2.min.css', array(), '4.0.6', 'all');
49 wp_enqueue_style(POLL_MAKER_AYS_NAME, POLL_MAKER_AYS_PUBLIC_URL . '/css/poll-maker-ays-public.css', array(), POLL_MAKER_AYS_VERSION, 'all');
50
51 // Enqueue the bundled block CSS file
52 if( $versionCompare ){
53 wp_enqueue_style(
54 'poll-maker-block-css',
55 POLL_MAKER_AYS_BASE_URL ."/poll/poll-maker-block-new.css",
56 array(),
57 POLL_MAKER_AYS_VERSION, 'all'
58 );
59 }
60 else{
61 wp_enqueue_style(
62 'poll-maker-block-css',
63 POLL_MAKER_AYS_BASE_URL ."/poll/poll-maker-block.css",
64 array(),
65 POLL_MAKER_AYS_VERSION, 'all'
66 );
67 }
68 }
69
70 function ays_poll_gutenberg_block_register() {
71
72 global $wpdb;
73 $block_name = 'poll';
74 $block_namespace = 'poll-maker/' . $block_name;
75
76 $sql = "SELECT id, title FROM ". $wpdb->prefix . "ayspoll_polls ORDER BY id DESC";
77 $results = $wpdb->get_results($sql, "ARRAY_A");
78
79 register_block_type(
80 $block_namespace,
81 array(
82 'render_callback' => 'pollmaker_render_callback',
83 'editor_script' => 'poll-maker-block-js', // The block script slug
84 'style' => 'poll-maker-block-css',
85 'attributes' => array(
86 'idner' => $results,
87 'metaFieldValue' => array(
88 'type' => 'integer',
89 ),
90 'shortcode' => array(
91 'type' => 'string',
92 ),
93 'className' => array(
94 'type' => 'string',
95 ),
96 'openPopupId' => array(
97 'type' => 'string',
98 ),
99 ),
100 )
101 );
102 }
103
104 function pollmaker_render_callback($attributes) {
105 $ays_html = "<div class='ays-poll-render-callback-box'></div>";
106 if(isset($attributes["metaFieldValue"]) && $attributes["metaFieldValue"] === 0) {
107 return $ays_html;
108 }
109
110 if(isset($attributes["shortcode"]) && $attributes["shortcode"] != '') {
111 $ays_html = do_shortcode( $attributes["shortcode"] );
112 }
113 return $ays_html;
114 }
115
116 function aysPollMakerVersionCompare($version1, $operator, $version2) {
117
118 $_fv = intval ( trim ( str_replace ( '.', '', $version1 ) ) );
119 $_sv = intval ( trim ( str_replace ( '.', '', $version2 ) ) );
120
121 if (strlen ( $_fv ) > strlen ( $_sv )) {
122 $_sv = str_pad ( $_sv, strlen ( $_fv ), 0 );
123 }
124
125 if (strlen ( $_fv ) < strlen ( $_sv )) {
126 $_fv = str_pad ( $_fv, strlen ( $_sv ), 0 );
127 }
128
129 return version_compare ( ( string ) $_fv, ( string ) $_sv, $operator );
130 }
131
132 if (function_exists("register_block_type")) {
133 global $wp_version;
134
135 $version1 = $wp_version;
136 $operator = '>=';
137 $version2 = '5.2';
138 $versionCompare = aysPollMakerVersionCompare($version1, $operator, $version2);
139
140 if ( $versionCompare ) {
141 // Hook scripts function into block editor hook
142 add_action('enqueue_block_editor_assets', 'ays_poll_gutenberg_scripts');
143
144 if ( version_compare( get_bloginfo( 'version' ), '5.9', '>=' ) ) {
145 add_action( 'enqueue_block_assets', 'ays_poll_gutenberg_scripts' );
146 }
147
148 add_action('init', 'ays_poll_gutenberg_block_register');
149 }
150 }