PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 5.6.3
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v5.6.3
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 5.6.6 All 153 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 5.6.3, at includes/lists/class-poll-maker-polls-list-table.php

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