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

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