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

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