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

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