PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.4.0
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.4.0
6.5.1 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 All 154 releases
poll-maker / includes / lists / class-poll-maker-polls-list-table.php

class-poll-maker-polls-list-table.php in Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls 6.4.0, at includes/lists/class-poll-maker-polls-list-table.php

2,136 lines 99.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 ob_start();
3
4 class Polls_List_Table extends WP_List_Table {
5 private $plugin_name;
6 private $title_length;
7
8 /** Class constructor */
9 public function __construct( $plugin_name ) {
10 $this->plugin_name = $plugin_name;
11 $this->title_length = Poll_Maker_Ays_Admin::get_listtables_title_length('polls');
12 parent::__construct(array(
13 'singular' =>esc_html__('Poll', "poll-maker"), //singular name of the listed records
14 'plural' =>esc_html__('Polls', "poll-maker"), //plural name of the listed records
15 'ajax' => false, //does this table support ajax?
16 ));
17 add_action('admin_notices', array($this, 'poll_notices'));
18 add_filter( 'default_hidden_columns', array( $this, 'get_hidden_columns'), 10, 2 );
19 }
20
21 public function get_categories() {
22 global $wpdb;
23 $cat_table = esc_sql($wpdb->prefix."ayspoll_categories");
24 $sql = "SELECT * FROM ".$cat_table;
25
26 return $wpdb->get_results($sql, 'ARRAY_A');
27 }
28
29 public function display_tablenav( $which ) {
30 ?>
31 <div class="tablenav <?php echo esc_attr( $which ); ?>">
32
33 <div class="alignleft actions">
34 <?php $this->bulk_actions( $which ); ?>
35 </div>
36 <?php
37 $this->extra_tablenav( $which );
38 $this->pagination( $which );
39 ?>
40 <br class="clear" />
41 </div>
42 <?php
43 }
44
45 public function extra_tablenav($which) {
46 global $wpdb;
47 $category_table = $wpdb->prefix . 'ayspoll_categories';
48 $titles_sql = "SELECT ".$category_table.".title,".$category_table.".id FROM ".$category_table;
49 $cat_titles = $wpdb->get_results($titles_sql);
50 $cat_id = null;
51 if( isset( $_GET['filterby'] )){
52 $cat_id = intval($_GET['filterby']);
53 }
54
55 if( isset( $_GET['filterbyauthor'] )){
56 $author_id_select = absint( sanitize_text_field( $_GET['filterbyauthor'] ) );
57 }
58
59 if( isset( $_GET['filterbytype'] )){
60 $type_select = sanitize_text_field( $_GET['filterbytype'] );
61 }
62
63 $categories_select = array();
64 foreach($cat_titles as $key => $cat_title){
65 $selected = "";
66 if($cat_id === intval($cat_title->id)){
67 $selected = "selected";
68 }
69 $categories_select[$cat_title->id]['title'] = $cat_title->title;
70 $categories_select[$cat_title->id]['selected'] = $selected;
71 $categories_select[$cat_title->id]['id'] = $cat_title->id;
72 }
73 sort($categories_select);
74
75 $cat_id = null;
76
77 $authors = array();
78 $users_sql = "SELECT `styles` FROM " .$wpdb->prefix . "ayspoll_polls";
79 $users = $wpdb->get_results($users_sql, "ARRAY_A");
80
81 foreach ($users as $user_key => $user) {
82 $options = (isset($user['styles']) && $user['styles'] != '') ? json_decode( $user['styles'], 'ARRAY_A' ) : '';
83 $author = (isset( $options['author'] ) && !empty($options['author'])) ? $options['author'] : array();
84
85 if (!is_array($author)) {
86 $author = json_decode($author, 'ARRAY_A');
87 }
88
89 if (!empty($author)) {
90 $author_id = (isset($author['id']) && $author['id'] != '') ? intval($author['id']) : '';
91 $author_name = (isset($author['name']) && $author['name'] != '') ? sanitize_text_field($author['name']) : '';
92 $authors[$author_id] = $author_name;
93 }
94 }
95
96 $types = array();
97 $type_sql = "SELECT DISTINCT `type` FROM " .$wpdb->prefix . "ayspoll_polls";
98 $existed_types = $wpdb->get_results( $type_sql, "ARRAY_A");
99
100 foreach( $existed_types as $type_key => $type){
101 $curent_type = ( isset( $type['type'] ) && $type['type'] != '') ? sanitize_text_field($type['type']) : '';
102 $types[$type_key] = $curent_type;
103 }
104
105 ?>
106 <div id="poll-filter-div-<?php echo esc_attr( $which ); ?>" class="alignleft actions bulkactions">
107 <select name="filterby-<?php echo esc_attr($which); ?>" id="bulk-action-selector-<?php echo esc_attr($which); ?>">
108 <option value=""><?php echo esc_html__('Select Category', "poll-maker")?></option>
109 <?php
110 foreach($categories_select as $key => $cat_title){
111 echo "<option ".$cat_title['selected']." value='".$cat_title['id']."'>".$cat_title['title']."</option>";
112 }
113 ?>
114 </select>
115 <select name="filterbyauthor-<?php echo esc_attr( $which ); ?>" id="bulk-action-selector-<?php echo esc_attr( $which ); ?>">
116 <option value=""><?php echo esc_html__('Select Author', "poll-maker")?></option>
117 <?php
118 foreach ($authors as $author_key => $author) {
119 $user_selected = ( isset($author_id_select) && $author_key == $author_id_select ) ? "selected" : "";
120
121 echo "<option " . $user_selected . " value='" . $author_key . "'>" . $author . "</option>";
122 }
123 ?>
124 </select>
125 <select name="filterbytype-<?php echo esc_attr( $which ); ?>" id="bulk-action-selector-<?php echo esc_attr( $which ); ?>">
126 <option value=""><?php echo esc_html__('Select Type', "poll-maker"); ?></option>
127 <?php
128 foreach( $types as $type_key => $type){
129 $user_selected_type = ( isset($type_select) && $type == $type_select ) ? "selected" : "";
130 echo "<option ".$user_selected_type." value='".$type."'>".$type."</option>";
131 }
132 ?>
133 </select>
134 <input type="button" id="doaction-<?php echo esc_attr($which); ?>" class="ays-poll-question-tab-all-filter-button-<?php echo esc_attr($which); ?> button" value="<?php echo esc_attr__('Filter', "poll-maker"); ?>">
135 </div>
136 <a href="?page=<?php echo esc_attr( $_REQUEST['page'] ); ?>" class="button actions_style"><?php echo esc_html__( "Clear filters", "poll-maker" ); ?></a>
137 <?php
138 }
139
140 protected function get_views() {
141 $published_count = $this->published_polls_count();
142 $unpublished_count = $this->unpublished_polls_count();
143 $all_count = $this->all_record_count();
144 $selected_all = "";
145 $selected_0 = "";
146 $selected_1 = "";
147 if( isset( $_REQUEST['fstatus'] ) && is_numeric( $_REQUEST['fstatus'] ) && ! is_null( sanitize_text_field( $_REQUEST['fstatus'] ) ) ){
148
149 $fstatus = absint( $_REQUEST['fstatus'] );
150
151 switch( $fstatus ){
152 case 0:
153 $selected_0 = " style='font-weight:bold;' ";
154 break;
155 case 1:
156 $selected_1 = " style='font-weight:bold;' ";
157 break;
158 default:
159 $selected_all = " style='font-weight:bold;' ";
160 break;
161 }
162 }else{
163 $selected_all = " style='font-weight:bold;' ";
164 }
165
166 $admin_url = get_admin_url( null, 'admin.php' );
167 $get_properties = http_build_query($_GET);
168
169 $status_links_url = $admin_url . "?" . $get_properties;
170 $publish_url = esc_url( add_query_arg('fstatus', 1, $status_links_url) );
171 $unpublish_url = esc_url( add_query_arg('fstatus', 0, $status_links_url) );
172
173 $status_links = array(
174 "all" => "<a ".$selected_all." href='?page=".esc_attr( $_REQUEST['page'] )."'>".esc_html__( 'All', "poll-maker" )." (".$all_count.")</a>",
175 "published" => "<a ".$selected_1." href='". $publish_url ."'>".esc_html__( 'Published', "poll-maker" )." (".$published_count.")</a>",
176 "unpublished" => "<a ".$selected_0." href='". $unpublish_url ."'>".esc_html__( 'Unpublished', "poll-maker" )." (".$unpublished_count.")</a>"
177 );
178 return $status_links;
179 }
180
181 public function add_or_edit_polls( $data, $id = null, $ays_change_type = "" ) {
182 global $allowedtags;
183 $old_allowedtags = $allowedtags;
184 $default_attribs = array(
185 'id' => array(),
186 'class' => array(),
187 'title' => array(),
188 'style' => array(),
189 );
190 $allowedtags = array(
191 'div' => $default_attribs,
192 'span' => $default_attribs,
193 'p' => $default_attribs,
194 'a' => array_merge($default_attribs, array(
195 'href' => array(),
196 'target' => array('_blank', '_top'),
197 )),
198 'input' => array_merge($default_attribs, array(
199 'type' => array(),
200 'name' => array(),
201 'value' => array(),
202 )),
203 'textarea' => array_merge($default_attribs, array(
204 'type' => array(),
205 'name' => array(),
206 )),
207 'u' => $default_attribs,
208 'i' => $default_attribs,
209 'q' => $default_attribs,
210 'b' => $default_attribs,
211 'ul' => $default_attribs,
212 'dl' => $default_attribs,
213 'ol' => $default_attribs,
214 'li' => $default_attribs,
215 'br' => $default_attribs,
216 'hr' => $default_attribs,
217 'strong' => $default_attribs,
218 'blockquote' => $default_attribs,
219 'del' => $default_attribs,
220 'strike' => $default_attribs,
221 'em' => $default_attribs,
222 'code' => $default_attribs,
223 );
224
225 global $wpdb;
226 $poll_table = esc_sql($wpdb->prefix . 'ayspoll_polls');
227 $answer_table = esc_sql($wpdb->prefix . 'ayspoll_answers');
228 if (isset($data["poll_action"]) && wp_verify_nonce($data["poll_action"], 'poll_action')) {
229
230 $poll_allowed_html = Poll_Maker_Data::ays_poll_custom_allowed_html();
231
232 $title = isset($data['ays-poll-title']) && $data['ays-poll-title'] != "" ? sanitize_text_field($data['ays-poll-title']) : "Default title";
233 $show_title = isset($data['show_title']) && $data['show_title'] == 'show' ? 1 : 0;
234 $limit_users = isset($data['apm_limit_users']) && $data['apm_limit_users'] == 'on' ? 1 : 0;
235 $limit_users_method = isset($data['ays_limit_method']) ? sanitize_text_field($data['ays_limit_method']) : 'ip';
236 $limit_users_msg = isset($data['ays_limitation_message']) ? wp_kses( $data['ays_limitation_message'], $poll_allowed_html ) : "";
237 $limit_users_url = isset($data['ays_redirect_url']) ? wp_http_validate_url($data['ays_redirect_url']) : "";
238 $limit_users_delay = isset($data['ays_redirection_delay']) ? absint($data['ays_redirection_delay']) : 0;
239 $limit_users_role_enable = isset($data['ays_enable_restriction_pass']) && $data['ays_enable_restriction_pass'] == 'on' ? 1 : 0;
240 $limit_users_role = (isset($data["ays_users_roles"]) && !empty($data["ays_users_roles"])) ? $data["ays_users_roles"] : array();
241 $limit_users_role_msg = isset($data['restriction_pass_message']) ? wp_kses( $data['restriction_pass_message'], $poll_allowed_html ) : "";
242
243 $limit_users_logged_enable = (isset($data['ays_enable_logged_users']) && $data['ays_enable_logged_users'] == 'on') || $limit_users_role_enable ? 1 : 0;
244 $limit_users_logged_msg = isset($data['ays_enable_logged_users_message']) ? wp_kses( $data['ays_enable_logged_users_message'], $poll_allowed_html ) : "";
245
246 $hide_results = isset($data['ays-poll-hide-results']) && 'hide' == $data['ays-poll-hide-results'] ? 1 : 0;
247 $hide_result_message = isset($data['ays_poll_result_message']) && 'hide' == $data['ays_poll_result_message'] ? 1 : 0;
248
249 $hide_results_text = isset( $data['ays-poll-hide-results-text'] ) && $data['ays-poll-hide-results-text'] != '' ? wp_kses( $data['ays-poll-hide-results-text'], $poll_allowed_html ) : '';
250
251 $ays_result_message = isset( $data['ays_result_message'] ) && $data['ays_result_message'] != '' ? wp_kses( $data['ays_result_message'], $poll_allowed_html ) : '';
252
253 $allow_not_vote = isset($data['ays-poll-allow-not-vote']) && 'allow' == $data['ays-poll-allow-not-vote'] ? 1 : 0;
254 $show_social = isset($data['ays-poll-show-social']) && 'show' == $data['ays-poll-show-social'] ? 1 : 0;
255 $poll_social_buttons_heading = ( isset( $data[ 'ays_poll_social_buttons_heading' ] ) && $data[ 'ays_poll_social_buttons_heading' ] != '' ) ? wp_kses( $data['ays_poll_social_buttons_heading'], $poll_allowed_html ) : '';
256 $poll_show_social_ln = isset($data['ays_poll_enable_linkedin_share_button']) && $data['ays_poll_enable_linkedin_share_button'] == "on" ? "on" : "off";
257 $poll_show_social_fb = isset($data['ays_poll_enable_facebook_share_button']) && $data['ays_poll_enable_facebook_share_button'] == "on" ? "on" : "off";
258 $poll_show_social_tr = isset($data['ays_poll_enable_twitter_share_button']) && $data['ays_poll_enable_twitter_share_button'] == "on" ? "on" : "off";
259 $poll_show_social_vk = isset($data['ays_poll_enable_vkontakte_share_button']) && $data['ays_poll_enable_vkontakte_share_button'] == "on" ? "on" : "off";
260 $categories = isset($data['ays-poll-categories']) ? ',' . implode(',', $data['ays-poll-categories']) . ',' : ',1,';
261 $description = isset($data['ays-poll-description']) && $data['ays-poll-description'] != '' ? sanitize_textarea_field($data['ays-poll-description']) : "";
262 $type = isset($data['ays-poll-type']) ? sanitize_text_field($data['ays-poll-type']) : "";
263
264 $question = isset( $data['ays_poll_question'] ) && $data['ays_poll_question'] != '' ? wp_kses( $data['ays_poll_question'], $poll_allowed_html ) : '';
265
266 $image = isset($data['ays_poll_image']) && $data['ays_poll_image'] != '' ? sanitize_url($data['ays_poll_image']): '';
267
268 if( $image != "" ){
269 $check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($image);
270
271 if( !$check_if_current_image_exists ){
272 $image = "";
273 }
274 }
275
276 $theme_id = isset($data['ays_poll_theme']) ? absint($data['ays_poll_theme']) : 1;
277 $main_color = isset($data['ays_poll_main_color']) ? sanitize_text_field($data['ays_poll_main_color']) : '#000000';
278 $text_color = isset($data['ays_poll_text_color']) ? sanitize_text_field($data['ays_poll_text_color']) : '#000000';
279 $button_text_color = isset($data['ays_poll_button_text_color']) ? sanitize_text_field($data['ays_poll_button_text_color']) : '#ffffff';
280 $button_bg_color = isset($data['ays_poll_button_bg_color']) ? sanitize_text_field($data['ays_poll_button_bg_color']) : '#000000';
281 $icon_color = isset($data['ays_poll_icon_color']) ? sanitize_text_field($data['ays_poll_icon_color']) : '#000000';
282 $bg_color = isset($data['ays_poll_bg_color']) ? sanitize_text_field($data['ays_poll_bg_color']) : '#ffffff';
283 $answer_bg_color = isset($data['ays_poll_answer_bg_color']) ? sanitize_text_field($data['ays_poll_answer_bg_color']) : '#FBFEF9';
284 $answer_hover_color = isset($data['ays_poll_answer_hover_color']) ? sanitize_text_field($data['ays_poll_answer_hover_color']) : $text_color;
285 $answer_border_side = isset($data['ays_poll_border_side']) ? sanitize_text_field($data['ays_poll_border_side']) : 'all_sides';
286 $bg_image = isset($data['ays_poll_bg_image']) && $data['ays_poll_bg_image'] != '' ? sanitize_url($data['ays_poll_bg_image']): '';
287 // if ($bg_image != '') {
288 // if ( !(filter_var($bg_image, FILTER_VALIDATE_URL) && wp_http_validate_url($bg_image)) ) {
289 // // invalid URL, handle accordingly
290 // $bg_image = '';
291 // }
292 // }
293 if( $bg_image != "" ){
294 $check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($bg_image);
295
296 if( !$check_if_current_image_exists ){
297 $bg_image = "";
298 }
299 }
300 $randomize_answers = !isset($data['randomize_answers']) ? "off" : $data['randomize_answers'];
301 $enable_asnwers_sound = !isset($data['ays_poll_enable_asnwers_sound']) ? "off" : $data['ays_poll_enable_asnwers_sound'];
302 $icon_size = absint($data['ays_poll_icon_size']) >= 10 ? absint($data['ays_poll_icon_size']) : 24;
303 $width = absint($data['ays_poll_width']);
304 $width_for_mobile = ( isset( $data['ays_poll_width_for_mobile'] ) && $data['ays_poll_width_for_mobile'] != '' ) ? absint($data['ays_poll_width_for_mobile']) : 0;
305 $btn_text = sanitize_text_field($data['ays_poll_btn_text']);
306 $see_res_btn_text = sanitize_text_field($data['ays_poll_res_btn_text']);
307 $border_style = sanitize_text_field($data['ays_poll_border_style']);
308 $border_radius = sanitize_text_field($data['ays_poll_border_radius']);
309 $border_width = sanitize_text_field($data['ays_poll_border_width']);
310 $box_shadow_color = sanitize_text_field($data['ays_poll_box_shadow_color']);
311
312 //Gradient
313 $enable_background_gradient = isset($data['ays_enable_background_gradient']) && $data['ays_enable_background_gradient'] == "on" ? sanitize_text_field($data['ays_enable_background_gradient']) : "off";
314 $background_gradient_color_1 = sanitize_text_field($data['ays_background_gradient_color_1']);
315 $background_gradient_color_2 = sanitize_text_field($data['ays_background_gradient_color_2']);
316 $poll_gradient_direction = sanitize_text_field($data['ays_poll_gradient_direction']);
317 ///
318
319 // Redirect after submit
320 $redirect_after_submit = ( isset( $data['ays_redirect_after_submit'] ) && $data['ays_redirect_after_submit'] == 'on' ) ? 1 : 0;
321
322 $submit_redirect_url = !isset($data['ays_submit_redirect_url']) ? '' : $data['ays_submit_redirect_url'];
323 // $submit_redirect_delay = !isset($data['ays_submit_redirect_delay']) ? '' : $data['ays_submit_redirect_delay'];
324 ///
325
326 $enable_box_shadow = isset($data['ays_poll_enable_box_shadow']) && $data['ays_poll_enable_box_shadow'] == "on" ? sanitize_text_field($data['ays_poll_enable_box_shadow']) : "off";
327 $enable_answer_style = isset($data['ays_poll_enable_answer_style']) && $data['ays_poll_enable_answer_style'] == "on" ? sanitize_text_field($data['ays_poll_enable_answer_style']) : "off";
328 $load_effect = sanitize_text_field($data['ays-poll-load-effect']);
329 $load_gif = isset($data['ays-poll-load-gif']) ? sanitize_text_field($data['ays-poll-load-gif']) : 'plg_default';
330 $notify_on = isset($data['ays_notify_by_email_on']) && $data['ays_notify_by_email_on'] == 'on' ? 1 : 0;
331 $notify_email = isset($data['ays_notify_email']) && !empty($data['ays_notify_email']) ? sanitize_email($data['ays_notify_email']) : get_option('admin_email');
332 $redirect_users = isset($data['ays_redirect_after_vote']) && $data['ays_redirect_after_vote'] == 'on' ? 1 : 0;
333 $redirect_after_vote_url = isset($data['redirection_url']) ? wp_http_validate_url($data['redirection_url']) : "";
334 $redirect_after_vote_delay = isset($data['redirection_delay']) ? absint($data['redirection_delay']) : 0;
335 $result_sort_type = sanitize_text_field($data['ays-poll-result-sort-type']);
336 $poll_direction = sanitize_text_field($data['ays_poll_direction']);
337 $published = absint(intval($data['ays_publish']));
338 $enable_pass_count = !isset($data['ays_enable_pass_count']) ? null : $data['ays_enable_pass_count'];
339
340 $activeInterval_full = isset($data['ays-active']) ? $data['ays-active'] : "";
341 $activeInterval_fullArr = explode(" ",$activeInterval_full);
342 $activeInterval = isset($activeInterval_fullArr[0]) ? $activeInterval_fullArr[0] : "";
343 $activeIntervalSec = isset($activeInterval_fullArr[1]) ? $activeInterval_fullArr[1] : "";
344
345 $deactiveInterval_full = isset($data['ays-deactive']) ? $data['ays-deactive'] : "";
346 $deactiveInterval_fullArr = explode(" ",$deactiveInterval_full);
347 $deactiveInterval = isset($deactiveInterval_fullArr[0]) ? $deactiveInterval_fullArr[0] : "";
348 $deactiveIntervalSec = isset($deactiveInterval_fullArr[1]) ? $deactiveInterval_fullArr[1] : "";
349
350 $active_date_message = isset( $data['active_date_message'] ) && $data['active_date_message'] != '' ? wp_kses( $data['active_date_message'], $poll_allowed_html ) : '';
351 $active_date_message_soon = isset( $data['active_date_message_soon'] ) && $data['active_date_message_soon'] != '' ? wp_kses( $data['active_date_message_soon'], $poll_allowed_html ) : '';
352
353 $css = stripcslashes($data['ays_custom_css']);
354 $active_date_check = isset($data['active_date_check']) && !empty($data['active_date_check']) ? $data['active_date_check'] : '';
355 $enable_restart_button = isset($data['ays_enable_restart_button']) && 'on' == $data['ays_enable_restart_button'] ? 1 : 0;
356 $enable_vote_btn = isset($data['ays_enable_vote_button']) && 1 == $data['ays_enable_vote_button'] ? 1 : 0;
357 $show_votes_count = isset($data['show_votes_count']) && 1 == $data['show_votes_count'] ? 1 : 0;
358 $show_create_date = isset($data['show_poll_creation_date']) && 1 == $data['show_poll_creation_date'] ? 1 : 0;
359 $show_author = isset($data['show_poll_author']) && 1 == $data['show_poll_author'] ? 1 : 0;
360 $show_res_percent = isset($data['show_res_percent']) && 1 == $data['show_res_percent'] ? 1 : 0;
361 $show_result_btn_schedule = isset($data['show_result_btn_schedule']) && 1 == $data['show_result_btn_schedule'] ? 1 : 0;
362 $ays_poll_show_timer = isset($data['ays_poll_show_timer']) && 1 == $data['ays_poll_show_timer'] ? 1 : 0;
363 $show_bottom_timer = isset($data['ays_show_bottom_timer']) && 1 == $data['ays_show_bottom_timer'] ? 1 : 0;
364 $ays_show_timer_type = isset($data['ays_show_timer_type']) && !empty($data['ays_show_timer_type']) ? $data['ays_show_timer_type'] : 'countdown';
365 $ays_show_result_btn_see = isset($data['ays_poll_show_result_btn_see_schedule']) && !empty($data['ays_poll_show_result_btn_see_schedule']) ? $data['ays_poll_show_result_btn_see_schedule'] : 'with_see';
366 $info_form = isset($data['ays_poll_info_form']) && 'on' == $data['ays_poll_info_form'] ? 1 : 0;
367 $form_fields = isset($data['ays-poll-form-fields']) ? sanitize_text_field(implode(',', $data['ays-poll-form-fields'])) : "";
368 $form_required_fields = isset($data['ays-poll-form-required-fields']) ? sanitize_text_field(implode(',', $data['ays-poll-form-required-fields'])) : "";
369 $info_form_title = isset($data['ays-poll-info-form-text']) ? wp_kses( $data['ays-poll-info-form-text'], $poll_allowed_html ) : "";
370 $title_bg_color = sanitize_text_field($data['ays_poll_title_bg_color']);
371
372 // Poll main URL
373 $poll_main_url = (isset( $_POST['ays_poll_main_url'] ) && $_POST['ays_poll_main_url'] != '') ? wp_kses_post( $_POST['ays_poll_main_url'] ) : '';
374
375 $changed_creation_date = (isset($data['ays_poll_change_creation_date']) && $data['ays_poll_change_creation_date'] != '') ? $data['ays_poll_change_creation_date'] : current_time( 'mysql' ) ;
376
377 $author = ( isset( $data['ays_poll_author'] ) && $data['ays_poll_author'] != '' ) ? stripslashes($data['ays_poll_author']) : '';
378
379 // Change the author of the current poll
380 $poll_create_author = ( isset($data['ays_poll_create_author']) && $data['ays_poll_create_author'] != "" ) ? absint( sanitize_text_field( $data['ays_poll_create_author'] ) ) : '';
381
382 if ( $poll_create_author != "" && $poll_create_author > 0 ) {
383 $user = get_userdata($poll_create_author);
384 if ( ! is_null( $user ) && $user ) {
385 $poll_author = array(
386 'id' => $user->ID."",
387 'name' => $user->data->display_name
388 );
389
390 $author = json_encode($poll_author, JSON_UNESCAPED_SLASHES);
391 } else {
392 $author_data = json_decode($author, true);
393 $poll_create_author = (isset( $author_data['id'] ) && $author_data['id'] != "") ? absint( sanitize_text_field( $author_data['id'] ) ) : get_current_user_id();
394 }
395 }
396
397 // MailChimp
398 $enable_mailchimp = isset($data['ays_enable_mailchimp']) && $data['ays_enable_mailchimp'] == 'on' ? "on": "off";
399 $mailchimp_list = !isset($data['ays_mailchimp_list'])?"":$data['ays_mailchimp_list'];
400
401
402 // Show login form for not logged in users
403 $show_login_form = (isset($data['ays_show_login_form']) && $data['ays_show_login_form'] == "on" && $limit_users_logged_enable == 1) ? 'on' : 'off';
404 // Disable answer hover
405 $disable_answer_hover = (isset($data['ays_disable_answer_hover']) && $data['ays_disable_answer_hover'] == 'on') ? 1 : 0;
406
407 $custom_class = (isset($data['ays_poll_custom_class']) && $data['ays_poll_custom_class'] != '') ? $data['ays_poll_custom_class'] : '';
408
409 // Bg image positioning
410 $poll_bg_image_position = (isset($data['ays_poll_bg_image_position']) && $data['ays_poll_bg_image_position'] != "") ? $data['ays_poll_bg_image_position'] : 'center center';
411 $poll_bg_img_in_finish_page = (isset($data['ays_poll_bg_img_in_finish_page']) && $data['ays_poll_bg_img_in_finish_page'] != "") ? $data['ays_poll_bg_img_in_finish_page'] : 'off';
412
413 // Results bar in RGBA
414 $result_in_rgba = (isset($data['ays-poll-res-rgba']) && $data['ays-poll-res-rgba'] == 'on' ) ? 'on' : 'off';
415
416 // Enable View more button
417 $enable_view_more_button = (isset($data['ays_enable_view_more_button']) && $data['ays_enable_view_more_button'] == 'on' ) ? 'on' : 'off';
418 $poll_view_more_button_count = (isset($data['ays_poll_view_more_button_count']) && $data['ays_poll_view_more_button_count'] != '' ) ? absint(intval($data['ays_poll_view_more_button_count'])) : 0;
419
420 // Poll Min Height
421 $poll_min_height = (isset($data['ays_poll_min_height']) && $data['ays_poll_min_height'] != '') ? absint(intval($data['ays_poll_min_height'])) : '';
422
423 // Poll answer ordering
424 $poll_answer_ordering = (isset($data['ays_answers_sort_select']) && $data['ays_answers_sort_select'] != '') ? sanitize_text_field($data['ays_answers_sort_select']) : '';
425
426 // Poll answers font size
427 $poll_answer_font_size = (isset($data['ays_answer_font_size']) && $data['ays_answer_font_size'] != '') ? sanitize_text_field($data['ays_answer_font_size']) : '16';
428
429 // Poll answers font size on mobile
430 $poll_answer_font_size_mobile = (isset($data['ays_poll_answer_font_size_mobile']) && $data['ays_poll_answer_font_size_mobile'] != '') ? sanitize_text_field($data['ays_poll_answer_font_size_mobile']) : '16';
431
432 // Poll show passed users in result page
433 $poll_show_passed_users = (isset($data['ays_poll_show_users']) && sanitize_text_field($data['ays_poll_show_users']) == 'on') ? 'on' : 'off';
434 $poll_show_passed_users_count = (isset($data['ays_poll_show_users_count']) && $data['ays_poll_show_users_count'] != '') ? intval(sanitize_text_field($data['ays_poll_show_users_count'])) : 3;
435
436 // Poll Logo image
437 $poll_logo_image = (isset($data['ays_poll_logo_image']) && $data['ays_poll_logo_image'] != '') ? sanitize_url($data['ays_poll_logo_image']) : '';
438 // if ($poll_logo_image != '') {
439 // if ( !(filter_var($poll_logo_image, FILTER_VALIDATE_URL) && wp_http_validate_url($poll_logo_image)) ) {
440 // // invalid URL, handle accordingly
441 // $poll_logo_image = '';
442 // }
443 // }
444 if( $poll_logo_image != "" ){
445 $check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($poll_logo_image);
446
447 if( !$check_if_current_image_exists ){
448 $poll_logo_image = "";
449 }
450 }
451
452 // Poll schedule container on/off
453 $poll_show_container = (isset($data['ays_show_poll_container']) && $data['ays_show_poll_container'] == 'on') ? 'on' : 'off';
454
455 // Show votes count per answers before voting
456 $show_votes_before_voting = (isset($data['ays_show_votes_before_voting']) && $data['ays_show_votes_before_voting'] == 'on') ? 'on' : 'off';
457 $show_votes_before_voting_by = (isset($data['ays_show_votes_before_voting_by']) && $data['ays_show_votes_before_voting_by'] != '') ? $data['ays_show_votes_before_voting_by'] : 'by_count';
458
459
460
461 // Poll see results button in limitations
462 $poll_see_result_button = (isset($data['ays_see_result_show']) && $data['ays_see_result_show'] == 'on') ? 'on' : 'off';
463 $poll_see_result_radio = (isset($data['ays_poll_see_result_show']) && $data['ays_poll_see_result_show'] != '') ? sanitize_text_field($data['ays_poll_see_result_show']) : '';
464
465 // loader font size
466 $poll_loader_font_size = (isset($data['ays_loader_font_size']) && $data['ays_loader_font_size'] != '') ? sanitize_text_field($data['ays_loader_font_size']) : '64';
467 if(intval($poll_loader_font_size) <= 0){
468 $poll_loader_font_size = '';
469 }
470
471 // Show answers numbering
472 $show_answers_numbering = (isset($_POST['ays_poll_show_answers_numbering']) && sanitize_text_field( $_POST['ays_poll_show_answers_numbering']) != '') ? sanitize_text_field( $_POST['ays_poll_show_answers_numbering'] ) : 'none';
473
474 // Poll border color
475 $poll_border_color = (isset($data['ays_poll_border_color']) && $data['ays_poll_border_color'] != '') ? sanitize_text_field($data['ays_poll_border_color']) : '';
476
477 // Poll load effect message
478 $poll_effect_message = (isset($data['ays_poll_load_effect_message']) && $data['ays_poll_load_effect_message'] != '') ? sanitize_text_field($data['ays_poll_load_effect_message']) : '';
479
480 // Box Shadow X offset
481 $poll_box_shadow_x_offset = (isset($data['ays_poll_box_shadow_x_offset']) && $data['ays_poll_box_shadow_x_offset'] != '' ) ? intval( sanitize_text_field( $data['ays_poll_box_shadow_x_offset'] ) ) : 0;
482
483 // Box Shadow Y offset
484 $poll_box_shadow_y_offset = (isset($data['ays_poll_box_shadow_y_offset']) && $data['ays_poll_box_shadow_y_offset'] != '' ) ? intval( sanitize_text_field( $data['ays_poll_box_shadow_y_offset'] ) ) : 0;
485
486 // Box Shadow Z offset
487 $poll_box_shadow_z_offset = (isset($data['ays_poll_box_shadow_z_offset']) && $data['ays_poll_box_shadow_z_offset'] != '' ) ? intval( sanitize_text_field( $data['ays_poll_box_shadow_z_offset'] ) ) : 15;
488
489 // Vote Reason
490 $poll_vote_reason = (isset($data['ays-poll-reason']) && $data['ays-poll-reason'] == 'on' ) ? "on" : "off";
491
492 // Allow multivote
493 $poll_allow_multivote = isset($data['ays_poll_allow_multivote']) && $data['ays_poll_allow_multivote'] == 'on' ? "on" : "off";
494 $multivote_answer_min_count = (isset($data['ays_poll_multivote_min_count']) && $data['ays_poll_multivote_min_count'] != '') ? sanitize_text_field($data['ays_poll_multivote_min_count']) : '';
495 $poll_multivote_answer_count = (isset($data['ays_poll_multivote_count']) && $data['ays_poll_multivote_count'] != '') ? sanitize_text_field($data['ays_poll_multivote_count']) : '';
496
497 // Allow collect user info
498 $poll_allow_collecting_users_data = (isset($data['ays_allow_collecting_logged_in_users_data']) && $data['ays_allow_collecting_logged_in_users_data'] == 'on') ? 'on' : 'off';
499
500 // Answer Icon
501 $poll_answer_icon_check = isset($data['ays_poll_show_answers_icon']) && $data['ays_poll_show_answers_icon'] == "on" ? "on" : "off";
502 $poll_answer_icon = isset($data['ays_poll_answer_icon']) && $data['ays_poll_answer_icon'] != "" ? sanitize_text_field($data['ays_poll_answer_icon']) : "radio";
503
504 // Every Answer redirect delay
505 $poll_every_answer_redirect_delay = isset($data['ays_poll_answer_redirect_delay']) && $data['ays_poll_answer_redirect_delay'] != "" ? sanitize_text_field($data['ays_poll_answer_redirect_delay']) : "";
506 $poll_enable_every_answer_redirect_delay = isset($data['ays_poll_enable_answer_redirect_delay']) && $data['ays_poll_enable_answer_redirect_delay'] == "on" ? "on" : "off";
507
508 // Show Answers image after voting
509 if(isset($data['ays-poll-answers-images']) && empty(array_filter($data['ays-poll-answers-images']))){
510 $data['ays_poll_enable_answer_image_after_voting'] = 'off';
511 }
512 $poll_enable_answer_image_after_voting = isset($data['ays_poll_enable_answer_image_after_voting']) && $data['ays_poll_enable_answer_image_after_voting'] == "on" ? "on" : "off";
513
514 // Poll logo image url
515 $poll_logo_image_url = isset($data['ays_poll_logo_image_url']) && $data['ays_poll_logo_image_url'] != "" ? sanitize_text_field($data['ays_poll_logo_image_url']) : "";
516 $poll_logo_image_url_check = isset($data['ays_poll_logo_enable_image_url']) && $data['ays_poll_logo_enable_image_url'] == "on" ? "on" : "off";
517
518 // Poll Logo title
519 $poll_logo_title = (isset( $data['ays_poll_logo_title'] ) && $data['ays_poll_logo_title'] != '') ? sanitize_text_field( $data['ays_poll_logo_title'] ) : '';
520
521 // Poll question font size
522 $poll_question_font_size_pc = isset($data['ays_poll_answers_font_size_pc']) && $data['ays_poll_answers_font_size_pc'] != "" ? sanitize_text_field($data['ays_poll_answers_font_size_pc']) : "16";
523 $poll_question_font_size_mobile = isset($data['ays_poll_answers_font_size_mobile']) && $data['ays_poll_answers_font_size_mobile'] != "" ? sanitize_text_field($data['ays_poll_answers_font_size_mobile']) : "16";
524
525 // Poll question image height
526 $poll_question_image_height = isset($data['ays_poll_question_image_height']) && $data['ays_poll_question_image_height'] != "" ? abs(sanitize_text_field($data['ays_poll_question_image_height'])) : "";
527
528 // Poll question object fit
529 $poll_question_image_object_fit = isset($data['ays_poll_question_image_object_fit']) && $data['ays_poll_question_image_object_fit'] != "" ? sanitize_text_field($data['ays_poll_question_image_object_fit']) : "cover";
530
531 // Poll container max-width for mobile
532 $poll_mobile_max_width = (isset($data['ays_poll_mobile_max_width']) && $data['ays_poll_mobile_max_width'] != "") ? abs(sanitize_text_field($data['ays_poll_mobile_max_width'])) : '';
533
534 // ==== Button Styles =====
535 // Buttons size
536 $poll_buttons_size = (isset($data['ays_poll_buttons_size']) && $data['ays_poll_buttons_size'] != "") ? sanitize_text_field($data['ays_poll_buttons_size']) : 'medium';
537
538 // Buttons font size
539 $poll_buttons_font_size = (isset($data['ays_poll_buttons_font_size']) && $data['ays_poll_buttons_font_size'] != "") ? sanitize_text_field($data['ays_poll_buttons_font_size']) : '17';
540
541 // Buttons mobile font size
542 $poll_buttons_mobile_font_size = (isset($data['ays_poll_buttons_mobile_font_size']) && $data['ays_poll_buttons_mobile_font_size'] != "") ? sanitize_text_field($data['ays_poll_buttons_mobile_font_size']) : '17';
543
544 // Buttons Left / Right padding
545 $poll_buttons_left_right_padding = (isset($data['ays_poll_buttons_left_right_padding']) && $data['ays_poll_buttons_left_right_padding'] != "") ? sanitize_text_field($data['ays_poll_buttons_left_right_padding']) : '20';
546
547 // Buttons Top / Bottom padding
548 $poll_buttons_top_bottom_padding = (isset($data['ays_poll_buttons_top_bottom_padding']) && $data['ays_poll_buttons_top_bottom_padding'] != "") ? sanitize_text_field($data['ays_poll_buttons_top_bottom_padding']) : '10';
549
550 // Buttons padding
551 $poll_buttons_border_radius = (isset($data['ays_poll_buttons_border_radius']) && $data['ays_poll_buttons_border_radius'] != "") ? sanitize_text_field($data['ays_poll_buttons_border_radius']) : '3';
552
553 // Buttons width
554 $poll_buttons_width = (isset($data['ays_poll_buttons_width']) && sanitize_text_field( $data['ays_poll_buttons_width'] ) != "") ? sanitize_text_field( $data['ays_poll_buttons_width'] ) : '';
555
556 // Buttons mobile width
557 $poll_buttons_mobile_width = (isset($data['ays_poll_buttons_mobile_width']) && sanitize_text_field( $data['ays_poll_buttons_mobile_width'] ) != "") ? sanitize_text_field( $data['ays_poll_buttons_mobile_width'] ) : $poll_buttons_width;
558 // ==== ====
559
560 // ==== Allow Answer options ====
561 // Allow custom answer
562 $poll_allow_answer = (isset($data['ays_poll_allow_add_answers']) && $data['ays_poll_allow_add_answers'] == "on") ? "on" : "off";
563 // Require admin approval
564
565 $poll_allow_answer_require = (isset($data['ays_poll_allow_answer_require']) && $data['ays_poll_allow_answer_require'] == "on") ? "on" : "off";
566
567 // ==== ====
568
569 // Poll answer view type
570 $poll_answer_view_type = (isset($data['ays_poll_choose_answer_type']) && $data['ays_poll_choose_answer_type'] != "") ? sanitize_text_field($data['ays_poll_choose_answer_type']) : "list";
571
572 // Poll answer box shadow
573 // Poll answer box shadow enable
574 $poll_answer_enable_box_shadow = (isset($data['ays_poll_answers_box_shadow_enable']) && $data['ays_poll_answers_box_shadow_enable'] == "on") ? "on" : "off";
575 // Poll answer box shadow color
576 $poll_answer_box_shadow_color = (isset($data['ays_poll_answers_box_shadow_color']) && $data['ays_poll_answers_box_shadow_color'] != "") ? sanitize_text_field($data['ays_poll_answers_box_shadow_color']) : "#000000";
577
578 $poll_answer_box_shadow_x_offset = (isset($data['ays_poll_answer_box_shadow_x_offset']) && $data['ays_poll_answer_box_shadow_x_offset'] != "") ? intval($data['ays_poll_answer_box_shadow_x_offset']) : 0;
579
580 $poll_answer_box_shadow_y_offset = (isset($data['ays_poll_answer_box_shadow_y_offset']) && $data['ays_poll_answer_box_shadow_y_offset'] != "") ? intval($data['ays_poll_answer_box_shadow_y_offset']) : 0;
581
582 $poll_answer_box_shadow_z_offset = (isset($data['ays_poll_answer_box_shadow_z_offset']) && $data['ays_poll_answer_box_shadow_z_offset'] != "") ? intval($data['ays_poll_answer_box_shadow_z_offset']) : 10;
583 //
584
585 // Poll answer image height
586 $poll_answer_image_height = (isset($data['ays_poll_answer_img_height']) && $data['ays_poll_answer_img_height'] != "") ? sanitize_text_field($data['ays_poll_answer_img_height']) : "150";
587 if($poll_answer_image_height == '0'){
588 $poll_answer_image_height = "150";
589 }
590
591 // Poll answer image height for mobile
592 $poll_answer_image_height_for_mobile = (isset($data['ays_poll_answer_image_height_for_mobile']) && $data['ays_poll_answer_image_height_for_mobile'] != "") ? sanitize_text_field($data['ays_poll_answer_image_height_for_mobile']) : "150";
593 if($poll_answer_image_height_for_mobile == '0'){
594 $poll_answer_image_height_for_mobile = "150";
595 }
596
597 // Poll answer image border radius
598 $poll_answer_image_border_radius = (isset($data['ays_poll_answer_image_border_radius']) && $data['ays_poll_answer_image_border_radius'] != "") ? sanitize_text_field($data['ays_poll_answer_image_border_radius']) : 0;
599
600 // Poll answer image object fit
601 $poll_answer_object_fit = (isset($data['ays_poll_image_background_size']) && $data['ays_poll_image_background_size'] != "") ? sanitize_text_field($data['ays_poll_image_background_size']) : "cover";
602
603 // Poll answer padding
604 $poll_answer_padding = (isset($data['ays_poll_answers_padding']) && $data['ays_poll_answers_padding'] != "") ? sanitize_text_field($data['ays_poll_answers_padding']) : "10";
605
606 // Poll answer gap
607 $poll_answer_margin = (isset($data['ays_poll_answers_margin']) && $data['ays_poll_answers_margin'] != "") ? sanitize_text_field($data['ays_poll_answers_margin']) : "10";
608
609 // Poll answer border radius
610 $poll_answer_border_radius = (isset($data['ays_poll_answer_border_radius']) && $data['ays_poll_answer_border_radius'] != "") ? absint(intval($data['ays_poll_answer_border_radius'])) : 0;
611
612 // Poll title font size
613 $poll_title_font_size = (isset($data['ays_poll_title_font_size']) && $data['ays_poll_title_font_size'] != "" && $data['ays_poll_title_font_size'] > 0) ? sanitize_text_field($data['ays_poll_title_font_size']) : "20";
614
615 // Poll title font size for mobile
616 $poll_title_font_size_mobile = (isset($data['ays_poll_title_font_size_mobile']) && $data['ays_poll_title_font_size_mobile'] != "" && $data['ays_poll_title_font_size_mobile'] > 0) ? sanitize_text_field($data['ays_poll_title_font_size_mobile']) : "20";
617
618 // Poll title alignment
619 $poll_title_alignment = ( isset($data['ays_poll_title_alignment']) && $data['ays_poll_title_alignment'] != "" ) ? sanitize_text_field($data['ays_poll_title_alignment']) : "center";
620
621 // Poll title alignment mobile
622 $poll_title_alignment_mobile = ( isset($data['ays_poll_title_alignment_mobile']) && $data['ays_poll_title_alignment_mobile'] != "" ) ? sanitize_text_field($data['ays_poll_title_alignment_mobile']) : "center";
623
624 // ===== Poll text type options start =====
625 $poll_text_type_length_enable = ( isset($data['ays_poll_enable_question_length']) && $data['ays_poll_enable_question_length'] != "" ) ? sanitize_text_field($data['ays_poll_enable_question_length']) : "off";
626 $poll_text_type_limit_type = ( isset($data['ays_poll_question_limit_text_type']) && $data['ays_poll_question_limit_text_type'] != "" ) ? sanitize_text_field($data['ays_poll_question_limit_text_type']) : "characters";
627 $poll_text_type_limit_length = ( isset($data['ays_poll_question_text_max_length']) && $data['ays_poll_question_text_max_length'] != "" ) ? sanitize_text_field($data['ays_poll_question_text_max_length']) : "";
628 $poll_text_type_limit_message = ( isset($data['ays_poll_question_enable_text_message']) && $data['ays_poll_question_enable_text_message'] != "" ) ? sanitize_text_field($data['ays_poll_question_enable_text_message']) : "off";
629 $poll_text_type_placeholder = ( isset($data['ays_poll_text_type_placeholder']) && $data['ays_poll_text_type_placeholder'] != "" ) ? sanitize_text_field($data['ays_poll_text_type_placeholder']) : "";
630 $poll_text_type_width = ( isset($data['ays_poll_text_type_width']) && $data['ays_poll_text_type_width'] != "" ) ? absint(intval(sanitize_text_field($data['ays_poll_text_type_width']))) : "";
631 $poll_text_type_width_type = ( isset($data['ays_poll_text_type_width_type']) && $data['ays_poll_text_type_width_type'] != "" ) ? sanitize_text_field($data['ays_poll_text_type_width_type']) : "percent";
632 // ===== Poll text type options end =====
633
634 $poll_enable_password = ( isset($data['ays_poll_enable_password']) && $data['ays_poll_enable_password'] == "on" ) ? "on" : "off";
635 $poll_password = ( isset($data['ays_poll_password']) && $data['ays_poll_password'] != "" ) ? sanitize_text_field($data['ays_poll_password']) : "";
636 // Enable toggle password visibility
637 $poll_enable_password_visibility = (isset($data['ays_poll_enable_password_visibility']) && $data['ays_poll_enable_password_visibility'] == 'on') ? 'on' : 'off';
638 $poll_password_message = ( isset($data['ays_poll_password_message']) && $data['ays_poll_password_message'] != "" ) ? wp_kses( $data['ays_poll_password_message'], $poll_allowed_html ) : "Please enter password";
639
640 // Add post for poll
641 $ays_add_post_for_poll = isset($data['ays_add_post_for_poll']) && $data['ays_add_post_for_poll'] == 'on' ? 'on' : 'off';
642
643 //Title Text Shadow
644 $enable_poll_title_text_shadow = ( isset( $data['ays_poll_enable_title_text_shadow'] ) && $data['ays_poll_enable_title_text_shadow'] != '' ) ? 'on' : 'off';
645
646 // Enable/disable grid column layout for answers on mobile devices
647 $answers_grid_column_mobile = (isset($data['ays_answers_grid_column_mobile']) && $data['ays_answers_grid_column_mobile'] == 'on') ? 'on' :'off';
648
649
650 $poll_title_text_shadow = ( isset($data['ays_poll_title_text_shadow_color'] ) && $data['ays_poll_title_text_shadow_color'] != '' ) ? sanitize_text_field( $data['ays_poll_title_text_shadow_color'] ) : 'rgba(255,255,255,0)';
651 $poll_title_text_shadow_x_offset = (isset($data['ays_poll_title_text_shadow_x_offset']) && $data['ays_poll_title_text_shadow_x_offset'] != '') ? intval( $data['ays_poll_title_text_shadow_x_offset'] ) : 2;
652
653 $poll_title_text_shadow_y_offset = (isset($data['ays_poll_title_text_shadow_y_offset']) && $data['ays_poll_title_text_shadow_y_offset'] != '') ? intval( $data['ays_poll_title_text_shadow_y_offset'] ) : 2;
654
655 $poll_title_text_shadow_z_offset = (isset($data['ays_poll_title_text_shadow_z_offset']) && $data['ays_poll_title_text_shadow_z_offset'] != '') ? intval( $data['ays_poll_title_text_shadow_z_offset'] ) : 0;
656
657 //Display form fields labels
658 $display_fields_labels = ( isset($data['ays_poll_display_fields_labels']) && sanitize_text_field( $data['ays_poll_display_fields_labels'] ) == 'on' ) ? 'on' : 'off';
659
660 // Autofill users data
661 $autofill_user_data = ( isset($data['ays_poll_autofill_user_data']) && sanitize_text_field( $data['ays_poll_autofill_user_data'] ) == 'on' ) ? 'on' : 'off';
662
663 //Open Logo Url in new tab
664 $poll_logo_url_new_tab = (isset( $data[ 'ays_poll_logo_enable_image_url_new_tab' ] ) && $data[ 'ays_poll_logo_enable_image_url_new_tab' ] == 'on') ? "on" : 'off';
665
666 // Social Media links
667 $enable_social_links = (isset($data['ays_poll_enable_social_links']) && sanitize_text_field( $data['ays_poll_enable_social_links'] ) == "on") ? 'on' : 'off';
668 $poll_social_links_heading = ( isset( $data[ 'ays_poll_social_links_heading' ] ) && $data[ 'ays_poll_social_links_heading' ] != '' ) ? wp_kses( $data['ays_poll_social_links_heading'], $poll_allowed_html ) : '';
669 $ays_social_links = (isset($data['ays_poll_social_links'])) ? array_map( 'sanitize_text_field', $data['ays_poll_social_links'] ) : array(
670 'linkedin_link' => '',
671 'facebook_link' => '',
672 'twitter_link' => '',
673 'vkontakte_link' => '',
674 'youtube_link' => '',
675 'tiktok_link' => '',
676 );
677
678 $linkedin_link = isset($ays_social_links['ays_linkedin_link']) && sanitize_text_field( $ays_social_links['ays_linkedin_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_linkedin_link'] ) : '';
679 $facebook_link = isset($ays_social_links['ays_facebook_link']) && sanitize_text_field( $ays_social_links['ays_facebook_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_facebook_link'] ) : '';
680 $twitter_link = isset($ays_social_links['ays_twitter_link']) && sanitize_text_field( $ays_social_links['ays_twitter_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_twitter_link'] ) : '';
681 $vkontakte_link = isset($ays_social_links['ays_vkontakte_link']) && sanitize_text_field( $ays_social_links['ays_vkontakte_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_vkontakte_link'] ) : '';
682 $youtube_link = isset($ays_social_links['ays_youtube_link']) && sanitize_text_field( $ays_social_links['ays_youtube_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_youtube_link'] ) : '';
683 $tiktok_link = isset($ays_social_links['ays_tiktok_link']) && sanitize_text_field( $ays_social_links['ays_tiktok_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_tiktok_link'] ) : '';
684
685 $social_links = array(
686 'linkedin_link' => $linkedin_link,
687 'facebook_link' => $facebook_link,
688 'twitter_link' => $twitter_link,
689 'vkontakte_link' => $vkontakte_link,
690 'youtube_link' => $youtube_link,
691 'tiktok_link' => $tiktok_link,
692 );
693
694 $show_chart_type = (isset($_POST['ays_poll_show_result_chart']) && sanitize_text_field( $_POST['ays_poll_show_result_chart'] ) != "") ? sanitize_text_field( $_POST['ays_poll_show_result_chart'] ) : 'default_bar_chart';
695 $show_chart_type_google_height = (isset($_POST['ays_poll_show_result_chart_google_height']) && $_POST['ays_poll_show_result_chart_google_height'] != "" && $_POST['ays_poll_show_result_chart_google_height'] != 0) ? absint( intval($_POST['ays_poll_show_result_chart_google_height']) ) : 400;
696
697 $styles = json_encode(array(
698 // Style tab start
699 'main_color' => $main_color,
700 'text_color' => $text_color,
701 'button_text_color' => $button_text_color,
702 'button_bg_color' => $button_bg_color,
703 'icon_color' => $icon_color,
704 'bg_color' => $bg_color,
705 'bg_image' => $bg_image,
706 'enable_answer_style' => $enable_answer_style,
707 'answer_bg_color' => $answer_bg_color,
708 'answer_hover_color' => $answer_hover_color,
709 'answer_border_side' => $answer_border_side,
710 "answer_font_size" => $poll_answer_font_size,
711 "poll_answer_font_size_mobile" => $poll_answer_font_size_mobile,
712 'poll_answer_object_fit' => $poll_answer_object_fit,
713 'poll_answer_padding' => $poll_answer_padding,
714 'poll_answer_margin' => $poll_answer_margin,
715 'poll_answer_border_radius' => $poll_answer_border_radius,
716 'poll_answer_icon_check' => $poll_answer_icon_check,
717 'poll_answer_icon' => $poll_answer_icon,
718 'poll_answer_view_type' => $poll_answer_view_type,
719 'poll_answer_enable_box_shadow' => $poll_answer_enable_box_shadow,
720 'poll_answer_box_shadow_color' => $poll_answer_box_shadow_color,
721 'poll_answer_box_shadow_x_offset' => $poll_answer_box_shadow_x_offset,
722 'poll_answer_box_shadow_y_offset' => $poll_answer_box_shadow_y_offset,
723 'poll_answer_box_shadow_z_offset' => $poll_answer_box_shadow_z_offset,
724 'title_bg_color' => $title_bg_color, //aray
725 'poll_title_font_size' => $poll_title_font_size,
726 'poll_title_font_size_mobile' => $poll_title_font_size_mobile,
727 'icon_size' => $icon_size,
728 'width' => $width,
729 'width_for_mobile' => $width_for_mobile,
730 "poll_min_height" => $poll_min_height,
731 'border_style' => $border_style,
732 'border_radius' => $border_radius,
733 'border_width' => $border_width,
734 "border_color" => $poll_border_color,
735 'enable_box_shadow' => $enable_box_shadow,
736 'box_shadow_color' => $box_shadow_color,
737 "poll_box_shadow_x_offset" => $poll_box_shadow_x_offset,
738 "poll_box_shadow_y_offset" => $poll_box_shadow_y_offset,
739 "poll_box_shadow_z_offset" => $poll_box_shadow_z_offset,
740 'enable_background_gradient' => $enable_background_gradient,
741 'background_gradient_color_1' => $background_gradient_color_1,
742 'background_gradient_color_2' => $background_gradient_color_2,
743 'poll_gradient_direction' => $poll_gradient_direction,
744 'poll_question_size_pc' => $poll_question_font_size_pc,
745 'poll_question_size_mobile' => $poll_question_font_size_mobile,
746 'poll_question_image_height' => $poll_question_image_height,
747 'poll_question_image_object_fit' => $poll_question_image_object_fit,
748 'poll_mobile_max_width' => $poll_mobile_max_width,
749 'poll_buttons_size' => $poll_buttons_size,
750 'poll_buttons_font_size' => $poll_buttons_font_size,
751 'poll_buttons_mobile_font_size' => $poll_buttons_mobile_font_size,
752 'poll_buttons_left_right_padding' => $poll_buttons_left_right_padding,
753 'poll_buttons_top_bottom_padding' => $poll_buttons_top_bottom_padding,
754 'poll_buttons_border_radius' => $poll_buttons_border_radius,
755 'poll_buttons_width' => $poll_buttons_width,
756 'poll_buttons_mobile_width' => $poll_buttons_mobile_width,
757 "disable_answer_hover" => $disable_answer_hover,
758 "logo_image" => $poll_logo_image,
759 'poll_enable_logo_url' => $poll_logo_image_url_check,
760 'poll_logo_title' => $poll_logo_title,
761 'poll_logo_url' => $poll_logo_image_url,
762 "custom_class" => $custom_class,
763 "enable_poll_title_text_shadow" => $enable_poll_title_text_shadow,
764 "poll_title_text_shadow" => $poll_title_text_shadow,
765 "poll_title_text_shadow_x_offset" => $poll_title_text_shadow_x_offset,
766 "poll_title_text_shadow_y_offset" => $poll_title_text_shadow_y_offset,
767 "poll_title_text_shadow_z_offset" => $poll_title_text_shadow_z_offset,
768
769 // Settings tab start
770 "poll_allow_multivote" => $poll_allow_multivote,
771 "multivote_answer_min_count" => $multivote_answer_min_count,
772 "poll_allow_multivote_count" => $poll_multivote_answer_count,
773 'poll_direction' => $poll_direction,
774 'show_create_date' => $show_create_date,
775 'show_author' => $show_author,
776 'active_date_check' => $active_date_check,
777 'activeInterval' => $activeInterval,
778 'activeIntervalSec' => $activeIntervalSec,
779 'deactiveInterval' => $deactiveInterval,
780 'deactiveIntervalSec' => $deactiveIntervalSec,
781 'ays_poll_show_timer' => $ays_poll_show_timer,
782 'show_bottom_timer' => $show_bottom_timer,
783 'ays_show_timer_type' => $ays_show_timer_type,
784 'show_result_btn_see_schedule' => $ays_show_result_btn_see,
785 'active_date_message_soon' => $active_date_message_soon,
786 'active_date_message' => $active_date_message,
787 'show_result_btn_schedule' => $show_result_btn_schedule,
788 "dont_show_poll_cont" => $poll_show_container,
789 'allow_not_vote' => $allow_not_vote,
790 'see_res_btn_text' => $see_res_btn_text,
791 'enable_pass_count' => $enable_pass_count,
792 'redirect_users' => $redirect_users,
793 'redirect_after_vote_url' => $redirect_after_vote_url,
794 'redirection_delay' => $limit_users_delay,
795 'randomize_answers' => $randomize_answers,
796 'enable_asnwers_sound' => $enable_asnwers_sound,
797 "poll_vote_reason" => $poll_vote_reason,
798 'enable_vote_btn' => $enable_vote_btn,
799 'btn_text' => $btn_text,
800 "enable_view_more_button" => $enable_view_more_button,
801 "poll_view_more_button_count" => $poll_view_more_button_count,
802 "answer_sort_type" => $poll_answer_ordering,
803 "show_answers_numbering" => $show_answers_numbering,
804 "show_votes_before_voting" => $show_votes_before_voting,
805 "show_votes_before_voting_by" => $show_votes_before_voting_by,
806 // Settings tab end
807 'hide_results' => $hide_results,
808 'hide_result_message' => $hide_result_message,
809 'hide_results_text' => $hide_results_text,
810 'result_message' => $ays_result_message,
811 'show_social' => $show_social,
812 'poll_social_buttons_heading' => $poll_social_buttons_heading,
813 'poll_show_social_ln' => $poll_show_social_ln,
814 'poll_show_social_fb' => $poll_show_social_fb,
815 'poll_show_social_tr' => $poll_show_social_tr,
816 'poll_show_social_vk' => $poll_show_social_vk,
817 'load_effect' => $load_effect,
818 'load_gif' => $load_gif,
819 'limit_users' => $limit_users,
820 'limit_users_method' => $limit_users_method,
821 'limitation_message' => $limit_users_msg,
822 'redirect_url' => $limit_users_url,
823 'user_role' => $limit_users_role,
824 'enable_restriction_pass' => $limit_users_role_enable,
825 'restriction_pass_message' => $limit_users_role_msg,
826 'enable_logged_users' => $limit_users_logged_enable,
827 'enable_logged_users_message' => $limit_users_logged_msg,
828 'notify_email_on' => $notify_on,
829 'notify_email' => $notify_email,
830 'result_sort_type' => $result_sort_type,
831 'create_date' => $changed_creation_date,
832 'author' => $author,
833 'poll_main_url' => $poll_main_url,
834 'redirect_after_vote_delay' => $redirect_after_vote_delay,
835 'published' => $published,
836 'enable_restart_button' => $enable_restart_button,
837 'show_votes_count' => $show_votes_count,
838 'show_res_percent' => $show_res_percent,
839 'show_login_form' => $show_login_form,
840 'info_form' => $info_form,
841 'fields' => $form_fields,
842 "answers_grid_column_mobile" => $answers_grid_column_mobile,
843 'required_fields' => $form_required_fields,
844 'info_form_title' => $info_form_title,
845 'enable_mailchimp' => $enable_mailchimp,
846 'redirect_after_submit' => $redirect_after_submit,
847 'mailchimp_list' => $mailchimp_list,
848 "users_role" => json_encode($limit_users_role),
849 "poll_bg_image_position" => $poll_bg_image_position,
850 "poll_bg_img_in_finish_page" => $poll_bg_img_in_finish_page,
851 'ays_add_post_for_poll' => $ays_add_post_for_poll,
852 "result_in_rgba" => $result_in_rgba,
853 "show_passed_users" => $poll_show_passed_users,
854 "see_result_button" => $poll_see_result_button,
855 "see_result_radio" => $poll_see_result_radio,
856 "loader_font_size" => $poll_loader_font_size,
857 "effect_message" => $poll_effect_message,
858
859 "poll_allow_collecting_users_data" => $poll_allow_collecting_users_data,
860 'poll_every_answer_redirect_delay' => $poll_every_answer_redirect_delay,
861 'poll_enable_answer_image_after_voting' => $poll_enable_answer_image_after_voting,
862 'poll_enable_answer_redirect_delay' => $poll_enable_every_answer_redirect_delay,
863 'poll_show_passed_users_count' => $poll_show_passed_users_count,
864 'poll_allow_answer' => $poll_allow_answer,
865 'poll_allow_answer_require' => $poll_allow_answer_require,
866 'poll_answer_image_height' => $poll_answer_image_height,
867 'poll_answer_image_height_for_mobile' => $poll_answer_image_height_for_mobile,
868 'poll_answer_image_border_radius' => $poll_answer_image_border_radius,
869 'poll_title_alignment' => $poll_title_alignment,
870 'poll_title_alignment_mobile' => $poll_title_alignment_mobile,
871 // Text type options
872 'poll_text_type_length_enable' => $poll_text_type_length_enable,
873 'poll_text_type_limit_type' => $poll_text_type_limit_type,
874 'poll_text_type_limit_length' => $poll_text_type_limit_length,
875 'poll_text_type_limit_message' => $poll_text_type_limit_message,
876 'poll_text_type_placeholder' => $poll_text_type_placeholder,
877 'poll_text_type_width' => $poll_text_type_width,
878 'poll_text_type_width_type' => $poll_text_type_width_type,
879
880 'poll_enable_password' => $poll_enable_password,
881 'poll_password' => $poll_password,
882 'poll_enable_password_visibility' => $poll_enable_password_visibility,
883 'poll_password_message' => $poll_password_message,
884 'display_fields_labels' => $display_fields_labels,
885 'autofill_user_data' => $autofill_user_data,
886 'poll_create_author' => $poll_create_author,
887 'poll_logo_url_new_tab' => $poll_logo_url_new_tab,
888 'enable_social_links' => $enable_social_links,
889 'poll_social_links_heading' => $poll_social_links_heading,
890 'social_links' => $social_links,
891 'show_chart_type' => $show_chart_type,
892 'show_chart_type_google_height' => $show_chart_type_google_height,
893 ));
894
895 $poll_answers_img = array();
896 $answers = array();
897 switch ( $type ) {
898 case 'choosing':
899 $view_type = isset( $data['ays_poll_choose_answer_type'] ) ? sanitize_text_field($data['ays_poll_choose_answer_type'] ) : "list";
900 $poll_answers_img = isset($data['ays-poll-answers-images']) && !empty($data['ays-poll-answers-images']) ? $data['ays-poll-answers-images'] : $poll_answers_img;
901 $answers = isset($data['ays-poll-answers']) && !empty($data['ays-poll-answers']) ? $data['ays-poll-answers'] : array();
902 $answers_ids = $data['ays-poll-answers-ids'];
903 $answers_url = $data['ays_submit_redirect_url'];
904 $answers_show_added = isset($data['ays_poll_show_user_added']) && !empty( $data['ays_poll_show_user_added']) ? $data['ays_poll_show_user_added'] : array(1,1);
905 break;
906 case 'voting':
907 $view_type = isset($data['ays-poll-vote-type']) ? sanitize_text_field($data['ays-poll-vote-type']) : "";
908 $answers = array(1, -1);
909 $answers_show_added = array(1,1);
910 break;
911 case 'rating':
912 $view_type = isset($data['ays-poll-rate-type']) ? sanitize_text_field($data['ays-poll-rate-type']) : "";
913 $rate_value = $data['ays-poll-rate-value'];
914 $answers = range(1, $rate_value);
915 $answers_show_added = array(1,1);
916 break;
917 case 'text':
918 $view_type = isset($data['ays_poll_text_type']) ? sanitize_text_field($data['ays_poll_text_type']) : "";
919 break;
920 default:
921 # code...
922 break;
923 }
924 if (0 == $id) {
925 $poll_result = $wpdb->insert(
926 $poll_table,
927 array(
928 'title' => $title,
929 'description' => $description,
930 'type' => $type,
931 'question' => $question,
932 'view_type' => $view_type,
933 'categories' => $categories,
934 'image' => $image,
935 'show_title' => $show_title,
936 'styles' => $styles,
937 'custom_css' => $css,
938 'theme_id' => $theme_id,
939 ),
940 array(
941 '%s',
942 '%s',
943 '%s',
944 '%s',
945 '%s',
946 '%s',
947 '%s',
948 '%d',
949 '%s',
950 '%s',
951 '%d',
952 )
953 );
954 $last_id = $wpdb->insert_id;
955 $answer_count = isset($answers) && is_array($answers) ? count($answers) : 0;
956 $empty_answers_count = 0;
957 $not_empty_answers_count = 0;
958 foreach ( $answers as $k => $answer ) {
959 if (empty($answer)) {
960 $empty_answers_count++;
961 continue;
962 }
963 else{
964 $not_empty_answers_count++;
965 }
966
967 $wpdb->insert(
968 $answer_table,
969 array(
970 'poll_id' => $last_id,
971 'answer' => wp_filter_kses($answer),
972 'redirect' => isset($answers_url[$k]) && $answers_url[$k] != "" ? sanitize_url($answers_url[$k]) : "",
973 'ordering' => ($k + 1),
974 'show_user_added' => isset($answers_show_added[$k]) ? $answers_show_added[$k] : 1,
975 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$k])) ? wp_http_validate_url($poll_answers_img[$k]) : "",
976 ),
977 array(
978 '%d', // poll_id
979 '%s', // answer
980 '%s', // redirect
981 '%d', // ordering
982 '%d', // show_user_added
983 '%s', // Answer Image
984 )
985 );
986 }
987 if($empty_answers_count == $answer_count && $type != "text"){
988 for($i = 0 ; $i < 2 ; $i++){
989 $wpdb->insert(
990 $answer_table,
991 array(
992 'poll_id' => $last_id,
993 'answer' => "Answer ".($i+1),
994 'redirect' => isset($answers_url[$i]) && $answers_url[$i] != "" ? sanitize_url($answers_url[$i]) : "",
995 'ordering' => ($i + 1),
996 'show_user_added' => isset($answers_show_added[$i]) ? $answers_show_added[$i] : 1,
997 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$i])) ? wp_http_validate_url($poll_answers_img[$i]) : "",
998 ),
999 array(
1000 '%d', // poll_id
1001 '%s', // answer
1002 '%s', // redirect
1003 '%d', // ordering
1004 '%d', // show_user_added
1005 '%s', // Answer Image
1006 )
1007 );
1008 }
1009 }
1010 if($not_empty_answers_count == 1){
1011 $wpdb->insert(
1012 $answer_table,
1013 array(
1014 'poll_id' => $last_id,
1015 'answer' => "Answer 1",
1016 'redirect' => isset($answers_url[$i]) && $answers_url[$i] != "" ? sanitize_url($answers_url[$i]) : "",
1017 'ordering' => ($i + 1),
1018 'show_user_added' => isset($answers_show_added[$i]) ? $answers_show_added[$i] : 1,
1019 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$i])) ? wp_http_validate_url($poll_answers_img[$i]) : "",
1020 ),
1021 array(
1022 '%d', // poll_id
1023 '%s', // answer
1024 '%s', // redirect
1025 '%d', // ordering
1026 '%d', // show_user_added
1027 '%s', // Answer Image
1028 )
1029 );
1030 }
1031 $message = 'created';
1032
1033 $post_type_args = array(
1034 'poll_id' => $last_id,
1035 'author_id' => !empty($poll_create_author) ? $poll_create_author : get_current_user_id(),
1036 'poll_title' => $title,
1037 );
1038
1039 $custom_post_id = Poll_Maker_Custom_Post_Type::ays_poll_add_custom_post($post_type_args);
1040
1041 } else {
1042 $poll = $this->get_poll_by_id($id);
1043 $poll_result = $wpdb->update(
1044 $poll_table,
1045 array(
1046 'title' => $title,
1047 'description' => $description,
1048 'type' => $type,
1049 'question' => $question,
1050 'view_type' => $view_type,
1051 'categories' => $categories,
1052 'image' => $image,
1053 'show_title' => $show_title,
1054 'styles' => $styles,
1055 'custom_css' => $css,
1056 'theme_id' => $theme_id,
1057 ),
1058 array('id' => $id),
1059 array(
1060 '%s', // title
1061 '%s', // description
1062 '%s', // type
1063 '%s', // question
1064 '%s', // view_type
1065 '%s', // categories
1066 '%s', // image
1067 '%d', // show_title
1068 '%s', // styles
1069 '%s', // custom_css
1070 '%d', // theme_id
1071 ),
1072 array('%d')
1073 );
1074 if ($type != $poll['type']) {
1075 $reports_table = esc_sql($wpdb->prefix."ayspoll_reports");
1076 $poll_id = absint(intval($id));
1077 $sql = "DELETE r FROM ".$reports_table." as r JOIN ".$answer_table." ON ".$answer_table.".id = r.answer_id JOIN ".$poll_table." ON ".$poll_table.".id = ".$answer_table.".poll_id WHERE ".$poll_table.".id = %d";
1078
1079 $wpdb->query(
1080 $wpdb->prepare($sql,$poll_id)
1081 );
1082
1083 $wpdb->delete(
1084 $answer_table,
1085 array('poll_id' => $id),
1086 array('%d')
1087 );
1088
1089 foreach ( $answers as $k => $answer ) {
1090 if (empty($answer)) {
1091 continue;
1092 }
1093
1094 $wpdb->insert(
1095 $answer_table,
1096 array(
1097 'poll_id' => $id,
1098 'answer' => wp_filter_kses($answer),
1099 'redirect' => isset($answers_url[$k]) && $answers_url[$k] != "" ? sanitize_url($answers_url[$k]) : "",
1100 'ordering' => ($k + 1),
1101 'show_user_added' => isset($answers_show_added[$k]) ? $answers_show_added[$k] : 1,
1102 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$k])) ? wp_http_validate_url($poll_answers_img[$k]) : "",
1103 ),
1104 array(
1105 '%d', // poll_id
1106 '%s', // answer
1107 '%s', // redirect
1108 '%d', // ordering
1109 '%d', // show_user_added
1110 '%s', // Answer Image
1111 )
1112 );
1113 }
1114 }
1115 if ('choosing' == $type && $type == $poll['type']) {
1116 foreach ( $poll['answers'] as $answer ) {
1117 $old_id = $answer['id'];
1118 $index = array_search($old_id, $answers_ids);
1119 if ($index !== false && !empty($answers[$index])) {
1120 $new_answer = isset($answers[$index]) && $answers[$index] != "" ? $answers[$index] : "";
1121 $new_url = sanitize_url($answers_url[$index]);
1122
1123 if (empty($new_url)) {
1124 $new_url = null;
1125 }
1126
1127 $wpdb->update(
1128 $answer_table,
1129 array(
1130 'answer' => wp_filter_kses($new_answer),
1131 'redirect' => $new_url,
1132 'ordering' => ($index + 1),
1133 'show_user_added' => isset($answers_show_added[$index]) ? $answers_show_added[$index] : 1,
1134 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "",
1135 ),
1136 array('id' => $old_id),
1137 array(
1138 '%s', // answer
1139 '%s', // redirect
1140 '%d', // ordering
1141 '%d', // show_user_added
1142 '%s', // Answer Image
1143 ),
1144 array('%d')
1145 );
1146 } else {
1147 $report_table = esc_sql($wpdb->prefix."ayspoll_reports");
1148 $wpdb->delete(
1149 $report_table,
1150 array('answer_id' => $old_id),
1151 array('%d')
1152 );
1153 $wpdb->delete(
1154 $answer_table,
1155 array('id' => $old_id),
1156 array('%d')
1157 );
1158 }
1159 }
1160 $e_answer_count = 0;
1161 $full_answer_count = 0;
1162 $answer_ids_count = count($answers);
1163 foreach ( $answers_ids as $index => $value ) {
1164 if (empty($answers[$index])) {
1165 $e_answer_count++;
1166 }
1167 else{
1168 $full_answer_count++;
1169 }
1170 if (0 == $value) {
1171 if (empty($answers[$index])) {
1172 continue;
1173 }
1174
1175 $wpdb->insert(
1176 $answer_table,
1177 array(
1178 'poll_id' => $id,
1179 'answer' => wp_filter_kses($answers[$index]),
1180 'redirect' => isset($answers_url[$index]) && $answers_url[$index] != "" ? sanitize_url($answers_url[$index]) : null,
1181 'ordering' => ($index + 1),
1182 'show_user_added' => isset($answers_show_added[$index]) ? $answers_show_added[$index] : 1,
1183 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "",
1184 ),
1185 array(
1186 '%d', // poll_id
1187 '%s', // answer
1188 '%s', // redirect
1189 '%d', // ordering
1190 '%d', // show_user_added
1191 '%s', // Answer Image
1192 )
1193 );
1194 }
1195
1196 }
1197 if($e_answer_count == $answer_ids_count){
1198 for($j = 0 ; $j < 2 ; $j++){
1199 $wpdb->insert(
1200 $answer_table,
1201 array(
1202 'poll_id' => $id,
1203 'answer' => "Answer ".($j+1),
1204 'redirect' => isset($answers_url[$j]) && isset($answers_url[$j]) != "" ? sanitize_url($answers_url[$j]) : null,
1205 'ordering' => ($j + 1),
1206 'show_user_added' => isset($answers_show_added[$index]) ? $answers_show_added[$index] : 1,
1207 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "",
1208 ),
1209 array(
1210 '%d', // poll_id
1211 '%s', // answer
1212 '%s', // redirect
1213 '%d', // ordering
1214 '%d', // show_user_added
1215 '%s', // Answer Image
1216 )
1217 );
1218 }
1219 }
1220 if($full_answer_count == 1){
1221 $wpdb->insert(
1222 $answer_table,
1223 array(
1224 'poll_id' => $id,
1225 'answer' => "Answer 1",
1226 'redirect' => isset($answers_url[$j]) && isset($answers_url[$j]) != "" ? sanitize_url($answers_url[$j]) : null,
1227 'ordering' => 1,
1228 'show_user_added' => isset($answers_show_added[$j]) ? $answers_show_added[$j] : 1,
1229 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "",
1230 ),
1231 array(
1232 '%d', // poll_id
1233 '%s', // answer
1234 '%s', // redirect
1235 '%d', // ordering
1236 '%d', // show_user_added
1237 '%s', // Answer Image
1238 )
1239 );
1240 }
1241 }
1242 if ($type == 'rating' && $poll['type'] == 'rating' && count($poll['answers']) != $rate_value) {
1243 if (count($poll['answers']) > $rate_value) {
1244 for ( $i = intval($rate_value); $i < count($poll['answers']); $i++ ) {
1245 $wpdb->delete(
1246 "{$wpdb->prefix}ayspoll_reports",
1247 array('answer_id' => $poll['answers'][$i]['id']),
1248 array('%d')
1249 );
1250 $wpdb->delete(
1251 $answer_table,
1252 array('id' => $poll['answers'][$i]['id']),
1253 array('%d')
1254 );
1255 }
1256 } else {
1257 for ( $i = count($poll['answers']); $i < $rate_value; $i++ ) {
1258 $wpdb->insert(
1259 $answer_table,
1260 array(
1261 'poll_id' => $id,
1262 'ordering'=> wp_filter_kses($answers[$i]),
1263 'answer' => wp_filter_kses($answers[$i]),
1264 ),
1265 array('%d', '%s')
1266 );
1267 }
1268 }
1269 }
1270 $message = 'updated';
1271 }
1272
1273 $add_post_for_poll = (isset($data['ays_add_post_for_poll']) && $data['ays_add_post_for_poll'] == 'on') ? 'on' : 'off';
1274 $add_postcat_for_poll = isset($data['ays_add_postcat_for_poll']) ? $data['ays_add_postcat_for_poll'] : array();
1275 $poll_post_id = ($id == 0) ? $last_id : $id;
1276
1277 if($add_post_for_poll == "on"){
1278 global $user_ID;
1279 $post_content = '[ays_poll id="'.$poll_post_id.'"]';
1280
1281 if ( Poll_Maker_Ays_Admin::is_active_gutenberg() ) {
1282 $post_content = '<!-- wp:poll-maker/poll {"metaFieldValue":'.$poll_post_id.',"shortcode":"[ays_poll id='.$poll_post_id.']"} -->
1283 <div class="wp-block-poll-maker-poll">[ays_poll id="'.$poll_post_id.'"]</div>
1284 <!-- /wp:poll-maker/poll -->';
1285 }
1286
1287 $new_post = array(
1288 'post_title' => $title,
1289 'post_content' => $post_content,
1290 'post_status' => 'publish',
1291 'post_date' => current_time( 'mysql' ),
1292 'post_author' => $user_ID,
1293 'post_type' => 'post',
1294 'post_category' => $add_postcat_for_poll
1295 );
1296 $post_id = wp_insert_post($new_post);
1297 if(! empty($image)){
1298 $sql = "SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'attachment' AND guid = '".$image."'";
1299 $attachment_id = intval($wpdb->get_var($sql));
1300 if($attachment_id !== 0){
1301 $featured_image = set_post_thumbnail($post_id, $attachment_id);
1302 }
1303 }
1304 $poll_post_result = $wpdb->update(
1305 $poll_table,
1306 array( 'post_id' => $post_id ),
1307 array( 'id' => $poll_post_id ),
1308 array( '%d' ),
1309 array( '%d' )
1310 );
1311 }
1312
1313 $active_tabs = !empty($data['ays_poll_active_tab']) ? sanitize_text_field($data['ays_poll_active_tab']) : "General";
1314 $active_tab = urlencode($active_tabs);
1315
1316 if ($poll_result >= 0) {
1317 if($message == 'created'){
1318 setcookie('ays_poll_created_new', $last_id, time() + 3600, '/');
1319 if(!empty($custom_post_id)){
1320 $custom_post_url = array(
1321 'post_type' => 'ays-poll-maker',
1322 'p' => $custom_post_id,
1323 'preview' => 'true',
1324 );
1325 $custom_post_url_ready = http_build_query($custom_post_url);
1326 $ready_url = get_home_url();
1327 $ready_url .= '/?' . $custom_post_url_ready;
1328 setcookie('ays_poll_created_new_'.$last_id.'_post_id', $ready_url, time() + 3600, '/');
1329 }
1330
1331 }
1332 }
1333
1334 if ($poll_result >= 0) {
1335 if ('' != $ays_change_type) {
1336 if($id == 0){
1337 $url = esc_url_raw( add_query_arg( array(
1338 "action" => "edit",
1339 "poll" => $last_id,
1340 "active-tab" => $active_tab,
1341 "status" => $message
1342 ) ) );
1343 }else{
1344 $url = esc_url_raw( remove_query_arg(false) ) . '&active-tab='.$active_tab.'&status=' . $message;
1345 }
1346 wp_redirect($url);
1347 } else {
1348 $url = esc_url_raw(remove_query_arg(['action'])) . "&active-tab=".$active_tab."&status=" . $message;
1349 wp_redirect($url);
1350 }
1351 }
1352 }
1353 $allowedtags = $old_allowedtags;
1354 }
1355
1356 public function duplicate_poll( $id ) {
1357 global $wpdb;
1358
1359 // Nonce verification for CSRF protection
1360 if (!isset($_GET['_wpnonce']) && !wp_verify_nonce($_GET['_wpnonce'], $this->plugin_name . '-duplicate-poll')) {
1361 wp_die( esc_html__('Security check error. Try again.', "poll-maker"));
1362 }
1363
1364 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
1365 $answers_table = esc_sql($wpdb->prefix."ayspoll_answers");
1366
1367 $duplicate = $this->get_poll_by_id($id, false);
1368 if (empty($duplicate)) {
1369 $url = esc_url_raw(remove_query_arg(array('action', 'poll'))) . '&status=failed';
1370 wp_redirect($url);
1371 exit;
1372 }
1373
1374 $user_id = get_current_user_id();
1375 $user = get_userdata($user_id);
1376 $author = array(
1377 'id' => $user->ID,
1378 'name' => $user->data->display_name
1379 );
1380 $options = json_decode($duplicate['styles'], true);
1381
1382 $options['create_date'] = current_time( 'mysql' );
1383 $options['author'] = $author;
1384
1385 $options['ays_add_post_for_poll'] = 'off';
1386
1387 $answers = $duplicate['answers'];
1388 unset($duplicate['answers']);
1389 unset($duplicate['id']);
1390 $duplicate['title'] = "Copy - " . $duplicate['title'];
1391 $duplicate['styles'] = json_encode($options);
1392 $result = $wpdb->insert(
1393 $poll_table,
1394 $duplicate,
1395 array(
1396 '%d', // post_id
1397 '%s', // title
1398 '%s', // description
1399 '%s', // question
1400 '%s', // type
1401 '%s', // view_type
1402 '%s', // categories
1403 '%s', // image
1404 '%s', // show_title
1405 '%s', // styles
1406 '%s', // custom_css
1407 '%d', // theme_id
1408 )
1409 );
1410
1411 $poll_id = $wpdb->insert_id;
1412 $answers_results = array();
1413 $flag = true;
1414
1415 foreach ( $answers as $answer ) {
1416 $answer['poll_id'] = $poll_id;
1417 unset($answer['id']);
1418 unset($answer['votes']);
1419 $answers_results[] = $wpdb->insert(
1420 $answers_table,
1421 $answer,
1422 array(
1423 '%s',
1424 '%s',
1425 '%s',
1426 )
1427 );
1428 }
1429
1430 foreach ( $answers_results as $answers_result ) {
1431 if ($answers_result >= 0) {
1432 $flag = true;
1433 } else {
1434 $flag = false;
1435 break;
1436 }
1437 }
1438 $message = 'duplicated';
1439 if ($result >= 0 && $flag == true) {
1440
1441 $post_type_args = array(
1442 'poll_id' => $poll_id,
1443 'author_id' => !empty($user->ID) ? $user->ID : $user_id,
1444 'poll_title' => "Copy - ".$duplicate['title'],
1445 );
1446
1447 $custom_post_id = Poll_Maker_Custom_Post_Type::ays_poll_add_custom_post($post_type_args);
1448
1449 $url = esc_url_raw(remove_query_arg(array('action', 'poll'))) . '&status=' . $message;
1450 wp_redirect($url);
1451 exit;
1452 }
1453
1454 }
1455
1456 public static function get_poll_pass_count($id) {
1457 global $wpdb;
1458 $poll_id = absint(sanitize_text_field($id));
1459 $args_id = esc_sql($poll_id);
1460 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
1461 $sql = "SELECT SUM(votes) FROM ".$answ_table." WHERE poll_id=%d";
1462 $result = $wpdb->get_var(
1463 $wpdb->prepare( $sql, $args_id)
1464 );
1465
1466 return $result;
1467 }
1468
1469 public function get_poll_by_id( $id, $decode = true ) {
1470 global $wpdb;
1471 $poll_id = absint(sanitize_text_field($id));
1472 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
1473 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
1474 $sql = "SELECT * FROM ".$poll_table." WHERE id=%d";
1475 $poll = $wpdb->get_row(
1476 $wpdb->prepare( $sql, $poll_id),
1477 'ARRAY_A'
1478 );
1479
1480 if (empty($poll)) {
1481 return array();
1482 }
1483
1484 $sql_answ = "SELECT * FROM ".$answ_table." WHERE poll_id=%d ORDER BY ordering ASC, id ASC";
1485 $poll['answers'] = $wpdb->get_results(
1486 $wpdb->prepare( $sql_answ, $poll_id),
1487 'ARRAY_A'
1488 );
1489
1490 if ($decode) {
1491 $cats = explode(',', $poll['categories']);
1492 $poll['categories'] = !empty($cats) ? $cats : array();
1493 $json = $poll['styles'];
1494 $poll['styles'] = json_decode($json, true);
1495 }
1496
1497 return $poll;
1498 }
1499
1500 /** Text displayed when no customer data is available */
1501 public function no_items() {
1502 _e('There are no polls yet.', "poll-maker");
1503 }
1504
1505 /**
1506 * Render a column when no column specific method exist.
1507 *
1508 * @param array $item
1509 * @param string $column_name
1510 *
1511 * @return mixed
1512 */
1513 public function column_default( $item, $column_name ) {
1514 switch ( $column_name ) {
1515 case 'title':
1516 case 'poll_image':
1517 case 'categories':
1518 case 'type':
1519 case 'shortcode':
1520 case 'code_include':
1521 case 'results':
1522 case 'create_date':
1523 case 'completed_count':
1524 case 'id':
1525 case 'publish':
1526 return $item[$column_name];
1527 break;
1528 default:
1529 return print_r($item, true); //Show the whole array for troubleshooting purposes
1530 }
1531 }
1532
1533 /**
1534 * Render the bulk edit checkbox
1535 *
1536 * @param array $item
1537 *
1538 * @return string
1539 */
1540 function column_cb( $item ) {
1541 return sprintf(
1542 '<input type="checkbox" name="bulk-delete[]" value="%s" />',
1543 $item['id']
1544 );
1545 }
1546
1547 /**
1548 * Method for name column
1549 *
1550 * @param array $item an array of DB data
1551 *
1552 * @return string
1553 */
1554 function column_title( $item ) {
1555 $delete_nonce = wp_create_nonce($this->plugin_name . '-delete-poll');
1556 $duplicate_nonce = wp_create_nonce($this->plugin_name . '-duplicate-poll');
1557
1558 $poll_title = stripcslashes($item['title']);
1559
1560 $custom_post_id = isset($item['custom_post_id']) && $item['custom_post_id'] != 0 && $item['custom_post_id'] != '' ? esc_attr(intval($item['custom_post_id'])) : 0;
1561
1562 $p = esc_attr($poll_title);
1563 $polls_title_length = intval( $this->title_length );
1564
1565 $restitle = Poll_Maker_Ays_Admin::ays_restriction_string("word", $poll_title, $polls_title_length);
1566
1567 $title = sprintf('<a href="?page=%s&action=%s&poll=%d" title="%s">%s</a>', esc_attr($_REQUEST['page']), 'edit', absint($item['id']), $p, $restitle);
1568
1569 $actions['edit'] = sprintf( '<a href="?page=%s&action=%s&poll=%d">'. esc_html__('Edit', 'poll-maker') .'</a>', esc_attr( $_REQUEST['page'] ), 'edit', absint( $item['id'] ) );
1570
1571 $actions['duplicate'] = sprintf('<a href="?page=%s&action=%s&poll=%d&_wpnonce=%s">' .esc_html__('Duplicate', "poll-maker") . '</a>', esc_attr($_REQUEST['page']), 'duplicate', absint($item['id']),$duplicate_nonce);
1572
1573 $actions['results'] = sprintf( '<a href="?page=%s&poll=%d&title=%s">'. esc_html__('View Results', 'poll-maker') .'</a>', esc_attr( $_REQUEST['page'] ) . '-results-each', absint( $item['id'] ), $poll_title );
1574
1575 if($custom_post_id > 0){
1576 $actions['custom_posts'] = sprintf( '<a href="%s" target="_blank">'. esc_html__('Preview', "poll-maker") .'</a>', esc_url( add_query_arg( 'preview', 'true', get_permalink($custom_post_id) ) ));
1577 }
1578
1579 $actions['delete'] = sprintf( '<a class="ays_confirm_del" data-message="%s" href="?page=%s&action=%s&poll=%d&_wpnonce=%s">'. esc_html__('Delete', 'poll-maker') .'</a>', $restitle, esc_attr( $_REQUEST['page'] ), 'delete', absint( $item['id'] ), $delete_nonce );
1580
1581
1582 return $title . $this->row_actions($actions);
1583 }
1584
1585 function column_shortcode( $item ) {
1586 $shortcode_content = '<div class="ays-poll-shortcode-container">
1587 <div class="ays-poll-copy-image" data-toggle="tooltip" aria-label="' . __( 'Click to copy', "poll-maker" ) . '" data-original-title="' . __( 'Click to copy', "poll-maker" ) . '">
1588 <img src="' . esc_url(POLL_MAKER_AYS_ADMIN_URL) . '/images/icons/edit-shortcode.svg">
1589 </div>';
1590
1591 $shortcode_input = sprintf('<input type="text" class="ays-poll-shortcode-input" onclick="this.setSelectionRange(0, this.value.length)" readonly value="[ays_poll id=%s]" />', $item["id"]);
1592
1593 $shortcode_content .= $shortcode_input;
1594 $shortcode_content .= '</div>';
1595
1596 return $shortcode_content;
1597 }
1598
1599 function column_code_include( $item ) {
1600 return sprintf('<input type="text" onClick="this.setSelectionRange(0, this.value.length)" readonly value="<?php echo do_shortcode(\'[ays_poll id=%s]\'); ?>" />', $item["id"]);
1601 }
1602
1603 function column_results($item) {
1604 return sprintf('<a href="?page=%s&poll=%d&title=%s"><img src="'. esc_url(POLL_MAKER_AYS_ADMIN_URL) .'/images/icons/view-poll-results.svg"></a>', esc_attr( $_REQUEST['page'] ) . '-results-each', absint( $item['id']), $item['title']);
1605 }
1606
1607 function column_categories( $item ) {
1608 if ($item['categories'] == '') {
1609 return '';
1610 }
1611 global $wpdb;
1612 $cats_ids = explode(',', $item['categories']);
1613 $cat_table = esc_sql($wpdb->prefix."ayspoll_categories");
1614 $category_location = "#";
1615 foreach ( $cats_ids as $id ) {
1616 if (empty($id)) {
1617 continue;
1618 }
1619 $args_id = absint( esc_sql($id) );
1620 $sql = "SELECT * FROM ".$cat_table." WHERE id=%d";
1621
1622 $result = $wpdb->get_row(
1623 $wpdb->prepare( $sql, $args_id),
1624 'ARRAY_A'
1625 );
1626 if (empty($result)) {
1627 continue;
1628 }
1629
1630 if ( isset($result) && $result > 0 ) {
1631 $category_location = sprintf( '<span>%s</span>', $result['title']);
1632 }
1633
1634 $cats_content = $category_location;
1635 }
1636
1637 return $cats_content;
1638 }
1639
1640 function column_create_date( $item ) {
1641 $options = json_decode($item['styles'], true);
1642 $date = isset($options['create_date']) && $options['create_date'] != '' ? sanitize_text_field($options['create_date']) : current_time( 'mysql' );
1643 if(isset($options['author'])){
1644 if(is_array($options['author'])){
1645 $author = $options['author'];
1646 }else{
1647 $author = json_decode($options['author'], true);
1648 }
1649 }else{
1650 $author = array("name"=>"Unknown");
1651 }
1652 $text = "";
1653 if(Poll_Maker_Ays_Admin::validateDate($date)){
1654 $text .= "<p><b>Date:</b> ".$date."</p>";
1655 }
1656 if(isset($author['name']) && $author['name'] !== "Unknown"){
1657 $text .= "<p><b>Author:</b> ".$author['name']."</p>";
1658 }
1659 return $text;
1660 }
1661
1662 function column_completed_count( $item ) {
1663 $id = $item['id'];
1664 $passed_count = $this->get_poll_pass_count($id);
1665 $text = "<p style='text-align:center;font-size:14px;'>".$passed_count."</p>";
1666 return $text;
1667 }
1668
1669 function column_publish( $item ) {
1670 global $wpdb;
1671 $id = absint(sanitize_text_field($item['id']));
1672 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
1673 $sql = "SELECT * FROM ".$poll_table." WHERE id=%d";
1674
1675 $res = $wpdb->get_row(
1676 $wpdb->prepare( $sql, $id),
1677 'ARRAY_A'
1678 );
1679 $options = json_decode($res['styles'], true);
1680 $status = isset($options['published']) ? $options['published'] : 1;
1681
1682 return $status ? "<i class=\"ays_poll_far ays_poll_fa-check-square\"></i> " .esc_html__("Published", "poll-maker") : "<i class=\"ays_poll_far ays_poll_fa-xmark-square\"></i> " .esc_html__("Unpublished", "poll-maker");
1683 }
1684
1685 function column_poll_image( $item ) {
1686 global $wpdb;
1687 $poll_image = (isset( $item['image'] ) && $item['image'] != '') ? esc_url( $item['image'] ) : '';
1688
1689 $image_html = array();
1690 $edit_page_url = '';
1691
1692 if($poll_image != ''){
1693
1694 if ( isset( $item['id'] ) && absint( $item['id'] ) > 0 ) {
1695 $edit_page_url = sprintf( 'href="?page=%s&action=%s&poll=%d"', esc_attr( $_REQUEST['page'] ), 'edit', absint( $item['id'] ) );
1696 }
1697
1698 $poll_image_url = $poll_image;
1699 $this_site_path = trim( get_site_url(), "https:" );
1700 if( strpos( trim( $poll_image_url, "https:" ), $this_site_path ) !== false ){
1701 $query = "SELECT * FROM `" . $wpdb->prefix . "posts` WHERE `post_type` = 'attachment' AND `guid` = '" . $poll_image_url . "'";
1702 $result_img = $wpdb->get_results( $query, "ARRAY_A" );
1703
1704 if( ! empty( $result_img ) ){
1705 $url_img = wp_get_attachment_image_src( $result_img[0]['ID'], 'thumbnail' );
1706 if( $url_img !== false ){
1707 $poll_image_url = $url_img[0];
1708 }
1709 }
1710 }
1711
1712 $image_html[] = '<div class="ays-poll-image-list-table-column">';
1713 $image_html[] = '<a '. $edit_page_url .' class="ays-poll-image-list-table-link-column">';
1714 $image_html[] = '<img src="'. $poll_image_url .'" class="ays-poll-image-list-table-img-column">';
1715 $image_html[] = '</a>';
1716 $image_html[] = '</div>';
1717 }
1718
1719 $image_html = implode('', $image_html);
1720
1721 return $image_html;
1722 }
1723
1724 /**
1725 * Associative array of columns
1726 *
1727 * @return array
1728 */
1729 function get_columns() {
1730 $columns = array(
1731 'cb' => '<input type="checkbox" />',
1732 'title' => esc_html__('Title', "poll-maker"),
1733 'poll_image' => esc_html__('Question image', "poll-maker"),
1734 'type' => esc_html__('Type', "poll-maker"),
1735 'shortcode' => esc_html__('Shortcode', "poll-maker"),
1736 'code_include' => esc_html__('Code Include', "poll-maker"),
1737 'results' => esc_html__('Results', "poll-maker"),
1738 'categories' => esc_html__('Categories', "poll-maker"),
1739 'create_date' => esc_html__('Created', "poll-maker" ),
1740 'completed_count' => esc_html__('Completed count', "poll-maker" ),
1741 'publish' => esc_html__('Status', "poll-maker"),
1742 'id' => esc_html__('ID', "poll-maker"),
1743 );
1744
1745 return $columns;
1746 }
1747
1748 /**
1749 * Columns to make sortable.
1750 *
1751 * @return array
1752 */
1753 public function get_sortable_columns() {
1754 $sortable_columns = array(
1755 'title' => array('title', true),
1756 'type' => array('type', true),
1757 'id' => array('id', true),
1758 );
1759
1760 return $sortable_columns;
1761 }
1762
1763 /**
1764 * Columns to make sortable.
1765 *
1766 * @return array
1767 */
1768 public function get_hidden_columns() {
1769 $hidden_culumns = array(
1770 'poll_image',
1771 'code_include',
1772 );
1773 return $hidden_culumns;
1774 }
1775
1776 /**
1777 * Returns an associative array containing the bulk action
1778 *
1779 * @return array
1780 */
1781 public function get_bulk_actions() {
1782 $actions = array(
1783 'bulk-delete' =>esc_html__('Delete', "poll-maker"),
1784 );
1785
1786 return $actions;
1787 }
1788
1789 /**
1790 * Handles data query and filter, sorting, and pagination.
1791 */
1792 public function prepare_items() {
1793 global $wpdb;
1794
1795 $this->_column_headers = $this->get_column_info();
1796
1797 /** Process bulk action */
1798 $this->process_bulk_action();
1799
1800 $per_page = $this->get_items_per_page('polls_per_page', 20);
1801 $current_page = $this->get_pagenum();
1802 $total_items = self::record_count();
1803
1804 $this->set_pagination_args(array(
1805 'total_items' => $total_items, //WE have to calculate the total number of items
1806 'per_page' => $per_page, //WE have to determine how many items to show on a page
1807 ));
1808
1809 $search = ( isset( $_REQUEST['s'] ) ) ? esc_sql( sanitize_text_field( $_REQUEST['s'] ) ) : false;
1810 $do_search = ( $search ) ? sprintf(" title LIKE '%%%s%%' ", esc_sql( $wpdb->esc_like( $search ) ) ) : '';
1811
1812 $this->items = self::get_polls($per_page, $current_page, $do_search);
1813 }
1814
1815 public function process_bulk_action() {
1816 //Detect when a bulk action is being triggered...
1817 $message = 'deleted';
1818 if ('delete' === $this->current_action()) {
1819
1820 // In our file that handles the request, verify the nonce.
1821 $nonce = esc_attr($_REQUEST['_wpnonce']);
1822
1823 if (!wp_verify_nonce($nonce, $this->plugin_name . '-delete-poll')) {
1824 die('Go get a life script kiddies');
1825 } else {
1826 self::delete_polls(absint($_GET['poll']));
1827
1828 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
1829 // add_query_arg() return the current url
1830
1831 $url = esc_url_raw(remove_query_arg(['action', 'poll', '_wpnonce'])) . '&status=' . $message;
1832 wp_redirect($url);
1833 }
1834 }
1835
1836 // If the delete bulk action is triggered
1837 if ((isset($_POST['action']) && 'bulk-delete' == $_POST['action'])
1838 || (isset($_POST['action2']) && 'bulk-delete' == $_POST['action2'])
1839 ) {
1840
1841 $delete_ids = ( isset( $_POST['bulk-delete'] ) && ! empty( $_POST['bulk-delete'] ) ) ? esc_sql( $_POST['bulk-delete'] ) : array();
1842
1843 // loop over the array of record IDs and delete them
1844 $deleted_polls_count = 0;
1845 foreach ( $delete_ids as $id ) {
1846 $deleted_polls_count++;
1847 self::delete_polls($id);
1848 }
1849
1850 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
1851 // add_query_arg() return the current url
1852
1853 $url = esc_url_raw(remove_query_arg(['action', 'poll', '_wpnonce'])) . '&status=' . $message . '&d_count=' .$deleted_polls_count;
1854 wp_redirect($url);
1855 }
1856 }
1857
1858 /**
1859 * Delete a customer record.
1860 *
1861 * @param int $id customer ID
1862 */
1863 public static function delete_polls( $id ) {
1864 global $wpdb;
1865 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
1866 $answ_table = esc_sql($wpdb->prefix . "ayspoll_answers");
1867 $reports_table = esc_sql($wpdb->prefix . "ayspoll_reports");
1868 $wpdb->delete(
1869 $poll_table,
1870 array('id' => $id),
1871 array('%d')
1872 );
1873 $wpdb->delete(
1874 $answ_table,
1875 array('poll_id' => $id),
1876 array('%d')
1877 );
1878 $sql = "DELETE FROM ".$reports_table."
1879 WHERE answer_id NOT IN (SELECT id FROM ".$answ_table.")";
1880 $wpdb->query($sql);
1881 }
1882
1883 /**
1884 * Returns the count of records in the database.
1885 *
1886 * @return null|string
1887 */
1888 public static function record_count() {
1889 global $wpdb;
1890 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
1891 $sql = "SELECT COUNT(*) FROM ".$poll_table;
1892 $sql_count = self::get_where_condition();
1893 if(isset($sql_count) && !empty($sql_count)){
1894 $sql .= $sql_count;
1895 }
1896 return $wpdb->get_var($sql);
1897 }
1898
1899 public static function all_record_count() {
1900 global $wpdb;
1901
1902 $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}ayspoll_polls";
1903
1904 if (isset($_GET['filterby']) && absint(intval($_GET['filterby'])) > 0) {
1905 $cat_id = absint(intval($_GET['filterby']));
1906 if (isset($_SERVER['HTTP_HOST']) && sanitize_text_field($_SERVER['HTTP_HOST']) == "playground.wordpress.net") {
1907 $sql .= " WHERE categories LIKE '%," . $cat_id . ",%' OR categories LIKE '" . $cat_id . ",%' OR categories LIKE '%," . $cat_id . "' OR categories = '" . $cat_id . "'";
1908 } else {
1909 $sql .= " WHERE FIND_IN_SET('{$cat_id}', categories) > 0";
1910 }
1911 }
1912
1913 return $wpdb->get_var( $sql );
1914 }
1915
1916 public static function published_polls_count() {
1917 global $wpdb;
1918
1919 // Counters
1920 $publishedCount = 0;
1921
1922 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
1923 $sql = "SELECT * FROM " . $poll_table;
1924
1925 if (isset($_GET['filterby']) && absint(intval($_GET['filterby'])) > 0) {
1926 $cat_id = absint(intval($_GET['filterby']));
1927 if (isset($_SERVER['HTTP_HOST']) && sanitize_text_field($_SERVER['HTTP_HOST']) == "playground.wordpress.net") {
1928 $sql .= " WHERE categories LIKE '%," . $cat_id . ",%' OR categories LIKE '" . $cat_id . ",%' OR categories LIKE '%," . $cat_id . "' OR categories = '" . $cat_id . "'";
1929 } else {
1930 $sql .= " WHERE FIND_IN_SET('{$cat_id}', categories) > 0";
1931 }
1932 }
1933
1934 $results = $wpdb->get_results($sql, ARRAY_A);
1935
1936 foreach ($results as $poll) {
1937 $options = json_decode($poll['styles'], true);
1938 $status = isset($options['published']) ? $options['published'] : 1;
1939
1940 if ($status == 1) {
1941 $publishedCount++;
1942 }
1943 }
1944
1945 return $publishedCount;
1946 }
1947
1948 public static function unpublished_polls_count() {
1949 global $wpdb;
1950
1951 // Counters
1952 $unpublishedCount = 0;
1953
1954 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
1955 $sql = "SELECT * FROM " . $poll_table;
1956
1957 if (isset($_GET['filterby']) && absint(intval($_GET['filterby'])) > 0) {
1958 $cat_id = absint(intval($_GET['filterby']));
1959 if (isset($_SERVER['HTTP_HOST']) && sanitize_text_field($_SERVER['HTTP_HOST']) == "playground.wordpress.net") {
1960 $sql .= " WHERE categories LIKE '%," . $cat_id . ",%' OR categories LIKE '" . $cat_id . ",%' OR categories LIKE '%," . $cat_id . "' OR categories = '" . $cat_id . "'";
1961 } else {
1962 $sql .= " WHERE FIND_IN_SET('{$cat_id}', categories) > 0";
1963 }
1964 }
1965
1966 $results = $wpdb->get_results($sql, ARRAY_A);
1967
1968 foreach ($results as $poll) {
1969 $options = json_decode($poll['styles'], true);
1970 $status = isset($options['published']) ? $options['published'] : 1;
1971
1972 if ($status == 0) {
1973 $unpublishedCount++;
1974 }
1975 }
1976
1977 return $unpublishedCount;
1978 }
1979
1980 public static function get_where_condition(){
1981 global $wpdb;
1982
1983 $where = array();
1984 $sql = '';
1985
1986 $search = ( isset( $_REQUEST['s'] ) ) ? esc_sql( sanitize_text_field( $_REQUEST['s'] ) ) : false;
1987 if( $search ){
1988 $where[] = sprintf(" title LIKE '%%%s%%' ", esc_sql( $wpdb->esc_like( $search ) ) );
1989 }
1990
1991 if(isset( $_REQUEST['filterby'] ) && $_REQUEST['filterby'] > 0 ){
1992 $cat_id = esc_sql( sanitize_text_field( $_REQUEST['filterby'] ) );
1993
1994 $where[] = sprintf(" categories LIKE('%%,%s,%%') ", esc_sql( $wpdb->esc_like( $cat_id ) ) );
1995 }
1996
1997 if( isset( $_REQUEST['fstatus'] ) && is_numeric( $_REQUEST['fstatus'] ) && ! is_null( sanitize_text_field( $_REQUEST['fstatus'] ) ) ){
1998 if( esc_sql( $_REQUEST['fstatus'] ) != '' ){
1999 $fstatus = absint( esc_sql( $_REQUEST['fstatus'] ) );
2000 $where[] = " JSON_EXTRACT(styles, '$.published') = " . ($fstatus == 1 ? '1' : '0');
2001 }
2002 }
2003
2004 if(isset( $_REQUEST['filterbyauthor'] ) && $_REQUEST['filterbyauthor'] > 0 ){
2005 $author_id = esc_sql( sanitize_text_field( $_REQUEST['filterbyauthor'] ) );
2006
2007 $where[] = sprintf(" categories LIKE('%%,%s,%%') ", esc_sql( $wpdb->esc_like( $author_id ) ) );
2008 }
2009 if(isset( $_REQUEST['filterbytype'] ) && $_REQUEST['filterbytype'] != "" ){
2010 $type = esc_sql( sanitize_text_field( $_REQUEST['filterbytype'] ) );
2011 if (isset($type) && $type != '') {
2012 $where[] = " type = '" . $type . "'";
2013 }
2014 }
2015
2016 if( !empty($where) ){
2017 $sql = " WHERE " . implode( " AND ", $where );
2018 }
2019 return $sql;
2020 }
2021
2022 /**
2023 * Retrieve customers data from the database
2024 *
2025 * @param int $per_page
2026 * @param int $page_number
2027 *
2028 * @return mixed
2029 */
2030 public static function get_polls( $per_page = 20, $page_number = 1 , $search = '') {
2031
2032 global $wpdb;
2033 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
2034 $sql = "SELECT * FROM ".$poll_table;
2035 $args = array();
2036
2037 $where = array();
2038
2039 if( $search != '' ){
2040 $where[] = $search;
2041 }
2042
2043 if(isset( $_REQUEST['filterby'] ) && $_REQUEST['filterby'] > 0 ){
2044 $cat_id = esc_sql( sanitize_text_field( $_REQUEST['filterby'] ) );
2045
2046 $where[] = sprintf(" categories LIKE('%%,%s,%%') ", esc_sql( $wpdb->esc_like( $cat_id ) ) );
2047 }
2048
2049 if ( isset( $_REQUEST['filterbyauthor'] ) && absint( $_REQUEST['filterbyauthor'] ) > 0 ) {
2050 $poll_author = absint( $_REQUEST['filterbyauthor'] );
2051 $where[] = $wpdb->prepare( "JSON_EXTRACT(styles, '$.poll_create_author') = %d", $poll_author );
2052 }
2053
2054 if(isset( $_REQUEST['filterbytype'] ) && $_REQUEST['filterbytype'] != "" ){
2055 $type = esc_sql( sanitize_text_field( $_REQUEST['filterbytype'] ) );
2056 if (isset($type) && $type != '') {
2057 $where[] = " type = '" . $type . "'";
2058 }
2059 }
2060
2061 if( isset( $_REQUEST['fstatus'] ) && is_numeric( $_REQUEST['fstatus'] ) && ! is_null( sanitize_text_field( $_REQUEST['fstatus'] ) ) ){
2062 if( esc_sql( $_REQUEST['fstatus'] ) != '' ){
2063 $fstatus = absint( esc_sql( $_REQUEST['fstatus'] ) );
2064 $where[] = " JSON_EXTRACT(styles, '$.published') = " . ($fstatus == 1 ? '1' : '0');
2065 }
2066 }
2067
2068 if( ! empty($where) ){
2069 $sql .= " WHERE " . implode( " AND ", $where );
2070 }
2071
2072 if ( ! empty( $_REQUEST['orderby'] ) ) {
2073
2074 $order_by = ( isset( $_REQUEST['orderby'] ) && sanitize_text_field( $_REQUEST['orderby'] ) != '' ) ? sanitize_text_field( $_REQUEST['orderby'] ) : 'id';
2075 $order_by .= ( ! empty( $_REQUEST['order'] ) && strtolower( $_REQUEST['order'] ) == 'asc' ) ? ' ASC' : ' DESC';
2076
2077 $sql_orderby = sanitize_sql_orderby($order_by);
2078
2079 if ( $sql_orderby ) {
2080 $sql .= ' ORDER BY ' . $sql_orderby;
2081 } else {
2082 $sql .= ' ORDER BY id DESC';
2083 }
2084 }else{
2085 $sql .= ' ORDER BY id DESC';
2086 }
2087
2088 $sql .= " LIMIT %d";
2089 $args[] = $per_page;
2090 $offset = ($page_number - 1) * $per_page;
2091 $sql .= " OFFSET %d";
2092 $args[] = $offset;
2093 $result = $wpdb->get_results(
2094 $wpdb->prepare( $sql, $args),
2095 'ARRAY_A'
2096 );
2097
2098 return $result;
2099 }
2100
2101 public function poll_notices() {
2102 $status = (isset($_REQUEST['status'])) ? sanitize_text_field($_REQUEST['status']) : '';
2103
2104 if (empty($status)) {
2105 return;
2106 }
2107
2108 if ('created' == $status) {
2109 $updated_message = esc_html( esc_html__('Poll created.', "poll-maker"));
2110 } elseif ('updated' == $status) {
2111 $updated_message = esc_html( esc_html__('Poll saved.', "poll-maker"));
2112 } elseif ('duplicated' == $status) {
2113 $updated_message = esc_html( esc_html__('Poll duplicated.', "poll-maker"));
2114 } elseif ('deleted' == $status) {
2115 $deleted_count = isset($_GET['d_count']) && $_GET['d_count'] != "" ? intval(esc_attr($_GET['d_count'])) : 0;
2116 $deleted_count_message =esc_html__('Poll deleted.', "poll-maker");
2117 if($deleted_count > 1){
2118 $deleted_count_message = $deleted_count .esc_html__(' Polls are deleted.', "poll-maker");
2119 }
2120 $updated_message = $deleted_count_message;
2121 }
2122
2123 if (empty($updated_message)) {
2124 return;
2125 }
2126
2127 ?>
2128 <div class="ays-poll-admin-notice notice notice-success is-dismissible">
2129 <p>
2130 <?php echo $updated_message; ?>
2131 </p>
2132 </div>
2133 <?php
2134 }
2135 }
2136