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

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

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