| @@ -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. |
| @@ -205,13 +206,131 @@ | ||
| 205 | 206 | } |
| 206 | 207 | |
| 207 | 208 | public function show_chart_js() { |
| 208 | 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()); | |
| 209 | 332 | } |
| 210 | - // public function show_column_chart_js() { | |
| 211 | - // // wp_enqueue_script( $this->plugin_name . '-column-chart', 'https://www.gstatic.com/charts/loader.js', array('jquery'), $this->version, true); | |
| 212 | - // wp_enqueue_script( $this->plugin_name . '-column-chart', plugin_dir_url(__FILE__) . 'js/poll-maker-chart-loader.js', array('jquery'), $this->version, true); | |
| 213 | - // } | |
| 214 | 333 | |
| 215 | 334 | public function ays_poll_results_generate_shortcode($attr) { |
| 216 | 335 | ob_start(); |
| 217 | 336 | |
| @@ -247,9 +366,8 @@ | ||
| 247 | 366 | |
| 248 | 367 | $chart_style = false; |
| 249 | 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' )) { |
| 250 | 369 | $this->show_chart_js(); |
| 251 | - // $this->show_column_chart_js(); | |
| 252 | 370 | $chart_style = true; |
| 253 | 371 | } |
| 254 | 372 | |
| 255 | 373 | if ($polls == null) { |
| @@ -653,12 +771,15 @@ | ||
| 653 | 771 | if (isset($options['published']) && intval($options['published']) === 0) { |
| 654 | 772 | return ""; |
| 655 | 773 | } |
| 656 | 774 | |
| 657 | - $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); | |
| 658 | 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>"; |
| 659 | - $fields = !empty($options['fields']) && !is_array($options['fields']) ? explode(",", $options['fields']) : (is_array($options['fields']) ? $options['fields'] : array()); | |
| 660 | - $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()); | |
| 661 | 782 | |
| 662 | 783 | $is_expired = false; |
| 663 | 784 | $is_start_soon = false; |
| 664 | 785 | $startDate = ''; |
| @@ -793,14 +914,9 @@ | ||
| 793 | 914 | ); |
| 794 | 915 | |
| 795 | 916 | $bg_color = $options['bg_color']; |
| 796 | 917 | $bg_image = isset($options['bg_image']) && $options['bg_image'] != '' ? esc_url($options['bg_image']): ''; |
| 797 | - // if ($bg_image != '') { | |
| 798 | - // if ( !(filter_var($bg_image, FILTER_VALIDATE_URL) && wp_http_validate_url($bg_image)) ) { | |
| 799 | - // // invalid URL, handle accordingly | |
| 800 | - // $bg_image = ''; | |
| 801 | - // } | |
| 802 | - // } | |
| 918 | + | |
| 803 | 919 | if( $bg_image != "" ){ |
| 804 | 920 | $check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($bg_image); |
| 805 | 921 | |
| 806 | 922 | if( !$check_if_current_image_exists ){ |
| @@ -1166,8 +1282,14 @@ | ||
| 1166 | 1282 | |
| 1167 | 1283 | // Poll title font size mobile |
| 1168 | 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"; |
| 1169 | 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 | + | |
| 1170 | 1292 | // Poll title alignment |
| 1171 | 1293 | $poll_title_alignment = ( isset($options['poll_title_alignment']) && $options['poll_title_alignment'] != "" ) ? esc_attr($options['poll_title_alignment']) : "center"; |
| 1172 | 1294 | |
| 1173 | 1295 | // Poll title alignment mobile |
| @@ -1172,8 +1294,11 @@ | ||
| 1172 | 1294 | |
| 1173 | 1295 | // Poll title alignment mobile |
| 1174 | 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; |
| 1175 | 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 | + | |
| 1176 | 1301 | // ===== Poll text type options start ===== |
| 1177 | 1302 | $poll_view_type_text = isset($poll['view_type']) && $poll['view_type'] != "" ? $poll['view_type'] : "short_text"; |
| 1178 | 1303 | |
| 1179 | 1304 | $poll_text_type_length_enable = (isset($options['poll_text_type_length_enable']) && $options['poll_text_type_length_enable'] == "on") ? true : false; |
| @@ -1334,8 +1459,12 @@ | ||
| 1334 | 1459 | width: 55px; |
| 1335 | 1460 | height: 55px; |
| 1336 | 1461 | } |
| 1337 | 1462 | |
| 1463 | + #".$this_poll_id." span.ayspoll-answers-votes-count-before-voting{ | |
| 1464 | + padding: 10px !important; | |
| 1465 | + } | |
| 1466 | + | |
| 1338 | 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{ |
| 1339 | 1468 | background-color: " . ($answer_hover_color ? $answer_hover_color : "initial") . " !important; |
| 1340 | 1469 | color: $main_color !important; |
| 1341 | 1470 | border-color: $main_color !important; |
| @@ -1540,11 +1669,13 @@ | ||
| 1540 | 1669 | } |
| 1541 | 1670 | |
| 1542 | 1671 | #".$this_poll_id.".box-apm .apm-title-box div{ |
| 1543 | 1672 | font-size: ".$poll_title_font_size."px; |
| 1673 | + font-weight: ".$poll_title_font_weight."; | |
| 1544 | 1674 | word-break: break-word; |
| 1545 | 1675 | word-wrap: break-word; |
| 1546 | 1676 | text-align: ".$poll_title_alignment."; |
| 1677 | + text-transform: ".$poll_title_text_transform."; | |
| 1547 | 1678 | } |
| 1548 | 1679 | |
| 1549 | 1680 | #".$this_poll_id.".box-apm .ays-poll-answer-container-list{ |
| 1550 | 1681 | margin-bottom: ".$poll_answer_margin."px; |
| @@ -1579,8 +1710,9 @@ | ||
| 1579 | 1710 | |
| 1580 | 1711 | #".$this_poll_id.".box-apm .apm-answers .apm-choosing label.ays_label_poll{ |
| 1581 | 1712 | ".$answers_box_shadow_content."; |
| 1582 | 1713 | border-radius: ".$poll_answer_border_radius."px; |
| 1714 | + position: relative; | |
| 1583 | 1715 | } |
| 1584 | 1716 | |
| 1585 | 1717 | #".$this_poll_id.".box-apm.text-poll .apm-answers .ays-poll-text-types-inputs{ |
| 1586 | 1718 | font-size: ".$poll_answer_font_size."; |
| @@ -1798,9 +1930,11 @@ | ||
| 1798 | 1930 | |
| 1799 | 1931 | $content .= " |
| 1800 | 1932 | #".$this_poll_id.".box-apm .apm-title-box div{ |
| 1801 | 1933 | font-size: ".$poll_title_font_size_mobile."px; |
| 1934 | + font-weight: ".$poll_title_font_weight_mobile."; | |
| 1802 | 1935 | text-align: ".$poll_title_alignment_mobile."; |
| 1936 | + text-transform: ".$poll_title_text_transform."; | |
| 1803 | 1937 | word-break: break-word; |
| 1804 | 1938 | word-wrap: break-word; |
| 1805 | 1939 | } |
| 1806 | 1940 | |
| @@ -1992,8 +2126,13 @@ | ||
| 1992 | 2126 | } |
| 1993 | 2127 | |
| 1994 | 2128 | $show_cd_and_author .= "</div>"; |
| 1995 | 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 | + | |
| 1996 | 2135 | $poll_login_form = ""; |
| 1997 | 2136 | if($show_login_form){ |
| 1998 | 2137 | $args = array( |
| 1999 | 2138 | 'echo' => false, |
| @@ -2305,9 +2444,11 @@ | ||
| 2305 | 2444 | } |
| 2306 | 2445 | }else{ |
| 2307 | 2446 | $answer_icon_class = ''; |
| 2308 | 2447 | } |
| 2309 | - | |
| 2448 | + | |
| 2449 | + $poll_answer_votes = null; | |
| 2450 | + $poll_answer_votes_sum = null; | |
| 2310 | 2451 | $content .= "<div class='apm-answers $without_vote ".$answers_container."'>"; |
| 2311 | 2452 | switch ( $poll['type'] ) { |
| 2312 | 2453 | case 'choosing': |
| 2313 | 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"; |
| @@ -2322,8 +2463,26 @@ | ||
| 2322 | 2463 | $numbering_type_arr = array(); |
| 2323 | 2464 | if($answers_count){ |
| 2324 | 2465 | $numbering_type_arr = $this->ays_answer_numbering($show_answers_numbering , $answers_count); |
| 2325 | 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 | + | |
| 2326 | 2485 | if($poll_allow_multivote){ |
| 2327 | 2486 | $content .= "<input type='hidden' id='multivot_answer_count' value='".$multivote_answer_count."'/>"; |
| 2328 | 2487 | $content .= $poll_multivote_min_count_content; |
| 2329 | 2488 | } |
| @@ -2345,8 +2504,29 @@ | ||
| 2345 | 2504 | if ($poll_view_more_button_count - 1 < $index) { |
| 2346 | 2505 | $answer_style_class = 'ays_poll_display_none'; |
| 2347 | 2506 | } |
| 2348 | 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 | + | |
| 2349 | 2529 | $pol_answer_view_type_show = 'ays_poll_list_view_item'; |
| 2350 | 2530 | $pol_answer_view_type_image = 'ays-poll-each-image-list'; |
| 2351 | 2531 | $pol_answer_view_type_cont = 'ays-poll-answer-container-list'; |
| 2352 | 2532 | $pol_answer_view_type_label_cont = 'ays-poll-answer-container-label-list'; |
| @@ -2373,8 +2553,22 @@ | ||
| 2373 | 2553 | $pol_answer_view_type_text_show = 'ays-poll-each-answer-list'; |
| 2374 | 2554 | |
| 2375 | 2555 | $poll_class_for_answer_label_text = "ays_poll_label_text_with_padding"; |
| 2376 | 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 | + | |
| 2377 | 2571 | $content .= " |
| 2378 | 2572 | <div class='apm-choosing answer-$this_poll_id ". $answer_style_class ." ays-poll-field ".$pol_answer_view_type_cont."' > |
| 2379 | 2573 | <input type=".$poll_multivote_checkbox." name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}' {$autocomplete_attr}> |
| 2380 | 2574 | <label |
| @@ -2382,9 +2576,16 @@ | ||
| 2382 | 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."' |
| 2383 | 2577 | data-answers-url='".(isset($answer['redirect']) && is_string($answer['redirect']) ? esc_url($answer['redirect']) : '')."' |
| 2384 | 2578 | >".$poll_answer_image_show." <p style='".$poll_added_style."' class='ays-poll-answers'><span class='".$pol_answer_view_type_text_show."'>" |
| 2385 | 2579 | . $numbering_type . esc_attr(stripcslashes($answer['answer'])) . |
| 2386 | - "</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> | |
| 2387 | 2588 | </div>"; |
| 2388 | 2589 | } |
| 2389 | 2590 | } |
| 2390 | 2591 | } |
| @@ -2833,9 +3034,11 @@ | ||
| 2833 | 3034 | return $poll; |
| 2834 | 3035 | } |
| 2835 | 3036 | |
| 2836 | 3037 | private static function get_user_ip() { |
| 2837 | - $ipaddress = ''; | |
| 3038 | + | |
| 3039 | + $ipaddress = false; | |
| 3040 | + | |
| 2838 | 3041 | if (getenv('HTTP_CLIENT_IP')) { |
| 2839 | 3042 | $ipaddress = getenv('HTTP_CLIENT_IP'); |
| 2840 | 3043 | } else if (getenv('HTTP_X_FORWARDED_FOR')) { |
| 2841 | 3044 | $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); |
| @@ -2844,15 +3047,20 @@ | ||
| 2844 | 3047 | } else if (getenv('HTTP_FORWARDED_FOR')) { |
| 2845 | 3048 | $ipaddress = getenv('HTTP_FORWARDED_FOR'); |
| 2846 | 3049 | } else if (getenv('HTTP_FORWARDED')) { |
| 2847 | 3050 | $ipaddress = getenv('HTTP_FORWARDED'); |
| 2848 | - } else if (getenv('REMOTE_ADDR')) { | |
| 2849 | - $ipaddress = getenv('REMOTE_ADDR'); | |
| 2850 | - } else { | |
| 2851 | - $ipaddress = 'UNKNOWN'; | |
| 2852 | 3051 | } |
| 2853 | 3052 | |
| 2854 | - 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'; | |
| 2855 | 3063 | } |
| 2856 | 3064 | |
| 2857 | 3065 | public static function get_user_ip_validated(){ |
| 2858 | 3066 | $headers_to_check = array( |
| @@ -2936,8 +3144,28 @@ | ||
| 2936 | 3144 | |
| 2937 | 3145 | return $result; |
| 2938 | 3146 | } |
| 2939 | 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 | + | |
| 2940 | 3168 | public function get_poll_status($id) { |
| 2941 | 3169 | global $wpdb; |
| 2942 | 3170 | $poll_id = absint(intval($id)); |
| 2943 | 3171 | $poll_table = $wpdb->prefix . 'ayspoll_polls'; |
| @@ -3046,8 +3274,22 @@ | ||
| 3046 | 3274 | $poll_answers_count = isset($poll['answers']) ? count($poll['answers']) : 0; |
| 3047 | 3275 | $added_answer_id = array(); |
| 3048 | 3276 | |
| 3049 | 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 | + | |
| 3050 | 3292 | $poll_vote_reason_text = ""; |
| 3051 | 3293 | $poll_vote_reason = false; |
| 3052 | 3294 | $show_answers_numbering = (isset($options['show_answers_numbering']) && sanitize_text_field( $options['show_answers_numbering'] ) != '') ? sanitize_text_field( $options['show_answers_numbering'] ) : 'none'; |
| 3053 | 3295 | if (isset($options['poll_vote_reason']) && $options['poll_vote_reason'] == "on" && isset($_POST['ays-poll-reason-text'])) { |
| @@ -3259,8 +3501,9 @@ | ||
| 3259 | 3501 | $current_poll_author_email = ''; |
| 3260 | 3502 | $current_poll_author_nickname = ''; |
| 3261 | 3503 | $current_poll_author_display_name = ''; |
| 3262 | 3504 | $current_poll_author_website_url = ''; |
| 3505 | + $current_poll_author_registered = ''; | |
| 3263 | 3506 | if( !empty($options['author']) ){ |
| 3264 | 3507 | if( !is_array($options['author']) ){ |
| 3265 | 3508 | $options['author'] = json_decode($options['author'], true); |
| 3266 | 3509 | } |
| @@ -3273,8 +3516,9 @@ | ||
| 3273 | 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 ) : ""; |
| 3274 | 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 ) : ""; |
| 3275 | 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 ) : ""; |
| 3276 | 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 ) : ""; | |
| 3277 | 3521 | } |
| 3278 | 3522 | } |
| 3279 | 3523 | |
| 3280 | 3524 | // Get Current date |
| @@ -3398,50 +3642,52 @@ | ||
| 3398 | 3642 | $form_apm_email = (isset($_POST['apm_email']) && $_POST['apm_email'] != "") ? esc_attr($_POST['apm_email']) : ""; |
| 3399 | 3643 | $form_apm_phone = (isset($_POST['apm_phone']) && $_POST['apm_phone'] != "") ? esc_attr($_POST['apm_phone']) : ""; |
| 3400 | 3644 | |
| 3401 | 3645 | $message_data = array( |
| 3402 | - 'user_name' => $form_apm_name, | |
| 3403 | - 'user_email' => $form_apm_email, | |
| 3404 | - 'user_phone' => $form_apm_phone, | |
| 3405 | - 'poll_title' => $poll_title, | |
| 3406 | - 'poll_id' => $poll_id, | |
| 3407 | - 'users_first_name' => $user_first_name, | |
| 3408 | - 'users_last_name' => $user_last_name, | |
| 3409 | - 'creation_date' => $creation_date, | |
| 3410 | - 'current_date' => $poll_current_date, | |
| 3411 | - 'current_time' => $poll_current_time, | |
| 3412 | - 'current_day' => $poll_current_day, | |
| 3413 | - 'current_month' => $poll_current_month, | |
| 3414 | - 'current_poll_page_link' => $current_poll_page_link_html, | |
| 3415 | - 'current_poll_author' => $current_poll_author, | |
| 3416 | - 'current_poll_author_email' => $current_poll_author_email, | |
| 3417 | - 'current_poll_author_nickname' => $current_poll_author_nickname, | |
| 3418 | - 'current_poll_author_display_name' => $current_poll_author_display_name, | |
| 3419 | - 'current_poll_author_website_url' => $current_poll_author_website_url, | |
| 3420 | - 'admin_email' => $super_admin_email, | |
| 3421 | - 'user_nickname' => $user_nickname, | |
| 3422 | - 'user_first_name' => $user_first_name, | |
| 3423 | - 'user_display_name' => $user_display_name, | |
| 3424 | - 'user_wordpress_email' => $user_wordpress_email, | |
| 3425 | - 'user_wordpress_roles' => $user_wordpress_roles, | |
| 3426 | - 'poll_pass_count' => $pass_count, | |
| 3427 | - 'passed_poll_count_per_user' => $passed_poll_count_per_user, | |
| 3428 | - 'user_wordpress_website' => $user_wordpress_website, | |
| 3429 | - 'user_ip_address' => $user_ip_address, | |
| 3430 | - 'user_id' => $current_user_id, | |
| 3431 | - 'user_registered' => $user_registered, | |
| 3432 | - 'post_title' => $post_title, | |
| 3433 | - 'post_author_email' => $post_author_email, | |
| 3434 | - 'post_author_display_name' => $post_author_display_name, | |
| 3435 | - 'post_author_nickname' => $post_author_nickname, | |
| 3436 | - 'post_author_first_name' => $post_author_first_name, | |
| 3437 | - 'post_author_last_name' => $post_author_last_name, | |
| 3438 | - 'post_author_website_url' => $post_author_website_url, | |
| 3439 | - 'post_author_roles' => $post_author_roles, | |
| 3440 | - 'post_id' => $post_id, | |
| 3441 | - 'site_title' => $get_site_title, | |
| 3442 | - 'site_description' => $get_site_description, | |
| 3443 | - '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, | |
| 3444 | 3690 | ); |
| 3445 | 3691 | |
| 3446 | 3692 | $user_ip = esc_sql($user_ips); |
| 3447 | 3693 | |
| @@ -4565,5 +4811,5 @@ | ||
| 4565 | 4811 | $id = isset($last_poll_sql['id']) && $last_poll_sql['id'] !== 0 ? absint(intval($last_poll_sql['id'])) : ""; |
| 4566 | 4812 | |
| 4567 | 4813 | return $id; |
| 4568 | 4814 | } |
| 4569 | -} | |
| 4815 | +} | |