PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.3.7
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.3.7
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.7, at public/class-poll-maker-ays-public.php

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