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

class-poll-maker-ays-public.php in Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls 6.3.8, at public/class-poll-maker-ays-public.php

4,570 lines 189.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The public-facing functionality of the plugin.
5 *
6 * @link https://ays-pro.com/
7 * @since 1.0.0
8 *
9 * @package Poll_Maker_Ays
10 * @subpackage Poll_Maker_Ays/public
11 */
12
13 /**
14 * The public-facing functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the public-facing stylesheet and JavaScript.
18 *
19 * @package Poll_Maker_Ays
20 * @subpackage Poll_Maker_Ays/public
21 * @author Poll Maker Team <[email protected]>
22 */
23 class Poll_Maker_Ays_Public {
24
25 /**
26 * The settings of this plugin.
27 *
28 * @since 1.0.0
29 * @access protected
30 * @var Poll_Maker_Settings_Actions object $settings The current settings of this plugin.
31 */
32 protected $settings;
33 protected $fields_placeholders;
34 /**
35 * The ID of this plugin.
36 *
37 * @since 1.0.0
38 * @access private
39 * @var string $plugin_name The ID of this plugin.
40 */
41 private $plugin_name;
42 private static $p;
43
44 /**
45 * The version of this plugin.
46 *
47 * @since 1.0.0
48 * @access private
49 * @var string $version The current version of this plugin.
50 */
51 private $version;
52 private static $v;
53
54 /**
55 * The instance of this plugin public class.
56 *
57 * @since 1.0.0
58 * @access private
59 * @var Poll_Maker_Ays_Public object.
60 */
61 private static $instance = null;
62
63 /**
64 * Initialize the class and set its properties.
65 *
66 * @param string $plugin_name The name of the plugin.
67 * @param string $version The version of this plugin.
68 *
69 * @since 1.0.0
70 */
71 public function __construct( $plugin_name, $version ) {
72
73 $this->plugin_name = $plugin_name;
74 $this->version = $version;
75 self::$p = $plugin_name;
76 self::$v = $version;
77
78 add_shortcode('ays_poll', array($this, 'ays_poll_generate_shortcode'));
79 $this->settings = new Poll_Maker_Settings_Actions($this->plugin_name);
80 add_shortcode('ays_poll_all', array($this, 'ays_poll_all_generate_shortcode'));
81 add_shortcode('ayspoll_results', array($this, 'ays_poll_results_generate_shortcode'));
82 add_shortcode('ays_display_polls', array($this, 'ays_generate_display_polls_method'));
83 }
84
85 /**
86 * Get instance of this class. Singleton pattern.
87 *
88 * @since 1.4.0
89 */
90 public static function get_instance() {
91 if (self::$instance == null) {
92 self::$instance = new Poll_Maker_Ays_Public(self::$p, self::$v);
93 }
94
95 return self::$instance;
96 }
97
98 /**
99 * Register the stylesheets for the public-facing side of the site.
100 *
101 * @since 1.0.0
102 */
103 public function enqueue_styles() {
104
105 /**
106 * This function is provided for demonstration purposes only.
107 *
108 * An instance of this class should be passed to the run() function
109 * defined in Poll_Maker_Ays_Loader as all of the hooks are defined
110 * in that particular class.
111 *
112 * The Poll_Maker_Ays_Loader will then create the relationship
113 * between the defined hooks and the functions defined in this
114 * class.
115 */
116
117 wp_enqueue_style( 'ays_poll_font_awesome', esc_url(POLL_MAKER_AYS_ADMIN_URL) . '/css/poll-maker-ays-admin-fonts.css', array(), $this->version, 'all');
118
119 }
120
121 public function enqueue_styles_early(){
122
123 $settings_options = $this->settings->ays_get_setting('options');
124 if($settings_options){
125 $settings_options = json_decode(stripcslashes($settings_options), true);
126 }else{
127 $settings_options = array();
128 }
129
130 // General CSS File
131 $settings_options['poll_exclude_general_css'] = isset($settings_options['poll_exclude_general_css']) ? esc_attr( $settings_options['poll_exclude_general_css'] ) : 'off';
132 $poll_exclude_general_css = (isset($settings_options['poll_exclude_general_css']) && esc_attr( $settings_options['poll_exclude_general_css'] ) == "on") ? true : false;
133
134 if( ! $poll_exclude_general_css ){
135 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/poll-maker-ays-public.css', array(), $this->version, 'all');
136 }else{
137 if( ! is_front_page() ){
138 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/poll-maker-ays-public.css', array(), $this->version, 'all');
139 }
140 }
141
142 $ays_is_elementor = $this->ays_is_elementor();
143 if ( $ays_is_elementor ) {
144 wp_enqueue_style( 'ays_poll_font_awesome', esc_url(POLL_MAKER_AYS_ADMIN_URL) . '/css/poll-maker-ays-admin-fonts.css', array(), $this->version, 'all');
145 }
146 }
147
148 public function ays_is_elementor(){
149 if ( defined( 'ELEMENTOR_PATH' ) && class_exists( 'Elementor\Widget_Base' ) ) {
150 if ( class_exists( 'Elementor\Plugin' ) ) {
151 if ( is_callable( 'Elementor\Plugin', 'instance' ) ) {
152 $elementor = Elementor\Plugin::instance();
153 if ( isset( $elementor->preview ) ) {
154 return \Elementor\Plugin::$instance->preview->is_preview_mode();
155 }
156 }
157 }
158 }
159 }
160
161 /**
162 * Register the JavaScript for the public-facing side of the site.
163 *
164 * @since 1.0.0
165 */
166 public function enqueue_scripts() {
167
168 /**
169 * This function is provided for demonstration purposes only.
170 *
171 * An instance of this class should be passed to the run() function
172 * defined in Poll_Maker_Ays_Loader as all of the hooks are defined
173 * in that particular class.
174 *
175 * The Poll_Maker_Ays_Loader will then create the relationship
176 * between the defined hooks and the functions defined in this
177 * class.
178 */
179 //wp_enqueue_script($this->plugin_name . '-font-awesome', "https://use.fontawesome.com/releases/v5.5.0/js/all.js", array('jquery'), $this->version, true);
180
181 wp_enqueue_script("jquery");
182 wp_enqueue_script("jquery-effects-core");
183 wp_enqueue_script( $this->plugin_name . '-charts-google', plugin_dir_url(__FILE__) . 'js/google-chart.js', array('jquery'), $this->version, true);
184 wp_enqueue_script($this->plugin_name . '-ajax-public', plugin_dir_url(__FILE__) . 'js/poll-maker-public-ajax.js', array('jquery'), $this->version, true);
185 wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/poll-maker-ays-public.js', array('jquery'), $this->version, false);
186 wp_enqueue_script($this->plugin_name.'-category', plugin_dir_url(__FILE__) . 'js/poll-maker-public-category.js', array('jquery'), $this->version, false);
187 wp_enqueue_script( $this->plugin_name . '-autosize', plugin_dir_url(__FILE__) . 'js/poll-maker-autosize.js', array( 'jquery' ), $this->version, false );
188 wp_localize_script($this->plugin_name . '-ajax-public', 'poll_maker_ajax_public',
189 array(
190 'ajax_url' => admin_url('admin-ajax.php'),
191 'nonce' => wp_create_nonce('ays_poll_nonce'),
192 'alreadyVoted' =>esc_html__( "You have already voted" , "poll-maker" ),
193 'day' =>esc_html__( 'day', "poll-maker" ),
194 'days' =>esc_html__( 'days', "poll-maker" ),
195 'hour' =>esc_html__( 'hour', "poll-maker" ),
196 'hours' =>esc_html__( 'hours', "poll-maker" ),
197 'minute' =>esc_html__( 'minute', "poll-maker" ),
198 'minutes' =>esc_html__( 'minutes', "poll-maker" ),
199 'second' =>esc_html__( 'second', "poll-maker" ),
200 'seconds' =>esc_html__( 'seconds', "poll-maker" ),
201 'thank_message' =>esc_html__( 'Your answer has been successfully sent to the admin. Please wait for the approval.', "poll-maker" ),
202 'restart' =>esc_html__( 'Restart', "poll-maker" ),
203 )
204 );
205 }
206
207 public function show_chart_js() {
208 wp_enqueue_script( $this->plugin_name . '-charts-google', plugin_dir_url(__FILE__) . 'js/google-chart.js', array('jquery'), $this->version, true);
209 }
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
215 public function ays_poll_results_generate_shortcode($attr) {
216 ob_start();
217
218 $this->enqueue_styles();
219 $this->enqueue_scripts();
220
221 global $wpdb;
222 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
223 $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
224 $polls_table = esc_sql($wpdb->prefix."ayspoll_polls");
225
226 if(isset($attr['recent']) && $attr['recent'] === 'true'){
227 $id = $this->ays_poll_get_recent_poll_id();
228 }else{
229 $id = isset($attr['id']) && $attr['id'] !== 0 ? absint(intval($attr['id'])) : "";
230 }
231
232 $ans_sql = "SELECT * FROM ".$answ_table." WHERE poll_id =%d ORDER BY votes DESC";
233 $poll_answers = $wpdb->get_results(
234 $wpdb->prepare( $ans_sql, $id),
235 'ARRAY_A'
236 );
237
238 $poll_sql = "SELECT * FROM ".$polls_table." WHERE id =%d";
239 $polls = $wpdb->get_row(
240 $wpdb->prepare( $poll_sql, $id),
241 'ARRAY_A'
242 );
243
244 $settings_options = $this->settings->ays_get_setting('options');
245 $result_options_res = ($settings_options === false) ? json_encode(array()) : $settings_options;
246 $result_option_res = json_decode($result_options_res, true);
247
248 $chart_style = false;
249 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 $this->show_chart_js();
251 // $this->show_column_chart_js();
252 $chart_style = true;
253 }
254
255 if ($polls == null) {
256 $content = '<p style="text-align:center;">No ratings yet</p>';
257 }else{
258 $show_title = isset($polls['show_title']) && $polls['show_title'] == 0 ? false : true;
259 $poll_title = isset($polls['title']) ? $polls['title'] : '';
260 $votes_count = $this->get_poll_results_count_by_id($id);
261 $poll = $this->get_poll_by_id($id);
262 $polls_options = $poll['styles'];
263 if (intval($votes_count['res_count']) > 0) {
264 $one_percent = 100/intval($votes_count['res_count']);
265 }else{
266 $one_percent = 1;
267 }
268 $poll_border_color_res = isset($polls_options['border_color']) && $polls_options['border_color'] != "" ? esc_attr($polls_options['border_color']) : '';
269
270 // Poll question font size
271 $poll_question_font_size_pc = isset($polls_options['poll_question_size_pc']) && $polls_options['poll_question_size_pc'] != "" ? esc_attr($polls_options['poll_question_size_pc']) : "16";
272 $poll_question_font_size_mobile = isset($polls_options['poll_question_size_mobile']) && $polls_options['poll_question_size_mobile'] != "" ? esc_attr($polls_options['poll_question_size_mobile']) : "16";
273 $content = "";
274 $content .= "<style>
275 .ays-poll-main .ays_question p{
276 font-size: ".$poll_question_font_size_pc."px;
277 }
278
279 @media only screen and (max-width: 768px){
280 .ays-poll-main .ays_question p{
281 font-size: ".$poll_question_font_size_mobile."px;
282 }
283 }
284 </style>";
285 $content .= '<div class="ays-poll-main" style="margin-bottom: 1rem; border:2px solid '.$poll_border_color_res.'; background-color: '.$polls_options['bg_color'].';color: '.$polls_options['main_color'].';" id="ays-poll-container-'.htmlentities($id).'">';
286
287 if($show_title){
288 $content .= '<div class="apm-title-box">
289 <div style="text-align:center;">'.stripslashes($poll_title).'</div>
290 </div>';
291 }
292
293 $content .= '<div class="ays_question">
294 <p>'.stripslashes($polls['question']).'</p>
295 </div>';
296 $content .= "<input type='hidden' name='ays_poll_curent_page_link' class='ays-poll-curent-page-link'/>";
297 if ($votes_count['res_count'] == 0) {
298 $content .= '<p style="text-align:center; margin: 0;">No ratings yet</p>';
299 }
300 if($chart_style){
301 $content .= '<div class="results-apm" id="pollAllResultId'.$id.'" style="height:400px;display: flex;justify-content: center;">';
302 $aysChartData = array(['','']);
303 foreach ($poll_answers as $key => $c_value) {
304 $all_votes_chart = 0;
305 $real_votes = isset($c_value['votes']) ? intval($c_value['votes']) : 0;
306 $all_votes_chart += $real_votes;
307 if(isset($poll["type"]) && $poll["type"] == "voting"){
308 $c_value['answer'] = $c_value['answer'] == 1 ? "Like" : "Dislike";
309 }
310 $arr = [$c_value['answer'] , $all_votes_chart];
311 array_push($aysChartData,$arr);
312 }
313 $show_result_view = isset($result_option_res['show_result_view']) && $result_option_res['show_result_view'] != '' ? $result_option_res['show_result_view'] : 'standart';
314 }
315 else{
316 $content .= '<div class="results-apm">';
317 }
318
319 $poll_answers_count = count($poll_answers);
320 $chart_font_size = "fontSize:12";
321 if(isset($poll["type"]) && ($poll["type"] == "voting" || $poll["type"] == "rating" )){
322 $chart_font_size = "fontSize:18";
323 }
324
325 $title_bg_color = isset($polls_options['main_color']) ? $polls_options['main_color'] : '#fff';
326 if($chart_style && $show_result_view == 'pie_chart'){
327 $content .= '
328 <script>
329 (function ($) {
330 "use strict";
331 $(document).ready(function () {
332
333 var aysChartData = '. json_encode($aysChartData).';
334 google.charts.load("current", {packages:["corechart"]});
335 google.charts.setOnLoadCallback(drawChart);
336
337 function drawChart() {
338 var dataGoogle = google.visualization.arrayToDataTable(aysChartData);
339
340 var options = {
341 legend: {position: "right",},
342 pieSliceText: "label",
343 chartArea:{"left":"100","width":"100%"},
344 width: 500,
345 height: 400,
346 '.$chart_font_size.',
347 legend: {textStyle :{color:"'.$title_bg_color.'"}},
348 backgroundColor: { fill:"transparent" },
349 };
350
351 var chart = new google.visualization.PieChart(pollAllResultId'.$id.');
352 chart.draw(dataGoogle, options);
353 }
354 });
355 })(jQuery);
356 </script>';
357 }
358 elseif($chart_style && $show_result_view == 'column_chart'){
359 $content .= '
360 <script>
361 (function ($) {
362 "use strict";
363 $(document).ready(function () {
364 var aysChartData = '. json_encode($aysChartData).';
365 google.charts.load("current", {"packages":["bar"]});
366 google.charts.setOnLoadCallback(drawStuff);
367
368 function drawStuff() {
369 var dataColumnChart = new google.visualization.arrayToDataTable(aysChartData);
370
371 var options = {
372 width: 500,
373 maxWidth: "100%",
374 height: 400,
375 legend: { position: "none" },
376 axes: {
377 x: {
378 0: { side: "bottom"}
379 }
380 },
381 bar: { groupWidth: "90%" }
382 };
383
384 var chart = new google.charts.Bar(pollAllResultId'.$id.');
385
386 chart.draw(dataColumnChart, google.charts.Bar.convertOptions(options));
387 }
388 });
389 })(jQuery);
390 </script>';
391 }
392 else{
393 foreach ($poll_answers as $ans_key => $ans_val) {
394 $percent = round($one_percent*intval($ans_val['votes']));
395 $real_votes = 0;
396 $all_votes_bar = 0;
397 if($polls['type'] == 'choosing'){
398 $real_votes = isset($ans_val['votes']) ? intval($ans_val['votes']) : 0;
399 $fake_votes = isset($ans_val['fake_votes']) ? intval($ans_val['fake_votes']) : 0;
400 if($poll_fake_votes){
401 if($fake_votes + $real_votes < 0){
402 $all_votes_bar += $real_votes;
403 }
404 else{
405 $all_votes_bar += ($real_votes + $fake_votes);
406 }
407 }
408 else{
409 $all_votes_bar += $real_votes;
410 }
411
412 if($sum_of_votes > 0){
413 $percent = round((100*$all_votes_bar)/$sum_of_votes);
414 }
415 }
416 else{
417 $all_votes_bar = $ans_val['votes'];
418 }
419
420 if ($percent == 0) {
421 $perc_cont = '';
422 }else{
423 $perc_cont = $percent.' %';
424 }
425 switch ($polls['type']) {
426 case 'choosing':
427 $answer_image = isset($ans_val['answer_img']) && $ans_val['answer_img'] != '' ? sanitize_url($ans_val['answer_img']) : '';
428 $answer_image_box = "<div class='ays-poll-answers-image-box-empty-image'></div>";
429 $answer_image_is_empty_class = "ays-poll-answers-box-no-image";
430 if($answer_image != ""){
431 $answer_image_is_empty_class = "ays-poll-answers-box";
432 $answer_image_box = "<div class='ays-poll-answers-image-box'><img src=" . $answer_image . " class='ays-poll-answers-current-image'></div>";
433 }
434 $content .= '
435
436 <div class=' . $answer_image_is_empty_class. '>
437 '. $answer_image_box . '
438 <div class="ays-poll-answer-text-and-percent-box">
439 <div class="answer-title flex-apm">
440 <span class="answer-text">'.stripslashes($ans_val['answer']).'</span>
441 <span class="answer-votes">'.$all_votes_bar.' ('.$percent.'%)</span>
442 </div>
443 <div class="progress-bar-container">
444 <div class="answer-percent-res"
445 style="width: '.$percent.'%;
446 background-color: '.$polls_options['main_color'].';
447 height: 20px;
448 border-radius: 4px;
449 transition: width 0.3s ease;
450 display: flex;
451 align-items: center;
452 padding-left: 8px;
453 padding-right: 13px;
454 color: '.$polls_options['bg_color'].';">
455 '.($percent == 0 ? '' : $percent.'%').'
456 </div>
457 </div>
458 </div>
459 </div>';
460 break;
461
462 case 'rating':
463 switch ($polls['view_type']) {
464 case 'star':
465 $star_type = '';
466 for ($i=0; $i < intval($ans_val['answer']); $i++) {
467 $star_type .= '<i class="ays_poll_far ays_poll_fa-star far"></i>';
468 }
469 $content .= '<div class="answer-title flex-apm">
470 <span class="answer-text">'.$star_type.'</span>
471 <span class="answer-votes">'.$ans_val['votes'].'</span>
472 </div>
473 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$polls_options['main_color'].'; color: '.$polls_options['bg_color'].';">'.$perc_cont.'</div>';
474 break;
475
476 case 'emoji':
477 $emojy_type = '';
478 if ($poll_answers_count == 3) {
479 switch (intval($ans_val['answer'])) {
480 case 1:
481 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
482 break;
483 case 2:
484 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-meh far"></i>';
485 break;
486 case 3:
487 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
488 break;
489 default:
490 break;
491 }
492 }else{
493 switch (intval($ans_val['answer'])) {
494 case 1:
495 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-tired far"></i>';
496 break;
497 case 2:
498 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
499 break;
500 case 3:
501 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-meh far"></i>';
502 break;
503 case 4:
504 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
505 break;
506 case 5:
507 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-dizzy far"></i>';
508 break;
509 default:
510 break;
511 }
512 }
513
514 $content .= '<div class="answer-title flex-apm">
515 <span class="answer-text">'.$emojy_type.'</span>
516 <span class="answer-votes">'.$ans_val['votes'].'</span>
517 </div>
518 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$polls_options['main_color'].'; color: '.$polls_options['bg_color'].';">'.$perc_cont.'</div>';
519
520 break;
521 default:
522 break;
523 }
524 break;
525 case 'voting':
526 switch ($polls['view_type']) {
527 case 'hand':
528 $hand_type = '';
529 if (intval($ans_val['answer'] == 1)) {
530 $hand_type = '<i class="ays_poll_far ays_poll_fa-thumbs-up far"></i>';
531 }else{
532 $hand_type = '<i class="ays_poll_far ays_poll_fa-thumbs-down far"></i>';
533 }
534 $content .= '<div class="answer-title flex-apm">
535 <span class="answer-text">'.$hand_type.'</span>
536 <span class="answer-votes">'.$all_votes_bar.' ('.$percent.'%)</span>
537 </div>
538 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$polls_options['main_color'].'; color: '.$polls_options['bg_color'].';">'.$perc_cont.'</div>';
539 break;
540 case 'emoji':
541 $emojy_type = '';
542 if (intval($ans_val['answer'] == 1)) {
543 $emojy_type = '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
544 }else{
545 $emojy_type = '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
546 }
547 $content .= '<div class="answer-title flex-apm">
548 <span class="answer-text">'.$emojy_type.'</span>
549 <span class="answer-votes">'.$all_votes_bar.' ('.$percent.'%)</span>
550 </div>
551 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$polls_options['main_color'].'; color: '.$polls_options['bg_color'].';">'.$perc_cont.'</div>';
552
553 break;
554 default:
555 break;
556 }
557 break;
558 default:
559 break;
560 }
561
562 }
563 }
564
565 $content .= '</div>
566 </div>';
567 }
568
569 echo $content;
570
571 return str_replace(array("\r\n", "\n", "\r"), '', ob_get_clean());
572 }
573
574 public function ays_poll_all_generate_shortcode($attr) {
575 ob_start();
576 global $wpdb;
577
578 $check_published = "published";
579 if(is_array($attr) && !empty($attr)){
580 $check_published = isset($attr['display']) && $attr['display'] == "all" ? "all" : "published";
581 }
582
583 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
584 $sql = "SELECT id FROM ".$poll_table;
585 $poll = $wpdb->get_results($sql, 'ARRAY_A');
586
587 $this->enqueue_styles();
588 $this->enqueue_scripts();
589 $checker = array();
590 foreach ($poll as $poll_id) {
591 $current_id = isset($poll_id['id']) ? $poll_id['id'] : "";
592 $check_poll = $this->check_shedule_expired_poll( $current_id );
593 $checker[] = $check_poll;
594 if($check_published == 'published'){
595 if ($check_poll) {
596 $this->show_poll($poll_id);
597 }
598 }
599 elseif($check_published == 'all'){
600 $this->show_poll($poll_id);
601 }
602 }
603
604 if(array_sum($checker) == 0){
605 $poll_settings = $this->settings;
606 $general_options = ($poll_settings->ays_get_setting('options') !== false) ? json_decode($poll_settings->ays_get_setting('options') , true) : array();
607 $message = '';
608 if(!empty($general_options)){
609 $message = (isset($general_options['all_shortcode_message']) && $general_options['all_shortcode_message'] != '') ? esc_html($general_options['all_shortcode_message']) : '';
610 }
611 echo '<div class="ays_poll_all_res_none_message">'.$message.'</div>';
612 }
613
614 return str_replace(array("\r\n", "\n", "\r"), '', ob_get_clean());
615 }
616
617 public function ays_poll_generate_shortcode( $attr ) {
618 ob_start();
619
620 $this->enqueue_styles();
621 $this->enqueue_scripts();
622
623 $this->show_poll($attr);
624
625 return str_replace(array("\r\n", "\n", "\r"), '', ob_get_clean());
626 }
627
628 public function show_poll( $attr ) {
629 if (isset($attr['id'])) {
630 return $this->ays_poll_generate_html($attr['id']);
631 } elseif (isset($attr['cat_id'])) {
632 return $this->ays_poll_category_generate_html($attr);
633 }
634 }
635
636 public function ays_poll_generate_html( $poll_id, $echo = true, $width = -1 ) {
637 global $wpdb;
638 if (!isset($poll_id) || null == $poll_id) {
639 return "";
640 }
641
642 $id = absint($poll_id);
643 $poll = $this->get_poll_by_id($id);
644 if (empty($poll)) {
645 return "";
646 }
647
648 $this_poll_id = uniqid("ays-poll-id-");
649 $options = $poll['styles'];
650 $poll_settings = $this->settings;
651 $general_options = ($poll_settings->ays_get_setting('options') === false) ? json_encode(array()) : json_decode($poll_settings->ays_get_setting('options'), true);
652
653 if (isset($options['published']) && intval($options['published']) === 0) {
654 return "";
655 }
656
657 $info_form = !empty($options['info_form']) && !empty($options['fields']);
658 $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());
661
662 $is_expired = false;
663 $is_start_soon = false;
664 $startDate = '';
665 $endDate = '';
666 $current_time = strtotime(current_time( "Y:m:d H:i:s" ));
667 $poll_check_exp_cont = isset($options['dont_show_poll_cont']) && $options['dont_show_poll_cont'] == 'on' ? true : false;
668 if (isset($options['active_date_check']) && !empty($options['active_date_check'])) {
669 if (isset($options['activeInterval']) && isset($options['deactiveInterval'])) {
670 if (isset($options['activeIntervalSec']) && !empty($options['activeIntervalSec'])) {
671 $startDate = strtotime($options['activeInterval']." ".$options['activeIntervalSec']);
672 $startDate_atr = $startDate - $current_time;
673 }
674 else{
675 $startDate = strtotime($options['activeInterval']);
676 $startDate_atr = $startDate - $current_time;
677 }
678
679 if (isset($options['deactiveIntervalSec']) && !empty($options['deactiveIntervalSec'])) {
680 $endDate = strtotime($options['deactiveInterval']." ".$options['deactiveIntervalSec']);
681 $endDate_atr = $endDate - $current_time;
682 }
683 else{
684 $endDate = strtotime($options['deactiveInterval']);
685 $endDate_atr = $endDate - $current_time;
686 }
687
688 if ($startDate > $current_time) {
689 $is_start_soon = true;
690 }
691
692 if ($startDate > $current_time || $endDate < $current_time) {
693 $is_expired = true;
694 }
695 }
696 }
697
698 $poll_directions = isset($options['poll_direction']) && $options['poll_direction'] != '' ? $options['poll_direction'] : 'ltr';
699
700 switch ($poll_directions) {
701 case 'ltr':
702 $poll_direction = 'ltr';
703 break;
704
705 case 'center':
706 $poll_direction = 'center';
707 break;
708
709 case 'rtl':
710 $poll_direction = 'rtl';
711 break;
712 default:
713 $poll_direction = 'ltr';
714 break;
715 }
716
717 if ($poll_direction == 'center') {
718 $poll_direction_center = "justify-content: center;";
719 }else{
720 $poll_direction_center = "";
721 }
722
723 $load_effect = isset($options['load_effect']) ? $options['load_effect'] : "opacity";
724 $load_gif = isset($options['load_effect']) && $options['load_effect'] == 'load_gif' && isset($options['load_gif']) ? $options['load_gif'] : "";
725 $poll_load_message_data = "";
726 if(isset($options['load_effect']) && $options['load_effect'] == "message"){
727 $poll_load_message = isset($options['effect_message']) && $options['effect_message'] != "" ? esc_attr($options['effect_message']) : "";
728 $poll_load_message_data = 'data-load-message="'.$poll_load_message.'"';
729 }
730 $result_sort = isset($options['result_sort_type']) ? $options['result_sort_type'] : "none";
731 if (isset($options['show_social']) && $options['show_social'] == 1) {
732 $show_social = true;
733 } else {
734 $show_social = false;
735 }
736
737 $without_vote = isset($options['enable_vote_btn']) && $options['enable_vote_btn'] == 0 ? 'apm-answers-without-submit' : "";
738 $with_vote = isset($options['enable_vote_btn']) && $options['enable_vote_btn'] != 0 ? true : false;
739
740 // Allow custom answer
741 $poll_allow_answer = (isset($options['poll_allow_answer']) && $options['poll_allow_answer'] == "on") ? "checked" : "";
742 // Require admin approval
743 $poll_allow_answer_require = (isset($options['poll_allow_answer_require']) && $options['poll_allow_answer_require'] == "on") ? "checked" : "";
744
745 if (isset($options['hide_results']) && $options['hide_results'] == 1) {
746 $hide_results = "1";
747 if (!empty($options['hide_results_text'])) {
748 $hide_results_text = wpautop($options['hide_results_text']);
749 } else {
750 $hide_results_text =esc_html__("Thanks for your answer", "poll-maker");
751 }
752 } else {
753 $hide_results = "0";
754 $hide_results_text = "";
755 }
756
757 if (isset( $options['redirect_after_submit'] ) && $options['redirect_after_submit'] == 1) {
758 $redirect_after_vote_url = '';
759 $redirect_users = 0;
760 $check_delay = isset($options['poll_enable_answer_redirect_delay']) && $options['poll_enable_answer_redirect_delay'] == "on" ? true : false;
761 $redirect_delay = 0;
762 if($check_delay){
763 $redirect_delay = isset($options['poll_every_answer_redirect_delay']) && $options['poll_every_answer_redirect_delay'] != "" ? esc_attr($options['poll_every_answer_redirect_delay']) : 0;
764 }
765 $redirect_url_href = '';
766 $redirect_url_checked = 1;
767 $redirect_after_vote = "<p class='redirectionAfterVote'>" .esc_html__("You will be redirected", "poll-maker") . " " . ($redirect_delay <= 0 ? "" :esc_html__("after", "poll-maker") . " <span>" . $redirect_delay . "</span>" . " " .esc_html__("seconds", "poll-maker")) . "</p>";
768 }elseif (isset($options['redirect_users']) && $options['redirect_users'] != 0 && !empty($options['redirect_after_vote_url'])) {
769 $redirect_after_vote_url = stripslashes($options['redirect_after_vote_url']);
770 $redirect_url_href = '';
771 $redirect_users = $options['redirect_users'];
772 $redirect_delay = $options['redirect_after_vote_delay'];
773 $redirect_url_checked = 0;
774 $redirect_after_vote = "<p class='redirectionAfterVote'>" .esc_html__("You will be redirected", "poll-maker") . " " . ($redirect_delay <= 0 ? "" :esc_html__("after", "poll-maker") . " <span>" . $redirect_delay . "</span>" . " " .esc_html__("seconds", "poll-maker")) . "</p>";
775 } else {
776 $redirect_after_vote_url = '';
777 $redirect_url_href = '';
778 $redirect_users = 0;
779 $redirect_delay = 0;
780 $redirect_url_checked = 0;
781 $redirect_after_vote = "";
782 }
783
784 $limit_users = 0;
785 $limitusers = isset($options['limit_users']) ? intval($options['limit_users']) : 0;
786 $load_poll = false;
787 $emoji = array(
788 "<i class='ays_poll_far ays_poll_fa-dizzy'></i>",
789 "<i class='ays_poll_far ays_poll_fa-smile'></i>",
790 "<i class='ays_poll_far ays_poll_fa-meh'></i>",
791 "<i class='ays_poll_far ays_poll_fa-frown'></i>",
792 "<i class='ays_poll_far ays_poll_fa-tired'></i>",
793 );
794
795 $bg_color = $options['bg_color'];
796 $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 // }
803 if( $bg_image != "" ){
804 $check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($bg_image);
805
806 if( !$check_if_current_image_exists ){
807 $bg_image = "";
808 }
809 }
810 $main_color = $options['main_color'];
811 $text_color = $options['text_color'];
812 $button_text_color = isset($options['button_text_color']) ? $options['button_text_color'] : $bg_color;
813 $button_bg_color = isset($options['button_bg_color']) ? $options['button_bg_color'] : $main_color;
814 $icon_color = $options['icon_color'];
815 $answer_bg_color = isset($options['answer_bg_color']) ? $options['answer_bg_color'] : 'transparent';
816 $answer_hover_color = isset($options['answer_hover_color']) ? $options['answer_hover_color'] : $text_color;
817 $answer_border_side = isset($options['answer_border_side']) ? $options['answer_border_side'] : 'all_sides';
818 $title_bg_color = isset($options['title_bg_color']) ? $options['title_bg_color'] : 'transparent';
819
820 $enable_pass_count = (isset($options['enable_pass_count']) && $options['enable_pass_count'] == 'on') ? true : false;
821
822 $poll_theme = isset($poll['theme_id']) && absint($poll['theme_id']) == 3 ? 'ays-minimal-theme' : '';
823
824 $answer_percent_color = $this->rgb2hex($main_color);
825 if (isset($poll['theme_id']) && absint($poll['theme_id']) != '') {
826 switch ( absint($poll['theme_id']) ) {
827 case 3:
828 case 7:
829 $answer_percent_color = $this->rgb2hex($icon_color);
830 break;
831 default:
832 $answer_percent_color = $this->rgb2hex($main_color);
833 break;
834 }
835 }
836
837 if ($enable_pass_count) {
838 $poll_result_reports = $this->get_poll_results_count_by_id($id);
839 $poll_result_reports = "<span class='ays_poll_passed_count'><i class='ays_poll_fa ays_poll_fa-users' aria-hidden='true'></i> " . $poll_result_reports['res_count'] . "</span>";
840 } else {
841 $poll_result_reports = '';
842 }
843 if ($width < 0) {
844 $poll_width = $options['width'] > 0 ? $options['width'] . "px" : "100%";
845 } elseif ($width == 0) {
846 $poll_width = "100%";
847 } else {
848 $poll_width = $width . "px";
849 }
850
851 $width_for_mobile = ( isset( $options['width_for_mobile'] ) && $options['width_for_mobile'] != '' ) ? absint( $options['width_for_mobile'] ) : 0;
852
853 if ($width_for_mobile < 0) {
854 $poll_width_for_mobile = $width_for_mobile > 0 ? $width_for_mobile . "px" : "100%";
855 } elseif ($width_for_mobile == 0) {
856 $poll_width_for_mobile = "100%";
857 } else {
858 $poll_width_for_mobile = $width_for_mobile . "px";
859 }
860
861 $ays_see_result_button = (isset($options['see_res_btn_text']) && $options['see_res_btn_text'] != '') ? stripslashes( esc_attr( $options['see_res_btn_text'] )) : 'See Results';
862
863 if ($ays_see_result_button === 'See Results') {
864 $ays_see_result_button_text = esc_html__("See Results", "poll-maker");
865 }else{
866 $ays_see_result_button_text = $ays_see_result_button;
867 }
868
869 $pollTypeShort = array(
870 'choosing' => 'choose',
871 'voting' => 'rate',
872 'rating' => 'vote',
873 'text' => 'text'
874 );
875
876 $show_res_btn_sch = (isset($options['show_result_btn_schedule']) && $options['show_result_btn_schedule'] == 1) ? true : false;
877 $show_res_see = isset($options['show_result_btn_see_schedule']) && !empty($options['show_result_btn_see_schedule']) ? $options['show_result_btn_see_schedule'] : 'with_see';
878 $show_res_see_display = $show_res_see == 'without_see' ? 'display:none;' : '';
879 $see_result_button = '';
880 $see_result_button = wp_nonce_field('ays_finish_poll', 'ays_finish_poll_' . $poll_id) . "<div class='apm-button-box' style='".$show_res_see_display."' >";
881 if($poll['type'] != "text"){
882 $see_result_button .= "<input id='ays_res_". $show_res_see ."' type='button' class='btn ays-poll-btn {$poll['type']}-btn ays-see-res-button-show' data-form='$this_poll_id' value='" . $ays_see_result_button_text . "' data-seeRes='true' data-pollType='".$pollTypeShort[$poll['type']]."' >";
883 }
884 $see_result_button .= '</div>';
885
886 // Results bar in RGBA
887 $result_in_rgba = (isset($options['result_in_rgba']) && $options['result_in_rgba'] == 'on' ) ? true : false;
888
889 // Enable View more button
890 $enable_view_more_button = (isset($options['enable_view_more_button']) && $options['enable_view_more_button'] == 'on' ) ? true : false;
891 $poll_view_more_button_count = (isset($options['poll_view_more_button_count']) && $options['poll_view_more_button_count'] != '' ) ? absint(intval($options['poll_view_more_button_count'])) : 0;
892
893 /*
894 * Poll container background gradient
895 *
896 */
897
898 // Checking exists background gradient option
899 $options['enable_background_gradient'] = (!isset($options['enable_background_gradient'])) ? "off" : $options['enable_background_gradient'];
900
901 if(isset($options['background_gradient_color_1']) && $options['background_gradient_color_1'] != ''){
902 $background_gradient_color_1 = $options['background_gradient_color_1'];
903 }else{
904 $background_gradient_color_1 = "#103251";
905 }
906
907 if(isset($options['background_gradient_color_2']) && $options['background_gradient_color_2'] != ''){
908 $background_gradient_color_2 = $options['background_gradient_color_2'];
909 }else{
910 $background_gradient_color_2 = "#607593";
911 }
912
913 if(isset($options['poll_gradient_direction']) && $options['poll_gradient_direction'] != ''){
914 $poll_gradient_direction = $options['poll_gradient_direction'];
915 }else{
916 $poll_gradient_direction = 'vertical';
917 }
918 switch($poll_gradient_direction) {
919 case "horizontal":
920 $poll_gradient_direction = "to right";
921 break;
922 case "diagonal_left_to_right":
923 $poll_gradient_direction = "to bottom right";
924 break;
925 case "diagonal_right_to_left":
926 $poll_gradient_direction = "to bottom left";
927 break;
928 default:
929 $poll_gradient_direction = "to bottom";
930 }
931
932 // Poll container background gradient enabled/disabled
933 if(isset($options['enable_background_gradient']) && $options['enable_background_gradient'] == "on"){
934 $enable_background_gradient = true;
935 }else{
936 $enable_background_gradient = false;
937 }
938
939 if( isset($bg_image) && $bg_image != false){
940 $poll_styles = "background-image: url('".$bg_image."');";
941 }elseif($enable_background_gradient) {
942 $poll_styles = "background-image: linear-gradient($poll_gradient_direction, $background_gradient_color_1, $background_gradient_color_2);";
943 }elseif (isset($bg_color)) {
944 $poll_styles = "background-color: ".$bg_color.";";
945 }
946 else{
947
948 $poll_styles = "background-image: unset;";
949 }
950
951 $options['enable_answer_style'] = isset($options['enable_answer_style']) ? $options['enable_answer_style'] : 'on';
952
953 $answer_style = $options['enable_answer_style'] == 'on' ? true : false;
954
955 $disable_answer_hover = isset($options['disable_answer_hover']) && $options['disable_answer_hover'] == 1 ? 'disable_hover' : 'ays_enable_hover';
956
957 //Bg image position
958 $poll_bg_image_position = (isset($options['poll_bg_image_position']) && $options['poll_bg_image_position'] != "") ? $options['poll_bg_image_position'] : 'center center';
959 $poll_bg_img_in_finish_page = (isset($options['poll_bg_img_in_finish_page']) && $options['poll_bg_img_in_finish_page'] == "on") ? 'true' : "false";
960 $poll_bg_img_in_finish_page_off_color = (isset($options['bg_color']) && $options['bg_color'] != "") ? esc_attr($options['bg_color']) : "false";
961
962 // Poll minimal height
963 $poll_min_height_val = (isset($options['poll_min_height']) && $options['poll_min_height'] != '') ? absint(intval($options['poll_min_height'])) : 0;
964
965 // Poll answer font size
966 $poll_answer_font_size = (isset($options['answer_font_size']) && $options['answer_font_size'] != '') ? $options['answer_font_size']."px" : '15px';
967
968 // Poll answers font size on mobile
969 $poll_answer_font_size_mobile = (isset($options['poll_answer_font_size_mobile']) && $options['poll_answer_font_size_mobile'] != '') ? esc_attr($options['poll_answer_font_size_mobile']) : '16';
970
971 // Poll see results button in limitations
972 $poll_see_result_button_check = (isset($options['see_result_button']) && $options['see_result_button'] == 'on') ? true : false;
973
974 // Loading font size
975 $poll_loader_font_size = (isset($options['loader_font_size']) && $options['loader_font_size'] != '') ? esc_attr($options['loader_font_size']) : '64';
976 if(!isset($options['see_result_button'])){
977 $poll_see_result_button_check = true;
978 }
979 $poll_see_result_radio = (isset($options['see_result_radio']) && $options['see_result_radio'] != '') ? esc_attr($options['see_result_radio']) : 'ays_see_result_button';
980 $poll_show_result_button_limit = isset($poll_see_result_radio) && $poll_see_result_radio == 'ays_see_result_button' ? true : false;
981 $poll_see_result_immediately = isset($poll_see_result_radio) && $poll_see_result_radio == 'ays_see_result_immediately' ? true : false;
982 $poll_show_avatars = isset($options['show_passed_users']) && $options['show_passed_users'] == "on" ? true : false;
983 $poll_logo_image = (isset($options['logo_image']) && $options['logo_image'] != '') ? esc_url($options['logo_image']) : '';
984 // if ($poll_logo_image != '') {
985 // if ( !(filter_var($poll_logo_image, FILTER_VALIDATE_URL) && wp_http_validate_url($poll_logo_image)) ) {
986 // // invalid URL, handle accordingly
987 // $poll_logo_image = '';
988 // }
989 // }
990 if( $poll_logo_image != "" ){
991 $check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($poll_logo_image);
992
993 if( !$check_if_current_image_exists ){
994 $poll_logo_image = "";
995 }
996 }
997
998 $poll_logo_check = (isset($poll_logo_image) && $poll_logo_image != '') ? true : false;
999 $poll_image_cont = '';
1000 // Poll logo image url
1001 $poll_logo_image_url = isset($options['poll_logo_url']) && $options['poll_logo_url'] != "" ? esc_attr($options['poll_logo_url']) : "";
1002 $poll_logo_image_url_check = isset($options['poll_enable_logo_url']) && $options['poll_enable_logo_url'] == "on" ? true : false;
1003 $poll_logo_image_url_href = "javascript:void(0)";
1004 if($poll_logo_image_url_check){
1005 if($poll_logo_image_url != ""){
1006 if(filter_var($poll_logo_image_url, FILTER_VALIDATE_URL)){
1007 $poll_logo_image_url_href = $poll_logo_image_url;
1008 }
1009 }
1010 }
1011
1012 //Open logo URL in new tab
1013 $options['poll_logo_url_new_tab' ] = (isset($options['poll_logo_url_new_tab' ]) && $options['poll_logo_url_new_tab' ] == 'on') ? 'on' : 'off';
1014 $poll_logo_image_url_check_new_tab = (isset($options['poll_logo_url_new_tab' ]) && $options['poll_logo_url_new_tab' ] == 'on') ? true : false;
1015
1016 $target_blank = ( $poll_logo_image_url_check_new_tab && $poll_logo_image_url_check && $poll_logo_image_url != "" ) ? "target='_blank'" : "" ;
1017
1018 //Poll Logo title
1019 $poll_logo_title = (isset( $options['poll_logo_title' ] ) && $options['poll_logo_title' ] != '') ? esc_attr( $options['poll_logo_title' ] ) : '';
1020
1021 if($poll_logo_check){
1022 $poll_image_cont = "<div class='ays-image-logo-show'><a href='".$poll_logo_image_url_href."' class='ays-poll-logo-image-url-link' {$target_blank} ><img src=".$poll_logo_image." class='ays-poll-image-logo' title='".$poll_logo_title."'></a></div>";
1023 }
1024
1025 if ($poll_min_height_val == 0) {
1026 $poll_min_height = '';
1027 }else{
1028 $poll_min_height = 'min-height: '. $poll_min_height_val .'px;';
1029 }
1030
1031 // Show answers numbering
1032 $show_answers_numbering = (isset($options['show_answers_numbering']) && sanitize_text_field( $options['show_answers_numbering'] ) != '') ? sanitize_text_field( $options['show_answers_numbering'] ) : 'none';
1033
1034 // Poll border color
1035 $poll_border_color = (isset($options['border_color']) && $options['border_color'] != '') ? sanitize_text_field( $options['border_color'] ) : $main_color;
1036
1037 $enable_box_shadow = isset($options['enable_box_shadow']) && $options['enable_box_shadow'] == "on" ? true : false;
1038
1039 $box_shadow_color = isset($options['box_shadow_color']) && $options['box_shadow_color'] != "" ? esc_attr($options['box_shadow_color']) : "";
1040 // Box Shadow X offset
1041 $poll_box_shadow_x_offset = (isset($options['poll_box_shadow_x_offset']) && $options['poll_box_shadow_x_offset'] != '' && $options['poll_box_shadow_x_offset'] != 0 ) ? intval( esc_attr( $options['poll_box_shadow_x_offset'] ) ) : 0;
1042
1043 // Box Shadow Y offset
1044 $poll_box_shadow_y_offset = (isset($options['poll_box_shadow_y_offset']) && $options['poll_box_shadow_y_offset'] != '' && $options['poll_box_shadow_y_offset'] != 0 ) ? intval( esc_attr( $options['poll_box_shadow_y_offset'] ) ) : 0;
1045
1046 // Box Shadow Z offset
1047 $poll_box_shadow_z_offset = (isset($options['poll_box_shadow_z_offset']) && $options['poll_box_shadow_z_offset'] != '' && $options['poll_box_shadow_z_offset'] != 0 ) ? intval( esc_attr( $options['poll_box_shadow_z_offset'] ) ) : 15;
1048
1049 // Poll Vote Reason
1050 $poll_vote_reason = (isset($options['poll_vote_reason']) && $options['poll_vote_reason'] == 'on') ? true : false;
1051
1052 if($enable_box_shadow){
1053 $box_shadow_offsets = $poll_box_shadow_x_offset . 'px ' . $poll_box_shadow_y_offset . 'px ' . $poll_box_shadow_z_offset . 'px ' . '1px ' . $box_shadow_color;
1054 }
1055 else{
1056 $box_shadow_offsets = "none";
1057 }
1058
1059 if ($poll_vote_reason) {
1060 $vote_reason = "<div class='ays-poll-vote-reason'>
1061 <div class='ays-poll-for-reason'>".esc_html__("Please add vote reason", "poll-maker")."</div>
1062 <div><textarea name='ays-poll-reason-text' id='ays-poll-reason-text'></textarea></div>
1063 </div>";
1064 } else {
1065 $vote_reason = "";
1066 }
1067
1068 // Enable/disable grid column layout for answers on mobile devices
1069 $options['answers_grid_column_mobile'] = isset($options['answers_grid_column_mobile']) ? $options['answers_grid_column_mobile'] : 'on';
1070 $answers_grid_column_mobile = (isset($options['answers_grid_column_mobile']) && $options['answers_grid_column_mobile'] == 'on') ? true : false;
1071
1072 // Show answers icon
1073 $poll_answer_icon_check = (isset($options['poll_answer_icon_check']) && $options['poll_answer_icon_check'] == 'on') ? true : false;
1074 $poll_answer_icon = isset($options['poll_answer_icon']) ? $options['poll_answer_icon'] : 'radio';
1075
1076 // Poll question font size
1077 $poll_question_font_size_pc = isset($options['poll_question_size_pc']) && $options['poll_question_size_pc'] != "" ? esc_attr($options['poll_question_size_pc']) : "16";
1078 $poll_question_font_size_mobile = isset($options['poll_question_size_mobile']) && $options['poll_question_size_mobile'] != "" ? esc_attr($options['poll_question_size_mobile']) : "16";
1079
1080 // Poll question image height
1081 $poll_question_image_height = isset($options['poll_question_image_height']) && $options['poll_question_image_height'] != "" ? esc_attr($options['poll_question_image_height'])."px" : "100%";
1082
1083 // Poll answer image height
1084 $poll_question_image_object_fit = (isset($options['poll_question_image_object_fit']) && $options['poll_question_image_object_fit'] != "") ? esc_attr($options['poll_question_image_object_fit']) : "cover";
1085
1086 // Poll container max-width for mobile
1087 $poll_mobile_max_width = isset($options['poll_mobile_max_width']) && $options['poll_mobile_max_width'] != '' ? esc_attr($options['poll_mobile_max_width']) . '%' : "100%";
1088
1089 // Titile text shadow
1090 $options['enable_poll_title_text_shadow'] = (isset($options['enable_poll_title_text_shadow']) && $options['enable_poll_title_text_shadow'] == 'on') ? 'on' : 'off';
1091
1092 $enable_poll_title_text_shadow = (isset($options['enable_poll_title_text_shadow']) && $options['enable_poll_title_text_shadow'] == 'on') ? true : false;
1093
1094 $poll_title_text_shadow = ( isset( $options['poll_title_text_shadow'] ) && $options['poll_title_text_shadow'] != '' ) ? stripslashes( esc_attr( $options['poll_title_text_shadow'] ) ) : 'rgba(255,255,255,0)';
1095
1096 $poll_title_text_shadow_x_offset = (isset($options['poll_title_text_shadow_x_offset']) && $options['poll_title_text_shadow_x_offset'] != '') ? stripslashes( esc_attr( $options['poll_title_text_shadow_x_offset'] ) ) : 2;
1097
1098 $poll_title_text_shadow_y_offset = (isset($options['poll_title_text_shadow_y_offset']) && $options['poll_title_text_shadow_y_offset'] != '') ? stripslashes( esc_attr( $options['poll_title_text_shadow_y_offset'] ) ) : 2;
1099
1100 $poll_title_text_shadow_z_offset = (isset($options['poll_title_text_shadow_z_offset']) && $options['poll_title_text_shadow_z_offset'] != '') ? stripslashes( esc_attr( $options['poll_title_text_shadow_z_offset'] ) ) : 0;
1101
1102 if( $enable_poll_title_text_shadow ){
1103 $title_text_shadow = 'text-shadow: '.$poll_title_text_shadow_x_offset.'px '.$poll_title_text_shadow_y_offset.'px '.$poll_title_text_shadow_z_offset.'px '.$poll_title_text_shadow;
1104 }else{
1105 $title_text_shadow = "";
1106 }
1107
1108 // ==== Buttons styles start ====
1109
1110 // Buttons font size
1111 $buttons_font_size = isset($options['poll_buttons_font_size']) && $options['poll_buttons_font_size'] != '' ? esc_attr($options['poll_buttons_font_size']) . 'px' : '17px';
1112 // Poll button text color
1113 $poll_button_text_color = (isset($options['button_text_color']) && $options['button_text_color'] != '') ? sanitize_text_field( $options['button_text_color'] ) : $button_text_color;
1114 // Poll button background color
1115 $button_bg_color = (isset($options['button_bg_color']) && $options['button_bg_color'] != '') ? sanitize_text_field( $options['button_bg_color'] ) : $button_bg_color;
1116 // Buttons mobile font size
1117 $poll_buttons_mobile_font_size = isset($options['poll_buttons_mobile_font_size']) && $options['poll_buttons_mobile_font_size'] != '' ? esc_attr($options['poll_buttons_mobile_font_size']) . 'px' : $buttons_font_size;
1118 // Buttons Left / Right padding
1119 $buttons_left_right_padding = isset($options['poll_buttons_left_right_padding']) && $options['poll_buttons_left_right_padding'] != '' ? esc_attr($options['poll_buttons_left_right_padding']) . 'px' : '20px';
1120 // Buttons Top / Bottom padding
1121 $buttons_top_bottom_padding = isset($options['poll_buttons_top_bottom_padding']) && $options['poll_buttons_top_bottom_padding'] != '' ? esc_attr($options['poll_buttons_top_bottom_padding']) . 'px' : '10px';
1122 // Buttons border radius
1123 $buttons_border_radius = isset($options['poll_buttons_border_radius']) && $options['poll_buttons_border_radius'] != '' ? esc_attr($options['poll_buttons_border_radius']) . 'px' : '3px';
1124 // Buttons width
1125 $buttons_width = isset($options['poll_buttons_width']) && $options['poll_buttons_width'] != '' ? esc_attr($options['poll_buttons_width']) . 'px' : 'auto';
1126 // Buttons mobile width
1127 $buttons_mobile_width = isset($options['poll_buttons_mobile_width']) && $options['poll_buttons_mobile_width'] != '' ? esc_attr($options['poll_buttons_mobile_width']) . 'px' : 'auto';
1128
1129 // Poll View Type
1130 $answer_view_type_old = isset($options['poll_answer_view_type']) && $options['poll_answer_view_type'] != '' ? esc_attr($options['poll_answer_view_type']) : 'list';
1131 $answer_view_type = isset($poll['view_type']) && $poll['view_type'] != '' ? esc_attr($poll['view_type']) : $answer_view_type_old;
1132
1133 $answers_container = "";
1134 if($answer_view_type == "grid" && $poll['type'] == "choosing"){
1135 $answers_container = "ays_poll_grid_view_container";
1136 }
1137 elseif($answer_view_type == "list" && $poll['type'] == "choosing"){
1138 $answers_container = "ays_poll_list_view_container";
1139
1140 }
1141
1142 // ==== Buttons styles end ====
1143 $poll_answer_image_height = "150";
1144 $poll_answer_object_fit = "cover";
1145 $poll_answer_padding = "10";
1146 $poll_answer_margin = "1";
1147 $poll_answer_image_height_for_mobile = "150";
1148 $poll_answer_image_border_radius = 0;
1149 if($answer_style){
1150 // Poll answer image height
1151 $poll_answer_image_height = (isset($options['poll_answer_image_height']) && $options['poll_answer_image_height'] != "") ? esc_attr($options['poll_answer_image_height']) : "150";
1152 // Poll answer image height for mobile
1153 $poll_answer_image_height_for_mobile = (isset($options['poll_answer_image_height_for_mobile']) && $options['poll_answer_image_height_for_mobile'] != "") ? esc_attr($options['poll_answer_image_height_for_mobile']) : "150";
1154 // Poll answer image border radius
1155 $poll_answer_image_border_radius = (isset($options['poll_answer_image_border_radius']) && $options['poll_answer_image_border_radius'] != "") ? esc_attr($options['poll_answer_image_border_radius']) : 0;
1156 // Poll answer image object fit
1157 $poll_answer_object_fit = (isset($options['poll_answer_object_fit']) && $options['poll_answer_object_fit'] != "") ? esc_attr($options['poll_answer_object_fit']) : "cover";
1158 // Poll answer padding
1159 $poll_answer_padding = (isset($options['poll_answer_padding']) && $options['poll_answer_padding'] != "") ? esc_attr($options['poll_answer_padding']) : "10";
1160 // Poll answer gap
1161 $poll_answer_margin = (isset($options['poll_answer_margin']) && $options['poll_answer_margin'] != "" && intval($options['poll_answer_margin']) != 0) ? esc_attr($options['poll_answer_margin']) : "1";
1162 }
1163
1164 // Poll title font size
1165 $poll_title_font_size = (isset($options['poll_title_font_size']) && $options['poll_title_font_size'] != "") ? absint(intval(esc_attr($options['poll_title_font_size']))) : "20";
1166
1167 // Poll title font size mobile
1168 $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
1170 // Poll title alignment
1171 $poll_title_alignment = ( isset($options['poll_title_alignment']) && $options['poll_title_alignment'] != "" ) ? esc_attr($options['poll_title_alignment']) : "center";
1172
1173 // Poll title alignment mobile
1174 $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
1176 // ===== Poll text type options start =====
1177 $poll_view_type_text = isset($poll['view_type']) && $poll['view_type'] != "" ? $poll['view_type'] : "short_text";
1178
1179 $poll_text_type_length_enable = (isset($options['poll_text_type_length_enable']) && $options['poll_text_type_length_enable'] == "on") ? true : false;
1180 $poll_text_type_limit_type = (isset($options['poll_text_type_limit_type']) && $options['poll_text_type_limit_type'] != "") ? esc_attr($options['poll_text_type_limit_type']) : "characters";
1181 $poll_text_type_limit_length = (isset($options['poll_text_type_limit_length']) && $options['poll_text_type_limit_length'] != "") ? esc_attr($options['poll_text_type_limit_length']) : "";
1182 $poll_text_type_limit_message = (isset($options['poll_text_type_limit_message']) && $options['poll_text_type_limit_message'] == "on") ? true : false;
1183 $poll_text_type_width = (isset($options['poll_text_type_width']) && $options['poll_text_type_width'] != "") ? stripslashes(esc_attr($options['poll_text_type_width'])) : "";
1184 $poll_text_type_width_type = (isset($options['poll_text_type_width_type']) && $options['poll_text_type_width_type'] != "") ? esc_attr($options['poll_text_type_width_type']) : "percent";
1185
1186 $poll_class_for_limits = $poll_text_type_length_enable ? "ays_poll_question_limit_length" : "";
1187 $poll_box_for_limit_message = "";
1188
1189 if($poll_text_type_limit_message && ($poll_text_type_limit_length != "" && intval($poll_text_type_limit_length) != 0)){
1190 $poll_box_for_limit_message = '<div class="ays_quiz_question_text_conteiner">
1191 <div class="ays_quiz_question_text_message">
1192 <span class="ays_poll_question_text_message_span">'. $poll_text_type_limit_length . '</span> ' . $poll_text_type_limit_type . ' '. esc_html__( ' left' , "poll-maker" ) . '
1193 </div>
1194 </div>';
1195 }
1196 $poll_text_type_ready_width = "";
1197 $poll_text_type_ready_type = "%";
1198 if($poll['type'] == 'text'){
1199 if($poll_view_type_text == "short_text"){
1200 if($poll_text_type_width == "" || intval($poll_text_type_width) == 0){
1201 $poll_text_type_ready_width = "60";
1202 $poll_text_type_ready_type = "%";
1203 }
1204 else{
1205 $poll_text_type_ready_width = $poll_text_type_width;
1206 $poll_text_type_ready_type = ($poll_text_type_width_type == "percent" ? "%" : "px");
1207 }
1208 }
1209 else{
1210 if($poll_text_type_width == "" || intval($poll_text_type_width) == 0){
1211 $poll_text_type_ready_width = "100";
1212 $poll_text_type_ready_type = "%";
1213 }
1214 else{
1215 $poll_text_type_ready_width = $poll_text_type_width;
1216 $poll_text_type_ready_type = ($poll_text_type_width_type == "percent" ? "%" : "px");
1217 }
1218 }
1219 }
1220 // ===== Poll text type options end =====
1221
1222 $poll_password_box = '';
1223 $form_method = '';
1224 $password_message_with_toggle = "";
1225 $password_message_with_toggle_class = "";
1226
1227 $poll_enable_password = isset($options['poll_enable_password']) && $options['poll_enable_password'] == 'on' ? true : false;
1228 $poll_password_poll = isset($options['poll_password']) && $options['poll_password'] != "" ? stripslashes(esc_attr($options['poll_password'])) : "";
1229
1230 // Enable toggle password visibility
1231 $options['poll_enable_password_visibility'] = isset($options['poll_enable_password_visibility']) ? $options['poll_enable_password_visibility'] : 'off';
1232 $poll_enable_password_visibility = (isset($options['poll_enable_password_visibility']) && $options['poll_enable_password_visibility'] == 'on') ? true : false;
1233
1234
1235 $password_input_val = isset($_POST['ays_poll_password_val_'. $id ]) && $_POST['ays_poll_password_val_'. $id ] != "" ? stripslashes(esc_attr($_POST['ays_poll_password_val_'. $id ])) : '';
1236 $poll_password_message = (isset($options['poll_password_message']) && $options['poll_password_message'] != '') ? stripslashes( wpautop( $options['poll_password_message'] ) ) : "<p>" .esc_html__( "Please enter password", "poll-maker" ) . "</p>";
1237
1238 $poll_check_only_logged = (isset($options['enable_logged_users']) && $options['enable_logged_users'] == 1 && !is_user_logged_in()) ? true : false;
1239 $poll_password_message_input = "<input type='password' class='ays-poll-password-input' id='ays_poll_password_val_". $id ."' name='ays_poll_password_val_". $id ."' required autocomplete='off'>";
1240
1241 if ( $poll_enable_password_visibility ) {
1242 $password_message_with_toggle_class = "ays-poll-password-input-box-visibility";
1243 $password_message_with_toggle .= "<img src='". esc_url(POLL_MAKER_AYS_PUBLIC_URL) ."/images/poll-maker-eye-visibility-off.svg' class='ays-poll-password-toggle ays-poll-password-toggle-visibility-off'>";
1244 $password_message_with_toggle .= "<img src='". esc_url(POLL_MAKER_AYS_PUBLIC_URL) ."/images/poll-maker-eye-visibility.svg' class='ays-poll-password-toggle ays-poll-password-toggle-visibility ays_poll_display_none'>";
1245 }
1246
1247
1248 if($poll_enable_password){
1249 $form_method = "method='post'";
1250 $poll_password_box = "<div style='padding:50px;text-align:center;' id='ays-poll-password-". $id ."' >
1251 <div class='ays-poll-password-title'>
1252 ". $poll_password_message . "
1253 </div>
1254 <div class='ays-poll-password-box '>
1255 <div class='ays-poll-password-input-box ays-poll-password-input-box-visibility'>
1256 ".$poll_password_message_input."
1257 ".$password_message_with_toggle."
1258 </div>
1259 <div class='ays-poll-password-button-box'>
1260 <input type='submit' class='ays-poll-password-button' name='ays_poll_password_sub_". $id ."' class='ays_poll_password' value='". esc_html__( "Submit", "poll-maker" )."'>
1261 </div>
1262 </div>
1263 </div></div></form></div>";
1264 }
1265 $poll_password_check = ($password_input_val == $poll_password_poll) ? true : false;
1266
1267 // Animation Top (px)
1268 $poll_animation_top = (isset($general_options['poll_animation_top']) && $general_options['poll_animation_top'] != '') ? absint(intval($general_options['poll_animation_top'])) : 100 ;
1269 $options['poll_enable_animation_top'] = isset($general_options['poll_enable_animation_top']) ? $general_options['poll_enable_animation_top'] : 'on';
1270 $poll_enable_animation_top = (isset($general_options['poll_enable_animation_top']) && $general_options['poll_enable_animation_top'] == "on") ? true : false;
1271
1272 // Answers box shadow
1273 $answers_box_shadow = (isset($options['poll_answer_enable_box_shadow']) && $options['poll_answer_enable_box_shadow'] == "on") ? true : false;
1274 $answers_box_shadow_color = isset($options['poll_answer_box_shadow_color']) && $options['poll_answer_box_shadow_color'] != '' ? esc_attr($options['poll_answer_box_shadow_color']) : '#000000';
1275
1276 $poll_answer_box_shadow_x_offset = isset($options['poll_answer_box_shadow_x_offset']) && $options['poll_answer_box_shadow_x_offset'] != '' ? intval($options['poll_answer_box_shadow_x_offset']) : 0;
1277
1278 $poll_answer_box_shadow_y_offset = isset($options['poll_answer_box_shadow_y_offset']) && $options['poll_answer_box_shadow_y_offset'] != '' ? intval($options['poll_answer_box_shadow_y_offset']) : 0;
1279
1280 $poll_answer_box_shadow_z_offset = isset($options['poll_answer_box_shadow_z_offset']) && $options['poll_answer_box_shadow_z_offset'] != '' ? intval($options['poll_answer_box_shadow_z_offset']) : 10;
1281
1282 $answers_box_shadow_content = 'box-shadow:unset';
1283 if($answers_box_shadow){
1284 $answers_box_shadow_content = 'box-shadow: '.$poll_answer_box_shadow_x_offset.'px '.$poll_answer_box_shadow_y_offset.'px '.$poll_answer_box_shadow_z_offset.'px '.$answers_box_shadow_color;
1285 }
1286
1287 $poll_answer_border_radius = isset($options['poll_answer_border_radius']) && $options['poll_answer_border_radius'] != '' ? intval(esc_attr($options['poll_answer_border_radius'])) : 0;
1288
1289 // Display form fields labels
1290 $options['display_fields_labels'] = isset($options['display_fields_labels']) ? $options['display_fields_labels'] : 'on';
1291 $display_fields_labels = (isset($options['display_fields_labels']) && $options['display_fields_labels'] == 'on') ? true : false;
1292
1293 // Social Media links
1294 $enable_social_links = (isset($options['enable_social_links']) && $options['enable_social_links'] == "on") ? true : false;
1295
1296 $show_chart_type = (isset($options['show_chart_type']) && $options['show_chart_type'] != "") ? $options['show_chart_type'] : "default_bar_chart";
1297
1298 $content = "<style>
1299
1300 #".$this_poll_id.".box-apm {
1301 width: $poll_width;
1302 ". $poll_min_height ."
1303 margin: 0 auto !important;
1304 border-style: {$options['border_style']};
1305 border-color: $poll_border_color;
1306 border-radius: " . ((isset($options['border_radius']) && !empty($options['border_radius'])) ? (int) $options['border_radius'] . 'px' : 0) . ";
1307 border-width: " . ((isset($options['border_width']) && $options['border_width'] != '') ? (int) $options['border_width'] . 'px' : '2px') . ";
1308 box-shadow: " . $box_shadow_offsets . ";".
1309 $poll_styles."
1310 background-position: ".$poll_bg_image_position.";
1311 background-repeat: no-repeat;
1312 background-size: cover;
1313 max-width: 100%;
1314 position: relative;
1315 padding-bottom: 60px;
1316 }
1317
1318 .$this_poll_id.ays-minimal-theme .apm-choosing{
1319 display: flex;
1320 align-items: center;
1321 }
1322
1323 .$this_poll_id div.ays-image-logo-show{
1324 position: absolute;
1325 bottom: -5px;
1326 left: 1px;
1327 margin: 2px 0 0 0;
1328 padding: 2px;
1329 width: 100%;
1330 height: 65px;
1331 text-align: left;
1332 }
1333 .$this_poll_id .ays-poll-image-logo{
1334 width: 55px;
1335 height: 55px;
1336 }
1337
1338 .$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 background-color: " . ($answer_hover_color ? $answer_hover_color : "initial") . " !important;
1340 color: $main_color !important;
1341 border-color: $main_color !important;
1342 font-weight: initial !important;
1343 margin:3px 0 !important;
1344 }
1345
1346 .$this_poll_id.ays-minimal-theme .apm-choosing input[type=radio]:checked + label *,
1347 .$this_poll_id.ays-minimal-theme .apm-choosing input[type=checkbox]:checked + label *,
1348 .$this_poll_id.ays-minimal-theme .apm-choosing label.ays_enable_hover:hover *{
1349 color: $main_color;
1350 }
1351
1352 .$this_poll_id.ays-minimal-theme .apm-choosing input[type=radio]{
1353 border-radius: 50%;
1354 width: 20px;
1355 height: 19px;
1356 margin: 3px !important;
1357 border: 1px solid #1e8cbe;
1358 opacity: 1;
1359 }
1360
1361 .$this_poll_id.ays-minimal-theme .apm-answers .apm-choosing input[type=radio]:checked::after{
1362 content: '';
1363 border-radius: 50%;
1364 width: 11px;
1365 height: 11px;
1366 background-color: #1e8cbe;
1367 }
1368
1369 .$this_poll_id.ays-minimal-theme .apm-choosing input[type=radio]:focus{
1370 outline-offset: 0 !important;
1371 outline: unset !important;
1372 }
1373
1374 .$this_poll_id.ays-minimal-theme .apm-choosing label{
1375 border-color: $text_color !important;
1376 font-weight: initial !important;
1377 margin:3px 0 !important;
1378 }
1379
1380 .$this_poll_id.ays-minimal-theme .apm-choosing input[type='radio']{
1381 display: block !important;
1382 }
1383
1384 .$this_poll_id.ays-minimal-theme input[type='button'].ays-poll-btn:hover, .$this_poll_id.ays-minimal-theme input[type='button'].ays-poll-btn:focus{
1385 text-decoration: none;
1386 }
1387
1388 .$this_poll_id.ays-minimal-theme input[type='button'].ays-poll-btn{
1389 color: initial !important;
1390 background: initial !important;
1391 border: 1px solid $text_color;
1392 border-radius: 3px;
1393 }
1394
1395 .$this_poll_id.ays-minimal-theme .ays_poll_passed_count{
1396 color: $text_color !important;
1397 background: initial !important;
1398 border: 1px solid $text_color;
1399 border-radius: 3px;
1400 }
1401
1402 .$this_poll_id.ays-minimal-theme .ays_poll_passed_count i.ays_poll_fa:before{
1403 color: $text_color !important;
1404 }
1405
1406 .$this_poll_id.ays-minimal-theme .answer-percent{
1407 color: initial !important;
1408 }
1409
1410 .$this_poll_id.box-apm span.ays_poll_passed_count{
1411 background-color: $text_color;
1412 color: $bg_color;
1413 }
1414
1415 #$this_poll_id.box-apm span.ays_poll_passed_count i{
1416 color: $bg_color;
1417 }
1418 #$this_poll_id.box-apm .apm-title-box{
1419 background-color: $title_bg_color;
1420 }
1421
1422 .$this_poll_id .answer-percent {
1423 background-color: $main_color;
1424 color: $bg_color !important;
1425 }
1426 .$this_poll_id .ays-poll-btn{
1427 color: $button_text_color !important;
1428 background-color: $button_bg_color !important;
1429 overflow: hidden;
1430 }
1431 #".$this_poll_id." .ays-poll-view-more-button{
1432 border-radius: 0;
1433 }
1434 .$this_poll_id.box-apm * {
1435 color: $text_color;
1436 }
1437 .$this_poll_id.box-apm .apm-title-box div {
1438 color: $text_color;
1439 text-transform: inherit;
1440 font-family: inherit;
1441 {$title_text_shadow}
1442 }
1443 #".$this_poll_id.".box-apm i {
1444 color: $icon_color;
1445 font-size: {$options['icon_size']}px;
1446 font-style: normal;
1447 }
1448
1449 #".$this_poll_id." .ays-poll-btn{
1450 width: " . $buttons_width . ";
1451 font-size: " . $buttons_font_size . ";
1452 padding: " . $buttons_top_bottom_padding . " " . $buttons_left_right_padding . ";
1453 border-radius: " . $buttons_border_radius . ";
1454 color: ". $poll_button_text_color ." !important;
1455 background: ". $button_bg_color ." !important;
1456 border: none;
1457 line-height: 12px !important;
1458 }
1459
1460 #".$this_poll_id ." .apm-add-answer input.ays-poll-new-answer-apply-text{
1461 width: 100%;
1462 margin-bottom: 0;
1463 margin-right: 5px;
1464 border-color: ".$main_color.";
1465 padding: 7px;
1466 font-size: 14px;
1467 color: black;
1468 height: 40px;
1469 outline: none;
1470 display: inline-block;
1471 }
1472
1473 #".$this_poll_id.".box-apm i.ays_poll_far{
1474 font-family: 'Font Awesome 5 Free';
1475 }
1476
1477 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-answer-list{
1478 width: initial;
1479 text-align: initial;
1480 display: initial;
1481 padding: 10px;
1482 }
1483
1484 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-answer-grid{
1485 width: 100%;
1486 text-align: left;
1487 display: inline-block;
1488 word-break: break-word;
1489 }
1490
1491
1492 #".$this_poll_id.".box-apm .apm-choosing .ays_label_poll{
1493 width: 100%;
1494 text-align: center;
1495 display: flex;
1496 $poll_direction_center;
1497 align-items: center;
1498 padding: ".$poll_answer_padding."px;
1499 }
1500
1501 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-image{
1502 height: ".$poll_answer_image_height."px;
1503 border-radius: ".$poll_answer_image_border_radius."px;
1504 object-fit: ".$poll_answer_object_fit.";
1505 }
1506
1507 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-image-list{
1508 width: 220px;
1509 }
1510
1511 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-image-grid{
1512 width: 100%;
1513 }
1514
1515
1516 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-answer-container-label-grid{
1517 align-items: center;
1518 }
1519
1520 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-answer-container-label-list{
1521 flex-direction: row;
1522 }
1523
1524 #".$this_poll_id.".box-apm .ays_poll_grid_view_container{
1525 display: flex;
1526 flex-wrap: wrap;
1527 justify-content: space-between;
1528 align-items: flex-start;
1529 }
1530
1531 #".$this_poll_id.".box-apm .ays-poll-answer-container-gird{
1532 width: calc(50% - 5px);
1533 margin-bottom: ".$poll_answer_margin."px;
1534 }
1535
1536 #".$this_poll_id.".box-apm .ays_poll_label_without_padding{
1537 padding: 10px;
1538 align-items: center;
1539 flex-direction: column;
1540 }
1541
1542 #".$this_poll_id.".box-apm .apm-title-box div{
1543 font-size: ".$poll_title_font_size."px;
1544 word-break: break-word;
1545 word-wrap: break-word;
1546 text-align: ".$poll_title_alignment.";
1547 }
1548
1549 #".$this_poll_id.".box-apm .ays-poll-answer-container-list{
1550 margin-bottom: ".$poll_answer_margin."px;
1551 display: flex;
1552 width: 100%;
1553 }
1554
1555 #".$this_poll_id.".box-apm .ays-poll-maker-text-answer-main input,
1556 #".$this_poll_id.".box-apm .ays-poll-maker-text-answer-main textarea{
1557 min-width: 150px;
1558 max-width: 100%;
1559 width: ".$poll_text_type_ready_width.$poll_text_type_ready_type.";
1560 }
1561
1562 #".$this_poll_id.".box-apm .ays-poll-password-box .ays-poll-password-button-box .ays-poll-password-button{
1563 background-color: ".$main_color.";
1564 color: ".$bg_color.";
1565 border-color: ".$main_color.";
1566 outline: none;
1567 box-shadow: unset;
1568 border: 0;
1569 transition: .5s;
1570 }
1571
1572 #".$this_poll_id.".box-apm .ays-poll-password-box .ays-poll-password-button-box .ays-poll-password-button:hover{
1573 background-color: ".$main_color."b5;
1574 }
1575
1576 #".$this_poll_id.".box-apm .ays-poll-password-box .ays-poll-password-input-box .ays-poll-password-input{
1577 border-color: ".$main_color.";
1578 }
1579
1580 #".$this_poll_id.".box-apm .apm-answers .apm-choosing label.ays_label_poll{
1581 ".$answers_box_shadow_content.";
1582 border-radius: ".$poll_answer_border_radius."px;
1583 }
1584
1585 #".$this_poll_id.".box-apm.text-poll .apm-answers .ays-poll-text-types-inputs{
1586 font-size: ".$poll_answer_font_size.";
1587 }
1588
1589 ";
1590
1591
1592 if(!$poll_theme){
1593 $content .= "#".$this_poll_id." div.apm-load-message-container{
1594 background-color: ".$bg_color." !important;
1595 }";
1596 }
1597 switch ($answer_border_side) {
1598 case 'none':
1599 $answer_border_type = "border: none";
1600 break;
1601 case 'all_sides':
1602 $answer_border_type = "border: 1px solid ".$main_color;
1603 break;
1604 case 'top':
1605 $answer_border_type = "border-top: 1px solid ".$main_color;
1606 break;
1607 case 'bottom':
1608 $answer_border_type = "border-bottom: 1px solid ".$main_color;
1609 break;
1610 case 'left':
1611 $answer_border_type = "border-left: 1px solid ".$main_color;
1612 break;
1613 case 'right':
1614 $answer_border_type = "border-right: 1px solid ".$main_color;
1615 break;
1616 default:
1617 $answer_border_type = "border: 1px solid ".$main_color;
1618 break;
1619 }
1620
1621 if ( $answer_style ) {
1622 $content .= "
1623 #".$this_poll_id.".choosing-poll label {
1624 background-color: $answer_bg_color;
1625 ".$answer_border_type.";
1626 text-transform: inherit;
1627 }";
1628 }
1629
1630 $content .= "
1631 .$this_poll_id.choosing-poll input[type=radio]:checked + label,
1632 .$this_poll_id:not(.ays-minimal-theme).choosing-poll input[type='checkbox']:checked + label,
1633 .$this_poll_id.choosing-poll label.ays_enable_hover:hover {
1634 background-color: " . ($answer_hover_color ? $answer_hover_color : $text_color) . " !important;
1635 color: $bg_color;
1636 }
1637
1638 .$this_poll_id:not(.ays-minimal-theme).choosing-poll input[type='checkbox']{
1639 display: none;
1640 }
1641 .$this_poll_id.choosing-poll input[type=radio]:checked + label *,
1642 .$this_poll_id.choosing-poll input[type=checkbox]:checked + label *,
1643 .$this_poll_id.choosing-poll label.ays_enable_hover:hover * {
1644 color: $answer_bg_color;
1645 }";
1646
1647 if ($poll_answer_icon_check) {
1648 $content .= "
1649 #".$this_poll_id.".choosing-poll label.ays_label_poll:not(.apm-label-with-bg) span.ays_grid_answer_span{
1650 display: inline-block;
1651 width: calc(100% - 10px);
1652 margin: 0 -15px;
1653 }
1654 #".$this_poll_id.".choosing-poll label.ays_label_poll span.ays_grid_answer_span{
1655 display: inline-block;
1656 width: calc(100% - 10px);
1657 }";
1658 }
1659
1660 if ($poll_answer_icon_check) {
1661 $content .=
1662 "#".$this_poll_id." label.ays_poll_answer_icon_radio:before,
1663 #".$this_poll_id." label.ays_poll_answer_icon_checkbox:before{
1664 content: '';
1665 display: inline-block;
1666 background: #ddd;
1667 background-clip: content-box;
1668 width: 20px;
1669 height: 20px;
1670 border: 3px solid #ccc;
1671 padding: 3px 3px 3px 3px;
1672 box-sizing: border-box;
1673 transition: all .4s linear;
1674 vertical-align: middle;
1675 margin-right: 10px;
1676 margin-bottom: 2px;
1677 }
1678
1679 #".$this_poll_id." label.ays_poll_answer_icon[for='poll_answer_icon_radio']:before,
1680 #".$this_poll_id." label.ays_poll_answer_icon_radio:before{
1681 border-radius: 50%;
1682 }
1683
1684 #".$this_poll_id." input[name='answer']:checked + label.ays_poll_answer_icon_radio:before,
1685 #".$this_poll_id." input[name='answer']:checked + label.ays_poll_answer_icon_checkbox:before{
1686 background: green;
1687 border: 3px solid green;
1688 padding: 3px 3px 3px 3px;
1689 background-clip: content-box;
1690 background-color: green !important;
1691 }";
1692 }
1693
1694
1695 $content .= ".$this_poll_id .apm-info-form input {
1696 border-color: $main_color;
1697 }
1698 div[class~=".$this_poll_id."] label.ays_label_font_size {
1699 font-size: $poll_answer_font_size;
1700 }
1701 button.ays-poll-next-btn:focus {
1702 background: unset;
1703 outline: none;
1704 }
1705 button.ays-poll-next-btn:disabled {
1706 cursor: not-allowed;
1707 background: dimgrey !important;
1708 color: white !important;
1709 }
1710 button.ays-poll-next-btn:enabled {
1711 cursor: pointer;
1712 }
1713 .$this_poll_id .apm-info-form input {
1714 color: $text_color !important;
1715 background-color: $answer_bg_color !important;
1716 }
1717
1718 .ays-poll-main #".$this_poll_id." .ays-poll-img {
1719 object-fit: ".$poll_question_image_object_fit.";
1720 height: ".$poll_question_image_height.";
1721 }
1722
1723 .$this_poll_id div.apm-loading-gif .apm-loader svg path,
1724 .$this_poll_id div.apm-loading-gif .apm-loader svg rect {
1725 fill: $main_color;
1726 }" . (isset($load_gif) && $load_gif == 'plg_4' ?
1727 ".$this_poll_id div.apm-loading-gif .apm-loader svg {
1728 stroke: $main_color;
1729 }
1730
1731 .$this_poll_id.choosing-poll .ays_poll_cb_and_a,
1732 .$this_poll_id.choosing-poll .ays_poll_cb_and_a * {
1733 color: " . $this->hex2rgba($text_color) . ";
1734 }
1735
1736 .ays_poll_category-container{
1737 width: '".$poll_width."',
1738 maxWidth: '98%',
1739 fontSize: '16px',
1740 padding: '10px',
1741 margin: '0 auto',
1742 marginTop: '-1rem',
1743 borderStyle: '{$options['border_style']}',
1744 borderWidth: '2px',
1745 borderColor: '$main_color',
1746 background: '$bg_color',
1747 color: '$main_color',
1748 transition: '.3s ease',
1749 WebkitAppearance: 'none',
1750 appearance: 'none',
1751 }
1752
1753 .$this_poll_id div.apm-loading-gif .apm-loader svg>g {
1754 fill: $bg_color;
1755 }"
1756 : "")
1757 . "{$poll['custom_css']}";
1758 if($poll_loader_font_size != ''){
1759 $content .= ".$this_poll_id div.apm-loading-gif .apm-loader{
1760 display: flex;
1761 justify-content: center;
1762 align-items: center;
1763 padding-top: 10px;
1764 }
1765 .$this_poll_id div.apm-loading-gif{
1766 width: 100%;
1767 height: 100%;
1768 }
1769 ";
1770 }
1771
1772 $content .= ".$this_poll_id.box-apm .ays_question p{
1773 font-size: ".$poll_question_font_size_pc."px;
1774 }
1775
1776 @media only screen and (max-width: 768px){
1777 #".$this_poll_id.".box-apm {
1778 width: $poll_width_for_mobile;
1779 }
1780
1781 #".$this_poll_id.".box-apm .ays-poll-btn{
1782 width: ".$buttons_mobile_width.";
1783 }
1784
1785 .$this_poll_id.box-apm .ays_question p{
1786 font-size: ".$poll_question_font_size_mobile."px;
1787 }";
1788
1789 if ($answers_grid_column_mobile) {
1790 $content .= "
1791 .".$this_poll_id." .apm-answers .apm-rating i.ays_poll_fa-star {
1792 font-size: 4vw !important;
1793 }
1794 #".$this_poll_id.".box-apm .ays-poll-answer-container-gird{
1795 width: 100%;
1796 }";
1797 }
1798
1799 $content .= "
1800 #".$this_poll_id.".box-apm .apm-title-box div{
1801 font-size: ".$poll_title_font_size_mobile."px;
1802 text-align: ".$poll_title_alignment_mobile.";
1803 word-break: break-word;
1804 word-wrap: break-word;
1805 }
1806
1807 .$this_poll_id.box-apm label.ays_label_font_size {
1808 font-size: ".$poll_answer_font_size_mobile."px;
1809 }
1810
1811 #".$this_poll_id.".box-apm.text-poll .apm-answers .ays-poll-text-types-inputs{
1812 font-size: ".$poll_answer_font_size_mobile."px;
1813 }
1814
1815 #".$this_poll_id.".box-apm .apm-answers > .apm-choosing > .ays_label_poll > div.ays-poll-answer-image > img.ays-poll-each-image{
1816 height: ".$poll_answer_image_height_for_mobile."px;
1817 }
1818
1819 #".$this_poll_id.".box-apm .apm-answers .apm-choosing > label.ays-poll-answer-container-label-list > p.ays-poll-answers > span.ays-poll-each-answer-list {
1820 padding: unset;
1821 word-wrap: break-word;
1822 }
1823
1824 #".$this_poll_id." .ays-poll-btn{
1825 font-size: " . $poll_buttons_mobile_font_size . ";
1826 line-height: 1;
1827 white-space: normal;
1828 word-break: break-word;
1829 }
1830 }
1831
1832 @media screen and (max-width: 768px){
1833 #".$this_poll_id."{
1834 max-width: ".$poll_mobile_max_width.";
1835 }
1836 }
1837
1838 #ays-poll-container-" . $id . "{
1839 width: $poll_width;
1840 }
1841
1842 @media screen and (max-width: 768px){
1843 #ays-poll-container-" . $id . "{
1844 width: ".$poll_width_for_mobile.";
1845 max-width: 96%;
1846 }
1847
1848 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-image-list{
1849 width: 100%;
1850 }
1851 }
1852
1853 ";
1854
1855
1856 $content .= "
1857 </style>
1858 <script>
1859 var dataCss = {
1860 width: '".$poll_width."',
1861 maxWidth: '98%',
1862 fontSize: '16px',
1863 padding: '10px',
1864 margin: '0 auto',
1865 marginTop: '-1rem',
1866 borderStyle: '{$options['border_style']}',
1867 borderWidth: '2px',
1868 borderColor: '$main_color',
1869 background: '$bg_color',
1870 color: '$main_color',
1871 transition: '.3s ease',
1872 WebkitAppearance: 'none',
1873 appearance: 'none',
1874 };
1875 var hoverCss = {
1876 background: '$main_color',
1877 color: '$bg_color',
1878 borderColor: '$bg_color',
1879 };
1880 </script>";
1881
1882 if ($poll_direction == 'center') {
1883 $poll_direction_center = "style='text-align: center;'";
1884 $poll_direction = 'ltr';
1885 }else{
1886 $poll_direction_center = "";
1887 }
1888
1889 // AV Show login form for not logged in users
1890 $options['show_login_form'] = isset($options['show_login_form']) ? $options['show_login_form'] : 'off';
1891 $show_login_form = (isset($options['show_login_form']) && $options['show_login_form'] == "on") ? true : false;
1892 $add_form = $show_login_form && !is_user_logged_in() ? "" : "<form style='margin-bottom: 0;' ".$form_method.">";
1893
1894 if(isset($options['show_create_date']) && $options['show_create_date'] == 1){
1895 $show_create_date = true;
1896 }else{
1897 $show_create_date = false;
1898 }
1899
1900 if(isset($options['show_author']) && $options['show_author'] == 1){
1901 $show_author = true;
1902 }else{
1903 $show_author = false;
1904 }
1905
1906 //Enabled ansers sound
1907 $enable_asnwers_sound = isset($options['enable_asnwers_sound']) && $options['enable_asnwers_sound'] == 'on' ? true : false;
1908 $answers_sound = '';
1909 $answers_sound_class = '';
1910 $answers_sound_mute = '';
1911 if ($enable_asnwers_sound) {
1912
1913 $settings_options = ($poll_settings->ays_get_setting('options') === false) ? json_encode(array()) : $poll_settings->ays_get_setting('options');
1914 $setting_options = json_decode($settings_options, true);
1915 $answers_sound_path = isset($setting_options['answers_sound']) && !empty($setting_options['answers_sound']) ? $setting_options['answers_sound'] : false;
1916
1917 if ($answers_sound_path != false) {
1918 $answers_sound = "<audio id='ays_poll_ans_sound_".$id."' class='ays_poll_ans_sound' src='".$answers_sound_path."'></audio>";
1919 $answers_sound_class = 'poll_answers_sound';
1920 $answers_sound_mute = "<span class='ays_music_sound ays_sound_active'><i class='ays_poll_far ays_poll_fa-volume_up'></i></span>";
1921
1922 }
1923 }
1924
1925 //AV show timer
1926 $activeDateCheck = isset($options['active_date_check']) && !empty($options['active_date_check']) ? true : false;
1927 $activeDeactiveDateCheck = isset($options['deactiveInterval']) && !empty($options['deactiveInterval']) ? true : false;
1928 $activeActiveDateCheck = isset($options['activeInterval']) && !empty($options['activeInterval']) ? true : false;
1929 $show_timer_type = isset($options['ays_show_timer_type']) && !empty($options['ays_show_timer_type']) ? $options['ays_show_timer_type'] : 'countdown';
1930 $show_bottom_timer = isset($options['show_bottom_timer']) && 1 == $options['show_bottom_timer'] ? 1 : 0;
1931
1932 $show_timer = '';
1933 if ( $activeDateCheck && $activeDeactiveDateCheck && !$is_start_soon) {
1934 if (isset($options['ays_poll_show_timer']) && $options['ays_poll_show_timer'] == 1) {
1935 $show_timer .= "<div class='ays_poll_show_timer'>";
1936 if ($show_timer_type == 'countdown') {
1937 if ($endDate_atr > 0) {
1938 $show_timer .= '<p class="show_timer_countdown" data-timer_countdown="'.$endDate_atr.'"></p>';
1939 }
1940 }else if ($show_timer_type == 'enddate') {
1941 $show_timer .= '<p class="show_timer_countdown">'. esc_html__('This Poll is active until ', "poll-maker").gmdate('jS \of F Y H:i:s', intval($endDate)).'</p>';
1942 }
1943 $show_timer .= "</div>";
1944 }
1945 }elseif ($activeDateCheck && $activeActiveDateCheck && $is_start_soon) {
1946 if (isset($options['ays_poll_show_timer']) && $options['ays_poll_show_timer'] == 1) {
1947 $show_timer .= "<div class='ays_poll_show_timer'>";
1948 if ($show_timer_type == 'countdown') {
1949 $show_timer .= '<p class="show_timer_countdown" data-timer_countdown="'.$startDate_atr.'"></p>';
1950 }else if ($show_timer_type == 'enddate') {
1951 $show_timer .= '<p class="show_timer_countdown">'. esc_html__('This Poll will start ', "poll-maker").gmdate('jS \of F Y H:i:s', intval($startDate)).'</p>';
1952 }
1953 $show_timer .= "</div>";
1954 }
1955 }
1956
1957 $show_cd_and_author = "<div class='ays_poll_cb_and_a'>";
1958 if($show_create_date){
1959 $poll_create_date = (isset($options['create_date']) && $options['create_date'] != '') ? $options['create_date'] : "0000-00-00 00:00:00";
1960 if(Poll_Maker_Ays_Admin::validateDate($poll_create_date)){
1961 $show_cd_and_author .= "<span>". esc_html__("Created on", "poll-maker")." </span><strong><time>".date("F d, Y", strtotime($poll_create_date))."</time></strong>";
1962 }else{
1963 $show_cd_and_author .= "";
1964 }
1965 }
1966
1967 if($show_author){
1968 if(isset($options['author'])){
1969 if(is_array($options['author'])){
1970 $author = $options['author'];
1971 }else{
1972 $author = json_decode($options['author'], true);
1973 }
1974 }else{
1975 $author = array("name"=>"Unknown");
1976 }
1977 $user_id = 0;
1978 if(isset($author['id']) && intval($author['id']) != 0){
1979 $user_id = intval($author['id']);
1980 }
1981 $image = get_avatar($user_id, 32);
1982 if(isset( $author['name'] ) && $author['name'] !== "Unknown"){
1983 if($show_create_date){
1984 $text =esc_html__("By", "poll-maker");
1985 }else{
1986 $text =esc_html__("Created by", "poll-maker");
1987 }
1988 $show_cd_and_author .= "<span> ".$text." </span>".$image."<strong>".$author['name']."</strong>";
1989 }else{
1990 $show_cd_and_author .= "";
1991 }
1992 }
1993
1994 $show_cd_and_author .= "</div>";
1995
1996 $poll_login_form = "";
1997 if($show_login_form){
1998 $args = array(
1999 'echo' => false,
2000 'form_id' => 'ays_loginform_'.$this_poll_id,
2001 'id_username' => 'ays_user_login_'.$this_poll_id,
2002 'id_password' => 'ays_user_pass_'.$this_poll_id,
2003 'id_remember' => 'ays_rememberme_'.$this_poll_id,
2004 'id_submit' => 'ays-submit_'.$this_poll_id
2005 );
2006 $poll_login_form = "<div class='ays_poll_login_form'>" . wp_login_form( $args ) . "</div>";
2007 }
2008
2009 $poll_user_information = $this->get_user_profile_data();
2010 $user_first_name = (isset( $poll_user_information['user_first_name'] ) && $poll_user_information['user_first_name'] != "") ? $poll_user_information['user_first_name'] : '';
2011 $user_last_name = (isset( $poll_user_information['user_last_name'] ) && $poll_user_information['user_last_name'] != "") ? $poll_user_information['user_last_name'] : '';
2012 $creation_date = (isset( $poll['styles']['create_date'] ) && $poll['styles']['create_date'] != '') ? $poll['styles']['create_date'] : '';
2013
2014 $current_poll_author = esc_html__( "Unknown", "poll-maker" );
2015 if( !empty($options['author']) ){
2016 if( !is_array($options['author']) ){
2017 $options['author'] = json_decode($options['author'], true);
2018 }
2019
2020 $poll_current_author = (isset($options['author']['id']) && $options['author']['id'] != "") ? absint(sanitize_text_field( $options['author']['id'] )) : "";
2021
2022 $current_poll_user_data = get_userdata( $poll_current_author );
2023 if ( ! is_null( $current_poll_user_data ) && $current_poll_user_data ) {
2024 $current_poll_author = ( 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 ) : "";
2025 }
2026 }
2027
2028 $user_nickname = '';
2029 $user_first_name = '';
2030 $user_display_name = '';
2031 $user_wordpress_email = '';
2032 $user_wordpress_roles = '';
2033 $user_wordpress_website = '';
2034 $user_ip_address = '';
2035 $user_id = get_current_user_id();
2036 if($user_id != 0){
2037 $usermeta = get_user_meta( $user_id );
2038 if($usermeta !== null){
2039 $user_nickname = (isset($usermeta['nickname'][0]) && sanitize_text_field( $usermeta['nickname'][0] != '') ) ? sanitize_text_field( $usermeta['nickname'][0] ) : '';
2040 $user_first_name = (isset($usermeta['first_name'][0]) && sanitize_text_field( $usermeta['first_name'][0] != '') ) ? sanitize_text_field( $usermeta['first_name'][0] ) : '';
2041 }
2042
2043 $current_user_data = get_userdata( $user_id );
2044 if ( ! is_null( $current_user_data ) && $current_user_data ) {
2045 $user_display_name = ( isset( $current_user_data->data->display_name ) && $current_user_data->data->display_name != '' ) ? sanitize_text_field( $current_user_data->data->display_name ) : "";
2046 $user_wordpress_email = ( isset( $current_user_data->data->user_email ) && $current_user_data->data->user_email != '' ) ? sanitize_text_field( $current_user_data->data->user_email ) : "";
2047
2048 $user_wordpress_roles = ( isset( $current_user_data->roles ) && ! empty( $current_user_data->roles ) ) ? $current_user_data->roles : "";
2049 $user_ip_address = $this->get_user_ip_validated();
2050
2051 if ( !empty( $user_wordpress_roles ) && $user_wordpress_roles != "" ) {
2052 if ( is_array( $user_wordpress_roles ) ) {
2053 $user_wordpress_roles = implode(",", $user_wordpress_roles);
2054 }
2055 }
2056
2057 $user_wordpress_website_url = ( isset( $current_user_data->user_url ) && ! empty( $current_user_data->user_url ) ) ? sanitize_url($current_user_data->user_url) : "";
2058
2059 if( !empty( $user_wordpress_website_url ) ){
2060 $user_wordpress_website = "<a href='". esc_url( $user_wordpress_website_url ) ."' target='_blank' class='ays-poll-user-website-link-a-tag'>".esc_html__( "Website", "poll-maker" ) ."</a>";
2061 }
2062 }
2063 }
2064
2065 $report_table = $wpdb->prefix."ayspoll_reports";
2066 $answ_table = $wpdb->prefix."ayspoll_answers";
2067
2068 $result_message = isset($options['hide_result_message']) && $options['hide_result_message'] == 1 ? "<div class='apm-title-box ays_res_mess'>" . " " . "</div>" : "";
2069
2070 $custom_class = isset($options['custom_class']) && $options['custom_class'] != '' ? $options['custom_class'] : "";
2071
2072 $content .= "<div style='margin-bottom: 1rem;' class='ays-poll-main ".$custom_class."' id='ays-poll-container-" . $id . "' data-load-method='".$poll_see_result_immediately."'>
2073 ".$add_form."
2074 ".$answers_sound."
2075 <div
2076 $poll_direction_center
2077 dir='$poll_direction'
2078 data-loading='$load_effect'
2079 data-load-gif='$load_gif'
2080 data-load-gif-font-size='$poll_loader_font_size'
2081 ".$poll_load_message_data."
2082 data-hide-bg-image='$poll_bg_img_in_finish_page'
2083 data-gradient-check='$enable_background_gradient'
2084 data-gradient-dir='$poll_gradient_direction'
2085 data-gradient-c1='$background_gradient_color_1'
2086 data-gradient-c2='$background_gradient_color_2'
2087 data-hide-bg-image-def-color='$poll_bg_img_in_finish_page_off_color'
2088 data-show-social='$show_social'
2089 class='box-apm $poll_theme {$poll['type']}-poll $this_poll_id '
2090 id='$this_poll_id'
2091 data-res='$hide_results'
2092 data-res-sort='$result_sort'
2093 data-restart ='" . (isset($options['enable_restart_button']) && $options['enable_restart_button'] ? 'true' : 'false') . "'
2094 data-redirection = '$redirect_users'
2095 data-redirect-check = '".$redirect_url_checked."'
2096 data-url-href = '".$redirect_url_href."'
2097 data-href = '$redirect_after_vote_url'
2098 data-delay = '$redirect_delay'
2099 data-id='{$poll['id']}'
2100 data-res-rgba = '". $result_in_rgba ."'
2101 data-percent-color = '". $answer_percent_color ."'
2102 data-enable-top-animation = '". $poll_enable_animation_top ."'
2103 data-top-animation-scroll = '". $poll_animation_top ."'
2104 data-info-form='$info_form'
2105 data-enable-social-links='$enable_social_links'
2106 >" . $poll_result_reports;
2107
2108 if($poll_enable_password && !$poll_password_check && !$is_expired && !$poll_check_only_logged){
2109 $content .= $poll_password_box;
2110 echo $content;
2111 return;
2112 }
2113
2114 $poll_question_image = isset($poll['image']) && $poll['image'] != '' ? esc_url($poll['image']): '';
2115 // if ($poll_question_image != '') {
2116 // if ( !(filter_var($poll_question_image, FILTER_VALIDATE_URL) && wp_http_validate_url($poll_question_image)) ) {
2117 // // invalid URL, handle accordingly
2118 // $poll_question_image = '';
2119 // }
2120 // }
2121 if( $poll_question_image != "" ){
2122 $check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($poll_question_image);
2123
2124 if( !$check_if_current_image_exists ){
2125 $poll_question_image = "";
2126 }
2127 }
2128 $poll_question_image_alt_text = Poll_Maker_Data::ays_poll_get_image_id_by_url($poll_question_image);
2129
2130 $content .= $show_cd_and_author;
2131 if ( $activeDateCheck && $activeDeactiveDateCheck && !$show_bottom_timer){
2132 $content .= $show_timer;
2133 }
2134 $content .= $poll_image_cont;
2135 $content .= $answers_sound_mute;
2136 $content .= ($poll['show_title'] == 1) ? "<div class='apm-title-box'><div>" . stripslashes($poll['title']) . "</div></div>" : "";
2137 $content .= "<div class='$this_poll_id ays_question'>" . do_shortcode(wpautop(stripslashes($poll['question']))) . "</div>";
2138 $content .= $poll_question_image ? "<div class='apm-img-box'><img class='ays-poll-img' src='{$poll_question_image}' alt='{$poll_question_image_alt_text}'></div>" : "";
2139 $content .= "<div class='$this_poll_id hideResults ays-poll-hide-result-box'>" . " " . "</div>";
2140 if(($is_expired || $is_start_soon) && $poll_check_exp_cont){
2141 $content = "";
2142 return $content;
2143 }
2144 if (!$is_expired) {
2145 //CHECK IF ENABLED ONLY LOGGED IN USERS OPTION
2146 if (isset($options['enable_logged_users']) && $options['enable_logged_users'] == 1 && !is_user_logged_in()) {
2147 $logged_users_message = isset($options['enable_logged_users_message']) && $options['enable_logged_users_message'] != '' ? $this->ays_autoembed(stripslashes($options['enable_logged_users_message'])) : "<p>" .esc_html__('You must sign in for voting.', "poll-maker") . "</p>"; // smbo
2148
2149 $content .= "<div class='apm-need-sign-in'>".$logged_users_message."</div>";
2150
2151 if($logged_users_message !== null){
2152 if(!is_user_logged_in()){
2153 $content .= "<div class='apm-need-sign-in'>".$poll_login_form."</div>";
2154 }
2155 }
2156 } else {
2157 $load_poll = true;
2158 if (isset($options['enable_restriction_pass']) && $options['enable_restriction_pass'] == 1) {
2159 // Users role Aro start
2160 global $wp_roles;
2161 $user = wp_get_current_user();
2162 $users_roles = $wp_roles->role_names;
2163 $message = (isset($options['restriction_pass_message']) && $options['restriction_pass_message'] != '') ? stripslashes($options['restriction_pass_message']) : ("<p>" .esc_html__('You not have permissions for voting.', "poll-maker") . "</p>");
2164 $users_role = (isset($options['users_role']) && $options['users_role'] != '') ? $options['users_role'] : '';
2165 $users_role = json_decode($users_role);
2166 if(!empty($users_role)){
2167 if (is_array($users_role)) {
2168 foreach($users_role as $key => $role){
2169 if(in_array($role, $users_roles)){
2170 $users_role[$key] = array_search($role, $users_roles);
2171 }
2172 }
2173 }else{
2174 if(in_array($users_role, $users_roles)){
2175 $users_role = array_search($users_role, $users_roles);
2176 }
2177 }
2178 $is_user_role = false;
2179 if(is_array($users_role)){
2180 foreach($users_role as $role){
2181 if (in_array(strtolower($role), (array)$user->roles)) {
2182 $is_user_role = true;
2183 break;
2184 }
2185 }
2186 }else{
2187 if (in_array(strtolower($users_role), (array)$user->roles)) {
2188 $is_user_role = true;
2189 }
2190 }
2191
2192 if (!$is_user_role) {
2193 $content .= "<div class='ays-poll-limitation'>$message</div>";
2194 $load_poll = false;
2195 }
2196 }
2197 //Aro end
2198 }
2199 if ($load_poll) {
2200 $limit_users = 0;
2201 global $wpdb;
2202 if ($limitusers) {
2203 $report_table = esc_sql($wpdb->prefix."ayspoll_reports");
2204 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
2205 if ((!empty($options['limit_users_method']) && $options['limit_users_method'] == 'ip') || empty($options['limit_users_method'])) {
2206 // $user_ips = $this->get_user_ip();
2207 // $user_ip = esc_sql($user_ips);
2208 // $args_ip = array($user_ip,$id);
2209 // $args_tables = array(
2210 // 'reports_table' => $report_table,
2211 // 'answer_table' => $answ_table
2212 // );
2213 $limit_users = $this->ays_poll_get_limit_user_count_by_ip($id);
2214 if (isset($_COOKIE['ays_this_poll_cookie_'.$id])) {
2215 unset($_COOKIE['ays_this_poll_cookie_'.$id]);
2216 setcookie('ays_this_poll_cookie_'.$id, null,time() -1, '/');
2217 }
2218 }
2219 elseif((isset($options['limit_users_method']) && $options['limit_users_method'] == 'cookie')){
2220 $cookie_name = "ays_this_poll_cookie_".$poll_id;
2221 if(isset($_COOKIE[$cookie_name])){
2222 $limit_users = 1;
2223 }
2224 }
2225 elseif((isset($options['limit_users_method']) && $options['limit_users_method'] == 'cookie_ip')){
2226 $cookie_name = "ays_this_poll_cookie_".$poll_id;
2227 $limit_users_check = $this->ays_poll_get_limit_user_count_by_ip($id);
2228 if(isset($_COOKIE[$cookie_name]) || $limit_users_check > 0){
2229 $limit_users = 1;
2230 }
2231 elseif(!isset($_COOKIE[$cookie_name]) || $limit_users_check > 0){
2232 $limit_users = $this->ays_poll_get_limit_user_count_by_ip($id);
2233 }
2234 }
2235 else {
2236 $user_id = is_user_logged_in() ? wp_get_current_user()->ID : 0;
2237 $args_id = array($user_id, $id);
2238 $sql = "SELECT COUNT(*)
2239 FROM ".$report_table."
2240 JOIN ".$answ_table."
2241 ON ".$answ_table.".id = ".$report_table.".answer_id
2242 WHERE ".$report_table.".user_id = %d
2243 AND ".$answ_table.".poll_id = %d";
2244 if ($user_id > 0) {
2245 $limit_users = $wpdb->get_var(
2246 $wpdb->prepare( $sql, $args_id)
2247 );
2248 }else{
2249 $limit_users = 0;
2250 }
2251 if (isset($_COOKIE['ays_this_poll_cookie_'.$id])) {
2252 unset($_COOKIE['ays_this_poll_cookie_'.$id]);
2253 setcookie('ays_this_poll_cookie_'.$id, null,time() -1, '/');
2254 }
2255 }
2256 }
2257 else{
2258 if (isset($_COOKIE['ays_this_poll_cookie_'.$id])) {
2259 unset($_COOKIE['ays_this_poll_cookie_'.$id]);
2260 setcookie('ays_this_poll_cookie_'.$id, null,time() -1, '/');
2261 }
2262 }
2263 $poll_allow_multivote = isset($options['poll_allow_multivote']) && $options['poll_allow_multivote'] == 'on' ? true : false;
2264 $poll_multivote_checkbox = $poll_allow_multivote ? 'checkbox' : 'radio';
2265 $autocomplete_attr = $poll_multivote_checkbox == 'checkbox' ? '' : 'autocomplete="off"';
2266
2267 $poll_multivote_min_count = '';
2268 $poll_multivote_min_count_content = '';
2269 $multivote_answer_count = '';
2270 $allow_multivote_answer = '';
2271 $poll_multivote_message_content = '';
2272 if($poll_allow_multivote){
2273 $multivote_answer_count = (isset($options['poll_allow_multivote_count']) && $options['poll_allow_multivote_count'] != '') ? absint(intval($options['poll_allow_multivote_count'])) : '1';
2274 $multiple_select = 'multiple';
2275 $allow_multivote_answer = 'on';
2276 $poll_multivote_min_count = (isset($options['multivote_answer_min_count']) && $options['multivote_answer_min_count'] != '') ? absint(intval($options['multivote_answer_min_count'])) : '1';
2277 $poll_multivote_min_count_content = "<input type='hidden' id='ays_poll_multivote_min_count' data-allow='true' value='".$poll_multivote_min_count."'/>";
2278 $poll_multivote_message_content = "<div class='ays-poll-multivote-message add_answer_for_grid'>". esc_html__("Min votes count should be" , "poll-maker")." ".$poll_multivote_min_count."</div>";
2279 }else{
2280 $multiple_select = '';
2281 $allow_multivote_answer = '';
2282 }
2283 if ($limit_users == 0) {
2284
2285 $view_more_button_flag = false;
2286 if (isset($poll['type']) && $poll['type'] == 'choosing') {
2287 if ($enable_view_more_button) {
2288 if ( $poll_view_more_button_count != 0 && $poll_view_more_button_count < count($poll['answers']) ) {
2289 $view_more_button_flag = true;
2290 }
2291 }
2292 }
2293
2294 if ($poll_answer_icon_check && $poll_theme != 'ays-minimal-theme') {
2295 switch ($poll_answer_icon) {
2296 case 'radio':
2297 $answer_icon_class = 'ays_poll_answer_icon_radio';
2298 break;
2299 case 'checkbox':
2300 $answer_icon_class = 'ays_poll_answer_icon_checkbox';
2301 break;
2302 default:
2303 $answer_icon_class = '';
2304 break;
2305 }
2306 }else{
2307 $answer_icon_class = '';
2308 }
2309
2310 $content .= "<div class='apm-answers $without_vote ".$answers_container."'>";
2311 switch ( $poll['type'] ) {
2312 case 'choosing':
2313 $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";
2314 $randomize_answers = (isset($poll['styles']['randomize_answers']) && $poll['styles']['randomize_answers'] == 'on') ? true : false;
2315 $redirect_after_submit = (isset($poll['styles']['redirect_after_submit']) && $poll['styles']['redirect_after_submit'] == 1) ? 'redirect-after-vote-url' : '';
2316
2317 $numbering_type = "";
2318 if ($randomize_answers) {
2319 shuffle($poll['answers']);
2320 }
2321 $answers_count = isset($poll['answers']) && $poll['answers'] != '' ? count($poll['answers']) : false;
2322 $numbering_type_arr = array();
2323 if($answers_count){
2324 $numbering_type_arr = $this->ays_answer_numbering($show_answers_numbering , $answers_count);
2325 }
2326 if($poll_allow_multivote){
2327 $content .= "<input type='hidden' id='multivot_answer_count' value='".$multivote_answer_count."'/>";
2328 $content .= $poll_multivote_min_count_content;
2329 }
2330 foreach ( $poll['answers'] as $index => $answer ) {
2331 if ($answer['user_added'] == 1 && $answer['show_user_added'] == 0) {
2332 continue;
2333 }
2334 else{
2335 if ($answer['show_user_added'] == 0){
2336 continue;
2337 }
2338 else{
2339 if(!empty($numbering_type_arr)){
2340 $numbering_type = isset($numbering_type_arr[$index]) && $numbering_type_arr[$index] != "" ? $numbering_type_arr[$index] : "";
2341 $numbering_type = $numbering_type . " ";
2342 }
2343 $answer_style_class = '';
2344 if ($view_more_button_flag) {
2345 if ($poll_view_more_button_count - 1 < $index) {
2346 $answer_style_class = 'ays_poll_display_none';
2347 }
2348 }
2349 $pol_answer_view_type_show = 'ays_poll_list_view_item';
2350 $pol_answer_view_type_image = 'ays-poll-each-image-list';
2351 $pol_answer_view_type_cont = 'ays-poll-answer-container-list';
2352 $pol_answer_view_type_label_cont = 'ays-poll-answer-container-label-list';
2353 if($pol_answer_view_type == "grid"){
2354 $pol_answer_view_type_label_cont = 'ays-poll-answer-container-label-grid';
2355 $pol_answer_view_type_cont = 'ays-poll-answer-container-gird';
2356 $pol_answer_view_type_show = 'ays_poll_grid_view_item';
2357 $pol_answer_view_type_image = 'ays-poll-each-image-grid';
2358 }
2359
2360 $poll_answer_image = isset($answer['answer_img']) && $answer['answer_img'] != "" ? esc_attr($answer['answer_img']) : "";
2361 $poll_added_style = "";
2362 if($poll_answer_image && $answer_view_type == 'list'){
2363 $poll_added_style = "max-width: calc(100% - 220px);";
2364
2365 }
2366 $poll_answer_image_show = $poll_answer_image ? "<div class='ays-poll-answer-image'><img src=".esc_attr($answer['answer_img'])." class='".$pol_answer_view_type_image." ays-poll-each-image'></div>" : "";
2367 $poll_class_for_answer_label = "";
2368 $poll_class_for_answer_label_text = "";
2369
2370 $pol_answer_view_type_text_show = 'ays-poll-each-answer-grid';
2371 if($poll_answer_image){
2372 $poll_class_for_answer_label = "ays_poll_label_without_padding";
2373 $pol_answer_view_type_text_show = 'ays-poll-each-answer-list';
2374
2375 $poll_class_for_answer_label_text = "ays_poll_label_text_with_padding";
2376 }
2377 $content .= "
2378 <div class='apm-choosing answer-$this_poll_id ". $answer_style_class ." ays-poll-field ".$pol_answer_view_type_cont."' >
2379 <input type=".$poll_multivote_checkbox." name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}' {$autocomplete_attr}>
2380 <label
2381 for='radio-$index-$this_poll_id'
2382 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 data-answers-url='".(isset($answer['redirect']) && is_string($answer['redirect']) ? esc_url($answer['redirect']) : '')."'
2384 >".$poll_answer_image_show." <p style='".$poll_added_style."' class='ays-poll-answers'><span class='".$pol_answer_view_type_text_show."'>"
2385 . $numbering_type . esc_attr(stripcslashes($answer['answer'])) .
2386 "</span></p></label>
2387 </div>";
2388 }
2389 }
2390 }
2391 $add_answer_for_grid = isset($poll['view_type']) && $poll['view_type'] == 'grid' ? 'add_answer_for_grid' : '';
2392 if ($poll_allow_answer && $with_vote) {
2393 $content .= "
2394 <div class='apm-choosing answer-$this_poll_id ".$this_poll_id."_addAnswer apm-add-answer ".$add_answer_for_grid."'>
2395 <input type='text' placeholder='" .esc_html__("Other - please specify", "poll-maker") . "' class='ays-poll-new-answer-apply-text' name='ays_poll_new_answer'>
2396 </div>
2397 ";
2398 $allow_multi_vote_for_other = isset($options["poll_allow_multivote"]) && $options["poll_allow_multivote"] == "on" ? true : false;
2399 if(!$allow_multi_vote_for_other){
2400 $content .= "
2401 <div class='ays-poll-add-answer-note ays-poll-add-answer-note-enable'>
2402 <div class='ays-poll-add-answer-note-text'><img src='".esc_url(POLL_MAKER_AYS_ADMIN_URL)."/images/icons/other-answer-note.svg' >". esc_html__( "If 'Other' is filled, checked answers are ignored.", "poll-maker")."</div>
2403 </div>
2404 ";
2405 }
2406 }
2407 $content .= $poll_multivote_message_content;
2408 break;
2409 case 'voting':
2410 switch ( $poll['view_type'] ) {
2411 case 'hand':
2412 foreach ( $poll['answers'] as $index => $answer ) {
2413 $content .= "<div class='apm-voting answer-$this_poll_id'><input type='radio' name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}'>
2414 <label for='radio-$index-$this_poll_id' class='".$answers_sound_class."'>";
2415 $content .= ((int) $answer['answer'] > 0 ? "<i class='ays_poll_far ays_poll_fa-thumbs-up'></i>" : "<i class='ays_poll_far ays_poll_fa-thumbs-down'></i>") . "</label></div>";
2416 }
2417 break;
2418 case 'emoji':
2419 foreach ( $poll['answers'] as $index => $answer ) {
2420 $content .= "<div class='apm-voting answer-$this_poll_id'><input type='radio' name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}'>
2421 <label for='radio-$index-$this_poll_id' class='".$answers_sound_class."'>";
2422 $content .= ((int) $answer['answer'] > 0 ? $emoji[1] : $emoji[3]) . "</label></div>";
2423 }
2424 break;
2425 default:
2426 break;
2427 }
2428 break;
2429 case 'rating':
2430 switch ( $poll['view_type'] ) {
2431 case 'star':
2432 foreach ( $poll['answers'] as $index => $answer ) {
2433 $content .= "<div class='apm-rating answer-$this_poll_id'><input type='radio' name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}'>
2434 <label for='radio-$index-$this_poll_id'><i class='ays_poll_far ays_poll_fa-star ".$answers_sound_class."'></i></label></div>";
2435 }
2436 break;
2437 case 'emoji':
2438 foreach ( $poll['answers'] as $index => $answer ) {
2439 $content .= "<div class='apm-rating answer-$this_poll_id'><input type='radio' name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}'>
2440 <label class='emoji ".$answers_sound_class."' for='radio-$index-$this_poll_id'>" . $emoji[(count($poll['answers']) / 2 - $index + 1.5)] . "</label></div>";
2441 }
2442 break;
2443 default:
2444 break;
2445 }
2446 break;
2447 case 'text':
2448 $poll_text_type_placeholder = ( isset($options['poll_text_type_placeholder']) && $options['poll_text_type_placeholder'] != "" ) ? stripslashes(esc_attr($options['poll_text_type_placeholder'])) : "";
2449 switch ( $poll_view_type_text ) {
2450 case 'short_text':
2451 $content .= "<div class='ays-poll-maker-text-answer-main answer-".$this_poll_id."'>
2452 <div>
2453 <input
2454 type='text'
2455 id='ays-poll-text-type-short-".$this_poll_id."'
2456 class='ays-poll-text-types-inputs ".$poll_class_for_limits."'
2457 placeholder='".$poll_text_type_placeholder."'
2458 name='answer'
2459 data-max-length='".$poll_text_type_limit_length."'
2460 data-limit-type='".$poll_text_type_limit_type."'
2461 autocomplete='off'>
2462 <label class='ays-poll-text-type-short-label' for='ays-poll-text-type-short-".$this_poll_id."'></label>
2463 </div>
2464 ".$poll_box_for_limit_message."
2465 </div>";
2466 break;
2467 case 'paragraph':
2468 $content .= "<div class='ays-poll-maker-text-answer-main answer-".$this_poll_id."'>
2469 <div>
2470 <textarea
2471 id='ays-poll-text-type-paragraph-".$this_poll_id."'
2472 class='ays-poll-text-types-inputs ays-poll-text-types-inputs-only-textarea ".$poll_class_for_limits."'
2473 placeholder='".$poll_text_type_placeholder."'
2474 name='answer'
2475 data-max-length='".$poll_text_type_limit_length."'
2476 data-limit-type='".$poll_text_type_limit_type."'
2477 ></textarea>
2478 <label for='ays-poll-text-type-paragraph-".$this_poll_id."'></label>
2479 </div>
2480 ".$poll_box_for_limit_message."
2481 </div>";
2482 break;
2483 default:
2484 break;
2485 }
2486 break;
2487 default:
2488 break;
2489 }
2490
2491 if ($view_more_button_flag) {
2492 $content .= '
2493 <div class="ays-poll-view-more-button-box">
2494 <input type="button" class="btn ays-poll-btn ays-poll-view-more-button" value="'.esc_html__( "View more", "poll-maker" ) .'">
2495 </div>';
2496 }
2497
2498 $content .= "</div>";
2499 $content .= "<div class='apm-cashed-fa'>";
2500 foreach ( $poll['answers'] as $index => $answer ) {
2501 $content .= "<div>
2502 <i class='ays_poll_fas ays_poll_fa-star' style='font-size: 0'></i>
2503 </div>";
2504 }
2505 $content .= "</div>";
2506 if ($info_form) {
2507 $this->fields_placeholders = $this->ays_set_poll_fields_placeholders_texts();
2508 $content .= "\n
2509 <div class='apm-info-form' data-text='" .esc_html__("Send", "poll-maker") . "' style='display: none;'>
2510 $info_form_title
2511 <div class='amp-info-form-input-box'>
2512 ";
2513 foreach ( $fields as $f ) {
2514 $required = array_search($f, $required_fields) !== false ? "true" : "false";
2515 switch ( $f ) {
2516 case "apm_email":
2517 if( $display_fields_labels ){
2518 $content .= "<label for='ays_poll_form_field_user_email_". $id ."' style='border: none;'>". $this->fields_placeholders['emailLabel'] ."</label>";
2519 }
2520 $content .= "
2521 <input type='email' check_id='".$this_poll_id."' class='ays_animated_xms' name='$f' data-required='$required' placeholder='".$this->fields_placeholders['emailPlaceholder']."'>
2522 ";
2523 break;
2524 case "apm_phone":
2525 if( $display_fields_labels ){
2526 $content .= "<label for='ays_form_field_user_phone_". $id ."' style='border: none;'>". $this->fields_placeholders['phoneLabel'] ."</label>";
2527 }
2528 $content .= "
2529 <input type='tel' class='ays_animated_xms' name='$f' data-required='$required' placeholder='".$this->fields_placeholders['phonePlaceholder']."'>
2530 ";
2531 break;
2532 default:
2533 if( $display_fields_labels ){
2534 $content .= "<label for='ays_form_field_user_name_". $id ."' style='border: none;'>". $this->fields_placeholders['nameLabel'] ."</label>";
2535 }
2536 $content .= "
2537 <input type='text' class='ays_animated_xms' name='$f' data-required='$required' placeholder='".$this->fields_placeholders['namePlaceholder']."'>
2538 ";
2539 break;
2540 }
2541 }
2542 $content .= "</div></div>";
2543 }
2544 } else {
2545 $content .= "<div class='ays-poll-limitation'>" . (isset($options['limitation_message']) && $options['limitation_message'] != '' ? stripslashes($options['limitation_message']) : ("<p>" .esc_html__("You have already voted.", "poll-maker") . "</p>")) . "</div>";
2546 if (isset($options['redirect_url']) && $options['redirect_url'] != '' && isset($options['redirection_delay']) && $options['redirection_delay'] != 0) {
2547 $content .= "<div class='apm-redirection apm-redirection-$this_poll_id'>
2548 <p data-id='$this_poll_id' data-href='" . stripslashes($options['redirect_url']) . "' data-delay='{$options['redirection_delay']}'>" .esc_html__('Redirecting after', "poll-maker")
2549 . " <b>{$this->secondsToWords($options['redirection_delay'])}</b>
2550 </p>
2551 </div>";
2552 }
2553 }
2554 }
2555 }
2556
2557 $show_res_button = !is_user_logged_in() && !$show_login_form ? true : false;
2558
2559 if (is_user_logged_in() || $show_res_button ) {
2560 $content .= $vote_reason;
2561 if($limit_users > 0){
2562 $content .= wp_nonce_field('ays_finish_poll', 'ays_finish_poll_show_res_' . $poll_id);
2563 }
2564 else{
2565 $content .= wp_nonce_field('ays_finish_poll', 'ays_finish_poll_show_res_' . $poll_id) . "<div class='apm-button-box'>";
2566 }
2567 if (!empty($options['allow_not_vote']) && $limit_users == 0 && $poll['type'] != "text") {
2568 $content .= "<input type='button' class='btn ays-poll-btn {$poll['type']}-btn ays-see-res-button-show' data-form='$this_poll_id' value='" . $ays_see_result_button_text . "' data-seeRes='true' >";
2569 }
2570 elseif($limit_users > 0){
2571 if($poll_see_result_button_check){
2572 if($poll_show_result_button_limit){
2573 $content .= "<div class='apm-button-box'>";
2574 if($poll['type'] != "text"){
2575 $content .= "<input type='button' class='btn ays-poll-btn {$poll['type']}-btn ays-see-res-button-show' data-form='$this_poll_id' value='" . $ays_see_result_button_text . "' data-seeRes='true' data-limitation='true' >";
2576 }
2577 $content .= "</div>";
2578
2579 }
2580 elseif($poll_see_result_immediately){
2581 $result_content = $this->ays_poll_get_results($id);
2582 $content .= $result_content;
2583 if($poll_show_avatars){
2584 $content .= "<script>
2585 var resLoader = '".POLL_MAKER_AYS_PUBLIC_URL."/images/tail-spin.svg';
2586 var idChecker = 'ays-poll-container-" . $id . "';
2587 </script>";
2588 }
2589 }
2590
2591 }
2592 }
2593 if ($limit_users == 0 && $load_poll) {
2594
2595 $ays_vote_button = (isset($options['btn_text']) && $options['btn_text'] != '') ? stripslashes($options['btn_text']) : 'Vote';
2596
2597 if ($ays_vote_button === 'Vote') {
2598 $ays_vote_button_text = esc_html__("Vote", "poll-maker");
2599 }else{
2600 $ays_vote_button_text = $ays_vote_button;
2601 }
2602
2603 $content .= "<input type='button'
2604 name='ays_finish_poll'
2605 class='btn ays-poll-btn {$poll['type']}-btn ays_finish_poll'
2606 data-form='$this_poll_id'
2607 " . (!$load_poll ? "data-allow='false'" : "") .
2608 'value="' . $ays_vote_button_text . '"
2609 >';
2610
2611 }
2612 }
2613 if(!$limit_users > 0 && (is_user_logged_in() || $show_res_button )){
2614 $content .= '</div>';
2615 }
2616
2617 $is_elementor_exists = Poll_Maker_Data::ays_poll_is_elementor();
2618 $is_editor_exists = Poll_Maker_Data::ays_poll_is_editor();
2619
2620 $poll_block_preview_message = "";
2621 if( $is_elementor_exists || $is_editor_exists ){
2622 $poll_block_preview_message = '
2623 <span class="ays_poll_small_hint_text ays_poll_preview_mode_hint">'. esc_attr(esc_html__( "You're in the preview mode. Note: All elements work correctly on the front end." , "poll-maker") ) .'</span>';
2624 }
2625
2626 $content .= $poll_block_preview_message;
2627 $content .= $result_message;
2628 $content .= $redirect_after_vote;
2629 } elseif ($is_start_soon) {
2630 $poll_is_start_message = isset($options['active_date_message_soon']) ? stripslashes($options['active_date_message_soon']) : "<p>" .esc_html__('The poll will be available soon.', "poll-maker") . "</p>";
2631 $content .= "<div class='apm_expired_poll'>".$poll_is_start_message."</div>";
2632
2633 } else {
2634 $expired_poll_message = isset($options['active_date_message']) ? stripslashes($options['active_date_message']) : "<p>" .esc_html__('The poll has expired.', "poll-maker") . "</p>";
2635 $content .= "<div class='apm_expired_poll'>$expired_poll_message</div>";
2636
2637 if ($show_res_btn_sch) {
2638 $content .= $see_result_button;
2639 }
2640
2641 }
2642 $poll_options = $options;
2643 if ( $activeDateCheck && $activeDeactiveDateCheck && $show_bottom_timer){
2644 $content .= $show_timer;
2645 }
2646 $content .= "<script>";
2647 $content .= "
2648 if(typeof aysPollOptions === 'undefined'){
2649 var aysPollOptions = [];
2650 }
2651 aysPollOptions['".$this_poll_id."'] = '" . base64_encode(json_encode($poll_options)) . "';";
2652 $content .= "
2653 </script>";
2654 $content .= '</div></form></div>';
2655 if ($echo) {
2656 echo $content;
2657 } else {
2658 return $content;
2659 }
2660 }
2661
2662 public function ays_poll_category_generate_html($attr, $echo = true) {
2663 global $wpdb;
2664
2665 $id = absint($attr['cat_id']);
2666 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
2667 $like = '%' . $wpdb->esc_like( $id ) . '%';
2668 $sql = "SELECT id FROM ".$poll_table." WHERE categories LIKE %s;";
2669 $result = $wpdb->get_results(
2670 $wpdb->prepare($sql, $like),
2671 'ARRAY_A'
2672 );
2673
2674 $cat = $this->ays_get_poll_category($id);
2675 if (empty($cat)) {
2676 return "";
2677 }
2678
2679 //AV Check expired polls
2680 $check_poll = false;
2681 $new_res = array();
2682 $checker = array();
2683 $widths = array();
2684 foreach ($result as $key => $value) {
2685 $check_poll = $this->check_shedule_expired_poll( $value['id'] );
2686
2687 $polls = $this->get_poll_by_id($value['id']);
2688 $widths[] = $polls['styles']['width']."px";
2689 if ($check_poll) {
2690 $new_res[] = $result[$key];
2691 }
2692 $checker[] = $check_poll;
2693 }
2694
2695 if (isset($widths[0]) && $widths[0] == "0px") {
2696 $widths[0] = "98%";
2697 }
2698
2699 $cat_opt = null;
2700 if ($cat['options'] !== null) {
2701 $cat_opt = json_decode($cat['options'], true);
2702 }
2703
2704 $default_message = 'The polls that belong to this category are expired or unpublished';
2705 $exp_message = isset($cat_opt['exp_message']) && $cat_opt['exp_message'] != '' ? $this->ays_autoembed($cat_opt['exp_message']) : $default_message;
2706
2707 if (array_sum($checker) == 0) {
2708 echo "<div class='ays_exp_cat_message'>".$exp_message."</div>";
2709 }
2710
2711 if (empty($new_res)) {
2712 return "";
2713 }
2714
2715 $polls_pool = $this->ays_get_polls_pool($new_res);
2716
2717 $ays_next_button = (isset($cat_opt['next_text']) && $cat_opt['next_text'] != '') ? stripslashes($cat_opt['next_text']) : 'Next';
2718 if ($ays_next_button === 'Next') {
2719 $ays_next_button_text = esc_html__("Next", "poll-maker");
2720 } else {
2721 $ays_next_button_text = $ays_next_button;
2722 }
2723
2724 $ays_previous_button = (isset($cat_opt['previous_text']) && $cat_opt['previous_text'] != '') ? stripslashes($cat_opt['previous_text']) : 'Previous';
2725 if ($ays_previous_button === 'Previous') {
2726 $ays_previous_button_text = esc_html__("Previous", "poll-maker");
2727 }else{
2728 $ays_previous_button_text = $ays_previous_button;
2729 }
2730
2731 $show_next = isset($cat_opt['allow_skip']) && $cat_opt['allow_skip'] == 'allow' ? 'true' : 'false';
2732 $show_next_val = ($show_next == 'true') ? 'true' : 'false';
2733 $cat_id = uniqid('ays-poll-category-pool-');
2734 $j = uniqid('JsVariable');
2735 $content = "
2736 <div style='margin:1rem auto;' class='ays_poll_category-container' data-var='" . $j . "' id='$cat_id'>
2737 </div>
2738 <style>
2739 #" . $cat_id . " div.previous_next_buttons {
2740 display:flex;
2741 width: " . $widths[0] . ";
2742 max-width: 98%;
2743 }
2744 </style>
2745 <script>
2746 var catContainer" . $j . " = '" . $cat_id . "';
2747 var pollsGlobalPool" . $j . " = " . $polls_pool . ";
2748 var showNext" . $j . " = " . $show_next . ";
2749 var showNextVal" . $j . " = " . $show_next_val . ";
2750 var catIndex" . $j . " = 0;
2751 var aysPollBtnText" . $j . " = '" . $ays_next_button_text . "';
2752 var showPrev" . $j . " = false;
2753 var aysPollPreviousBtnText" . $j . " = '" . $ays_previous_button_text . "';
2754 var aysPollWidths" . $j . " = '" . json_encode($widths) . "';
2755 </script>";
2756
2757 if ($echo) {
2758 echo $content;
2759 } else {
2760 return $content;
2761 }
2762 }
2763
2764 private function get_poll_by_id( $id ) {
2765 global $wpdb;
2766 $args_id = absint(intval($id));
2767 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
2768 $sql = "SELECT * FROM ".$poll_table." WHERE id=%d";
2769 $ordering = 'ORDER BY ordering ASC, id ASC';
2770 $poll = $wpdb->get_row(
2771 $wpdb->prepare( $sql, $args_id),
2772 'ARRAY_A'
2773 );
2774
2775 if (empty($poll)) {
2776 return $poll;
2777 }
2778
2779 $json = $poll['styles'];
2780 $poll['styles'] = json_decode($json, true);
2781 $poll_type = (isset($poll['type']) && $poll['type'] != '') ? $poll['type'] : '';
2782 if($poll_type == 'choosing'){
2783 $answer_ordering = isset($poll['styles']['answer_sort_type']) && $poll['styles']['answer_sort_type'] != '' ? $poll['styles']['answer_sort_type'] : '';
2784 if($answer_ordering != ''){
2785 switch ($answer_ordering){
2786 case 'ascending':
2787 $ordering = 'ORDER BY answer ASC';
2788 break;
2789 case 'descending':
2790 $ordering = 'ORDER BY answer DESC';
2791 break;
2792 case 'votes_asc':
2793 $ordering = 'ORDER BY votes DESC, id ASC';
2794 break;
2795 case 'votes_desc':
2796 $ordering = 'ORDER BY votes ASC, id ASC';
2797 break;
2798 default:
2799 $ordering = "ORDER BY ordering ASC, id ASC";
2800 break;
2801 }
2802 }
2803 }
2804 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
2805 $sql = "SELECT * FROM ".$answ_table." WHERE poll_id=%d AND show_user_added = %d ".$ordering;
2806
2807 $poll['answers'] = $wpdb->get_results(
2808 $wpdb->prepare( $sql, $args_id, 1),
2809 'ARRAY_A'
2810 );
2811
2812 return $poll;
2813 }
2814
2815 public static function get_poll_results_count_by_id( $id ) {
2816 global $wpdb;
2817
2818 $args_id = absint(intval($id));
2819 $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
2820 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
2821
2822 $sql = "SELECT COUNT(*) AS res_count
2823 FROM ".$rep_table."
2824 INNER JOIN ".$answ_table."
2825 ON ".$answ_table.".id=".$rep_table.".answer_id
2826 WHERE ".$answ_table.".poll_id = %d";
2827
2828 $poll = $wpdb->get_row(
2829 $wpdb->prepare( $sql, $args_id),
2830 'ARRAY_A'
2831 );
2832
2833 return $poll;
2834 }
2835
2836 private static function get_user_ip() {
2837 $ipaddress = '';
2838 if (getenv('HTTP_CLIENT_IP')) {
2839 $ipaddress = getenv('HTTP_CLIENT_IP');
2840 } else if (getenv('HTTP_X_FORWARDED_FOR')) {
2841 $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
2842 } else if (getenv('HTTP_X_FORWARDED')) {
2843 $ipaddress = getenv('HTTP_X_FORWARDED');
2844 } else if (getenv('HTTP_FORWARDED_FOR')) {
2845 $ipaddress = getenv('HTTP_FORWARDED_FOR');
2846 } else if (getenv('HTTP_FORWARDED')) {
2847 $ipaddress = getenv('HTTP_FORWARDED');
2848 } else if (getenv('REMOTE_ADDR')) {
2849 $ipaddress = getenv('REMOTE_ADDR');
2850 } else {
2851 $ipaddress = 'UNKNOWN';
2852 }
2853
2854 return $ipaddress;
2855 }
2856
2857 public static function get_user_ip_validated(){
2858 $headers_to_check = array(
2859 'HTTP_CLIENT_IP',
2860 'HTTP_X_FORWARDED_FOR',
2861 'HTTP_X_FORWARDED',
2862 'HTTP_FORWARDED_FOR',
2863 'HTTP_FORWARDED',
2864 'REMOTE_ADDR'
2865 );
2866
2867 foreach ($headers_to_check as $header) {
2868 if (!empty($_SERVER[$header])) {
2869 // In case of multiple IPs in HTTP_X_FORWARDED_FOR, take the last one
2870 if ($header === 'HTTP_X_FORWARDED_FOR') {
2871 $ips = explode(',', $_SERVER[$header]);
2872 $ip = trim(end($ips));
2873 } else {
2874 $ip = $_SERVER[$header];
2875 }
2876
2877 // Validate the IP address
2878 if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) && $ip !== '0.0.0.0') {
2879 return $ip;
2880 }
2881 }
2882 }
2883
2884 return 'UNKNOWN';
2885 }
2886
2887 public function secondsToWords( $seconds ) {
2888 $ret = "";
2889 $seconds = absint($seconds);
2890
2891 /*** get the days ***/
2892 $days = (int)($seconds / (3600 * 24));
2893 if ($days > 0) {
2894 $ret .= "$days " .esc_html__( 'days', "poll-maker" ) . ' ';
2895 }
2896
2897 /*** get the hours ***/
2898 $hours = (int)(($seconds / 3600) % 24);
2899 if ($hours > 0) {
2900 $ret .= "$hours " .esc_html__( 'hours', "poll-maker" ) . ' ';
2901 }
2902
2903 /*** get the minutes ***/
2904 $minutes = (int)(($seconds / 60) % 60);
2905 if ($minutes > 0) {
2906 $ret .= "$minutes " .esc_html__( 'minutes', "poll-maker" ) . ' ';
2907 }
2908
2909 /*** get the seconds ***/
2910 $seconds = (int)(($seconds) % 60);
2911 if ($seconds > 0) {
2912 $ret .= "$seconds " .esc_html__( 'seconds', "poll-maker" );
2913 }
2914
2915 return $ret;
2916 }
2917
2918 public function ays_get_polls_pool( $array_of_poll_id ) {
2919 $pool = array();
2920 foreach ( $array_of_poll_id as $poll ) {
2921 $pool[] = $this->ays_poll_generate_html($poll['id'], false);
2922 }
2923
2924 return json_encode($pool);
2925 }
2926
2927 public function ays_get_poll_category( $id ) {
2928 global $wpdb;
2929 $cat_id = absint(intval($id));
2930 $cat_table = esc_sql($wpdb->prefix."ayspoll_categories");
2931 $sql = "SELECT * FROM ".$cat_table." WHERE id=%d";
2932 $result = $wpdb->get_row(
2933 $wpdb->prepare( $sql, $cat_id),
2934 'ARRAY_A'
2935 );
2936
2937 return $result;
2938 }
2939
2940 public function get_poll_status($id) {
2941 global $wpdb;
2942 $poll_id = absint(intval($id));
2943 $poll_table = $wpdb->prefix . 'ayspoll_polls';
2944
2945 $poll = $wpdb->get_row($wpdb->prepare("SELECT styles FROM $poll_table WHERE id = %d", $poll_id));
2946
2947 if ($poll) {
2948 $styles = json_decode($poll->styles, true);
2949 if (isset($styles['published']) && $styles['published'] == 1) {
2950 return 'published';
2951 } else {
2952 return 'unpublished';
2953 }
2954 } else {
2955 return false;
2956 }
2957 }
2958
2959 public function ays_poll_get_user_information() {
2960 if ( ! check_ajax_referer( 'ays_poll_nonce', '_ajax_nonce', false ) ) {
2961 wp_send_json_error( array( 'message' => 'Invalid request' ), 403 );
2962 }
2963 if ( ! is_user_logged_in() ) {
2964 wp_send_json_error( array( 'message' => 'User not logged in' ), 401 );
2965 }
2966
2967 $user = wp_get_current_user();
2968
2969 wp_send_json_success( array(
2970 'display_name' => $user->display_name,
2971 'user_email' => $user->user_email,
2972
2973 ) );
2974 }
2975
2976 public function ays_finish_poll() {
2977 global $wpdb;
2978 $poll_id = absint($_POST['poll_id']);
2979 if (
2980 (isset($_POST["ays_finish_poll_" . $poll_id]) && wp_verify_nonce($_POST["ays_finish_poll_" . $poll_id], 'ays_finish_poll')) ||
2981 (isset($_POST["ays_finish_poll_show_res_" . $poll_id]) && wp_verify_nonce($_POST["ays_finish_poll_show_res_" . $poll_id], 'ays_finish_poll'))
2982 ) {
2983
2984 // $answer_id = (isset($_POST['answer']) && $_POST['answer'] !== null) ? $_POST['answer'] : 0;
2985 // $poll_id = absint($_POST['poll_id']);
2986 $poll_status = $this->get_poll_status($poll_id);
2987
2988 if ($poll_status === 'unpublished') {
2989 $res = array('error' => 'The poll is not published.');
2990 echo json_encode($res);
2991 wp_die();
2992 }
2993
2994 $title_ids = array();
2995 $answer_titless = array();
2996 if (isset($_POST['answer'])) {
2997 if( is_array($_POST['answer']) ){
2998 $answer_id = array_map('absint', $_POST['answer']);
2999 $multi_answer_id = array_map('absint', $_POST['answer']);
3000 $title_ids = implode(',' , $multi_answer_id);
3001 }else{
3002 $answer_id = absint( $_POST['answer'] );
3003
3004 $answer_id2 = array();
3005 $answer_id2[] = $answer_id;
3006 $multi_answer_id = array();
3007 $title_ids = implode(',' , $answer_id2);
3008 }
3009 }else{
3010 $answer_id = 0;
3011 $answer_id2[] = false;
3012 }
3013
3014 if(!is_array($answer_id)){
3015 $answer_id = absint($answer_id);
3016 }
3017
3018 // $title_ids = array();
3019 // $answer_titless = array();
3020 // if (isset($_POST['answer']) && is_array($_POST['answer'])) {
3021 // $answer_id = $_POST['answer'];
3022 // $multi_answer_id = $_POST['answer'];
3023 // $title_ids = implode(',' , $multi_answer_id);
3024 // } else {
3025 // $answer_id2 = array();
3026 // $answer_id2[] = !isset($_POST['answer']) || $_POST['answer'] === null ? false : absint($_POST['answer']);
3027 // $multi_answer_id = array();
3028 // $title_ids = implode(',' , $answer_id2);
3029 // }
3030 if(!empty($title_ids)){
3031 $answer_titles = $this->get_answer_by_ids($title_ids);
3032 if(isset($answer_titles) && $answer_titles != null){
3033 foreach($answer_titles as $t_key => $t_value){
3034 foreach ($t_value as $r_key => $r_value) {
3035 if($r_key == 'answer'){
3036 $answer_titless[] = $r_value;
3037 }
3038 }
3039 }
3040 }
3041 }
3042
3043
3044 $poll = $this->get_poll_by_id($poll_id);
3045 $options = $poll['styles'];
3046 $poll_answers_count = isset($poll['answers']) ? count($poll['answers']) : 0;
3047 $added_answer_id = array();
3048
3049 $poll_title = (isset($poll['title']) && $poll['title'] != '') ? stripslashes( sanitize_text_field( $poll['title'] ) ) : '';
3050 $poll_vote_reason_text = "";
3051 $poll_vote_reason = false;
3052 $show_answers_numbering = (isset($options['show_answers_numbering']) && sanitize_text_field( $options['show_answers_numbering'] ) != '') ? sanitize_text_field( $options['show_answers_numbering'] ) : 'none';
3053 if (isset($options['poll_vote_reason']) && $options['poll_vote_reason'] == "on" && isset($_POST['ays-poll-reason-text'])) {
3054 // $poll_vote_reason_text = $_POST['ays-poll-reason-text'];
3055 $poll_vote_reason_text = esc_html( $_POST['ays-poll-reason-text'] );
3056 $poll_vote_reason = true;
3057 }
3058
3059 $allow_multi_vote = isset($options["poll_allow_multivote"]) && $options["poll_allow_multivote"] == "on" ? true : false;
3060 $allow_add_answer = isset($options["poll_allow_answer"]) && $options["poll_allow_answer"] == "on" ? true : false;
3061 $check_admin_approval = false;
3062 $flag_for_added_answer = false;
3063 if($allow_add_answer && (isset($_POST['ays_poll_new_answer']) && $_POST['ays_poll_new_answer'] != "")){
3064
3065 $flag_for_added_answer = true;
3066 $poll_allow_answer_require = isset($options['poll_allow_answer_require']) && $options['poll_allow_answer_require'] == "on" ? true : false;
3067 if($poll_allow_answer_require){
3068 $check_admin_approval = true;
3069 }
3070 // $poll_answers_count = isset($poll['answers']) ? count($poll['answers']) : 0;
3071 $new_anwer_data = array(
3072 'poll_id' => $poll_id,
3073 'new_answer' => wp_kses_post(stripslashes($_POST['ays_poll_new_answer'])),
3074 'admin_require' => $poll_allow_answer_require,
3075 'answers_count' => $poll_answers_count,
3076 'if_text_type' => false
3077 );
3078
3079 $added_answer_id = $this->ays_add_answer_poll($new_anwer_data);
3080
3081 if((is_array($answer_id) && !empty($answer_id)) && $allow_multi_vote){
3082 $answer_id[] = $added_answer_id['new_id'];
3083 }
3084 elseif(isset($answer_id) && !is_array($answer_id) && $answer_id > 0 && $allow_multi_vote){
3085 $answer_id = explode(" " , $answer_id);
3086 array_push($answer_id , $added_answer_id['new_id']);
3087 }
3088 else{
3089 $answer_id = $added_answer_id['new_id'];
3090 }
3091 }
3092 $poll_type_for_text_type = isset($poll['type']) && $poll['type'] == "text" ? true : false;
3093 $poll_answer = isset($_POST['answer']) && $_POST['answer'] != '' ? sanitize_text_field($_POST['answer']) : "";
3094
3095 // Add new text answer if not exist
3096 if($poll_type_for_text_type) {
3097 $text_anwer_data = array(
3098 'poll_id' => $poll_id,
3099 'new_answer' => $poll_answer,
3100 'admin_require' => false,
3101 'answers_count' => $poll_answers_count,
3102 'if_text_type' => true
3103 );
3104
3105 $is_answer_exist = $this->check_text_answer_exist($poll_id, $poll_answer);
3106 if (!$is_answer_exist) {
3107 $added_answer_id = $this->ays_add_answer_poll($text_anwer_data);
3108 $answer_id = $added_answer_id['new_id'];
3109 } else {
3110 $answer_id = $this->get_text_answer_id($poll_id, $poll_answer);
3111 }
3112 }
3113
3114 if ($answer_id > 0 || is_array($answer_id)) {
3115 if (isset($options['limit_users']) && $options['limit_users'] == 1) {
3116 $user_id = is_user_logged_in() ? wp_get_current_user()->ID : 0;
3117 $limit_users_method = isset($options['limit_users_method']) ? sanitize_text_field($options['limit_users_method']) : 'ip';
3118 $user_voted_count = 0;
3119 if ($limit_users_method == 'ip') {
3120 $user_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3121 }
3122 elseif($limit_users_method == 'cookie'){
3123 $cookie_name = "ays_this_poll_cookie_".$poll_id;
3124 if(!isset($_COOKIE[$cookie_name])){
3125 $cookie_value = "ays_vote_limitation_cookie_value";
3126 $time_limit = time() + (86400 * 30);
3127 setcookie($cookie_name, $cookie_value,$time_limit , '/');
3128 }else{
3129 $user_voted_count = 1;
3130 }
3131 }
3132 elseif($limit_users_method == 'cookie_ip'){
3133 $cookie_name = "ays_this_poll_cookie_".$poll_id;
3134 $limit_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3135 if(!isset($_COOKIE[$cookie_name])){
3136 $cookie_value = "ays_vote_limitation_cookie_value";
3137 $time_limit = time() + (86400 * 30);
3138 setcookie($cookie_name, $cookie_value,$time_limit , '/');
3139 }
3140 else{
3141 $user_voted_count = 1;
3142 }
3143 if(isset($_COOKIE[$cookie_name]) || $limit_voted_count > 0){
3144 $user_voted_count = 1;
3145 }
3146 elseif(!isset($_COOKIE[$cookie_name]) || $limit_voted_count > 0){
3147 $user_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3148 }
3149 }
3150 else{
3151 if ($user_id != 0) {
3152 $user_voted_count = $this->ays_poll_get_limit_user_count_by_id($poll_id,$user_id);
3153 }else{
3154 $user_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3155 }
3156 }
3157
3158 $user_voted_count = absint(intval(($user_voted_count)));
3159
3160 if ( $user_voted_count > 0 ) {
3161 $res = $this->get_poll_by_id($poll_id);
3162 $res['voted_status'] = false;
3163 ob_end_clean();
3164 $ob_get_clean = ob_get_clean();
3165 echo json_encode($res);
3166 wp_die();
3167 }
3168 }
3169
3170 if (!empty($options['info_form'])) {
3171 $user_email = isset($_POST["apm_email"]) && $_POST['apm_email'] !== null ? sanitize_email($_POST["apm_email"]) : '';
3172 }else{
3173 $user_email = '';
3174 }
3175
3176 $check_allowing = (isset($options['poll_allow_collecting_users_data']) && $options['poll_allow_collecting_users_data'] == 'on') ? true : false;
3177 $check_fields = (isset($options['info_form']) && $options['info_form'] == 1) ? true : false;
3178 if($check_allowing && !$check_fields){
3179 $this_user = wp_get_current_user();
3180 if($this_user->ID != 0){
3181 $_POST["apm_email"] = $this_user->data->user_email;
3182 $user_email = isset($_POST["apm_email"]) ? sanitize_email($_POST["apm_email"]) : "";
3183 $_POST['apm_name'] = $this_user->data->display_name;
3184 }
3185 }
3186 // MailChimp
3187
3188 if (isset($options['enable_mailchimp']) && $options['enable_mailchimp'] == 'on') {
3189 if (isset($options['mailchimp_list']) && $options['mailchimp_list'] != "") {
3190 $poll_settings = $this->settings;
3191 $mailchimp_res = ($poll_settings->ays_get_setting('mailchimp') === false) ? json_encode(array()) : $poll_settings->ays_get_setting('mailchimp');
3192 $mailchimp = json_decode($mailchimp_res, true);
3193 $mailchimp_username = isset($mailchimp['username']) ? $mailchimp['username'] : '';
3194 $mailchimp_api_key = isset($mailchimp['apiKey']) ? $mailchimp['apiKey'] : '';
3195 $mailchimp_list = (isset($options['mailchimp_list'])) ? $options['mailchimp_list'] : '';
3196 $mailchimp_email = $user_email;
3197 $user_name = isset($_POST['apm_name']) ? explode(" ", wp_filter_post_kses($_POST['apm_name'])) : array();
3198 $mailchimp_fname = (isset($user_name[0]) && $user_name[0] != "") ? $user_name[0] : "";
3199 $mailchimp_lname = (isset($user_name[1]) && $user_name[1] != "") ? $user_name[1] : "";
3200 $user_phone = isset($_POST['apm_phone']) ? explode(" ", wp_filter_post_kses($_POST['apm_phone'])) : array();
3201 $mailchimp_phone = (isset($user_phone[0]) && $user_phone[0] != "") ? $user_phone[0] : "";
3202 if ($mailchimp_username != "" && $mailchimp_api_key != "") {
3203 $args = array(
3204 "email" => $mailchimp_email,
3205 "fname" => $mailchimp_fname,
3206 "lname" => $mailchimp_lname,
3207 "pnumber" => $mailchimp_phone,
3208 );
3209 $mresult = $this->ays_add_mailchimp_transaction($mailchimp_username, $mailchimp_api_key, $mailchimp_list, $args);
3210 }
3211 }
3212 }
3213
3214 // $answer = $this->get_answer_by_id($answer_id);
3215
3216 // $votes = isset($answer['voted']) && $answer['voted'] !== null ? $answer['voted'] : 0;
3217 // $votes++;
3218
3219 $other_info = array(
3220 "Name" => "",
3221 "email" => "",
3222 "phone" => "",
3223 );
3224
3225 if (!empty($options['info_form']) || $check_allowing) {
3226 $other_info = array(
3227 "Name" => !empty($_POST['apm_name']) ? sanitize_text_field($_POST['apm_name']) : "",
3228 "email" => !empty($_POST['apm_email']) ? sanitize_email($_POST['apm_email']) : "",
3229 "phone" => !empty($_POST['apm_phone']) ? sanitize_text_field($_POST['apm_phone']) : "",
3230 );
3231 }
3232 if($poll_vote_reason){
3233 $other_info['voteReason'] = $poll_vote_reason_text;
3234 }
3235 // global $wpdb;
3236 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
3237 $report_table = esc_sql($wpdb->prefix."ayspoll_reports");
3238
3239 // AV IP Storing
3240 $settings_table = esc_sql($wpdb->prefix."ayspoll_settings");
3241 $key_meta = esc_sql('options');
3242 $sql_ip = "SELECT meta_value FROM ".$settings_table." WHERE meta_key = %s";
3243 $res_ip = $wpdb->get_var(
3244 $wpdb->prepare( $sql_ip, $key_meta)
3245 );
3246
3247 $options_res = ($res_ip === false) ? json_encode(array()) : $res_ip;
3248 $option_res = json_decode((string)$options_res, true);
3249
3250 $user_ips = isset($option_res['disable_ip_storing']) && $option_res['disable_ip_storing'] == 'on' ? '' : $this->get_user_ip_validated();
3251
3252 $poll_user_information = $this->get_user_profile_data();
3253 $user_first_name = (isset( $poll_user_information['user_first_name'] ) && $poll_user_information['user_first_name'] != "") ? $poll_user_information['user_first_name'] : '';
3254 $user_last_name = (isset( $poll_user_information['user_last_name'] ) && $poll_user_information['user_last_name'] != "") ? $poll_user_information['user_last_name'] : '';
3255 $creation_date = (isset( $poll['styles']['create_date'] ) && $poll['styles']['create_date'] != '') ? $poll['styles']['create_date'] : '';
3256
3257
3258 $current_poll_author = esc_html__( "Unknown", "poll-maker" );
3259 $current_poll_author_email = '';
3260 $current_poll_author_nickname = '';
3261 $current_poll_author_display_name = '';
3262 $current_poll_author_website_url = '';
3263 if( !empty($options['author']) ){
3264 if( !is_array($options['author']) ){
3265 $options['author'] = json_decode($options['author'], true);
3266 }
3267
3268 $poll_current_author = (isset($options['author']['id']) && $options['author']['id'] != "") ? absint(sanitize_text_field( $options['author']['id'] )) : "";
3269
3270 $current_poll_user_data = get_userdata( $poll_current_author );
3271 if ( ! is_null( $current_poll_user_data ) && $current_poll_user_data ) {
3272 $current_poll_author = ( 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 ) : "";
3273 $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 $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 $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 $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 ) : "";
3277 }
3278 }
3279
3280 // Get Current date
3281 $poll_current_date = date_i18n( 'M d, Y', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3282
3283 // Get Current time
3284 $poll_current_time = date_i18n( get_option( 'time_format' ), strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3285
3286 // Get Current day
3287 $poll_current_day = date_i18n( 'l', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3288
3289 // Get Current month
3290 $poll_current_month = date_i18n( 'F', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3291
3292 // Get Post Title
3293 $post_id = url_to_postid( $_POST['_wp_http_referer'] );
3294 $post_title = get_the_title( $post_id );
3295 $get_site_title = get_bloginfo('name');
3296 $get_site_description = get_bloginfo('description');
3297
3298 // WP home page url
3299 $home_main_url = home_url();
3300 $home_page_url = '<a href="'. $home_main_url .'" target="_blank">'. $home_main_url .'</a>';
3301
3302 $user_nickname = '';
3303 $user_first_name = '';
3304 $user_display_name = '';
3305 $user_wordpress_email = '';
3306 $user_wordpress_roles = '';
3307 $user_wordpress_website = '';
3308 $user_ip_address = '';
3309 $user_id = get_current_user_id();
3310 $user_data = wp_get_current_user();
3311 $super_admin_email = get_option('admin_email');
3312
3313 $post_author = get_post_field( 'post_author', $post_id );
3314 $author_id = get_the_author_meta('ID', $post_author);
3315 $post_author_email = get_the_author_meta( 'email', $author_id );
3316 $post_author_display_name = get_the_author_meta( 'display_name', $author_id );
3317 $post_author_nickname = get_the_author_meta( 'nickname', $author_id );
3318 $post_author_first_name = get_the_author_meta( 'first_name', $author_id );
3319 $post_author_last_name = get_the_author_meta( 'last_name', $author_id );
3320 $post_author_website_url = get_the_author_meta( 'url', $author_id );
3321
3322 $post_author_roles = '';
3323 $user_registered = '';
3324 if ( is_user_logged_in() ) {
3325 $post_author_roles = get_the_author_meta( 'roles', $author_id );
3326 $user_registered = $user_data->user_registered;
3327 }
3328
3329 if ( ! empty( $post_author_website_url ) ) {
3330 $post_author_website_url = '<a href="'. $post_author_website_url .'" target="_blank">'. $post_author_website_url .'</a>';
3331 }
3332
3333 if ( ! empty( $current_poll_author_website_url ) ) {
3334 $current_poll_author_website_url = '<a href="'. $current_poll_author_website_url .'" target="_blank">'. $current_poll_author_website_url .'</a>';
3335 }
3336
3337 if ( ! empty( $post_author_roles ) && $post_author_roles != "" ) {
3338 if ( is_array( $post_author_roles ) ) {
3339 $post_author_roles = implode( ", ", $post_author_roles );
3340 }
3341 }
3342
3343 if( $user_id != 0 ){
3344 $usermeta = get_user_meta( $user_id );
3345 if($usermeta !== null){
3346 $user_nickname = (isset($usermeta['nickname'][0]) && sanitize_text_field( $usermeta['nickname'][0] != '') ) ? sanitize_text_field( $usermeta['nickname'][0] ) : '';
3347 $user_first_name = (isset($usermeta['first_name'][0]) && sanitize_text_field( $usermeta['first_name'][0] != '') ) ? sanitize_text_field( $usermeta['first_name'][0] ) : '';
3348 }
3349
3350 $current_user_data = get_userdata( $user_id );
3351 if ( ! is_null( $current_user_data ) && $current_user_data ) {
3352 $user_display_name = ( isset( $current_user_data->data->display_name ) && $current_user_data->data->display_name != '' ) ? sanitize_text_field( $current_user_data->data->display_name ) : "";
3353 $user_wordpress_email = ( isset( $current_user_data->data->user_email ) && $current_user_data->data->user_email != '' ) ? sanitize_text_field( $current_user_data->data->user_email ) : "";
3354
3355 $user_wordpress_roles = ( isset( $current_user_data->roles ) && ! empty( $current_user_data->roles ) ) ? $current_user_data->roles : "";
3356 $user_ip_address = $this->get_user_ip_validated();
3357
3358 if ( !empty( $user_wordpress_roles ) && $user_wordpress_roles != "" ) {
3359 if ( is_array( $user_wordpress_roles ) ) {
3360 $user_wordpress_roles = implode(",", $user_wordpress_roles);
3361 }
3362 }
3363
3364 $user_wordpress_website_url = ( isset( $current_user_data->user_url ) && ! empty( $current_user_data->user_url ) ) ? sanitize_url($current_user_data->user_url) : "";
3365
3366 if( !empty( $user_wordpress_website_url ) ){
3367 $user_wordpress_website = "<a href='". esc_url( $user_wordpress_website_url ) ."' target='_blank' class='ays-poll-user-website-link-a-tag'>".esc_html__( "Website", "poll-maker" ) ."</a>";
3368 }
3369 }
3370 }
3371
3372 if ( is_user_logged_in() ) {
3373 $current_user_id = get_current_user_id();
3374 } else {
3375 $current_user_id = '';
3376 }
3377
3378 $report_table = $wpdb->prefix."ayspoll_reports";
3379 $answ_table = $wpdb->prefix."ayspoll_answers";
3380
3381 $sql = "SELECT COUNT(*)
3382 FROM ".$report_table."
3383 JOIN ".$answ_table."
3384 ON ".$answ_table.".id = ".$report_table.".answer_id
3385 WHERE ".$answ_table.".poll_id =".$poll_id;
3386
3387 $pass_count_results = $wpdb->get_var($sql);
3388 $pass_count = ( isset($pass_count_results) && $pass_count_results != '' ) ? intval( $pass_count_results ) : 0;
3389
3390 $passed_poll_count_per_user = Poll_Maker_Data::get_user_passed_polls_count( $user_id );
3391
3392 $ays_protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
3393
3394 $current_poll_page_link = isset( $_REQUEST['ays_poll_curent_page_link'] ) && $_REQUEST['ays_poll_curent_page_link'] != '' ? sanitize_url( $_REQUEST['ays_poll_curent_page_link'] ) : "";
3395 $current_poll_page_link_html = "<a href='". esc_sql( $current_poll_page_link ) ."' target='_blank' class='ays-poll-curent-page-link-a-tag'>".esc_html__( "Poll link", "poll-maker" ) ."</a>";
3396
3397 $form_apm_name = (isset($_POST['apm_name']) && $_POST['apm_name'] != "") ? esc_attr($_POST['apm_name']) : "";
3398 $form_apm_email = (isset($_POST['apm_email']) && $_POST['apm_email'] != "") ? esc_attr($_POST['apm_email']) : "";
3399 $form_apm_phone = (isset($_POST['apm_phone']) && $_POST['apm_phone'] != "") ? esc_attr($_POST['apm_phone']) : "";
3400
3401 $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,
3444 );
3445
3446 $user_ip = esc_sql($user_ips);
3447
3448 // Race condition fix
3449 $limitusers = isset($poll['styles']['limit_users']) ? intval($poll['styles']['limit_users']) : 0;
3450
3451 if ($limitusers > 0) {
3452
3453 $limit_users_method = isset($poll['styles']['limit_users_method']) ? $poll['styles']['limit_users_method'] : "ip";
3454
3455 switch ($limit_users_method) {
3456 case 'ip':
3457 default:
3458 $wpdb->query("START TRANSACTION");
3459 $already_voted = $wpdb->get_var($wpdb->prepare(
3460 "SELECT COUNT(*) FROM {$report_table} WHERE user_ip = %s AND poll_id = %d FOR UPDATE",
3461 $user_ip,
3462 $poll_id
3463 ));
3464 break;
3465 case 'cookie':
3466 $wpdb->query("START TRANSACTION");
3467 $already_voted = isset($_COOKIE["ays_this_poll_cookie_" . $poll_id]) ? 1 : 0;
3468 break;
3469 case 'user':
3470 $wpdb->query("START TRANSACTION");
3471 $already_voted = $wpdb->get_var($wpdb->prepare(
3472 "SELECT COUNT(*) FROM {$report_table} WHERE user_id = %s AND poll_id = %d FOR UPDATE",
3473 $user_id,
3474 $poll_id
3475 ));
3476 break;
3477 }
3478
3479 if ($already_voted > 0) {
3480 $wpdb->query("ROLLBACK");
3481
3482 $res = $this->get_poll_by_id($poll_id);
3483 $res['voted_status'] = false;
3484 echo json_encode($res);
3485 wp_die();
3486 }
3487 }
3488
3489 $multi_answer_ids = array();
3490 if ((is_array($answer_id) && !empty($answer_id)) && $allow_multi_vote) {
3491 $multi_answer_ids = $answer_id;
3492 $answer_changed_id = $answer_id[0];
3493 foreach($answer_id as $a_key => $a_id){
3494 $this_answer = $this->get_answer_by_id_multi($a_id);
3495 if(isset($this_answer[0])){
3496 $votes_new = isset($this_answer[0]['votes']) ? intval($this_answer[0]['votes']) : 0;
3497 $votes_new++;
3498 $wpdb->update(
3499 $answ_table,
3500 array('votes' => $votes_new),
3501 array('id' => $a_id),
3502 array('%d'),
3503 array('%d')
3504 );
3505
3506 }
3507
3508 }
3509 } else {
3510 $answer_changed_id = $answer_id;
3511 $multi_answer_ids[] = $answer_changed_id;
3512 $answer = $this->get_answer_by_id($answer_id);
3513 $votes = isset($answer['votes']) && $answer['votes'] !== null ? intval($answer['votes']) : 0;
3514 $votes++;
3515 $wpdb->update(
3516 $answ_table,
3517 array('votes' => $votes),
3518 array('id' => $answer_id),
3519 array('%d'),
3520 array('%d')
3521 );
3522 }
3523 $wpdb->insert(
3524 $report_table,
3525 array(
3526 'answer_id' => $answer_changed_id,
3527 'user_ip' => $user_ip,
3528 'user_id' => is_user_logged_in() ? wp_get_current_user()->ID : 0,
3529 'vote_date' => esc_sql( sanitize_text_field( $_REQUEST['end_date'] ) ),
3530 'user_email' => $user_email,
3531 'other_info' => json_encode($other_info),
3532 'poll_id' => $poll_id,
3533 'multi_answer_ids' => json_encode($multi_answer_ids)
3534 ),
3535 array(
3536 '%d', // answer_id
3537 '%s', // user_ip
3538 '%s', // user_id
3539 '%s', // vote_date
3540 '%s', // user_email
3541 '%s', // other_info
3542 '%d', // poll_id
3543 '%s', // multi_answer_ids
3544 )
3545 );
3546
3547 // Race condition fix
3548 if ($limitusers > 0) {
3549 $wpdb->query("COMMIT");
3550 }
3551
3552 // $answers = $this->get_answer_by_id($answer_changed_id);
3553 if (!empty($options['notify_email_on'])) {
3554 $notify_admin_email = $options['notify_email'];
3555 $use_answered = '';
3556 if(isset($answer_titless) && !empty($answer_titless)){
3557 $use_answered = implode(', ', $answer_titless);
3558 }
3559 $subject = $poll_title;
3560 $headers = "MIME-Version: 1.0\r\n";
3561 $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
3562 $attachment = array();
3563 $mail_text = (
3564 /* translators: 1: user answer variable, 2: poll title variable 3: anchor tag */
3565 sprintf(esc_html__( "Someone's answer %1\$s in your %2\$s poll on %3\$s.", "poll-maker" ),
3566 $use_answered,
3567 '"' . $poll_title . '"',
3568 "<a href='" . home_url() . "' target='_blank'>" . home_url() . "</a>"
3569 ));
3570 wp_mail($notify_admin_email, $subject, $mail_text, $headers, $attachment);
3571 }
3572
3573 }
3574 $res = $this->get_poll_by_id($poll_id);
3575 $res['voted_status'] = true;
3576 $numbering_arr = array();
3577 // $res['numbering'] = "none";
3578 // if($show_answers_numbering != "none"){
3579 // $answer_count = isset($res['answers']) && !empty($res['answers']) ? count($res['answers']) : false;
3580 // if($answer_count){
3581 // $numbering_arr = $this->ays_answer_numbering($show_answers_numbering , $answer_count);
3582 // $res['numbering'] = $numbering_arr;
3583 // }
3584 // }
3585 $check_user = false;
3586 if(isset($options['show_passed_users']) && $options['show_passed_users'] == 'on'){
3587 $check_user = true;
3588 $poll_avatar_user_count = isset($options['poll_show_passed_users_count']) && $options['poll_show_passed_users_count'] != "" ? $options['poll_show_passed_users_count'] : 3;
3589 $results_table = $wpdb->prefix."ayspoll_reports";
3590 $all_answers = isset($res['answers']) && !empty($res['answers']) ? $res['answers'] : array();
3591 $answer_ids = array();
3592 if(isset($all_answers) && !empty($all_answers)){
3593 foreach($all_answers as $answer => $value){
3594 $answer_ids[] = $value['id'];
3595 }
3596 }
3597 $answer_ids = implode(',' , $answer_ids);
3598 $sql_users = "SELECT `user_id` , `answer_id`
3599 FROM ".$results_table."
3600 WHERE `answer_id` IN (".$answer_ids.")
3601 GROUP BY user_id, answer_id
3602 ORDER BY vote_date DESC";
3603 $user_res = $wpdb->get_results($sql_users , ARRAY_A);
3604 $user_pic_args = array(
3605 "class" => "ays-user-profile-pic"
3606 );
3607 $users_res_array = array();
3608 foreach($user_res as $ar){
3609 // if( isset( $users_res_array[$ar['answer_id']] ) ){
3610 // continue;
3611 // }
3612 $users_res_array[$ar['answer_id']][] = intval( $ar['user_id'] );
3613 }
3614
3615 if(isset($all_answers) && !empty($all_answers)){
3616 foreach($all_answers as $key => $answer){
3617 $user_answers = array();
3618 if( array_key_exists( $answer['id'], $users_res_array ) ){
3619 $user_answers = $this->ays_poll_get_avatars($answer['id'] , $users_res_array);
3620 }
3621 $res['answers'][$key]['avatar'] = $user_answers;
3622 }
3623 }
3624 $res['check_user_pic'] = $check_user;
3625 $res['check_user_pic_count'] = $poll_avatar_user_count;
3626 $res['check_user_pic_url'] = POLL_MAKER_AYS_PUBLIC_URL.'/images/more.png';
3627 $res['check_user_pic_loader'] = POLL_MAKER_AYS_PUBLIC_URL.'/images/tail-spin.svg';
3628 }
3629 if(!isset($message_data)){
3630 $message_data = array();
3631 }
3632 $res['styles']['poll_social_links_heading'] = ( isset( $res['styles']['poll_social_links_heading'] ) && $res['styles']['poll_social_links_heading'] != "" ) ? $this->ays_autoembed($res['styles']['poll_social_links_heading']) : "";
3633
3634
3635 $res['styles']['result_message'] = ( isset( $res['styles']['result_message'] ) && $res['styles']['result_message'] != "" ) ? $this->ays_autoembed($this->replace_message_variables($res['styles']['result_message'], $message_data)) : "";
3636 $res['styles']['hide_results_text'] = ( isset( $res['styles']['hide_results_text'] ) && $res['styles']['hide_results_text'] != "" ) ? $this->ays_autoembed($this->replace_message_variables($res['styles']['hide_results_text'], $message_data)) : "";
3637 $sensitive_fields = [
3638 'notify_email',
3639 'author',
3640 'poll_create_author',
3641 'mailchimp_list',
3642 'users_role'
3643 ];
3644 if (!current_user_can('manage_options')) {
3645 foreach ($sensitive_fields as $field) {
3646 if (isset($res['styles'][$field]) && $res['styles'][$field] != "") {
3647 unset($res['styles'][$field]);
3648 }
3649 }
3650 }
3651 $res['styles']['poll_social_buttons_heading'] = ( isset( $res['styles']['poll_social_buttons_heading'] ) && $res['styles']['poll_social_buttons_heading'] != "" ) ? $this->ays_autoembed($res['styles']['poll_social_buttons_heading']) : "";
3652 $res['check_admin_approval'] = $check_admin_approval;
3653
3654 /**
3655 * Fires after a user successfully submits a vote in Poll Maker.
3656 *
3657 * @since 1.0.0
3658 *
3659 * @param int $poll_id The poll ID.
3660 */
3661 if (has_action('ays_poll_maker_after_vote')) {
3662 // Collect extra contextual data for hooks
3663 $user_id = get_current_user_id();
3664 $data = array_merge(
3665 (array) $message_data,
3666 array(
3667 'poll_id' => $poll_id,
3668 'answer_id' => $answer_id,
3669 'user_id' => $user_id,
3670 )
3671 );
3672 do_action(
3673 'ays_poll_maker_after_vote',
3674 $data
3675 );
3676 }
3677
3678 ob_end_clean();
3679 $ob_get_clean = ob_get_clean();
3680 echo json_encode($res);
3681 wp_die();
3682 }
3683 }
3684
3685 public function ays_poll_get_avatars($answer , $users){
3686 $user_answers = array();
3687 $user_pic_args = array(
3688 "class" => "ays-user-profile-pic"
3689 );
3690 foreach($users[$answer] as $res_key => $res_value){
3691 if($res_value == 0){
3692 continue;
3693 }
3694 $user_avatars = get_avatar($res_value, 24, $default = '', $alt = '', $user_pic_args);
3695 $user_avatars = isset($user_avatars) && $user_avatars ? $user_avatars : '' ;
3696 $user_answers[] = "<div class='ays-users-profile-pics'>".$user_avatars."</div>";
3697 }
3698 return $user_answers;
3699 }
3700
3701 public function ays_add_mailchimp_transaction( $username, $api_key, $list_id, $args ) {
3702
3703 $email = isset($args['email']) ? $args['email'] : null;
3704 $fname = isset($args['fname']) ? $args['fname'] : "";
3705 $lname = isset($args['lname']) ? $args['lname'] : "";
3706 $phone = isset($args['pnumber']) ? $args['pnumber'] : "";
3707
3708 $api_prefix = explode("-", $api_key)[1];
3709
3710 $fields = array(
3711 "email_address" => $email,
3712 "status" => "subscribed",
3713 "merge_fields" => array(
3714 "FNAME" => $fname,
3715 "LNAME" => $lname,
3716 "PHONE" => $phone
3717 )
3718 );
3719 $curl = curl_init();
3720 curl_setopt_array($curl, array(
3721 CURLOPT_URL => "https://" . $api_prefix . ".api.mailchimp.com/3.0/lists/" . $list_id . "/members/",
3722 CURLOPT_RETURNTRANSFER => true,
3723 CURLOPT_ENCODING => "",
3724 CURLOPT_MAXREDIRS => 10,
3725 CURLOPT_TIMEOUT => 30,
3726 CURLOPT_SSL_VERIFYPEER => false,
3727 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
3728 CURLOPT_USERPWD => "$username:$api_key",
3729 CURLOPT_CUSTOMREQUEST => "POST",
3730 CURLOPT_POSTFIELDS => json_encode($fields),
3731 CURLOPT_HTTPHEADER => array(
3732 "Content-Type: application/json",
3733 "cache-control: no-cache"
3734 ),
3735 ));
3736
3737 $response = curl_exec($curl);
3738
3739 $err = curl_error($curl);
3740
3741 curl_close($curl);
3742
3743 if ($err) {
3744 return "cURL Error #: " . $err;
3745 } else {
3746 return $response;
3747 }
3748 }
3749
3750 private function get_answer_by_id( $id ) {
3751 global $wpdb;
3752 $args_id = absint(intval($id));
3753 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
3754 // $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
3755 // $sql = "SELECT a.*, COUNT(r.id) as voted FROM ".$answ_table." as a
3756 // JOIN ".$rep_table." as r
3757 // ON FIND_IN_SET(a.id , r.answer_id)
3758 // WHERE a.id = %d";
3759
3760 $sql = "SELECT * FROM ".$answ_table."
3761 WHERE id = %d";
3762
3763 $answ_id = $wpdb->get_row(
3764 $wpdb->prepare( $sql, $args_id),
3765 'ARRAY_A'
3766 );
3767
3768 return $answ_id;
3769 }
3770
3771 private function check_text_answer_exist( $poll_id, $user_answer ) {
3772 global $wpdb;
3773
3774 $answ_table = esc_sql($wpdb->prefix . "ayspoll_answers");
3775
3776 $sql = "SELECT * FROM " . $answ_table . " WHERE poll_id = %d AND answer = %s";
3777
3778 $answ_id = $wpdb->get_results(
3779 $wpdb->prepare( $sql, $poll_id, $user_answer),
3780 'ARRAY_A'
3781 );
3782 return (!empty($answ_id));
3783 }
3784
3785 private function get_text_answer_id($poll_id, $user_answer) {
3786 global $wpdb;
3787 $answ_table = esc_sql($wpdb->prefix . "ayspoll_answers");
3788
3789 $sql = $wpdb->prepare(
3790 "SELECT MAX(id) FROM $answ_table WHERE poll_id = %d AND answer = %s",
3791 $poll_id,
3792 $user_answer
3793 );
3794
3795 $last_id = $wpdb->get_var($sql);
3796
3797 if (is_null($last_id)) {
3798 return 0;
3799 }
3800
3801 return (int) $last_id;
3802 }
3803
3804 public static function get_answer_by_ids( $ids ) {
3805 global $wpdb;
3806 $sql = "SELECT * FROM {$wpdb->prefix}ayspoll_answers
3807 WHERE id IN (".$ids.")";
3808 return $wpdb->get_results($sql, 'ARRAY_A');
3809 }
3810
3811 public function check_shedule_expired_poll( $args ) {
3812 $id = absint(intval($args));
3813 $poll_options = $this->get_poll_by_id($id);
3814 $options = $poll_options['styles'];
3815
3816 $is_expired = true;
3817 $startDate = '';
3818 $endDate = '';
3819 $current_time = strtotime(current_time( "Y:m:d H:i:s" ));
3820 if (isset($options['active_date_check']) && !empty($options['active_date_check'])) {
3821 if (isset($options['activeInterval']) && isset($options['deactiveInterval'])) {
3822 if (isset($options['activeIntervalSec']) && !empty($options['activeIntervalSec'])) {
3823 $startDate = strtotime($options['activeInterval']." ".$options['activeIntervalSec']);
3824 }
3825 else{
3826 $startDate = strtotime($options['activeInterval']);
3827 }
3828
3829 if (isset($options['deactiveIntervalSec']) && !empty($options['deactiveIntervalSec'])) {
3830 $endDate = strtotime($options['deactiveInterval']." ".$options['deactiveIntervalSec']);
3831 }
3832 else{
3833 $endDate = strtotime($options['deactiveInterval']);
3834 }
3835
3836 if ($startDate < $current_time && $endDate > $current_time) {
3837 $is_expired = true;
3838 }else{
3839 $is_expired = false;
3840 }
3841 }
3842 }
3843 $published = (isset($options['published']) && intval($options['published']) === 0) ? false : true;
3844 return $is_expired && $published ? true : false;
3845 }
3846
3847 protected function hex2rgba($color, $opacity = false){
3848
3849 $default = 'rgb(0,0,0)';
3850
3851 //Return default if no color provided
3852 if (empty($color))
3853 return $default;
3854
3855 //Sanitize $color if "#" is provided
3856 if ($color[0] == '#') {
3857 $color = substr($color, 1);
3858 }else{
3859 return $color;
3860 }
3861
3862 //Check if color has 6 or 3 characters and get values
3863 if (strlen($color) == 6) {
3864 $hex = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]);
3865 } elseif (strlen($color) == 3) {
3866 $hex = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]);
3867 } else {
3868 return $default;
3869 }
3870
3871 //Convert hexadec to rgb
3872 $rgb = array_map('hexdec', $hex);
3873
3874 //Check if opacity is set(rgba or rgb)
3875 if ($opacity) {
3876 if (abs($opacity) > 1)
3877 $opacity = 1.0;
3878 $output = 'rgba(' . implode(",", $rgb) . ',' . $opacity . ')';
3879 } else {
3880 $output = 'rgb(' . implode(",", $rgb) . ')';
3881 }
3882
3883 //Return rgb(a) color string
3884 return $output;
3885 }
3886
3887 public function rgb2hex( $rgb ) {
3888 if ($rgb[0] == '#') {
3889 return $rgb;
3890 }
3891 $colors = explode(',', rtrim(explode('(', $rgb)[1], ')'));
3892
3893 return sprintf("#%02x%02x%02x", $colors[0], $colors[1], $colors[2]);
3894 }
3895
3896 public static function ays_poll_get_limit_user_count_by_id($poll_id, $user_id){
3897 global $wpdb;
3898
3899 $id = absint(intval($poll_id));
3900 $reports_table = esc_sql($wpdb->prefix."ayspoll_reports");
3901 $answers_table = esc_sql($wpdb->prefix."ayspoll_answers");
3902
3903 $sql = "SELECT COUNT(*)
3904 FROM ".$reports_table."
3905 INNER JOIN ".$answers_table."
3906 ON ".$answers_table.".id=".$reports_table.".answer_id
3907 WHERE ".$answers_table.".poll_id = ".$id." AND ".$reports_table.".user_id = ".$user_id;
3908
3909 $result = intval($wpdb->get_var($sql));
3910
3911 return $result;
3912 }
3913
3914 public static function ays_poll_get_limit_user_count_by_ip($poll_id){
3915 global $wpdb;
3916 $id = absint(intval($poll_id));
3917 $user_ip = self::get_user_ip_validated();
3918 $reports_table = esc_sql($wpdb->prefix."ayspoll_reports");
3919 $answers_table = esc_sql($wpdb->prefix."ayspoll_answers");
3920
3921 $sql = "SELECT COUNT(*)
3922 FROM ".$reports_table."
3923 INNER JOIN ".$answers_table."
3924 ON ".$answers_table.".id=".$reports_table.".answer_id
3925 WHERE ".$answers_table.".poll_id = ".$id." AND ".$reports_table.".user_ip = '". $user_ip ."'";
3926
3927 $result = intval($wpdb->get_var($sql));
3928
3929 return $result;
3930 }
3931
3932 public function ays_poll_get_results($id) {
3933
3934 global $wpdb;
3935 $content = '';
3936 $id = absint(intval($id));
3937 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
3938 $polls_table = esc_sql($wpdb->prefix."ayspoll_polls");
3939
3940
3941 $poll_sql = "SELECT * FROM ".$polls_table." WHERE id =%d";
3942 $polls = $wpdb->get_row(
3943 $wpdb->prepare( $poll_sql, $id),
3944 'ARRAY_A'
3945 );
3946 $votes_count = $this->get_poll_results_count_by_id($id);
3947 $poll = $this->get_poll_by_id($id);
3948 $polls_options = $poll['styles'];
3949
3950
3951 // $poll_answer_sorting = isset($polls_options['result_sort_type']) && $polls_options['result_sort_type'] != "none" ? $polls_options['result_sort_type'] : "ASC";
3952 $ans_sql = "SELECT * FROM ".$answ_table." WHERE poll_id =%d ORDER BY votes DESC";
3953 $poll_answers = $wpdb->get_results(
3954 $wpdb->prepare( $ans_sql, $id),
3955 'ARRAY_A'
3956 );
3957 if ($polls == null) {
3958 $content = '<p style="text-align:center;">No ratings yet</p>';
3959 }else{
3960 // $votes_count = $this->get_poll_results_count_by_id($id);
3961 // $poll = $this->get_poll_by_id($id);
3962 // $polls_options = $poll['styles'];
3963 $content .= "<div class='results-apm'>";
3964 if (intval($votes_count['res_count']) > 0) {
3965 $one_percent = 100/intval($votes_count['res_count']);
3966 }else{
3967 $one_percent = 1;
3968 }
3969
3970 $poll_show_answer_perc = isset($polls_options['show_res_percent']) && $polls_options['show_res_percent'] == 1 ? true : false;
3971 $poll_show_votes_count = isset($polls_options['show_votes_count']) && $polls_options['show_votes_count'] == 1 ? true : false;
3972 $poll_main_color = isset($polls_options['main_color']) && $polls_options['main_color'] != '' ? esc_attr($polls_options['main_color']) : '';
3973 $poll_bg_color = isset($polls_options['bg_color']) && $polls_options['bg_color'] != '' ? esc_attr($polls_options['bg_color']) : '';
3974 $poll_hide_result = isset($polls_options['hide_results']) && $polls_options['hide_results'] == 1 ? true : false;
3975 $poll_hide_result_message_check = isset($polls_options['hide_result_message']) && $polls_options['hide_result_message'] == 1 ? true : false;
3976 $poll_hide_result_message = isset($polls_options['hide_results_text']) && $polls_options['hide_results_text'] != "" ? wpautop($polls_options['hide_results_text']) : "";
3977 $poll_show_avatars = isset($polls_options['show_passed_users']) && $polls_options['show_passed_users'] == "on" ? true : false;
3978 $poll_avatars_count = isset($polls_options['poll_show_passed_users_count']) && $polls_options['poll_show_passed_users_count'] != "" ? $polls_options['poll_show_passed_users_count'] : 3;
3979 if($poll_hide_result){
3980 $content .= "<div >" . $poll_hide_result_message . "</div>";
3981 }
3982 else{
3983 $poll_answers_count = count($poll_answers);
3984
3985 if($poll_show_avatars){
3986 $results_table = $wpdb->prefix."ayspoll_reports";
3987 $answer_ids = array();
3988 if(isset($poll_answers) && !empty($poll_answers)){
3989 foreach($poll_answers as $answer => $value){
3990 $answer_ids[] = $value['id'];
3991 }
3992 }
3993 $answer_ids = implode(',' , $answer_ids);
3994 $sql_users = "SELECT `user_id` , `answer_id`
3995 FROM ".$results_table."
3996 WHERE `answer_id` IN (".$answer_ids.")
3997 GROUP BY user_id, answer_id
3998 ORDER BY vote_date DESC";
3999 $user_res = $wpdb->get_results($sql_users , ARRAY_A);
4000 $user_pic_args = array(
4001 "class" => "ays-user-profile-pic"
4002 );
4003 $users_res_array = array();
4004 foreach($user_res as $ar){
4005 $users_res_array[$ar['answer_id']][] = intval( $ar['user_id'] );
4006 }
4007
4008 if(isset($poll_answers) && !empty($poll_answers)){
4009 foreach($poll_answers as $key => $answer){
4010 $user_answers = array();
4011 if( array_key_exists( $answer['id'], $users_res_array ) ){
4012 $user_answers = $this->ays_poll_get_avatars($answer['id'] , $users_res_array);
4013 }
4014 $poll_answers[$key]['avatar'] = $user_answers;
4015 }
4016 }
4017 }
4018 foreach ($poll_answers as $ans_key => $ans_val) {
4019 $poll_avatars_content = "";
4020 $poll_user_avatars = "";
4021 $answer_img = (isset( $ans_val['answer_img'] ) && $ans_val['answer_img'] != '') ? $ans_val['answer_img'] : "";
4022 if(isset($ans_val["avatar"]) && !empty($ans_val["avatar"])){
4023 $x = array_splice($ans_val["avatar"] , 0 ,$poll_avatars_count);
4024 $poll_user_avatars = implode(" " , $x);
4025
4026 }
4027 if($poll_show_avatars && $poll_user_avatars != ""){
4028 $poll_avatars_content = '<div class="ays-user-count">
4029 '.$poll_user_avatars.'
4030 <div class="ays-users-profile-pics">
4031 <img src="'.esc_url(POLL_MAKER_AYS_PUBLIC_URL).'/images/more.png" width="24" height="24" class="ays-user-image-more" data-answer-id='.$ans_val["id"].'>
4032 </div>
4033 </div>';
4034 }
4035 $perc_cont = '';
4036 $percent = round($one_percent*intval($ans_val['votes']));
4037 $perc_conta_hide_or_no = '';
4038 if($poll_show_answer_perc){
4039 if ($percent == 0) {
4040 $perc_cont = '0 %';
4041 $perc_conta_hide_or_no = '';
4042 }else{
4043 $perc_cont = $percent.' %';
4044 $perc_conta_hide_or_no = '('.$percent.'%'.')';
4045 }
4046
4047 }
4048
4049 $answer_votes_count = '';
4050 if($poll_show_votes_count){
4051 $answer_votes_count = isset($ans_val['votes']) ? esc_attr($ans_val['votes']) : '';
4052 }
4053 switch ($polls['type']) {
4054 case 'choosing':
4055 $content .= "<div class='ays-poll-answers-box'>";
4056 if($answer_img != ''){
4057 $content .= "<div class='ays-poll-answers-image-box'>
4058
4059 <img src='" . $answer_img ."' class='ays-poll-answers-current-image'>
4060
4061 </div>";
4062 }
4063
4064 $content .= '<div class="ays-poll-answer-text-and-percent-box">';
4065 $content .= '<div class="answer-title flex-apm">
4066 <span class="answer-text">' . stripslashes($ans_val['answer']) . '</span>
4067 <span class="answer-votes">'.$answer_votes_count.' '.$perc_conta_hide_or_no.'</span>
4068 </div>
4069 ' . $poll_avatars_content . '
4070 <div class="answer-percent-res" style="width: ' . ($percent == 0 ? '10' : $percent) . '%;
4071 border-radius: 20px;
4072 background-color: ' . $poll_main_color . ';
4073 color: ' . $poll_bg_color . ';
4074 padding-left: 10px;
4075 font-size: 15px;
4076 text-align: left;">' . $perc_cont . '</div>';
4077 $content .= '</div>';
4078 $content .= '</div>';
4079 break;
4080
4081 case 'rating':
4082 switch ($polls['view_type']) {
4083 case 'star':
4084 $star_type = '';
4085 for ($i=0; $i < intval($ans_val['answer']); $i++) {
4086 $star_type .= '<i class="ays_poll_far ays_poll_fa-star far"></i>';
4087 }
4088 $content .= '<div class="answer-title flex-apm">
4089 <span class="answer-text">'.$star_type.'</span>
4090 <span class="answer-votes">'.$answer_votes_count.'</span>
4091 </div>
4092 '.$poll_avatars_content.'
4093 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4094 break;
4095
4096 case 'emoji':
4097 $emojy_type = '';
4098 if ($poll_answers_count == 3) {
4099 switch (intval($ans_val['answer'])) {
4100 case 1:
4101 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
4102 break;
4103 case 2:
4104 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-meh far"></i>';
4105 break;
4106 case 3:
4107 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
4108 break;
4109 default:
4110 break;
4111 }
4112 }else{
4113 switch (intval($ans_val['answer'])) {
4114 case 1:
4115 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-tired far"></i>';
4116 break;
4117 case 2:
4118 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
4119 break;
4120 case 3:
4121 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-meh far"></i>';
4122 break;
4123 case 4:
4124 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
4125 break;
4126 case 5:
4127 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-dizzy far"></i>';
4128 break;
4129 default:
4130 break;
4131 }
4132 }
4133
4134 $content .= '<div class="answer-title flex-apm">
4135 <span class="answer-text">'.$emojy_type.'</span>
4136 <span class="answer-votes">'.$answer_votes_count.'</span>
4137 </div>
4138 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4139
4140 break;
4141 default:
4142 break;
4143 }
4144 break;
4145
4146 case 'voting':
4147 switch ($polls['view_type']) {
4148 case 'hand':
4149 $hand_type = '';
4150 if (intval($ans_val['answer'] == 1)) {
4151 $hand_type = '<i class="ays_poll_far ays_poll_fa-thumbs-up far"></i>';
4152 }else{
4153 $hand_type = '<i class="ays_poll_far ays_poll_fa-thumbs-down far"></i>';
4154 }
4155 $content .= '<div class="answer-title flex-apm">
4156 <span class="answer-text">'.$hand_type.'</span>
4157 <span class="answer-votes">'.$answer_votes_count.'</span>
4158 </div>
4159 '.$poll_avatars_content.'
4160 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4161 break;
4162
4163 case 'emoji':
4164 $emojy_type = '';
4165 if (intval($ans_val['answer'] == 1)) {
4166 $emojy_type = '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
4167 }else{
4168 $emojy_type = '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
4169 }
4170 $content .= '<div class="answer-title flex-apm">
4171 <span class="answer-text">'.$emojy_type.'</span>
4172 <span class="answer-votes">'.$answer_votes_count.'</span>
4173 </div>
4174 '.$poll_avatars_content.'
4175 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4176
4177 break;
4178 default:
4179 break;
4180 }
4181 break;
4182 default:
4183 break;
4184 }
4185
4186 }
4187 }
4188
4189 }
4190 $content .= "</div>";
4191 return $content;
4192 }
4193
4194 public function intToRoman($num) {
4195 $map = array(
4196 1000 => 'M', 900 => 'CM', 500 => 'D', 400 => 'CD',
4197 100 => 'C', 90 => 'XC', 50 => 'L', 40 => 'XL',
4198 10 => 'X', 9 => 'IX', 5 => 'V', 4 => 'IV', 1 => 'I'
4199 );
4200 $roman = '';
4201 foreach ($map as $value => $symbol) {
4202 while ($num >= $value) {
4203 $roman .= $symbol;
4204 $num -= $value;
4205 }
4206 }
4207 return $roman;
4208 }
4209
4210 public function ays_answer_numbering($numbering , $count){
4211 $keyword_arr = array();
4212 switch ($numbering) {
4213 case '1.':
4214 $char_min_val = 1;
4215 for($x = $char_min_val; $x <= $count; $x++){
4216 $keyword_arr[] = $x .".";
4217 }
4218 break;
4219 case '1)':
4220 $char_min_val = 1;
4221 for($x = $char_min_val; $x <= $count; $x++){
4222 $keyword_arr[] = $x .")";
4223 }
4224 break;
4225 case 'A.':
4226 $columns = array();
4227 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4228 foreach($keyword_arr as $key => $value){
4229 $columns[] = $value . ".";
4230 }
4231 $keyword_arr = $columns;
4232 break;
4233 case 'A)':
4234 $columns = array();
4235 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4236 foreach($keyword_arr as $key => $value){
4237 $columns[] = $value . ")";
4238 }
4239 $keyword_arr = $columns;
4240 break;
4241 case 'a.':
4242 $columns = array();
4243 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4244 foreach($keyword_arr as $key => $value){
4245 $columns[] = strtolower($value) . ".";
4246 }
4247 $keyword_arr = $columns;
4248 break;
4249 case 'a)':
4250 $columns = array();
4251 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4252 foreach($keyword_arr as $key => $value){
4253 $columns[] = strtolower($value) . ")";
4254 }
4255 $keyword_arr = $columns;
4256 break;
4257 case 'VI.':
4258 $columns = array();
4259 for ($i = 1; $i <= $count; $i++) {
4260 $columns[] = $this->intToRoman($i) . ".";
4261 }
4262 $keyword_arr = $columns;
4263 break;
4264 default:
4265 break;
4266 }
4267 return $keyword_arr;
4268 }
4269 public static function ays_poll_generate_keyword_array( $max_val ) {
4270 if (is_null($max_val) || $max_val == '') {
4271 $max_val = 6; //'F';
4272 }
4273 $max_val = absint(intval($max_val)) - 1;
4274 $keyword_arr = array();
4275 $letters = range('A', 'Z');
4276 if($max_val <= 25){
4277 $max_alpha_val = $letters[$max_val];
4278 }
4279 elseif($max_val > 25){
4280 $dividend = ($max_val + 1);
4281 $max_alpha_val = '';
4282 $modulo = 0;
4283 while ($dividend > 0){
4284 $modulo = ($dividend - 1) % 26;
4285 $max_alpha_val = $letters[$modulo] . $max_alpha_val;
4286 $dividend = floor((($dividend - $modulo) / 26));
4287 }
4288 }
4289 $keyword_arr = self::ays_poll_create_columns_array( $max_alpha_val );
4290 return $keyword_arr;
4291 }
4292 public static function ays_poll_create_columns_array($end_column, $first_letters = '') {
4293 $columns = array();
4294 $letters = range('A', 'Z');
4295 $length = strlen($end_column);
4296 // Iterate over 26 letters.
4297 foreach ($letters as $letter) {
4298 // Paste the $first_letters before the next.
4299 $column = $first_letters . $letter;
4300 // Add the column to the final array.
4301 $columns[] = $column;
4302 // If it was the end column that was added, return the columns.
4303 if ($column == $end_column)
4304 return $columns;
4305 }
4306 // Add the column children.
4307 foreach ($columns as $column) {
4308 // Don't itterate if the $end_column was already set in a previous itteration.
4309 // Stop iterating if you've reached the maximum character length.
4310 if (!in_array($end_column, $columns) && strlen($column) < $length) {
4311 $new_columns = self::ays_poll_create_columns_array($end_column, $column);
4312 // Merge the new columns which were created with the final columns array.
4313 $columns = array_merge($columns, $new_columns);
4314 }
4315 }
4316 return $columns;
4317 }
4318
4319 public function get_answer_by_id_multi( $id ) {
4320 global $wpdb;
4321 $args_id = absint(intval($id));
4322 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
4323 // $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
4324 // $sql = "SELECT a.*, COUNT(r.id) as voted FROM ".$answ_table." as a
4325 // JOIN ".$rep_table." as r
4326 // ON r.answer_id = a.id
4327 // WHERE a.id = %d";
4328
4329 $sql = "SELECT * FROM ".$answ_table."
4330 WHERE id = %d";
4331
4332 $answ_id = $wpdb->get_results(
4333 $wpdb->prepare( $sql, $args_id),
4334 'ARRAY_A'
4335 );
4336
4337 return $answ_id;
4338 }
4339
4340 // Users avatars
4341 public function ays_poll_get_current_answer_users_pics(){
4342 global $wpdb;
4343 $results_table = $wpdb->prefix."ayspoll_reports";
4344
4345 $answer_id = isset($_POST['answer_id']) && $_POST['answer_id'] != "" ? absint($_POST['answer_id']) : null;
4346 $user_answers = array();
4347
4348 if(isset($answer_id)){
4349 $sql_users = "SELECT `user_id`
4350 FROM ".$results_table."
4351 WHERE `answer_id` = ".$answer_id."
4352 GROUP BY user_id, answer_id
4353 ORDER BY vote_date DESC";
4354 $user_res = $wpdb->get_results($sql_users , ARRAY_A);
4355 if(isset($user_res)){
4356 $user_pic_args = array(
4357 "class" => "ays-user-profile-pic-popup"
4358 );
4359
4360 foreach($user_res as $key => $value){
4361 $user_id = isset($value['user_id']) && $value['user_id'] != "" ? intval($value['user_id']) : 0;
4362 if($user_id == 0){
4363 continue;
4364 }
4365
4366 $user_avatars = get_avatar($user_id, 24, $default = '', $alt = '', $user_pic_args);
4367 $user_data = get_userdata($user_id);
4368 $user_name = "";
4369 if(isset($user_data)){
4370 if(isset($user_data->data)){
4371 $user_name = isset($user_data->data->display_name) && $user_data->data->display_name != "" ? esc_attr($user_data->data->display_name) : "";
4372 }
4373 }
4374 $user_avatars = isset($user_avatars) && $user_avatars ? $user_avatars : '';
4375 $user_answers[] = "<div class='ays-users-profile-pics-popup'><div>".$user_avatars."</div><div class='ays-users-profile-pics-popup-text'><span class='ays-poll-modal-names'>".$user_name."</span></div></div>";
4376 }
4377 }
4378 }
4379 echo json_encode($user_answers);
4380 wp_die();
4381 }
4382
4383 public function ays_add_answer_poll($data) {
4384 global $wpdb;
4385 $poll_id = absint($data['poll_id']);
4386 $new_answer = wp_filter_kses($data['new_answer']);
4387 $poll_add_answer_require = $data['admin_require'];
4388 $poll_answers_count = isset($data['answers_count']) && $data['answers_count'] > 0 ? intval($data['answers_count']) : 1;
4389 $if_text_type = isset($data['if_text_type']) && $data['if_text_type'] ? true : false;
4390
4391 $show_user_added = 0;
4392 // $votes = 0;
4393 // if($if_text_type){
4394 // $votes = 1;
4395 // }
4396 if(!$poll_add_answer_require){
4397 $show_user_added = 1;
4398 }
4399 $wpdb->insert(
4400 "{$wpdb->prefix}ayspoll_answers",
4401 array(
4402 'poll_id' => $poll_id,
4403 'answer' => $new_answer,
4404 'votes' => 0,
4405 'ordering' => ($poll_answers_count + 1),
4406 'user_added' => 1,
4407 'show_user_added' => $show_user_added
4408 ),
4409 array(
4410 '%d',
4411 '%s',
4412 '%d',
4413 '%d',
4414 '%d',
4415 '%d',
4416 )
4417 );
4418
4419 $last_id = $wpdb->insert_id;
4420 return array(
4421 "new_id" => strval($last_id)
4422 );
4423 }
4424
4425 public function ays_generate_display_polls_method($attr){
4426 $recent_poll_ids = $this->ays_recent_poll_ids($attr);
4427 $content = '<div class="ays_poll_recent_polls">';
4428 $polls = array();
4429 foreach ($recent_poll_ids as $key => $last_poll_id) {
4430 $poll_id = (isset($last_poll_id['id']) && intval($last_poll_id['id']) != '') ? intval($last_poll_id['id']) : '';
4431 $shortcode = '[ays_poll id="'.$poll_id.'"]';
4432 $polls[] = do_shortcode( $shortcode );
4433 }
4434 $content .= implode( '', $polls );
4435 $content .= '</div>';
4436 return str_replace(array("\r\n", "\n", "\r"), "\n", $content);
4437 }
4438
4439 public function ays_recent_poll_ids($data){
4440 global $wpdb;
4441 $polls_table = $wpdb->prefix.'ayspoll_polls';
4442
4443 $ays_recent_poll_order_by = (isset($data['orderby']) && $data['orderby'] != '') ? sanitize_text_field($data['orderby']) : "recent";
4444 $ays_recent_poll_count = (isset($data['count']) && $data['count'] != '') ? intval($data['count']) : 5;
4445
4446 $last_polls_sql = "SELECT id FROM {$polls_table} WHERE styles LIKE '%\"published\":1%' ";
4447
4448 switch ($ays_recent_poll_order_by) {
4449 case 'recent':
4450 $last_polls_sql .= "ORDER BY id DESC LIMIT ".$ays_recent_poll_count;
4451 break;
4452 case 'random':
4453 $last_polls_sql .= "ORDER BY RAND() LIMIT ".$ays_recent_poll_count;
4454 break;
4455 default:
4456 $last_polls_sql .= "ORDER BY id DESC LIMIT ".$ays_recent_poll_count;
4457 break;
4458 }
4459
4460 $last_poll_ids = $wpdb->get_results($last_polls_sql,'ARRAY_A');
4461
4462 return $last_poll_ids;
4463 }
4464
4465 public function ays_set_poll_fields_placeholders_texts(){
4466
4467 /*
4468 * Get Poll fields placeholders from database
4469 */
4470
4471 $settings_placeholders_texts = $this->settings->ays_get_setting('fields_placeholders');
4472 if($settings_placeholders_texts){
4473 $settings_placeholders_texts = json_decode(stripcslashes($settings_placeholders_texts), true);
4474 }else{
4475 $settings_placeholders_texts = array();
4476 }
4477
4478 $poll_fields_placeholder_name = (isset($settings_placeholders_texts['poll_fields_placeholder_name']) && $settings_placeholders_texts['poll_fields_placeholder_name'] != '') ? stripslashes( esc_attr( $settings_placeholders_texts['poll_fields_placeholder_name'] ) ) : 'Name';
4479
4480 $poll_fields_placeholder_email = (isset($settings_placeholders_texts['poll_fields_placeholder_email']) && $settings_placeholders_texts['poll_fields_placeholder_email'] != '') ? stripslashes( esc_attr( $settings_placeholders_texts['poll_fields_placeholder_email'] ) ) : 'E-mail';
4481
4482 $poll_fields_placeholder_phone = (isset($settings_placeholders_texts['poll_fields_placeholder_phone']) && $settings_placeholders_texts['poll_fields_placeholder_phone'] != '') ? stripslashes( esc_attr( $settings_placeholders_texts['poll_fields_placeholder_phone'] ) ) : 'Phone';
4483
4484
4485 $poll_fields_placeholder_name_text = $poll_fields_placeholder_name === 'Name' ?esc_html__('Name', "poll-maker") : $poll_fields_placeholder_name;
4486 $poll_fields_placeholder_email_text = $poll_fields_placeholder_email === 'Email' ?esc_html__('Email', "poll-maker") : $poll_fields_placeholder_email;
4487 $poll_fields_placeholder_phone_text = $poll_fields_placeholder_phone === 'Phone' ?esc_html__('Phone', "poll-maker") : $poll_fields_placeholder_phone;
4488
4489
4490 $poll_fields_label_name = (isset($settings_placeholders_texts['poll_fields_label_name']) && $settings_placeholders_texts['poll_fields_label_name'] != '') ? stripslashes( esc_attr( $settings_placeholders_texts['poll_fields_label_name'] ) ) : 'Name';
4491
4492 $poll_fields_label_email = (isset($settings_placeholders_texts['poll_fields_label_email']) && $settings_placeholders_texts['poll_fields_label_email'] != '') ? stripslashes( esc_attr( $settings_placeholders_texts['poll_fields_label_email'] ) ) : 'E-mail';
4493
4494 $poll_fields_label_phone = (isset($settings_placeholders_texts['poll_fields_label_phone']) && $settings_placeholders_texts['poll_fields_label_phone'] != '') ? stripslashes( esc_attr( $settings_placeholders_texts['poll_fields_label_phone'] ) ) : 'Phone';
4495
4496
4497 $poll_fields_label_name_text = $poll_fields_label_name === 'Name' ?esc_html__('Name', "poll-maker") : $poll_fields_label_name;
4498 $poll_fields_label_email_text = $poll_fields_label_email === 'Email' ?esc_html__('Email', "poll-maker") : $poll_fields_label_email;
4499 $poll_fields_label_phone_text = $poll_fields_label_phone === 'Phone' ?esc_html__('Phone', "poll-maker") : $poll_fields_label_phone;
4500
4501 $texts = array(
4502 'namePlaceholder' => $poll_fields_placeholder_name_text,
4503 'emailPlaceholder' => $poll_fields_placeholder_email_text,
4504 'phonePlaceholder' => $poll_fields_placeholder_phone_text,
4505
4506 'nameLabel' => $poll_fields_label_name_text,
4507 'emailLabel' => $poll_fields_label_email_text,
4508 'phoneLabel' => $poll_fields_label_phone_text,
4509 );
4510
4511 return $texts;
4512 }
4513
4514 public function ays_autoembed( $content ) {
4515 global $wp_embed;
4516 $content = stripslashes( wpautop( $content ) );
4517 $content = $wp_embed->autoembed( $content );
4518 if ( strpos( $content, '[embed]' ) !== false ) {
4519 $content = $wp_embed->run_shortcode( $content );
4520 }
4521 $content = do_shortcode( $content );
4522 return $content;
4523 }
4524
4525 public function replace_message_variables($content, $data){
4526 foreach($data as $variable => $value){
4527 $content = str_replace("%%".$variable."%%", $value, $content);
4528 }
4529 return $content;
4530 }
4531
4532 public function get_user_profile_data(){
4533
4534 $user_first_name = '';
4535 $user_last_name = '';
4536 $user_nickname = '';
4537
4538 $user_id = get_current_user_id();
4539 if($user_id != 0){
4540 $usermeta = get_user_meta( $user_id );
4541 if($usermeta !== null){
4542 $user_first_name = (isset($usermeta['first_name'][0]) && $usermeta['first_name'][0] != '' ) ? sanitize_text_field( $usermeta['first_name'][0] ) : '';
4543 $user_last_name = (isset($usermeta['last_name'][0]) && $usermeta['last_name'][0] != '' ) ? sanitize_text_field( $usermeta['last_name'][0] ) : '';
4544 $user_nickname = (isset($usermeta['nickname'][0]) && $usermeta['nickname'][0] != '' ) ? sanitize_text_field( $usermeta['nickname'][0] ) : '';
4545 }
4546 }
4547
4548 $message_data = array(
4549 'user_first_name' => $user_first_name,
4550 'user_last_name' => $user_last_name,
4551 'user_nickname' => $user_nickname,
4552 );
4553
4554 return $message_data;
4555 }
4556
4557 public function ays_poll_get_recent_poll_id(){
4558 global $wpdb;
4559 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
4560 $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
4561
4562 $last_polls_sql = "SELECT id FROM ".$poll_table." ORDER BY id DESC LIMIT 0, 1";
4563 $last_poll_sql = $wpdb->get_row($last_polls_sql , ARRAY_A);
4564
4565 $id = isset($last_poll_sql['id']) && $last_poll_sql['id'] !== 0 ? absint(intval($last_poll_sql['id'])) : "";
4566
4567 return $id;
4568 }
4569 }
4570