*/
class Poll_Maker_Ays_Public {
/**
* The settings of this plugin.
*
* @since 1.0.0
* @access protected
* @var Poll_Maker_Settings_Actions object $settings The current settings of this plugin.
*/
protected $settings;
protected $fields_placeholders;
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
private static $p;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
private static $v;
/**
* The instance of this plugin public class.
*
* @since 1.0.0
* @access private
* @var Poll_Maker_Ays_Public object.
*/
private static $instance = null;
/**
* Initialize the class and set its properties.
*
* @param string $plugin_name The name of the plugin.
* @param string $version The version of this plugin.
*
* @since 1.0.0
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
self::$p = $plugin_name;
self::$v = $version;
add_shortcode('ays_poll', array($this, 'ays_poll_generate_shortcode'));
$this->settings = new Poll_Maker_Settings_Actions($this->plugin_name);
add_shortcode('ays_poll_all', array($this, 'ays_poll_all_generate_shortcode'));
add_shortcode('ayspoll_results', array($this, 'ays_poll_results_generate_shortcode'));
add_shortcode('ays_display_polls', array($this, 'ays_generate_display_polls_method'));
}
/**
* Get instance of this class. Singleton pattern.
*
* @since 1.4.0
*/
public static function get_instance() {
if (self::$instance == null) {
self::$instance = new Poll_Maker_Ays_Public(self::$p, self::$v);
}
return self::$instance;
}
/**
* Register the stylesheets for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Poll_Maker_Ays_Loader as all of the hooks are defined
* in that particular class.
*
* The Poll_Maker_Ays_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( 'ays_poll_font_awesome', plugin_dir_url(__FILE__) . '/css/poll-maker-ays-public-fonts.css', array(), $this->version, 'all');
}
public function enqueue_styles_early(){
$settings_options = $this->settings->ays_get_setting('options');
if($settings_options){
$settings_options = json_decode(stripcslashes($settings_options), true);
}else{
$settings_options = array();
}
// General CSS File
$settings_options['poll_exclude_general_css'] = isset($settings_options['poll_exclude_general_css']) ? esc_attr( $settings_options['poll_exclude_general_css'] ) : 'off';
$poll_exclude_general_css = (isset($settings_options['poll_exclude_general_css']) && esc_attr( $settings_options['poll_exclude_general_css'] ) == "on") ? true : false;
if( ! $poll_exclude_general_css ){
wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/poll-maker-ays-public.css', array(), $this->version, 'all');
}else{
if( ! is_front_page() ){
wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/poll-maker-ays-public.css', array(), $this->version, 'all');
}
}
$ays_is_elementor = $this->ays_is_elementor();
if ( $ays_is_elementor ) {
wp_enqueue_style( 'ays_poll_font_awesome', plugin_dir_url(__FILE__) . '/css/poll-maker-ays-public-fonts.css', array(), $this->version, 'all');
}
}
public function ays_is_elementor(){
if ( defined( 'ELEMENTOR_PATH' ) && class_exists( 'Elementor\Widget_Base' ) ) {
if ( class_exists( 'Elementor\Plugin' ) ) {
if ( is_callable( 'Elementor\Plugin', 'instance' ) ) {
$elementor = Elementor\Plugin::instance();
if ( isset( $elementor->preview ) ) {
return \Elementor\Plugin::$instance->preview->is_preview_mode();
}
}
}
}
}
/**
* Register the JavaScript for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Poll_Maker_Ays_Loader as all of the hooks are defined
* in that particular class.
*
* The Poll_Maker_Ays_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
//wp_enqueue_script($this->plugin_name . '-font-awesome', "https://use.fontawesome.com/releases/v5.5.0/js/all.js", array('jquery'), $this->version, true);
wp_enqueue_script("jquery");
wp_enqueue_script("jquery-effects-core");
wp_enqueue_script( $this->plugin_name . '-charts-google', plugin_dir_url(__FILE__) . 'js/google-chart.js', array('jquery'), $this->version, true);
wp_enqueue_script($this->plugin_name . '-ajax-public', plugin_dir_url(__FILE__) . 'js/poll-maker-public-ajax.js', array('jquery'), $this->version, true);
wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/poll-maker-ays-public.js', array('jquery'), $this->version, false);
wp_enqueue_script($this->plugin_name.'-category', plugin_dir_url(__FILE__) . 'js/poll-maker-public-category.js', array('jquery'), $this->version, false);
wp_enqueue_script( $this->plugin_name . '-autosize', plugin_dir_url(__FILE__) . 'js/poll-maker-autosize.js', array( 'jquery' ), $this->version, false );
wp_localize_script($this->plugin_name . '-ajax-public', 'poll_maker_ajax_public',
array(
'ajax_url' => admin_url('admin-ajax.php'),
'alreadyVoted' => __( "You have already voted" , $this->plugin_name ),
'day' => __( 'day', $this->plugin_name ),
'days' => __( 'days', $this->plugin_name ),
'hour' => __( 'hour', $this->plugin_name ),
'hours' => __( 'hours', $this->plugin_name ),
'minute' => __( 'minute', $this->plugin_name ),
'minutes' => __( 'minutes', $this->plugin_name ),
'second' => __( 'second', $this->plugin_name ),
'seconds' => __( 'seconds', $this->plugin_name ),
'thank_message' => __( 'Your answer has been successfully sent to the admin. Please wait for the approval.', $this->plugin_name ),
)
);
}
public function show_chart_js() {
wp_enqueue_script( $this->plugin_name . '-charts-google', plugin_dir_url(__FILE__) . 'js/google-chart.js', array('jquery'), $this->version, true);
}
// public function show_column_chart_js() {
// // wp_enqueue_script( $this->plugin_name . '-column-chart', 'https://www.gstatic.com/charts/loader.js', array('jquery'), $this->version, true);
// wp_enqueue_script( $this->plugin_name . '-column-chart', plugin_dir_url(__FILE__) . 'js/poll-maker-chart-loader.js', array('jquery'), $this->version, true);
// }
public function ays_poll_results_generate_shortcode($attr) {
ob_start();
$this->enqueue_styles();
$this->enqueue_scripts();
global $wpdb;
$answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
$rep_table = esc_sql($wpdb->prefix."ayspoll_reports");
$polls_table = esc_sql($wpdb->prefix."ayspoll_polls");
if(isset($attr['recent']) && $attr['recent'] === 'true'){
$id = $this->ays_poll_get_recent_poll_id();
}else{
$id = isset($attr['id']) && $attr['id'] !== 0 ? absint(intval($attr['id'])) : "";
}
$ans_sql = "SELECT * FROM ".$answ_table." WHERE poll_id =%d ORDER BY votes DESC";
$poll_answers = $wpdb->get_results(
$wpdb->prepare( $ans_sql, $id),
'ARRAY_A'
);
$poll_sql = "SELECT * FROM ".$polls_table." WHERE id =%d";
$polls = $wpdb->get_row(
$wpdb->prepare( $poll_sql, $id),
'ARRAY_A'
);
$settings_options = $this->settings->ays_get_setting('options');
$result_options_res = ($settings_options === false) ? json_encode(array()) : $settings_options;
$result_option_res = json_decode($result_options_res, true);
$chart_style = false;
if (isset( $result_option_res['show_result_view']) && ( $result_option_res['show_result_view'] == 'pie_chart' || $result_option_res['show_result_view'] == 'column_chart' )) {
$this->show_chart_js();
// $this->show_column_chart_js();
$chart_style = true;
}
if ($polls == null) {
$content = '
No ratings yet
';
}else{
$show_title = isset($polls['show_title']) && $polls['show_title'] == 0 ? false : true;
$poll_title = isset($polls['title']) ? $polls['title'] : '';
$votes_count = $this->get_poll_results_count_by_id($id);
$poll = $this->get_poll_by_id($id);
$polls_options = $poll['styles'];
if (intval($votes_count['res_count']) > 0) {
$one_percent = 100/intval($votes_count['res_count']);
}else{
$one_percent = 1;
}
$poll_border_color_res = isset($polls_options['border_color']) && $polls_options['border_color'] != "" ? esc_attr($polls_options['border_color']) : '';
// Poll question font size
$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";
$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";
$content = "";
$content .= "";
$content .= '';
if($show_title){
$content .= '
'.stripslashes($poll_title).'
';
}
$content .= '
'.stripslashes($polls['question']).'
';
$content .= "
";
if ($votes_count['res_count'] == 0) {
$content .= '
No ratings yet
';
}
if($chart_style){
$content .= '
';
$aysChartData = array(['','']);
foreach ($poll_answers as $key => $c_value) {
$all_votes_chart = 0;
$real_votes = isset($c_value['votes']) ? intval($c_value['votes']) : 0;
$all_votes_chart += $real_votes;
if(isset($poll["type"]) && $poll["type"] == "voting"){
$c_value['answer'] = $c_value['answer'] == 1 ? "Like" : "Dislike";
}
$arr = [$c_value['answer'] , $all_votes_chart];
array_push($aysChartData,$arr);
}
$show_result_view = isset($result_option_res['show_result_view']) && $result_option_res['show_result_view'] != '' ? $result_option_res['show_result_view'] : 'standart';
}
else{
$content .= '
';
}
$poll_answers_count = count($poll_answers);
$chart_font_size = "fontSize:12";
if(isset($poll["type"]) && ($poll["type"] == "voting" || $poll["type"] == "rating" )){
$chart_font_size = "fontSize:18";
}
$title_bg_color = isset($polls_options['main_color']) ? $polls_options['main_color'] : '#fff';
if($chart_style && $show_result_view == 'pie_chart'){
$content .= '
';
}
elseif($chart_style && $show_result_view == 'column_chart'){
$content .= '
';
}
else{
foreach ($poll_answers as $ans_key => $ans_val) {
$percent = round($one_percent*intval($ans_val['votes']));
if ($percent == 0) {
$perc_cont = '';
}else{
$perc_cont = $percent.' %';
}
switch ($polls['type']) {
case 'choosing':
$content .= '
'.stripslashes($ans_val['answer']).'
'.$ans_val['votes'].'
'.$perc_cont.'
';
break;
case 'rating':
switch ($polls['view_type']) {
case 'star':
$star_type = '';
for ($i=0; $i < intval($ans_val['answer']); $i++) {
$star_type .= '
';
}
$content .= '
'.$star_type.'
'.$ans_val['votes'].'
'.$perc_cont.'
';
break;
case 'emoji':
$emojy_type = '';
if ($poll_answers_count == 3) {
switch (intval($ans_val['answer'])) {
case 1:
$emojy_type .= '
';
break;
case 2:
$emojy_type .= '
';
break;
case 3:
$emojy_type .= '
';
break;
default:
break;
}
}else{
switch (intval($ans_val['answer'])) {
case 1:
$emojy_type .= '
';
break;
case 2:
$emojy_type .= '
';
break;
case 3:
$emojy_type .= '
';
break;
case 4:
$emojy_type .= '
';
break;
case 5:
$emojy_type .= '
';
break;
default:
break;
}
}
$content .= '
'.$emojy_type.'
'.$ans_val['votes'].'
'.$perc_cont.'
';
break;
default:
break;
}
break;
case 'voting':
switch ($polls['view_type']) {
case 'hand':
$hand_type = '';
if (intval($ans_val['answer'] == 1)) {
$hand_type = '
';
}else{
$hand_type = '
';
}
$content .= '
'.$hand_type.'
'.$ans_val['votes'].'
'.$perc_cont.'
';
break;
case 'emoji':
$emojy_type = '';
if (intval($ans_val['answer'] == 1)) {
$emojy_type = '
';
}else{
$emojy_type = '
';
}
$content .= '
'.$emojy_type.'
'.$ans_val['votes'].'
'.$perc_cont.'
';
break;
default:
break;
}
break;
default:
break;
}
}
}
$content .= '
';
}
echo $content;
return str_replace(array("\r\n", "\n", "\r"), '', ob_get_clean());
}
public function ays_poll_all_generate_shortcode($attr) {
ob_start();
global $wpdb;
$check_published = "published";
if(is_array($attr) && !empty($attr)){
$check_published = isset($attr['display']) && $attr['display'] == "all" ? "all" : "published";
}
$poll_table = esc_sql($wpdb->prefix."ayspoll_polls");
$sql = "SELECT id FROM ".$poll_table;
$poll = $wpdb->get_results($sql, 'ARRAY_A');
$this->enqueue_styles();
$this->enqueue_scripts();
$checker = array();
foreach ($poll as $poll_id) {
$current_id = isset($poll_id['id']) ? $poll_id['id'] : "";
$check_poll = $this->check_shedule_expired_poll( $current_id );
$checker[] = $check_poll;
if($check_published == 'published'){
if ($check_poll) {
$this->show_poll($poll_id);
}
}
elseif($check_published == 'all'){
$this->show_poll($poll_id);
}
}
if(array_sum($checker) == 0){
$poll_settings = $this->settings;
$general_options = ($poll_settings->ays_get_setting('options') !== false) ? json_decode($poll_settings->ays_get_setting('options') , true) : array();
$message = '';
if(!empty($general_options)){
$message = (isset($general_options['all_shortcode_message']) && $general_options['all_shortcode_message'] != '') ? esc_html($general_options['all_shortcode_message']) : '';
}
echo '
'.$message.'
';
}
return str_replace(array("\r\n", "\n", "\r"), '', ob_get_clean());
}
public function ays_poll_generate_shortcode( $attr ) {
ob_start();
$this->enqueue_styles();
$this->enqueue_scripts();
$this->show_poll($attr);
return str_replace(array("\r\n", "\n", "\r"), '', ob_get_clean());
}
public function show_poll( $attr ) {
if (isset($attr['id'])) {
return $this->ays_poll_generate_html($attr['id']);
} elseif (isset($attr['cat_id'])) {
return $this->ays_poll_category_generate_html($attr);
}
}
public function ays_poll_generate_html( $poll_id, $echo = true, $width = -1 ) {
global $wpdb;
if (!isset($poll_id) || null == $poll_id) {
return "";
}
$id = absint($poll_id);
$poll = $this->get_poll_by_id($id);
if (empty($poll)) {
return "";
}
$this_poll_id = uniqid("ays-poll-id-");
$options = $poll['styles'];
$poll_settings = $this->settings;
$general_options = ($poll_settings->ays_get_setting('options') === false) ? json_encode(array()) : json_decode($poll_settings->ays_get_setting('options'), true);
if (isset($options['published']) && intval($options['published']) === 0) {
return "";
}
$info_form = !empty($options['info_form']) && !empty($options['fields']);
$info_form_title = !empty($options['info_form_title']) ? $options['info_form_title'] : "
" . __("Please fill out the form:", $this->plugin_name) . " ";
$fields = !empty($options['fields']) ? explode(",", $options['fields']) : array();
$required_fields = !empty($options['required_fields']) ? explode(",", $options['required_fields']) : array();
$is_expired = false;
$is_start_soon = false;
$startDate = '';
$endDate = '';
$current_time = strtotime(current_time( "Y:m:d H:i:s" ));
$poll_check_exp_cont = isset($options['dont_show_poll_cont']) && $options['dont_show_poll_cont'] == 'on' ? true : false;
if (isset($options['active_date_check']) && !empty($options['active_date_check'])) {
if (isset($options['activeInterval']) && isset($options['deactiveInterval'])) {
if (isset($options['activeIntervalSec']) && !empty($options['activeIntervalSec'])) {
$startDate = strtotime($options['activeInterval']." ".$options['activeIntervalSec']);
$startDate_atr = $startDate - $current_time;
}
else{
$startDate = strtotime($options['activeInterval']);
$startDate_atr = $startDate - $current_time;
}
if (isset($options['deactiveIntervalSec']) && !empty($options['deactiveIntervalSec'])) {
$endDate = strtotime($options['deactiveInterval']." ".$options['deactiveIntervalSec']);
$endDate_atr = $endDate - $current_time;
}
else{
$endDate = strtotime($options['deactiveInterval']);
$endDate_atr = $endDate - $current_time;
}
if ($startDate > $current_time) {
$is_start_soon = true;
}
if ($startDate > $current_time || $endDate < $current_time) {
$is_expired = true;
}
}
}
$poll_directions = isset($options['poll_direction']) && $options['poll_direction'] != '' ? $options['poll_direction'] : 'ltr';
switch ($poll_directions) {
case 'ltr':
$poll_direction = 'ltr';
break;
case 'center':
$poll_direction = 'center';
break;
case 'rtl':
$poll_direction = 'rtl';
break;
default:
$poll_direction = 'ltr';
break;
}
if ($poll_direction == 'center') {
$poll_direction_center = "justify-content: center;";
}else{
$poll_direction_center = "";
}
$load_effect = isset($options['load_effect']) ? $options['load_effect'] : "opacity";
$load_gif = isset($options['load_effect']) && $options['load_effect'] == 'load_gif' && isset($options['load_gif']) ? $options['load_gif'] : "";
$poll_load_message_data = "";
if(isset($options['load_effect']) && $options['load_effect'] == "message"){
$poll_load_message = isset($options['effect_message']) && $options['effect_message'] != "" ? esc_attr($options['effect_message']) : "";
$poll_load_message_data = 'data-load-message="'.$poll_load_message.'"';
}
$result_sort = isset($options['result_sort_type']) ? $options['result_sort_type'] : "none";
if (isset($options['show_social']) && $options['show_social'] == 1) {
$show_social = true;
} else {
$show_social = false;
}
$without_vote = isset($options['enable_vote_btn']) && $options['enable_vote_btn'] == 0 ? 'apm-answers-without-submit' : "";
$with_vote = isset($options['enable_vote_btn']) && $options['enable_vote_btn'] != 0 ? true : false;
// Allow custom answer
$poll_allow_answer = (isset($options['poll_allow_answer']) && $options['poll_allow_answer'] == "on") ? "checked" : "";
// Require admin approval
$poll_allow_answer_require = (isset($options['poll_allow_answer_require']) && $options['poll_allow_answer_require'] == "on") ? "checked" : "";
if (isset($options['hide_results']) && $options['hide_results'] == 1) {
$hide_results = "1";
if (!empty($options['hide_results_text'])) {
$hide_results_text = wpautop($options['hide_results_text']);
} else {
$hide_results_text = __("Thanks for your answer", $this->plugin_name);
}
} else {
$hide_results = "0";
$hide_results_text = "";
}
if (isset( $options['redirect_after_submit'] ) && $options['redirect_after_submit'] == 1) {
$redirect_after_vote_url = '';
$redirect_users = 0;
$check_delay = isset($options['poll_enable_answer_redirect_delay']) && $options['poll_enable_answer_redirect_delay'] == "on" ? true : false;
$redirect_delay = 0;
if($check_delay){
$redirect_delay = isset($options['poll_every_answer_redirect_delay']) && $options['poll_every_answer_redirect_delay'] != "" ? esc_attr($options['poll_every_answer_redirect_delay']) : 0;
}
$redirect_url_href = '';
$redirect_url_checked = 1;
$redirect_after_vote = "
" . __("You will be redirected ".($redirect_delay <= 0 ? "" : " after ".$redirect_delay." seconds "), $this->plugin_name) . "
";
}elseif (isset($options['redirect_users']) && $options['redirect_users'] != 0 && !empty($options['redirect_after_vote_url'])) {
$redirect_after_vote_url = stripslashes($options['redirect_after_vote_url']);
$redirect_url_href = '';
$redirect_users = $options['redirect_users'];
$redirect_delay = $options['redirect_after_vote_delay'];
$redirect_url_checked = 0;
$redirect_after_vote = "
" . __("You will be redirected ".($redirect_delay <= 0 ? "" : " after ".$redirect_delay." seconds "), $this->plugin_name) . "
";
} else {
$redirect_after_vote_url = '';
$redirect_url_href = '';
$redirect_users = 0;
$redirect_delay = 0;
$redirect_url_checked = 0;
$redirect_after_vote = "";
}
$limit_users = 0;
$limitusers = isset($options['limit_users']) ? intval($options['limit_users']) : 0;
$load_poll = false;
$emoji = array(
"
",
"
",
"
",
"
",
"
",
);
$bg_color = $options['bg_color'];
$bg_image = isset($options['bg_image']) ? $options['bg_image'] : '';
$main_color = $options['main_color'];
$text_color = $options['text_color'];
$button_text_color = isset($options['button_text_color']) ? $options['button_text_color'] : $bg_color;
$button_bg_color = isset($options['button_bg_color']) ? $options['button_bg_color'] : $main_color;
$icon_color = $options['icon_color'];
$answer_bg_color = isset($options['answer_bg_color']) ? $options['answer_bg_color'] : 'transparent';
$answer_border_side = isset($options['answer_border_side']) ? $options['answer_border_side'] : 'all_sides';
$title_bg_color = isset($options['title_bg_color']) ? $options['title_bg_color'] : 'transparent';
$enable_pass_count = (isset($options['enable_pass_count']) && $options['enable_pass_count'] == 'on') ? true : false;
$poll_theme = isset($poll['theme_id']) && absint($poll['theme_id']) == 3 ? 'ays-minimal-theme' : '';
$answer_percent_color = $this->rgb2hex($main_color);
if (isset($poll['theme_id']) && absint($poll['theme_id']) != '') {
switch ( absint($poll['theme_id']) ) {
case 3:
case 7:
$answer_percent_color = $this->rgb2hex($icon_color);
break;
default:
$answer_percent_color = $this->rgb2hex($main_color);
break;
}
}
if ($enable_pass_count) {
$poll_result_reports = $this->get_poll_results_count_by_id($id);
$poll_result_reports = "
" . $poll_result_reports['res_count'] . "";
} else {
$poll_result_reports = '';
}
if ($width < 0) {
$poll_width = $options['width'] > 0 ? $options['width'] . "px" : "100%";
} elseif ($width == 0) {
$poll_width = "100%";
} else {
$poll_width = $width . "px";
}
$width_for_mobile = ( isset( $options['width_for_mobile'] ) && $options['width_for_mobile'] != '' ) ? absint( $options['width_for_mobile'] ) : 0;
if ($width_for_mobile < 0) {
$poll_width_for_mobile = $width_for_mobile > 0 ? $width_for_mobile . "px" : "100%";
} elseif ($width_for_mobile == 0) {
$poll_width_for_mobile = "100%";
} else {
$poll_width_for_mobile = $width_for_mobile . "px";
}
$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';
if ($ays_see_result_button === 'See Results') {
$ays_see_result_button_text = __("See Results", $this->plugin_name);
}else{
$ays_see_result_button_text = $ays_see_result_button;
}
$pollTypeShort = array(
'choosing' => 'choose',
'voting' => 'rate',
'rating' => 'vote',
'text' => 'text'
);
$show_res_btn_sch = (isset($options['show_result_btn_schedule']) && $options['show_result_btn_schedule'] == 1) ? true : false;
$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';
$show_res_see_display = $show_res_see == 'without_see' ? 'display:none;' : '';
$see_result_button = '';
$see_result_button = wp_nonce_field('ays_finish_poll', 'ays_finish_poll') . "
";
if($poll['type'] != "text"){
$see_result_button .= " ";
}
$see_result_button .= '
';
// Results bar in RGBA
$result_in_rgba = (isset($options['result_in_rgba']) && $options['result_in_rgba'] == 'on' ) ? true : false;
// Enable View more button
$enable_view_more_button = (isset($options['enable_view_more_button']) && $options['enable_view_more_button'] == 'on' ) ? true : false;
$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;
/*
* Poll container background gradient
*
*/
// Checking exists background gradient option
$options['enable_background_gradient'] = (!isset($options['enable_background_gradient'])) ? "off" : $options['enable_background_gradient'];
if(isset($options['background_gradient_color_1']) && $options['background_gradient_color_1'] != ''){
$background_gradient_color_1 = $options['background_gradient_color_1'];
}else{
$background_gradient_color_1 = "#103251";
}
if(isset($options['background_gradient_color_2']) && $options['background_gradient_color_2'] != ''){
$background_gradient_color_2 = $options['background_gradient_color_2'];
}else{
$background_gradient_color_2 = "#607593";
}
if(isset($options['poll_gradient_direction']) && $options['poll_gradient_direction'] != ''){
$poll_gradient_direction = $options['poll_gradient_direction'];
}else{
$poll_gradient_direction = 'vertical';
}
switch($poll_gradient_direction) {
case "horizontal":
$poll_gradient_direction = "to right";
break;
case "diagonal_left_to_right":
$poll_gradient_direction = "to bottom right";
break;
case "diagonal_right_to_left":
$poll_gradient_direction = "to bottom left";
break;
default:
$poll_gradient_direction = "to bottom";
}
// Poll container background gradient enabled/disabled
if(isset($options['enable_background_gradient']) && $options['enable_background_gradient'] == "on"){
$enable_background_gradient = true;
}else{
$enable_background_gradient = false;
}
if( isset($bg_image) && $bg_image != false){
$poll_styles = "background-image: url('".$bg_image."');";
}elseif($enable_background_gradient) {
$poll_styles = "background-image: linear-gradient($poll_gradient_direction, $background_gradient_color_1, $background_gradient_color_2);";
}elseif (isset($bg_color)) {
$poll_styles = "background-color: ".$bg_color.";";
}
else{
$poll_styles = "background-image: unset;";
}
$options['enable_answer_style'] = isset($options['enable_answer_style']) ? $options['enable_answer_style'] : 'on';
$answer_style = $options['enable_answer_style'] == 'on' ? true : false;
$disable_answer_hover = isset($options['disable_answer_hover']) && $options['disable_answer_hover'] == 1 ? 'disable_hover' : 'ays_enable_hover';
//Bg image position
$poll_bg_image_position = (isset($options['poll_bg_image_position']) && $options['poll_bg_image_position'] != "") ? $options['poll_bg_image_position'] : 'center center';
$poll_bg_img_in_finish_page = (isset($options['poll_bg_img_in_finish_page']) && $options['poll_bg_img_in_finish_page'] == "on") ? 'true' : "false";
$poll_bg_img_in_finish_page_off_color = (isset($options['bg_color']) && $options['bg_color'] != "") ? esc_attr($options['bg_color']) : "false";
// Poll minimal height
$poll_min_height_val = (isset($options['poll_min_height']) && $options['poll_min_height'] != '') ? absint(intval($options['poll_min_height'])) : 0;
// Poll answer font size
$poll_answer_font_size = (isset($options['answer_font_size']) && $options['answer_font_size'] != '') ? $options['answer_font_size']."px" : '15px';
// Poll answers font size on mobile
$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';
// Poll see results button in limitations
$poll_see_result_button_check = (isset($options['see_result_button']) && $options['see_result_button'] == 'on') ? true : false;
// Loading font size
$poll_loader_font_size = (isset($options['loader_font_size']) && $options['loader_font_size'] != '') ? esc_attr($options['loader_font_size']) : '64';
if(!isset($options['see_result_button'])){
$poll_see_result_button_check = true;
}
$poll_see_result_radio = (isset($options['see_result_radio']) && $options['see_result_radio'] != '') ? esc_attr($options['see_result_radio']) : 'ays_see_result_button';
$poll_show_result_button_limit = isset($poll_see_result_radio) && $poll_see_result_radio == 'ays_see_result_button' ? true : false;
$poll_see_result_immediately = isset($poll_see_result_radio) && $poll_see_result_radio == 'ays_see_result_immediately' ? true : false;
$poll_show_avatars = isset($options['show_passed_users']) && $options['show_passed_users'] == "on" ? true : false;
$poll_logo_image = (isset($options['logo_image']) && $options['logo_image'] != '') ? esc_url($options['logo_image']) : '';
$poll_logo_check = (isset($poll_logo_image) && $poll_logo_image != '') ? true : false;
$poll_image_cont = '';
// Poll logo image url
$poll_logo_image_url = isset($options['poll_logo_url']) && $options['poll_logo_url'] != "" ? esc_attr($options['poll_logo_url']) : "";
$poll_logo_image_url_check = isset($options['poll_enable_logo_url']) && $options['poll_enable_logo_url'] == "on" ? true : false;
$poll_logo_image_url_href = "javascript:void(0)";
if($poll_logo_image_url_check){
if($poll_logo_image_url != ""){
if(filter_var($poll_logo_image_url, FILTER_VALIDATE_URL)){
$poll_logo_image_url_href = $poll_logo_image_url;
}
}
}
//Open logo URL in new tab
$options['poll_logo_url_new_tab' ] = (isset($options['poll_logo_url_new_tab' ]) && $options['poll_logo_url_new_tab' ] == 'on') ? 'on' : 'off';
$poll_logo_image_url_check_new_tab = (isset($options['poll_logo_url_new_tab' ]) && $options['poll_logo_url_new_tab' ] == 'on') ? true : false;
$target_blank = ( $poll_logo_image_url_check_new_tab && $poll_logo_image_url_check && $poll_logo_image_url != "" ) ? "target='_blank'" : "" ;
//Poll Logo title
$poll_logo_title = (isset( $options['poll_logo_title' ] ) && $options['poll_logo_title' ] != '') ? esc_attr( $options['poll_logo_title' ] ) : '';
if($poll_logo_check){
$poll_image_cont = "
";
}
if ($poll_min_height_val == 0) {
$poll_min_height = '';
}else{
$poll_min_height = 'min-height: '. $poll_min_height_val .'px;';
}
// Show answers numbering
$show_answers_numbering = (isset($options['show_answers_numbering']) && sanitize_text_field( $options['show_answers_numbering'] ) != '') ? sanitize_text_field( $options['show_answers_numbering'] ) : 'none';
// Poll border color
$poll_border_color = (isset($options['border_color']) && $options['border_color'] != '') ? sanitize_text_field( $options['border_color'] ) : $main_color;
$enable_box_shadow = isset($options['enable_box_shadow']) && $options['enable_box_shadow'] == "on" ? true : false;
$box_shadow_color = isset($options['box_shadow_color']) && $options['box_shadow_color'] != "" ? esc_attr($options['box_shadow_color']) : "";
// Box Shadow X offset
$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;
// Box Shadow Y offset
$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;
// Box Shadow Z offset
$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;
// Poll Vote Reason
$poll_vote_reason = (isset($options['poll_vote_reason']) && $options['poll_vote_reason'] == 'on') ? true : false;
if($enable_box_shadow){
$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;
}
else{
$box_shadow_offsets = "none";
}
if ($poll_vote_reason) {
$vote_reason = "
". __("Please add vote reason", $this->plugin_name)."
";
} else {
$vote_reason = "";
}
// Show answers icon
$poll_answer_icon_check = (isset($options['poll_answer_icon_check']) && $options['poll_answer_icon_check'] == 'on') ? true : false;
$poll_answer_icon = isset($options['poll_answer_icon']) ? $options['poll_answer_icon'] : 'radio';
// Poll question font size
$poll_question_font_size_pc = isset($options['poll_question_size_pc']) && $options['poll_question_size_pc'] != "" ? esc_attr($options['poll_question_size_pc']) : "16";
$poll_question_font_size_mobile = isset($options['poll_question_size_mobile']) && $options['poll_question_size_mobile'] != "" ? esc_attr($options['poll_question_size_mobile']) : "16";
// Poll question image height
$poll_question_image_height = isset($options['poll_question_image_height']) && $options['poll_question_image_height'] != "" ? esc_attr($options['poll_question_image_height'])."px" : "100%";
// Poll answer image height
$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";
// Poll container max-width for mobile
$poll_mobile_max_width = isset($options['poll_mobile_max_width']) && $options['poll_mobile_max_width'] != '' ? esc_attr($options['poll_mobile_max_width']) . '%' : "100%";
// Titile text shadow
$options['enable_poll_title_text_shadow'] = (isset($options['enable_poll_title_text_shadow']) && $options['enable_poll_title_text_shadow'] == 'on') ? 'on' : 'off';
$enable_poll_title_text_shadow = (isset($options['enable_poll_title_text_shadow']) && $options['enable_poll_title_text_shadow'] == 'on') ? true : false;
$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)';
$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;
$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;
$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;
if( $enable_poll_title_text_shadow ){
$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;
}else{
$title_text_shadow = "";
}
// ==== Buttons styles start ====
// Buttons font size
$buttons_font_size = isset($options['poll_buttons_font_size']) && $options['poll_buttons_font_size'] != '' ? esc_attr($options['poll_buttons_font_size']) . 'px' : '17px';
// Poll button text color
$poll_button_text_color = (isset($options['button_text_color']) && $options['button_text_color'] != '') ? sanitize_text_field( $options['button_text_color'] ) : $button_text_color;
// Poll button background color
$button_bg_color = (isset($options['button_bg_color']) && $options['button_bg_color'] != '') ? sanitize_text_field( $options['button_bg_color'] ) : $button_bg_color;
// Buttons mobile font size
$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;
// Buttons Left / Right padding
$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';
// Buttons Top / Bottom padding
$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';
// Buttons border radius
$buttons_border_radius = isset($options['poll_buttons_border_radius']) && $options['poll_buttons_border_radius'] != '' ? esc_attr($options['poll_buttons_border_radius']) . 'px' : '3px';
// Buttons width
$buttons_width = isset($options['poll_buttons_width']) && $options['poll_buttons_width'] != '' ? esc_attr($options['poll_buttons_width']) . 'px' : 'auto';
// Poll View Type
$answer_view_type_old = isset($options['poll_answer_view_type']) && $options['poll_answer_view_type'] != '' ? esc_attr($options['poll_answer_view_type']) : 'list';
$answer_view_type = isset($poll['view_type']) && $poll['view_type'] != '' ? esc_attr($poll['view_type']) : $answer_view_type_old;
$answers_container = "";
if($answer_view_type == "grid" && $poll['type'] == "choosing"){
$answers_container = "ays_poll_grid_view_container";
}
elseif($answer_view_type == "list" && $poll['type'] == "choosing"){
$answers_container = "ays_poll_list_view_container";
}
// ==== Buttons styles end ====
$poll_answer_image_height = "150";
$poll_answer_object_fit = "cover";
$poll_answer_padding = "10";
$poll_answer_margin = "1";
$poll_answer_image_height_for_mobile = "150";
if($answer_style){
// Poll answer image height
$poll_answer_image_height = (isset($options['poll_answer_image_height']) && $options['poll_answer_image_height'] != "") ? esc_attr($options['poll_answer_image_height']) : "150";
// Poll answer image height for mobile
$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";
// Poll answer image object fit
$poll_answer_object_fit = (isset($options['poll_answer_object_fit']) && $options['poll_answer_object_fit'] != "") ? esc_attr($options['poll_answer_object_fit']) : "cover";
// Poll answer padding
$poll_answer_padding = (isset($options['poll_answer_padding']) && $options['poll_answer_padding'] != "") ? esc_attr($options['poll_answer_padding']) : "10";
// Poll answer gap
$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";
}
// Poll title font size
$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";
// Poll title font size mobile
$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";
// Poll title alignment
$poll_title_alignment = ( isset($options['poll_title_alignment']) && $options['poll_title_alignment'] != "" ) ? esc_attr($options['poll_title_alignment']) : "center";
// ===== Poll text type options start =====
$poll_view_type_text = isset($poll['view_type']) && $poll['view_type'] != "" ? $poll['view_type'] : "short_text";
$poll_text_type_length_enable = (isset($options['poll_text_type_length_enable']) && $options['poll_text_type_length_enable'] == "on") ? true : false;
$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";
$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']) : "";
$poll_text_type_limit_message = (isset($options['poll_text_type_limit_message']) && $options['poll_text_type_limit_message'] == "on") ? true : false;
$poll_text_type_width = (isset($options['poll_text_type_width']) && $options['poll_text_type_width'] != "") ? stripslashes(esc_attr($options['poll_text_type_width'])) : "";
$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";
$poll_class_for_limits = $poll_text_type_length_enable ? "ays_poll_question_limit_length" : "";
$poll_box_for_limit_message = "";
if($poll_text_type_limit_message && ($poll_text_type_limit_length != "" && intval($poll_text_type_limit_length) != 0)){
$poll_box_for_limit_message = '
'. $poll_text_type_limit_length . ' ' . $poll_text_type_limit_type . ' '. __( ' left' , $this->plugin_name ) . '
';
}
$poll_text_type_ready_width = "";
$poll_text_type_ready_type = "%";
if($poll['type'] == 'text'){
if($poll_view_type_text == "short_text"){
if($poll_text_type_width == "" || intval($poll_text_type_width) == 0){
$poll_text_type_ready_width = "60";
$poll_text_type_ready_type = "%";
}
else{
$poll_text_type_ready_width = $poll_text_type_width;
$poll_text_type_ready_type = ($poll_text_type_width_type == "percent" ? "%" : "px");
}
}
else{
if($poll_text_type_width == "" || intval($poll_text_type_width) == 0){
$poll_text_type_ready_width = "100";
$poll_text_type_ready_type = "%";
}
else{
$poll_text_type_ready_width = $poll_text_type_width;
$poll_text_type_ready_type = ($poll_text_type_width_type == "percent" ? "%" : "px");
}
}
}
// ===== Poll text type options end =====
$poll_password_box = '';
$form_method = '';
$password_message_with_toggle = "";
$password_message_with_toggle_class = "";
$poll_enable_password = isset($options['poll_enable_password']) && $options['poll_enable_password'] == 'on' ? true : false;
$poll_password_poll = isset($options['poll_password']) && $options['poll_password'] != "" ? stripslashes(esc_attr($options['poll_password'])) : "";
// Enable toggle password visibility
$options['poll_enable_password_visibility'] = isset($options['poll_enable_password_visibility']) ? $options['poll_enable_password_visibility'] : 'off';
$poll_enable_password_visibility = (isset($options['poll_enable_password_visibility']) && $options['poll_enable_password_visibility'] == 'on') ? true : false;
$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 ])) : '';
$poll_password_message = (isset($options['poll_password_message']) && $options['poll_password_message'] != '') ? stripslashes( wpautop( $options['poll_password_message'] ) ) : "
" . __( "Please enter password", $this->plugin_name ) . "
";
$poll_check_only_logged = (isset($options['enable_logged_users']) && $options['enable_logged_users'] == 1 && !is_user_logged_in()) ? true : false;
$poll_password_message_input = "
";
if ( $poll_enable_password_visibility ) {
$password_message_with_toggle_class = "ays-poll-password-input-box-visibility";
$password_message_with_toggle .= "
";
$password_message_with_toggle .= "
";
}
if($poll_enable_password){
$form_method = "method='post'";
$poll_password_box = "
". $poll_password_message . "
";
}
$poll_password_check = ($password_input_val == $poll_password_poll) ? true : false;
// Animation Top (px)
$poll_animation_top = (isset($general_options['poll_animation_top']) && $general_options['poll_animation_top'] != '') ? absint(intval($general_options['poll_animation_top'])) : 100 ;
$options['poll_enable_animation_top'] = isset($general_options['poll_enable_animation_top']) ? $general_options['poll_enable_animation_top'] : 'on';
$poll_enable_animation_top = (isset($general_options['poll_enable_animation_top']) && $general_options['poll_enable_animation_top'] == "on") ? true : false;
// Answers box shadow
$answers_box_shadow = (isset($options['poll_answer_enable_box_shadow']) && $options['poll_answer_enable_box_shadow'] == "on") ? true : false;
$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';
$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;
$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;
$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;
$answers_box_shadow_content = 'box-shadow:unset';
if($answers_box_shadow){
$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;
}
$poll_answer_border_radius = isset($options['poll_answer_border_radius']) && $options['poll_answer_border_radius'] != '' ? intval(esc_attr($options['poll_answer_border_radius'])) : 0;
// Display form fields labels
$options['display_fields_labels'] = isset($options['display_fields_labels']) ? $options['display_fields_labels'] : 'on';
$display_fields_labels = (isset($options['display_fields_labels']) && $options['display_fields_labels'] == 'on') ? true : false;
// Social Media links
$enable_social_links = (isset($options['enable_social_links']) && $options['enable_social_links'] == "on") ? true : false;
$show_chart_type = (isset($options['show_chart_type']) && $options['show_chart_type'] != "") ? $options['show_chart_type'] : "default_bar_chart";
$content = "
";
if ($poll_direction == 'center') {
$poll_direction_center = "style='text-align: center;'";
$poll_direction = 'ltr';
}else{
$poll_direction_center = "";
}
// AV Show login form for not logged in users
$options['show_login_form'] = isset($options['show_login_form']) ? $options['show_login_form'] : 'off';
$show_login_form = (isset($options['show_login_form']) && $options['show_login_form'] == "on") ? true : false;
$add_form = $show_login_form && !is_user_logged_in() ? "" : "