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

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

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