PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.5.1
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.5.1
6.5.1 6.5.0 6.4.9 6.4.8 6.4.7 6.4.6 6.4.5 6.4.4 6.4.3 6.4.2 6.4.1 6.4.0 6.3.9 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.6.5 All 154 releases
← All changes | public/class-poll-maker-ays-public.php +336 -85 6.3.5 → 6.5.1 View file →
@@ -79,8 +79,9 @@
79 79 $this->settings = new Poll_Maker_Settings_Actions($this->plugin_name);
80 80 add_shortcode('ays_poll_all', array($this, 'ays_poll_all_generate_shortcode'));
81 81 add_shortcode('ayspoll_results', array($this, 'ays_poll_results_generate_shortcode'));
82 82 add_shortcode('ays_display_polls', array($this, 'ays_generate_display_polls_method'));
83 + add_shortcode('ays_poll_cat', array($this, 'ays_poll_generate_categories_method'));
83 84 }
84 85
85 86 /**
86 87 * Get instance of this class. Singleton pattern.
@@ -186,20 +187,21 @@
186 187 wp_enqueue_script($this->plugin_name.'-category', plugin_dir_url(__FILE__) . 'js/poll-maker-public-category.js', array('jquery'), $this->version, false);
187 188 wp_enqueue_script( $this->plugin_name . '-autosize', plugin_dir_url(__FILE__) . 'js/poll-maker-autosize.js', array( 'jquery' ), $this->version, false );
188 189 wp_localize_script($this->plugin_name . '-ajax-public', 'poll_maker_ajax_public',
189 190 array(
190 - 'ajax_url' => admin_url('admin-ajax.php'),
191 - 'alreadyVoted' =>esc_html__( "You have already voted" , "poll-maker" ),
192 - 'day' =>esc_html__( 'day', "poll-maker" ),
193 - 'days' =>esc_html__( 'days', "poll-maker" ),
194 - 'hour' =>esc_html__( 'hour', "poll-maker" ),
195 - 'hours' =>esc_html__( 'hours', "poll-maker" ),
196 - 'minute' =>esc_html__( 'minute', "poll-maker" ),
197 - 'minutes' =>esc_html__( 'minutes', "poll-maker" ),
198 - 'second' =>esc_html__( 'second', "poll-maker" ),
199 - 'seconds' =>esc_html__( 'seconds', "poll-maker" ),
200 - 'thank_message' =>esc_html__( 'Your answer has been successfully sent to the admin. Please wait for the approval.', "poll-maker" ),
201 - 'restart' =>esc_html__( 'Restart', "poll-maker" ),
191 + 'ajax_url' => admin_url('admin-ajax.php'),
192 + 'nonce' => wp_create_nonce('ays_poll_nonce'),
193 + 'alreadyVoted' =>esc_html__( "You have already voted" , "poll-maker" ),
194 + 'day' =>esc_html__( 'day', "poll-maker" ),
195 + 'days' =>esc_html__( 'days', "poll-maker" ),
196 + 'hour' =>esc_html__( 'hour', "poll-maker" ),
197 + 'hours' =>esc_html__( 'hours', "poll-maker" ),
198 + 'minute' =>esc_html__( 'minute', "poll-maker" ),
199 + 'minutes' =>esc_html__( 'minutes', "poll-maker" ),
200 + 'second' =>esc_html__( 'second', "poll-maker" ),
201 + 'seconds' =>esc_html__( 'seconds', "poll-maker" ),
202 + 'thank_message' =>esc_html__( 'Your answer has been successfully sent to the admin. Please wait for the approval.', "poll-maker" ),
203 + 'restart' =>esc_html__( 'Restart', "poll-maker" ),
202 204 )
203 205 );
204 206 }
205 207
@@ -204,13 +206,131 @@
204 206 }
205 207
206 208 public function show_chart_js() {
207 209 wp_enqueue_script( $this->plugin_name . '-charts-google', plugin_dir_url(__FILE__) . 'js/google-chart.js', array('jquery'), $this->version, true);
210 + }
211 +
212 + // Categories shortcode
213 + public function ays_poll_generate_categories_method($attr) {
214 + ob_start();
215 + global $wpdb;
216 + $id = (isset($attr['id'])) ? absint(intval($attr['id'])) : null;
217 +
218 + if (is_null($id)) {
219 + echo "<p class='wrong_shortcode_text' style='color:red;'>" . __('Wrong shortcode initialized', 'poll-maker') . "</p>";
220 + return false;
221 + }
222 +
223 + $display = ( isset($attr['display']) && $attr['display'] != '' ) ? $attr['display'] : 'all';
224 + $layout = ( isset($attr['layout']) && $attr['layout'] != '' ) ? $attr['layout'] : 'list';
225 + $count = ( isset($attr['count']) && $attr['count'] != '' ) ? absint(intval($attr['count'])) : 5;
226 + $cat_polls_sorting = (isset($attr['sorting']) && $attr['sorting'] != '' ) ? $attr['sorting'] : 'date_asc';
227 +
228 + $style = '';
229 + $conteiner_style = '';
230 + if ($layout == 'grid') {
231 + $conteiner_style = 'display: flex; flex-wrap: wrap;';
232 + $style = 'margin: 5px;';
233 + }
234 +
235 + $category = $this->ays_get_poll_category($id);
236 +
237 + $sql = "SELECT * FROM {$wpdb->prefix}ayspoll_polls WHERE `categories` LIKE '%".$id."%'";
238 +
239 + $content = "";
240 + $random_poll_id = array();
241 + if ($display === 'random') {
242 + $sql .= " ORDER BY RAND() LIMIT ".$count;
243 + }
244 +
245 + $result = '';
246 + if($cat_polls_sorting == 'popular_asc' && $display == 'all'){
247 + $popular_asc_sql = "SELECT p.*
248 + FROM {$wpdb->prefix}ayspoll_reports AS r
249 + RIGHT JOIN {$wpdb->prefix}ayspoll_polls AS p
250 + ON r.poll_id = p.id
251 + WHERE p.categories LIKE '%{$id}%'
252 + GROUP BY p.id
253 + ORDER BY COUNT(answer_id) ASC LIMIT ".$count;
254 + $result = $wpdb->get_results($popular_asc_sql, 'ARRAY_A');
255 + }elseif($cat_polls_sorting == 'popular_desc' && $display == 'all'){
256 + $popular_desc_sql = "SELECT p.id
257 + FROM {$wpdb->prefix}ayspoll_reports AS r
258 + RIGHT JOIN {$wpdb->prefix}ayspoll_polls AS p
259 + ON r.poll_id = p.id
260 + WHERE p.categories LIKE '%{$id}%'
261 + GROUP BY p.id
262 + ORDER BY COUNT(answer_id) DESC LIMIT ".$count;
263 + $result = $wpdb->get_results($popular_desc_sql, 'ARRAY_A');
264 + }else if($cat_polls_sorting == 'date_asc' && $display == 'all'){
265 + $sql = "SELECT * FROM {$wpdb->prefix}ayspoll_polls
266 + WHERE `categories`
267 + LIKE '%".$id."%'
268 + ORDER BY id ASC LIMIT ".$count;
269 + $result = $wpdb->get_results($sql, 'ARRAY_A');
270 + }else if($cat_polls_sorting == 'date_desc' && $display == 'all'){
271 + $sql = "SELECT * FROM {$wpdb->prefix}ayspoll_polls
272 + WHERE `categories`
273 + LIKE '%".$id."%'
274 + ORDER BY id DESC LIMIT ".$count;
275 + $result = $wpdb->get_results($sql, 'ARRAY_A');
276 + }else{
277 + $sql = "SELECT * FROM {$wpdb->prefix}ayspoll_polls
278 + WHERE `categories`
279 + LIKE '%".$id."%'
280 + ORDER BY RAND() LIMIT ".$count;
281 + $result = $wpdb->get_results($sql, 'ARRAY_A');
282 + }
283 +
284 +
285 + $check_poll = false;
286 + $all_poll_count = count($result);
287 + foreach ($result as $val) {
288 + $val = absint(intval($val['id']));
289 + $options = (isset($val['styles']) && $val['styles'] != null) ? json_decode($val['styles'], true) : array();
290 + $check_poll = $this->check_shedule_expired_poll( $val );
291 +
292 + if (!$check_poll) {
293 + continue;
294 + }
295 +
296 + $random_poll_id[] = $val;
297 + }
298 +
299 + $cat_settings_table = esc_sql($wpdb->prefix."ayspoll_settings");
300 + $cat_key_meta = esc_sql('options');
301 + $cat_sql = "SELECT meta_value FROM ".$cat_settings_table." WHERE meta_key = %s";
302 + $ct_sql = $wpdb->get_var(
303 + $wpdb->prepare( $cat_sql, $cat_key_meta)
304 + );
305 +
306 + $cat_options_res = ($ct_sql === false) ? json_encode(array()) : $ct_sql;
307 + $cat_option_res = json_decode($cat_options_res, true);
308 +
309 + if (isset($cat_option_res['show_cat_title']) && $cat_option_res['show_cat_title'] == 'on') {
310 + $content .= "<h2 class='ays-poll-category-title' style='text-align:center;'>
311 + <span style='font-size:3rem;'>". __( "Category", 'poll-maker') .":</span>
312 + <em>". stripslashes($category['title']) ."</em>
313 + </h2>";
314 +
315 + if(isset($category['description']) && $category['description'] != ''){
316 + $content .= "<div class='ays-poll-category-description'>". do_shortcode(stripslashes(wpautop($category['description']))) ."</div>";
317 + }
318 + }
319 +
320 + $content .= "<div class='ays-poll-category-containers' style='".$conteiner_style."'>";
321 + foreach ($random_poll_id as $poll_id) {
322 + $content .= '<div class="ays-poll-main" id="ays-poll-container-'.$poll_id.'" style="'.$style.'">';
323 + $content .= '<div class="ays-poll-category-item">';
324 + $shortcode = '[ays_poll id="'.$poll_id.'"]';
325 + $content .= do_shortcode($shortcode);
326 + $content .= '</div>';
327 + $content .= '</div>';
328 + }
329 + $content .= '</div>';
330 + echo $content;
331 + return str_replace(array("\r\n", "\n", "\r"), '', ob_get_clean());
208 332 }
209 - // public function show_column_chart_js() {
210 - // // wp_enqueue_script( $this->plugin_name . '-column-chart', 'https://www.gstatic.com/charts/loader.js', array('jquery'), $this->version, true);
211 - // wp_enqueue_script( $this->plugin_name . '-column-chart', plugin_dir_url(__FILE__) . 'js/poll-maker-chart-loader.js', array('jquery'), $this->version, true);
212 - // }
213 333
214 334 public function ays_poll_results_generate_shortcode($attr) {
215 335 ob_start();
216 336
@@ -246,9 +366,8 @@
246 366
247 367 $chart_style = false;
248 368 if (isset( $result_option_res['show_result_view']) && ( $result_option_res['show_result_view'] == 'pie_chart' || $result_option_res['show_result_view'] == 'column_chart' )) {
249 369 $this->show_chart_js();
250 - // $this->show_column_chart_js();
251 370 $chart_style = true;
252 371 }
253 372
254 373 if ($polls == null) {
@@ -652,12 +771,15 @@
652 771 if (isset($options['published']) && intval($options['published']) === 0) {
653 772 return "";
654 773 }
655 774
656 - $info_form = !empty($options['info_form']) && !empty($options['fields']);
775 + $form_fields_option = isset($options['fields']) ? $options['fields'] : array();
776 + $form_required_fields_option = isset($options['required_fields']) ? $options['required_fields'] : array();
777 +
778 + $info_form = !empty($options['info_form']) && !empty($form_fields_option);
657 779 $info_form_title = !empty($options['info_form_title']) ? wp_kses_post(stripslashes($options['info_form_title'])) : "<div>" .esc_html__("Please fill out the form:", "poll-maker") . "</div>";
658 - $fields = !empty($options['fields']) && !is_array($options['fields']) ? explode(",", $options['fields']) : (is_array($options['fields']) ? $options['fields'] : array());
659 - $required_fields = !empty($options['required_fields']) && !is_array($options['required_fields']) ? explode(",", $options['required_fields']) : (is_array($options['required_fields']) ? $options['required_fields'] : array());
780 + $fields = !empty($form_fields_option) && !is_array($form_fields_option) ? explode(",", $form_fields_option) : (is_array($form_fields_option) ? $form_fields_option : array());
781 + $required_fields = !empty($form_required_fields_option) && !is_array($form_required_fields_option) ? explode(",", $form_required_fields_option) : (is_array($form_required_fields_option) ? $form_required_fields_option : array());
660 782
661 783 $is_expired = false;
662 784 $is_start_soon = false;
663 785 $startDate = '';
@@ -792,14 +914,9 @@
792 914 );
793 915
794 916 $bg_color = $options['bg_color'];
795 917 $bg_image = isset($options['bg_image']) && $options['bg_image'] != '' ? esc_url($options['bg_image']): '';
796 - // if ($bg_image != '') {
797 - // if ( !(filter_var($bg_image, FILTER_VALIDATE_URL) && wp_http_validate_url($bg_image)) ) {
798 - // // invalid URL, handle accordingly
799 - // $bg_image = '';
800 - // }
801 - // }
918 +
802 919 if( $bg_image != "" ){
803 920 $check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($bg_image);
804 921
805 922 if( !$check_if_current_image_exists ){
@@ -1165,8 +1282,14 @@
1165 1282
1166 1283 // Poll title font size mobile
1167 1284 $poll_title_font_size_mobile = (isset($options['poll_title_font_size_mobile']) && $options['poll_title_font_size_mobile'] != "") ? absint(intval(esc_attr($options['poll_title_font_size_mobile']))) : "20";
1168 1285
1286 + // Poll title font weight
1287 + $poll_title_font_weight = (isset($options['poll_title_font_weight']) && $options['poll_title_font_weight'] != "") ? esc_attr($options['poll_title_font_weight']) : "normal";
1288 +
1289 + // Poll title font weight mobile
1290 + $poll_title_font_weight_mobile = (isset($options['poll_title_font_weight_mobile']) && $options['poll_title_font_weight_mobile'] != "") ? esc_attr($options['poll_title_font_weight_mobile']) : $poll_title_font_weight;
1291 +
1169 1292 // Poll title alignment
1170 1293 $poll_title_alignment = ( isset($options['poll_title_alignment']) && $options['poll_title_alignment'] != "" ) ? esc_attr($options['poll_title_alignment']) : "center";
1171 1294
1172 1295 // Poll title alignment mobile
@@ -1171,8 +1294,11 @@
1171 1294
1172 1295 // Poll title alignment mobile
1173 1296 $poll_title_alignment_mobile = ( isset($options['poll_title_alignment_mobile']) && $options['poll_title_alignment_mobile'] != "" ) ? esc_attr($options['poll_title_alignment_mobile']) : $poll_title_alignment;
1174 1297
1298 + // Poll title text transform
1299 + $poll_title_text_transform = ( isset($options['poll_title_text_transform']) && $options['poll_title_text_transform'] != "" ) ? esc_attr($options['poll_title_text_transform']) : "none";
1300 +
1175 1301 // ===== Poll text type options start =====
1176 1302 $poll_view_type_text = isset($poll['view_type']) && $poll['view_type'] != "" ? $poll['view_type'] : "short_text";
1177 1303
1178 1304 $poll_text_type_length_enable = (isset($options['poll_text_type_length_enable']) && $options['poll_text_type_length_enable'] == "on") ? true : false;
@@ -1333,8 +1459,12 @@
1333 1459 width: 55px;
1334 1460 height: 55px;
1335 1461 }
1336 1462
1463 + #".$this_poll_id." span.ayspoll-answers-votes-count-before-voting{
1464 + padding: 10px !important;
1465 + }
1466 +
1337 1467 .$this_poll_id.ays-minimal-theme .apm-choosing input[type=radio]:checked + label, .$this_poll_id.ays-minimal-theme .apm-choosing label.ays_enable_hover:hover{
1338 1468 background-color: " . ($answer_hover_color ? $answer_hover_color : "initial") . " !important;
1339 1469 color: $main_color !important;
1340 1470 border-color: $main_color !important;
@@ -1539,11 +1669,13 @@
1539 1669 }
1540 1670
1541 1671 #".$this_poll_id.".box-apm .apm-title-box div{
1542 1672 font-size: ".$poll_title_font_size."px;
1673 + font-weight: ".$poll_title_font_weight.";
1543 1674 word-break: break-word;
1544 1675 word-wrap: break-word;
1545 1676 text-align: ".$poll_title_alignment.";
1677 + text-transform: ".$poll_title_text_transform.";
1546 1678 }
1547 1679
1548 1680 #".$this_poll_id.".box-apm .ays-poll-answer-container-list{
1549 1681 margin-bottom: ".$poll_answer_margin."px;
@@ -1578,8 +1710,9 @@
1578 1710
1579 1711 #".$this_poll_id.".box-apm .apm-answers .apm-choosing label.ays_label_poll{
1580 1712 ".$answers_box_shadow_content.";
1581 1713 border-radius: ".$poll_answer_border_radius."px;
1714 + position: relative;
1582 1715 }
1583 1716
1584 1717 #".$this_poll_id.".box-apm.text-poll .apm-answers .ays-poll-text-types-inputs{
1585 1718 font-size: ".$poll_answer_font_size.";
@@ -1797,9 +1930,11 @@
1797 1930
1798 1931 $content .= "
1799 1932 #".$this_poll_id.".box-apm .apm-title-box div{
1800 1933 font-size: ".$poll_title_font_size_mobile."px;
1934 + font-weight: ".$poll_title_font_weight_mobile.";
1801 1935 text-align: ".$poll_title_alignment_mobile.";
1936 + text-transform: ".$poll_title_text_transform.";
1802 1937 word-break: break-word;
1803 1938 word-wrap: break-word;
1804 1939 }
1805 1940
@@ -1991,8 +2126,13 @@
1991 2126 }
1992 2127
1993 2128 $show_cd_and_author .= "</div>";
1994 2129
2130 + // Show votes count per answers before voting
2131 + $options['show_votes_before_voting'] = isset($options['show_votes_before_voting']) ? $options['show_votes_before_voting'] : 'off';
2132 + $show_votes_before_voting = (isset($options['show_votes_before_voting']) && $options['show_votes_before_voting'] == 'on') ? true : false;
2133 + $show_votes_before_voting_by = (isset($options['show_votes_before_voting_by']) && $options['show_votes_before_voting_by'] != '') ? $options['show_votes_before_voting_by'] : 'by_count';
2134 +
1995 2135 $poll_login_form = "";
1996 2136 if($show_login_form){
1997 2137 $args = array(
1998 2138 'echo' => false,
@@ -2304,9 +2444,11 @@
2304 2444 }
2305 2445 }else{
2306 2446 $answer_icon_class = '';
2307 2447 }
2308 -
2448 +
2449 + $poll_answer_votes = null;
2450 + $poll_answer_votes_sum = null;
2309 2451 $content .= "<div class='apm-answers $without_vote ".$answers_container."'>";
2310 2452 switch ( $poll['type'] ) {
2311 2453 case 'choosing':
2312 2454 $pol_answer_view_type = isset($poll['styles']['poll_answer_view_type']) && $poll['styles']['poll_answer_view_type'] != "" ? esc_attr($poll['styles']['poll_answer_view_type']) : "list";
@@ -2321,8 +2463,26 @@
2321 2463 $numbering_type_arr = array();
2322 2464 if($answers_count){
2323 2465 $numbering_type_arr = $this->ays_answer_numbering($show_answers_numbering , $answers_count);
2324 2466 }
2467 +
2468 + $poll_answer_percentages = array();
2469 + $poll_answer_votes = array();
2470 + foreach ( $poll['answers'] as $index => $answer ) {
2471 +
2472 + $poll_answer_votes[$answer['id']] = intval( $answer['votes'] );
2473 + }
2474 +
2475 + $poll_answer_votes_sum = array_sum( $poll_answer_votes );
2476 + $poll_answer_percentages = array();
2477 + foreach ( $poll_answer_votes as $index => $answer_vote_count ) {
2478 + if( $poll_answer_votes_sum != 0 ){
2479 + $poll_answer_percentages[$index] = round( ( $answer_vote_count * 100 ) / $poll_answer_votes_sum, 1);
2480 + }else{
2481 + $poll_answer_percentages[$index] = 0;
2482 + }
2483 + }
2484 +
2325 2485 if($poll_allow_multivote){
2326 2486 $content .= "<input type='hidden' id='multivot_answer_count' value='".$multivote_answer_count."'/>";
2327 2487 $content .= $poll_multivote_min_count_content;
2328 2488 }
@@ -2344,8 +2504,29 @@
2344 2504 if ($poll_view_more_button_count - 1 < $index) {
2345 2505 $answer_style_class = 'ays_poll_display_none';
2346 2506 }
2347 2507 }
2508 +
2509 + $show_votes_before_voting_display_none = "";
2510 + if( !$show_votes_before_voting ){
2511 + $show_votes_before_voting_display_none = "display:none;";
2512 + }
2513 + $opacity_bg_color_svbv = $poll['view_type'] == 'grid' ? 0.6 : 0.3;
2514 + $show_votes_before_voting_color = $this->rgb2hex( $text_color );
2515 + $show_votes_before_voting_color = $this->hex2rgba( $show_votes_before_voting_color, $opacity_bg_color_svbv );
2516 +
2517 + $show_votes_before_voting_display = "style='text-shadow: 0px 0px 5px " . $bg_color . ";'";
2518 + $show_votes_before_voting_display_width = "";
2519 + if( !$show_votes_before_voting ){
2520 + $show_votes_before_voting_display = "style='{$show_votes_before_voting_display_none}text-shadow: 0px 0px 5px " . $bg_color . ";'";
2521 + $show_votes_before_voting_display_width = "style='{$show_votes_before_voting_display_none}text-shadow: 0px 0px 5px " . $bg_color . ";'";
2522 + }
2523 +
2524 + if( $poll['view_type'] == 'grid' ){
2525 + $show_votes_before_voting_display = "style='{$show_votes_before_voting_display_none}justify-content:center;font-weight:900;text-shadow: 0px 0px 5px " . $bg_color . ";'";
2526 + $show_votes_before_voting_display_width = "style='{$show_votes_before_voting_display_none}text-shadow: 0px 0px 5px " . $bg_color . ";'";
2527 + }
2528 +
2348 2529 $pol_answer_view_type_show = 'ays_poll_list_view_item';
2349 2530 $pol_answer_view_type_image = 'ays-poll-each-image-list';
2350 2531 $pol_answer_view_type_cont = 'ays-poll-answer-container-list';
2351 2532 $pol_answer_view_type_label_cont = 'ays-poll-answer-container-label-list';
@@ -2372,8 +2553,22 @@
2372 2553 $pol_answer_view_type_text_show = 'ays-poll-each-answer-list';
2373 2554
2374 2555 $poll_class_for_answer_label_text = "ays_poll_label_text_with_padding";
2375 2556 }
2557 +
2558 + $answer_votes_count_before_voting = "";
2559 + switch ( $show_votes_before_voting_by ) {
2560 + case 'by_percentage':
2561 + $answer_votes_count_before_voting = $poll_answer_percentages[$answer['id']] . "%";
2562 + break;
2563 + default:
2564 + $real_votes = isset($answer['votes']) && $answer['votes'] != "" ? intval( $answer['votes'] ) : 0;
2565 +
2566 + $answer_votes_count_before_voting = $real_votes;
2567 +
2568 + break;
2569 + }
2570 +
2376 2571 $content .= "
2377 2572 <div class='apm-choosing answer-$this_poll_id ". $answer_style_class ." ays-poll-field ".$pol_answer_view_type_cont."' >
2378 2573 <input type=".$poll_multivote_checkbox." name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}' {$autocomplete_attr}>
2379 2574 <label
@@ -2381,9 +2576,16 @@
2381 2576 class='ays_label_poll ".$answers_sound_class." ".$redirect_after_submit." ".$disable_answer_hover." ays_label_font_size ".$answer_icon_class." ".$poll_class_for_answer_label." ".$pol_answer_view_type_label_cont."'
2382 2577 data-answers-url='".(isset($answer['redirect']) && is_string($answer['redirect']) ? esc_url($answer['redirect']) : '')."'
2383 2578 >".$poll_answer_image_show." <p style='".$poll_added_style."' class='ays-poll-answers'><span class='".$pol_answer_view_type_text_show."'>"
2384 2579 . $numbering_type . esc_attr(stripcslashes($answer['answer'])) .
2385 - "</span></p></label>
2580 + "</span></p>";
2581 +
2582 + $content .= "<span class='ayspoll-answers-votes-count-before-voting' ". $show_votes_before_voting_display .">". $answer_votes_count_before_voting ."</span>
2583 + <span class='ayspoll-answers-votes-count-before-voting-width' ". $show_votes_before_voting_display_width .">
2584 + <span style='width: ". $poll_answer_percentages[$answer['id']] ."%; background-color:" . $show_votes_before_voting_color . ";'></span>
2585 + </span>";
2586 +
2587 + $content .= " </label>
2386 2588 </div>";
2387 2589 }
2388 2590 }
2389 2591 }
@@ -2832,9 +3034,11 @@
2832 3034 return $poll;
2833 3035 }
2834 3036
2835 3037 private static function get_user_ip() {
2836 - $ipaddress = '';
3038 +
3039 + $ipaddress = false;
3040 +
2837 3041 if (getenv('HTTP_CLIENT_IP')) {
2838 3042 $ipaddress = getenv('HTTP_CLIENT_IP');
2839 3043 } else if (getenv('HTTP_X_FORWARDED_FOR')) {
2840 3044 $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
@@ -2843,15 +3047,20 @@
2843 3047 } else if (getenv('HTTP_FORWARDED_FOR')) {
2844 3048 $ipaddress = getenv('HTTP_FORWARDED_FOR');
2845 3049 } else if (getenv('HTTP_FORWARDED')) {
2846 3050 $ipaddress = getenv('HTTP_FORWARDED');
2847 - } else if (getenv('REMOTE_ADDR')) {
2848 - $ipaddress = getenv('REMOTE_ADDR');
2849 - } else {
2850 - $ipaddress = 'UNKNOWN';
2851 3051 }
2852 3052
2853 - return $ipaddress;
3053 + if ( $ipaddress !== false && filter_var( $ipaddress, FILTER_VALIDATE_IP ) !== false ) {
3054 + return $ipaddress;
3055 + }
3056 +
3057 + $remote_address = getenv('REMOTE_ADDR');
3058 + if ( $remote_address !== false && filter_var( $remote_address, FILTER_VALIDATE_IP ) !== false ) {
3059 + return $remote_address;
3060 + }
3061 +
3062 + return 'UNKNOWN';
2854 3063 }
2855 3064
2856 3065 public static function get_user_ip_validated(){
2857 3066 $headers_to_check = array(
@@ -2935,8 +3144,28 @@
2935 3144
2936 3145 return $result;
2937 3146 }
2938 3147
3148 + public static function get_poll_category_by_ids($ids){
3149 + global $wpdb;
3150 +
3151 + $ids = array_map('intval', explode(',', $ids));
3152 + $ids = array_filter($ids);
3153 +
3154 + if (empty($ids)) {
3155 + return [];
3156 + }
3157 +
3158 + $ids_sql = implode(',', $ids);
3159 +
3160 + $sql = "SELECT *
3161 + FROM {$wpdb->prefix}ayspoll_categories
3162 + WHERE id IN ($ids_sql)
3163 + ORDER BY FIELD(id, $ids_sql)";
3164 +
3165 + return $wpdb->get_results($sql, ARRAY_A);
3166 + }
3167 +
2939 3168 public function get_poll_status($id) {
2940 3169 global $wpdb;
2941 3170 $poll_id = absint(intval($id));
2942 3171 $poll_table = $wpdb->prefix . 'ayspoll_polls';
@@ -2955,18 +3184,22 @@
2955 3184 }
2956 3185 }
2957 3186
2958 3187 public function ays_poll_get_user_information() {
2959 - if (is_user_logged_in()) {
2960 - $output = json_encode(wp_get_current_user());
2961 - } else {
2962 - $output = null;
3188 + if ( ! check_ajax_referer( 'ays_poll_nonce', '_ajax_nonce', false ) ) {
3189 + wp_send_json_error( array( 'message' => 'Invalid request' ), 403 );
2963 3190 }
3191 + if ( ! is_user_logged_in() ) {
3192 + wp_send_json_error( array( 'message' => 'User not logged in' ), 401 );
3193 + }
2964 3194
2965 - ob_end_clean();
2966 - $ob_get_clean = ob_get_clean();
2967 - echo $output;
2968 - wp_die();
3195 + $user = wp_get_current_user();
3196 +
3197 + wp_send_json_success( array(
3198 + 'display_name' => $user->display_name,
3199 + 'user_email' => $user->user_email,
3200 +
3201 + ) );
2969 3202 }
2970 3203
2971 3204 public function ays_finish_poll() {
2972 3205 global $wpdb;
@@ -3041,8 +3274,22 @@
3041 3274 $poll_answers_count = isset($poll['answers']) ? count($poll['answers']) : 0;
3042 3275 $added_answer_id = array();
3043 3276
3044 3277 $poll_title = (isset($poll['title']) && $poll['title'] != '') ? stripslashes( sanitize_text_field( $poll['title'] ) ) : '';
3278 +
3279 + // Poll category title
3280 + $poll_category_title = "";
3281 +
3282 + $poll_cats = isset( $poll['categories'] ) ? trim( $poll['categories'], ',' ) : '';
3283 + $poll_category_ids = $poll_cats !== '' ? sanitize_text_field( $poll_cats ) : '';
3284 +
3285 + if ( $poll_category_ids != '' ) {
3286 + $categories = self::get_poll_category_by_ids( $poll_category_ids );
3287 + $category_names = wp_list_pluck( $categories, 'title' );
3288 +
3289 + $poll_category_title = implode( ', ', $category_names );
3290 + }
3291 +
3045 3292 $poll_vote_reason_text = "";
3046 3293 $poll_vote_reason = false;
3047 3294 $show_answers_numbering = (isset($options['show_answers_numbering']) && sanitize_text_field( $options['show_answers_numbering'] ) != '') ? sanitize_text_field( $options['show_answers_numbering'] ) : 'none';
3048 3295 if (isset($options['poll_vote_reason']) && $options['poll_vote_reason'] == "on" && isset($_POST['ays-poll-reason-text'])) {
@@ -3254,8 +3501,9 @@
3254 3501 $current_poll_author_email = '';
3255 3502 $current_poll_author_nickname = '';
3256 3503 $current_poll_author_display_name = '';
3257 3504 $current_poll_author_website_url = '';
3505 + $current_poll_author_registered = '';
3258 3506 if( !empty($options['author']) ){
3259 3507 if( !is_array($options['author']) ){
3260 3508 $options['author'] = json_decode($options['author'], true);
3261 3509 }
@@ -3268,8 +3516,9 @@
3268 3516 $current_poll_author_email = ( isset( $current_poll_user_data->data->user_email ) && $current_poll_user_data->data->user_email != '' ) ? sanitize_text_field( $current_poll_user_data->data->user_email ) : "";
3269 3517 $current_poll_author_nickname = ( isset( $current_poll_user_data->data->user_nicename ) && $current_poll_user_data->data->user_nicename != '' ) ? sanitize_text_field( $current_poll_user_data->data->user_nicename ) : "";
3270 3518 $current_poll_author_display_name = ( isset( $current_poll_user_data->data->display_name ) && $current_poll_user_data->data->display_name != '' ) ? sanitize_text_field( $current_poll_user_data->data->display_name ) : "";
3271 3519 $current_poll_author_website_url = ( isset( $current_poll_user_data->data->user_url ) && $current_poll_user_data->data->user_url != '' ) ? sanitize_text_field( $current_poll_user_data->data->user_url ) : "";
3520 + $current_poll_author_registered = ( isset( $current_poll_user_data->data->user_registered ) && $current_poll_user_data->data->user_registered != '' ) ? sanitize_text_field( $current_poll_user_data->data->user_registered ) : "";
3272 3521 }
3273 3522 }
3274 3523
3275 3524 // Get Current date
@@ -3393,50 +3642,52 @@
3393 3642 $form_apm_email = (isset($_POST['apm_email']) && $_POST['apm_email'] != "") ? esc_attr($_POST['apm_email']) : "";
3394 3643 $form_apm_phone = (isset($_POST['apm_phone']) && $_POST['apm_phone'] != "") ? esc_attr($_POST['apm_phone']) : "";
3395 3644
3396 3645 $message_data = array(
3397 - 'user_name' => $form_apm_name,
3398 - 'user_email' => $form_apm_email,
3399 - 'user_phone' => $form_apm_phone,
3400 - 'poll_title' => $poll_title,
3401 - 'poll_id' => $poll_id,
3402 - 'users_first_name' => $user_first_name,
3403 - 'users_last_name' => $user_last_name,
3404 - 'creation_date' => $creation_date,
3405 - 'current_date' => $poll_current_date,
3406 - 'current_time' => $poll_current_time,
3407 - 'current_day' => $poll_current_day,
3408 - 'current_month' => $poll_current_month,
3409 - 'current_poll_page_link' => $current_poll_page_link_html,
3410 - 'current_poll_author' => $current_poll_author,
3411 - 'current_poll_author_email' => $current_poll_author_email,
3412 - 'current_poll_author_nickname' => $current_poll_author_nickname,
3413 - 'current_poll_author_display_name' => $current_poll_author_display_name,
3414 - 'current_poll_author_website_url' => $current_poll_author_website_url,
3415 - 'admin_email' => $super_admin_email,
3416 - 'user_nickname' => $user_nickname,
3417 - 'user_first_name' => $user_first_name,
3418 - 'user_display_name' => $user_display_name,
3419 - 'user_wordpress_email' => $user_wordpress_email,
3420 - 'user_wordpress_roles' => $user_wordpress_roles,
3421 - 'poll_pass_count' => $pass_count,
3422 - 'passed_poll_count_per_user' => $passed_poll_count_per_user,
3423 - 'user_wordpress_website' => $user_wordpress_website,
3424 - 'user_ip_address' => $user_ip_address,
3425 - 'user_id' => $current_user_id,
3426 - 'user_registered' => $user_registered,
3427 - 'post_title' => $post_title,
3428 - 'post_author_email' => $post_author_email,
3429 - 'post_author_display_name' => $post_author_display_name,
3430 - 'post_author_nickname' => $post_author_nickname,
3431 - 'post_author_first_name' => $post_author_first_name,
3432 - 'post_author_last_name' => $post_author_last_name,
3433 - 'post_author_website_url' => $post_author_website_url,
3434 - 'post_author_roles' => $post_author_roles,
3435 - 'post_id' => $post_id,
3436 - 'site_title' => $get_site_title,
3437 - 'site_description' => $get_site_description,
3438 - 'home_page_url' => $home_page_url,
3646 + 'user_name' => $form_apm_name,
3647 + 'user_email' => $form_apm_email,
3648 + 'user_phone' => $form_apm_phone,
3649 + 'poll_title' => $poll_title,
3650 + 'poll_category_title' => $poll_category_title,
3651 + 'poll_id' => $poll_id,
3652 + 'users_first_name' => $user_first_name,
3653 + 'users_last_name' => $user_last_name,
3654 + 'creation_date' => $creation_date,
3655 + 'current_date' => $poll_current_date,
3656 + 'current_time' => $poll_current_time,
3657 + 'current_day' => $poll_current_day,
3658 + 'current_month' => $poll_current_month,
3659 + 'current_poll_page_link' => $current_poll_page_link_html,
3660 + 'current_poll_author' => $current_poll_author,
3661 + 'current_poll_author_email' => $current_poll_author_email,
3662 + 'current_poll_author_nickname' => $current_poll_author_nickname,
3663 + 'current_poll_author_display_name' => $current_poll_author_display_name,
3664 + 'current_poll_author_website_url' => $current_poll_author_website_url,
3665 + 'current_poll_author_registered' => $current_poll_author_registered,
3666 + 'admin_email' => $super_admin_email,
3667 + 'user_nickname' => $user_nickname,
3668 + 'user_first_name' => $user_first_name,
3669 + 'user_display_name' => $user_display_name,
3670 + 'user_wordpress_email' => $user_wordpress_email,
3671 + 'user_wordpress_roles' => $user_wordpress_roles,
3672 + 'poll_pass_count' => $pass_count,
3673 + 'passed_poll_count_per_user' => $passed_poll_count_per_user,
3674 + 'user_wordpress_website' => $user_wordpress_website,
3675 + 'user_ip_address' => $user_ip_address,
3676 + 'user_id' => $current_user_id,
3677 + 'user_registered' => $user_registered,
3678 + 'post_title' => $post_title,
3679 + 'post_author_email' => $post_author_email,
3680 + 'post_author_display_name' => $post_author_display_name,
3681 + 'post_author_nickname' => $post_author_nickname,
3682 + 'post_author_first_name' => $post_author_first_name,
3683 + 'post_author_last_name' => $post_author_last_name,
3684 + 'post_author_website_url' => $post_author_website_url,
3685 + 'post_author_roles' => $post_author_roles,
3686 + 'post_id' => $post_id,
3687 + 'site_title' => $get_site_title,
3688 + 'site_description' => $get_site_description,
3689 + 'home_page_url' => $home_page_url,
3439 3690 );
3440 3691
3441 3692 $user_ip = esc_sql($user_ips);
3442 3693
@@ -4560,5 +4811,5 @@
4560 4811 $id = isset($last_poll_sql['id']) && $last_poll_sql['id'] !== 0 ? absint(intval($last_poll_sql['id'])) : "";
4561 4812
4562 4813 return $id;
4563 4814 }
4564 -}
4815 +}