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

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

4,845 lines 203.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The public-facing functionality of the plugin.
5 *
6 * @link https://ays-pro.com/
7 * @since 1.0.0
8 *
9 * @package Poll_Maker_Ays
10 * @subpackage Poll_Maker_Ays/public
11 */
12
13 /**
14 * The public-facing functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the public-facing stylesheet and JavaScript.
18 *
19 * @package Poll_Maker_Ays
20 * @subpackage Poll_Maker_Ays/public
21 * @author Poll Maker Team <[email protected]>
22 */
23 class Poll_Maker_Ays_Public {
24
25 /**
26 * The settings of this plugin.
27 *
28 * @since 1.0.0
29 * @access protected
30 * @var Poll_Maker_Settings_Actions object $settings The current settings of this plugin.
31 */
32 protected $settings;
33 protected $fields_placeholders;
34 /**
35 * The ID of this plugin.
36 *
37 * @since 1.0.0
38 * @access private
39 * @var string $plugin_name The ID of this plugin.
40 */
41 private $plugin_name;
42 private static $p;
43
44 /**
45 * The version of this plugin.
46 *
47 * @since 1.0.0
48 * @access private
49 * @var string $version The current version of this plugin.
50 */
51 private $version;
52 private static $v;
53
54 /**
55 * The instance of this plugin public class.
56 *
57 * @since 1.0.0
58 * @access private
59 * @var Poll_Maker_Ays_Public object.
60 */
61 private static $instance = null;
62
63 /**
64 * Initialize the class and set its properties.
65 *
66 * @param string $plugin_name The name of the plugin.
67 * @param string $version The version of this plugin.
68 *
69 * @since 1.0.0
70 */
71 public function __construct( $plugin_name, $version ) {
72
73 $this->plugin_name = $plugin_name;
74 $this->version = $version;
75 self::$p = $plugin_name;
76 self::$v = $version;
77
78 add_shortcode('ays_poll', array($this, 'ays_poll_generate_shortcode'));
79 $this->settings = new Poll_Maker_Settings_Actions($this->plugin_name);
80 add_shortcode('ays_poll_all', array($this, 'ays_poll_all_generate_shortcode'));
81 add_shortcode('ayspoll_results', array($this, 'ays_poll_results_generate_shortcode'));
82 add_shortcode('ays_display_polls', array($this, 'ays_generate_display_polls_method'));
83 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 static function get_poll_category_by_ids($ids){
3179 global $wpdb;
3180
3181 $ids = array_map('intval', explode(',', $ids));
3182 $ids = array_filter($ids);
3183
3184 if (empty($ids)) {
3185 return [];
3186 }
3187
3188 $ids_sql = implode(',', $ids);
3189
3190 $sql = "SELECT *
3191 FROM {$wpdb->prefix}ayspoll_categories
3192 WHERE id IN ($ids_sql)
3193 ORDER BY FIELD(id, $ids_sql)";
3194
3195 return $wpdb->get_results($sql, ARRAY_A);
3196 }
3197
3198 public function get_poll_status($id) {
3199 global $wpdb;
3200 $poll_id = absint(intval($id));
3201 $poll_table = $wpdb->prefix . 'ayspoll_polls';
3202
3203 $poll = $wpdb->get_row($wpdb->prepare("SELECT styles FROM $poll_table WHERE id = %d", $poll_id));
3204
3205 if ($poll) {
3206 $styles = json_decode($poll->styles, true);
3207 if (isset($styles['published']) && $styles['published'] == 1) {
3208 return 'published';
3209 } else {
3210 return 'unpublished';
3211 }
3212 } else {
3213 return false;
3214 }
3215 }
3216
3217 public function ays_poll_get_user_information() {
3218 if ( ! check_ajax_referer( 'ays_poll_nonce', '_ajax_nonce', false ) ) {
3219 wp_send_json_error( array( 'message' => 'Invalid request' ), 403 );
3220 }
3221 if ( ! is_user_logged_in() ) {
3222 wp_send_json_error( array( 'message' => 'User not logged in' ), 401 );
3223 }
3224
3225 $user = wp_get_current_user();
3226
3227 wp_send_json_success( array(
3228 'display_name' => $user->display_name,
3229 'user_email' => $user->user_email,
3230
3231 ) );
3232 }
3233
3234 public function ays_finish_poll() {
3235 global $wpdb;
3236 $poll_id = absint($_POST['poll_id']);
3237 if (
3238 (isset($_POST["ays_finish_poll_" . $poll_id]) && wp_verify_nonce($_POST["ays_finish_poll_" . $poll_id], 'ays_finish_poll')) ||
3239 (isset($_POST["ays_finish_poll_show_res_" . $poll_id]) && wp_verify_nonce($_POST["ays_finish_poll_show_res_" . $poll_id], 'ays_finish_poll'))
3240 ) {
3241
3242 // $answer_id = (isset($_POST['answer']) && $_POST['answer'] !== null) ? $_POST['answer'] : 0;
3243 // $poll_id = absint($_POST['poll_id']);
3244 $poll_status = $this->get_poll_status($poll_id);
3245
3246 if ($poll_status === 'unpublished') {
3247 $res = array('error' => 'The poll is not published.');
3248 echo json_encode($res);
3249 wp_die();
3250 }
3251
3252 $title_ids = array();
3253 $answer_titless = array();
3254 if (isset($_POST['answer'])) {
3255 if( is_array($_POST['answer']) ){
3256 $answer_id = array_map('absint', $_POST['answer']);
3257 $multi_answer_id = array_map('absint', $_POST['answer']);
3258 $title_ids = implode(',' , $multi_answer_id);
3259 }else{
3260 $answer_id = absint( $_POST['answer'] );
3261
3262 $answer_id2 = array();
3263 $answer_id2[] = $answer_id;
3264 $multi_answer_id = array();
3265 $title_ids = implode(',' , $answer_id2);
3266 }
3267 }else{
3268 $answer_id = 0;
3269 $answer_id2[] = false;
3270 }
3271
3272 if(!is_array($answer_id)){
3273 $answer_id = absint($answer_id);
3274 }
3275
3276 // $title_ids = array();
3277 // $answer_titless = array();
3278 // if (isset($_POST['answer']) && is_array($_POST['answer'])) {
3279 // $answer_id = $_POST['answer'];
3280 // $multi_answer_id = $_POST['answer'];
3281 // $title_ids = implode(',' , $multi_answer_id);
3282 // } else {
3283 // $answer_id2 = array();
3284 // $answer_id2[] = !isset($_POST['answer']) || $_POST['answer'] === null ? false : absint($_POST['answer']);
3285 // $multi_answer_id = array();
3286 // $title_ids = implode(',' , $answer_id2);
3287 // }
3288 if(!empty($title_ids)){
3289 $answer_titles = $this->get_answer_by_ids($title_ids);
3290 if(isset($answer_titles) && $answer_titles != null){
3291 foreach($answer_titles as $t_key => $t_value){
3292 foreach ($t_value as $r_key => $r_value) {
3293 if($r_key == 'answer'){
3294 $answer_titless[] = $r_value;
3295 }
3296 }
3297 }
3298 }
3299 }
3300
3301
3302 $poll = $this->get_poll_by_id($poll_id);
3303 $options = $poll['styles'];
3304 $poll_answers_count = isset($poll['answers']) ? count($poll['answers']) : 0;
3305 $added_answer_id = array();
3306
3307 $poll_title = (isset($poll['title']) && $poll['title'] != '') ? stripslashes( sanitize_text_field( $poll['title'] ) ) : '';
3308
3309 // Poll category title
3310 $poll_category_title = "";
3311
3312 $poll_cats = isset( $poll['categories'] ) ? trim( $poll['categories'], ',' ) : '';
3313 $poll_category_ids = $poll_cats !== '' ? sanitize_text_field( $poll_cats ) : '';
3314
3315 if ( $poll_category_ids != '' ) {
3316 $categories = self::get_poll_category_by_ids( $poll_category_ids );
3317 $category_names = wp_list_pluck( $categories, 'title' );
3318
3319 $poll_category_title = implode( ', ', $category_names );
3320 }
3321
3322 $poll_vote_reason_text = "";
3323 $poll_vote_reason = false;
3324 $show_answers_numbering = (isset($options['show_answers_numbering']) && sanitize_text_field( $options['show_answers_numbering'] ) != '') ? sanitize_text_field( $options['show_answers_numbering'] ) : 'none';
3325 if (isset($options['poll_vote_reason']) && $options['poll_vote_reason'] == "on" && isset($_POST['ays-poll-reason-text'])) {
3326 // $poll_vote_reason_text = $_POST['ays-poll-reason-text'];
3327 $poll_vote_reason_text = esc_html( $_POST['ays-poll-reason-text'] );
3328 $poll_vote_reason = true;
3329 }
3330
3331 $allow_multi_vote = isset($options["poll_allow_multivote"]) && $options["poll_allow_multivote"] == "on" ? true : false;
3332 $allow_add_answer = isset($options["poll_allow_answer"]) && $options["poll_allow_answer"] == "on" ? true : false;
3333 $check_admin_approval = false;
3334 $flag_for_added_answer = false;
3335 if($allow_add_answer && (isset($_POST['ays_poll_new_answer']) && $_POST['ays_poll_new_answer'] != "")){
3336
3337 $flag_for_added_answer = true;
3338 $poll_allow_answer_require = isset($options['poll_allow_answer_require']) && $options['poll_allow_answer_require'] == "on" ? true : false;
3339 if($poll_allow_answer_require){
3340 $check_admin_approval = true;
3341 }
3342 // $poll_answers_count = isset($poll['answers']) ? count($poll['answers']) : 0;
3343 $new_anwer_data = array(
3344 'poll_id' => $poll_id,
3345 'new_answer' => wp_kses_post(stripslashes($_POST['ays_poll_new_answer'])),
3346 'admin_require' => $poll_allow_answer_require,
3347 'answers_count' => $poll_answers_count,
3348 'if_text_type' => false
3349 );
3350
3351 $added_answer_id = $this->ays_add_answer_poll($new_anwer_data);
3352
3353 if((is_array($answer_id) && !empty($answer_id)) && $allow_multi_vote){
3354 $answer_id[] = $added_answer_id['new_id'];
3355 }
3356 elseif(isset($answer_id) && !is_array($answer_id) && $answer_id > 0 && $allow_multi_vote){
3357 $answer_id = explode(" " , $answer_id);
3358 array_push($answer_id , $added_answer_id['new_id']);
3359 }
3360 else{
3361 $answer_id = $added_answer_id['new_id'];
3362 }
3363 }
3364 $poll_type_for_text_type = isset($poll['type']) && $poll['type'] == "text" ? true : false;
3365 $poll_answer = isset($_POST['answer']) && $_POST['answer'] != '' ? sanitize_text_field($_POST['answer']) : "";
3366
3367 // Add new text answer if not exist
3368 if($poll_type_for_text_type) {
3369 $text_anwer_data = array(
3370 'poll_id' => $poll_id,
3371 'new_answer' => $poll_answer,
3372 'admin_require' => false,
3373 'answers_count' => $poll_answers_count,
3374 'if_text_type' => true
3375 );
3376
3377 $is_answer_exist = $this->check_text_answer_exist($poll_id, $poll_answer);
3378 if (!$is_answer_exist) {
3379 $added_answer_id = $this->ays_add_answer_poll($text_anwer_data);
3380 $answer_id = $added_answer_id['new_id'];
3381 } else {
3382 $answer_id = $this->get_text_answer_id($poll_id, $poll_answer);
3383 }
3384 }
3385
3386 if ($answer_id > 0 || is_array($answer_id)) {
3387 if (isset($options['limit_users']) && $options['limit_users'] == 1) {
3388 $user_id = is_user_logged_in() ? wp_get_current_user()->ID : 0;
3389 $limit_users_method = isset($options['limit_users_method']) ? sanitize_text_field($options['limit_users_method']) : 'ip';
3390 $user_voted_count = 0;
3391 if ($limit_users_method == 'ip') {
3392 $user_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3393 }
3394 elseif($limit_users_method == 'cookie'){
3395 $cookie_name = "ays_this_poll_cookie_".$poll_id;
3396 if(!isset($_COOKIE[$cookie_name])){
3397 $cookie_value = "ays_vote_limitation_cookie_value";
3398 $time_limit = time() + (86400 * 30);
3399 setcookie($cookie_name, $cookie_value,$time_limit , '/');
3400 }else{
3401 $user_voted_count = 1;
3402 }
3403 }
3404 elseif($limit_users_method == 'cookie_ip'){
3405 $cookie_name = "ays_this_poll_cookie_".$poll_id;
3406 $limit_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3407 if(!isset($_COOKIE[$cookie_name])){
3408 $cookie_value = "ays_vote_limitation_cookie_value";
3409 $time_limit = time() + (86400 * 30);
3410 setcookie($cookie_name, $cookie_value,$time_limit , '/');
3411 }
3412 else{
3413 $user_voted_count = 1;
3414 }
3415 if(isset($_COOKIE[$cookie_name]) || $limit_voted_count > 0){
3416 $user_voted_count = 1;
3417 }
3418 elseif(!isset($_COOKIE[$cookie_name]) || $limit_voted_count > 0){
3419 $user_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3420 }
3421 }
3422 else{
3423 if ($user_id != 0) {
3424 $user_voted_count = $this->ays_poll_get_limit_user_count_by_id($poll_id,$user_id);
3425 }else{
3426 $user_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3427 }
3428 }
3429
3430 $user_voted_count = absint(intval(($user_voted_count)));
3431
3432 if ( $user_voted_count > 0 ) {
3433 $res = $this->get_poll_by_id($poll_id);
3434 $res['voted_status'] = false;
3435 ob_end_clean();
3436 $ob_get_clean = ob_get_clean();
3437 echo json_encode($res);
3438 wp_die();
3439 }
3440 }
3441
3442 if (!empty($options['info_form'])) {
3443 $user_email = isset($_POST["apm_email"]) && $_POST['apm_email'] !== null ? sanitize_email($_POST["apm_email"]) : '';
3444 }else{
3445 $user_email = '';
3446 }
3447
3448 $check_allowing = (isset($options['poll_allow_collecting_users_data']) && $options['poll_allow_collecting_users_data'] == 'on') ? true : false;
3449 $check_fields = (isset($options['info_form']) && $options['info_form'] == 1) ? true : false;
3450 if($check_allowing && !$check_fields){
3451 $this_user = wp_get_current_user();
3452 if($this_user->ID != 0){
3453 $_POST["apm_email"] = $this_user->data->user_email;
3454 $user_email = isset($_POST["apm_email"]) ? sanitize_email($_POST["apm_email"]) : "";
3455 $_POST['apm_name'] = $this_user->data->display_name;
3456 }
3457 }
3458 // MailChimp
3459
3460 if (isset($options['enable_mailchimp']) && $options['enable_mailchimp'] == 'on') {
3461 if (isset($options['mailchimp_list']) && $options['mailchimp_list'] != "") {
3462 $poll_settings = $this->settings;
3463 $mailchimp_res = ($poll_settings->ays_get_setting('mailchimp') === false) ? json_encode(array()) : $poll_settings->ays_get_setting('mailchimp');
3464 $mailchimp = json_decode($mailchimp_res, true);
3465 $mailchimp_username = isset($mailchimp['username']) ? $mailchimp['username'] : '';
3466 $mailchimp_api_key = isset($mailchimp['apiKey']) ? $mailchimp['apiKey'] : '';
3467 $mailchimp_list = (isset($options['mailchimp_list'])) ? $options['mailchimp_list'] : '';
3468 $mailchimp_email = $user_email;
3469 $user_name = isset($_POST['apm_name']) ? explode(" ", wp_filter_post_kses($_POST['apm_name'])) : array();
3470 $mailchimp_fname = (isset($user_name[0]) && $user_name[0] != "") ? $user_name[0] : "";
3471 $mailchimp_lname = (isset($user_name[1]) && $user_name[1] != "") ? $user_name[1] : "";
3472 $user_phone = isset($_POST['apm_phone']) ? explode(" ", wp_filter_post_kses($_POST['apm_phone'])) : array();
3473 $mailchimp_phone = (isset($user_phone[0]) && $user_phone[0] != "") ? $user_phone[0] : "";
3474 if ($mailchimp_username != "" && $mailchimp_api_key != "") {
3475 $args = array(
3476 "email" => $mailchimp_email,
3477 "fname" => $mailchimp_fname,
3478 "lname" => $mailchimp_lname,
3479 "pnumber" => $mailchimp_phone,
3480 );
3481 $mresult = $this->ays_add_mailchimp_transaction($mailchimp_username, $mailchimp_api_key, $mailchimp_list, $args);
3482 }
3483 }
3484 }
3485
3486 // $answer = $this->get_answer_by_id($answer_id);
3487
3488 // $votes = isset($answer['voted']) && $answer['voted'] !== null ? $answer['voted'] : 0;
3489 // $votes++;
3490
3491 $other_info = array(
3492 "Name" => "",
3493 "email" => "",
3494 "phone" => "",
3495 );
3496
3497 if (!empty($options['info_form']) || $check_allowing) {
3498 $other_info = array(
3499 "Name" => !empty($_POST['apm_name']) ? sanitize_text_field($_POST['apm_name']) : "",
3500 "email" => !empty($_POST['apm_email']) ? sanitize_email($_POST['apm_email']) : "",
3501 "phone" => !empty($_POST['apm_phone']) ? sanitize_text_field($_POST['apm_phone']) : "",
3502 );
3503 }
3504 if($poll_vote_reason){
3505 $other_info['voteReason'] = $poll_vote_reason_text;
3506 }
3507 // global $wpdb;
3508 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
3509 $report_table = esc_sql($wpdb->prefix."ayspoll_reports");
3510
3511 // AV IP Storing
3512 $settings_table = esc_sql($wpdb->prefix."ayspoll_settings");
3513 $key_meta = esc_sql('options');
3514 $sql_ip = "SELECT meta_value FROM ".$settings_table." WHERE meta_key = %s";
3515 $res_ip = $wpdb->get_var(
3516 $wpdb->prepare( $sql_ip, $key_meta)
3517 );
3518
3519 $options_res = ($res_ip === false) ? json_encode(array()) : $res_ip;
3520 $option_res = json_decode((string)$options_res, true);
3521
3522 $user_ips = isset($option_res['disable_ip_storing']) && $option_res['disable_ip_storing'] == 'on' ? '' : $this->get_user_ip_validated();
3523
3524 $poll_user_information = $this->get_user_profile_data();
3525 $user_first_name = (isset( $poll_user_information['user_first_name'] ) && $poll_user_information['user_first_name'] != "") ? $poll_user_information['user_first_name'] : '';
3526 $user_last_name = (isset( $poll_user_information['user_last_name'] ) && $poll_user_information['user_last_name'] != "") ? $poll_user_information['user_last_name'] : '';
3527 $creation_date = (isset( $poll['styles']['create_date'] ) && $poll['styles']['create_date'] != '') ? $poll['styles']['create_date'] : '';
3528
3529
3530 $current_poll_author = esc_html__( "Unknown", "poll-maker" );
3531 $current_poll_author_email = '';
3532 $current_poll_author_nickname = '';
3533 $current_poll_author_display_name = '';
3534 $current_poll_author_website_url = '';
3535 $current_poll_author_registered = '';
3536 if( !empty($options['author']) ){
3537 if( !is_array($options['author']) ){
3538 $options['author'] = json_decode($options['author'], true);
3539 }
3540
3541 $poll_current_author = (isset($options['author']['id']) && $options['author']['id'] != "") ? absint(sanitize_text_field( $options['author']['id'] )) : "";
3542
3543 $current_poll_user_data = get_userdata( $poll_current_author );
3544 if ( ! is_null( $current_poll_user_data ) && $current_poll_user_data ) {
3545 $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 ) : "";
3546 $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 ) : "";
3547 $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 ) : "";
3548 $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 ) : "";
3549 $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 ) : "";
3550 $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 ) : "";
3551 }
3552 }
3553
3554 // Get Current date
3555 $poll_current_date = date_i18n( 'M d, Y', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3556
3557 // Get Current time
3558 $poll_current_time = date_i18n( get_option( 'time_format' ), strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3559
3560 // Get Current day
3561 $poll_current_day = date_i18n( 'l', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3562
3563 // Get Current month
3564 $poll_current_month = date_i18n( 'F', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3565
3566 // Get Post Title
3567 $post_id = url_to_postid( $_POST['_wp_http_referer'] );
3568 $post_title = get_the_title( $post_id );
3569 $get_site_title = get_bloginfo('name');
3570 $get_site_description = get_bloginfo('description');
3571
3572 // WP home page url
3573 $home_main_url = home_url();
3574 $home_page_url = '<a href="'. $home_main_url .'" target="_blank">'. $home_main_url .'</a>';
3575
3576 $user_nickname = '';
3577 $user_first_name = '';
3578 $user_display_name = '';
3579 $user_wordpress_email = '';
3580 $user_wordpress_roles = '';
3581 $user_wordpress_website = '';
3582 $user_ip_address = '';
3583 $user_id = get_current_user_id();
3584 $user_data = wp_get_current_user();
3585 $super_admin_email = get_option('admin_email');
3586
3587 $post_author = get_post_field( 'post_author', $post_id );
3588 $author_id = get_the_author_meta('ID', $post_author);
3589 $post_author_email = get_the_author_meta( 'email', $author_id );
3590 $post_author_display_name = get_the_author_meta( 'display_name', $author_id );
3591 $post_author_nickname = get_the_author_meta( 'nickname', $author_id );
3592 $post_author_first_name = get_the_author_meta( 'first_name', $author_id );
3593 $post_author_last_name = get_the_author_meta( 'last_name', $author_id );
3594 $post_author_website_url = get_the_author_meta( 'url', $author_id );
3595
3596 $post_author_roles = '';
3597 $user_registered = '';
3598 if ( is_user_logged_in() ) {
3599 $post_author_roles = get_the_author_meta( 'roles', $author_id );
3600 $user_registered = $user_data->user_registered;
3601 }
3602
3603 if ( ! empty( $post_author_website_url ) ) {
3604 $post_author_website_url = '<a href="'. $post_author_website_url .'" target="_blank">'. $post_author_website_url .'</a>';
3605 }
3606
3607 if ( ! empty( $current_poll_author_website_url ) ) {
3608 $current_poll_author_website_url = '<a href="'. $current_poll_author_website_url .'" target="_blank">'. $current_poll_author_website_url .'</a>';
3609 }
3610
3611 if ( ! empty( $post_author_roles ) && $post_author_roles != "" ) {
3612 if ( is_array( $post_author_roles ) ) {
3613 $post_author_roles = implode( ", ", $post_author_roles );
3614 }
3615 }
3616
3617 if( $user_id != 0 ){
3618 $usermeta = get_user_meta( $user_id );
3619 if($usermeta !== null){
3620 $user_nickname = (isset($usermeta['nickname'][0]) && sanitize_text_field( $usermeta['nickname'][0] != '') ) ? sanitize_text_field( $usermeta['nickname'][0] ) : '';
3621 $user_first_name = (isset($usermeta['first_name'][0]) && sanitize_text_field( $usermeta['first_name'][0] != '') ) ? sanitize_text_field( $usermeta['first_name'][0] ) : '';
3622 }
3623
3624 $current_user_data = get_userdata( $user_id );
3625 if ( ! is_null( $current_user_data ) && $current_user_data ) {
3626 $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 ) : "";
3627 $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 ) : "";
3628
3629 $user_wordpress_roles = ( isset( $current_user_data->roles ) && ! empty( $current_user_data->roles ) ) ? $current_user_data->roles : "";
3630 $user_ip_address = $this->get_user_ip_validated();
3631
3632 if ( !empty( $user_wordpress_roles ) && $user_wordpress_roles != "" ) {
3633 if ( is_array( $user_wordpress_roles ) ) {
3634 $user_wordpress_roles = implode(",", $user_wordpress_roles);
3635 }
3636 }
3637
3638 $user_wordpress_website_url = ( isset( $current_user_data->user_url ) && ! empty( $current_user_data->user_url ) ) ? sanitize_url($current_user_data->user_url) : "";
3639
3640 if( !empty( $user_wordpress_website_url ) ){
3641 $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>";
3642 }
3643 }
3644 }
3645
3646 if ( is_user_logged_in() ) {
3647 $current_user_id = get_current_user_id();
3648 } else {
3649 $current_user_id = '';
3650 }
3651
3652 $report_table = $wpdb->prefix."ayspoll_reports";
3653 $answ_table = $wpdb->prefix."ayspoll_answers";
3654
3655 $sql = "SELECT COUNT(*)
3656 FROM ".$report_table."
3657 JOIN ".$answ_table."
3658 ON ".$answ_table.".id = ".$report_table.".answer_id
3659 WHERE ".$answ_table.".poll_id =".$poll_id;
3660
3661 $pass_count_results = $wpdb->get_var($sql);
3662 $pass_count = ( isset($pass_count_results) && $pass_count_results != '' ) ? intval( $pass_count_results ) : 0;
3663
3664 $passed_poll_count_per_user = Poll_Maker_Data::get_user_passed_polls_count( $user_id );
3665
3666 $ays_protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
3667
3668 $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'] ) : "";
3669 $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>";
3670
3671 $form_apm_name = (isset($_POST['apm_name']) && $_POST['apm_name'] != "") ? esc_attr($_POST['apm_name']) : "";
3672 $form_apm_email = (isset($_POST['apm_email']) && $_POST['apm_email'] != "") ? esc_attr($_POST['apm_email']) : "";
3673 $form_apm_phone = (isset($_POST['apm_phone']) && $_POST['apm_phone'] != "") ? esc_attr($_POST['apm_phone']) : "";
3674
3675 $message_data = array(
3676 'user_name' => $form_apm_name,
3677 'user_email' => $form_apm_email,
3678 'user_phone' => $form_apm_phone,
3679 'poll_title' => $poll_title,
3680 'poll_category_title' => $poll_category_title,
3681 'poll_id' => $poll_id,
3682 'users_first_name' => $user_first_name,
3683 'users_last_name' => $user_last_name,
3684 'creation_date' => $creation_date,
3685 'current_date' => $poll_current_date,
3686 'current_time' => $poll_current_time,
3687 'current_day' => $poll_current_day,
3688 'current_month' => $poll_current_month,
3689 'current_poll_page_link' => $current_poll_page_link_html,
3690 'current_poll_author' => $current_poll_author,
3691 'current_poll_author_email' => $current_poll_author_email,
3692 'current_poll_author_nickname' => $current_poll_author_nickname,
3693 'current_poll_author_display_name' => $current_poll_author_display_name,
3694 'current_poll_author_website_url' => $current_poll_author_website_url,
3695 'current_poll_author_registered' => $current_poll_author_registered,
3696 'admin_email' => $super_admin_email,
3697 'user_nickname' => $user_nickname,
3698 'user_first_name' => $user_first_name,
3699 'user_display_name' => $user_display_name,
3700 'user_wordpress_email' => $user_wordpress_email,
3701 'user_wordpress_roles' => $user_wordpress_roles,
3702 'poll_pass_count' => $pass_count,
3703 'passed_poll_count_per_user' => $passed_poll_count_per_user,
3704 'user_wordpress_website' => $user_wordpress_website,
3705 'user_ip_address' => $user_ip_address,
3706 'user_id' => $current_user_id,
3707 'user_registered' => $user_registered,
3708 'post_title' => $post_title,
3709 'post_author_email' => $post_author_email,
3710 'post_author_display_name' => $post_author_display_name,
3711 'post_author_nickname' => $post_author_nickname,
3712 'post_author_first_name' => $post_author_first_name,
3713 'post_author_last_name' => $post_author_last_name,
3714 'post_author_website_url' => $post_author_website_url,
3715 'post_author_roles' => $post_author_roles,
3716 'post_id' => $post_id,
3717 'site_title' => $get_site_title,
3718 'site_description' => $get_site_description,
3719 'home_page_url' => $home_page_url,
3720 );
3721
3722 $user_ip = esc_sql($user_ips);
3723
3724 // Race condition fix
3725 $limitusers = isset($poll['styles']['limit_users']) ? intval($poll['styles']['limit_users']) : 0;
3726
3727 if ($limitusers > 0) {
3728
3729 $limit_users_method = isset($poll['styles']['limit_users_method']) ? $poll['styles']['limit_users_method'] : "ip";
3730
3731 switch ($limit_users_method) {
3732 case 'ip':
3733 default:
3734 $wpdb->query("START TRANSACTION");
3735 $already_voted = $wpdb->get_var($wpdb->prepare(
3736 "SELECT COUNT(*) FROM {$report_table} WHERE user_ip = %s AND poll_id = %d FOR UPDATE",
3737 $user_ip,
3738 $poll_id
3739 ));
3740 break;
3741 case 'cookie':
3742 $wpdb->query("START TRANSACTION");
3743 $already_voted = isset($_COOKIE["ays_this_poll_cookie_" . $poll_id]) ? 1 : 0;
3744 break;
3745 case 'user':
3746 $wpdb->query("START TRANSACTION");
3747 $already_voted = $wpdb->get_var($wpdb->prepare(
3748 "SELECT COUNT(*) FROM {$report_table} WHERE user_id = %s AND poll_id = %d FOR UPDATE",
3749 $user_id,
3750 $poll_id
3751 ));
3752 break;
3753 }
3754
3755 if ($already_voted > 0) {
3756 $wpdb->query("ROLLBACK");
3757
3758 $res = $this->get_poll_by_id($poll_id);
3759 $res['voted_status'] = false;
3760 echo json_encode($res);
3761 wp_die();
3762 }
3763 }
3764
3765 $multi_answer_ids = array();
3766 if ((is_array($answer_id) && !empty($answer_id)) && $allow_multi_vote) {
3767 $multi_answer_ids = $answer_id;
3768 $answer_changed_id = $answer_id[0];
3769 foreach($answer_id as $a_key => $a_id){
3770 $this_answer = $this->get_answer_by_id_multi($a_id);
3771 if(isset($this_answer[0])){
3772 $votes_new = isset($this_answer[0]['votes']) ? intval($this_answer[0]['votes']) : 0;
3773 $votes_new++;
3774 $wpdb->update(
3775 $answ_table,
3776 array('votes' => $votes_new),
3777 array('id' => $a_id),
3778 array('%d'),
3779 array('%d')
3780 );
3781
3782 }
3783
3784 }
3785 } else {
3786 $answer_changed_id = $answer_id;
3787 $multi_answer_ids[] = $answer_changed_id;
3788 $answer = $this->get_answer_by_id($answer_id);
3789 $votes = isset($answer['votes']) && $answer['votes'] !== null ? intval($answer['votes']) : 0;
3790 $votes++;
3791 $wpdb->update(
3792 $answ_table,
3793 array('votes' => $votes),
3794 array('id' => $answer_id),
3795 array('%d'),
3796 array('%d')
3797 );
3798 }
3799 $wpdb->insert(
3800 $report_table,
3801 array(
3802 'answer_id' => $answer_changed_id,
3803 'user_ip' => $user_ip,
3804 'user_id' => is_user_logged_in() ? wp_get_current_user()->ID : 0,
3805 'vote_date' => esc_sql( sanitize_text_field( $_REQUEST['end_date'] ) ),
3806 'user_email' => $user_email,
3807 'other_info' => json_encode($other_info),
3808 'poll_id' => $poll_id,
3809 'multi_answer_ids' => json_encode($multi_answer_ids)
3810 ),
3811 array(
3812 '%d', // answer_id
3813 '%s', // user_ip
3814 '%s', // user_id
3815 '%s', // vote_date
3816 '%s', // user_email
3817 '%s', // other_info
3818 '%d', // poll_id
3819 '%s', // multi_answer_ids
3820 )
3821 );
3822
3823 // Race condition fix
3824 if ($limitusers > 0) {
3825 $wpdb->query("COMMIT");
3826 }
3827
3828 // $answers = $this->get_answer_by_id($answer_changed_id);
3829 if (!empty($options['notify_email_on'])) {
3830 $notify_admin_email = $options['notify_email'];
3831 $use_answered = '';
3832 if(isset($answer_titless) && !empty($answer_titless)){
3833 $use_answered = implode(', ', $answer_titless);
3834 }
3835 $subject = $poll_title;
3836 $headers = "MIME-Version: 1.0\r\n";
3837 $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
3838 $attachment = array();
3839 $mail_text = (
3840 /* translators: 1: user answer variable, 2: poll title variable 3: anchor tag */
3841 sprintf(esc_html__( "Someone's answer %1\$s in your %2\$s poll on %3\$s.", "poll-maker" ),
3842 $use_answered,
3843 '"' . $poll_title . '"',
3844 "<a href='" . home_url() . "' target='_blank'>" . home_url() . "</a>"
3845 ));
3846 wp_mail($notify_admin_email, $subject, $mail_text, $headers, $attachment);
3847 }
3848
3849 }
3850 $res = $this->get_poll_by_id($poll_id);
3851 $res['voted_status'] = true;
3852 $numbering_arr = array();
3853 // $res['numbering'] = "none";
3854 // if($show_answers_numbering != "none"){
3855 // $answer_count = isset($res['answers']) && !empty($res['answers']) ? count($res['answers']) : false;
3856 // if($answer_count){
3857 // $numbering_arr = $this->ays_answer_numbering($show_answers_numbering , $answer_count);
3858 // $res['numbering'] = $numbering_arr;
3859 // }
3860 // }
3861 $check_user = false;
3862 if(isset($options['show_passed_users']) && $options['show_passed_users'] == 'on'){
3863 $check_user = true;
3864 $poll_avatar_user_count = isset($options['poll_show_passed_users_count']) && $options['poll_show_passed_users_count'] != "" ? $options['poll_show_passed_users_count'] : 3;
3865 $results_table = $wpdb->prefix."ayspoll_reports";
3866 $all_answers = isset($res['answers']) && !empty($res['answers']) ? $res['answers'] : array();
3867 $answer_ids = array();
3868 if(isset($all_answers) && !empty($all_answers)){
3869 foreach($all_answers as $answer => $value){
3870 $answer_ids[] = $value['id'];
3871 }
3872 }
3873 $answer_ids = implode(',' , $answer_ids);
3874 $sql_users = "SELECT `user_id` , `answer_id`
3875 FROM ".$results_table."
3876 WHERE `answer_id` IN (".$answer_ids.")
3877 GROUP BY user_id, answer_id
3878 ORDER BY vote_date DESC";
3879 $user_res = $wpdb->get_results($sql_users , ARRAY_A);
3880 $user_pic_args = array(
3881 "class" => "ays-user-profile-pic"
3882 );
3883 $users_res_array = array();
3884 foreach($user_res as $ar){
3885 // if( isset( $users_res_array[$ar['answer_id']] ) ){
3886 // continue;
3887 // }
3888 $users_res_array[$ar['answer_id']][] = intval( $ar['user_id'] );
3889 }
3890
3891 if(isset($all_answers) && !empty($all_answers)){
3892 foreach($all_answers as $key => $answer){
3893 $user_answers = array();
3894 if( array_key_exists( $answer['id'], $users_res_array ) ){
3895 $user_answers = $this->ays_poll_get_avatars($answer['id'] , $users_res_array);
3896 }
3897 $res['answers'][$key]['avatar'] = $user_answers;
3898 }
3899 }
3900 $res['check_user_pic'] = $check_user;
3901 $res['check_user_pic_count'] = $poll_avatar_user_count;
3902 $res['check_user_pic_url'] = POLL_MAKER_AYS_PUBLIC_URL.'/images/more.png';
3903 $res['check_user_pic_loader'] = POLL_MAKER_AYS_PUBLIC_URL.'/images/tail-spin.svg';
3904 }
3905 if(!isset($message_data)){
3906 $message_data = array();
3907 }
3908 $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']) : "";
3909
3910
3911 $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)) : "";
3912 $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)) : "";
3913 $sensitive_fields = [
3914 'notify_email',
3915 'author',
3916 'poll_create_author',
3917 'mailchimp_list',
3918 'users_role'
3919 ];
3920 if (!current_user_can('manage_options')) {
3921 foreach ($sensitive_fields as $field) {
3922 if (isset($res['styles'][$field]) && $res['styles'][$field] != "") {
3923 unset($res['styles'][$field]);
3924 }
3925 }
3926 }
3927 $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']) : "";
3928 $res['check_admin_approval'] = $check_admin_approval;
3929
3930 /**
3931 * Fires after a user successfully submits a vote in Poll Maker.
3932 *
3933 * @since 1.0.0
3934 *
3935 * @param int $poll_id The poll ID.
3936 */
3937 if (has_action('ays_poll_maker_after_vote')) {
3938 // Collect extra contextual data for hooks
3939 $user_id = get_current_user_id();
3940 $data = array_merge(
3941 (array) $message_data,
3942 array(
3943 'poll_id' => $poll_id,
3944 'answer_id' => $answer_id,
3945 'user_id' => $user_id,
3946 )
3947 );
3948 do_action(
3949 'ays_poll_maker_after_vote',
3950 $data
3951 );
3952 }
3953
3954 ob_end_clean();
3955 $ob_get_clean = ob_get_clean();
3956 echo json_encode($res);
3957 wp_die();
3958 }
3959 }
3960
3961 public function ays_poll_get_avatars($answer , $users){
3962 $user_answers = array();
3963 $user_pic_args = array(
3964 "class" => "ays-user-profile-pic"
3965 );
3966 foreach($users[$answer] as $res_key => $res_value){
3967 if($res_value == 0){
3968 continue;
3969 }
3970 $user_avatars = get_avatar($res_value, 24, $default = '', $alt = '', $user_pic_args);
3971 $user_avatars = isset($user_avatars) && $user_avatars ? $user_avatars : '' ;
3972 $user_answers[] = "<div class='ays-users-profile-pics'>".$user_avatars."</div>";
3973 }
3974 return $user_answers;
3975 }
3976
3977 public function ays_add_mailchimp_transaction( $username, $api_key, $list_id, $args ) {
3978
3979 $email = isset($args['email']) ? $args['email'] : null;
3980 $fname = isset($args['fname']) ? $args['fname'] : "";
3981 $lname = isset($args['lname']) ? $args['lname'] : "";
3982 $phone = isset($args['pnumber']) ? $args['pnumber'] : "";
3983
3984 $api_prefix = explode("-", $api_key)[1];
3985
3986 $fields = array(
3987 "email_address" => $email,
3988 "status" => "subscribed",
3989 "merge_fields" => array(
3990 "FNAME" => $fname,
3991 "LNAME" => $lname,
3992 "PHONE" => $phone
3993 )
3994 );
3995 $curl = curl_init();
3996 curl_setopt_array($curl, array(
3997 CURLOPT_URL => "https://" . $api_prefix . ".api.mailchimp.com/3.0/lists/" . $list_id . "/members/",
3998 CURLOPT_RETURNTRANSFER => true,
3999 CURLOPT_ENCODING => "",
4000 CURLOPT_MAXREDIRS => 10,
4001 CURLOPT_TIMEOUT => 30,
4002 CURLOPT_SSL_VERIFYPEER => false,
4003 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
4004 CURLOPT_USERPWD => "$username:$api_key",
4005 CURLOPT_CUSTOMREQUEST => "POST",
4006 CURLOPT_POSTFIELDS => json_encode($fields),
4007 CURLOPT_HTTPHEADER => array(
4008 "Content-Type: application/json",
4009 "cache-control: no-cache"
4010 ),
4011 ));
4012
4013 $response = curl_exec($curl);
4014
4015 $err = curl_error($curl);
4016
4017 curl_close($curl);
4018
4019 if ($err) {
4020 return "cURL Error #: " . $err;
4021 } else {
4022 return $response;
4023 }
4024 }
4025
4026 private function get_answer_by_id( $id ) {
4027 global $wpdb;
4028 $args_id = absint(intval($id));
4029 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
4030 // $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
4031 // $sql = "SELECT a.*, COUNT(r.id) as voted FROM ".$answ_table." as a
4032 // JOIN ".$rep_table." as r
4033 // ON FIND_IN_SET(a.id , r.answer_id)
4034 // WHERE a.id = %d";
4035
4036 $sql = "SELECT * FROM ".$answ_table."
4037 WHERE id = %d";
4038
4039 $answ_id = $wpdb->get_row(
4040 $wpdb->prepare( $sql, $args_id),
4041 'ARRAY_A'
4042 );
4043
4044 return $answ_id;
4045 }
4046
4047 private function check_text_answer_exist( $poll_id, $user_answer ) {
4048 global $wpdb;
4049
4050 $answ_table = esc_sql($wpdb->prefix . "ayspoll_answers");
4051
4052 $sql = "SELECT * FROM " . $answ_table . " WHERE poll_id = %d AND answer = %s";
4053
4054 $answ_id = $wpdb->get_results(
4055 $wpdb->prepare( $sql, $poll_id, $user_answer),
4056 'ARRAY_A'
4057 );
4058 return (!empty($answ_id));
4059 }
4060
4061 private function get_text_answer_id($poll_id, $user_answer) {
4062 global $wpdb;
4063 $answ_table = esc_sql($wpdb->prefix . "ayspoll_answers");
4064
4065 $sql = $wpdb->prepare(
4066 "SELECT MAX(id) FROM $answ_table WHERE poll_id = %d AND answer = %s",
4067 $poll_id,
4068 $user_answer
4069 );
4070
4071 $last_id = $wpdb->get_var($sql);
4072
4073 if (is_null($last_id)) {
4074 return 0;
4075 }
4076
4077 return (int) $last_id;
4078 }
4079
4080 public static function get_answer_by_ids( $ids ) {
4081 global $wpdb;
4082 $sql = "SELECT * FROM {$wpdb->prefix}ayspoll_answers
4083 WHERE id IN (".$ids.")";
4084 return $wpdb->get_results($sql, 'ARRAY_A');
4085 }
4086
4087 public function check_shedule_expired_poll( $args ) {
4088 $id = absint(intval($args));
4089 $poll_options = $this->get_poll_by_id($id);
4090 $options = $poll_options['styles'];
4091
4092 $is_expired = true;
4093 $startDate = '';
4094 $endDate = '';
4095 $current_time = strtotime(current_time( "Y:m:d H:i:s" ));
4096 if (isset($options['active_date_check']) && !empty($options['active_date_check'])) {
4097 if (isset($options['activeInterval']) && isset($options['deactiveInterval'])) {
4098 if (isset($options['activeIntervalSec']) && !empty($options['activeIntervalSec'])) {
4099 $startDate = strtotime($options['activeInterval']." ".$options['activeIntervalSec']);
4100 }
4101 else{
4102 $startDate = strtotime($options['activeInterval']);
4103 }
4104
4105 if (isset($options['deactiveIntervalSec']) && !empty($options['deactiveIntervalSec'])) {
4106 $endDate = strtotime($options['deactiveInterval']." ".$options['deactiveIntervalSec']);
4107 }
4108 else{
4109 $endDate = strtotime($options['deactiveInterval']);
4110 }
4111
4112 if ($startDate < $current_time && $endDate > $current_time) {
4113 $is_expired = true;
4114 }else{
4115 $is_expired = false;
4116 }
4117 }
4118 }
4119 $published = (isset($options['published']) && intval($options['published']) === 0) ? false : true;
4120 return $is_expired && $published ? true : false;
4121 }
4122
4123 protected function hex2rgba($color, $opacity = false){
4124
4125 $default = 'rgb(0,0,0)';
4126
4127 //Return default if no color provided
4128 if (empty($color))
4129 return $default;
4130
4131 //Sanitize $color if "#" is provided
4132 if ($color[0] == '#') {
4133 $color = substr($color, 1);
4134 }else{
4135 return $color;
4136 }
4137
4138 //Check if color has 6 or 3 characters and get values
4139 if (strlen($color) == 6) {
4140 $hex = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]);
4141 } elseif (strlen($color) == 3) {
4142 $hex = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]);
4143 } else {
4144 return $default;
4145 }
4146
4147 //Convert hexadec to rgb
4148 $rgb = array_map('hexdec', $hex);
4149
4150 //Check if opacity is set(rgba or rgb)
4151 if ($opacity) {
4152 if (abs($opacity) > 1)
4153 $opacity = 1.0;
4154 $output = 'rgba(' . implode(",", $rgb) . ',' . $opacity . ')';
4155 } else {
4156 $output = 'rgb(' . implode(",", $rgb) . ')';
4157 }
4158
4159 //Return rgb(a) color string
4160 return $output;
4161 }
4162
4163 public function rgb2hex( $rgb ) {
4164 if ($rgb[0] == '#') {
4165 return $rgb;
4166 }
4167 $colors = explode(',', rtrim(explode('(', $rgb)[1], ')'));
4168
4169 return sprintf("#%02x%02x%02x", $colors[0], $colors[1], $colors[2]);
4170 }
4171
4172 public static function ays_poll_get_limit_user_count_by_id($poll_id, $user_id){
4173 global $wpdb;
4174
4175 $id = absint(intval($poll_id));
4176 $reports_table = esc_sql($wpdb->prefix."ayspoll_reports");
4177 $answers_table = esc_sql($wpdb->prefix."ayspoll_answers");
4178
4179 $sql = "SELECT COUNT(*)
4180 FROM ".$reports_table."
4181 INNER JOIN ".$answers_table."
4182 ON ".$answers_table.".id=".$reports_table.".answer_id
4183 WHERE ".$answers_table.".poll_id = ".$id." AND ".$reports_table.".user_id = ".$user_id;
4184
4185 $result = intval($wpdb->get_var($sql));
4186
4187 return $result;
4188 }
4189
4190 public static function ays_poll_get_limit_user_count_by_ip($poll_id){
4191 global $wpdb;
4192 $id = absint(intval($poll_id));
4193 $user_ip = self::get_user_ip_validated();
4194 $reports_table = esc_sql($wpdb->prefix."ayspoll_reports");
4195 $answers_table = esc_sql($wpdb->prefix."ayspoll_answers");
4196
4197 $sql = "SELECT COUNT(*)
4198 FROM ".$reports_table."
4199 INNER JOIN ".$answers_table."
4200 ON ".$answers_table.".id=".$reports_table.".answer_id
4201 WHERE ".$answers_table.".poll_id = ".$id." AND ".$reports_table.".user_ip = '". $user_ip ."'";
4202
4203 $result = intval($wpdb->get_var($sql));
4204
4205 return $result;
4206 }
4207
4208 public function ays_poll_get_results($id) {
4209
4210 global $wpdb;
4211 $content = '';
4212 $id = absint(intval($id));
4213 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
4214 $polls_table = esc_sql($wpdb->prefix."ayspoll_polls");
4215
4216
4217 $poll_sql = "SELECT * FROM ".$polls_table." WHERE id =%d";
4218 $polls = $wpdb->get_row(
4219 $wpdb->prepare( $poll_sql, $id),
4220 'ARRAY_A'
4221 );
4222 $votes_count = $this->get_poll_results_count_by_id($id);
4223 $poll = $this->get_poll_by_id($id);
4224 $polls_options = $poll['styles'];
4225
4226
4227 // $poll_answer_sorting = isset($polls_options['result_sort_type']) && $polls_options['result_sort_type'] != "none" ? $polls_options['result_sort_type'] : "ASC";
4228 $ans_sql = "SELECT * FROM ".$answ_table." WHERE poll_id =%d ORDER BY votes DESC";
4229 $poll_answers = $wpdb->get_results(
4230 $wpdb->prepare( $ans_sql, $id),
4231 'ARRAY_A'
4232 );
4233 if ($polls == null) {
4234 $content = '<p style="text-align:center;">No ratings yet</p>';
4235 }else{
4236 // $votes_count = $this->get_poll_results_count_by_id($id);
4237 // $poll = $this->get_poll_by_id($id);
4238 // $polls_options = $poll['styles'];
4239 $content .= "<div class='results-apm'>";
4240 if (intval($votes_count['res_count']) > 0) {
4241 $one_percent = 100/intval($votes_count['res_count']);
4242 }else{
4243 $one_percent = 1;
4244 }
4245
4246 $poll_show_answer_perc = isset($polls_options['show_res_percent']) && $polls_options['show_res_percent'] == 1 ? true : false;
4247 $poll_show_votes_count = isset($polls_options['show_votes_count']) && $polls_options['show_votes_count'] == 1 ? true : false;
4248 $poll_main_color = isset($polls_options['main_color']) && $polls_options['main_color'] != '' ? esc_attr($polls_options['main_color']) : '';
4249 $poll_bg_color = isset($polls_options['bg_color']) && $polls_options['bg_color'] != '' ? esc_attr($polls_options['bg_color']) : '';
4250 $poll_hide_result = isset($polls_options['hide_results']) && $polls_options['hide_results'] == 1 ? true : false;
4251 $poll_hide_result_message_check = isset($polls_options['hide_result_message']) && $polls_options['hide_result_message'] == 1 ? true : false;
4252 $poll_hide_result_message = isset($polls_options['hide_results_text']) && $polls_options['hide_results_text'] != "" ? wpautop($polls_options['hide_results_text']) : "";
4253 $poll_show_avatars = isset($polls_options['show_passed_users']) && $polls_options['show_passed_users'] == "on" ? true : false;
4254 $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;
4255 if($poll_hide_result){
4256 $content .= "<div >" . $poll_hide_result_message . "</div>";
4257 }
4258 else{
4259 $poll_answers_count = count($poll_answers);
4260
4261 if($poll_show_avatars){
4262 $results_table = $wpdb->prefix."ayspoll_reports";
4263 $answer_ids = array();
4264 if(isset($poll_answers) && !empty($poll_answers)){
4265 foreach($poll_answers as $answer => $value){
4266 $answer_ids[] = $value['id'];
4267 }
4268 }
4269 $answer_ids = implode(',' , $answer_ids);
4270 $sql_users = "SELECT `user_id` , `answer_id`
4271 FROM ".$results_table."
4272 WHERE `answer_id` IN (".$answer_ids.")
4273 GROUP BY user_id, answer_id
4274 ORDER BY vote_date DESC";
4275 $user_res = $wpdb->get_results($sql_users , ARRAY_A);
4276 $user_pic_args = array(
4277 "class" => "ays-user-profile-pic"
4278 );
4279 $users_res_array = array();
4280 foreach($user_res as $ar){
4281 $users_res_array[$ar['answer_id']][] = intval( $ar['user_id'] );
4282 }
4283
4284 if(isset($poll_answers) && !empty($poll_answers)){
4285 foreach($poll_answers as $key => $answer){
4286 $user_answers = array();
4287 if( array_key_exists( $answer['id'], $users_res_array ) ){
4288 $user_answers = $this->ays_poll_get_avatars($answer['id'] , $users_res_array);
4289 }
4290 $poll_answers[$key]['avatar'] = $user_answers;
4291 }
4292 }
4293 }
4294 foreach ($poll_answers as $ans_key => $ans_val) {
4295 $poll_avatars_content = "";
4296 $poll_user_avatars = "";
4297 $answer_img = (isset( $ans_val['answer_img'] ) && $ans_val['answer_img'] != '') ? $ans_val['answer_img'] : "";
4298 if(isset($ans_val["avatar"]) && !empty($ans_val["avatar"])){
4299 $x = array_splice($ans_val["avatar"] , 0 ,$poll_avatars_count);
4300 $poll_user_avatars = implode(" " , $x);
4301
4302 }
4303 if($poll_show_avatars && $poll_user_avatars != ""){
4304 $poll_avatars_content = '<div class="ays-user-count">
4305 '.$poll_user_avatars.'
4306 <div class="ays-users-profile-pics">
4307 <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"].'>
4308 </div>
4309 </div>';
4310 }
4311 $perc_cont = '';
4312 $percent = round($one_percent*intval($ans_val['votes']));
4313 $perc_conta_hide_or_no = '';
4314 if($poll_show_answer_perc){
4315 if ($percent == 0) {
4316 $perc_cont = '0 %';
4317 $perc_conta_hide_or_no = '';
4318 }else{
4319 $perc_cont = $percent.' %';
4320 $perc_conta_hide_or_no = '('.$percent.'%'.')';
4321 }
4322
4323 }
4324
4325 $answer_votes_count = '';
4326 if($poll_show_votes_count){
4327 $answer_votes_count = isset($ans_val['votes']) ? esc_attr($ans_val['votes']) : '';
4328 }
4329 switch ($polls['type']) {
4330 case 'choosing':
4331 $content .= "<div class='ays-poll-answers-box'>";
4332 if($answer_img != ''){
4333 $content .= "<div class='ays-poll-answers-image-box'>
4334
4335 <img src='" . $answer_img ."' class='ays-poll-answers-current-image'>
4336
4337 </div>";
4338 }
4339
4340 $content .= '<div class="ays-poll-answer-text-and-percent-box">';
4341 $content .= '<div class="answer-title flex-apm">
4342 <span class="answer-text">' . stripslashes($ans_val['answer']) . '</span>
4343 <span class="answer-votes">'.$answer_votes_count.' '.$perc_conta_hide_or_no.'</span>
4344 </div>
4345 ' . $poll_avatars_content . '
4346 <div class="answer-percent-res" style="width: ' . ($percent == 0 ? '10' : $percent) . '%;
4347 border-radius: 20px;
4348 background-color: ' . $poll_main_color . ';
4349 color: ' . $poll_bg_color . ';
4350 padding-left: 10px;
4351 font-size: 15px;
4352 text-align: left;">' . $perc_cont . '</div>';
4353 $content .= '</div>';
4354 $content .= '</div>';
4355 break;
4356
4357 case 'rating':
4358 switch ($polls['view_type']) {
4359 case 'star':
4360 $star_type = '';
4361 for ($i=0; $i < intval($ans_val['answer']); $i++) {
4362 $star_type .= '<i class="ays_poll_far ays_poll_fa-star far"></i>';
4363 }
4364 $content .= '<div class="answer-title flex-apm">
4365 <span class="answer-text">'.$star_type.'</span>
4366 <span class="answer-votes">'.$answer_votes_count.'</span>
4367 </div>
4368 '.$poll_avatars_content.'
4369 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4370 break;
4371
4372 case 'emoji':
4373 $emojy_type = '';
4374 if ($poll_answers_count == 3) {
4375 switch (intval($ans_val['answer'])) {
4376 case 1:
4377 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
4378 break;
4379 case 2:
4380 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-meh far"></i>';
4381 break;
4382 case 3:
4383 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
4384 break;
4385 default:
4386 break;
4387 }
4388 }else{
4389 switch (intval($ans_val['answer'])) {
4390 case 1:
4391 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-tired far"></i>';
4392 break;
4393 case 2:
4394 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
4395 break;
4396 case 3:
4397 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-meh far"></i>';
4398 break;
4399 case 4:
4400 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
4401 break;
4402 case 5:
4403 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-dizzy far"></i>';
4404 break;
4405 default:
4406 break;
4407 }
4408 }
4409
4410 $content .= '<div class="answer-title flex-apm">
4411 <span class="answer-text">'.$emojy_type.'</span>
4412 <span class="answer-votes">'.$answer_votes_count.'</span>
4413 </div>
4414 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4415
4416 break;
4417 default:
4418 break;
4419 }
4420 break;
4421
4422 case 'voting':
4423 switch ($polls['view_type']) {
4424 case 'hand':
4425 $hand_type = '';
4426 if (intval($ans_val['answer'] == 1)) {
4427 $hand_type = '<i class="ays_poll_far ays_poll_fa-thumbs-up far"></i>';
4428 }else{
4429 $hand_type = '<i class="ays_poll_far ays_poll_fa-thumbs-down far"></i>';
4430 }
4431 $content .= '<div class="answer-title flex-apm">
4432 <span class="answer-text">'.$hand_type.'</span>
4433 <span class="answer-votes">'.$answer_votes_count.'</span>
4434 </div>
4435 '.$poll_avatars_content.'
4436 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4437 break;
4438
4439 case 'emoji':
4440 $emojy_type = '';
4441 if (intval($ans_val['answer'] == 1)) {
4442 $emojy_type = '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
4443 }else{
4444 $emojy_type = '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
4445 }
4446 $content .= '<div class="answer-title flex-apm">
4447 <span class="answer-text">'.$emojy_type.'</span>
4448 <span class="answer-votes">'.$answer_votes_count.'</span>
4449 </div>
4450 '.$poll_avatars_content.'
4451 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4452
4453 break;
4454 default:
4455 break;
4456 }
4457 break;
4458 default:
4459 break;
4460 }
4461
4462 }
4463 }
4464
4465 }
4466 $content .= "</div>";
4467 return $content;
4468 }
4469
4470 public function intToRoman($num) {
4471 $map = array(
4472 1000 => 'M', 900 => 'CM', 500 => 'D', 400 => 'CD',
4473 100 => 'C', 90 => 'XC', 50 => 'L', 40 => 'XL',
4474 10 => 'X', 9 => 'IX', 5 => 'V', 4 => 'IV', 1 => 'I'
4475 );
4476 $roman = '';
4477 foreach ($map as $value => $symbol) {
4478 while ($num >= $value) {
4479 $roman .= $symbol;
4480 $num -= $value;
4481 }
4482 }
4483 return $roman;
4484 }
4485
4486 public function ays_answer_numbering($numbering , $count){
4487 $keyword_arr = array();
4488 switch ($numbering) {
4489 case '1.':
4490 $char_min_val = 1;
4491 for($x = $char_min_val; $x <= $count; $x++){
4492 $keyword_arr[] = $x .".";
4493 }
4494 break;
4495 case '1)':
4496 $char_min_val = 1;
4497 for($x = $char_min_val; $x <= $count; $x++){
4498 $keyword_arr[] = $x .")";
4499 }
4500 break;
4501 case 'A.':
4502 $columns = array();
4503 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4504 foreach($keyword_arr as $key => $value){
4505 $columns[] = $value . ".";
4506 }
4507 $keyword_arr = $columns;
4508 break;
4509 case 'A)':
4510 $columns = array();
4511 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4512 foreach($keyword_arr as $key => $value){
4513 $columns[] = $value . ")";
4514 }
4515 $keyword_arr = $columns;
4516 break;
4517 case 'a.':
4518 $columns = array();
4519 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4520 foreach($keyword_arr as $key => $value){
4521 $columns[] = strtolower($value) . ".";
4522 }
4523 $keyword_arr = $columns;
4524 break;
4525 case 'a)':
4526 $columns = array();
4527 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4528 foreach($keyword_arr as $key => $value){
4529 $columns[] = strtolower($value) . ")";
4530 }
4531 $keyword_arr = $columns;
4532 break;
4533 case 'VI.':
4534 $columns = array();
4535 for ($i = 1; $i <= $count; $i++) {
4536 $columns[] = $this->intToRoman($i) . ".";
4537 }
4538 $keyword_arr = $columns;
4539 break;
4540 default:
4541 break;
4542 }
4543 return $keyword_arr;
4544 }
4545 public static function ays_poll_generate_keyword_array( $max_val ) {
4546 if (is_null($max_val) || $max_val == '') {
4547 $max_val = 6; //'F';
4548 }
4549 $max_val = absint(intval($max_val)) - 1;
4550 $keyword_arr = array();
4551 $letters = range('A', 'Z');
4552 if($max_val <= 25){
4553 $max_alpha_val = $letters[$max_val];
4554 }
4555 elseif($max_val > 25){
4556 $dividend = ($max_val + 1);
4557 $max_alpha_val = '';
4558 $modulo = 0;
4559 while ($dividend > 0){
4560 $modulo = ($dividend - 1) % 26;
4561 $max_alpha_val = $letters[$modulo] . $max_alpha_val;
4562 $dividend = floor((($dividend - $modulo) / 26));
4563 }
4564 }
4565 $keyword_arr = self::ays_poll_create_columns_array( $max_alpha_val );
4566 return $keyword_arr;
4567 }
4568 public static function ays_poll_create_columns_array($end_column, $first_letters = '') {
4569 $columns = array();
4570 $letters = range('A', 'Z');
4571 $length = strlen($end_column);
4572 // Iterate over 26 letters.
4573 foreach ($letters as $letter) {
4574 // Paste the $first_letters before the next.
4575 $column = $first_letters . $letter;
4576 // Add the column to the final array.
4577 $columns[] = $column;
4578 // If it was the end column that was added, return the columns.
4579 if ($column == $end_column)
4580 return $columns;
4581 }
4582 // Add the column children.
4583 foreach ($columns as $column) {
4584 // Don't itterate if the $end_column was already set in a previous itteration.
4585 // Stop iterating if you've reached the maximum character length.
4586 if (!in_array($end_column, $columns) && strlen($column) < $length) {
4587 $new_columns = self::ays_poll_create_columns_array($end_column, $column);
4588 // Merge the new columns which were created with the final columns array.
4589 $columns = array_merge($columns, $new_columns);
4590 }
4591 }
4592 return $columns;
4593 }
4594
4595 public function get_answer_by_id_multi( $id ) {
4596 global $wpdb;
4597 $args_id = absint(intval($id));
4598 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
4599 // $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
4600 // $sql = "SELECT a.*, COUNT(r.id) as voted FROM ".$answ_table." as a
4601 // JOIN ".$rep_table." as r
4602 // ON r.answer_id = a.id
4603 // WHERE a.id = %d";
4604
4605 $sql = "SELECT * FROM ".$answ_table."
4606 WHERE id = %d";
4607
4608 $answ_id = $wpdb->get_results(
4609 $wpdb->prepare( $sql, $args_id),
4610 'ARRAY_A'
4611 );
4612
4613 return $answ_id;
4614 }
4615
4616 // Users avatars
4617 public function ays_poll_get_current_answer_users_pics(){
4618 global $wpdb;
4619 $results_table = $wpdb->prefix."ayspoll_reports";
4620
4621 $answer_id = isset($_POST['answer_id']) && $_POST['answer_id'] != "" ? absint($_POST['answer_id']) : null;
4622 $user_answers = array();
4623
4624 if(isset($answer_id)){
4625 $sql_users = "SELECT `user_id`
4626 FROM ".$results_table."
4627 WHERE `answer_id` = ".$answer_id."
4628 GROUP BY user_id, answer_id
4629 ORDER BY vote_date DESC";
4630 $user_res = $wpdb->get_results($sql_users , ARRAY_A);
4631 if(isset($user_res)){
4632 $user_pic_args = array(
4633 "class" => "ays-user-profile-pic-popup"
4634 );
4635
4636 foreach($user_res as $key => $value){
4637 $user_id = isset($value['user_id']) && $value['user_id'] != "" ? intval($value['user_id']) : 0;
4638 if($user_id == 0){
4639 continue;
4640 }
4641
4642 $user_avatars = get_avatar($user_id, 24, $default = '', $alt = '', $user_pic_args);
4643 $user_data = get_userdata($user_id);
4644 $user_name = "";
4645 if(isset($user_data)){
4646 if(isset($user_data->data)){
4647 $user_name = isset($user_data->data->display_name) && $user_data->data->display_name != "" ? esc_attr($user_data->data->display_name) : "";
4648 }
4649 }
4650 $user_avatars = isset($user_avatars) && $user_avatars ? $user_avatars : '';
4651 $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>";
4652 }
4653 }
4654 }
4655 echo json_encode($user_answers);
4656 wp_die();
4657 }
4658
4659 public function ays_add_answer_poll($data) {
4660 global $wpdb;
4661 $poll_id = absint($data['poll_id']);
4662 $new_answer = wp_filter_kses($data['new_answer']);
4663 $poll_add_answer_require = $data['admin_require'];
4664 $poll_answers_count = isset($data['answers_count']) && $data['answers_count'] > 0 ? intval($data['answers_count']) : 1;
4665 $if_text_type = isset($data['if_text_type']) && $data['if_text_type'] ? true : false;
4666
4667 $show_user_added = 0;
4668 // $votes = 0;
4669 // if($if_text_type){
4670 // $votes = 1;
4671 // }
4672 if(!$poll_add_answer_require){
4673 $show_user_added = 1;
4674 }
4675 $wpdb->insert(
4676 "{$wpdb->prefix}ayspoll_answers",
4677 array(
4678 'poll_id' => $poll_id,
4679 'answer' => $new_answer,
4680 'votes' => 0,
4681 'ordering' => ($poll_answers_count + 1),
4682 'user_added' => 1,
4683 'show_user_added' => $show_user_added
4684 ),
4685 array(
4686 '%d',
4687 '%s',
4688 '%d',
4689 '%d',
4690 '%d',
4691 '%d',
4692 )
4693 );
4694
4695 $last_id = $wpdb->insert_id;
4696 return array(
4697 "new_id" => strval($last_id)
4698 );
4699 }
4700
4701 public function ays_generate_display_polls_method($attr){
4702 $recent_poll_ids = $this->ays_recent_poll_ids($attr);
4703 $content = '<div class="ays_poll_recent_polls">';
4704 $polls = array();
4705 foreach ($recent_poll_ids as $key => $last_poll_id) {
4706 $poll_id = (isset($last_poll_id['id']) && intval($last_poll_id['id']) != '') ? intval($last_poll_id['id']) : '';
4707 $shortcode = '[ays_poll id="'.$poll_id.'"]';
4708 $polls[] = do_shortcode( $shortcode );
4709 }
4710 $content .= implode( '', $polls );
4711 $content .= '</div>';
4712 return str_replace(array("\r\n", "\n", "\r"), "\n", $content);
4713 }
4714
4715 public function ays_recent_poll_ids($data){
4716 global $wpdb;
4717 $polls_table = $wpdb->prefix.'ayspoll_polls';
4718
4719 $ays_recent_poll_order_by = (isset($data['orderby']) && $data['orderby'] != '') ? sanitize_text_field($data['orderby']) : "recent";
4720 $ays_recent_poll_count = (isset($data['count']) && $data['count'] != '') ? intval($data['count']) : 5;
4721
4722 $last_polls_sql = "SELECT id FROM {$polls_table} WHERE styles LIKE '%\"published\":1%' ";
4723
4724 switch ($ays_recent_poll_order_by) {
4725 case 'recent':
4726 $last_polls_sql .= "ORDER BY id DESC LIMIT ".$ays_recent_poll_count;
4727 break;
4728 case 'random':
4729 $last_polls_sql .= "ORDER BY RAND() LIMIT ".$ays_recent_poll_count;
4730 break;
4731 default:
4732 $last_polls_sql .= "ORDER BY id DESC LIMIT ".$ays_recent_poll_count;
4733 break;
4734 }
4735
4736 $last_poll_ids = $wpdb->get_results($last_polls_sql,'ARRAY_A');
4737
4738 return $last_poll_ids;
4739 }
4740
4741 public function ays_set_poll_fields_placeholders_texts(){
4742
4743 /*
4744 * Get Poll fields placeholders from database
4745 */
4746
4747 $settings_placeholders_texts = $this->settings->ays_get_setting('fields_placeholders');
4748 if($settings_placeholders_texts){
4749 $settings_placeholders_texts = json_decode(stripcslashes($settings_placeholders_texts), true);
4750 }else{
4751 $settings_placeholders_texts = array();
4752 }
4753
4754 $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';
4755
4756 $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';
4757
4758 $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';
4759
4760
4761 $poll_fields_placeholder_name_text = $poll_fields_placeholder_name === 'Name' ?esc_html__('Name', "poll-maker") : $poll_fields_placeholder_name;
4762 $poll_fields_placeholder_email_text = $poll_fields_placeholder_email === 'Email' ?esc_html__('Email', "poll-maker") : $poll_fields_placeholder_email;
4763 $poll_fields_placeholder_phone_text = $poll_fields_placeholder_phone === 'Phone' ?esc_html__('Phone', "poll-maker") : $poll_fields_placeholder_phone;
4764
4765
4766 $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';
4767
4768 $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';
4769
4770 $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';
4771
4772
4773 $poll_fields_label_name_text = $poll_fields_label_name === 'Name' ?esc_html__('Name', "poll-maker") : $poll_fields_label_name;
4774 $poll_fields_label_email_text = $poll_fields_label_email === 'Email' ?esc_html__('Email', "poll-maker") : $poll_fields_label_email;
4775 $poll_fields_label_phone_text = $poll_fields_label_phone === 'Phone' ?esc_html__('Phone', "poll-maker") : $poll_fields_label_phone;
4776
4777 $texts = array(
4778 'namePlaceholder' => $poll_fields_placeholder_name_text,
4779 'emailPlaceholder' => $poll_fields_placeholder_email_text,
4780 'phonePlaceholder' => $poll_fields_placeholder_phone_text,
4781
4782 'nameLabel' => $poll_fields_label_name_text,
4783 'emailLabel' => $poll_fields_label_email_text,
4784 'phoneLabel' => $poll_fields_label_phone_text,
4785 );
4786
4787 return $texts;
4788 }
4789
4790 public function ays_autoembed( $content ) {
4791 global $wp_embed;
4792 $content = stripslashes( wpautop( $content ) );
4793 $content = $wp_embed->autoembed( $content );
4794 if ( strpos( $content, '[embed]' ) !== false ) {
4795 $content = $wp_embed->run_shortcode( $content );
4796 }
4797 $content = do_shortcode( $content );
4798 return $content;
4799 }
4800
4801 public function replace_message_variables($content, $data){
4802 foreach($data as $variable => $value){
4803 $content = str_replace("%%".$variable."%%", $value, $content);
4804 }
4805 return $content;
4806 }
4807
4808 public function get_user_profile_data(){
4809
4810 $user_first_name = '';
4811 $user_last_name = '';
4812 $user_nickname = '';
4813
4814 $user_id = get_current_user_id();
4815 if($user_id != 0){
4816 $usermeta = get_user_meta( $user_id );
4817 if($usermeta !== null){
4818 $user_first_name = (isset($usermeta['first_name'][0]) && $usermeta['first_name'][0] != '' ) ? sanitize_text_field( $usermeta['first_name'][0] ) : '';
4819 $user_last_name = (isset($usermeta['last_name'][0]) && $usermeta['last_name'][0] != '' ) ? sanitize_text_field( $usermeta['last_name'][0] ) : '';
4820 $user_nickname = (isset($usermeta['nickname'][0]) && $usermeta['nickname'][0] != '' ) ? sanitize_text_field( $usermeta['nickname'][0] ) : '';
4821 }
4822 }
4823
4824 $message_data = array(
4825 'user_first_name' => $user_first_name,
4826 'user_last_name' => $user_last_name,
4827 'user_nickname' => $user_nickname,
4828 );
4829
4830 return $message_data;
4831 }
4832
4833 public function ays_poll_get_recent_poll_id(){
4834 global $wpdb;
4835 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
4836 $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
4837
4838 $last_polls_sql = "SELECT id FROM ".$poll_table." ORDER BY id DESC LIMIT 0, 1";
4839 $last_poll_sql = $wpdb->get_row($last_polls_sql , ARRAY_A);
4840
4841 $id = isset($last_poll_sql['id']) && $last_poll_sql['id'] !== 0 ? absint(intval($last_poll_sql['id'])) : "";
4842
4843 return $id;
4844 }
4845 }