PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.5.1
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.5.1
6.5.1 6.5.0 6.4.9 6.4.8 6.4.7 6.4.6 6.4.5 6.4.4 6.4.3 6.4.2 6.4.1 6.4.0 6.3.9 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.6.5 All 154 releases
poll-maker / public / class-poll-maker-ays-public.php

class-poll-maker-ays-public.php in Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls 6.5.1, at public/class-poll-maker-ays-public.php

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