PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.5.1
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.5.1
6.5.1 6.5.0 6.4.9 6.4.8 6.4.7 6.4.6 6.4.5 6.4.4 6.4.3 6.4.2 6.4.1 6.4.0 6.3.9 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.6.5 All 154 releases
poll-maker / includes / lists / class-poll-maker-polls-list-table.php

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

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