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

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

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