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

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

4,805 lines 201.6 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 text type options start =====
1309 $poll_view_type_text = isset($poll['view_type']) && $poll['view_type'] != "" ? $poll['view_type'] : "short_text";
1310
1311 $poll_text_type_length_enable = (isset($options['poll_text_type_length_enable']) && $options['poll_text_type_length_enable'] == "on") ? true : false;
1312 $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";
1313 $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']) : "";
1314 $poll_text_type_limit_message = (isset($options['poll_text_type_limit_message']) && $options['poll_text_type_limit_message'] == "on") ? true : false;
1315 $poll_text_type_width = (isset($options['poll_text_type_width']) && $options['poll_text_type_width'] != "") ? stripslashes(esc_attr($options['poll_text_type_width'])) : "";
1316 $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";
1317
1318 $poll_class_for_limits = $poll_text_type_length_enable ? "ays_poll_question_limit_length" : "";
1319 $poll_box_for_limit_message = "";
1320
1321 if($poll_text_type_limit_message && ($poll_text_type_limit_length != "" && intval($poll_text_type_limit_length) != 0)){
1322 $poll_box_for_limit_message = '<div class="ays_quiz_question_text_conteiner">
1323 <div class="ays_quiz_question_text_message">
1324 <span class="ays_poll_question_text_message_span">'. $poll_text_type_limit_length . '</span> ' . $poll_text_type_limit_type . ' '. esc_html__( ' left' , "poll-maker" ) . '
1325 </div>
1326 </div>';
1327 }
1328 $poll_text_type_ready_width = "";
1329 $poll_text_type_ready_type = "%";
1330 if($poll['type'] == 'text'){
1331 if($poll_view_type_text == "short_text"){
1332 if($poll_text_type_width == "" || intval($poll_text_type_width) == 0){
1333 $poll_text_type_ready_width = "60";
1334 $poll_text_type_ready_type = "%";
1335 }
1336 else{
1337 $poll_text_type_ready_width = $poll_text_type_width;
1338 $poll_text_type_ready_type = ($poll_text_type_width_type == "percent" ? "%" : "px");
1339 }
1340 }
1341 else{
1342 if($poll_text_type_width == "" || intval($poll_text_type_width) == 0){
1343 $poll_text_type_ready_width = "100";
1344 $poll_text_type_ready_type = "%";
1345 }
1346 else{
1347 $poll_text_type_ready_width = $poll_text_type_width;
1348 $poll_text_type_ready_type = ($poll_text_type_width_type == "percent" ? "%" : "px");
1349 }
1350 }
1351 }
1352 // ===== Poll text type options end =====
1353
1354 $poll_password_box = '';
1355 $form_method = '';
1356 $password_message_with_toggle = "";
1357 $password_message_with_toggle_class = "";
1358
1359 $poll_enable_password = isset($options['poll_enable_password']) && $options['poll_enable_password'] == 'on' ? true : false;
1360 $poll_password_poll = isset($options['poll_password']) && $options['poll_password'] != "" ? stripslashes(esc_attr($options['poll_password'])) : "";
1361
1362 // Enable toggle password visibility
1363 $options['poll_enable_password_visibility'] = isset($options['poll_enable_password_visibility']) ? $options['poll_enable_password_visibility'] : 'off';
1364 $poll_enable_password_visibility = (isset($options['poll_enable_password_visibility']) && $options['poll_enable_password_visibility'] == 'on') ? true : false;
1365
1366
1367 $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 ])) : '';
1368 $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>";
1369
1370 $poll_check_only_logged = (isset($options['enable_logged_users']) && $options['enable_logged_users'] == 1 && !is_user_logged_in()) ? true : false;
1371 $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'>";
1372
1373 if ( $poll_enable_password_visibility ) {
1374 $password_message_with_toggle_class = "ays-poll-password-input-box-visibility";
1375 $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'>";
1376 $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'>";
1377 }
1378
1379
1380 if($poll_enable_password){
1381 $form_method = "method='post'";
1382 $poll_password_box = "<div style='padding:50px;text-align:center;' id='ays-poll-password-". $id ."' >
1383 <div class='ays-poll-password-title'>
1384 ". $poll_password_message . "
1385 </div>
1386 <div class='ays-poll-password-box '>
1387 <div class='ays-poll-password-input-box ays-poll-password-input-box-visibility'>
1388 ".$poll_password_message_input."
1389 ".$password_message_with_toggle."
1390 </div>
1391 <div class='ays-poll-password-button-box'>
1392 <input type='submit' class='ays-poll-password-button' name='ays_poll_password_sub_". $id ."' class='ays_poll_password' value='". esc_html__( "Submit", "poll-maker" )."'>
1393 </div>
1394 </div>
1395 </div></div></form></div>";
1396 }
1397 $poll_password_check = ($password_input_val == $poll_password_poll) ? true : false;
1398
1399 // Animation Top (px)
1400 $poll_animation_top = (isset($general_options['poll_animation_top']) && $general_options['poll_animation_top'] != '') ? absint(intval($general_options['poll_animation_top'])) : 100 ;
1401 $options['poll_enable_animation_top'] = isset($general_options['poll_enable_animation_top']) ? $general_options['poll_enable_animation_top'] : 'on';
1402 $poll_enable_animation_top = (isset($general_options['poll_enable_animation_top']) && $general_options['poll_enable_animation_top'] == "on") ? true : false;
1403
1404 // Answers box shadow
1405 $answers_box_shadow = (isset($options['poll_answer_enable_box_shadow']) && $options['poll_answer_enable_box_shadow'] == "on") ? true : false;
1406 $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';
1407
1408 $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;
1409
1410 $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;
1411
1412 $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;
1413
1414 $answers_box_shadow_content = 'box-shadow:unset';
1415 if($answers_box_shadow){
1416 $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;
1417 }
1418
1419 $poll_answer_border_radius = isset($options['poll_answer_border_radius']) && $options['poll_answer_border_radius'] != '' ? intval(esc_attr($options['poll_answer_border_radius'])) : 0;
1420
1421 // Display form fields labels
1422 $options['display_fields_labels'] = isset($options['display_fields_labels']) ? $options['display_fields_labels'] : 'on';
1423 $display_fields_labels = (isset($options['display_fields_labels']) && $options['display_fields_labels'] == 'on') ? true : false;
1424
1425 // Social Media links
1426 $enable_social_links = (isset($options['enable_social_links']) && $options['enable_social_links'] == "on") ? true : false;
1427
1428 $show_chart_type = (isset($options['show_chart_type']) && $options['show_chart_type'] != "") ? $options['show_chart_type'] : "default_bar_chart";
1429
1430 $content = "<style>
1431
1432 #".$this_poll_id.".box-apm {
1433 width: $poll_width;
1434 ". $poll_min_height ."
1435 margin: 0 auto !important;
1436 border-style: {$options['border_style']};
1437 border-color: $poll_border_color;
1438 border-radius: " . ((isset($options['border_radius']) && !empty($options['border_radius'])) ? (int) $options['border_radius'] . 'px' : 0) . ";
1439 border-width: " . ((isset($options['border_width']) && $options['border_width'] != '') ? (int) $options['border_width'] . 'px' : '2px') . ";
1440 box-shadow: " . $box_shadow_offsets . ";".
1441 $poll_styles."
1442 background-position: ".$poll_bg_image_position.";
1443 background-repeat: no-repeat;
1444 background-size: cover;
1445 max-width: 100%;
1446 position: relative;
1447 padding-bottom: 60px;
1448 }
1449
1450 .$this_poll_id.ays-minimal-theme .apm-choosing{
1451 display: flex;
1452 align-items: center;
1453 }
1454
1455 .$this_poll_id div.ays-image-logo-show{
1456 position: absolute;
1457 bottom: -5px;
1458 left: 1px;
1459 margin: 2px 0 0 0;
1460 padding: 2px;
1461 width: 100%;
1462 height: 65px;
1463 text-align: left;
1464 }
1465 .$this_poll_id .ays-poll-image-logo{
1466 width: 55px;
1467 height: 55px;
1468 }
1469
1470 #".$this_poll_id." span.ayspoll-answers-votes-count-before-voting{
1471 padding: 10px !important;
1472 }
1473
1474 .$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{
1475 background-color: " . ($answer_hover_color ? $answer_hover_color : "initial") . " !important;
1476 color: $main_color !important;
1477 border-color: $main_color !important;
1478 font-weight: initial !important;
1479 margin:3px 0 !important;
1480 }
1481
1482 .$this_poll_id.ays-minimal-theme .apm-choosing input[type=radio]:checked + label *,
1483 .$this_poll_id.ays-minimal-theme .apm-choosing input[type=checkbox]:checked + label *,
1484 .$this_poll_id.ays-minimal-theme .apm-choosing label.ays_enable_hover:hover *{
1485 color: $main_color;
1486 }
1487
1488 .$this_poll_id.ays-minimal-theme .apm-choosing input[type=radio]{
1489 border-radius: 50%;
1490 width: 20px;
1491 height: 19px;
1492 margin: 3px !important;
1493 border: 1px solid #1e8cbe;
1494 opacity: 1;
1495 }
1496
1497 .$this_poll_id.ays-minimal-theme .apm-answers .apm-choosing input[type=radio]:checked::after{
1498 content: '';
1499 border-radius: 50%;
1500 width: 11px;
1501 height: 11px;
1502 background-color: #1e8cbe;
1503 }
1504
1505 .$this_poll_id.ays-minimal-theme .apm-choosing input[type=radio]:focus{
1506 outline-offset: 0 !important;
1507 outline: unset !important;
1508 }
1509
1510 .$this_poll_id.ays-minimal-theme .apm-choosing label{
1511 border-color: $text_color !important;
1512 font-weight: initial !important;
1513 margin:3px 0 !important;
1514 }
1515
1516 .$this_poll_id.ays-minimal-theme .apm-choosing input[type='radio']{
1517 display: block !important;
1518 }
1519
1520 .$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{
1521 text-decoration: none;
1522 }
1523
1524 .$this_poll_id.ays-minimal-theme input[type='button'].ays-poll-btn{
1525 color: initial !important;
1526 background: initial !important;
1527 border: 1px solid $text_color;
1528 border-radius: 3px;
1529 }
1530
1531 .$this_poll_id.ays-minimal-theme .ays_poll_passed_count{
1532 color: $text_color !important;
1533 background: initial !important;
1534 border: 1px solid $text_color;
1535 border-radius: 3px;
1536 }
1537
1538 .$this_poll_id.ays-minimal-theme .ays_poll_passed_count i.ays_poll_fa:before{
1539 color: $text_color !important;
1540 }
1541
1542 .$this_poll_id.ays-minimal-theme .answer-percent{
1543 color: initial !important;
1544 }
1545
1546 .$this_poll_id.box-apm span.ays_poll_passed_count{
1547 background-color: $text_color;
1548 color: $bg_color;
1549 }
1550
1551 #$this_poll_id.box-apm span.ays_poll_passed_count i{
1552 color: $bg_color;
1553 }
1554 #$this_poll_id.box-apm .apm-title-box{
1555 background-color: $title_bg_color;
1556 }
1557
1558 .$this_poll_id .answer-percent {
1559 background-color: $main_color;
1560 color: $bg_color !important;
1561 }
1562 .$this_poll_id .ays-poll-btn{
1563 color: $button_text_color !important;
1564 background-color: $button_bg_color !important;
1565 overflow: hidden;
1566 }
1567 #".$this_poll_id." .ays-poll-view-more-button{
1568 border-radius: 0;
1569 }
1570 .$this_poll_id.box-apm * {
1571 color: $text_color;
1572 }
1573 .$this_poll_id.box-apm .apm-title-box div {
1574 color: $text_color;
1575 text-transform: inherit;
1576 font-family: inherit;
1577 {$title_text_shadow}
1578 }
1579 #".$this_poll_id.".box-apm i {
1580 color: $icon_color;
1581 font-size: {$options['icon_size']}px;
1582 font-style: normal;
1583 }
1584
1585 #".$this_poll_id." .ays-poll-btn{
1586 width: " . $buttons_width . ";
1587 font-size: " . $buttons_font_size . ";
1588 padding: " . $buttons_top_bottom_padding . " " . $buttons_left_right_padding . ";
1589 border-radius: " . $buttons_border_radius . ";
1590 color: ". $poll_button_text_color ." !important;
1591 background: ". $button_bg_color ." !important;
1592 border: none;
1593 line-height: 12px !important;
1594 }
1595
1596 #".$this_poll_id ." .apm-add-answer input.ays-poll-new-answer-apply-text{
1597 width: 100%;
1598 margin-bottom: 0;
1599 margin-right: 5px;
1600 border-color: ".$main_color.";
1601 padding: 7px;
1602 font-size: 14px;
1603 color: black;
1604 height: 40px;
1605 outline: none;
1606 display: inline-block;
1607 }
1608
1609 #".$this_poll_id.".box-apm i.ays_poll_far{
1610 font-family: 'Font Awesome 5 Free';
1611 }
1612
1613 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-answer-list{
1614 width: initial;
1615 text-align: initial;
1616 display: initial;
1617 padding: 10px;
1618 }
1619
1620 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-answer-grid{
1621 width: 100%;
1622 text-align: left;
1623 display: inline-block;
1624 word-break: break-word;
1625 }
1626
1627
1628 #".$this_poll_id.".box-apm .apm-choosing .ays_label_poll{
1629 width: 100%;
1630 text-align: center;
1631 display: flex;
1632 $poll_direction_center;
1633 align-items: center;
1634 padding: ".$poll_answer_padding."px;
1635 }
1636
1637 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-image{
1638 height: ".$poll_answer_image_height."px;
1639 border-radius: ".$poll_answer_image_border_radius."px;
1640 object-fit: ".$poll_answer_object_fit.";
1641 }
1642
1643 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-image-list{
1644 width: 220px;
1645 }
1646
1647 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-image-grid{
1648 width: 100%;
1649 }
1650
1651
1652 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-answer-container-label-grid{
1653 align-items: center;
1654 }
1655
1656 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-answer-container-label-list{
1657 flex-direction: row;
1658 }
1659
1660 #".$this_poll_id.".box-apm .ays_poll_grid_view_container{
1661 display: flex;
1662 flex-wrap: wrap;
1663 justify-content: space-between;
1664 align-items: flex-start;
1665 }
1666
1667 #".$this_poll_id.".box-apm .ays-poll-answer-container-gird{
1668 width: calc(50% - 5px);
1669 margin-bottom: ".$poll_answer_margin."px;
1670 }
1671
1672 #".$this_poll_id.".box-apm .ays_poll_label_without_padding{
1673 padding: 10px;
1674 align-items: center;
1675 flex-direction: column;
1676 }
1677
1678 #".$this_poll_id.".box-apm .apm-title-box div{
1679 font-size: ".$poll_title_font_size."px;
1680 font-weight: ".$poll_title_font_weight.";
1681 word-break: break-word;
1682 word-wrap: break-word;
1683 text-align: ".$poll_title_alignment.";
1684 }
1685
1686 #".$this_poll_id.".box-apm .ays-poll-answer-container-list{
1687 margin-bottom: ".$poll_answer_margin."px;
1688 display: flex;
1689 width: 100%;
1690 }
1691
1692 #".$this_poll_id.".box-apm .ays-poll-maker-text-answer-main input,
1693 #".$this_poll_id.".box-apm .ays-poll-maker-text-answer-main textarea{
1694 min-width: 150px;
1695 max-width: 100%;
1696 width: ".$poll_text_type_ready_width.$poll_text_type_ready_type.";
1697 }
1698
1699 #".$this_poll_id.".box-apm .ays-poll-password-box .ays-poll-password-button-box .ays-poll-password-button{
1700 background-color: ".$main_color.";
1701 color: ".$bg_color.";
1702 border-color: ".$main_color.";
1703 outline: none;
1704 box-shadow: unset;
1705 border: 0;
1706 transition: .5s;
1707 }
1708
1709 #".$this_poll_id.".box-apm .ays-poll-password-box .ays-poll-password-button-box .ays-poll-password-button:hover{
1710 background-color: ".$main_color."b5;
1711 }
1712
1713 #".$this_poll_id.".box-apm .ays-poll-password-box .ays-poll-password-input-box .ays-poll-password-input{
1714 border-color: ".$main_color.";
1715 }
1716
1717 #".$this_poll_id.".box-apm .apm-answers .apm-choosing label.ays_label_poll{
1718 ".$answers_box_shadow_content.";
1719 border-radius: ".$poll_answer_border_radius."px;
1720 position: relative;
1721 }
1722
1723 #".$this_poll_id.".box-apm.text-poll .apm-answers .ays-poll-text-types-inputs{
1724 font-size: ".$poll_answer_font_size.";
1725 }
1726
1727 ";
1728
1729
1730 if(!$poll_theme){
1731 $content .= "#".$this_poll_id." div.apm-load-message-container{
1732 background-color: ".$bg_color." !important;
1733 }";
1734 }
1735 switch ($answer_border_side) {
1736 case 'none':
1737 $answer_border_type = "border: none";
1738 break;
1739 case 'all_sides':
1740 $answer_border_type = "border: 1px solid ".$main_color;
1741 break;
1742 case 'top':
1743 $answer_border_type = "border-top: 1px solid ".$main_color;
1744 break;
1745 case 'bottom':
1746 $answer_border_type = "border-bottom: 1px solid ".$main_color;
1747 break;
1748 case 'left':
1749 $answer_border_type = "border-left: 1px solid ".$main_color;
1750 break;
1751 case 'right':
1752 $answer_border_type = "border-right: 1px solid ".$main_color;
1753 break;
1754 default:
1755 $answer_border_type = "border: 1px solid ".$main_color;
1756 break;
1757 }
1758
1759 if ( $answer_style ) {
1760 $content .= "
1761 #".$this_poll_id.".choosing-poll label {
1762 background-color: $answer_bg_color;
1763 ".$answer_border_type.";
1764 text-transform: inherit;
1765 }";
1766 }
1767
1768 $content .= "
1769 .$this_poll_id.choosing-poll input[type=radio]:checked + label,
1770 .$this_poll_id:not(.ays-minimal-theme).choosing-poll input[type='checkbox']:checked + label,
1771 .$this_poll_id.choosing-poll label.ays_enable_hover:hover {
1772 background-color: " . ($answer_hover_color ? $answer_hover_color : $text_color) . " !important;
1773 color: $bg_color;
1774 }
1775
1776 .$this_poll_id:not(.ays-minimal-theme).choosing-poll input[type='checkbox']{
1777 display: none;
1778 }
1779 .$this_poll_id.choosing-poll input[type=radio]:checked + label *,
1780 .$this_poll_id.choosing-poll input[type=checkbox]:checked + label *,
1781 .$this_poll_id.choosing-poll label.ays_enable_hover:hover * {
1782 color: $answer_bg_color;
1783 }";
1784
1785 if ($poll_answer_icon_check) {
1786 $content .= "
1787 #".$this_poll_id.".choosing-poll label.ays_label_poll:not(.apm-label-with-bg) span.ays_grid_answer_span{
1788 display: inline-block;
1789 width: calc(100% - 10px);
1790 margin: 0 -15px;
1791 }
1792 #".$this_poll_id.".choosing-poll label.ays_label_poll span.ays_grid_answer_span{
1793 display: inline-block;
1794 width: calc(100% - 10px);
1795 }";
1796 }
1797
1798 if ($poll_answer_icon_check) {
1799 $content .=
1800 "#".$this_poll_id." label.ays_poll_answer_icon_radio:before,
1801 #".$this_poll_id." label.ays_poll_answer_icon_checkbox:before{
1802 content: '';
1803 display: inline-block;
1804 background: #ddd;
1805 background-clip: content-box;
1806 width: 20px;
1807 height: 20px;
1808 border: 3px solid #ccc;
1809 padding: 3px 3px 3px 3px;
1810 box-sizing: border-box;
1811 transition: all .4s linear;
1812 vertical-align: middle;
1813 margin-right: 10px;
1814 margin-bottom: 2px;
1815 }
1816
1817 #".$this_poll_id." label.ays_poll_answer_icon[for='poll_answer_icon_radio']:before,
1818 #".$this_poll_id." label.ays_poll_answer_icon_radio:before{
1819 border-radius: 50%;
1820 }
1821
1822 #".$this_poll_id." input[name='answer']:checked + label.ays_poll_answer_icon_radio:before,
1823 #".$this_poll_id." input[name='answer']:checked + label.ays_poll_answer_icon_checkbox:before{
1824 background: green;
1825 border: 3px solid green;
1826 padding: 3px 3px 3px 3px;
1827 background-clip: content-box;
1828 background-color: green !important;
1829 }";
1830 }
1831
1832
1833 $content .= ".$this_poll_id .apm-info-form input {
1834 border-color: $main_color;
1835 }
1836 div[class~=".$this_poll_id."] label.ays_label_font_size {
1837 font-size: $poll_answer_font_size;
1838 }
1839 button.ays-poll-next-btn:focus {
1840 background: unset;
1841 outline: none;
1842 }
1843 button.ays-poll-next-btn:disabled {
1844 cursor: not-allowed;
1845 background: dimgrey !important;
1846 color: white !important;
1847 }
1848 button.ays-poll-next-btn:enabled {
1849 cursor: pointer;
1850 }
1851 .$this_poll_id .apm-info-form input {
1852 color: $text_color !important;
1853 background-color: $answer_bg_color !important;
1854 }
1855
1856 .ays-poll-main #".$this_poll_id." .ays-poll-img {
1857 object-fit: ".$poll_question_image_object_fit.";
1858 height: ".$poll_question_image_height.";
1859 }
1860
1861 .$this_poll_id div.apm-loading-gif .apm-loader svg path,
1862 .$this_poll_id div.apm-loading-gif .apm-loader svg rect {
1863 fill: $main_color;
1864 }" . (isset($load_gif) && $load_gif == 'plg_4' ?
1865 ".$this_poll_id div.apm-loading-gif .apm-loader svg {
1866 stroke: $main_color;
1867 }
1868
1869 .$this_poll_id.choosing-poll .ays_poll_cb_and_a,
1870 .$this_poll_id.choosing-poll .ays_poll_cb_and_a * {
1871 color: " . $this->hex2rgba($text_color) . ";
1872 }
1873
1874 .ays_poll_category-container{
1875 width: '".$poll_width."',
1876 maxWidth: '98%',
1877 fontSize: '16px',
1878 padding: '10px',
1879 margin: '0 auto',
1880 marginTop: '-1rem',
1881 borderStyle: '{$options['border_style']}',
1882 borderWidth: '2px',
1883 borderColor: '$main_color',
1884 background: '$bg_color',
1885 color: '$main_color',
1886 transition: '.3s ease',
1887 WebkitAppearance: 'none',
1888 appearance: 'none',
1889 }
1890
1891 .$this_poll_id div.apm-loading-gif .apm-loader svg>g {
1892 fill: $bg_color;
1893 }"
1894 : "")
1895 . "{$poll['custom_css']}";
1896 if($poll_loader_font_size != ''){
1897 $content .= ".$this_poll_id div.apm-loading-gif .apm-loader{
1898 display: flex;
1899 justify-content: center;
1900 align-items: center;
1901 padding-top: 10px;
1902 }
1903 .$this_poll_id div.apm-loading-gif{
1904 width: 100%;
1905 height: 100%;
1906 }
1907 ";
1908 }
1909
1910 $content .= ".$this_poll_id.box-apm .ays_question p{
1911 font-size: ".$poll_question_font_size_pc."px;
1912 }
1913
1914 @media only screen and (max-width: 768px){
1915 #".$this_poll_id.".box-apm {
1916 width: $poll_width_for_mobile;
1917 }
1918
1919 #".$this_poll_id.".box-apm .ays-poll-btn{
1920 width: ".$buttons_mobile_width.";
1921 }
1922
1923 .$this_poll_id.box-apm .ays_question p{
1924 font-size: ".$poll_question_font_size_mobile."px;
1925 }";
1926
1927 if ($answers_grid_column_mobile) {
1928 $content .= "
1929 .".$this_poll_id." .apm-answers .apm-rating i.ays_poll_fa-star {
1930 font-size: 4vw !important;
1931 }
1932 #".$this_poll_id.".box-apm .ays-poll-answer-container-gird{
1933 width: 100%;
1934 }";
1935 }
1936
1937 $content .= "
1938 #".$this_poll_id.".box-apm .apm-title-box div{
1939 font-size: ".$poll_title_font_size_mobile."px;
1940 font-weight: ".$poll_title_font_weight_mobile.";
1941 text-align: ".$poll_title_alignment_mobile.";
1942 word-break: break-word;
1943 word-wrap: break-word;
1944 }
1945
1946 .$this_poll_id.box-apm label.ays_label_font_size {
1947 font-size: ".$poll_answer_font_size_mobile."px;
1948 }
1949
1950 #".$this_poll_id.".box-apm.text-poll .apm-answers .ays-poll-text-types-inputs{
1951 font-size: ".$poll_answer_font_size_mobile."px;
1952 }
1953
1954 #".$this_poll_id.".box-apm .apm-answers > .apm-choosing > .ays_label_poll > div.ays-poll-answer-image > img.ays-poll-each-image{
1955 height: ".$poll_answer_image_height_for_mobile."px;
1956 }
1957
1958 #".$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 {
1959 padding: unset;
1960 word-wrap: break-word;
1961 }
1962
1963 #".$this_poll_id." .ays-poll-btn{
1964 font-size: " . $poll_buttons_mobile_font_size . ";
1965 line-height: 1;
1966 white-space: normal;
1967 word-break: break-word;
1968 }
1969 }
1970
1971 @media screen and (max-width: 768px){
1972 #".$this_poll_id."{
1973 max-width: ".$poll_mobile_max_width.";
1974 }
1975 }
1976
1977 #ays-poll-container-" . $id . "{
1978 width: $poll_width;
1979 }
1980
1981 @media screen and (max-width: 768px){
1982 #ays-poll-container-" . $id . "{
1983 width: ".$poll_width_for_mobile.";
1984 max-width: 96%;
1985 }
1986
1987 #".$this_poll_id.".box-apm .apm-choosing .ays-poll-each-image-list{
1988 width: 100%;
1989 }
1990 }
1991
1992 ";
1993
1994
1995 $content .= "
1996 </style>
1997 <script>
1998 var dataCss = {
1999 width: '".$poll_width."',
2000 maxWidth: '98%',
2001 fontSize: '16px',
2002 padding: '10px',
2003 margin: '0 auto',
2004 marginTop: '-1rem',
2005 borderStyle: '{$options['border_style']}',
2006 borderWidth: '2px',
2007 borderColor: '$main_color',
2008 background: '$bg_color',
2009 color: '$main_color',
2010 transition: '.3s ease',
2011 WebkitAppearance: 'none',
2012 appearance: 'none',
2013 };
2014 var hoverCss = {
2015 background: '$main_color',
2016 color: '$bg_color',
2017 borderColor: '$bg_color',
2018 };
2019 </script>";
2020
2021 if ($poll_direction == 'center') {
2022 $poll_direction_center = "style='text-align: center;'";
2023 $poll_direction = 'ltr';
2024 }else{
2025 $poll_direction_center = "";
2026 }
2027
2028 // AV Show login form for not logged in users
2029 $options['show_login_form'] = isset($options['show_login_form']) ? $options['show_login_form'] : 'off';
2030 $show_login_form = (isset($options['show_login_form']) && $options['show_login_form'] == "on") ? true : false;
2031 $add_form = $show_login_form && !is_user_logged_in() ? "" : "<form style='margin-bottom: 0;' ".$form_method.">";
2032
2033 if(isset($options['show_create_date']) && $options['show_create_date'] == 1){
2034 $show_create_date = true;
2035 }else{
2036 $show_create_date = false;
2037 }
2038
2039 if(isset($options['show_author']) && $options['show_author'] == 1){
2040 $show_author = true;
2041 }else{
2042 $show_author = false;
2043 }
2044
2045 //Enabled ansers sound
2046 $enable_asnwers_sound = isset($options['enable_asnwers_sound']) && $options['enable_asnwers_sound'] == 'on' ? true : false;
2047 $answers_sound = '';
2048 $answers_sound_class = '';
2049 $answers_sound_mute = '';
2050 if ($enable_asnwers_sound) {
2051
2052 $settings_options = ($poll_settings->ays_get_setting('options') === false) ? json_encode(array()) : $poll_settings->ays_get_setting('options');
2053 $setting_options = json_decode($settings_options, true);
2054 $answers_sound_path = isset($setting_options['answers_sound']) && !empty($setting_options['answers_sound']) ? $setting_options['answers_sound'] : false;
2055
2056 if ($answers_sound_path != false) {
2057 $answers_sound = "<audio id='ays_poll_ans_sound_".$id."' class='ays_poll_ans_sound' src='".$answers_sound_path."'></audio>";
2058 $answers_sound_class = 'poll_answers_sound';
2059 $answers_sound_mute = "<span class='ays_music_sound ays_sound_active'><i class='ays_poll_far ays_poll_fa-volume_up'></i></span>";
2060
2061 }
2062 }
2063
2064 //AV show timer
2065 $activeDateCheck = isset($options['active_date_check']) && !empty($options['active_date_check']) ? true : false;
2066 $activeDeactiveDateCheck = isset($options['deactiveInterval']) && !empty($options['deactiveInterval']) ? true : false;
2067 $activeActiveDateCheck = isset($options['activeInterval']) && !empty($options['activeInterval']) ? true : false;
2068 $show_timer_type = isset($options['ays_show_timer_type']) && !empty($options['ays_show_timer_type']) ? $options['ays_show_timer_type'] : 'countdown';
2069 $show_bottom_timer = isset($options['show_bottom_timer']) && 1 == $options['show_bottom_timer'] ? 1 : 0;
2070
2071 $show_timer = '';
2072 if ( $activeDateCheck && $activeDeactiveDateCheck && !$is_start_soon) {
2073 if (isset($options['ays_poll_show_timer']) && $options['ays_poll_show_timer'] == 1) {
2074 $show_timer .= "<div class='ays_poll_show_timer'>";
2075 if ($show_timer_type == 'countdown') {
2076 if ($endDate_atr > 0) {
2077 $show_timer .= '<p class="show_timer_countdown" data-timer_countdown="'.$endDate_atr.'"></p>';
2078 }
2079 }else if ($show_timer_type == 'enddate') {
2080 $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>';
2081 }
2082 $show_timer .= "</div>";
2083 }
2084 }elseif ($activeDateCheck && $activeActiveDateCheck && $is_start_soon) {
2085 if (isset($options['ays_poll_show_timer']) && $options['ays_poll_show_timer'] == 1) {
2086 $show_timer .= "<div class='ays_poll_show_timer'>";
2087 if ($show_timer_type == 'countdown') {
2088 $show_timer .= '<p class="show_timer_countdown" data-timer_countdown="'.$startDate_atr.'"></p>';
2089 }else if ($show_timer_type == 'enddate') {
2090 $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>';
2091 }
2092 $show_timer .= "</div>";
2093 }
2094 }
2095
2096 $show_cd_and_author = "<div class='ays_poll_cb_and_a'>";
2097 if($show_create_date){
2098 $poll_create_date = (isset($options['create_date']) && $options['create_date'] != '') ? $options['create_date'] : "0000-00-00 00:00:00";
2099 if(Poll_Maker_Ays_Admin::validateDate($poll_create_date)){
2100 $show_cd_and_author .= "<span>". esc_html__("Created on", "poll-maker")." </span><strong><time>".date("F d, Y", strtotime($poll_create_date))."</time></strong>";
2101 }else{
2102 $show_cd_and_author .= "";
2103 }
2104 }
2105
2106 if($show_author){
2107 if(isset($options['author'])){
2108 if(is_array($options['author'])){
2109 $author = $options['author'];
2110 }else{
2111 $author = json_decode($options['author'], true);
2112 }
2113 }else{
2114 $author = array("name"=>"Unknown");
2115 }
2116 $user_id = 0;
2117 if(isset($author['id']) && intval($author['id']) != 0){
2118 $user_id = intval($author['id']);
2119 }
2120 $image = get_avatar($user_id, 32);
2121 if(isset( $author['name'] ) && $author['name'] !== "Unknown"){
2122 if($show_create_date){
2123 $text =esc_html__("By", "poll-maker");
2124 }else{
2125 $text =esc_html__("Created by", "poll-maker");
2126 }
2127 $show_cd_and_author .= "<span> ".$text." </span>".$image."<strong>".$author['name']."</strong>";
2128 }else{
2129 $show_cd_and_author .= "";
2130 }
2131 }
2132
2133 $show_cd_and_author .= "</div>";
2134
2135 // Show votes count per answers before voting
2136 $options['show_votes_before_voting'] = isset($options['show_votes_before_voting']) ? $options['show_votes_before_voting'] : 'off';
2137 $show_votes_before_voting = (isset($options['show_votes_before_voting']) && $options['show_votes_before_voting'] == 'on') ? true : false;
2138 $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';
2139
2140 $poll_login_form = "";
2141 if($show_login_form){
2142 $args = array(
2143 'echo' => false,
2144 'form_id' => 'ays_loginform_'.$this_poll_id,
2145 'id_username' => 'ays_user_login_'.$this_poll_id,
2146 'id_password' => 'ays_user_pass_'.$this_poll_id,
2147 'id_remember' => 'ays_rememberme_'.$this_poll_id,
2148 'id_submit' => 'ays-submit_'.$this_poll_id
2149 );
2150 $poll_login_form = "<div class='ays_poll_login_form'>" . wp_login_form( $args ) . "</div>";
2151 }
2152
2153 $poll_user_information = $this->get_user_profile_data();
2154 $user_first_name = (isset( $poll_user_information['user_first_name'] ) && $poll_user_information['user_first_name'] != "") ? $poll_user_information['user_first_name'] : '';
2155 $user_last_name = (isset( $poll_user_information['user_last_name'] ) && $poll_user_information['user_last_name'] != "") ? $poll_user_information['user_last_name'] : '';
2156 $creation_date = (isset( $poll['styles']['create_date'] ) && $poll['styles']['create_date'] != '') ? $poll['styles']['create_date'] : '';
2157
2158 $current_poll_author = esc_html__( "Unknown", "poll-maker" );
2159 if( !empty($options['author']) ){
2160 if( !is_array($options['author']) ){
2161 $options['author'] = json_decode($options['author'], true);
2162 }
2163
2164 $poll_current_author = (isset($options['author']['id']) && $options['author']['id'] != "") ? absint(sanitize_text_field( $options['author']['id'] )) : "";
2165
2166 $current_poll_user_data = get_userdata( $poll_current_author );
2167 if ( ! is_null( $current_poll_user_data ) && $current_poll_user_data ) {
2168 $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 ) : "";
2169 }
2170 }
2171
2172 $user_nickname = '';
2173 $user_first_name = '';
2174 $user_display_name = '';
2175 $user_wordpress_email = '';
2176 $user_wordpress_roles = '';
2177 $user_wordpress_website = '';
2178 $user_ip_address = '';
2179 $user_id = get_current_user_id();
2180 if($user_id != 0){
2181 $usermeta = get_user_meta( $user_id );
2182 if($usermeta !== null){
2183 $user_nickname = (isset($usermeta['nickname'][0]) && sanitize_text_field( $usermeta['nickname'][0] != '') ) ? sanitize_text_field( $usermeta['nickname'][0] ) : '';
2184 $user_first_name = (isset($usermeta['first_name'][0]) && sanitize_text_field( $usermeta['first_name'][0] != '') ) ? sanitize_text_field( $usermeta['first_name'][0] ) : '';
2185 }
2186
2187 $current_user_data = get_userdata( $user_id );
2188 if ( ! is_null( $current_user_data ) && $current_user_data ) {
2189 $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 ) : "";
2190 $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 ) : "";
2191
2192 $user_wordpress_roles = ( isset( $current_user_data->roles ) && ! empty( $current_user_data->roles ) ) ? $current_user_data->roles : "";
2193 $user_ip_address = $this->get_user_ip_validated();
2194
2195 if ( !empty( $user_wordpress_roles ) && $user_wordpress_roles != "" ) {
2196 if ( is_array( $user_wordpress_roles ) ) {
2197 $user_wordpress_roles = implode(",", $user_wordpress_roles);
2198 }
2199 }
2200
2201 $user_wordpress_website_url = ( isset( $current_user_data->user_url ) && ! empty( $current_user_data->user_url ) ) ? sanitize_url($current_user_data->user_url) : "";
2202
2203 if( !empty( $user_wordpress_website_url ) ){
2204 $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>";
2205 }
2206 }
2207 }
2208
2209 $report_table = $wpdb->prefix."ayspoll_reports";
2210 $answ_table = $wpdb->prefix."ayspoll_answers";
2211
2212 $result_message = isset($options['hide_result_message']) && $options['hide_result_message'] == 1 ? "<div class='apm-title-box ays_res_mess'>" . " " . "</div>" : "";
2213
2214 $custom_class = isset($options['custom_class']) && $options['custom_class'] != '' ? $options['custom_class'] : "";
2215
2216 $content .= "<div style='margin-bottom: 1rem;' class='ays-poll-main ".$custom_class."' id='ays-poll-container-" . $id . "' data-load-method='".$poll_see_result_immediately."'>
2217 ".$add_form."
2218 ".$answers_sound."
2219 <div
2220 $poll_direction_center
2221 dir='$poll_direction'
2222 data-loading='$load_effect'
2223 data-load-gif='$load_gif'
2224 data-load-gif-font-size='$poll_loader_font_size'
2225 ".$poll_load_message_data."
2226 data-hide-bg-image='$poll_bg_img_in_finish_page'
2227 data-gradient-check='$enable_background_gradient'
2228 data-gradient-dir='$poll_gradient_direction'
2229 data-gradient-c1='$background_gradient_color_1'
2230 data-gradient-c2='$background_gradient_color_2'
2231 data-hide-bg-image-def-color='$poll_bg_img_in_finish_page_off_color'
2232 data-show-social='$show_social'
2233 class='box-apm $poll_theme {$poll['type']}-poll $this_poll_id '
2234 id='$this_poll_id'
2235 data-res='$hide_results'
2236 data-res-sort='$result_sort'
2237 data-restart ='" . (isset($options['enable_restart_button']) && $options['enable_restart_button'] ? 'true' : 'false') . "'
2238 data-redirection = '$redirect_users'
2239 data-redirect-check = '".$redirect_url_checked."'
2240 data-url-href = '".$redirect_url_href."'
2241 data-href = '$redirect_after_vote_url'
2242 data-delay = '$redirect_delay'
2243 data-id='{$poll['id']}'
2244 data-res-rgba = '". $result_in_rgba ."'
2245 data-percent-color = '". $answer_percent_color ."'
2246 data-enable-top-animation = '". $poll_enable_animation_top ."'
2247 data-top-animation-scroll = '". $poll_animation_top ."'
2248 data-info-form='$info_form'
2249 data-enable-social-links='$enable_social_links'
2250 >" . $poll_result_reports;
2251
2252 if($poll_enable_password && !$poll_password_check && !$is_expired && !$poll_check_only_logged){
2253 $content .= $poll_password_box;
2254 echo $content;
2255 return;
2256 }
2257
2258 $poll_question_image = isset($poll['image']) && $poll['image'] != '' ? esc_url($poll['image']): '';
2259 // if ($poll_question_image != '') {
2260 // if ( !(filter_var($poll_question_image, FILTER_VALIDATE_URL) && wp_http_validate_url($poll_question_image)) ) {
2261 // // invalid URL, handle accordingly
2262 // $poll_question_image = '';
2263 // }
2264 // }
2265 if( $poll_question_image != "" ){
2266 $check_if_current_image_exists = Poll_Maker_Ays_Admin::ays_poll_check_if_current_image_exists($poll_question_image);
2267
2268 if( !$check_if_current_image_exists ){
2269 $poll_question_image = "";
2270 }
2271 }
2272 $poll_question_image_alt_text = Poll_Maker_Data::ays_poll_get_image_id_by_url($poll_question_image);
2273
2274 $content .= $show_cd_and_author;
2275 if ( $activeDateCheck && $activeDeactiveDateCheck && !$show_bottom_timer){
2276 $content .= $show_timer;
2277 }
2278 $content .= $poll_image_cont;
2279 $content .= $answers_sound_mute;
2280 $content .= ($poll['show_title'] == 1) ? "<div class='apm-title-box'><div>" . stripslashes($poll['title']) . "</div></div>" : "";
2281 $content .= "<div class='$this_poll_id ays_question'>" . do_shortcode(wpautop(stripslashes($poll['question']))) . "</div>";
2282 $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>" : "";
2283 $content .= "<div class='$this_poll_id hideResults ays-poll-hide-result-box'>" . " " . "</div>";
2284 if(($is_expired || $is_start_soon) && $poll_check_exp_cont){
2285 $content = "";
2286 return $content;
2287 }
2288 if (!$is_expired) {
2289 //CHECK IF ENABLED ONLY LOGGED IN USERS OPTION
2290 if (isset($options['enable_logged_users']) && $options['enable_logged_users'] == 1 && !is_user_logged_in()) {
2291 $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
2292
2293 $content .= "<div class='apm-need-sign-in'>".$logged_users_message."</div>";
2294
2295 if($logged_users_message !== null){
2296 if(!is_user_logged_in()){
2297 $content .= "<div class='apm-need-sign-in'>".$poll_login_form."</div>";
2298 }
2299 }
2300 } else {
2301 $load_poll = true;
2302 if (isset($options['enable_restriction_pass']) && $options['enable_restriction_pass'] == 1) {
2303 // Users role Aro start
2304 global $wp_roles;
2305 $user = wp_get_current_user();
2306 $users_roles = $wp_roles->role_names;
2307 $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>");
2308 $users_role = (isset($options['users_role']) && $options['users_role'] != '') ? $options['users_role'] : '';
2309 $users_role = json_decode($users_role);
2310 if(!empty($users_role)){
2311 if (is_array($users_role)) {
2312 foreach($users_role as $key => $role){
2313 if(in_array($role, $users_roles)){
2314 $users_role[$key] = array_search($role, $users_roles);
2315 }
2316 }
2317 }else{
2318 if(in_array($users_role, $users_roles)){
2319 $users_role = array_search($users_role, $users_roles);
2320 }
2321 }
2322 $is_user_role = false;
2323 if(is_array($users_role)){
2324 foreach($users_role as $role){
2325 if (in_array(strtolower($role), (array)$user->roles)) {
2326 $is_user_role = true;
2327 break;
2328 }
2329 }
2330 }else{
2331 if (in_array(strtolower($users_role), (array)$user->roles)) {
2332 $is_user_role = true;
2333 }
2334 }
2335
2336 if (!$is_user_role) {
2337 $content .= "<div class='ays-poll-limitation'>$message</div>";
2338 $load_poll = false;
2339 }
2340 }
2341 //Aro end
2342 }
2343 if ($load_poll) {
2344 $limit_users = 0;
2345 global $wpdb;
2346 if ($limitusers) {
2347 $report_table = esc_sql($wpdb->prefix."ayspoll_reports");
2348 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
2349 if ((!empty($options['limit_users_method']) && $options['limit_users_method'] == 'ip') || empty($options['limit_users_method'])) {
2350 // $user_ips = $this->get_user_ip();
2351 // $user_ip = esc_sql($user_ips);
2352 // $args_ip = array($user_ip,$id);
2353 // $args_tables = array(
2354 // 'reports_table' => $report_table,
2355 // 'answer_table' => $answ_table
2356 // );
2357 $limit_users = $this->ays_poll_get_limit_user_count_by_ip($id);
2358 if (isset($_COOKIE['ays_this_poll_cookie_'.$id])) {
2359 unset($_COOKIE['ays_this_poll_cookie_'.$id]);
2360 setcookie('ays_this_poll_cookie_'.$id, null,time() -1, '/');
2361 }
2362 }
2363 elseif((isset($options['limit_users_method']) && $options['limit_users_method'] == 'cookie')){
2364 $cookie_name = "ays_this_poll_cookie_".$poll_id;
2365 if(isset($_COOKIE[$cookie_name])){
2366 $limit_users = 1;
2367 }
2368 }
2369 elseif((isset($options['limit_users_method']) && $options['limit_users_method'] == 'cookie_ip')){
2370 $cookie_name = "ays_this_poll_cookie_".$poll_id;
2371 $limit_users_check = $this->ays_poll_get_limit_user_count_by_ip($id);
2372 if(isset($_COOKIE[$cookie_name]) || $limit_users_check > 0){
2373 $limit_users = 1;
2374 }
2375 elseif(!isset($_COOKIE[$cookie_name]) || $limit_users_check > 0){
2376 $limit_users = $this->ays_poll_get_limit_user_count_by_ip($id);
2377 }
2378 }
2379 else {
2380 $user_id = is_user_logged_in() ? wp_get_current_user()->ID : 0;
2381 $args_id = array($user_id, $id);
2382 $sql = "SELECT COUNT(*)
2383 FROM ".$report_table."
2384 JOIN ".$answ_table."
2385 ON ".$answ_table.".id = ".$report_table.".answer_id
2386 WHERE ".$report_table.".user_id = %d
2387 AND ".$answ_table.".poll_id = %d";
2388 if ($user_id > 0) {
2389 $limit_users = $wpdb->get_var(
2390 $wpdb->prepare( $sql, $args_id)
2391 );
2392 }else{
2393 $limit_users = 0;
2394 }
2395 if (isset($_COOKIE['ays_this_poll_cookie_'.$id])) {
2396 unset($_COOKIE['ays_this_poll_cookie_'.$id]);
2397 setcookie('ays_this_poll_cookie_'.$id, null,time() -1, '/');
2398 }
2399 }
2400 }
2401 else{
2402 if (isset($_COOKIE['ays_this_poll_cookie_'.$id])) {
2403 unset($_COOKIE['ays_this_poll_cookie_'.$id]);
2404 setcookie('ays_this_poll_cookie_'.$id, null,time() -1, '/');
2405 }
2406 }
2407 $poll_allow_multivote = isset($options['poll_allow_multivote']) && $options['poll_allow_multivote'] == 'on' ? true : false;
2408 $poll_multivote_checkbox = $poll_allow_multivote ? 'checkbox' : 'radio';
2409 $autocomplete_attr = $poll_multivote_checkbox == 'checkbox' ? '' : 'autocomplete="off"';
2410
2411 $poll_multivote_min_count = '';
2412 $poll_multivote_min_count_content = '';
2413 $multivote_answer_count = '';
2414 $allow_multivote_answer = '';
2415 $poll_multivote_message_content = '';
2416 if($poll_allow_multivote){
2417 $multivote_answer_count = (isset($options['poll_allow_multivote_count']) && $options['poll_allow_multivote_count'] != '') ? absint(intval($options['poll_allow_multivote_count'])) : '1';
2418 $multiple_select = 'multiple';
2419 $allow_multivote_answer = 'on';
2420 $poll_multivote_min_count = (isset($options['multivote_answer_min_count']) && $options['multivote_answer_min_count'] != '') ? absint(intval($options['multivote_answer_min_count'])) : '1';
2421 $poll_multivote_min_count_content = "<input type='hidden' id='ays_poll_multivote_min_count' data-allow='true' value='".$poll_multivote_min_count."'/>";
2422 $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>";
2423 }else{
2424 $multiple_select = '';
2425 $allow_multivote_answer = '';
2426 }
2427 if ($limit_users == 0) {
2428
2429 $view_more_button_flag = false;
2430 if (isset($poll['type']) && $poll['type'] == 'choosing') {
2431 if ($enable_view_more_button) {
2432 if ( $poll_view_more_button_count != 0 && $poll_view_more_button_count < count($poll['answers']) ) {
2433 $view_more_button_flag = true;
2434 }
2435 }
2436 }
2437
2438 if ($poll_answer_icon_check && $poll_theme != 'ays-minimal-theme') {
2439 switch ($poll_answer_icon) {
2440 case 'radio':
2441 $answer_icon_class = 'ays_poll_answer_icon_radio';
2442 break;
2443 case 'checkbox':
2444 $answer_icon_class = 'ays_poll_answer_icon_checkbox';
2445 break;
2446 default:
2447 $answer_icon_class = '';
2448 break;
2449 }
2450 }else{
2451 $answer_icon_class = '';
2452 }
2453
2454 $poll_answer_votes = null;
2455 $poll_answer_votes_sum = null;
2456 $content .= "<div class='apm-answers $without_vote ".$answers_container."'>";
2457 switch ( $poll['type'] ) {
2458 case 'choosing':
2459 $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";
2460 $randomize_answers = (isset($poll['styles']['randomize_answers']) && $poll['styles']['randomize_answers'] == 'on') ? true : false;
2461 $redirect_after_submit = (isset($poll['styles']['redirect_after_submit']) && $poll['styles']['redirect_after_submit'] == 1) ? 'redirect-after-vote-url' : '';
2462
2463 $numbering_type = "";
2464 if ($randomize_answers) {
2465 shuffle($poll['answers']);
2466 }
2467 $answers_count = isset($poll['answers']) && $poll['answers'] != '' ? count($poll['answers']) : false;
2468 $numbering_type_arr = array();
2469 if($answers_count){
2470 $numbering_type_arr = $this->ays_answer_numbering($show_answers_numbering , $answers_count);
2471 }
2472
2473 $poll_answer_percentages = array();
2474 $poll_answer_votes = array();
2475 foreach ( $poll['answers'] as $index => $answer ) {
2476 // if($fake_votes){
2477 // if(intval( $answer['votes'] ) + intval( $answer['fake_votes'] ) < 0){
2478 // $poll_answer_votes[$answer['id']] = intval( $answer['votes'] );
2479 // }
2480 // else{
2481 // $poll_answer_votes[$answer['id']] = intval( $answer['votes'] ) + intval( $answer['fake_votes'] );
2482 // }
2483 // }
2484 // else{
2485 $poll_answer_votes[$answer['id']] = intval( $answer['votes'] );
2486 // }
2487 }
2488
2489 $poll_answer_votes_sum = array_sum( $poll_answer_votes );
2490 $poll_answer_percentages = array();
2491 foreach ( $poll_answer_votes as $index => $answer_vote_count ) {
2492 if( $poll_answer_votes_sum != 0 ){
2493 $poll_answer_percentages[$index] = round( ( $answer_vote_count * 100 ) / $poll_answer_votes_sum, 1);
2494 }else{
2495 $poll_answer_percentages[$index] = 0;
2496 }
2497 }
2498
2499 // $show_votes_count = isset($options['show_votes_count']) && $options['show_votes_count'] == 1 ? true : false;
2500 // $show_answer_percent = isset($options['show_res_percent']) && $options['show_res_percent'] == 1 ? true : false;
2501
2502 if($poll_allow_multivote){
2503 $content .= "<input type='hidden' id='multivot_answer_count' value='".$multivote_answer_count."'/>";
2504 $content .= $poll_multivote_min_count_content;
2505 }
2506 foreach ( $poll['answers'] as $index => $answer ) {
2507 if ($answer['user_added'] == 1 && $answer['show_user_added'] == 0) {
2508 continue;
2509 }
2510 else{
2511 if ($answer['show_user_added'] == 0){
2512 continue;
2513 }
2514 else{
2515 if(!empty($numbering_type_arr)){
2516 $numbering_type = isset($numbering_type_arr[$index]) && $numbering_type_arr[$index] != "" ? $numbering_type_arr[$index] : "";
2517 $numbering_type = $numbering_type . " ";
2518 }
2519 $answer_style_class = '';
2520 if ($view_more_button_flag) {
2521 if ($poll_view_more_button_count - 1 < $index) {
2522 $answer_style_class = 'ays_poll_display_none';
2523 }
2524 }
2525
2526 $show_votes_before_voting_display_none = "";
2527 if( !$show_votes_before_voting ){
2528 $show_votes_before_voting_display_none = "display:none;";
2529 }
2530 $opacity_bg_color_svbv = $poll['view_type'] == 'grid' ? 0.6 : 0.3;
2531 $show_votes_before_voting_color = $this->rgb2hex( $text_color );
2532 $show_votes_before_voting_color = $this->hex2rgba( $show_votes_before_voting_color, $opacity_bg_color_svbv );
2533
2534 $show_votes_before_voting_display = "style='text-shadow: 0px 0px 5px " . $bg_color . ";'";
2535 $show_votes_before_voting_display_width = "";
2536 if( !$show_votes_before_voting ){
2537 $show_votes_before_voting_display = "style='{$show_votes_before_voting_display_none}text-shadow: 0px 0px 5px " . $bg_color . ";'";
2538 $show_votes_before_voting_display_width = "style='{$show_votes_before_voting_display_none}text-shadow: 0px 0px 5px " . $bg_color . ";'";
2539 }
2540
2541 if( $poll['view_type'] == 'grid' ){
2542 $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 . ";'";
2543 $show_votes_before_voting_display_width = "style='{$show_votes_before_voting_display_none}text-shadow: 0px 0px 5px " . $bg_color . ";'";
2544 }
2545
2546 $pol_answer_view_type_show = 'ays_poll_list_view_item';
2547 $pol_answer_view_type_image = 'ays-poll-each-image-list';
2548 $pol_answer_view_type_cont = 'ays-poll-answer-container-list';
2549 $pol_answer_view_type_label_cont = 'ays-poll-answer-container-label-list';
2550 if($pol_answer_view_type == "grid"){
2551 $pol_answer_view_type_label_cont = 'ays-poll-answer-container-label-grid';
2552 $pol_answer_view_type_cont = 'ays-poll-answer-container-gird';
2553 $pol_answer_view_type_show = 'ays_poll_grid_view_item';
2554 $pol_answer_view_type_image = 'ays-poll-each-image-grid';
2555 }
2556
2557 $poll_answer_image = isset($answer['answer_img']) && $answer['answer_img'] != "" ? esc_attr($answer['answer_img']) : "";
2558 $poll_added_style = "";
2559 if($poll_answer_image && $answer_view_type == 'list'){
2560 $poll_added_style = "max-width: calc(100% - 220px);";
2561
2562 }
2563 $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>" : "";
2564 $poll_class_for_answer_label = "";
2565 $poll_class_for_answer_label_text = "";
2566
2567 $pol_answer_view_type_text_show = 'ays-poll-each-answer-grid';
2568 if($poll_answer_image){
2569 $poll_class_for_answer_label = "ays_poll_label_without_padding";
2570 $pol_answer_view_type_text_show = 'ays-poll-each-answer-list';
2571
2572 $poll_class_for_answer_label_text = "ays_poll_label_text_with_padding";
2573 }
2574
2575 $answer_votes_count_before_voting = "";
2576 switch ( $show_votes_before_voting_by ) {
2577 case 'by_percentage':
2578 $answer_votes_count_before_voting = $poll_answer_percentages[$answer['id']] . "%";
2579 // if( $show_votes_count ){
2580 // $answer_votes_count_before_voting .= " (". intval( $answer['votes'] ) .")";
2581 // }
2582 break;
2583 default:
2584 $real_votes = isset($answer['votes']) && $answer['votes'] != "" ? intval( $answer['votes'] ) : 0;
2585 // $fake_votes_all = isset($answer['fake_votes']) && $answer['fake_votes'] != "0" ? intval( $answer['fake_votes'] ) : 0;
2586 // if($fake_votes){
2587 // if($real_votes + $fake_votes_all < 0){
2588 // $answer_votes_count_before_voting = $real_votes;
2589 // }
2590 // else{
2591 // $answer_votes_count_before_voting = $real_votes + $fake_votes_all;
2592 // }
2593 // }
2594 // else{
2595 $answer_votes_count_before_voting = $real_votes;
2596 // }
2597 // if( $show_answer_percent ){
2598 // $answer_votes_count_before_voting .= " (". $poll_answer_percentages[$answer['id']] . "%" .")";
2599 // }
2600 break;
2601 }
2602
2603 $content .= "
2604 <div class='apm-choosing answer-$this_poll_id ". $answer_style_class ." ays-poll-field ".$pol_answer_view_type_cont."' >
2605 <input type=".$poll_multivote_checkbox." name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}' {$autocomplete_attr}>
2606 <label
2607 for='radio-$index-$this_poll_id'
2608 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."'
2609 data-answers-url='".(isset($answer['redirect']) && is_string($answer['redirect']) ? esc_url($answer['redirect']) : '')."'
2610 >".$poll_answer_image_show." <p style='".$poll_added_style."' class='ays-poll-answers'><span class='".$pol_answer_view_type_text_show."'>"
2611 . $numbering_type . esc_attr(stripcslashes($answer['answer'])) .
2612 "</span></p>";
2613
2614 $content .= "<span class='ayspoll-answers-votes-count-before-voting' ". $show_votes_before_voting_display .">". $answer_votes_count_before_voting ."</span>
2615 <span class='ayspoll-answers-votes-count-before-voting-width' ". $show_votes_before_voting_display_width .">
2616 <span style='width: ". $poll_answer_percentages[$answer['id']] ."%; background-color:" . $show_votes_before_voting_color . ";'></span>
2617 </span>";
2618
2619 $content .= " </label>
2620 </div>";
2621 }
2622 }
2623 }
2624 $add_answer_for_grid = isset($poll['view_type']) && $poll['view_type'] == 'grid' ? 'add_answer_for_grid' : '';
2625 if ($poll_allow_answer && $with_vote) {
2626 $content .= "
2627 <div class='apm-choosing answer-$this_poll_id ".$this_poll_id."_addAnswer apm-add-answer ".$add_answer_for_grid."'>
2628 <input type='text' placeholder='" .esc_html__("Other - please specify", "poll-maker") . "' class='ays-poll-new-answer-apply-text' name='ays_poll_new_answer'>
2629 </div>
2630 ";
2631 $allow_multi_vote_for_other = isset($options["poll_allow_multivote"]) && $options["poll_allow_multivote"] == "on" ? true : false;
2632 if(!$allow_multi_vote_for_other){
2633 $content .= "
2634 <div class='ays-poll-add-answer-note ays-poll-add-answer-note-enable'>
2635 <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>
2636 </div>
2637 ";
2638 }
2639 }
2640 $content .= $poll_multivote_message_content;
2641 break;
2642 case 'voting':
2643 switch ( $poll['view_type'] ) {
2644 case 'hand':
2645 foreach ( $poll['answers'] as $index => $answer ) {
2646 $content .= "<div class='apm-voting answer-$this_poll_id'><input type='radio' name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}'>
2647 <label for='radio-$index-$this_poll_id' class='".$answers_sound_class."'>";
2648 $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>";
2649 }
2650 break;
2651 case 'emoji':
2652 foreach ( $poll['answers'] as $index => $answer ) {
2653 $content .= "<div class='apm-voting answer-$this_poll_id'><input type='radio' name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}'>
2654 <label for='radio-$index-$this_poll_id' class='".$answers_sound_class."'>";
2655 $content .= ((int) $answer['answer'] > 0 ? $emoji[1] : $emoji[3]) . "</label></div>";
2656 }
2657 break;
2658 default:
2659 break;
2660 }
2661 break;
2662 case 'rating':
2663 switch ( $poll['view_type'] ) {
2664 case 'star':
2665 foreach ( $poll['answers'] as $index => $answer ) {
2666 $content .= "<div class='apm-rating answer-$this_poll_id'><input type='radio' name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}'>
2667 <label for='radio-$index-$this_poll_id'><i class='ays_poll_far ays_poll_fa-star ".$answers_sound_class."'></i></label></div>";
2668 }
2669 break;
2670 case 'emoji':
2671 foreach ( $poll['answers'] as $index => $answer ) {
2672 $content .= "<div class='apm-rating answer-$this_poll_id'><input type='radio' name='answer' id='radio-$index-$this_poll_id' value='{$answer['id']}'>
2673 <label class='emoji ".$answers_sound_class."' for='radio-$index-$this_poll_id'>" . $emoji[(count($poll['answers']) / 2 - $index + 1.5)] . "</label></div>";
2674 }
2675 break;
2676 default:
2677 break;
2678 }
2679 break;
2680 case 'text':
2681 $poll_text_type_placeholder = ( isset($options['poll_text_type_placeholder']) && $options['poll_text_type_placeholder'] != "" ) ? stripslashes(esc_attr($options['poll_text_type_placeholder'])) : "";
2682 switch ( $poll_view_type_text ) {
2683 case 'short_text':
2684 $content .= "<div class='ays-poll-maker-text-answer-main answer-".$this_poll_id."'>
2685 <div>
2686 <input
2687 type='text'
2688 id='ays-poll-text-type-short-".$this_poll_id."'
2689 class='ays-poll-text-types-inputs ".$poll_class_for_limits."'
2690 placeholder='".$poll_text_type_placeholder."'
2691 name='answer'
2692 data-max-length='".$poll_text_type_limit_length."'
2693 data-limit-type='".$poll_text_type_limit_type."'
2694 autocomplete='off'>
2695 <label class='ays-poll-text-type-short-label' for='ays-poll-text-type-short-".$this_poll_id."'></label>
2696 </div>
2697 ".$poll_box_for_limit_message."
2698 </div>";
2699 break;
2700 case 'paragraph':
2701 $content .= "<div class='ays-poll-maker-text-answer-main answer-".$this_poll_id."'>
2702 <div>
2703 <textarea
2704 id='ays-poll-text-type-paragraph-".$this_poll_id."'
2705 class='ays-poll-text-types-inputs ays-poll-text-types-inputs-only-textarea ".$poll_class_for_limits."'
2706 placeholder='".$poll_text_type_placeholder."'
2707 name='answer'
2708 data-max-length='".$poll_text_type_limit_length."'
2709 data-limit-type='".$poll_text_type_limit_type."'
2710 ></textarea>
2711 <label for='ays-poll-text-type-paragraph-".$this_poll_id."'></label>
2712 </div>
2713 ".$poll_box_for_limit_message."
2714 </div>";
2715 break;
2716 default:
2717 break;
2718 }
2719 break;
2720 default:
2721 break;
2722 }
2723
2724 if ($view_more_button_flag) {
2725 $content .= '
2726 <div class="ays-poll-view-more-button-box">
2727 <input type="button" class="btn ays-poll-btn ays-poll-view-more-button" value="'.esc_html__( "View more", "poll-maker" ) .'">
2728 </div>';
2729 }
2730
2731 $content .= "</div>";
2732 $content .= "<div class='apm-cashed-fa'>";
2733 foreach ( $poll['answers'] as $index => $answer ) {
2734 $content .= "<div>
2735 <i class='ays_poll_fas ays_poll_fa-star' style='font-size: 0'></i>
2736 </div>";
2737 }
2738 $content .= "</div>";
2739 if ($info_form) {
2740 $this->fields_placeholders = $this->ays_set_poll_fields_placeholders_texts();
2741 $content .= "\n
2742 <div class='apm-info-form' data-text='" .esc_html__("Send", "poll-maker") . "' style='display: none;'>
2743 $info_form_title
2744 <div class='amp-info-form-input-box'>
2745 ";
2746 foreach ( $fields as $f ) {
2747 $required = array_search($f, $required_fields) !== false ? "true" : "false";
2748 switch ( $f ) {
2749 case "apm_email":
2750 if( $display_fields_labels ){
2751 $content .= "<label for='ays_poll_form_field_user_email_". $id ."' style='border: none;'>". $this->fields_placeholders['emailLabel'] ."</label>";
2752 }
2753 $content .= "
2754 <input type='email' check_id='".$this_poll_id."' class='ays_animated_xms' name='$f' data-required='$required' placeholder='".$this->fields_placeholders['emailPlaceholder']."'>
2755 ";
2756 break;
2757 case "apm_phone":
2758 if( $display_fields_labels ){
2759 $content .= "<label for='ays_form_field_user_phone_". $id ."' style='border: none;'>". $this->fields_placeholders['phoneLabel'] ."</label>";
2760 }
2761 $content .= "
2762 <input type='tel' class='ays_animated_xms' name='$f' data-required='$required' placeholder='".$this->fields_placeholders['phonePlaceholder']."'>
2763 ";
2764 break;
2765 default:
2766 if( $display_fields_labels ){
2767 $content .= "<label for='ays_form_field_user_name_". $id ."' style='border: none;'>". $this->fields_placeholders['nameLabel'] ."</label>";
2768 }
2769 $content .= "
2770 <input type='text' class='ays_animated_xms' name='$f' data-required='$required' placeholder='".$this->fields_placeholders['namePlaceholder']."'>
2771 ";
2772 break;
2773 }
2774 }
2775 $content .= "</div></div>";
2776 }
2777 } else {
2778 $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>";
2779 if (isset($options['redirect_url']) && $options['redirect_url'] != '' && isset($options['redirection_delay']) && $options['redirection_delay'] != 0) {
2780 $content .= "<div class='apm-redirection apm-redirection-$this_poll_id'>
2781 <p data-id='$this_poll_id' data-href='" . stripslashes($options['redirect_url']) . "' data-delay='{$options['redirection_delay']}'>" .esc_html__('Redirecting after', "poll-maker")
2782 . " <b>{$this->secondsToWords($options['redirection_delay'])}</b>
2783 </p>
2784 </div>";
2785 }
2786 }
2787 }
2788 }
2789
2790 $show_res_button = !is_user_logged_in() && !$show_login_form ? true : false;
2791
2792 if (is_user_logged_in() || $show_res_button ) {
2793 $content .= $vote_reason;
2794 if($limit_users > 0){
2795 $content .= wp_nonce_field('ays_finish_poll', 'ays_finish_poll_show_res_' . $poll_id);
2796 }
2797 else{
2798 $content .= wp_nonce_field('ays_finish_poll', 'ays_finish_poll_show_res_' . $poll_id) . "<div class='apm-button-box'>";
2799 }
2800 if (!empty($options['allow_not_vote']) && $limit_users == 0 && $poll['type'] != "text") {
2801 $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' >";
2802 }
2803 elseif($limit_users > 0){
2804 if($poll_see_result_button_check){
2805 if($poll_show_result_button_limit){
2806 $content .= "<div class='apm-button-box'>";
2807 if($poll['type'] != "text"){
2808 $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' >";
2809 }
2810 $content .= "</div>";
2811
2812 }
2813 elseif($poll_see_result_immediately){
2814 $result_content = $this->ays_poll_get_results($id);
2815 $content .= $result_content;
2816 if($poll_show_avatars){
2817 $content .= "<script>
2818 var resLoader = '".POLL_MAKER_AYS_PUBLIC_URL."/images/tail-spin.svg';
2819 var idChecker = 'ays-poll-container-" . $id . "';
2820 </script>";
2821 }
2822 }
2823
2824 }
2825 }
2826 if ($limit_users == 0 && $load_poll) {
2827
2828 $ays_vote_button = (isset($options['btn_text']) && $options['btn_text'] != '') ? stripslashes($options['btn_text']) : 'Vote';
2829
2830 if ($ays_vote_button === 'Vote') {
2831 $ays_vote_button_text = esc_html__("Vote", "poll-maker");
2832 }else{
2833 $ays_vote_button_text = $ays_vote_button;
2834 }
2835
2836 $content .= "<input type='button'
2837 name='ays_finish_poll'
2838 class='btn ays-poll-btn {$poll['type']}-btn ays_finish_poll'
2839 data-form='$this_poll_id'
2840 " . (!$load_poll ? "data-allow='false'" : "") .
2841 'value="' . $ays_vote_button_text . '"
2842 >';
2843
2844 }
2845 }
2846 if(!$limit_users > 0 && (is_user_logged_in() || $show_res_button )){
2847 $content .= '</div>';
2848 }
2849
2850 $is_elementor_exists = Poll_Maker_Data::ays_poll_is_elementor();
2851 $is_editor_exists = Poll_Maker_Data::ays_poll_is_editor();
2852
2853 $poll_block_preview_message = "";
2854 if( $is_elementor_exists || $is_editor_exists ){
2855 $poll_block_preview_message = '
2856 <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>';
2857 }
2858
2859 $content .= $poll_block_preview_message;
2860 $content .= $result_message;
2861 $content .= $redirect_after_vote;
2862 } elseif ($is_start_soon) {
2863 $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>";
2864 $content .= "<div class='apm_expired_poll'>".$poll_is_start_message."</div>";
2865
2866 } else {
2867 $expired_poll_message = isset($options['active_date_message']) ? stripslashes($options['active_date_message']) : "<p>" .esc_html__('The poll has expired.', "poll-maker") . "</p>";
2868 $content .= "<div class='apm_expired_poll'>$expired_poll_message</div>";
2869
2870 if ($show_res_btn_sch) {
2871 $content .= $see_result_button;
2872 }
2873
2874 }
2875 $poll_options = $options;
2876 if ( $activeDateCheck && $activeDeactiveDateCheck && $show_bottom_timer){
2877 $content .= $show_timer;
2878 }
2879 $content .= "<script>";
2880 $content .= "
2881 if(typeof aysPollOptions === 'undefined'){
2882 var aysPollOptions = [];
2883 }
2884 aysPollOptions['".$this_poll_id."'] = '" . base64_encode(json_encode($poll_options)) . "';";
2885 $content .= "
2886 </script>";
2887 $content .= '</div></form></div>';
2888 if ($echo) {
2889 echo $content;
2890 } else {
2891 return $content;
2892 }
2893 }
2894
2895 public function ays_poll_category_generate_html($attr, $echo = true) {
2896 global $wpdb;
2897
2898 $id = absint($attr['cat_id']);
2899 $poll_table = esc_sql($wpdb->prefix . "ayspoll_polls");
2900 $like = '%' . $wpdb->esc_like( $id ) . '%';
2901 $sql = "SELECT id FROM ".$poll_table." WHERE categories LIKE %s;";
2902 $result = $wpdb->get_results(
2903 $wpdb->prepare($sql, $like),
2904 'ARRAY_A'
2905 );
2906
2907 $cat = $this->ays_get_poll_category($id);
2908 if (empty($cat)) {
2909 return "";
2910 }
2911
2912 //AV Check expired polls
2913 $check_poll = false;
2914 $new_res = array();
2915 $checker = array();
2916 $widths = array();
2917 foreach ($result as $key => $value) {
2918 $check_poll = $this->check_shedule_expired_poll( $value['id'] );
2919
2920 $polls = $this->get_poll_by_id($value['id']);
2921 $widths[] = $polls['styles']['width']."px";
2922 if ($check_poll) {
2923 $new_res[] = $result[$key];
2924 }
2925 $checker[] = $check_poll;
2926 }
2927
2928 if (isset($widths[0]) && $widths[0] == "0px") {
2929 $widths[0] = "98%";
2930 }
2931
2932 $cat_opt = null;
2933 if ($cat['options'] !== null) {
2934 $cat_opt = json_decode($cat['options'], true);
2935 }
2936
2937 $default_message = 'The polls that belong to this category are expired or unpublished';
2938 $exp_message = isset($cat_opt['exp_message']) && $cat_opt['exp_message'] != '' ? $this->ays_autoembed($cat_opt['exp_message']) : $default_message;
2939
2940 if (array_sum($checker) == 0) {
2941 echo "<div class='ays_exp_cat_message'>".$exp_message."</div>";
2942 }
2943
2944 if (empty($new_res)) {
2945 return "";
2946 }
2947
2948 $polls_pool = $this->ays_get_polls_pool($new_res);
2949
2950 $ays_next_button = (isset($cat_opt['next_text']) && $cat_opt['next_text'] != '') ? stripslashes($cat_opt['next_text']) : 'Next';
2951 if ($ays_next_button === 'Next') {
2952 $ays_next_button_text = esc_html__("Next", "poll-maker");
2953 } else {
2954 $ays_next_button_text = $ays_next_button;
2955 }
2956
2957 $ays_previous_button = (isset($cat_opt['previous_text']) && $cat_opt['previous_text'] != '') ? stripslashes($cat_opt['previous_text']) : 'Previous';
2958 if ($ays_previous_button === 'Previous') {
2959 $ays_previous_button_text = esc_html__("Previous", "poll-maker");
2960 }else{
2961 $ays_previous_button_text = $ays_previous_button;
2962 }
2963
2964 $show_next = isset($cat_opt['allow_skip']) && $cat_opt['allow_skip'] == 'allow' ? 'true' : 'false';
2965 $show_next_val = ($show_next == 'true') ? 'true' : 'false';
2966 $cat_id = uniqid('ays-poll-category-pool-');
2967 $j = uniqid('JsVariable');
2968 $content = "
2969 <div style='margin:1rem auto;' class='ays_poll_category-container' data-var='" . $j . "' id='$cat_id'>
2970 </div>
2971 <style>
2972 #" . $cat_id . " div.previous_next_buttons {
2973 display:flex;
2974 width: " . $widths[0] . ";
2975 max-width: 98%;
2976 }
2977 </style>
2978 <script>
2979 var catContainer" . $j . " = '" . $cat_id . "';
2980 var pollsGlobalPool" . $j . " = " . $polls_pool . ";
2981 var showNext" . $j . " = " . $show_next . ";
2982 var showNextVal" . $j . " = " . $show_next_val . ";
2983 var catIndex" . $j . " = 0;
2984 var aysPollBtnText" . $j . " = '" . $ays_next_button_text . "';
2985 var showPrev" . $j . " = false;
2986 var aysPollPreviousBtnText" . $j . " = '" . $ays_previous_button_text . "';
2987 var aysPollWidths" . $j . " = '" . json_encode($widths) . "';
2988 </script>";
2989
2990 if ($echo) {
2991 echo $content;
2992 } else {
2993 return $content;
2994 }
2995 }
2996
2997 private function get_poll_by_id( $id ) {
2998 global $wpdb;
2999 $args_id = absint(intval($id));
3000 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
3001 $sql = "SELECT * FROM ".$poll_table." WHERE id=%d";
3002 $ordering = 'ORDER BY ordering ASC, id ASC';
3003 $poll = $wpdb->get_row(
3004 $wpdb->prepare( $sql, $args_id),
3005 'ARRAY_A'
3006 );
3007
3008 if (empty($poll)) {
3009 return $poll;
3010 }
3011
3012 $json = $poll['styles'];
3013 $poll['styles'] = json_decode($json, true);
3014 $poll_type = (isset($poll['type']) && $poll['type'] != '') ? $poll['type'] : '';
3015 if($poll_type == 'choosing'){
3016 $answer_ordering = isset($poll['styles']['answer_sort_type']) && $poll['styles']['answer_sort_type'] != '' ? $poll['styles']['answer_sort_type'] : '';
3017 if($answer_ordering != ''){
3018 switch ($answer_ordering){
3019 case 'ascending':
3020 $ordering = 'ORDER BY answer ASC';
3021 break;
3022 case 'descending':
3023 $ordering = 'ORDER BY answer DESC';
3024 break;
3025 case 'votes_asc':
3026 $ordering = 'ORDER BY votes DESC, id ASC';
3027 break;
3028 case 'votes_desc':
3029 $ordering = 'ORDER BY votes ASC, id ASC';
3030 break;
3031 default:
3032 $ordering = "ORDER BY ordering ASC, id ASC";
3033 break;
3034 }
3035 }
3036 }
3037 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
3038 $sql = "SELECT * FROM ".$answ_table." WHERE poll_id=%d AND show_user_added = %d ".$ordering;
3039
3040 $poll['answers'] = $wpdb->get_results(
3041 $wpdb->prepare( $sql, $args_id, 1),
3042 'ARRAY_A'
3043 );
3044
3045 return $poll;
3046 }
3047
3048 public static function get_poll_results_count_by_id( $id ) {
3049 global $wpdb;
3050
3051 $args_id = absint(intval($id));
3052 $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
3053 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
3054
3055 $sql = "SELECT COUNT(*) AS res_count
3056 FROM ".$rep_table."
3057 INNER JOIN ".$answ_table."
3058 ON ".$answ_table.".id=".$rep_table.".answer_id
3059 WHERE ".$answ_table.".poll_id = %d";
3060
3061 $poll = $wpdb->get_row(
3062 $wpdb->prepare( $sql, $args_id),
3063 'ARRAY_A'
3064 );
3065
3066 return $poll;
3067 }
3068
3069 private static function get_user_ip() {
3070 $ipaddress = '';
3071 if (getenv('HTTP_CLIENT_IP')) {
3072 $ipaddress = getenv('HTTP_CLIENT_IP');
3073 } else if (getenv('HTTP_X_FORWARDED_FOR')) {
3074 $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
3075 } else if (getenv('HTTP_X_FORWARDED')) {
3076 $ipaddress = getenv('HTTP_X_FORWARDED');
3077 } else if (getenv('HTTP_FORWARDED_FOR')) {
3078 $ipaddress = getenv('HTTP_FORWARDED_FOR');
3079 } else if (getenv('HTTP_FORWARDED')) {
3080 $ipaddress = getenv('HTTP_FORWARDED');
3081 } else if (getenv('REMOTE_ADDR')) {
3082 $ipaddress = getenv('REMOTE_ADDR');
3083 } else {
3084 $ipaddress = 'UNKNOWN';
3085 }
3086
3087 return $ipaddress;
3088 }
3089
3090 public static function get_user_ip_validated(){
3091 $headers_to_check = array(
3092 'HTTP_CLIENT_IP',
3093 'HTTP_X_FORWARDED_FOR',
3094 'HTTP_X_FORWARDED',
3095 'HTTP_FORWARDED_FOR',
3096 'HTTP_FORWARDED',
3097 'REMOTE_ADDR'
3098 );
3099
3100 foreach ($headers_to_check as $header) {
3101 if (!empty($_SERVER[$header])) {
3102 // In case of multiple IPs in HTTP_X_FORWARDED_FOR, take the last one
3103 if ($header === 'HTTP_X_FORWARDED_FOR') {
3104 $ips = explode(',', $_SERVER[$header]);
3105 $ip = trim(end($ips));
3106 } else {
3107 $ip = $_SERVER[$header];
3108 }
3109
3110 // Validate the IP address
3111 if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) && $ip !== '0.0.0.0') {
3112 return $ip;
3113 }
3114 }
3115 }
3116
3117 return 'UNKNOWN';
3118 }
3119
3120 public function secondsToWords( $seconds ) {
3121 $ret = "";
3122 $seconds = absint($seconds);
3123
3124 /*** get the days ***/
3125 $days = (int)($seconds / (3600 * 24));
3126 if ($days > 0) {
3127 $ret .= "$days " .esc_html__( 'days', "poll-maker" ) . ' ';
3128 }
3129
3130 /*** get the hours ***/
3131 $hours = (int)(($seconds / 3600) % 24);
3132 if ($hours > 0) {
3133 $ret .= "$hours " .esc_html__( 'hours', "poll-maker" ) . ' ';
3134 }
3135
3136 /*** get the minutes ***/
3137 $minutes = (int)(($seconds / 60) % 60);
3138 if ($minutes > 0) {
3139 $ret .= "$minutes " .esc_html__( 'minutes', "poll-maker" ) . ' ';
3140 }
3141
3142 /*** get the seconds ***/
3143 $seconds = (int)(($seconds) % 60);
3144 if ($seconds > 0) {
3145 $ret .= "$seconds " .esc_html__( 'seconds', "poll-maker" );
3146 }
3147
3148 return $ret;
3149 }
3150
3151 public function ays_get_polls_pool( $array_of_poll_id ) {
3152 $pool = array();
3153 foreach ( $array_of_poll_id as $poll ) {
3154 $pool[] = $this->ays_poll_generate_html($poll['id'], false);
3155 }
3156
3157 return json_encode($pool);
3158 }
3159
3160 public function ays_get_poll_category( $id ) {
3161 global $wpdb;
3162 $cat_id = absint(intval($id));
3163 $cat_table = esc_sql($wpdb->prefix."ayspoll_categories");
3164 $sql = "SELECT * FROM ".$cat_table." WHERE id=%d";
3165 $result = $wpdb->get_row(
3166 $wpdb->prepare( $sql, $cat_id),
3167 'ARRAY_A'
3168 );
3169
3170 return $result;
3171 }
3172
3173 public function get_poll_status($id) {
3174 global $wpdb;
3175 $poll_id = absint(intval($id));
3176 $poll_table = $wpdb->prefix . 'ayspoll_polls';
3177
3178 $poll = $wpdb->get_row($wpdb->prepare("SELECT styles FROM $poll_table WHERE id = %d", $poll_id));
3179
3180 if ($poll) {
3181 $styles = json_decode($poll->styles, true);
3182 if (isset($styles['published']) && $styles['published'] == 1) {
3183 return 'published';
3184 } else {
3185 return 'unpublished';
3186 }
3187 } else {
3188 return false;
3189 }
3190 }
3191
3192 public function ays_poll_get_user_information() {
3193 if ( ! check_ajax_referer( 'ays_poll_nonce', '_ajax_nonce', false ) ) {
3194 wp_send_json_error( array( 'message' => 'Invalid request' ), 403 );
3195 }
3196 if ( ! is_user_logged_in() ) {
3197 wp_send_json_error( array( 'message' => 'User not logged in' ), 401 );
3198 }
3199
3200 $user = wp_get_current_user();
3201
3202 wp_send_json_success( array(
3203 'display_name' => $user->display_name,
3204 'user_email' => $user->user_email,
3205
3206 ) );
3207 }
3208
3209 public function ays_finish_poll() {
3210 global $wpdb;
3211 $poll_id = absint($_POST['poll_id']);
3212 if (
3213 (isset($_POST["ays_finish_poll_" . $poll_id]) && wp_verify_nonce($_POST["ays_finish_poll_" . $poll_id], 'ays_finish_poll')) ||
3214 (isset($_POST["ays_finish_poll_show_res_" . $poll_id]) && wp_verify_nonce($_POST["ays_finish_poll_show_res_" . $poll_id], 'ays_finish_poll'))
3215 ) {
3216
3217 // $answer_id = (isset($_POST['answer']) && $_POST['answer'] !== null) ? $_POST['answer'] : 0;
3218 // $poll_id = absint($_POST['poll_id']);
3219 $poll_status = $this->get_poll_status($poll_id);
3220
3221 if ($poll_status === 'unpublished') {
3222 $res = array('error' => 'The poll is not published.');
3223 echo json_encode($res);
3224 wp_die();
3225 }
3226
3227 $title_ids = array();
3228 $answer_titless = array();
3229 if (isset($_POST['answer'])) {
3230 if( is_array($_POST['answer']) ){
3231 $answer_id = array_map('absint', $_POST['answer']);
3232 $multi_answer_id = array_map('absint', $_POST['answer']);
3233 $title_ids = implode(',' , $multi_answer_id);
3234 }else{
3235 $answer_id = absint( $_POST['answer'] );
3236
3237 $answer_id2 = array();
3238 $answer_id2[] = $answer_id;
3239 $multi_answer_id = array();
3240 $title_ids = implode(',' , $answer_id2);
3241 }
3242 }else{
3243 $answer_id = 0;
3244 $answer_id2[] = false;
3245 }
3246
3247 if(!is_array($answer_id)){
3248 $answer_id = absint($answer_id);
3249 }
3250
3251 // $title_ids = array();
3252 // $answer_titless = array();
3253 // if (isset($_POST['answer']) && is_array($_POST['answer'])) {
3254 // $answer_id = $_POST['answer'];
3255 // $multi_answer_id = $_POST['answer'];
3256 // $title_ids = implode(',' , $multi_answer_id);
3257 // } else {
3258 // $answer_id2 = array();
3259 // $answer_id2[] = !isset($_POST['answer']) || $_POST['answer'] === null ? false : absint($_POST['answer']);
3260 // $multi_answer_id = array();
3261 // $title_ids = implode(',' , $answer_id2);
3262 // }
3263 if(!empty($title_ids)){
3264 $answer_titles = $this->get_answer_by_ids($title_ids);
3265 if(isset($answer_titles) && $answer_titles != null){
3266 foreach($answer_titles as $t_key => $t_value){
3267 foreach ($t_value as $r_key => $r_value) {
3268 if($r_key == 'answer'){
3269 $answer_titless[] = $r_value;
3270 }
3271 }
3272 }
3273 }
3274 }
3275
3276
3277 $poll = $this->get_poll_by_id($poll_id);
3278 $options = $poll['styles'];
3279 $poll_answers_count = isset($poll['answers']) ? count($poll['answers']) : 0;
3280 $added_answer_id = array();
3281
3282 $poll_title = (isset($poll['title']) && $poll['title'] != '') ? stripslashes( sanitize_text_field( $poll['title'] ) ) : '';
3283 $poll_vote_reason_text = "";
3284 $poll_vote_reason = false;
3285 $show_answers_numbering = (isset($options['show_answers_numbering']) && sanitize_text_field( $options['show_answers_numbering'] ) != '') ? sanitize_text_field( $options['show_answers_numbering'] ) : 'none';
3286 if (isset($options['poll_vote_reason']) && $options['poll_vote_reason'] == "on" && isset($_POST['ays-poll-reason-text'])) {
3287 // $poll_vote_reason_text = $_POST['ays-poll-reason-text'];
3288 $poll_vote_reason_text = esc_html( $_POST['ays-poll-reason-text'] );
3289 $poll_vote_reason = true;
3290 }
3291
3292 $allow_multi_vote = isset($options["poll_allow_multivote"]) && $options["poll_allow_multivote"] == "on" ? true : false;
3293 $allow_add_answer = isset($options["poll_allow_answer"]) && $options["poll_allow_answer"] == "on" ? true : false;
3294 $check_admin_approval = false;
3295 $flag_for_added_answer = false;
3296 if($allow_add_answer && (isset($_POST['ays_poll_new_answer']) && $_POST['ays_poll_new_answer'] != "")){
3297
3298 $flag_for_added_answer = true;
3299 $poll_allow_answer_require = isset($options['poll_allow_answer_require']) && $options['poll_allow_answer_require'] == "on" ? true : false;
3300 if($poll_allow_answer_require){
3301 $check_admin_approval = true;
3302 }
3303 // $poll_answers_count = isset($poll['answers']) ? count($poll['answers']) : 0;
3304 $new_anwer_data = array(
3305 'poll_id' => $poll_id,
3306 'new_answer' => wp_kses_post(stripslashes($_POST['ays_poll_new_answer'])),
3307 'admin_require' => $poll_allow_answer_require,
3308 'answers_count' => $poll_answers_count,
3309 'if_text_type' => false
3310 );
3311
3312 $added_answer_id = $this->ays_add_answer_poll($new_anwer_data);
3313
3314 if((is_array($answer_id) && !empty($answer_id)) && $allow_multi_vote){
3315 $answer_id[] = $added_answer_id['new_id'];
3316 }
3317 elseif(isset($answer_id) && !is_array($answer_id) && $answer_id > 0 && $allow_multi_vote){
3318 $answer_id = explode(" " , $answer_id);
3319 array_push($answer_id , $added_answer_id['new_id']);
3320 }
3321 else{
3322 $answer_id = $added_answer_id['new_id'];
3323 }
3324 }
3325 $poll_type_for_text_type = isset($poll['type']) && $poll['type'] == "text" ? true : false;
3326 $poll_answer = isset($_POST['answer']) && $_POST['answer'] != '' ? sanitize_text_field($_POST['answer']) : "";
3327
3328 // Add new text answer if not exist
3329 if($poll_type_for_text_type) {
3330 $text_anwer_data = array(
3331 'poll_id' => $poll_id,
3332 'new_answer' => $poll_answer,
3333 'admin_require' => false,
3334 'answers_count' => $poll_answers_count,
3335 'if_text_type' => true
3336 );
3337
3338 $is_answer_exist = $this->check_text_answer_exist($poll_id, $poll_answer);
3339 if (!$is_answer_exist) {
3340 $added_answer_id = $this->ays_add_answer_poll($text_anwer_data);
3341 $answer_id = $added_answer_id['new_id'];
3342 } else {
3343 $answer_id = $this->get_text_answer_id($poll_id, $poll_answer);
3344 }
3345 }
3346
3347 if ($answer_id > 0 || is_array($answer_id)) {
3348 if (isset($options['limit_users']) && $options['limit_users'] == 1) {
3349 $user_id = is_user_logged_in() ? wp_get_current_user()->ID : 0;
3350 $limit_users_method = isset($options['limit_users_method']) ? sanitize_text_field($options['limit_users_method']) : 'ip';
3351 $user_voted_count = 0;
3352 if ($limit_users_method == 'ip') {
3353 $user_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3354 }
3355 elseif($limit_users_method == 'cookie'){
3356 $cookie_name = "ays_this_poll_cookie_".$poll_id;
3357 if(!isset($_COOKIE[$cookie_name])){
3358 $cookie_value = "ays_vote_limitation_cookie_value";
3359 $time_limit = time() + (86400 * 30);
3360 setcookie($cookie_name, $cookie_value,$time_limit , '/');
3361 }else{
3362 $user_voted_count = 1;
3363 }
3364 }
3365 elseif($limit_users_method == 'cookie_ip'){
3366 $cookie_name = "ays_this_poll_cookie_".$poll_id;
3367 $limit_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3368 if(!isset($_COOKIE[$cookie_name])){
3369 $cookie_value = "ays_vote_limitation_cookie_value";
3370 $time_limit = time() + (86400 * 30);
3371 setcookie($cookie_name, $cookie_value,$time_limit , '/');
3372 }
3373 else{
3374 $user_voted_count = 1;
3375 }
3376 if(isset($_COOKIE[$cookie_name]) || $limit_voted_count > 0){
3377 $user_voted_count = 1;
3378 }
3379 elseif(!isset($_COOKIE[$cookie_name]) || $limit_voted_count > 0){
3380 $user_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3381 }
3382 }
3383 else{
3384 if ($user_id != 0) {
3385 $user_voted_count = $this->ays_poll_get_limit_user_count_by_id($poll_id,$user_id);
3386 }else{
3387 $user_voted_count = $this->ays_poll_get_limit_user_count_by_ip($poll_id);
3388 }
3389 }
3390
3391 $user_voted_count = absint(intval(($user_voted_count)));
3392
3393 if ( $user_voted_count > 0 ) {
3394 $res = $this->get_poll_by_id($poll_id);
3395 $res['voted_status'] = false;
3396 ob_end_clean();
3397 $ob_get_clean = ob_get_clean();
3398 echo json_encode($res);
3399 wp_die();
3400 }
3401 }
3402
3403 if (!empty($options['info_form'])) {
3404 $user_email = isset($_POST["apm_email"]) && $_POST['apm_email'] !== null ? sanitize_email($_POST["apm_email"]) : '';
3405 }else{
3406 $user_email = '';
3407 }
3408
3409 $check_allowing = (isset($options['poll_allow_collecting_users_data']) && $options['poll_allow_collecting_users_data'] == 'on') ? true : false;
3410 $check_fields = (isset($options['info_form']) && $options['info_form'] == 1) ? true : false;
3411 if($check_allowing && !$check_fields){
3412 $this_user = wp_get_current_user();
3413 if($this_user->ID != 0){
3414 $_POST["apm_email"] = $this_user->data->user_email;
3415 $user_email = isset($_POST["apm_email"]) ? sanitize_email($_POST["apm_email"]) : "";
3416 $_POST['apm_name'] = $this_user->data->display_name;
3417 }
3418 }
3419 // MailChimp
3420
3421 if (isset($options['enable_mailchimp']) && $options['enable_mailchimp'] == 'on') {
3422 if (isset($options['mailchimp_list']) && $options['mailchimp_list'] != "") {
3423 $poll_settings = $this->settings;
3424 $mailchimp_res = ($poll_settings->ays_get_setting('mailchimp') === false) ? json_encode(array()) : $poll_settings->ays_get_setting('mailchimp');
3425 $mailchimp = json_decode($mailchimp_res, true);
3426 $mailchimp_username = isset($mailchimp['username']) ? $mailchimp['username'] : '';
3427 $mailchimp_api_key = isset($mailchimp['apiKey']) ? $mailchimp['apiKey'] : '';
3428 $mailchimp_list = (isset($options['mailchimp_list'])) ? $options['mailchimp_list'] : '';
3429 $mailchimp_email = $user_email;
3430 $user_name = isset($_POST['apm_name']) ? explode(" ", wp_filter_post_kses($_POST['apm_name'])) : array();
3431 $mailchimp_fname = (isset($user_name[0]) && $user_name[0] != "") ? $user_name[0] : "";
3432 $mailchimp_lname = (isset($user_name[1]) && $user_name[1] != "") ? $user_name[1] : "";
3433 $user_phone = isset($_POST['apm_phone']) ? explode(" ", wp_filter_post_kses($_POST['apm_phone'])) : array();
3434 $mailchimp_phone = (isset($user_phone[0]) && $user_phone[0] != "") ? $user_phone[0] : "";
3435 if ($mailchimp_username != "" && $mailchimp_api_key != "") {
3436 $args = array(
3437 "email" => $mailchimp_email,
3438 "fname" => $mailchimp_fname,
3439 "lname" => $mailchimp_lname,
3440 "pnumber" => $mailchimp_phone,
3441 );
3442 $mresult = $this->ays_add_mailchimp_transaction($mailchimp_username, $mailchimp_api_key, $mailchimp_list, $args);
3443 }
3444 }
3445 }
3446
3447 // $answer = $this->get_answer_by_id($answer_id);
3448
3449 // $votes = isset($answer['voted']) && $answer['voted'] !== null ? $answer['voted'] : 0;
3450 // $votes++;
3451
3452 $other_info = array(
3453 "Name" => "",
3454 "email" => "",
3455 "phone" => "",
3456 );
3457
3458 if (!empty($options['info_form']) || $check_allowing) {
3459 $other_info = array(
3460 "Name" => !empty($_POST['apm_name']) ? sanitize_text_field($_POST['apm_name']) : "",
3461 "email" => !empty($_POST['apm_email']) ? sanitize_email($_POST['apm_email']) : "",
3462 "phone" => !empty($_POST['apm_phone']) ? sanitize_text_field($_POST['apm_phone']) : "",
3463 );
3464 }
3465 if($poll_vote_reason){
3466 $other_info['voteReason'] = $poll_vote_reason_text;
3467 }
3468 // global $wpdb;
3469 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
3470 $report_table = esc_sql($wpdb->prefix."ayspoll_reports");
3471
3472 // AV IP Storing
3473 $settings_table = esc_sql($wpdb->prefix."ayspoll_settings");
3474 $key_meta = esc_sql('options');
3475 $sql_ip = "SELECT meta_value FROM ".$settings_table." WHERE meta_key = %s";
3476 $res_ip = $wpdb->get_var(
3477 $wpdb->prepare( $sql_ip, $key_meta)
3478 );
3479
3480 $options_res = ($res_ip === false) ? json_encode(array()) : $res_ip;
3481 $option_res = json_decode((string)$options_res, true);
3482
3483 $user_ips = isset($option_res['disable_ip_storing']) && $option_res['disable_ip_storing'] == 'on' ? '' : $this->get_user_ip_validated();
3484
3485 $poll_user_information = $this->get_user_profile_data();
3486 $user_first_name = (isset( $poll_user_information['user_first_name'] ) && $poll_user_information['user_first_name'] != "") ? $poll_user_information['user_first_name'] : '';
3487 $user_last_name = (isset( $poll_user_information['user_last_name'] ) && $poll_user_information['user_last_name'] != "") ? $poll_user_information['user_last_name'] : '';
3488 $creation_date = (isset( $poll['styles']['create_date'] ) && $poll['styles']['create_date'] != '') ? $poll['styles']['create_date'] : '';
3489
3490
3491 $current_poll_author = esc_html__( "Unknown", "poll-maker" );
3492 $current_poll_author_email = '';
3493 $current_poll_author_nickname = '';
3494 $current_poll_author_display_name = '';
3495 $current_poll_author_website_url = '';
3496 $current_poll_author_registered = '';
3497 if( !empty($options['author']) ){
3498 if( !is_array($options['author']) ){
3499 $options['author'] = json_decode($options['author'], true);
3500 }
3501
3502 $poll_current_author = (isset($options['author']['id']) && $options['author']['id'] != "") ? absint(sanitize_text_field( $options['author']['id'] )) : "";
3503
3504 $current_poll_user_data = get_userdata( $poll_current_author );
3505 if ( ! is_null( $current_poll_user_data ) && $current_poll_user_data ) {
3506 $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 ) : "";
3507 $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 ) : "";
3508 $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 ) : "";
3509 $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 ) : "";
3510 $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 ) : "";
3511 $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 ) : "";
3512 }
3513 }
3514
3515 // Get Current date
3516 $poll_current_date = date_i18n( 'M d, Y', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3517
3518 // Get Current time
3519 $poll_current_time = date_i18n( get_option( 'time_format' ), strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3520
3521 // Get Current day
3522 $poll_current_day = date_i18n( 'l', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3523
3524 // Get Current month
3525 $poll_current_month = date_i18n( 'F', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
3526
3527 // Get Post Title
3528 $post_id = url_to_postid( $_POST['_wp_http_referer'] );
3529 $post_title = get_the_title( $post_id );
3530 $get_site_title = get_bloginfo('name');
3531 $get_site_description = get_bloginfo('description');
3532
3533 // WP home page url
3534 $home_main_url = home_url();
3535 $home_page_url = '<a href="'. $home_main_url .'" target="_blank">'. $home_main_url .'</a>';
3536
3537 $user_nickname = '';
3538 $user_first_name = '';
3539 $user_display_name = '';
3540 $user_wordpress_email = '';
3541 $user_wordpress_roles = '';
3542 $user_wordpress_website = '';
3543 $user_ip_address = '';
3544 $user_id = get_current_user_id();
3545 $user_data = wp_get_current_user();
3546 $super_admin_email = get_option('admin_email');
3547
3548 $post_author = get_post_field( 'post_author', $post_id );
3549 $author_id = get_the_author_meta('ID', $post_author);
3550 $post_author_email = get_the_author_meta( 'email', $author_id );
3551 $post_author_display_name = get_the_author_meta( 'display_name', $author_id );
3552 $post_author_nickname = get_the_author_meta( 'nickname', $author_id );
3553 $post_author_first_name = get_the_author_meta( 'first_name', $author_id );
3554 $post_author_last_name = get_the_author_meta( 'last_name', $author_id );
3555 $post_author_website_url = get_the_author_meta( 'url', $author_id );
3556
3557 $post_author_roles = '';
3558 $user_registered = '';
3559 if ( is_user_logged_in() ) {
3560 $post_author_roles = get_the_author_meta( 'roles', $author_id );
3561 $user_registered = $user_data->user_registered;
3562 }
3563
3564 if ( ! empty( $post_author_website_url ) ) {
3565 $post_author_website_url = '<a href="'. $post_author_website_url .'" target="_blank">'. $post_author_website_url .'</a>';
3566 }
3567
3568 if ( ! empty( $current_poll_author_website_url ) ) {
3569 $current_poll_author_website_url = '<a href="'. $current_poll_author_website_url .'" target="_blank">'. $current_poll_author_website_url .'</a>';
3570 }
3571
3572 if ( ! empty( $post_author_roles ) && $post_author_roles != "" ) {
3573 if ( is_array( $post_author_roles ) ) {
3574 $post_author_roles = implode( ", ", $post_author_roles );
3575 }
3576 }
3577
3578 if( $user_id != 0 ){
3579 $usermeta = get_user_meta( $user_id );
3580 if($usermeta !== null){
3581 $user_nickname = (isset($usermeta['nickname'][0]) && sanitize_text_field( $usermeta['nickname'][0] != '') ) ? sanitize_text_field( $usermeta['nickname'][0] ) : '';
3582 $user_first_name = (isset($usermeta['first_name'][0]) && sanitize_text_field( $usermeta['first_name'][0] != '') ) ? sanitize_text_field( $usermeta['first_name'][0] ) : '';
3583 }
3584
3585 $current_user_data = get_userdata( $user_id );
3586 if ( ! is_null( $current_user_data ) && $current_user_data ) {
3587 $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 ) : "";
3588 $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 ) : "";
3589
3590 $user_wordpress_roles = ( isset( $current_user_data->roles ) && ! empty( $current_user_data->roles ) ) ? $current_user_data->roles : "";
3591 $user_ip_address = $this->get_user_ip_validated();
3592
3593 if ( !empty( $user_wordpress_roles ) && $user_wordpress_roles != "" ) {
3594 if ( is_array( $user_wordpress_roles ) ) {
3595 $user_wordpress_roles = implode(",", $user_wordpress_roles);
3596 }
3597 }
3598
3599 $user_wordpress_website_url = ( isset( $current_user_data->user_url ) && ! empty( $current_user_data->user_url ) ) ? sanitize_url($current_user_data->user_url) : "";
3600
3601 if( !empty( $user_wordpress_website_url ) ){
3602 $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>";
3603 }
3604 }
3605 }
3606
3607 if ( is_user_logged_in() ) {
3608 $current_user_id = get_current_user_id();
3609 } else {
3610 $current_user_id = '';
3611 }
3612
3613 $report_table = $wpdb->prefix."ayspoll_reports";
3614 $answ_table = $wpdb->prefix."ayspoll_answers";
3615
3616 $sql = "SELECT COUNT(*)
3617 FROM ".$report_table."
3618 JOIN ".$answ_table."
3619 ON ".$answ_table.".id = ".$report_table.".answer_id
3620 WHERE ".$answ_table.".poll_id =".$poll_id;
3621
3622 $pass_count_results = $wpdb->get_var($sql);
3623 $pass_count = ( isset($pass_count_results) && $pass_count_results != '' ) ? intval( $pass_count_results ) : 0;
3624
3625 $passed_poll_count_per_user = Poll_Maker_Data::get_user_passed_polls_count( $user_id );
3626
3627 $ays_protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
3628
3629 $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'] ) : "";
3630 $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>";
3631
3632 $form_apm_name = (isset($_POST['apm_name']) && $_POST['apm_name'] != "") ? esc_attr($_POST['apm_name']) : "";
3633 $form_apm_email = (isset($_POST['apm_email']) && $_POST['apm_email'] != "") ? esc_attr($_POST['apm_email']) : "";
3634 $form_apm_phone = (isset($_POST['apm_phone']) && $_POST['apm_phone'] != "") ? esc_attr($_POST['apm_phone']) : "";
3635
3636 $message_data = array(
3637 'user_name' => $form_apm_name,
3638 'user_email' => $form_apm_email,
3639 'user_phone' => $form_apm_phone,
3640 'poll_title' => $poll_title,
3641 'poll_id' => $poll_id,
3642 'users_first_name' => $user_first_name,
3643 'users_last_name' => $user_last_name,
3644 'creation_date' => $creation_date,
3645 'current_date' => $poll_current_date,
3646 'current_time' => $poll_current_time,
3647 'current_day' => $poll_current_day,
3648 'current_month' => $poll_current_month,
3649 'current_poll_page_link' => $current_poll_page_link_html,
3650 'current_poll_author' => $current_poll_author,
3651 'current_poll_author_email' => $current_poll_author_email,
3652 'current_poll_author_nickname' => $current_poll_author_nickname,
3653 'current_poll_author_display_name' => $current_poll_author_display_name,
3654 'current_poll_author_website_url' => $current_poll_author_website_url,
3655 'current_poll_author_registered' => $current_poll_author_registered,
3656 'admin_email' => $super_admin_email,
3657 'user_nickname' => $user_nickname,
3658 'user_first_name' => $user_first_name,
3659 'user_display_name' => $user_display_name,
3660 'user_wordpress_email' => $user_wordpress_email,
3661 'user_wordpress_roles' => $user_wordpress_roles,
3662 'poll_pass_count' => $pass_count,
3663 'passed_poll_count_per_user' => $passed_poll_count_per_user,
3664 'user_wordpress_website' => $user_wordpress_website,
3665 'user_ip_address' => $user_ip_address,
3666 'user_id' => $current_user_id,
3667 'user_registered' => $user_registered,
3668 'post_title' => $post_title,
3669 'post_author_email' => $post_author_email,
3670 'post_author_display_name' => $post_author_display_name,
3671 'post_author_nickname' => $post_author_nickname,
3672 'post_author_first_name' => $post_author_first_name,
3673 'post_author_last_name' => $post_author_last_name,
3674 'post_author_website_url' => $post_author_website_url,
3675 'post_author_roles' => $post_author_roles,
3676 'post_id' => $post_id,
3677 'site_title' => $get_site_title,
3678 'site_description' => $get_site_description,
3679 'home_page_url' => $home_page_url,
3680 );
3681
3682 $user_ip = esc_sql($user_ips);
3683
3684 // Race condition fix
3685 $limitusers = isset($poll['styles']['limit_users']) ? intval($poll['styles']['limit_users']) : 0;
3686
3687 if ($limitusers > 0) {
3688
3689 $limit_users_method = isset($poll['styles']['limit_users_method']) ? $poll['styles']['limit_users_method'] : "ip";
3690
3691 switch ($limit_users_method) {
3692 case 'ip':
3693 default:
3694 $wpdb->query("START TRANSACTION");
3695 $already_voted = $wpdb->get_var($wpdb->prepare(
3696 "SELECT COUNT(*) FROM {$report_table} WHERE user_ip = %s AND poll_id = %d FOR UPDATE",
3697 $user_ip,
3698 $poll_id
3699 ));
3700 break;
3701 case 'cookie':
3702 $wpdb->query("START TRANSACTION");
3703 $already_voted = isset($_COOKIE["ays_this_poll_cookie_" . $poll_id]) ? 1 : 0;
3704 break;
3705 case 'user':
3706 $wpdb->query("START TRANSACTION");
3707 $already_voted = $wpdb->get_var($wpdb->prepare(
3708 "SELECT COUNT(*) FROM {$report_table} WHERE user_id = %s AND poll_id = %d FOR UPDATE",
3709 $user_id,
3710 $poll_id
3711 ));
3712 break;
3713 }
3714
3715 if ($already_voted > 0) {
3716 $wpdb->query("ROLLBACK");
3717
3718 $res = $this->get_poll_by_id($poll_id);
3719 $res['voted_status'] = false;
3720 echo json_encode($res);
3721 wp_die();
3722 }
3723 }
3724
3725 $multi_answer_ids = array();
3726 if ((is_array($answer_id) && !empty($answer_id)) && $allow_multi_vote) {
3727 $multi_answer_ids = $answer_id;
3728 $answer_changed_id = $answer_id[0];
3729 foreach($answer_id as $a_key => $a_id){
3730 $this_answer = $this->get_answer_by_id_multi($a_id);
3731 if(isset($this_answer[0])){
3732 $votes_new = isset($this_answer[0]['votes']) ? intval($this_answer[0]['votes']) : 0;
3733 $votes_new++;
3734 $wpdb->update(
3735 $answ_table,
3736 array('votes' => $votes_new),
3737 array('id' => $a_id),
3738 array('%d'),
3739 array('%d')
3740 );
3741
3742 }
3743
3744 }
3745 } else {
3746 $answer_changed_id = $answer_id;
3747 $multi_answer_ids[] = $answer_changed_id;
3748 $answer = $this->get_answer_by_id($answer_id);
3749 $votes = isset($answer['votes']) && $answer['votes'] !== null ? intval($answer['votes']) : 0;
3750 $votes++;
3751 $wpdb->update(
3752 $answ_table,
3753 array('votes' => $votes),
3754 array('id' => $answer_id),
3755 array('%d'),
3756 array('%d')
3757 );
3758 }
3759 $wpdb->insert(
3760 $report_table,
3761 array(
3762 'answer_id' => $answer_changed_id,
3763 'user_ip' => $user_ip,
3764 'user_id' => is_user_logged_in() ? wp_get_current_user()->ID : 0,
3765 'vote_date' => esc_sql( sanitize_text_field( $_REQUEST['end_date'] ) ),
3766 'user_email' => $user_email,
3767 'other_info' => json_encode($other_info),
3768 'poll_id' => $poll_id,
3769 'multi_answer_ids' => json_encode($multi_answer_ids)
3770 ),
3771 array(
3772 '%d', // answer_id
3773 '%s', // user_ip
3774 '%s', // user_id
3775 '%s', // vote_date
3776 '%s', // user_email
3777 '%s', // other_info
3778 '%d', // poll_id
3779 '%s', // multi_answer_ids
3780 )
3781 );
3782
3783 // Race condition fix
3784 if ($limitusers > 0) {
3785 $wpdb->query("COMMIT");
3786 }
3787
3788 // $answers = $this->get_answer_by_id($answer_changed_id);
3789 if (!empty($options['notify_email_on'])) {
3790 $notify_admin_email = $options['notify_email'];
3791 $use_answered = '';
3792 if(isset($answer_titless) && !empty($answer_titless)){
3793 $use_answered = implode(', ', $answer_titless);
3794 }
3795 $subject = $poll_title;
3796 $headers = "MIME-Version: 1.0\r\n";
3797 $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
3798 $attachment = array();
3799 $mail_text = (
3800 /* translators: 1: user answer variable, 2: poll title variable 3: anchor tag */
3801 sprintf(esc_html__( "Someone's answer %1\$s in your %2\$s poll on %3\$s.", "poll-maker" ),
3802 $use_answered,
3803 '"' . $poll_title . '"',
3804 "<a href='" . home_url() . "' target='_blank'>" . home_url() . "</a>"
3805 ));
3806 wp_mail($notify_admin_email, $subject, $mail_text, $headers, $attachment);
3807 }
3808
3809 }
3810 $res = $this->get_poll_by_id($poll_id);
3811 $res['voted_status'] = true;
3812 $numbering_arr = array();
3813 // $res['numbering'] = "none";
3814 // if($show_answers_numbering != "none"){
3815 // $answer_count = isset($res['answers']) && !empty($res['answers']) ? count($res['answers']) : false;
3816 // if($answer_count){
3817 // $numbering_arr = $this->ays_answer_numbering($show_answers_numbering , $answer_count);
3818 // $res['numbering'] = $numbering_arr;
3819 // }
3820 // }
3821 $check_user = false;
3822 if(isset($options['show_passed_users']) && $options['show_passed_users'] == 'on'){
3823 $check_user = true;
3824 $poll_avatar_user_count = isset($options['poll_show_passed_users_count']) && $options['poll_show_passed_users_count'] != "" ? $options['poll_show_passed_users_count'] : 3;
3825 $results_table = $wpdb->prefix."ayspoll_reports";
3826 $all_answers = isset($res['answers']) && !empty($res['answers']) ? $res['answers'] : array();
3827 $answer_ids = array();
3828 if(isset($all_answers) && !empty($all_answers)){
3829 foreach($all_answers as $answer => $value){
3830 $answer_ids[] = $value['id'];
3831 }
3832 }
3833 $answer_ids = implode(',' , $answer_ids);
3834 $sql_users = "SELECT `user_id` , `answer_id`
3835 FROM ".$results_table."
3836 WHERE `answer_id` IN (".$answer_ids.")
3837 GROUP BY user_id, answer_id
3838 ORDER BY vote_date DESC";
3839 $user_res = $wpdb->get_results($sql_users , ARRAY_A);
3840 $user_pic_args = array(
3841 "class" => "ays-user-profile-pic"
3842 );
3843 $users_res_array = array();
3844 foreach($user_res as $ar){
3845 // if( isset( $users_res_array[$ar['answer_id']] ) ){
3846 // continue;
3847 // }
3848 $users_res_array[$ar['answer_id']][] = intval( $ar['user_id'] );
3849 }
3850
3851 if(isset($all_answers) && !empty($all_answers)){
3852 foreach($all_answers as $key => $answer){
3853 $user_answers = array();
3854 if( array_key_exists( $answer['id'], $users_res_array ) ){
3855 $user_answers = $this->ays_poll_get_avatars($answer['id'] , $users_res_array);
3856 }
3857 $res['answers'][$key]['avatar'] = $user_answers;
3858 }
3859 }
3860 $res['check_user_pic'] = $check_user;
3861 $res['check_user_pic_count'] = $poll_avatar_user_count;
3862 $res['check_user_pic_url'] = POLL_MAKER_AYS_PUBLIC_URL.'/images/more.png';
3863 $res['check_user_pic_loader'] = POLL_MAKER_AYS_PUBLIC_URL.'/images/tail-spin.svg';
3864 }
3865 if(!isset($message_data)){
3866 $message_data = array();
3867 }
3868 $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']) : "";
3869
3870
3871 $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)) : "";
3872 $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)) : "";
3873 $sensitive_fields = [
3874 'notify_email',
3875 'author',
3876 'poll_create_author',
3877 'mailchimp_list',
3878 'users_role'
3879 ];
3880 if (!current_user_can('manage_options')) {
3881 foreach ($sensitive_fields as $field) {
3882 if (isset($res['styles'][$field]) && $res['styles'][$field] != "") {
3883 unset($res['styles'][$field]);
3884 }
3885 }
3886 }
3887 $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']) : "";
3888 $res['check_admin_approval'] = $check_admin_approval;
3889
3890 /**
3891 * Fires after a user successfully submits a vote in Poll Maker.
3892 *
3893 * @since 1.0.0
3894 *
3895 * @param int $poll_id The poll ID.
3896 */
3897 if (has_action('ays_poll_maker_after_vote')) {
3898 // Collect extra contextual data for hooks
3899 $user_id = get_current_user_id();
3900 $data = array_merge(
3901 (array) $message_data,
3902 array(
3903 'poll_id' => $poll_id,
3904 'answer_id' => $answer_id,
3905 'user_id' => $user_id,
3906 )
3907 );
3908 do_action(
3909 'ays_poll_maker_after_vote',
3910 $data
3911 );
3912 }
3913
3914 ob_end_clean();
3915 $ob_get_clean = ob_get_clean();
3916 echo json_encode($res);
3917 wp_die();
3918 }
3919 }
3920
3921 public function ays_poll_get_avatars($answer , $users){
3922 $user_answers = array();
3923 $user_pic_args = array(
3924 "class" => "ays-user-profile-pic"
3925 );
3926 foreach($users[$answer] as $res_key => $res_value){
3927 if($res_value == 0){
3928 continue;
3929 }
3930 $user_avatars = get_avatar($res_value, 24, $default = '', $alt = '', $user_pic_args);
3931 $user_avatars = isset($user_avatars) && $user_avatars ? $user_avatars : '' ;
3932 $user_answers[] = "<div class='ays-users-profile-pics'>".$user_avatars."</div>";
3933 }
3934 return $user_answers;
3935 }
3936
3937 public function ays_add_mailchimp_transaction( $username, $api_key, $list_id, $args ) {
3938
3939 $email = isset($args['email']) ? $args['email'] : null;
3940 $fname = isset($args['fname']) ? $args['fname'] : "";
3941 $lname = isset($args['lname']) ? $args['lname'] : "";
3942 $phone = isset($args['pnumber']) ? $args['pnumber'] : "";
3943
3944 $api_prefix = explode("-", $api_key)[1];
3945
3946 $fields = array(
3947 "email_address" => $email,
3948 "status" => "subscribed",
3949 "merge_fields" => array(
3950 "FNAME" => $fname,
3951 "LNAME" => $lname,
3952 "PHONE" => $phone
3953 )
3954 );
3955 $curl = curl_init();
3956 curl_setopt_array($curl, array(
3957 CURLOPT_URL => "https://" . $api_prefix . ".api.mailchimp.com/3.0/lists/" . $list_id . "/members/",
3958 CURLOPT_RETURNTRANSFER => true,
3959 CURLOPT_ENCODING => "",
3960 CURLOPT_MAXREDIRS => 10,
3961 CURLOPT_TIMEOUT => 30,
3962 CURLOPT_SSL_VERIFYPEER => false,
3963 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
3964 CURLOPT_USERPWD => "$username:$api_key",
3965 CURLOPT_CUSTOMREQUEST => "POST",
3966 CURLOPT_POSTFIELDS => json_encode($fields),
3967 CURLOPT_HTTPHEADER => array(
3968 "Content-Type: application/json",
3969 "cache-control: no-cache"
3970 ),
3971 ));
3972
3973 $response = curl_exec($curl);
3974
3975 $err = curl_error($curl);
3976
3977 curl_close($curl);
3978
3979 if ($err) {
3980 return "cURL Error #: " . $err;
3981 } else {
3982 return $response;
3983 }
3984 }
3985
3986 private function get_answer_by_id( $id ) {
3987 global $wpdb;
3988 $args_id = absint(intval($id));
3989 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
3990 // $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
3991 // $sql = "SELECT a.*, COUNT(r.id) as voted FROM ".$answ_table." as a
3992 // JOIN ".$rep_table." as r
3993 // ON FIND_IN_SET(a.id , r.answer_id)
3994 // WHERE a.id = %d";
3995
3996 $sql = "SELECT * FROM ".$answ_table."
3997 WHERE id = %d";
3998
3999 $answ_id = $wpdb->get_row(
4000 $wpdb->prepare( $sql, $args_id),
4001 'ARRAY_A'
4002 );
4003
4004 return $answ_id;
4005 }
4006
4007 private function check_text_answer_exist( $poll_id, $user_answer ) {
4008 global $wpdb;
4009
4010 $answ_table = esc_sql($wpdb->prefix . "ayspoll_answers");
4011
4012 $sql = "SELECT * FROM " . $answ_table . " WHERE poll_id = %d AND answer = %s";
4013
4014 $answ_id = $wpdb->get_results(
4015 $wpdb->prepare( $sql, $poll_id, $user_answer),
4016 'ARRAY_A'
4017 );
4018 return (!empty($answ_id));
4019 }
4020
4021 private function get_text_answer_id($poll_id, $user_answer) {
4022 global $wpdb;
4023 $answ_table = esc_sql($wpdb->prefix . "ayspoll_answers");
4024
4025 $sql = $wpdb->prepare(
4026 "SELECT MAX(id) FROM $answ_table WHERE poll_id = %d AND answer = %s",
4027 $poll_id,
4028 $user_answer
4029 );
4030
4031 $last_id = $wpdb->get_var($sql);
4032
4033 if (is_null($last_id)) {
4034 return 0;
4035 }
4036
4037 return (int) $last_id;
4038 }
4039
4040 public static function get_answer_by_ids( $ids ) {
4041 global $wpdb;
4042 $sql = "SELECT * FROM {$wpdb->prefix}ayspoll_answers
4043 WHERE id IN (".$ids.")";
4044 return $wpdb->get_results($sql, 'ARRAY_A');
4045 }
4046
4047 public function check_shedule_expired_poll( $args ) {
4048 $id = absint(intval($args));
4049 $poll_options = $this->get_poll_by_id($id);
4050 $options = $poll_options['styles'];
4051
4052 $is_expired = true;
4053 $startDate = '';
4054 $endDate = '';
4055 $current_time = strtotime(current_time( "Y:m:d H:i:s" ));
4056 if (isset($options['active_date_check']) && !empty($options['active_date_check'])) {
4057 if (isset($options['activeInterval']) && isset($options['deactiveInterval'])) {
4058 if (isset($options['activeIntervalSec']) && !empty($options['activeIntervalSec'])) {
4059 $startDate = strtotime($options['activeInterval']." ".$options['activeIntervalSec']);
4060 }
4061 else{
4062 $startDate = strtotime($options['activeInterval']);
4063 }
4064
4065 if (isset($options['deactiveIntervalSec']) && !empty($options['deactiveIntervalSec'])) {
4066 $endDate = strtotime($options['deactiveInterval']." ".$options['deactiveIntervalSec']);
4067 }
4068 else{
4069 $endDate = strtotime($options['deactiveInterval']);
4070 }
4071
4072 if ($startDate < $current_time && $endDate > $current_time) {
4073 $is_expired = true;
4074 }else{
4075 $is_expired = false;
4076 }
4077 }
4078 }
4079 $published = (isset($options['published']) && intval($options['published']) === 0) ? false : true;
4080 return $is_expired && $published ? true : false;
4081 }
4082
4083 protected function hex2rgba($color, $opacity = false){
4084
4085 $default = 'rgb(0,0,0)';
4086
4087 //Return default if no color provided
4088 if (empty($color))
4089 return $default;
4090
4091 //Sanitize $color if "#" is provided
4092 if ($color[0] == '#') {
4093 $color = substr($color, 1);
4094 }else{
4095 return $color;
4096 }
4097
4098 //Check if color has 6 or 3 characters and get values
4099 if (strlen($color) == 6) {
4100 $hex = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]);
4101 } elseif (strlen($color) == 3) {
4102 $hex = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]);
4103 } else {
4104 return $default;
4105 }
4106
4107 //Convert hexadec to rgb
4108 $rgb = array_map('hexdec', $hex);
4109
4110 //Check if opacity is set(rgba or rgb)
4111 if ($opacity) {
4112 if (abs($opacity) > 1)
4113 $opacity = 1.0;
4114 $output = 'rgba(' . implode(",", $rgb) . ',' . $opacity . ')';
4115 } else {
4116 $output = 'rgb(' . implode(",", $rgb) . ')';
4117 }
4118
4119 //Return rgb(a) color string
4120 return $output;
4121 }
4122
4123 public function rgb2hex( $rgb ) {
4124 if ($rgb[0] == '#') {
4125 return $rgb;
4126 }
4127 $colors = explode(',', rtrim(explode('(', $rgb)[1], ')'));
4128
4129 return sprintf("#%02x%02x%02x", $colors[0], $colors[1], $colors[2]);
4130 }
4131
4132 public static function ays_poll_get_limit_user_count_by_id($poll_id, $user_id){
4133 global $wpdb;
4134
4135 $id = absint(intval($poll_id));
4136 $reports_table = esc_sql($wpdb->prefix."ayspoll_reports");
4137 $answers_table = esc_sql($wpdb->prefix."ayspoll_answers");
4138
4139 $sql = "SELECT COUNT(*)
4140 FROM ".$reports_table."
4141 INNER JOIN ".$answers_table."
4142 ON ".$answers_table.".id=".$reports_table.".answer_id
4143 WHERE ".$answers_table.".poll_id = ".$id." AND ".$reports_table.".user_id = ".$user_id;
4144
4145 $result = intval($wpdb->get_var($sql));
4146
4147 return $result;
4148 }
4149
4150 public static function ays_poll_get_limit_user_count_by_ip($poll_id){
4151 global $wpdb;
4152 $id = absint(intval($poll_id));
4153 $user_ip = self::get_user_ip_validated();
4154 $reports_table = esc_sql($wpdb->prefix."ayspoll_reports");
4155 $answers_table = esc_sql($wpdb->prefix."ayspoll_answers");
4156
4157 $sql = "SELECT COUNT(*)
4158 FROM ".$reports_table."
4159 INNER JOIN ".$answers_table."
4160 ON ".$answers_table.".id=".$reports_table.".answer_id
4161 WHERE ".$answers_table.".poll_id = ".$id." AND ".$reports_table.".user_ip = '". $user_ip ."'";
4162
4163 $result = intval($wpdb->get_var($sql));
4164
4165 return $result;
4166 }
4167
4168 public function ays_poll_get_results($id) {
4169
4170 global $wpdb;
4171 $content = '';
4172 $id = absint(intval($id));
4173 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
4174 $polls_table = esc_sql($wpdb->prefix."ayspoll_polls");
4175
4176
4177 $poll_sql = "SELECT * FROM ".$polls_table." WHERE id =%d";
4178 $polls = $wpdb->get_row(
4179 $wpdb->prepare( $poll_sql, $id),
4180 'ARRAY_A'
4181 );
4182 $votes_count = $this->get_poll_results_count_by_id($id);
4183 $poll = $this->get_poll_by_id($id);
4184 $polls_options = $poll['styles'];
4185
4186
4187 // $poll_answer_sorting = isset($polls_options['result_sort_type']) && $polls_options['result_sort_type'] != "none" ? $polls_options['result_sort_type'] : "ASC";
4188 $ans_sql = "SELECT * FROM ".$answ_table." WHERE poll_id =%d ORDER BY votes DESC";
4189 $poll_answers = $wpdb->get_results(
4190 $wpdb->prepare( $ans_sql, $id),
4191 'ARRAY_A'
4192 );
4193 if ($polls == null) {
4194 $content = '<p style="text-align:center;">No ratings yet</p>';
4195 }else{
4196 // $votes_count = $this->get_poll_results_count_by_id($id);
4197 // $poll = $this->get_poll_by_id($id);
4198 // $polls_options = $poll['styles'];
4199 $content .= "<div class='results-apm'>";
4200 if (intval($votes_count['res_count']) > 0) {
4201 $one_percent = 100/intval($votes_count['res_count']);
4202 }else{
4203 $one_percent = 1;
4204 }
4205
4206 $poll_show_answer_perc = isset($polls_options['show_res_percent']) && $polls_options['show_res_percent'] == 1 ? true : false;
4207 $poll_show_votes_count = isset($polls_options['show_votes_count']) && $polls_options['show_votes_count'] == 1 ? true : false;
4208 $poll_main_color = isset($polls_options['main_color']) && $polls_options['main_color'] != '' ? esc_attr($polls_options['main_color']) : '';
4209 $poll_bg_color = isset($polls_options['bg_color']) && $polls_options['bg_color'] != '' ? esc_attr($polls_options['bg_color']) : '';
4210 $poll_hide_result = isset($polls_options['hide_results']) && $polls_options['hide_results'] == 1 ? true : false;
4211 $poll_hide_result_message_check = isset($polls_options['hide_result_message']) && $polls_options['hide_result_message'] == 1 ? true : false;
4212 $poll_hide_result_message = isset($polls_options['hide_results_text']) && $polls_options['hide_results_text'] != "" ? wpautop($polls_options['hide_results_text']) : "";
4213 $poll_show_avatars = isset($polls_options['show_passed_users']) && $polls_options['show_passed_users'] == "on" ? true : false;
4214 $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;
4215 if($poll_hide_result){
4216 $content .= "<div >" . $poll_hide_result_message . "</div>";
4217 }
4218 else{
4219 $poll_answers_count = count($poll_answers);
4220
4221 if($poll_show_avatars){
4222 $results_table = $wpdb->prefix."ayspoll_reports";
4223 $answer_ids = array();
4224 if(isset($poll_answers) && !empty($poll_answers)){
4225 foreach($poll_answers as $answer => $value){
4226 $answer_ids[] = $value['id'];
4227 }
4228 }
4229 $answer_ids = implode(',' , $answer_ids);
4230 $sql_users = "SELECT `user_id` , `answer_id`
4231 FROM ".$results_table."
4232 WHERE `answer_id` IN (".$answer_ids.")
4233 GROUP BY user_id, answer_id
4234 ORDER BY vote_date DESC";
4235 $user_res = $wpdb->get_results($sql_users , ARRAY_A);
4236 $user_pic_args = array(
4237 "class" => "ays-user-profile-pic"
4238 );
4239 $users_res_array = array();
4240 foreach($user_res as $ar){
4241 $users_res_array[$ar['answer_id']][] = intval( $ar['user_id'] );
4242 }
4243
4244 if(isset($poll_answers) && !empty($poll_answers)){
4245 foreach($poll_answers as $key => $answer){
4246 $user_answers = array();
4247 if( array_key_exists( $answer['id'], $users_res_array ) ){
4248 $user_answers = $this->ays_poll_get_avatars($answer['id'] , $users_res_array);
4249 }
4250 $poll_answers[$key]['avatar'] = $user_answers;
4251 }
4252 }
4253 }
4254 foreach ($poll_answers as $ans_key => $ans_val) {
4255 $poll_avatars_content = "";
4256 $poll_user_avatars = "";
4257 $answer_img = (isset( $ans_val['answer_img'] ) && $ans_val['answer_img'] != '') ? $ans_val['answer_img'] : "";
4258 if(isset($ans_val["avatar"]) && !empty($ans_val["avatar"])){
4259 $x = array_splice($ans_val["avatar"] , 0 ,$poll_avatars_count);
4260 $poll_user_avatars = implode(" " , $x);
4261
4262 }
4263 if($poll_show_avatars && $poll_user_avatars != ""){
4264 $poll_avatars_content = '<div class="ays-user-count">
4265 '.$poll_user_avatars.'
4266 <div class="ays-users-profile-pics">
4267 <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"].'>
4268 </div>
4269 </div>';
4270 }
4271 $perc_cont = '';
4272 $percent = round($one_percent*intval($ans_val['votes']));
4273 $perc_conta_hide_or_no = '';
4274 if($poll_show_answer_perc){
4275 if ($percent == 0) {
4276 $perc_cont = '0 %';
4277 $perc_conta_hide_or_no = '';
4278 }else{
4279 $perc_cont = $percent.' %';
4280 $perc_conta_hide_or_no = '('.$percent.'%'.')';
4281 }
4282
4283 }
4284
4285 $answer_votes_count = '';
4286 if($poll_show_votes_count){
4287 $answer_votes_count = isset($ans_val['votes']) ? esc_attr($ans_val['votes']) : '';
4288 }
4289 switch ($polls['type']) {
4290 case 'choosing':
4291 $content .= "<div class='ays-poll-answers-box'>";
4292 if($answer_img != ''){
4293 $content .= "<div class='ays-poll-answers-image-box'>
4294
4295 <img src='" . $answer_img ."' class='ays-poll-answers-current-image'>
4296
4297 </div>";
4298 }
4299
4300 $content .= '<div class="ays-poll-answer-text-and-percent-box">';
4301 $content .= '<div class="answer-title flex-apm">
4302 <span class="answer-text">' . stripslashes($ans_val['answer']) . '</span>
4303 <span class="answer-votes">'.$answer_votes_count.' '.$perc_conta_hide_or_no.'</span>
4304 </div>
4305 ' . $poll_avatars_content . '
4306 <div class="answer-percent-res" style="width: ' . ($percent == 0 ? '10' : $percent) . '%;
4307 border-radius: 20px;
4308 background-color: ' . $poll_main_color . ';
4309 color: ' . $poll_bg_color . ';
4310 padding-left: 10px;
4311 font-size: 15px;
4312 text-align: left;">' . $perc_cont . '</div>';
4313 $content .= '</div>';
4314 $content .= '</div>';
4315 break;
4316
4317 case 'rating':
4318 switch ($polls['view_type']) {
4319 case 'star':
4320 $star_type = '';
4321 for ($i=0; $i < intval($ans_val['answer']); $i++) {
4322 $star_type .= '<i class="ays_poll_far ays_poll_fa-star far"></i>';
4323 }
4324 $content .= '<div class="answer-title flex-apm">
4325 <span class="answer-text">'.$star_type.'</span>
4326 <span class="answer-votes">'.$answer_votes_count.'</span>
4327 </div>
4328 '.$poll_avatars_content.'
4329 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4330 break;
4331
4332 case 'emoji':
4333 $emojy_type = '';
4334 if ($poll_answers_count == 3) {
4335 switch (intval($ans_val['answer'])) {
4336 case 1:
4337 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
4338 break;
4339 case 2:
4340 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-meh far"></i>';
4341 break;
4342 case 3:
4343 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
4344 break;
4345 default:
4346 break;
4347 }
4348 }else{
4349 switch (intval($ans_val['answer'])) {
4350 case 1:
4351 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-tired far"></i>';
4352 break;
4353 case 2:
4354 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
4355 break;
4356 case 3:
4357 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-meh far"></i>';
4358 break;
4359 case 4:
4360 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
4361 break;
4362 case 5:
4363 $emojy_type .= '<i class="ays_poll_far ays_poll_fa-dizzy far"></i>';
4364 break;
4365 default:
4366 break;
4367 }
4368 }
4369
4370 $content .= '<div class="answer-title flex-apm">
4371 <span class="answer-text">'.$emojy_type.'</span>
4372 <span class="answer-votes">'.$answer_votes_count.'</span>
4373 </div>
4374 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4375
4376 break;
4377 default:
4378 break;
4379 }
4380 break;
4381
4382 case 'voting':
4383 switch ($polls['view_type']) {
4384 case 'hand':
4385 $hand_type = '';
4386 if (intval($ans_val['answer'] == 1)) {
4387 $hand_type = '<i class="ays_poll_far ays_poll_fa-thumbs-up far"></i>';
4388 }else{
4389 $hand_type = '<i class="ays_poll_far ays_poll_fa-thumbs-down far"></i>';
4390 }
4391 $content .= '<div class="answer-title flex-apm">
4392 <span class="answer-text">'.$hand_type.'</span>
4393 <span class="answer-votes">'.$answer_votes_count.'</span>
4394 </div>
4395 '.$poll_avatars_content.'
4396 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4397 break;
4398
4399 case 'emoji':
4400 $emojy_type = '';
4401 if (intval($ans_val['answer'] == 1)) {
4402 $emojy_type = '<i class="ays_poll_far ays_poll_fa-smile far"></i>';
4403 }else{
4404 $emojy_type = '<i class="ays_poll_far ays_poll_fa-frown far"></i>';
4405 }
4406 $content .= '<div class="answer-title flex-apm">
4407 <span class="answer-text">'.$emojy_type.'</span>
4408 <span class="answer-votes">'.$answer_votes_count.'</span>
4409 </div>
4410 '.$poll_avatars_content.'
4411 <div class="answer-percent" style="width: '.$percent.'%; background-color: '.$poll_main_color.'; color: '.$poll_bg_color.';">'.$perc_cont.'</div>';
4412
4413 break;
4414 default:
4415 break;
4416 }
4417 break;
4418 default:
4419 break;
4420 }
4421
4422 }
4423 }
4424
4425 }
4426 $content .= "</div>";
4427 return $content;
4428 }
4429
4430 public function intToRoman($num) {
4431 $map = array(
4432 1000 => 'M', 900 => 'CM', 500 => 'D', 400 => 'CD',
4433 100 => 'C', 90 => 'XC', 50 => 'L', 40 => 'XL',
4434 10 => 'X', 9 => 'IX', 5 => 'V', 4 => 'IV', 1 => 'I'
4435 );
4436 $roman = '';
4437 foreach ($map as $value => $symbol) {
4438 while ($num >= $value) {
4439 $roman .= $symbol;
4440 $num -= $value;
4441 }
4442 }
4443 return $roman;
4444 }
4445
4446 public function ays_answer_numbering($numbering , $count){
4447 $keyword_arr = array();
4448 switch ($numbering) {
4449 case '1.':
4450 $char_min_val = 1;
4451 for($x = $char_min_val; $x <= $count; $x++){
4452 $keyword_arr[] = $x .".";
4453 }
4454 break;
4455 case '1)':
4456 $char_min_val = 1;
4457 for($x = $char_min_val; $x <= $count; $x++){
4458 $keyword_arr[] = $x .")";
4459 }
4460 break;
4461 case 'A.':
4462 $columns = array();
4463 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4464 foreach($keyword_arr as $key => $value){
4465 $columns[] = $value . ".";
4466 }
4467 $keyword_arr = $columns;
4468 break;
4469 case 'A)':
4470 $columns = array();
4471 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4472 foreach($keyword_arr as $key => $value){
4473 $columns[] = $value . ")";
4474 }
4475 $keyword_arr = $columns;
4476 break;
4477 case 'a.':
4478 $columns = array();
4479 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4480 foreach($keyword_arr as $key => $value){
4481 $columns[] = strtolower($value) . ".";
4482 }
4483 $keyword_arr = $columns;
4484 break;
4485 case 'a)':
4486 $columns = array();
4487 $keyword_arr = $this->ays_poll_generate_keyword_array($count);
4488 foreach($keyword_arr as $key => $value){
4489 $columns[] = strtolower($value) . ")";
4490 }
4491 $keyword_arr = $columns;
4492 break;
4493 case 'VI.':
4494 $columns = array();
4495 for ($i = 1; $i <= $count; $i++) {
4496 $columns[] = $this->intToRoman($i) . ".";
4497 }
4498 $keyword_arr = $columns;
4499 break;
4500 default:
4501 break;
4502 }
4503 return $keyword_arr;
4504 }
4505 public static function ays_poll_generate_keyword_array( $max_val ) {
4506 if (is_null($max_val) || $max_val == '') {
4507 $max_val = 6; //'F';
4508 }
4509 $max_val = absint(intval($max_val)) - 1;
4510 $keyword_arr = array();
4511 $letters = range('A', 'Z');
4512 if($max_val <= 25){
4513 $max_alpha_val = $letters[$max_val];
4514 }
4515 elseif($max_val > 25){
4516 $dividend = ($max_val + 1);
4517 $max_alpha_val = '';
4518 $modulo = 0;
4519 while ($dividend > 0){
4520 $modulo = ($dividend - 1) % 26;
4521 $max_alpha_val = $letters[$modulo] . $max_alpha_val;
4522 $dividend = floor((($dividend - $modulo) / 26));
4523 }
4524 }
4525 $keyword_arr = self::ays_poll_create_columns_array( $max_alpha_val );
4526 return $keyword_arr;
4527 }
4528 public static function ays_poll_create_columns_array($end_column, $first_letters = '') {
4529 $columns = array();
4530 $letters = range('A', 'Z');
4531 $length = strlen($end_column);
4532 // Iterate over 26 letters.
4533 foreach ($letters as $letter) {
4534 // Paste the $first_letters before the next.
4535 $column = $first_letters . $letter;
4536 // Add the column to the final array.
4537 $columns[] = $column;
4538 // If it was the end column that was added, return the columns.
4539 if ($column == $end_column)
4540 return $columns;
4541 }
4542 // Add the column children.
4543 foreach ($columns as $column) {
4544 // Don't itterate if the $end_column was already set in a previous itteration.
4545 // Stop iterating if you've reached the maximum character length.
4546 if (!in_array($end_column, $columns) && strlen($column) < $length) {
4547 $new_columns = self::ays_poll_create_columns_array($end_column, $column);
4548 // Merge the new columns which were created with the final columns array.
4549 $columns = array_merge($columns, $new_columns);
4550 }
4551 }
4552 return $columns;
4553 }
4554
4555 public function get_answer_by_id_multi( $id ) {
4556 global $wpdb;
4557 $args_id = absint(intval($id));
4558 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
4559 // $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
4560 // $sql = "SELECT a.*, COUNT(r.id) as voted FROM ".$answ_table." as a
4561 // JOIN ".$rep_table." as r
4562 // ON r.answer_id = a.id
4563 // WHERE a.id = %d";
4564
4565 $sql = "SELECT * FROM ".$answ_table."
4566 WHERE id = %d";
4567
4568 $answ_id = $wpdb->get_results(
4569 $wpdb->prepare( $sql, $args_id),
4570 'ARRAY_A'
4571 );
4572
4573 return $answ_id;
4574 }
4575
4576 // Users avatars
4577 public function ays_poll_get_current_answer_users_pics(){
4578 global $wpdb;
4579 $results_table = $wpdb->prefix."ayspoll_reports";
4580
4581 $answer_id = isset($_POST['answer_id']) && $_POST['answer_id'] != "" ? absint($_POST['answer_id']) : null;
4582 $user_answers = array();
4583
4584 if(isset($answer_id)){
4585 $sql_users = "SELECT `user_id`
4586 FROM ".$results_table."
4587 WHERE `answer_id` = ".$answer_id."
4588 GROUP BY user_id, answer_id
4589 ORDER BY vote_date DESC";
4590 $user_res = $wpdb->get_results($sql_users , ARRAY_A);
4591 if(isset($user_res)){
4592 $user_pic_args = array(
4593 "class" => "ays-user-profile-pic-popup"
4594 );
4595
4596 foreach($user_res as $key => $value){
4597 $user_id = isset($value['user_id']) && $value['user_id'] != "" ? intval($value['user_id']) : 0;
4598 if($user_id == 0){
4599 continue;
4600 }
4601
4602 $user_avatars = get_avatar($user_id, 24, $default = '', $alt = '', $user_pic_args);
4603 $user_data = get_userdata($user_id);
4604 $user_name = "";
4605 if(isset($user_data)){
4606 if(isset($user_data->data)){
4607 $user_name = isset($user_data->data->display_name) && $user_data->data->display_name != "" ? esc_attr($user_data->data->display_name) : "";
4608 }
4609 }
4610 $user_avatars = isset($user_avatars) && $user_avatars ? $user_avatars : '';
4611 $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>";
4612 }
4613 }
4614 }
4615 echo json_encode($user_answers);
4616 wp_die();
4617 }
4618
4619 public function ays_add_answer_poll($data) {
4620 global $wpdb;
4621 $poll_id = absint($data['poll_id']);
4622 $new_answer = wp_filter_kses($data['new_answer']);
4623 $poll_add_answer_require = $data['admin_require'];
4624 $poll_answers_count = isset($data['answers_count']) && $data['answers_count'] > 0 ? intval($data['answers_count']) : 1;
4625 $if_text_type = isset($data['if_text_type']) && $data['if_text_type'] ? true : false;
4626
4627 $show_user_added = 0;
4628 // $votes = 0;
4629 // if($if_text_type){
4630 // $votes = 1;
4631 // }
4632 if(!$poll_add_answer_require){
4633 $show_user_added = 1;
4634 }
4635 $wpdb->insert(
4636 "{$wpdb->prefix}ayspoll_answers",
4637 array(
4638 'poll_id' => $poll_id,
4639 'answer' => $new_answer,
4640 'votes' => 0,
4641 'ordering' => ($poll_answers_count + 1),
4642 'user_added' => 1,
4643 'show_user_added' => $show_user_added
4644 ),
4645 array(
4646 '%d',
4647 '%s',
4648 '%d',
4649 '%d',
4650 '%d',
4651 '%d',
4652 )
4653 );
4654
4655 $last_id = $wpdb->insert_id;
4656 return array(
4657 "new_id" => strval($last_id)
4658 );
4659 }
4660
4661 public function ays_generate_display_polls_method($attr){
4662 $recent_poll_ids = $this->ays_recent_poll_ids($attr);
4663 $content = '<div class="ays_poll_recent_polls">';
4664 $polls = array();
4665 foreach ($recent_poll_ids as $key => $last_poll_id) {
4666 $poll_id = (isset($last_poll_id['id']) && intval($last_poll_id['id']) != '') ? intval($last_poll_id['id']) : '';
4667 $shortcode = '[ays_poll id="'.$poll_id.'"]';
4668 $polls[] = do_shortcode( $shortcode );
4669 }
4670 $content .= implode( '', $polls );
4671 $content .= '</div>';
4672 return str_replace(array("\r\n", "\n", "\r"), "\n", $content);
4673 }
4674
4675 public function ays_recent_poll_ids($data){
4676 global $wpdb;
4677 $polls_table = $wpdb->prefix.'ayspoll_polls';
4678
4679 $ays_recent_poll_order_by = (isset($data['orderby']) && $data['orderby'] != '') ? sanitize_text_field($data['orderby']) : "recent";
4680 $ays_recent_poll_count = (isset($data['count']) && $data['count'] != '') ? intval($data['count']) : 5;
4681
4682 $last_polls_sql = "SELECT id FROM {$polls_table} WHERE styles LIKE '%\"published\":1%' ";
4683
4684 switch ($ays_recent_poll_order_by) {
4685 case 'recent':
4686 $last_polls_sql .= "ORDER BY id DESC LIMIT ".$ays_recent_poll_count;
4687 break;
4688 case 'random':
4689 $last_polls_sql .= "ORDER BY RAND() LIMIT ".$ays_recent_poll_count;
4690 break;
4691 default:
4692 $last_polls_sql .= "ORDER BY id DESC LIMIT ".$ays_recent_poll_count;
4693 break;
4694 }
4695
4696 $last_poll_ids = $wpdb->get_results($last_polls_sql,'ARRAY_A');
4697
4698 return $last_poll_ids;
4699 }
4700
4701 public function ays_set_poll_fields_placeholders_texts(){
4702
4703 /*
4704 * Get Poll fields placeholders from database
4705 */
4706
4707 $settings_placeholders_texts = $this->settings->ays_get_setting('fields_placeholders');
4708 if($settings_placeholders_texts){
4709 $settings_placeholders_texts = json_decode(stripcslashes($settings_placeholders_texts), true);
4710 }else{
4711 $settings_placeholders_texts = array();
4712 }
4713
4714 $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';
4715
4716 $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';
4717
4718 $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';
4719
4720
4721 $poll_fields_placeholder_name_text = $poll_fields_placeholder_name === 'Name' ?esc_html__('Name', "poll-maker") : $poll_fields_placeholder_name;
4722 $poll_fields_placeholder_email_text = $poll_fields_placeholder_email === 'Email' ?esc_html__('Email', "poll-maker") : $poll_fields_placeholder_email;
4723 $poll_fields_placeholder_phone_text = $poll_fields_placeholder_phone === 'Phone' ?esc_html__('Phone', "poll-maker") : $poll_fields_placeholder_phone;
4724
4725
4726 $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';
4727
4728 $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';
4729
4730 $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';
4731
4732
4733 $poll_fields_label_name_text = $poll_fields_label_name === 'Name' ?esc_html__('Name', "poll-maker") : $poll_fields_label_name;
4734 $poll_fields_label_email_text = $poll_fields_label_email === 'Email' ?esc_html__('Email', "poll-maker") : $poll_fields_label_email;
4735 $poll_fields_label_phone_text = $poll_fields_label_phone === 'Phone' ?esc_html__('Phone', "poll-maker") : $poll_fields_label_phone;
4736
4737 $texts = array(
4738 'namePlaceholder' => $poll_fields_placeholder_name_text,
4739 'emailPlaceholder' => $poll_fields_placeholder_email_text,
4740 'phonePlaceholder' => $poll_fields_placeholder_phone_text,
4741
4742 'nameLabel' => $poll_fields_label_name_text,
4743 'emailLabel' => $poll_fields_label_email_text,
4744 'phoneLabel' => $poll_fields_label_phone_text,
4745 );
4746
4747 return $texts;
4748 }
4749
4750 public function ays_autoembed( $content ) {
4751 global $wp_embed;
4752 $content = stripslashes( wpautop( $content ) );
4753 $content = $wp_embed->autoembed( $content );
4754 if ( strpos( $content, '[embed]' ) !== false ) {
4755 $content = $wp_embed->run_shortcode( $content );
4756 }
4757 $content = do_shortcode( $content );
4758 return $content;
4759 }
4760
4761 public function replace_message_variables($content, $data){
4762 foreach($data as $variable => $value){
4763 $content = str_replace("%%".$variable."%%", $value, $content);
4764 }
4765 return $content;
4766 }
4767
4768 public function get_user_profile_data(){
4769
4770 $user_first_name = '';
4771 $user_last_name = '';
4772 $user_nickname = '';
4773
4774 $user_id = get_current_user_id();
4775 if($user_id != 0){
4776 $usermeta = get_user_meta( $user_id );
4777 if($usermeta !== null){
4778 $user_first_name = (isset($usermeta['first_name'][0]) && $usermeta['first_name'][0] != '' ) ? sanitize_text_field( $usermeta['first_name'][0] ) : '';
4779 $user_last_name = (isset($usermeta['last_name'][0]) && $usermeta['last_name'][0] != '' ) ? sanitize_text_field( $usermeta['last_name'][0] ) : '';
4780 $user_nickname = (isset($usermeta['nickname'][0]) && $usermeta['nickname'][0] != '' ) ? sanitize_text_field( $usermeta['nickname'][0] ) : '';
4781 }
4782 }
4783
4784 $message_data = array(
4785 'user_first_name' => $user_first_name,
4786 'user_last_name' => $user_last_name,
4787 'user_nickname' => $user_nickname,
4788 );
4789
4790 return $message_data;
4791 }
4792
4793 public function ays_poll_get_recent_poll_id(){
4794 global $wpdb;
4795 $poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
4796 $rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
4797
4798 $last_polls_sql = "SELECT id FROM ".$poll_table." ORDER BY id DESC LIMIT 0, 1";
4799 $last_poll_sql = $wpdb->get_row($last_polls_sql , ARRAY_A);
4800
4801 $id = isset($last_poll_sql['id']) && $last_poll_sql['id'] !== 0 ? absint(intval($last_poll_sql['id'])) : "";
4802
4803 return $id;
4804 }
4805 }