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

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

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