PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.4.5
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.4.5
6.4.9 6.4.8 6.4.7 6.4.6 6.4.5 6.4.4 6.4.3 6.4.2 6.4.1 6.4.0 6.3.9 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 All 152 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.5, at includes/lists/class-poll-maker-polls-list-table.php

2,139 lines 99.8 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 'instagram_link' => '',
677 );
678
679 $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'] ) : '';
680 $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'] ) : '';
681 $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'] ) : '';
682 $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'] ) : '';
683 $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'] ) : '';
684 $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'] ) : '';
685 $instagram_link = isset($ays_social_links['ays_instagram_link']) && sanitize_text_field( $ays_social_links['ays_instagram_link'] ) != '' ? sanitize_text_field( $ays_social_links['ays_instagram_link'] ) : '';
686
687 $social_links = array(
688 'linkedin_link' => $linkedin_link,
689 'facebook_link' => $facebook_link,
690 'twitter_link' => $twitter_link,
691 'vkontakte_link' => $vkontakte_link,
692 'youtube_link' => $youtube_link,
693 'tiktok_link' => $tiktok_link,
694 'instagram_link' => $instagram_link,
695 );
696
697 $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';
698 $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;
699
700 $styles = json_encode(array(
701 // Style tab start
702 'main_color' => $main_color,
703 'text_color' => $text_color,
704 'button_text_color' => $button_text_color,
705 'button_bg_color' => $button_bg_color,
706 'icon_color' => $icon_color,
707 'bg_color' => $bg_color,
708 'bg_image' => $bg_image,
709 'enable_answer_style' => $enable_answer_style,
710 'answer_bg_color' => $answer_bg_color,
711 'answer_hover_color' => $answer_hover_color,
712 'answer_border_side' => $answer_border_side,
713 "answer_font_size" => $poll_answer_font_size,
714 "poll_answer_font_size_mobile" => $poll_answer_font_size_mobile,
715 'poll_answer_object_fit' => $poll_answer_object_fit,
716 'poll_answer_padding' => $poll_answer_padding,
717 'poll_answer_margin' => $poll_answer_margin,
718 'poll_answer_border_radius' => $poll_answer_border_radius,
719 'poll_answer_icon_check' => $poll_answer_icon_check,
720 'poll_answer_icon' => $poll_answer_icon,
721 'poll_answer_view_type' => $poll_answer_view_type,
722 'poll_answer_enable_box_shadow' => $poll_answer_enable_box_shadow,
723 'poll_answer_box_shadow_color' => $poll_answer_box_shadow_color,
724 'poll_answer_box_shadow_x_offset' => $poll_answer_box_shadow_x_offset,
725 'poll_answer_box_shadow_y_offset' => $poll_answer_box_shadow_y_offset,
726 'poll_answer_box_shadow_z_offset' => $poll_answer_box_shadow_z_offset,
727 'title_bg_color' => $title_bg_color, //aray
728 'poll_title_font_size' => $poll_title_font_size,
729 'poll_title_font_size_mobile' => $poll_title_font_size_mobile,
730 'icon_size' => $icon_size,
731 'width' => $width,
732 'width_for_mobile' => $width_for_mobile,
733 "poll_min_height" => $poll_min_height,
734 'border_style' => $border_style,
735 'border_radius' => $border_radius,
736 'border_width' => $border_width,
737 "border_color" => $poll_border_color,
738 'enable_box_shadow' => $enable_box_shadow,
739 'box_shadow_color' => $box_shadow_color,
740 "poll_box_shadow_x_offset" => $poll_box_shadow_x_offset,
741 "poll_box_shadow_y_offset" => $poll_box_shadow_y_offset,
742 "poll_box_shadow_z_offset" => $poll_box_shadow_z_offset,
743 'enable_background_gradient' => $enable_background_gradient,
744 'background_gradient_color_1' => $background_gradient_color_1,
745 'background_gradient_color_2' => $background_gradient_color_2,
746 'poll_gradient_direction' => $poll_gradient_direction,
747 'poll_question_size_pc' => $poll_question_font_size_pc,
748 'poll_question_size_mobile' => $poll_question_font_size_mobile,
749 'poll_question_image_height' => $poll_question_image_height,
750 'poll_question_image_object_fit' => $poll_question_image_object_fit,
751 'poll_mobile_max_width' => $poll_mobile_max_width,
752 'poll_buttons_size' => $poll_buttons_size,
753 'poll_buttons_font_size' => $poll_buttons_font_size,
754 'poll_buttons_mobile_font_size' => $poll_buttons_mobile_font_size,
755 'poll_buttons_left_right_padding' => $poll_buttons_left_right_padding,
756 'poll_buttons_top_bottom_padding' => $poll_buttons_top_bottom_padding,
757 'poll_buttons_border_radius' => $poll_buttons_border_radius,
758 'poll_buttons_width' => $poll_buttons_width,
759 'poll_buttons_mobile_width' => $poll_buttons_mobile_width,
760 "disable_answer_hover" => $disable_answer_hover,
761 "logo_image" => $poll_logo_image,
762 'poll_enable_logo_url' => $poll_logo_image_url_check,
763 'poll_logo_title' => $poll_logo_title,
764 'poll_logo_url' => $poll_logo_image_url,
765 "custom_class" => $custom_class,
766 "enable_poll_title_text_shadow" => $enable_poll_title_text_shadow,
767 "poll_title_text_shadow" => $poll_title_text_shadow,
768 "poll_title_text_shadow_x_offset" => $poll_title_text_shadow_x_offset,
769 "poll_title_text_shadow_y_offset" => $poll_title_text_shadow_y_offset,
770 "poll_title_text_shadow_z_offset" => $poll_title_text_shadow_z_offset,
771
772 // Settings tab start
773 "poll_allow_multivote" => $poll_allow_multivote,
774 "multivote_answer_min_count" => $multivote_answer_min_count,
775 "poll_allow_multivote_count" => $poll_multivote_answer_count,
776 'poll_direction' => $poll_direction,
777 'show_create_date' => $show_create_date,
778 'show_author' => $show_author,
779 'active_date_check' => $active_date_check,
780 'activeInterval' => $activeInterval,
781 'activeIntervalSec' => $activeIntervalSec,
782 'deactiveInterval' => $deactiveInterval,
783 'deactiveIntervalSec' => $deactiveIntervalSec,
784 'ays_poll_show_timer' => $ays_poll_show_timer,
785 'show_bottom_timer' => $show_bottom_timer,
786 'ays_show_timer_type' => $ays_show_timer_type,
787 'show_result_btn_see_schedule' => $ays_show_result_btn_see,
788 'active_date_message_soon' => $active_date_message_soon,
789 'active_date_message' => $active_date_message,
790 'show_result_btn_schedule' => $show_result_btn_schedule,
791 "dont_show_poll_cont" => $poll_show_container,
792 'allow_not_vote' => $allow_not_vote,
793 'see_res_btn_text' => $see_res_btn_text,
794 'enable_pass_count' => $enable_pass_count,
795 'redirect_users' => $redirect_users,
796 'redirect_after_vote_url' => $redirect_after_vote_url,
797 'redirection_delay' => $limit_users_delay,
798 'randomize_answers' => $randomize_answers,
799 'enable_asnwers_sound' => $enable_asnwers_sound,
800 "poll_vote_reason" => $poll_vote_reason,
801 'enable_vote_btn' => $enable_vote_btn,
802 'btn_text' => $btn_text,
803 "enable_view_more_button" => $enable_view_more_button,
804 "poll_view_more_button_count" => $poll_view_more_button_count,
805 "answer_sort_type" => $poll_answer_ordering,
806 "show_answers_numbering" => $show_answers_numbering,
807 "show_votes_before_voting" => $show_votes_before_voting,
808 "show_votes_before_voting_by" => $show_votes_before_voting_by,
809 // Settings tab end
810 'hide_results' => $hide_results,
811 'hide_result_message' => $hide_result_message,
812 'hide_results_text' => $hide_results_text,
813 'result_message' => $ays_result_message,
814 'show_social' => $show_social,
815 'poll_social_buttons_heading' => $poll_social_buttons_heading,
816 'poll_show_social_ln' => $poll_show_social_ln,
817 'poll_show_social_fb' => $poll_show_social_fb,
818 'poll_show_social_tr' => $poll_show_social_tr,
819 'poll_show_social_vk' => $poll_show_social_vk,
820 'load_effect' => $load_effect,
821 'load_gif' => $load_gif,
822 'limit_users' => $limit_users,
823 'limit_users_method' => $limit_users_method,
824 'limitation_message' => $limit_users_msg,
825 'redirect_url' => $limit_users_url,
826 'user_role' => $limit_users_role,
827 'enable_restriction_pass' => $limit_users_role_enable,
828 'restriction_pass_message' => $limit_users_role_msg,
829 'enable_logged_users' => $limit_users_logged_enable,
830 'enable_logged_users_message' => $limit_users_logged_msg,
831 'notify_email_on' => $notify_on,
832 'notify_email' => $notify_email,
833 'result_sort_type' => $result_sort_type,
834 'create_date' => $changed_creation_date,
835 'author' => $author,
836 'poll_main_url' => $poll_main_url,
837 'redirect_after_vote_delay' => $redirect_after_vote_delay,
838 'published' => $published,
839 'enable_restart_button' => $enable_restart_button,
840 'show_votes_count' => $show_votes_count,
841 'show_res_percent' => $show_res_percent,
842 'show_login_form' => $show_login_form,
843 'info_form' => $info_form,
844 'fields' => $form_fields,
845 "answers_grid_column_mobile" => $answers_grid_column_mobile,
846 'required_fields' => $form_required_fields,
847 'info_form_title' => $info_form_title,
848 'enable_mailchimp' => $enable_mailchimp,
849 'redirect_after_submit' => $redirect_after_submit,
850 'mailchimp_list' => $mailchimp_list,
851 "users_role" => json_encode($limit_users_role),
852 "poll_bg_image_position" => $poll_bg_image_position,
853 "poll_bg_img_in_finish_page" => $poll_bg_img_in_finish_page,
854 'ays_add_post_for_poll' => $ays_add_post_for_poll,
855 "result_in_rgba" => $result_in_rgba,
856 "show_passed_users" => $poll_show_passed_users,
857 "see_result_button" => $poll_see_result_button,
858 "see_result_radio" => $poll_see_result_radio,
859 "loader_font_size" => $poll_loader_font_size,
860 "effect_message" => $poll_effect_message,
861
862 "poll_allow_collecting_users_data" => $poll_allow_collecting_users_data,
863 'poll_every_answer_redirect_delay' => $poll_every_answer_redirect_delay,
864 'poll_enable_answer_image_after_voting' => $poll_enable_answer_image_after_voting,
865 'poll_enable_answer_redirect_delay' => $poll_enable_every_answer_redirect_delay,
866 'poll_show_passed_users_count' => $poll_show_passed_users_count,
867 'poll_allow_answer' => $poll_allow_answer,
868 'poll_allow_answer_require' => $poll_allow_answer_require,
869 'poll_answer_image_height' => $poll_answer_image_height,
870 'poll_answer_image_height_for_mobile' => $poll_answer_image_height_for_mobile,
871 'poll_answer_image_border_radius' => $poll_answer_image_border_radius,
872 'poll_title_alignment' => $poll_title_alignment,
873 'poll_title_alignment_mobile' => $poll_title_alignment_mobile,
874 // Text type options
875 'poll_text_type_length_enable' => $poll_text_type_length_enable,
876 'poll_text_type_limit_type' => $poll_text_type_limit_type,
877 'poll_text_type_limit_length' => $poll_text_type_limit_length,
878 'poll_text_type_limit_message' => $poll_text_type_limit_message,
879 'poll_text_type_placeholder' => $poll_text_type_placeholder,
880 'poll_text_type_width' => $poll_text_type_width,
881 'poll_text_type_width_type' => $poll_text_type_width_type,
882
883 'poll_enable_password' => $poll_enable_password,
884 'poll_password' => $poll_password,
885 'poll_enable_password_visibility' => $poll_enable_password_visibility,
886 'poll_password_message' => $poll_password_message,
887 'display_fields_labels' => $display_fields_labels,
888 'autofill_user_data' => $autofill_user_data,
889 'poll_create_author' => $poll_create_author,
890 'poll_logo_url_new_tab' => $poll_logo_url_new_tab,
891 'enable_social_links' => $enable_social_links,
892 'poll_social_links_heading' => $poll_social_links_heading,
893 'social_links' => $social_links,
894 'show_chart_type' => $show_chart_type,
895 'show_chart_type_google_height' => $show_chart_type_google_height,
896 ));
897
898 $poll_answers_img = array();
899 $answers = array();
900 switch ( $type ) {
901 case 'choosing':
902 $view_type = isset( $data['ays_poll_choose_answer_type'] ) ? sanitize_text_field($data['ays_poll_choose_answer_type'] ) : "list";
903 $poll_answers_img = isset($data['ays-poll-answers-images']) && !empty($data['ays-poll-answers-images']) ? $data['ays-poll-answers-images'] : $poll_answers_img;
904 $answers = isset($data['ays-poll-answers']) && !empty($data['ays-poll-answers']) ? $data['ays-poll-answers'] : array();
905 $answers_ids = $data['ays-poll-answers-ids'];
906 $answers_url = $data['ays_submit_redirect_url'];
907 $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);
908 break;
909 case 'voting':
910 $view_type = isset($data['ays-poll-vote-type']) ? sanitize_text_field($data['ays-poll-vote-type']) : "";
911 $answers = array(1, -1);
912 $answers_show_added = array(1,1);
913 break;
914 case 'rating':
915 $view_type = isset($data['ays-poll-rate-type']) ? sanitize_text_field($data['ays-poll-rate-type']) : "";
916 $rate_value = $data['ays-poll-rate-value'];
917 $answers = range(1, $rate_value);
918 $answers_show_added = array(1,1);
919 break;
920 case 'text':
921 $view_type = isset($data['ays_poll_text_type']) ? sanitize_text_field($data['ays_poll_text_type']) : "";
922 break;
923 default:
924 # code...
925 break;
926 }
927 if (0 == $id) {
928 $poll_result = $wpdb->insert(
929 $poll_table,
930 array(
931 'title' => $title,
932 'description' => $description,
933 'type' => $type,
934 'question' => $question,
935 'view_type' => $view_type,
936 'categories' => $categories,
937 'image' => $image,
938 'show_title' => $show_title,
939 'styles' => $styles,
940 'custom_css' => $css,
941 'theme_id' => $theme_id,
942 ),
943 array(
944 '%s',
945 '%s',
946 '%s',
947 '%s',
948 '%s',
949 '%s',
950 '%s',
951 '%d',
952 '%s',
953 '%s',
954 '%d',
955 )
956 );
957 $last_id = $wpdb->insert_id;
958 $answer_count = isset($answers) && is_array($answers) ? count($answers) : 0;
959 $empty_answers_count = 0;
960 $not_empty_answers_count = 0;
961 foreach ( $answers as $k => $answer ) {
962 if (empty($answer)) {
963 $empty_answers_count++;
964 continue;
965 }
966 else{
967 $not_empty_answers_count++;
968 }
969
970 $wpdb->insert(
971 $answer_table,
972 array(
973 'poll_id' => $last_id,
974 'answer' => wp_filter_kses($answer),
975 'redirect' => isset($answers_url[$k]) && $answers_url[$k] != "" ? sanitize_url($answers_url[$k]) : "",
976 'ordering' => ($k + 1),
977 'show_user_added' => isset($answers_show_added[$k]) ? $answers_show_added[$k] : 1,
978 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$k])) ? wp_http_validate_url($poll_answers_img[$k]) : "",
979 ),
980 array(
981 '%d', // poll_id
982 '%s', // answer
983 '%s', // redirect
984 '%d', // ordering
985 '%d', // show_user_added
986 '%s', // Answer Image
987 )
988 );
989 }
990 if($empty_answers_count == $answer_count && $type != "text"){
991 for($i = 0 ; $i < 2 ; $i++){
992 $wpdb->insert(
993 $answer_table,
994 array(
995 'poll_id' => $last_id,
996 'answer' => "Answer ".($i+1),
997 'redirect' => isset($answers_url[$i]) && $answers_url[$i] != "" ? sanitize_url($answers_url[$i]) : "",
998 'ordering' => ($i + 1),
999 'show_user_added' => isset($answers_show_added[$i]) ? $answers_show_added[$i] : 1,
1000 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$i])) ? wp_http_validate_url($poll_answers_img[$i]) : "",
1001 ),
1002 array(
1003 '%d', // poll_id
1004 '%s', // answer
1005 '%s', // redirect
1006 '%d', // ordering
1007 '%d', // show_user_added
1008 '%s', // Answer Image
1009 )
1010 );
1011 }
1012 }
1013 if($not_empty_answers_count == 1){
1014 $wpdb->insert(
1015 $answer_table,
1016 array(
1017 'poll_id' => $last_id,
1018 'answer' => "Answer 1",
1019 'redirect' => isset($answers_url[$i]) && $answers_url[$i] != "" ? sanitize_url($answers_url[$i]) : "",
1020 'ordering' => ($i + 1),
1021 'show_user_added' => isset($answers_show_added[$i]) ? $answers_show_added[$i] : 1,
1022 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$i])) ? wp_http_validate_url($poll_answers_img[$i]) : "",
1023 ),
1024 array(
1025 '%d', // poll_id
1026 '%s', // answer
1027 '%s', // redirect
1028 '%d', // ordering
1029 '%d', // show_user_added
1030 '%s', // Answer Image
1031 )
1032 );
1033 }
1034 $message = 'created';
1035
1036 $post_type_args = array(
1037 'poll_id' => $last_id,
1038 'author_id' => !empty($poll_create_author) ? $poll_create_author : get_current_user_id(),
1039 'poll_title' => $title,
1040 );
1041
1042 $custom_post_id = Poll_Maker_Custom_Post_Type::ays_poll_add_custom_post($post_type_args);
1043
1044 } else {
1045 $poll = $this->get_poll_by_id($id);
1046 $poll_result = $wpdb->update(
1047 $poll_table,
1048 array(
1049 'title' => $title,
1050 'description' => $description,
1051 'type' => $type,
1052 'question' => $question,
1053 'view_type' => $view_type,
1054 'categories' => $categories,
1055 'image' => $image,
1056 'show_title' => $show_title,
1057 'styles' => $styles,
1058 'custom_css' => $css,
1059 'theme_id' => $theme_id,
1060 ),
1061 array('id' => $id),
1062 array(
1063 '%s', // title
1064 '%s', // description
1065 '%s', // type
1066 '%s', // question
1067 '%s', // view_type
1068 '%s', // categories
1069 '%s', // image
1070 '%d', // show_title
1071 '%s', // styles
1072 '%s', // custom_css
1073 '%d', // theme_id
1074 ),
1075 array('%d')
1076 );
1077 if ($type != $poll['type']) {
1078 $reports_table = esc_sql($wpdb->prefix."ayspoll_reports");
1079 $poll_id = absint(intval($id));
1080 $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";
1081
1082 $wpdb->query(
1083 $wpdb->prepare($sql,$poll_id)
1084 );
1085
1086 $wpdb->delete(
1087 $answer_table,
1088 array('poll_id' => $id),
1089 array('%d')
1090 );
1091
1092 foreach ( $answers as $k => $answer ) {
1093 if (empty($answer)) {
1094 continue;
1095 }
1096
1097 $wpdb->insert(
1098 $answer_table,
1099 array(
1100 'poll_id' => $id,
1101 'answer' => wp_filter_kses($answer),
1102 'redirect' => isset($answers_url[$k]) && $answers_url[$k] != "" ? sanitize_url($answers_url[$k]) : "",
1103 'ordering' => ($k + 1),
1104 'show_user_added' => isset($answers_show_added[$k]) ? $answers_show_added[$k] : 1,
1105 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$k])) ? wp_http_validate_url($poll_answers_img[$k]) : "",
1106 ),
1107 array(
1108 '%d', // poll_id
1109 '%s', // answer
1110 '%s', // redirect
1111 '%d', // ordering
1112 '%d', // show_user_added
1113 '%s', // Answer Image
1114 )
1115 );
1116 }
1117 }
1118 if ('choosing' == $type && $type == $poll['type']) {
1119 foreach ( $poll['answers'] as $answer ) {
1120 $old_id = $answer['id'];
1121 $index = array_search($old_id, $answers_ids);
1122 if ($index !== false && !empty($answers[$index])) {
1123 $new_answer = isset($answers[$index]) && $answers[$index] != "" ? $answers[$index] : "";
1124 $new_url = sanitize_url($answers_url[$index]);
1125
1126 if (empty($new_url)) {
1127 $new_url = null;
1128 }
1129
1130 $wpdb->update(
1131 $answer_table,
1132 array(
1133 'answer' => wp_filter_kses($new_answer),
1134 'redirect' => $new_url,
1135 'ordering' => ($index + 1),
1136 'show_user_added' => isset($answers_show_added[$index]) ? $answers_show_added[$index] : 1,
1137 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "",
1138 ),
1139 array('id' => $old_id),
1140 array(
1141 '%s', // answer
1142 '%s', // redirect
1143 '%d', // ordering
1144 '%d', // show_user_added
1145 '%s', // Answer Image
1146 ),
1147 array('%d')
1148 );
1149 } else {
1150 $report_table = esc_sql($wpdb->prefix."ayspoll_reports");
1151 $wpdb->delete(
1152 $report_table,
1153 array('answer_id' => $old_id),
1154 array('%d')
1155 );
1156 $wpdb->delete(
1157 $answer_table,
1158 array('id' => $old_id),
1159 array('%d')
1160 );
1161 }
1162 }
1163 $e_answer_count = 0;
1164 $full_answer_count = 0;
1165 $answer_ids_count = count($answers);
1166 foreach ( $answers_ids as $index => $value ) {
1167 if (empty($answers[$index])) {
1168 $e_answer_count++;
1169 }
1170 else{
1171 $full_answer_count++;
1172 }
1173 if (0 == $value) {
1174 if (empty($answers[$index])) {
1175 continue;
1176 }
1177
1178 $wpdb->insert(
1179 $answer_table,
1180 array(
1181 'poll_id' => $id,
1182 'answer' => wp_filter_kses($answers[$index]),
1183 'redirect' => isset($answers_url[$index]) && $answers_url[$index] != "" ? sanitize_url($answers_url[$index]) : null,
1184 'ordering' => ($index + 1),
1185 'show_user_added' => isset($answers_show_added[$index]) ? $answers_show_added[$index] : 1,
1186 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "",
1187 ),
1188 array(
1189 '%d', // poll_id
1190 '%s', // answer
1191 '%s', // redirect
1192 '%d', // ordering
1193 '%d', // show_user_added
1194 '%s', // Answer Image
1195 )
1196 );
1197 }
1198
1199 }
1200 if($e_answer_count == $answer_ids_count){
1201 for($j = 0 ; $j < 2 ; $j++){
1202 $wpdb->insert(
1203 $answer_table,
1204 array(
1205 'poll_id' => $id,
1206 'answer' => "Answer ".($j+1),
1207 'redirect' => isset($answers_url[$j]) && isset($answers_url[$j]) != "" ? sanitize_url($answers_url[$j]) : null,
1208 'ordering' => ($j + 1),
1209 'show_user_added' => isset($answers_show_added[$index]) ? $answers_show_added[$index] : 1,
1210 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "",
1211 ),
1212 array(
1213 '%d', // poll_id
1214 '%s', // answer
1215 '%s', // redirect
1216 '%d', // ordering
1217 '%d', // show_user_added
1218 '%s', // Answer Image
1219 )
1220 );
1221 }
1222 }
1223 if($full_answer_count == 1){
1224 $wpdb->insert(
1225 $answer_table,
1226 array(
1227 'poll_id' => $id,
1228 'answer' => "Answer 1",
1229 'redirect' => isset($answers_url[$j]) && isset($answers_url[$j]) != "" ? sanitize_url($answers_url[$j]) : null,
1230 'ordering' => 1,
1231 'show_user_added' => isset($answers_show_added[$j]) ? $answers_show_added[$j] : 1,
1232 'answer_img' => ($type == 'choosing' && isset($poll_answers_img[$index])) ? wp_http_validate_url($poll_answers_img[$index]) : "",
1233 ),
1234 array(
1235 '%d', // poll_id
1236 '%s', // answer
1237 '%s', // redirect
1238 '%d', // ordering
1239 '%d', // show_user_added
1240 '%s', // Answer Image
1241 )
1242 );
1243 }
1244 }
1245 if ($type == 'rating' && $poll['type'] == 'rating' && count($poll['answers']) != $rate_value) {
1246 if (count($poll['answers']) > $rate_value) {
1247 for ( $i = intval($rate_value); $i < count($poll['answers']); $i++ ) {
1248 $wpdb->delete(
1249 "{$wpdb->prefix}ayspoll_reports",
1250 array('answer_id' => $poll['answers'][$i]['id']),
1251 array('%d')
1252 );
1253 $wpdb->delete(
1254 $answer_table,
1255 array('id' => $poll['answers'][$i]['id']),
1256 array('%d')
1257 );
1258 }
1259 } else {
1260 for ( $i = count($poll['answers']); $i < $rate_value; $i++ ) {
1261 $wpdb->insert(
1262 $answer_table,
1263 array(
1264 'poll_id' => $id,
1265 'ordering'=> wp_filter_kses($answers[$i]),
1266 'answer' => wp_filter_kses($answers[$i]),
1267 ),
1268 array('%d', '%s')
1269 );
1270 }
1271 }
1272 }
1273 $message = 'updated';
1274 }
1275
1276 $add_post_for_poll = (isset($data['ays_add_post_for_poll']) && $data['ays_add_post_for_poll'] == 'on') ? 'on' : 'off';
1277 $add_postcat_for_poll = isset($data['ays_add_postcat_for_poll']) ? $data['ays_add_postcat_for_poll'] : array();
1278 $poll_post_id = ($id == 0) ? $last_id : $id;
1279
1280 if($add_post_for_poll == "on"){
1281 global $user_ID;
1282 $post_content = '[ays_poll id="'.$poll_post_id.'"]';
1283
1284 if ( Poll_Maker_Ays_Admin::is_active_gutenberg() ) {
1285 $post_content = '<!-- wp:poll-maker/poll {"metaFieldValue":'.$poll_post_id.',"shortcode":"[ays_poll id='.$poll_post_id.']"} -->
1286 <div class="wp-block-poll-maker-poll">[ays_poll id="'.$poll_post_id.'"]</div>
1287 <!-- /wp:poll-maker/poll -->';
1288 }
1289
1290 $new_post = array(
1291 'post_title' => $title,
1292 'post_content' => $post_content,
1293 'post_status' => 'publish',
1294 'post_date' => current_time( 'mysql' ),
1295 'post_author' => $user_ID,
1296 'post_type' => 'post',
1297 'post_category' => $add_postcat_for_poll
1298 );
1299 $post_id = wp_insert_post($new_post);
1300 if(! empty($image)){
1301 $sql = "SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'attachment' AND guid = '".$image."'";
1302 $attachment_id = intval($wpdb->get_var($sql));
1303 if($attachment_id !== 0){
1304 $featured_image = set_post_thumbnail($post_id, $attachment_id);
1305 }
1306 }
1307 $poll_post_result = $wpdb->update(
1308 $poll_table,
1309 array( 'post_id' => $post_id ),
1310 array( 'id' => $poll_post_id ),
1311 array( '%d' ),
1312 array( '%d' )
1313 );
1314 }
1315
1316 $active_tabs = !empty($data['ays_poll_active_tab']) ? sanitize_text_field($data['ays_poll_active_tab']) : "General";
1317 $active_tab = urlencode($active_tabs);
1318
1319 if ($poll_result >= 0) {
1320 if($message == 'created'){
1321 setcookie('ays_poll_created_new', $last_id, time() + 3600, '/');
1322 if(!empty($custom_post_id)){
1323 $custom_post_url = array(
1324 'post_type' => 'ays-poll-maker',
1325 'p' => $custom_post_id,
1326 'preview' => 'true',
1327 );
1328 $custom_post_url_ready = http_build_query($custom_post_url);
1329 $ready_url = get_home_url();
1330 $ready_url .= '/?' . $custom_post_url_ready;
1331 setcookie('ays_poll_created_new_'.$last_id.'_post_id', $ready_url, time() + 3600, '/');
1332 }
1333
1334 }
1335 }
1336
1337 if ($poll_result >= 0) {
1338 if ('' != $ays_change_type) {
1339 if($id == 0){
1340 $url = esc_url_raw( add_query_arg( array(
1341 "action" => "edit",
1342 "poll" => $last_id,
1343 "active-tab" => $active_tab,
1344 "status" => $message
1345 ) ) );
1346 }else{
1347 $url = esc_url_raw( remove_query_arg(false) ) . '&active-tab='.$active_tab.'&status=' . $message;
1348 }
1349 wp_redirect($url);
1350 } else {
1351 $url = esc_url_raw(remove_query_arg(['action'])) . "&active-tab=".$active_tab."&status=" . $message;
1352 wp_redirect($url);
1353 }
1354 }
1355 }
1356 $allowedtags = $old_allowedtags;
1357 }
1358
1359 public function duplicate_poll( $id ) {
1360 global $wpdb;
1361
1362 // Nonce verification for CSRF protection
1363 if (!isset($_GET['_wpnonce']) && !wp_verify_nonce($_GET['_wpnonce'], $this->plugin_name . '-duplicate-poll')) {
1364 wp_die( esc_html__('Security check error. Try again.', "poll-maker"));
1365 }
1366
1367 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
1368 $answers_table = esc_sql($wpdb->prefix."ayspoll_answers");
1369
1370 $duplicate = $this->get_poll_by_id($id, false);
1371 if (empty($duplicate)) {
1372 $url = esc_url_raw(remove_query_arg(array('action', 'poll'))) . '&status=failed';
1373 wp_redirect($url);
1374 exit;
1375 }
1376
1377 $user_id = get_current_user_id();
1378 $user = get_userdata($user_id);
1379 $author = array(
1380 'id' => $user->ID,
1381 'name' => $user->data->display_name
1382 );
1383 $options = json_decode($duplicate['styles'], true);
1384
1385 $options['create_date'] = current_time( 'mysql' );
1386 $options['author'] = $author;
1387
1388 $options['ays_add_post_for_poll'] = 'off';
1389
1390 $answers = $duplicate['answers'];
1391 unset($duplicate['answers']);
1392 unset($duplicate['id']);
1393 $duplicate['title'] = "Copy - " . $duplicate['title'];
1394 $duplicate['styles'] = json_encode($options);
1395 $result = $wpdb->insert(
1396 $poll_table,
1397 $duplicate,
1398 array(
1399 '%d', // post_id
1400 '%s', // title
1401 '%s', // description
1402 '%s', // question
1403 '%s', // type
1404 '%s', // view_type
1405 '%s', // categories
1406 '%s', // image
1407 '%s', // show_title
1408 '%s', // styles
1409 '%s', // custom_css
1410 '%d', // theme_id
1411 )
1412 );
1413
1414 $poll_id = $wpdb->insert_id;
1415 $answers_results = array();
1416 $flag = true;
1417
1418 foreach ( $answers as $answer ) {
1419 $answer['poll_id'] = $poll_id;
1420 unset($answer['id']);
1421 unset($answer['votes']);
1422 $answers_results[] = $wpdb->insert(
1423 $answers_table,
1424 $answer,
1425 array(
1426 '%s',
1427 '%s',
1428 '%s',
1429 )
1430 );
1431 }
1432
1433 foreach ( $answers_results as $answers_result ) {
1434 if ($answers_result >= 0) {
1435 $flag = true;
1436 } else {
1437 $flag = false;
1438 break;
1439 }
1440 }
1441 $message = 'duplicated';
1442 if ($result >= 0 && $flag == true) {
1443
1444 $post_type_args = array(
1445 'poll_id' => $poll_id,
1446 'author_id' => !empty($user->ID) ? $user->ID : $user_id,
1447 'poll_title' => "Copy - ".$duplicate['title'],
1448 );
1449
1450 $custom_post_id = Poll_Maker_Custom_Post_Type::ays_poll_add_custom_post($post_type_args);
1451
1452 $url = esc_url_raw(remove_query_arg(array('action', 'poll'))) . '&status=' . $message;
1453 wp_redirect($url);
1454 exit;
1455 }
1456
1457 }
1458
1459 public static function get_poll_pass_count($id) {
1460 global $wpdb;
1461 $poll_id = absint(sanitize_text_field($id));
1462 $args_id = esc_sql($poll_id);
1463 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
1464 $sql = "SELECT SUM(votes) FROM ".$answ_table." WHERE poll_id=%d";
1465 $result = $wpdb->get_var(
1466 $wpdb->prepare( $sql, $args_id)
1467 );
1468
1469 return $result;
1470 }
1471
1472 public function get_poll_by_id( $id, $decode = true ) {
1473 global $wpdb;
1474 $poll_id = absint(sanitize_text_field($id));
1475 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
1476 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
1477 $sql = "SELECT * FROM ".$poll_table." WHERE id=%d";
1478 $poll = $wpdb->get_row(
1479 $wpdb->prepare( $sql, $poll_id),
1480 'ARRAY_A'
1481 );
1482
1483 if (empty($poll)) {
1484 return array();
1485 }
1486
1487 $sql_answ = "SELECT * FROM ".$answ_table." WHERE poll_id=%d ORDER BY ordering ASC, id ASC";
1488 $poll['answers'] = $wpdb->get_results(
1489 $wpdb->prepare( $sql_answ, $poll_id),
1490 'ARRAY_A'
1491 );
1492
1493 if ($decode) {
1494 $cats = explode(',', $poll['categories']);
1495 $poll['categories'] = !empty($cats) ? $cats : array();
1496 $json = $poll['styles'];
1497 $poll['styles'] = json_decode($json, true);
1498 }
1499
1500 return $poll;
1501 }
1502
1503 /** Text displayed when no customer data is available */
1504 public function no_items() {
1505 _e('There are no polls yet.', "poll-maker");
1506 }
1507
1508 /**
1509 * Render a column when no column specific method exist.
1510 *
1511 * @param array $item
1512 * @param string $column_name
1513 *
1514 * @return mixed
1515 */
1516 public function column_default( $item, $column_name ) {
1517 switch ( $column_name ) {
1518 case 'title':
1519 case 'poll_image':
1520 case 'categories':
1521 case 'type':
1522 case 'shortcode':
1523 case 'code_include':
1524 case 'results':
1525 case 'create_date':
1526 case 'completed_count':
1527 case 'id':
1528 case 'publish':
1529 return $item[$column_name];
1530 break;
1531 default:
1532 return print_r($item, true); //Show the whole array for troubleshooting purposes
1533 }
1534 }
1535
1536 /**
1537 * Render the bulk edit checkbox
1538 *
1539 * @param array $item
1540 *
1541 * @return string
1542 */
1543 function column_cb( $item ) {
1544 return sprintf(
1545 '<input type="checkbox" name="bulk-delete[]" value="%s" />',
1546 $item['id']
1547 );
1548 }
1549
1550 /**
1551 * Method for name column
1552 *
1553 * @param array $item an array of DB data
1554 *
1555 * @return string
1556 */
1557 function column_title( $item ) {
1558 $delete_nonce = wp_create_nonce($this->plugin_name . '-delete-poll');
1559 $duplicate_nonce = wp_create_nonce($this->plugin_name . '-duplicate-poll');
1560
1561 $poll_title = stripcslashes($item['title']);
1562
1563 $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;
1564
1565 $p = esc_attr($poll_title);
1566 $polls_title_length = intval( $this->title_length );
1567
1568 $restitle = Poll_Maker_Ays_Admin::ays_restriction_string("word", $poll_title, $polls_title_length);
1569
1570 $title = sprintf('<a href="?page=%s&action=%s&poll=%d" title="%s">%s</a>', esc_attr($_REQUEST['page']), 'edit', absint($item['id']), $p, $restitle);
1571
1572 $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'] ) );
1573
1574 $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);
1575
1576 $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 );
1577
1578 if($custom_post_id > 0){
1579 $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) ) ));
1580 }
1581
1582 $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 );
1583
1584
1585 return $title . $this->row_actions($actions);
1586 }
1587
1588 function column_shortcode( $item ) {
1589 $shortcode_content = '<div class="ays-poll-shortcode-container">
1590 <div class="ays-poll-copy-image" data-toggle="tooltip" aria-label="' . __( 'Click to copy', "poll-maker" ) . '" data-original-title="' . __( 'Click to copy', "poll-maker" ) . '">
1591 <img src="' . esc_url(POLL_MAKER_AYS_ADMIN_URL) . '/images/icons/edit-shortcode.svg">
1592 </div>';
1593
1594 $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"]);
1595
1596 $shortcode_content .= $shortcode_input;
1597 $shortcode_content .= '</div>';
1598
1599 return $shortcode_content;
1600 }
1601
1602 function column_code_include( $item ) {
1603 return sprintf('<input type="text" onClick="this.setSelectionRange(0, this.value.length)" readonly value="<?php echo do_shortcode(\'[ays_poll id=%s]\'); ?>" />', $item["id"]);
1604 }
1605
1606 function column_results($item) {
1607 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']);
1608 }
1609
1610 function column_categories( $item ) {
1611 if ($item['categories'] == '') {
1612 return '';
1613 }
1614 global $wpdb;
1615 $cats_ids = explode(',', $item['categories']);
1616 $cat_table = esc_sql($wpdb->prefix."ayspoll_categories");
1617 $category_location = "#";
1618 foreach ( $cats_ids as $id ) {
1619 if (empty($id)) {
1620 continue;
1621 }
1622 $args_id = absint( esc_sql($id) );
1623 $sql = "SELECT * FROM ".$cat_table." WHERE id=%d";
1624
1625 $result = $wpdb->get_row(
1626 $wpdb->prepare( $sql, $args_id),
1627 'ARRAY_A'
1628 );
1629 if (empty($result)) {
1630 continue;
1631 }
1632
1633 if ( isset($result) && $result > 0 ) {
1634 $category_location = sprintf( '<span>%s</span>', $result['title']);
1635 }
1636
1637 $cats_content = $category_location;
1638 }
1639
1640 return $cats_content;
1641 }
1642
1643 function column_create_date( $item ) {
1644 $options = json_decode($item['styles'], true);
1645 $date = isset($options['create_date']) && $options['create_date'] != '' ? sanitize_text_field($options['create_date']) : current_time( 'mysql' );
1646 if(isset($options['author'])){
1647 if(is_array($options['author'])){
1648 $author = $options['author'];
1649 }else{
1650 $author = json_decode($options['author'], true);
1651 }
1652 }else{
1653 $author = array("name"=>"Unknown");
1654 }
1655 $text = "";
1656 if(Poll_Maker_Ays_Admin::validateDate($date)){
1657 $text .= "<p><b>Date:</b> ".$date."</p>";
1658 }
1659 if(isset($author['name']) && $author['name'] !== "Unknown"){
1660 $text .= "<p><b>Author:</b> ".$author['name']."</p>";
1661 }
1662 return $text;
1663 }
1664
1665 function column_completed_count( $item ) {
1666 $id = $item['id'];
1667 $passed_count = $this->get_poll_pass_count($id);
1668 $text = "<p style='text-align:center;font-size:14px;'>".$passed_count."</p>";
1669 return $text;
1670 }
1671
1672 function column_publish( $item ) {
1673 global $wpdb;
1674 $id = absint(sanitize_text_field($item['id']));
1675 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
1676 $sql = "SELECT * FROM ".$poll_table." WHERE id=%d";
1677
1678 $res = $wpdb->get_row(
1679 $wpdb->prepare( $sql, $id),
1680 'ARRAY_A'
1681 );
1682 $options = json_decode($res['styles'], true);
1683 $status = isset($options['published']) ? $options['published'] : 1;
1684
1685 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");
1686 }
1687
1688 function column_poll_image( $item ) {
1689 global $wpdb;
1690 $poll_image = (isset( $item['image'] ) && $item['image'] != '') ? esc_url( $item['image'] ) : '';
1691
1692 $image_html = array();
1693 $edit_page_url = '';
1694
1695 if($poll_image != ''){
1696
1697 if ( isset( $item['id'] ) && absint( $item['id'] ) > 0 ) {
1698 $edit_page_url = sprintf( 'href="?page=%s&action=%s&poll=%d"', esc_attr( $_REQUEST['page'] ), 'edit', absint( $item['id'] ) );
1699 }
1700
1701 $poll_image_url = $poll_image;
1702 $this_site_path = trim( get_site_url(), "https:" );
1703 if( strpos( trim( $poll_image_url, "https:" ), $this_site_path ) !== false ){
1704 $query = "SELECT * FROM `" . $wpdb->prefix . "posts` WHERE `post_type` = 'attachment' AND `guid` = '" . $poll_image_url . "'";
1705 $result_img = $wpdb->get_results( $query, "ARRAY_A" );
1706
1707 if( ! empty( $result_img ) ){
1708 $url_img = wp_get_attachment_image_src( $result_img[0]['ID'], 'thumbnail' );
1709 if( $url_img !== false ){
1710 $poll_image_url = $url_img[0];
1711 }
1712 }
1713 }
1714
1715 $image_html[] = '<div class="ays-poll-image-list-table-column">';
1716 $image_html[] = '<a '. $edit_page_url .' class="ays-poll-image-list-table-link-column">';
1717 $image_html[] = '<img src="'. $poll_image_url .'" class="ays-poll-image-list-table-img-column">';
1718 $image_html[] = '</a>';
1719 $image_html[] = '</div>';
1720 }
1721
1722 $image_html = implode('', $image_html);
1723
1724 return $image_html;
1725 }
1726
1727 /**
1728 * Associative array of columns
1729 *
1730 * @return array
1731 */
1732 function get_columns() {
1733 $columns = array(
1734 'cb' => '<input type="checkbox" />',
1735 'title' => esc_html__('Title', "poll-maker"),
1736 'poll_image' => esc_html__('Question image', "poll-maker"),
1737 'type' => esc_html__('Type', "poll-maker"),
1738 'shortcode' => esc_html__('Shortcode', "poll-maker"),
1739 'code_include' => esc_html__('Code Include', "poll-maker"),
1740 'results' => esc_html__('Results', "poll-maker"),
1741 'categories' => esc_html__('Categories', "poll-maker"),
1742 'create_date' => esc_html__('Created', "poll-maker" ),
1743 'completed_count' => esc_html__('Completed count', "poll-maker" ),
1744 'publish' => esc_html__('Status', "poll-maker"),
1745 'id' => esc_html__('ID', "poll-maker"),
1746 );
1747
1748 return $columns;
1749 }
1750
1751 /**
1752 * Columns to make sortable.
1753 *
1754 * @return array
1755 */
1756 public function get_sortable_columns() {
1757 $sortable_columns = array(
1758 'title' => array('title', true),
1759 'type' => array('type', true),
1760 'id' => array('id', true),
1761 );
1762
1763 return $sortable_columns;
1764 }
1765
1766 /**
1767 * Columns to make sortable.
1768 *
1769 * @return array
1770 */
1771 public function get_hidden_columns() {
1772 $hidden_culumns = array(
1773 'poll_image',
1774 'code_include',
1775 );
1776 return $hidden_culumns;
1777 }
1778
1779 /**
1780 * Returns an associative array containing the bulk action
1781 *
1782 * @return array
1783 */
1784 public function get_bulk_actions() {
1785 $actions = array(
1786 'bulk-delete' =>esc_html__('Delete', "poll-maker"),
1787 );
1788
1789 return $actions;
1790 }
1791
1792 /**
1793 * Handles data query and filter, sorting, and pagination.
1794 */
1795 public function prepare_items() {
1796 global $wpdb;
1797
1798 $this->_column_headers = $this->get_column_info();
1799
1800 /** Process bulk action */
1801 $this->process_bulk_action();
1802
1803 $per_page = $this->get_items_per_page('polls_per_page', 20);
1804 $current_page = $this->get_pagenum();
1805 $total_items = self::record_count();
1806
1807 $this->set_pagination_args(array(
1808 'total_items' => $total_items, //WE have to calculate the total number of items
1809 'per_page' => $per_page, //WE have to determine how many items to show on a page
1810 ));
1811
1812 $search = ( isset( $_REQUEST['s'] ) ) ? esc_sql( sanitize_text_field( $_REQUEST['s'] ) ) : false;
1813 $do_search = ( $search ) ? sprintf(" title LIKE '%%%s%%' ", esc_sql( $wpdb->esc_like( $search ) ) ) : '';
1814
1815 $this->items = self::get_polls($per_page, $current_page, $do_search);
1816 }
1817
1818 public function process_bulk_action() {
1819 //Detect when a bulk action is being triggered...
1820 $message = 'deleted';
1821 if ('delete' === $this->current_action()) {
1822
1823 // In our file that handles the request, verify the nonce.
1824 $nonce = esc_attr($_REQUEST['_wpnonce']);
1825
1826 if (!wp_verify_nonce($nonce, $this->plugin_name . '-delete-poll')) {
1827 die('Go get a life script kiddies');
1828 } else {
1829 self::delete_polls(absint($_GET['poll']));
1830
1831 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
1832 // add_query_arg() return the current url
1833
1834 $url = esc_url_raw(remove_query_arg(['action', 'poll', '_wpnonce'])) . '&status=' . $message;
1835 wp_redirect($url);
1836 }
1837 }
1838
1839 // If the delete bulk action is triggered
1840 if ((isset($_POST['action']) && 'bulk-delete' == $_POST['action'])
1841 || (isset($_POST['action2']) && 'bulk-delete' == $_POST['action2'])
1842 ) {
1843
1844 $delete_ids = ( isset( $_POST['bulk-delete'] ) && ! empty( $_POST['bulk-delete'] ) ) ? esc_sql( $_POST['bulk-delete'] ) : array();
1845
1846 // loop over the array of record IDs and delete them
1847 $deleted_polls_count = 0;
1848 foreach ( $delete_ids as $id ) {
1849 $deleted_polls_count++;
1850 self::delete_polls($id);
1851 }
1852
1853 // esc_url_raw() is used to prevent converting ampersand in url to "#038;"
1854 // add_query_arg() return the current url
1855
1856 $url = esc_url_raw(remove_query_arg(['action', 'poll', '_wpnonce'])) . '&status=' . $message . '&d_count=' .$deleted_polls_count;
1857 wp_redirect($url);
1858 }
1859 }
1860
1861 /**
1862 * Delete a customer record.
1863 *
1864 * @param int $id customer ID
1865 */
1866 public static function delete_polls( $id ) {
1867 global $wpdb;
1868 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
1869 $answ_table = esc_sql($wpdb->prefix . "ayspoll_answers");
1870 $reports_table = esc_sql($wpdb->prefix . "ayspoll_reports");
1871 $wpdb->delete(
1872 $poll_table,
1873 array('id' => $id),
1874 array('%d')
1875 );
1876 $wpdb->delete(
1877 $answ_table,
1878 array('poll_id' => $id),
1879 array('%d')
1880 );
1881 $sql = "DELETE FROM ".$reports_table."
1882 WHERE answer_id NOT IN (SELECT id FROM ".$answ_table.")";
1883 $wpdb->query($sql);
1884 }
1885
1886 /**
1887 * Returns the count of records in the database.
1888 *
1889 * @return null|string
1890 */
1891 public static function record_count() {
1892 global $wpdb;
1893 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
1894 $sql = "SELECT COUNT(*) FROM ".$poll_table;
1895 $sql_count = self::get_where_condition();
1896 if(isset($sql_count) && !empty($sql_count)){
1897 $sql .= $sql_count;
1898 }
1899 return $wpdb->get_var($sql);
1900 }
1901
1902 public static function all_record_count() {
1903 global $wpdb;
1904
1905 $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}ayspoll_polls";
1906
1907 if (isset($_GET['filterby']) && absint(intval($_GET['filterby'])) > 0) {
1908 $cat_id = absint(intval($_GET['filterby']));
1909 if (isset($_SERVER['HTTP_HOST']) && sanitize_text_field($_SERVER['HTTP_HOST']) == "playground.wordpress.net") {
1910 $sql .= " WHERE categories LIKE '%," . $cat_id . ",%' OR categories LIKE '" . $cat_id . ",%' OR categories LIKE '%," . $cat_id . "' OR categories = '" . $cat_id . "'";
1911 } else {
1912 $sql .= " WHERE FIND_IN_SET('{$cat_id}', categories) > 0";
1913 }
1914 }
1915
1916 return $wpdb->get_var( $sql );
1917 }
1918
1919 public static function published_polls_count() {
1920 global $wpdb;
1921
1922 // Counters
1923 $publishedCount = 0;
1924
1925 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
1926 $sql = "SELECT * FROM " . $poll_table;
1927
1928 if (isset($_GET['filterby']) && absint(intval($_GET['filterby'])) > 0) {
1929 $cat_id = absint(intval($_GET['filterby']));
1930 if (isset($_SERVER['HTTP_HOST']) && sanitize_text_field($_SERVER['HTTP_HOST']) == "playground.wordpress.net") {
1931 $sql .= " WHERE categories LIKE '%," . $cat_id . ",%' OR categories LIKE '" . $cat_id . ",%' OR categories LIKE '%," . $cat_id . "' OR categories = '" . $cat_id . "'";
1932 } else {
1933 $sql .= " WHERE FIND_IN_SET('{$cat_id}', categories) > 0";
1934 }
1935 }
1936
1937 $results = $wpdb->get_results($sql, ARRAY_A);
1938
1939 foreach ($results as $poll) {
1940 $options = json_decode($poll['styles'], true);
1941 $status = isset($options['published']) ? $options['published'] : 1;
1942
1943 if ($status == 1) {
1944 $publishedCount++;
1945 }
1946 }
1947
1948 return $publishedCount;
1949 }
1950
1951 public static function unpublished_polls_count() {
1952 global $wpdb;
1953
1954 // Counters
1955 $unpublishedCount = 0;
1956
1957 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
1958 $sql = "SELECT * FROM " . $poll_table;
1959
1960 if (isset($_GET['filterby']) && absint(intval($_GET['filterby'])) > 0) {
1961 $cat_id = absint(intval($_GET['filterby']));
1962 if (isset($_SERVER['HTTP_HOST']) && sanitize_text_field($_SERVER['HTTP_HOST']) == "playground.wordpress.net") {
1963 $sql .= " WHERE categories LIKE '%," . $cat_id . ",%' OR categories LIKE '" . $cat_id . ",%' OR categories LIKE '%," . $cat_id . "' OR categories = '" . $cat_id . "'";
1964 } else {
1965 $sql .= " WHERE FIND_IN_SET('{$cat_id}', categories) > 0";
1966 }
1967 }
1968
1969 $results = $wpdb->get_results($sql, ARRAY_A);
1970
1971 foreach ($results as $poll) {
1972 $options = json_decode($poll['styles'], true);
1973 $status = isset($options['published']) ? $options['published'] : 1;
1974
1975 if ($status == 0) {
1976 $unpublishedCount++;
1977 }
1978 }
1979
1980 return $unpublishedCount;
1981 }
1982
1983 public static function get_where_condition(){
1984 global $wpdb;
1985
1986 $where = array();
1987 $sql = '';
1988
1989 $search = ( isset( $_REQUEST['s'] ) ) ? esc_sql( sanitize_text_field( $_REQUEST['s'] ) ) : false;
1990 if( $search ){
1991 $where[] = sprintf(" title LIKE '%%%s%%' ", esc_sql( $wpdb->esc_like( $search ) ) );
1992 }
1993
1994 if(isset( $_REQUEST['filterby'] ) && $_REQUEST['filterby'] > 0 ){
1995 $cat_id = esc_sql( sanitize_text_field( $_REQUEST['filterby'] ) );
1996
1997 $where[] = sprintf(" categories LIKE('%%,%s,%%') ", esc_sql( $wpdb->esc_like( $cat_id ) ) );
1998 }
1999
2000 if( isset( $_REQUEST['fstatus'] ) && is_numeric( $_REQUEST['fstatus'] ) && ! is_null( sanitize_text_field( $_REQUEST['fstatus'] ) ) ){
2001 if( esc_sql( $_REQUEST['fstatus'] ) != '' ){
2002 $fstatus = absint( esc_sql( $_REQUEST['fstatus'] ) );
2003 $where[] = " JSON_EXTRACT(styles, '$.published') = " . ($fstatus == 1 ? '1' : '0');
2004 }
2005 }
2006
2007 if(isset( $_REQUEST['filterbyauthor'] ) && $_REQUEST['filterbyauthor'] > 0 ){
2008 $author_id = esc_sql( sanitize_text_field( $_REQUEST['filterbyauthor'] ) );
2009
2010 $where[] = sprintf(" categories LIKE('%%,%s,%%') ", esc_sql( $wpdb->esc_like( $author_id ) ) );
2011 }
2012 if(isset( $_REQUEST['filterbytype'] ) && $_REQUEST['filterbytype'] != "" ){
2013 $type = esc_sql( sanitize_text_field( $_REQUEST['filterbytype'] ) );
2014 if (isset($type) && $type != '') {
2015 $where[] = " type = '" . $type . "'";
2016 }
2017 }
2018
2019 if( !empty($where) ){
2020 $sql = " WHERE " . implode( " AND ", $where );
2021 }
2022 return $sql;
2023 }
2024
2025 /**
2026 * Retrieve customers data from the database
2027 *
2028 * @param int $per_page
2029 * @param int $page_number
2030 *
2031 * @return mixed
2032 */
2033 public static function get_polls( $per_page = 20, $page_number = 1 , $search = '') {
2034
2035 global $wpdb;
2036 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
2037 $sql = "SELECT * FROM ".$poll_table;
2038 $args = array();
2039
2040 $where = array();
2041
2042 if( $search != '' ){
2043 $where[] = $search;
2044 }
2045
2046 if(isset( $_REQUEST['filterby'] ) && $_REQUEST['filterby'] > 0 ){
2047 $cat_id = esc_sql( sanitize_text_field( $_REQUEST['filterby'] ) );
2048
2049 $where[] = sprintf(" categories LIKE('%%,%s,%%') ", esc_sql( $wpdb->esc_like( $cat_id ) ) );
2050 }
2051
2052 if ( isset( $_REQUEST['filterbyauthor'] ) && absint( $_REQUEST['filterbyauthor'] ) > 0 ) {
2053 $poll_author = absint( $_REQUEST['filterbyauthor'] );
2054 $where[] = $wpdb->prepare( "JSON_EXTRACT(styles, '$.poll_create_author') = %d", $poll_author );
2055 }
2056
2057 if(isset( $_REQUEST['filterbytype'] ) && $_REQUEST['filterbytype'] != "" ){
2058 $type = esc_sql( sanitize_text_field( $_REQUEST['filterbytype'] ) );
2059 if (isset($type) && $type != '') {
2060 $where[] = " type = '" . $type . "'";
2061 }
2062 }
2063
2064 if( isset( $_REQUEST['fstatus'] ) && is_numeric( $_REQUEST['fstatus'] ) && ! is_null( sanitize_text_field( $_REQUEST['fstatus'] ) ) ){
2065 if( esc_sql( $_REQUEST['fstatus'] ) != '' ){
2066 $fstatus = absint( esc_sql( $_REQUEST['fstatus'] ) );
2067 $where[] = " JSON_EXTRACT(styles, '$.published') = " . ($fstatus == 1 ? '1' : '0');
2068 }
2069 }
2070
2071 if( ! empty($where) ){
2072 $sql .= " WHERE " . implode( " AND ", $where );
2073 }
2074
2075 if ( ! empty( $_REQUEST['orderby'] ) ) {
2076
2077 $order_by = ( isset( $_REQUEST['orderby'] ) && sanitize_text_field( $_REQUEST['orderby'] ) != '' ) ? sanitize_text_field( $_REQUEST['orderby'] ) : 'id';
2078 $order_by .= ( ! empty( $_REQUEST['order'] ) && strtolower( $_REQUEST['order'] ) == 'asc' ) ? ' ASC' : ' DESC';
2079
2080 $sql_orderby = sanitize_sql_orderby($order_by);
2081
2082 if ( $sql_orderby ) {
2083 $sql .= ' ORDER BY ' . $sql_orderby;
2084 } else {
2085 $sql .= ' ORDER BY id DESC';
2086 }
2087 }else{
2088 $sql .= ' ORDER BY id DESC';
2089 }
2090
2091 $sql .= " LIMIT %d";
2092 $args[] = $per_page;
2093 $offset = ($page_number - 1) * $per_page;
2094 $sql .= " OFFSET %d";
2095 $args[] = $offset;
2096 $result = $wpdb->get_results(
2097 $wpdb->prepare( $sql, $args),
2098 'ARRAY_A'
2099 );
2100
2101 return $result;
2102 }
2103
2104 public function poll_notices() {
2105 $status = (isset($_REQUEST['status'])) ? sanitize_text_field($_REQUEST['status']) : '';
2106
2107 if (empty($status)) {
2108 return;
2109 }
2110
2111 if ('created' == $status) {
2112 $updated_message = esc_html( esc_html__('Poll created.', "poll-maker"));
2113 } elseif ('updated' == $status) {
2114 $updated_message = esc_html( esc_html__('Poll saved.', "poll-maker"));
2115 } elseif ('duplicated' == $status) {
2116 $updated_message = esc_html( esc_html__('Poll duplicated.', "poll-maker"));
2117 } elseif ('deleted' == $status) {
2118 $deleted_count = isset($_GET['d_count']) && $_GET['d_count'] != "" ? intval(esc_attr($_GET['d_count'])) : 0;
2119 $deleted_count_message =esc_html__('Poll deleted.', "poll-maker");
2120 if($deleted_count > 1){
2121 $deleted_count_message = $deleted_count .esc_html__(' Polls are deleted.', "poll-maker");
2122 }
2123 $updated_message = $deleted_count_message;
2124 }
2125
2126 if (empty($updated_message)) {
2127 return;
2128 }
2129
2130 ?>
2131 <div class="ays-poll-admin-notice notice notice-success is-dismissible">
2132 <p>
2133 <?php echo $updated_message; ?>
2134 </p>
2135 </div>
2136 <?php
2137 }
2138 }
2139