PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 5.6.1
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v5.6.1
6.5.0 6.4.9 6.4.8 6.4.7 6.4.6 6.4.5 6.4.4 6.4.3 6.4.2 6.4.1 6.4.0 6.3.9 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.6.5 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.1, at public/class-poll-maker-ays-public.php

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