*/
class Survey_Maker_Public {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
private $html_class_prefix = 'ays-survey-';
private $html_name_prefix = 'ays-survey-';
private $name_prefix = 'survey_';
private $unique_id;
private $unique_id_in_class;
private $options;
private $settings;
protected $default_texts;
private $buttons_texts;
private $lazy_loading;
private $message_variable_data;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of the plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->settings = new Survey_Maker_Settings_Actions($this->plugin_name);
add_shortcode('ays_survey', array($this, 'ays_generate_survey_method'));
add_shortcode('ays_survey_popup', array($this, 'ays_generate_survey_popup_method'));
}
/**
* 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 Survey_Maker_Loader as all of the hooks are defined
* in that particular class.
*
* The Survey_Maker_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name . "-font-awesome", plugin_dir_url( __FILE__ ) . 'css/survey-maker-font-awesome.min.css', array(), $this->version, 'all' );
wp_enqueue_style( $this->plugin_name . "-transition", plugin_dir_url( __FILE__ ) . 'css/transition.min.css', array(), $this->version, 'all' );
wp_enqueue_style( $this->plugin_name . "-dropdown", plugin_dir_url( __FILE__ ) . 'css/dropdown.min.css', array(), $this->version, 'all' );
wp_enqueue_style( $this->plugin_name . '-select2', plugin_dir_url(__FILE__) . 'css/survey-maker-select2.min.css', array(), $this->version, 'all');
wp_enqueue_style( $this->plugin_name . "-loaders", plugin_dir_url( __FILE__ ) . 'css/loaders.css', array(), $this->version, 'all' );
wp_enqueue_style( $this->plugin_name . '-timepicker', plugin_dir_url( __FILE__ ) . '/css/survey-maker-timepicker.css', array(), $this->version, 'all');
}
public function enqueue_styles_early(){
wp_enqueue_style( $this->plugin_name . '-min', plugin_dir_url( __FILE__ ) . 'css/survey-maker-public-min.css', array(), $this->version, 'all' );
}
/**
* 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 Survey_Maker_Loader as all of the hooks are defined
* in that particular class.
*
* The Survey_Maker_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
$is_elementor_exists = Survey_Maker_Data::ays_survey_is_elementor();
if( !$is_elementor_exists ){
wp_enqueue_script( $this->plugin_name . '-autosize', plugin_dir_url( __FILE__ ) . 'js/survey-maker-autosize.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( $this->plugin_name . '-transition', plugin_dir_url( __FILE__ ) . 'js/transition.min.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( $this->plugin_name . '-dropdown', plugin_dir_url( __FILE__ ) . 'js/dropdown.min.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( $this->plugin_name . '-select2js', plugin_dir_url(__FILE__) . 'js/survey-maker-select2.min.js', array('jquery'), $this->version, false);
wp_enqueue_script( $this->plugin_name . '-plugin', plugin_dir_url( __FILE__ ) . 'js/survey-maker-public-plugin.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/survey-maker-public.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( $this->plugin_name . '-sweetalert-js', SURVEY_MAKER_PUBLIC_URL . '/js/survey-maker-sweetalert2.all.min.js', array('jquery'), $this->version, true );
wp_enqueue_script( $this->plugin_name . '-ajax', plugin_dir_url( __FILE__ ) . 'js/survey-maker-public-ajax.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( $this->plugin_name . "-timepicker", plugin_dir_url(__FILE__) . '/js/survey-maker-timepicker.js', array( 'jquery' ), $this->version, false );
wp_localize_script( $this->plugin_name . '-plugin', 'aysSurveyMakerAjaxPublic', array(
'ajaxUrl' => admin_url('admin-ajax.php'),
'warningIcon' => SURVEY_MAKER_PUBLIC_URL . "/images/warning.svg",
'autofill_nonce' => wp_create_nonce('survey_maker_autofill_nonce')
) );
wp_localize_script( $this->plugin_name, 'aysSurveyLangObj', array(
'notAnsweredText' => __( 'You have not answered this question', "survey-maker" ),
'areYouSure' => __( 'Do you want to finish the quiz? Are you sure?', "survey-maker" ),
'sorry' => __( 'Sorry', "survey-maker" ),
'unableStoreData' => __( 'We are unable to store your data', "survey-maker" ),
'connectionLost' => __( 'Connection is lost', "survey-maker" ),
'checkConnection' => __( 'Please check your connection and try again', "survey-maker" ),
'selectPlaceholder' => __( 'Select an answer', "survey-maker" ),
'shareDialog' => __( 'Share Dialog', "survey-maker" ),
'passwordIsWrong' => __( 'Password is wrong!', "survey-maker" ),
'choose' => __( 'Choose', "survey-maker" ),
'redirectAfter' => $this->default_texts['redirectingAfter'],
'emailValidationError' => $this->default_texts['emailValidationError'],
'requiredError' => __( 'This is a required question', "survey-maker" ),
'minimumVotes' => __( 'Min votes count should be', "survey-maker" ),
'maximumVotes' => __( 'Max votes count should be', "survey-maker" ),
) );
}
}
public function enqueue_scripts_popups() {
wp_enqueue_script( $this->plugin_name . '-popups', plugin_dir_url( __FILE__ ) . 'js/survey-maker-public-popups.js', array( 'jquery' ), $this->version, false );
wp_localize_script( $this->plugin_name . '-popups', 'aysSurveyMakerPopupsAjaxPublic', array(
'ajaxUrl' => admin_url('admin-ajax.php'),
) );
}
public function ays_survey_ajax(){
global $wpdb;
$results = array(
"status" => false
);
$function = isset($_REQUEST['function']) ? $_REQUEST['function'] : null;
if($function !== null){
$data = $_REQUEST;
$results = array();
unset($data['action']);
unset($data['function']);
switch ($function) {
case 'ays_finish_survey':
$results = $this->ays_finish_survey( $data );
break;
case 'ays_survey_get_user_information':
$results = $this->ays_survey_get_user_information( $data );
break;
case 'ays_survey_popup_set_cookie':
$results = $this->ays_survey_popup_set_cookie( $data );
break;
}
ob_end_clean();
$ob_get_clean = ob_get_clean();
echo json_encode( $results );
wp_die();
}
ob_end_clean();
$ob_get_clean = ob_get_clean();
echo json_encode( $results );
wp_die();
}
public function ays_finish_survey( $data ){
$unique_id = isset($data['unique_id']) ? $data['unique_id'] : null;
if($unique_id === null){
return array("status" => false, "message" => "No no no" );
} else {
global $wpdb;
$name_prefix = 'ays-survey-';
$valid_name_prefix = 'survey_';
$survey_id = isset( $data[ $name_prefix . 'id-' . $unique_id ] ) ? absint( intval( $data[ $name_prefix . 'id-' . $unique_id ] ) ) : null;
if($survey_id === null){
return array("status" => false, "message" => "No no no" );
}else{
$survey = Survey_Maker_Data::get_survey_by_id( $survey_id );
$user_id = get_current_user_id();
$attr = array(
'id' => $survey_id
);
$options = Survey_Maker_Data::get_survey_validated_data_from_array( $survey, $attr );
$answered_questions = isset( $data[ $name_prefix . 'answers-' . $unique_id ] ) && !empty( $data[ $name_prefix . 'answers-' . $unique_id ] ) ? $data[ $name_prefix . 'answers-' . $unique_id ] : array();
$questions_data = isset( $data[ $name_prefix . 'questions-' . $unique_id ] ) && !empty( $data[ $name_prefix . 'questions-' . $unique_id ] ) ? $data[ $name_prefix . 'questions-' . $unique_id ] : array();
$survey_additional_wp_data = isset($data[ $valid_name_prefix . 'additional_wp_data' ]) && $data[ $valid_name_prefix . 'additional_wp_data' ] != '' ? json_decode(base64_decode($data[ $valid_name_prefix . 'additional_wp_data' ]) , true) : array();
$survey_current_page_link = isset( $data['ays_'.$valid_name_prefix.'_current_page_link'] ) && $data['ays_'.$valid_name_prefix.'_current_page_link'] != '' ? sanitize_url( $data['ays_'.$valid_name_prefix.'_current_page_link'] ) : "";
$survey_current_page_link_html = "". __( "Survey link", "survey-maker" ) ."";
// Survey modified date
$survey_modified_date = (isset($survey->date_modified) && $survey->date_modified != '') ? esc_attr( $survey->date_modified ) : "";
if( $survey_modified_date != "" ){
$survey_modified_date = date_i18n( get_option( 'date_format' ), strtotime( $survey_modified_date ) );
}
$user_email = '';
if( isset( $data[ $name_prefix . 'user-email-' . $unique_id ] ) && !empty( $data[ $name_prefix . 'user-email-' . $unique_id ] ) ){
if( is_array( $data[ $name_prefix . 'user-email-' . $unique_id ] ) ){
$user_emails_arr = $data[ $name_prefix . 'user-email-' . $unique_id ];
$user_email = $answered_questions[ $user_emails_arr[ count( $user_emails_arr ) - 1 ] ];
}else{
$user_email = $answered_questions[ $data[ $name_prefix . 'user-email-' . $unique_id ] ];
}
}
if( is_array( $user_email ) ){
if( isset( $user_email['answer'] ) && !empty( $user_email['answer'] ) ){
$user_email = $user_email['answer'];
}else{
$user_email = '';
}
}
$user_name = '';
if( isset( $data[ $name_prefix . 'user-name-' . $unique_id ] ) && !empty( $data[ $name_prefix . 'user-name-' . $unique_id ] ) ){
if( is_array( $data[ $name_prefix . 'user-name-' . $unique_id ] ) ){
$user_names_arr = $data[ $name_prefix . 'user-name-' . $unique_id ];
$user_name = $answered_questions[ $user_names_arr[ count( $user_names_arr ) - 1 ] ];
}else{
$user_name = $answered_questions[ $data[ $name_prefix . 'user-name-' . $unique_id ] ];
}
}
if( is_array( $user_name ) ){
if( isset( $user_name['answer'] ) && !empty( $user_name['answer'] ) ){
$user_name = $user_name['answer'];
}else{
$user_name = '';
}
}
$result_unique_code = strtoupper( uniqid() );
$setting_options = Survey_Maker_Data::get_setting_data( 'options' );
// Do not store IP adressess
$settings_options[ $valid_name_prefix . 'disable_user_ip' ] = (isset($setting_options[ $valid_name_prefix . 'disable_user_ip' ]) && $setting_options[ $valid_name_prefix . 'disable_user_ip' ] == 'on') ? stripslashes( $setting_options[ $valid_name_prefix . 'disable_user_ip' ] ): 'off';
$survey_disable_user_ip = (isset($setting_options[ $valid_name_prefix . 'disable_user_ip' ]) && $setting_options[ $valid_name_prefix . 'disable_user_ip' ] == 'on') ? true : false;
// Do not store User Names
$settings_options[ $valid_name_prefix . 'disable_user_name' ] = (isset($setting_options[ $valid_name_prefix . 'disable_user_name' ]) && $setting_options[ $valid_name_prefix . 'disable_user_name' ] == 'on') ? stripslashes( $setting_options[ $valid_name_prefix . 'disable_user_name' ] ): 'off';
$survey_disable_user_name = (isset($setting_options[ $valid_name_prefix . 'disable_user_name' ]) && $setting_options[ $valid_name_prefix . 'disable_user_name' ] == 'on') ? true : false;
// Do not store User Emails
$settings_options[ $valid_name_prefix . 'disable_user_email' ] = (isset($setting_options[ $valid_name_prefix . 'disable_user_email' ]) && $setting_options[ $valid_name_prefix . 'disable_user_email' ] == 'on') ? stripslashes( $setting_options[ $valid_name_prefix . 'disable_user_email' ] ): 'off';
$survey_disable_user_email = (isset($setting_options[ $valid_name_prefix . 'disable_user_email' ]) && $setting_options[ $valid_name_prefix . 'disable_user_email' ] == 'on') ? true : false;
$survey_question_count = Survey_Maker_Data::get_survey_questions_count($survey_id);
$survey_sections_count = Survey_Maker_Data::get_survey_sections_count($survey_id);
$survey_passed_users_count = Survey_Maker_Data::ays_survey_get_passed_users_count($survey_id);
$user_ip = '';
if($survey_disable_user_ip){
$user_ip = '';
}else{
$user_ip = Survey_Maker_Data::get_user_ip_validated();
$user_ip = ($user_ip != 'UNKNOWN') ? $user_ip : '';
}
if ( $survey_disable_user_name ) {
$user_name = '';
$user_id = '';
}
if ( $survey_disable_user_email ) {
$user_email = '';
$user_id = '';
}
$survey_user_information = Survey_Maker_Data::get_user_profile_data();
// Get user first name
$user_first_name = (isset( $survey_user_information['user_first_name'] ) && $survey_user_information['user_first_name'] != "") ? $survey_user_information['user_first_name'] : '';
// Get user last name
$user_last_name = (isset( $survey_user_information['user_last_name'] ) && $survey_user_information['user_last_name'] != "") ? $survey_user_information['user_last_name'] : '';
// Get user nick name
$user_nick_name = (isset( $survey_user_information['user_nickname'] ) && $survey_user_information['user_nickname'] != "") ? $survey_user_information['user_nickname'] : '';
// Get display name
$user_display_name = (isset( $survey_user_information['user_display_name'] ) && $survey_user_information['user_display_name'] != "") ? $survey_user_information['user_display_name'] : '';
// User Wordpress role
$user_wordpress_roles = (isset( $survey_user_information['user_wordpress_roles'] ) && $survey_user_information['user_wordpress_roles'] != "") ? $survey_user_information['user_wordpress_roles'] : '';
// User Website URL
$user_website_url = (isset( $survey_user_information['user_website_url'] ) && $survey_user_information['user_website_url'] != "") ? $survey_user_information['user_website_url'] : '';
if ( ! empty( $user_website_url ) ) {
$user_website_url = ''. $user_website_url .'';
}
// User Registered
$user_data = wp_get_current_user();
$user_registered = '';
if ( is_user_logged_in() ) {
$user_registered = $user_data->user_registered;
}
// User ip address
$user_ip_address = (isset( $survey_user_information['user_ip_address'] ) && $survey_user_information['user_ip_address'] != "") ? $survey_user_information['user_ip_address'] : '';
// User wordpress email
$user_wordpress_email = (isset( $survey_user_information['user_wordpress_email'] ) && $survey_user_information['user_wordpress_email'] != "") ? esc_attr($survey_user_information['user_wordpress_email']) : '';
// Current date
$survey_current_date = date_i18n( 'M d, Y', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
// WP home page url
$home_main_url = home_url();
$wp_home_page_url = ''.$home_main_url.'';
// Current time
$survey_current_time = explode( ' ', current_time( 'mysql' ) );
$survey_current_time_only = ($survey_current_time[1]) ? $survey_current_time[1] : '';
// Current day
$survey_current_day = date_i18n( 'l', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
// Current month
$survey_current_month = date_i18n( 'F', strtotime( sanitize_text_field( $_REQUEST['end_date'] ) ) );
// Get survey author
$current_survey_user_data = get_userdata( $survey->author_id );
$current_survey_author = '';
$current_survey_author_email = '';
$current_survey_author_nickname = '';
$current_survey_author_display_name = '';
$current_survey_author_website_url = '';
if ( isset( $current_survey_user_data ) && $current_survey_user_data ) {
// Get survey author name
$current_survey_author = ( isset( $current_survey_user_data->data->display_name ) && $current_survey_user_data->data->display_name != '' ) ? sanitize_text_field( $current_survey_user_data->data->display_name ) : "";
// Get survey author email
$current_survey_author_email = ( isset( $current_survey_user_data->data->user_email ) && $current_survey_user_data->data->user_email != '' ) ? sanitize_text_field( $current_survey_user_data->data->user_email ) : "";
// Get survey author nickname
$current_survey_author_nickname = ( isset( $current_survey_user_data->data->user_nicename ) && $current_survey_user_data->data->user_nicename != '' ) ? sanitize_text_field( $current_survey_user_data->data->user_nicename ) : "";
// Get survey author display name
$current_survey_author_display_name = ( isset( $current_survey_user_data->data->display_name ) && $current_survey_user_data->data->display_name != '' ) ? sanitize_text_field( $current_survey_user_data->data->display_name ) : "";
// Get survey author Website URL
$current_survey_author_website_url = ( isset( $current_survey_user_data->data->user_url ) && $current_survey_user_data->data->user_url != '' ) ? sanitize_text_field( $current_survey_user_data->data->user_url ) : "";
}
$super_admin_email = "";
$wp_all_admins = get_users('role=Administrator');
if(!empty($wp_all_admins)){
$super_admin_email = isset($wp_all_admins[0]) ? $wp_all_admins[0]->data->user_email : '';
}
$survey_current_post_id = '';
$survey_current_post_author_email = '';
$survey_current_post_author_nickname = '';
$survey_current_post_author_display_name = '';
$survey_current_post_author_first_name = '';
$survey_current_post_author_last_name = '';
$survey_current_post_author_website_url = '';
$survey_current_post_author_roles = '';
$survey_current_post_title = '';
if(!empty($survey_additional_wp_data)){
if(isset($survey_additional_wp_data['survey_post_type']) && $survey_additional_wp_data['survey_post_type'] == 'post'){
$survey_current_post_id = isset($survey_additional_wp_data['survey_post_id']) && $survey_additional_wp_data['survey_post_id'] != '' ? $survey_additional_wp_data['survey_post_id'] : '';
}
$survey_current_post_author_email = isset($survey_additional_wp_data['survey_post_author_email']) && $survey_additional_wp_data['survey_post_author_email'] != '' ? esc_attr($survey_additional_wp_data['survey_post_author_email']) : '';
$survey_current_post_author_nickname = isset($survey_additional_wp_data['survey_current_post_author_nickname']) && $survey_additional_wp_data['survey_current_post_author_nickname'] != '' ? esc_attr($survey_additional_wp_data['survey_current_post_author_nickname']) : '';
$survey_current_post_author_display_name = isset($survey_additional_wp_data['survey_current_post_author_display_name']) && $survey_additional_wp_data['survey_current_post_author_display_name'] != '' ? esc_attr($survey_additional_wp_data['survey_current_post_author_display_name']) : '';
$survey_current_post_author_first_name = isset($survey_additional_wp_data['survey_current_post_author_first_name']) && $survey_additional_wp_data['survey_current_post_author_first_name'] != '' ? esc_attr($survey_additional_wp_data['survey_current_post_author_first_name']) : '';
$survey_current_post_author_last_name = isset($survey_additional_wp_data['survey_current_post_author_last_name']) && $survey_additional_wp_data['survey_current_post_author_last_name'] != '' ? esc_attr($survey_additional_wp_data['survey_current_post_author_last_name']) : '';
$survey_current_post_author_website_url = isset($survey_additional_wp_data['survey_current_post_author_website_url']) && $survey_additional_wp_data['survey_current_post_author_website_url'] != '' ? esc_attr($survey_additional_wp_data['survey_current_post_author_website_url']) : '';
$survey_current_post_author_roles = isset($survey_additional_wp_data['survey_current_post_author_roles']) && $survey_additional_wp_data['survey_current_post_author_roles'] != '' ? $survey_additional_wp_data['survey_current_post_author_roles'] : '';
$survey_current_post_title = isset($survey_additional_wp_data['survey_current_post_title']) && $survey_additional_wp_data['survey_current_post_title'] != '' ? esc_attr($survey_additional_wp_data['survey_current_post_title']) : '';
}
if ( ! empty( $survey_current_post_author_website_url ) ) {
$survey_current_post_author_website_url = ''.$survey_current_post_author_website_url.'';
}
if ( ! empty( $survey_current_post_author_roles ) && $survey_current_post_author_roles != "" ) {
if ( is_array( $survey_current_post_author_roles ) ) {
$survey_current_post_author_roles = implode( ", ", $survey_current_post_author_roles );
}
}
$get_site_title = get_bloginfo('name');
$get_site_description = get_bloginfo('description');
$detectedDevice = Survey_Maker_Data::ays_survey_detected_device_chart();
$message_data = array(
'survey_title' => stripslashes($survey->title),
'survey_id' => stripslashes($survey->id),
'post_id' => $survey_current_post_id,
'user_name' => $user_name,
'user_email' => $user_email,
'user_wordpress_email' => $user_wordpress_email,
'user_id' => $user_id,
'user_registered' => $user_registered,
'questions_count' => $survey_question_count,
'current_date' => $survey_current_date,
'current_time' => $survey_current_time_only,
'current_day' => $survey_current_day,
'current_month' => $survey_current_month,
'unique_code' => $result_unique_code,
'sections_count' => $survey_sections_count,
'users_count' => $survey_passed_users_count,
'users_first_name' => $user_first_name,
'users_last_name' => $user_last_name,
'users_nick_name' => $user_nick_name,
'users_display_name' => $user_display_name,
'users_ip_address' => $user_ip_address,
'user_wordpress_roles' => $user_wordpress_roles,
'user_website_url' => $user_website_url,
'creation_date' => date_i18n( get_option( 'date_format' ), strtotime( sanitize_text_field( $survey->date_created ) ) ),
'modified_date' => $survey_modified_date,
'current_survey_author' => $current_survey_author,
'current_survey_author_email' => $current_survey_author_email,
'current_survey_author_nickname' => $current_survey_author_nickname,
'current_survey_author_display_name' => $current_survey_author_display_name,
'current_survey_author_website_url' => $current_survey_author_website_url,
'current_survey_page_link' => $survey_current_page_link_html,
'admin_email' => $super_admin_email,
'home_page_url' => $wp_home_page_url,
'post_author_email' => $survey_current_post_author_email,
'post_author_nickname' => $survey_current_post_author_nickname,
'post_author_display_name' => $survey_current_post_author_display_name,
'post_author_first_name' => $survey_current_post_author_first_name,
'post_author_last_name' => $survey_current_post_author_last_name,
'post_author_website_url' => $survey_current_post_author_website_url,
'post_author_roles' => $survey_current_post_author_roles,
'post_title' => $survey_current_post_title,
'site_title' => $get_site_title,
'site_description' => $get_site_description,
);
$send_data = array(
'questions_data' => $questions_data,
'answered_questions' => $answered_questions,
'survey' => $survey,
'questions_ids' => $survey->question_ids,
'user_id' => $user_id,
'user_ip' => $user_ip,
'user_name' => $user_name,
'user_email' => $user_email,
'start_date' => current_time( 'mysql' ),
'end_date' => current_time( 'mysql' ),
'unique_code' => $result_unique_code,
'detectedDevice' => $detectedDevice,
);
$check_limitations = false;
if(isset($options['survey_limit_users']) && $options['survey_limit_users']){
$limit_users_by = isset($options['survey_limit_users_by']) && $options['survey_limit_users_by'] != "" ? $options['survey_limit_users_by'] : "";
$limit_users_attr = array(
'id' => $survey_id,
'name' => 'ays_survey_cookie_',
'title' => $survey->title,
);
$check_limitations = $this->ays_survey_check_limitations($limit_users_by, $limit_users_attr);
}
$result = $this->add_results_to_db( $send_data );
// Get submission count
$survey_submission_count_and_ids = Survey_Maker_Data::get_submission_count_and_ids_for_summary($survey_id);
$survey_submission_count = isset($survey_submission_count_and_ids['submission_count']) && $survey_submission_count_and_ids['submission_count'] != '' ? esc_attr($survey_submission_count_and_ids['submission_count']) : '';
$message_data['submission_count'] = $survey_submission_count;
$thank_you_message = trim( $options[ $valid_name_prefix . 'final_result_text' ] );
if( $thank_you_message == '' ){
$thank_you_message = __( "Thank you for completing this survey.", "survey-maker" );
}
$thank_you_message = Survey_Maker_Data::replace_message_variables($thank_you_message, $message_data);
$thank_you_message = Survey_Maker_Data::ays_autoembed( $thank_you_message );
$heading_for_share_buttons = '';
if( isset($options['survey_social_buttons']) && $options['survey_social_buttons'] ){
$heading_for_share_buttons = $options[ $this->name_prefix . 'social_buttons_heading' ];
$heading_for_share_buttons = Survey_Maker_Data::replace_message_variables($heading_for_share_buttons, $message_data);
$heading_for_share_buttons = Survey_Maker_Data::ays_autoembed( $heading_for_share_buttons );
}
return array(
'status' => $result,
"message" => $thank_you_message,
"limited" => $check_limitations,
"socialHeading" => $heading_for_share_buttons
);
}
}
return array("status" => false, "message" => "No no no" );
}
protected function add_results_to_db( $data ){
global $wpdb;
$questions_table = ( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "questions";
$answers_table = ( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "answers";
$submissions_table = ( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "submissions";
$submissions_questions_table = ( $wpdb->prefix . SURVEY_MAKER_DB_PREFIX ) . "submissions_questions";
$survey = $data['survey'];
$questions_ids = $data['questions_ids'];
$user_id = $data['user_id'];
$user_ip = $data['user_ip'];
$user_name = $data['user_name'];
$user_email = $data['user_email'];
$start_date = $data['start_date'];
$end_date = $data['end_date'];
$answered_questions = $data['answered_questions'];
$questions_data = $data['questions_data'];
$duration = strtotime($end_date) - strtotime($start_date);
$unique_code = $data['unique_code'];
$detectedDevice = $data['detectedDevice'];
$question_ids_array = $questions_ids != '' ? explode(',', $questions_ids) : array();
$questions_count = count( $question_ids_array );
$options = array(
'device' => $detectedDevice,
);
$results_submissions = $wpdb->insert(
$submissions_table,
array(
'survey_id' => absint( intval( $survey->id ) ),
'questions_ids' => $questions_ids,
'user_id' => $user_id,
'user_ip' => $user_ip,
'user_name' => $user_name,
'user_email' => $user_email,
'start_date' => $start_date,
'end_date' => $end_date,
'submission_date' => $end_date,
'duration' => $duration,
'questions_count' => $questions_count,
'unique_code' => $unique_code,
'options' => json_encode($options)
),
array(
'%d', // survey_id
'%s', // questions_ids
'%d', // user_id
'%s', // user_ip
'%s', // user_name
'%s', // user_email
'%s', // start_date
'%s', // end_date
'%s', // submission_date
'%s', // duration
'%s', // questions_count
'%s', // unique_code
'%s' // options
)
);
$submission_id = $wpdb->insert_id;
$results_submissions_questions = 0;
foreach ($question_ids_array as $key => $qid) {
$questions_options = array(
);
$user_answer = '';
$user_variant = '';
$section_id = $questions_data[$qid]['section'];
$question_answer = '';
if( isset( $answered_questions[$qid] ) ){
if( isset( $answered_questions[$qid]['other'] ) ){
$user_variant = $answered_questions[$qid]['other'];
unset( $answered_questions[$qid]['other'] );
}
if( is_array( $answered_questions[$qid] ) ){
if( isset( $answered_questions[$qid]['answer'] ) && !empty( $answered_questions[$qid]['answer'] ) ){
$question_answer = $answered_questions[$qid]['answer'];
}else{
$question_answer = '';
}
}else{
$question_answer = $answered_questions[$qid];
}
}
$answer_id = $question_answer;
$question_type = (isset($questions_data[$qid]['questionType']) && $questions_data[$qid]['questionType'] != '') ? stripslashes ( sanitize_text_field( $questions_data[$qid]['questionType'] ) ) : 'radio';
switch ( $question_type ) {
case "radio":
$user_answer = '';
if($question_answer != ""){
$user_variant = '';
}
break;
case "checkbox":
if( is_array( $question_answer ) ){
if( !in_array( '0', $question_answer ) ){
$user_variant = '';
}
$user_answer = implode(',', $question_answer);
}else{
$user_answer = $question_answer;
if( '0' != $question_answer ){
$user_variant = '';
}
}
$answer_id = 0;
break;
case "select":
$user_answer = '';
break;
case "text":
case "star":
$user_answer = $question_answer;
$answer_id = 0;
break;
case "short_text":
$user_answer = $question_answer;
$answer_id = 0;
break;
case "number":
case "phone":
case "date":
case "time":
$user_answer = $question_answer;
$answer_id = 0;
break;
case "date_time":
if(is_array($question_answer) && ($question_answer['date'] != '' || $question_answer['time'] != '')){
$question_answer['date'] = $question_answer['date'] != '' ? stripslashes ( sanitize_text_field( $question_answer['date'] ) ) : '-';
$question_answer['time'] = $question_answer['time'] != '' ? stripslashes ( sanitize_text_field( $question_answer['time'] ) ) : '-';
$user_answer = implode(" " , $question_answer);
}
else{
$user_answer = $question_answer;
}
$answer_id = 0;
break;
case "name":
$user_answer = $question_answer;
$answer_id = 0;
break;
case "email":
$user_answer = $question_answer;
$answer_id = 0;
break;
default:
$user_answer = '';
break;
}
$results_submissions_quests = $wpdb->insert(
$submissions_questions_table,
array(
'submission_id' => intval( $submission_id ),
'question_id' => intval( $qid ),
'section_id' => intval( $section_id ),
'survey_id' => intval( $survey->id ),
'user_id' => $user_id,
'answer_id' => intval( $answer_id ),
'user_answer' => $user_answer,
'user_variant' => $user_variant,
'user_explanation' => '',
'type' => $question_type,
'options' => json_encode( $questions_options )
),
array(
'%d', // submission_id
'%d', // question_id
'%d', // section_id
'%d', // survey_id
'%d', // user_id
'%d', // answer_id
'%s', // user_answer
'%s', // user_variant
'%s', // user_explanation
'%s', // type
'%s', // options
)
);
}
if ($results_submissions >= 0) {
return true;
}
return false;
}
public function ays_generate_survey_method( $attr ){
$id = (isset($attr['id'])) ? absint(intval($attr['id'])) : null;
$this->default_texts = Survey_Maker_Data::ays_set_default_texts( $this->plugin_name, array() );
if (is_null($id)) {
$content = "
" . $this->default_texts['wrongShortcode'] . "
";
return $content;
}
$this->enqueue_styles();
$this->enqueue_scripts();
$content = $this->show_survey($id, $attr);
return str_replace( array( "\r\n", "\n", "\r" ), '', $content );
}
public function show_survey( $id, $attr ){
$survey = Survey_Maker_Data::get_survey_by_id( $id );
if ( is_null( $survey ) ) {
return "" . $this->default_texts['wrongShortcode'] . "
";
}
$status = isset( $survey->status ) && $survey->status != '' ? sanitize_text_field($survey->status) : '';
if ( $status == 'trashed' ) {
return "" . $this->default_texts['wrongShortcode'] . "
";
}
elseif( $status == 'draft' ){
return '';
}
$unique_id = uniqid();
$this->unique_id = $unique_id;
$this->unique_id_in_class = $id . "-" . $unique_id;;
/*******************************************************************************************************/
$settings_options = $this->settings->ays_get_setting('options');
if($settings_options){
$settings_options = json_decode( $settings_options, true );
}else{
$settings_options = array();
}
// $this->buttons_texts = Survey_Maker_Data::ays_set_survey_texts( $this->plugin_name, $this->options );
$this->message_variable_data = Survey_Maker_Data::ays_set_survey_message_variables_data( $id, $survey, $settings_options );
$this->options = Survey_Maker_Data::get_survey_validated_data_from_array( $survey, $attr );
$this->buttons_texts = Survey_Maker_Data::ays_set_survey_texts( $this->plugin_name, $this->options );
$user_id = get_current_user_id();
/*******************************************************************************************************/
/*
==========================================
General settings
==========================================
*/
// Textarea height (public)
$this->options[ $this->name_prefix . 'textarea_height' ] = (isset($settings_options['survey_textarea_height']) && $settings_options['survey_textarea_height'] != '' && $settings_options['survey_textarea_height'] != 0) ? absint( sanitize_text_field($settings_options['survey_textarea_height']) ) : 100;
// Lazy loading for images
$this->options[ $this->name_prefix . 'lazy_loading_for_images' ] = (isset($settings_options['survey_lazy_loading_for_images']) && $settings_options['survey_lazy_loading_for_images'] == 'on') ? true : false;
$this->lazy_loading = '';
if($this->options[ $this->name_prefix . 'lazy_loading_for_images' ]){
$this->lazy_loading = Survey_Maker_Data::survey_lazy_loading_for_images($this->options[ $this->name_prefix . 'lazy_loading_for_images' ]);
}
/*******************************************************************************************************/
$options = isset( $survey->options ) && $survey->options != '' ? json_decode( $survey->options, true ) : array();
$sections_ids = isset( $survey->section_ids ) && $survey->section_ids != '' ? $survey->section_ids : '';
$question_ids = isset( $survey->question_ids ) && $survey->question_ids != '' ? $survey->question_ids : '';
if( $sections_ids != '' ){
$section_ids_array = explode( ',', $sections_ids );
}else{
$section_ids_array = array();
}
/*******************************************************************************************************/
/* Limit users */
/*******************************************************************************************************/
$limit = false;
$limit_message = false;
$limit_users_attr = array(
'id' => $id,
'name' => 'ays_survey_cookie_',
'title' => $survey->title,
);
if( $this->options[ $this->name_prefix . 'limit_users' ] ){
switch( $this->options[ $this->name_prefix . 'limit_users_by' ] ){
case 'ip':
$limit_by = Survey_Maker_Data::get_limit_user_by_ip( $id );
$remove_cookie = Survey_Maker_Data::ays_survey_remove_cookie( $limit_users_attr );
break;
case 'user_id':
$limit_by = Survey_Maker_Data::get_limit_user_by_id( $id, $user_id );
$remove_cookie = Survey_Maker_Data::ays_survey_remove_cookie( $limit_users_attr );
if( ! is_user_logged_in() ){
$limit_by = 0;
}
break;
case 'cookie':
$check_cookie = Survey_Maker_Data::ays_survey_check_cookie( $limit_users_attr );
if ( !$check_cookie ) {
$limit_by = 0;
}else{
$limit_by = Survey_Maker_Data::get_limit_cookie_count( $limit_users_attr );
}
break;
case 'ip_cookie':
$check_cookie = Survey_Maker_Data::ays_survey_check_cookie( $limit_users_attr );
$check_user_by_ip = Survey_Maker_Data::get_user_by_ip( $id );
if($check_cookie || $check_user_by_ip > 0){
$limit_by = $check_user_by_ip;
}elseif(! $check_cookie || $check_user_by_ip <= 0){
$limit_by = 0;
}
break;
}
if( $limit_by > 0 ){
$limit = true;
$limit_message = $this->options[ $this->name_prefix . 'limitation_message' ];
$limit_message = Survey_Maker_Data::replace_message_variables($this->options[ $this->name_prefix . 'limitation_message' ], $this->message_variable_data);
if( $limit_message == '' ){
$limit_message = __( "You've already responded", "survey-maker" );
}
}
}
$logged_in_limit = false;
$logged_in_limit_message = false;
if( $this->options[ $this->name_prefix . 'enable_logged_users' ] ){
if( ! is_user_logged_in() ){
// $limit = true;
// $limit_message = $this->options[ $this->name_prefix . 'logged_in_message' ];
// if( $limit_message == '' ){
// $limit_message = "" . __( "Sign in to continue", "survey-maker" ) . "
";
// $limit_message .= "" . __( "To fill out this form, you must be signed in. Your identity will remain anonymous.", "survey-maker" ) . "
";
// }
$logged_in_limit = true;
$logged_in_limit_message = $this->options[ $this->name_prefix . 'logged_in_message' ];
$logged_in_limit_message = Survey_Maker_Data::replace_message_variables($logged_in_limit_message, $this->message_variable_data);
if( $logged_in_limit_message == '' ){
$logged_in_limit_message = "" . __( "Sign in to continue", "survey-maker" ) . "
";
$logged_in_limit_message .= "" . __( "To fill out this form, you must be signed in. Your identity will remain anonymous.", "survey-maker" ) . "
";
}
}
// Show login form for not logged in users
$survey_login_form = "";
if($this->options[ $this->name_prefix . 'show_login_form' ]){
$ays_survey_login_button_text = $this->buttons_texts[ 'loginButton' ];
$args = array(
'echo' => false,
'id_username' => 'user_login',
'id_password' => 'user_pass',
'id_remember' => 'rememberme',
'id_submit' => 'wp-submit',
'label_log_in' => $ays_survey_login_button_text,
);
$survey_login_form = "" . wp_login_form( $args ) . "
";
}
if($logged_in_limit){
if(!is_user_logged_in()){
$logged_in_limit_message .= $survey_login_form;
}
}
}
// Limitation tackers of quiz
$tackers_message = "" . __( "This survey has expired!", "survey-maker" ) . "
";
$takers_count = Survey_Maker_Data::get_survey_takers_count($id);
if($this->options[ $this->name_prefix . 'enable_takers_count' ]){
if($this->options[ $this->name_prefix . 'takers_count' ] <= $takers_count ){
$limit = true;
$limit_message = $tackers_message;
}
}
$survey_loader = $this->options[ $this->name_prefix . 'loader' ];
$survey_loader_text = '';
if(isset($this->options['options'])){
$survey_loader_text = isset($this->options['options'][ $this->name_prefix . 'loader_text' ]) && $this->options['options'][ $this->name_prefix . 'loader_text' ] != "" ? stripslashes(esc_attr($this->options['options'][ $this->name_prefix . 'loader_text' ])) : '';
}
// Loader Gif
$survey_loader_gif = (isset($this->options[ $this->name_prefix . 'loader_gif' ]) && $this->options[ $this->name_prefix . 'loader_gif' ] != '') ? $this->options[ $this->name_prefix . 'loader_gif' ] : '';
$survey_loader_gif_width = (isset($this->options[ $this->name_prefix . 'loader_gif_width' ]) && $this->options[ $this->name_prefix . 'loader_gif_width' ] != '') ? stripslashes( $this->options[ $this->name_prefix . 'loader_gif_width' ] ) : '';
switch( $survey_loader ){
case 'default':
$survey_loader_html = "";
break;
case 'circle':
$survey_loader_html = "";
break;
case 'dual_ring':
$survey_loader_html = "";
break;
case 'facebook':
$survey_loader_html = "";
break;
case 'hourglass':
$survey_loader_html = "";
break;
case 'ripple':
$survey_loader_html = "";
break;
case 'snake':
$survey_loader_html = '';
break;
case 'text':
$survey_loader_html = ''.$survey_loader_text.'
';
break;
case 'custom_gif':
$survey_loader_html = '
lazy_loading.' style="width: '.$survey_loader_gif_width.'px;object-fit:cover;">
';
break;
default:
$survey_loader_html = "";
break;
}
$this->options[ $this->name_prefix . 'loader_html' ] = $survey_loader_html;
/*
* Schedule quiz
* Check is quiz expired
*/
$is_expired = false;
$active_date_check = false;
$startDate_atr = '';
$endDate_atr = '';
$current_time = strtotime( current_time( "Y:m:d H:i:s" ) );
$startDate = strtotime( $this->options[ $this->name_prefix . 'schedule_active' ] );
$endDate = strtotime( $this->options[ $this->name_prefix . 'schedule_deactive' ] );
$expired_survey_message = __('The survey has expired.', "survey-maker");
if ( $this->options[ $this->name_prefix . 'enable_schedule' ] ) {
$active_date_check = true;
if ( $this->options[ $this->name_prefix . 'schedule_active' ] ) {
$startDate_atr = $startDate - $current_time;
}elseif ( $this->options[ $this->name_prefix . 'schedule_deactive' ] ) {
$endDate_atr = $endDate - $current_time;
}
if ($startDate > $current_time) {
if($this->options[ $this->name_prefix . 'dont_show_survey_container' ]){
$hide_survey_and_popup = '
';
return $hide_survey_and_popup;
}
$is_expired = true;
$expired_survey_message = $this->options[ $this->name_prefix . 'schedule_pre_start_message' ];
}elseif ($endDate < $current_time) {
if($this->options[ $this->name_prefix . 'dont_show_survey_container' ]){
$hide_survey_and_popup = '
';
return $hide_survey_and_popup;
}
$is_expired = true;
$expired_survey_message = $this->options[ $this->name_prefix . 'schedule_expiration_message' ];
}
}
if( !$limit ){
$sections = Survey_Maker_Data::get_sections_by_survey_id( $sections_ids );
$sections_count = count( $sections );
$question_types_placeholders = array(
"radio" => '',
"checkbox" => '',
"select" => '',
"yesorno" => '',
"text" => __("Your answer", "survey-maker"),
"short_text" => __("Your answer", "survey-maker"),
"number" => __("Your answer", "survey-maker"),
"email" => __("Your email", "survey-maker"),
"name" => __("Your name", "survey-maker"),
);
$multiple_sections = $sections_count > 1 ? true : false;
foreach ($sections as $section_key => $section) {
$sections[$section_key]['title'] = (isset($section['title']) && $section['title'] != '') ? stripslashes( esc_html( $section['title'] ) ) : '';
if ( $this->options[ $this->name_prefix . 'allow_html_in_section_description' ] ) {
$survey_allowed_html = Survey_Maker_Data::ays_survey_custom_allowed_html();
$sections[$section_key]['description'] = (isset($section['description']) && $section['description'] != '') ? nl2br( wp_kses( $section['description'] ), $survey_allowed_html ) : '';
} else {
$sections[$section_key]['description'] = (isset($section['description']) && $section['description'] != '') ? nl2br( esc_html( $section['description'] ) ) : '';
}
$section_questions = Survey_Maker_Data::get_questions_by_section_id( intval( $section['id'] ), $question_ids );
foreach ($section_questions as $question_key => $question) {
$section_questions[$question_key]['question'] = (isset($question['question']) && $question['question'] != '') ? nl2br( $question['question'] ) : '';
$section_questions[$question_key]['image'] = (isset($question['image']) && $question['image'] != '') ? $question['image'] : '';
$section_questions[$question_key]['type'] = (isset($question['type']) && $question['type'] != '') ? $question['type'] : 'radio';
$section_questions[$question_key]['user_variant'] = (isset($question['user_variant']) && $question['user_variant'] == 'on') ? true : false;
$opts = json_decode( $question['options'], true );
$opts['required'] = (isset($opts['required']) && $opts['required'] == 'on') ? true : false;
$opts['enable_max_selection_count'] = (isset($opts['enable_max_selection_count']) && $opts['enable_max_selection_count'] == 'on') ? true : false;
$opts['max_selection_count'] = (isset($opts['max_selection_count']) && $opts['max_selection_count'] != '') ? intval( $opts['max_selection_count'] ) : null;
$opts['min_selection_count'] = (isset($opts['min_selection_count']) && $opts['min_selection_count'] != '') ? intval( $opts['min_selection_count'] ) : null;
// Text Limitations
$opts['enable_word_limitation'] = (isset($opts['enable_word_limitation']) && $opts['enable_word_limitation'] == 'on') ? true : false;
$opts['limit_by'] = (isset($opts['limit_by']) && $opts['limit_by'] != '') ? sanitize_text_field($opts['limit_by']) : '';
$opts['limit_length'] = (isset($opts['limit_length']) && $opts['limit_length'] != '') ? intval( $opts['limit_length'] ) : '';
$opts['limit_counter'] = (isset($opts['limit_counter']) && $opts['limit_counter'] == 'on') ? true : false;
// Number Limitations
$opts['enable_number_limitation'] = (isset($opts['enable_number_limitation']) && $opts['enable_number_limitation'] == 'on') ? true : false;
$opts['number_min_selection'] = (isset($opts['number_min_selection']) && $opts['number_min_selection'] != '') ? sanitize_text_field($opts['number_min_selection']) : '';
$opts['number_max_selection'] = (isset($opts['number_max_selection']) && $opts['number_max_selection'] != '') ? sanitize_text_field($opts['number_max_selection']) : '';
$opts['number_error_message'] = (isset($opts['number_error_message']) && $opts['number_error_message'] != '') ? sanitize_text_field($opts['number_error_message']) : '';
$opts['enable_number_error_message'] = (isset($opts['enable_number_error_message']) && $opts['enable_number_error_message'] == 'on') ? true : false;
$opts['number_limit_length'] = (isset($opts['number_limit_length']) && $opts['number_limit_length'] != '') ? intval( $opts['number_limit_length'] ) : '';
$opts['enable_number_limit_counter'] = (isset($opts['enable_number_limit_counter']) && $opts['enable_number_limit_counter'] == 'on') ? true : false;
// Input types placeholders
$opts['placeholder'] = (isset($opts['survey_input_type_placeholder'])) ? stripslashes(esc_attr($opts['survey_input_type_placeholder'])) : $question_types_placeholders[$section_questions[$question_key]['type']];
$opts['image_caption'] = (isset($opts['image_caption'])) ? stripslashes(esc_attr($opts['image_caption'])) : '';
$opts['image_caption_enable'] = (isset($opts['image_caption_enable']) && $opts['image_caption_enable'] == 'on') ? true : false;
//Admin note
$opts['enable_admin_note'] = ( isset( $opts['enable_admin_note'] ) && $opts['enable_admin_note'] == 'on' ) ? true : false;
$opts['admin_note'] = isset( $opts['admin_note'] ) && $opts['admin_note'] != '' ? stripslashes( esc_attr( $opts['admin_note'] ) ) : '';
if( $section_questions[$question_key]['type'] == 'checkbox' ){
$this->options[ 'survey_checkbox_options' ][$question['id']]['enable_max_selection_count'] = $opts['enable_max_selection_count'];
$this->options[ 'survey_checkbox_options' ][$question['id']]['max_selection_count'] = $opts['max_selection_count'];
$this->options[ 'survey_checkbox_options' ][$question['id']]['min_selection_count'] = $opts['min_selection_count'];
}
if( $section_questions[$question_key]['type'] == 'text' || $section_questions[$question_key]['type'] == 'short_text'){
$this->options[ 'survey_text_limit_options' ][$question['id']]['enable_word_limitation'] = $opts['enable_word_limitation'];
$this->options[ 'survey_text_limit_options' ][$question['id']]['limit_by'] = $opts['limit_by'];
$this->options[ 'survey_text_limit_options' ][$question['id']]['limit_length'] = $opts['limit_length'];
$this->options[ 'survey_text_limit_options' ][$question['id']]['limit_counter'] = $opts['limit_counter'];
}
if( $section_questions[$question_key]['type'] == 'number' || $section_questions[$question_key]['type'] == 'phone'){
$this->options[ 'survey_number_limit_options' ][$question['id']]['enable_number_limitation'] = $opts['enable_number_limitation'];
$this->options[ 'survey_number_limit_options' ][$question['id']]['number_min_selection'] = $opts['number_min_selection'];
$this->options[ 'survey_number_limit_options' ][$question['id']]['number_max_selection'] = $opts['number_max_selection'];
$this->options[ 'survey_number_limit_options' ][$question['id']]['number_error_message'] = $opts['number_error_message'];
$this->options[ 'survey_number_limit_options' ][$question['id']]['enable_number_error_message'] = $opts['enable_number_error_message'];
$this->options[ 'survey_number_limit_options' ][$question['id']]['number_limit_length'] = $opts['number_limit_length'];
$this->options[ 'survey_number_limit_options' ][$question['id']]['enable_number_limit_counter'] = $opts['enable_number_limit_counter'];
}
$q_answers = Survey_Maker_Data::get_answers_by_question_id( intval( $question['id'] ) );
foreach ($q_answers as $answer_key => $answer) {
$answer_content = (isset($answer['answer']) && $answer['answer'] != '') ? $answer['answer'] : '';
if( $this->options[ $this->name_prefix . 'allow_html_in_answers' ] === false ){
$answer_content = htmlentities( $answer_content );
}
$q_answers[$answer_key]['answer'] = stripslashes( $answer_content );
$q_answers[$answer_key]['image'] = (isset($answer['image']) && $answer['image'] != '') ? $answer['image'] : '';
$q_answers[$answer_key]['placeholder'] = (isset($answer['placeholder']) && $answer['placeholder'] != '') ? $answer['placeholder'] : '';
}
$section_questions[$question_key]['answers'] = $q_answers;
$section_questions[$question_key]['options'] = $opts;
}
$sections[$section_key]['questions'] = $section_questions;
}
}
if( $logged_in_limit ){
$limit = true;
$limit_message = $logged_in_limit_message;
}
$blocked_content_class = '';
if( ( $limit || $is_expired ) && !$logged_in_limit ){
$blocked_content_class = " " . $this->html_class_prefix . "blocked-content ";
}
$content = array();
$content[] = '';
if(Survey_Maker_Data::ays_survey_is_elementor() || Survey_Maker_Data::ays_survey_is_editor()){
$content[] = '
';
$content[] = '
';
$content[] = '
'. esc_attr( __( "You're in the preview mode. Note: All elements work correctly on the front end." , "survey-maker") ).'
';
$content[] = '
';
}
if($this->options[ $this->name_prefix . 'enable_survey_start_loader' ] && !Survey_Maker_Data::ays_survey_is_elementor()){
$content[] = Survey_Maker_Data::survey_get_loader($this->options[ $this->name_prefix . 'before_start_loader' ]);
}
$survey_full_screen_button_pos = $this->options[ $this->name_prefix . 'show_title' ] ? "" : $this->html_class_prefix . "full-screen-and-no-title";
$survey_no_cover_photo_class = "";
if( $this->options[ $this->name_prefix . 'full_screen_mode' ] ){
$survey_cover_photo_class = "";
if( $this->options[ $this->name_prefix . 'cover_photo' ] != "" ){
$survey_cover_photo_class = $this->html_class_prefix . "cover-photo-title-wrap";
$survey_no_cover_photo_class = $this->html_class_prefix . "no-cover-photo";
}
$content[] = '
';
$content = implode( '', $content );
return $content;
}
}
$content[] = '
';
$content[] = $this->get_styles();
$content[] = $this->get_custom_css();
$content[] = $this->get_encoded_options( $limit );
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function create_sections( $sections ){
$content = array();
$content[] = '';
if( $this->options[ $this->name_prefix . 'enable_start_page'] === true ){
$content[] = '
';
$content[] = '
';
$content[] = '';
$content[] = '
';
$content[] = '
';
}
$survey_current_post_id = get_the_ID();
$author_id = get_the_author_meta('ID');
$survey_current_post_author_email = get_the_author_meta('email');
$survey_current_post_author_nickname = get_the_author_meta('user_nicename');
$survey_current_post_author_display_name = get_the_author_meta( 'display_name', $author_id );
$survey_current_post_author_first_name = get_the_author_meta( 'first_name', $author_id );
$survey_current_post_author_last_name = get_the_author_meta( 'last_name', $author_id );
$survey_current_post_author_website_url = get_the_author_meta( 'url', $author_id );
$survey_current_post_author_roles = get_the_author_meta( 'roles', $author_id );
$survey_current_post_title = get_the_title();
$survey_additional_wp_data = array(
'survey_post_type' => get_post_type(),
'survey_post_id' => $survey_current_post_id,
'survey_post_author_email' => $survey_current_post_author_email,
'survey_current_post_author_nickname' => $survey_current_post_author_nickname,
'survey_current_post_author_display_name' => $survey_current_post_author_display_name,
'survey_current_post_author_first_name' => $survey_current_post_author_first_name,
'survey_current_post_author_last_name' => $survey_current_post_author_last_name,
'survey_current_post_author_website_url' => $survey_current_post_author_website_url,
'survey_current_post_author_roles' => $survey_current_post_author_roles,
'survey_current_post_title' => $survey_current_post_title,
);
$additional_data = base64_encode(json_encode($survey_additional_wp_data));
$sections_count = count( $sections );
foreach ( $sections as $key => $section ) {
$first = $key == 0 ? true : false;
$last = $key + 1 == $sections_count ? true : false;
$section_numbering = $key+1;
$content[] = $this->create_section( $section, $last, $first , $sections_count , $section_numbering);
}
$minimal_theme_header = $this->options[ $this->name_prefix . 'is_minimal' ] ? 'ays-survey-minimal-theme-header' : "";
$modern_theme_header = $this->options[ $this->name_prefix . 'is_modern' ] ? 'ays-survey-modern-theme-header' : "";
$content[] = '
';
$content[] = '';
$content[] = '
';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function create_section( $section, $last, $first, $section_count, $section_numbering ){
$content = array();
$show_question_numbering = $this->options[ $this->name_prefix . 'auto_numbering_questions' ];
$this->options[ $this->name_prefix . 'question_numbering_array' ] = Survey_Maker_Data::ays_survey_numbering_all( $show_question_numbering );
$content[] = '';
$minimal_theme_header = $this->options[ $this->name_prefix . 'is_minimal' ] ? 'ays-survey-minimal-theme-header' : "";
$modern_theme_header = $this->options[ $this->name_prefix . 'is_modern' ] ? 'ays-survey-modern-theme-header' : "";
if( $this->options[ $this->name_prefix . 'show_section_header' ] ){
$show_section_header = true;
if( $section['title'] == '' && $section['description'] == '' ){
$show_section_header = false;
}
if( $this->options[ $this->name_prefix . 'show_sections_questions_count' ] ){
$show_section_header = true;
}
if( $show_section_header ){
$content[] = '';
}
}
$content[] = '
';
$content[] = '
';
if( $this->options[ $this->name_prefix . 'enable_randomize_questions' ] ){
shuffle( $section['questions'] );
}
$loop_count = 1;
$other_answer_count = 0;
$check_question_type_for_next_button = 0;
$allowed_question_to_disable_next_button = array(
'radio',
'select',
'yesorno'
);
foreach ( $section['questions'] as $key => $question ) {
$numbering = "";
if(isset($this->options[ $this->name_prefix . 'question_numbering_array' ]) && !empty($this->options[ $this->name_prefix . 'question_numbering_array' ])){
$numbering = $this->options[ $this->name_prefix . 'question_numbering_array' ][$key]." ";
}
$content[] = $this->create_question( $question , $numbering, $loop_count );
$loop_count++;
if( isset($question['user_variant']) && $question['user_variant'] ){
$other_answer_count++;
}
if( isset($question['type']) && !in_array($question['type'], $allowed_question_to_disable_next_button) ){
$check_question_type_for_next_button++;
}
}
$content[] = '
';
$content[] = '
';
$footer_class_with_bar = "";
if($this->options[ $this->name_prefix . 'enable_progress_bar' ] == "on"){
$footer_class_with_bar = "ays-survey-footer-with-live-bar";
}
$content[] = '';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function create_question( $question , $numbering, $loop_count ){
$question_type = $question['type'];
$answers = $question['answers'];
$answers_html = array();
$is_required = isset( $question['options']['required'] ) && $question['options']['required'] == 'on' ? true : false;
$image_caption = isset($question['options']['image_caption']) ? $question['options']['image_caption'] : '';
$image_caption_enable = $question['options']['image_caption_enable'];
$is_minimum = "false";
if($question_type == 'checkbox'){
if(isset($question['options']['enable_max_selection_count']) && $question['options']['enable_max_selection_count'])
$is_minimum = isset($question['options']['min_selection_count']) && $question['options']['min_selection_count'] != "" ? "true" : "false";
}
// Admin note
$enable_admin_note = $question['options']['enable_admin_note'];
$admin_note = $question['options']['admin_note'];
// Logo Image URL
$survey_logo_url_validate = "javascript:void(0)";
$survey_logo_url = isset($this->options['options'][ $this->name_prefix . 'logo_url' ]) && $this->options['options'][ $this->name_prefix . 'logo_url' ] != "" ? $this->options['options'][ $this->name_prefix . 'logo_url' ] : "";
$survey_logo_url_check = isset($this->options['options'][ $this->name_prefix . 'enable_logo_url' ]) && $this->options['options'][ $this->name_prefix . 'enable_logo_url' ] == "on" ? true : false;
$survey_logo_url_check_new_tab = isset($this->options['options'][ $this->name_prefix . 'logo_url_new_tab' ]) && $this->options['options'][ $this->name_prefix . 'logo_url_new_tab' ] == "on" ? true : false;
$survey_logo_target = "";
if($survey_logo_url_check){
$survey_logo_url_validate = filter_var($survey_logo_url, FILTER_VALIDATE_URL) ? $survey_logo_url : $survey_logo_url_validate;
if(filter_var($survey_logo_url, FILTER_VALIDATE_URL) && $survey_logo_url_check_new_tab){
$survey_logo_target = "target='_blank'";
}
}
//
if( $this->options[ $this->name_prefix . 'enable_randomize_answers' ] ){
shuffle( $question['answers'] );
shuffle( $answers );
}
$other_answer = $question['user_variant'];
if( $other_answer ){
$answers[] = array(
'id' => '0',
'question_id' => $question['id'],
'answer' => '',
'image' => '',
'ordering' => count( $answers ) + 1,
'placeholder' => '',
'is_other' => true,
);
}
$answers['is_first_question'] = $loop_count;
$question['answers']['is_first_question'] = $loop_count;
$is_lazy_loading = ($loop_count > 1) ? $this->lazy_loading : "";
$show_answers_numbering = $this->options[ $this->name_prefix . 'auto_numbering' ];
$this->options[ $this->name_prefix . 'numbering_array' ] = Survey_Maker_Data::ays_survey_numbering_all( $show_answers_numbering );
$minimal_theme_question = $this->options[ $this->name_prefix . 'is_minimal' ] ? 'ays-survey-minimal-theme-question' : "";
$modern_theme_question = $this->options[ $this->name_prefix . 'is_modern' ] ? 'ays-survey-modern-theme-question' : "";
$has_answer_image = false;
foreach ($answers as $key => $answer) {
if(isset( $answer['image'] ) && $answer['image'] != ""){
$has_answer_image = true;
}
}
$question_types = array(
"radio",
"checkbox",
"select",
"star",
"date",
"time",
"date_time",
"text",
"short_text",
"number",
"phone",
"email",
"name",
);
$question_types_getting_answers_array = array(
"radio",
"checkbox",
);
if( !in_array( $question_type, $question_types ) ){
$question_type = "radio";
}
$question_type_function = 'ays_survey_question_type_' . strtoupper( $question_type ) . '_html';
$transmitting_array = in_array( $question_type, $question_types_getting_answers_array ) ? $answers : $question;
$answers_html[] = $this->$question_type_function( $transmitting_array );
$answers_html = implode( '', $answers_html );
$answer_grid = '';
if( $has_answer_image || $this->options[ $this->name_prefix . 'answers_view' ] == 'grid' ){
$answer_grid = $this->html_class_prefix . 'question-answers-grid';
}
$data_required = $is_required ? "true" : "false";
$is_required_field = $is_required ? '*' : "";
$question_title = Survey_Maker_Data::survey_sanitize_specific_content($question['question']);
if($numbering){
preg_match('/<([a-z]+[1-9]*)\b[^>]*>(.*?)<\/\1>/', $question_title, $matches );
if(empty($matches)){
$question_title = $numbering . $question_title;
}else{
$question_title_numbering_1 = $numbering . $matches[2];
$question_title_numbering_2 = str_replace( $matches[2], $question_title_numbering_1, $matches[0] );
$question_title = str_replace( $matches[0], $question_title_numbering_2, $question_title );
}
}
if ( $is_required_field != "" ) {
preg_match('/<([a-z]+[1-9]*)\b[^>]*>(.*?)<\/\1>/', $question_title, $matches );
if(empty($matches)){
$question_title = $question_title . $is_required_field;
}else{
$question_title_numbering_1 = $matches[2] . $is_required_field;
$question_title_numbering_2 = str_replace( $matches[2], $question_title_numbering_1, $matches[0] );
$question_title = str_replace( $matches[0], $question_title_numbering_2, $question_title );
}
}
$content = array();
$content[] = '';
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = $answers_html;
$content[] = '
';
$content[] = '
';
$content[] = '
';
if( $this->options[ $this->name_prefix . 'enable_clear_answer' ] ){
$content[] = '
';
$content[] = '
';
$content[] = '
';
}
$content[] = '
';
$content[] = '
';
if( $enable_admin_note && $admin_note != "" ){
$content[] = "
";
}
$content[] = '';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_RADIO_html( $answers ){
$content = array();
$has_answer_image = false;
foreach ($answers as $key => $answer) {
if(isset( $answer['image'] ) && $answer['image'] != ""){
$has_answer_image = true;
}
}
$answer_grid = '';
$answer_label_grid = '';
if( $has_answer_image || $this->options[ $this->name_prefix . 'answers_view' ] == 'grid' ){
$answer_grid = $this->html_class_prefix . 'answer-grid';
$answer_label_grid = $this->html_class_prefix . 'answer-label-grid';
}
$is_first_question = $answers['is_first_question'];
$is_lazy_loading = ($is_first_question > 1) ? $this->lazy_loading : "";
unset($answers['is_first_question']);
foreach ($answers as $key => $answer) {
$is_other = false;
if( isset( $answer['is_other'] ) && $answer['is_other'] == true ){
$is_other = true;
}
$answer_label_other = '';
$other_answer_box_width = '';
if( $is_other ){
$answer_label_other = $this->html_class_prefix . 'answer-label-other';
$other_answer_box_width = $this->html_class_prefix . 'other-answer-container';
}
$content[] = '';
$content[] = '
';
if( $is_other ){
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
}
$content[] = '
';
}
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_CHECKBOX_html( $answers ){
$content = array();
$has_answer_image = false;
foreach ($answers as $key => $answer) {
if(isset( $answer['image'] ) && $answer['image'] != ""){
$has_answer_image = true;
}
}
$answer_grid = '';
$answer_label_grid = '';
if( $has_answer_image || $this->options[ $this->name_prefix . 'answers_view' ] == 'grid' ){
$answer_grid = $this->html_class_prefix . 'answer-grid';
$answer_label_grid = $this->html_class_prefix . 'answer-label-grid';
}
$is_first_question = $answers['is_first_question'];
$is_lazy_loading = ($is_first_question > 1) ? $this->lazy_loading : "";
unset($answers['is_first_question']);
foreach ($answers as $key => $answer) {
$is_other = false;
if( isset( $answer['is_other'] ) && $answer['is_other'] == true ){
$is_other = true;
}
$answer_label_other = '';
$other_answer_box_width = '';
if( $is_other ){
$answer_label_other = $this->html_class_prefix . 'answer-label-other';
$other_answer_box_width = $this->html_class_prefix . 'other-answer-container';
}
$content[] = '';
$content[] = '
';
if( $is_other ){
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
}
$content[] = '
';
}
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_SELECT_html( $question ){
$content = array();
$is_first_question = $question['answers']['is_first_question'];
$is_lazy_loading = ($is_first_question > 1) ? $this->lazy_loading : "";
unset($question['answers']['is_first_question']);
$select_class = $this->html_class_prefix . 'question-select-conteiner-minimal';
if( $this->options[$this->name_prefix . 'is_minimal']){
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = '
';
}
else{
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
'.__('Choose', "survey-maker").'
';
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
}
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_STAR_html( $question ){
$content = array();
//checked Input
$enable_url_parameter = isset($question['options']['enable_url_parameter']) && $question['options']['enable_url_parameter'] == true ? true : false;
$url_parameter = $enable_url_parameter && isset($question['options']['url_parameter']) && $question['options']['url_parameter'] != "" ? $question['options']['url_parameter'] : '';
$selected_input = isset($_GET[$url_parameter]) && $_GET[$url_parameter] ? $_GET[$url_parameter] : '';
$star_label_1 = (isset($question['options']['star_1']) && $question['options']['star_1'] != '') ? $question['options']['star_1'] : '';
$star_label_2 = (isset($question['options']['star_2']) && $question['options']['star_2'] != '') ? $question['options']['star_2'] : '';
$star_scale_length = (isset($question['options']['star_scale_length']) && $question['options']['star_scale_length'] != '') ? absint( $question['options']['star_scale_length'] ) : 5;
$content[] = '';
$content[] = '
';
for ($i=1; $i <= $star_scale_length; $i++) {
$is_selected = $i == $selected_input ? "checked" : "";
$active_answer = $i == $selected_input ? "active-answer" : "";
$selected_stars = ($i <= $selected_input) && ($selected_input <= $star_scale_length) ? "fa-star" : "fa-star-o";
$content[] = '
';
}
$content[] = '
';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_TEXT_html( $question ){
$content = array();
// Input types placeholders
$survey_input_type_placeholder = isset($question['options']['placeholder']) && $question['options']['placeholder'] != "" ? $question['options']['placeholder'] : '';
$enable_word_limit = isset($question['options']['enable_word_limitation']) && $question['options']['enable_word_limitation'] == "on" ? true : false;
$show_limit = isset($question['options']['limit_counter']) && $question['options']['limit_counter'] == "on" ? true : false;
$limit_length = isset($question['options']['limit_length']) && $question['options']['limit_length'] != "" ? $question['options']['limit_length'] : "";
$limit_by = "Character";
$limit_checker = false;
$survey_question_limit_length_class = '';
if($enable_word_limit ){
if($show_limit){
$limit_checker = true;
}
$survey_question_limit_length_class = $this->html_class_prefix . 'check-word-limit ';
}
if($question['options']['limit_by'] && $question['options']['limit_by'] == "word"){
$limit_by = "Word";
}
if(intval($limit_length) > 0){
$limit_by .= "s ";
}
$limit_by .= __("left", "survey-maker");
if(intval($limit_length) <= 0){
$limit_by = '';
}
$minimal_theme = $this->options[ $this->name_prefix . 'is_minimal' ] ? true : false;
$minimal_class = $this->html_class_prefix . 'remove-default-border ' . $this->html_class_prefix . 'question-input-textarea ' . $this->html_class_prefix . 'question-input';
if( $minimal_theme ){
$minimal_class = $this->html_class_prefix . "minimal-theme-textarea-input";
}
$content[] = '';
$content[] = '
';
$content[] = '
';
if($limit_checker){
$content[] .= '
';
$content[] .= '
';
$content[] .= ''. $limit_length . ' ' . $limit_by;
$content[] .= '
';
$content[] .= '
';
}
$content[] = '
';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_SHORT_TEXT_html( $question ){
$content = array();
// Input types placeholders
$survey_input_type_placeholder = isset($question['options']['placeholder']) && $question['options']['placeholder'] != "" ? $question['options']['placeholder'] : '';
$enable_word_limit = isset($question['options']['enable_word_limitation']) && $question['options']['enable_word_limitation'] ? true : false;
$show_limit = isset($question['options']['limit_counter']) && $question['options']['limit_counter'] == "on" ? true : false;
$limit_length = isset($question['options']['limit_length']) && $question['options']['limit_length'] != "" ? $question['options']['limit_length'] : "";
$limit_by = "Character";
$limit_checker = false;
$survey_question_limit_length_class = '';
if($enable_word_limit ){
if($show_limit){
$limit_checker = true;
}
$survey_question_limit_length_class = $this->html_class_prefix . 'check-word-limit ';
}
if($question['options']['limit_by'] && $question['options']['limit_by'] == "word"){
$limit_by = "Word";
}
if(intval($limit_length) > 0){
$limit_by .= "s ";
}
$limit_by .= __("left", "survey-maker");
if(intval($limit_length) <= 0){
$limit_by = '';
}
$minimal_theme = $this->options[ $this->name_prefix . 'is_minimal' ] ? true : false;
$minimal_class = $this->html_class_prefix . 'remove-default-border ' .$this->html_class_prefix . 'question-input';
if( $minimal_theme ){
$minimal_class = $this->html_class_prefix . "minimal-theme-textarea-input";
}
$content[] = '';
$content[] = '
';
$content[] = '
';
if($limit_checker){
$content[] .= '
';
$content[] .= '
';
$content[] .= ''. $limit_length . ' ' . $limit_by;
$content[] .= '
';
$content[] .= '
';
}
$content[] = '
';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_NUMBER_html( $question ){
$content = array();
// Input types placeholders
$survey_input_type_placeholder = isset($question['options']['placeholder']) && $question['options']['placeholder'] != "" ? $question['options']['placeholder'] : '';
$enable_number_limit = isset($question['options']['enable_number_limitation']) && $question['options']['enable_number_limitation'] == "on" ? true : false;
$enable_number_limit_message = isset($question['options']['enable_number_error_message']) && $question['options']['enable_number_error_message'] == "on" ? true : false;
$number_limit_message = isset($question['options']['number_error_message']) && $question['options']['number_error_message'] != "" ? stripslashes(esc_attr($question['options']['number_error_message'])) : "";
$show_limit = isset($question['options']['enable_number_limit_counter']) && $question['options']['enable_number_limit_counter'] == "on" ? true : false;
$limit_length = isset($question['options']['number_limit_length']) && $question['options']['number_limit_length'] != "" ? $question['options']['number_limit_length'] : "";
$limit_by = "Character";
$limit_checker = false;
// $survey_question_limit_length_class = '';
$number_limit_class = "";
if($enable_number_limit){
if($show_limit){
$limit_checker = true;
}
$number_limit_class = $this->html_class_prefix . 'check-number-limit ';
}
if(intval($limit_length) > 0){
$limit_by .= "s ";
}
$limit_by .= __("left", "survey-maker");
if(intval($limit_length) <= 0){
$limit_by = '';
}
$minimal_theme = $this->options[ $this->name_prefix . 'is_minimal' ] ? true : false;
$minimal_class = $this->html_class_prefix . 'remove-default-border ' . $this->html_class_prefix . 'question-input';
if( $minimal_theme ){
$minimal_class = $this->html_class_prefix . "minimal-theme-textarea-input";
}
$content[] = '';
$content[] = '
';
$content[] = '
';
if($enable_number_limit_message){
$content[] = '
';
$content[] = '';
$content[] = $number_limit_message;
$content[] = '';
$content[] = '
';
}
if($limit_checker){
$content[] .= '
';
$content[] .= '
';
$content[] .= ''. $limit_length . ' ' . $limit_by;
$content[] .= '
';
$content[] .= '
';
}
$content[] = '
';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_PHONE_html( $question ){
$content = array();
// Input types placeholders
$survey_input_type_placeholder = isset($question['options']['placeholder']) && $question['options']['placeholder'] != "" ? $question['options']['placeholder'] : '';
//Input types value
$enable_url_parameter = isset($question['options']['enable_url_parameter']) && $question['options']['enable_url_parameter'] == true ? true : false;
$url_parameter = $enable_url_parameter && isset($question['options']['url_parameter']) && $question['options']['url_parameter'] != "" ? $question['options']['url_parameter'] : '';
$survey_input_type_value = isset($_GET[$url_parameter]) && $_GET[$url_parameter] ? $_GET[$url_parameter] : '';
$enable_number_limit = isset($question['options']['enable_number_limitation']) && $question['options']['enable_number_limitation'] == "on" ? true : false;
$enable_number_limit_message = isset($question['options']['enable_number_error_message']) && $question['options']['enable_number_error_message'] == "on" ? true : false;
$number_limit_message = isset($question['options']['number_error_message']) && $question['options']['number_error_message'] != "" ? stripslashes(esc_attr($question['options']['number_error_message'])) : "";
$show_limit = isset($question['options']['enable_number_limit_counter']) && $question['options']['enable_number_limit_counter'] == "on" ? true : false;
$limit_length = isset($question['options']['number_limit_length']) && $question['options']['number_limit_length'] != "" ? $question['options']['number_limit_length'] : "";
$limit_by = "Character";
$limit_checker = false;
$number_limit_class = $this->html_class_prefix . 'is-phone-type ';
if($enable_number_limit){
if($show_limit){
$limit_checker = true;
}
$number_limit_class .= $this->html_class_prefix . 'check-number-limit ';
}
if(intval($limit_length) > 0){
$limit_by .= "s ";
}
$limit_by .= __("left", "survey-maker");
if(intval($limit_length) <= 0){
$limit_by = '';
}
$minimal_theme = $this->options[ $this->name_prefix . 'is_minimal' ] ? true : false;
$minimal_class = $this->html_class_prefix . 'remove-default-border ' . $this->html_class_prefix . 'question-input';
if( $minimal_theme ){
$minimal_class = $this->html_class_prefix . "minimal-theme-textarea-input";
}
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_DATE_html( $question ){
$content = array();
$minimal_theme = $this->options[ $this->name_prefix . 'is_minimal' ] ? true : false;
$minimal_class = $this->html_class_prefix . 'remove-default-border ' . $this->html_class_prefix . 'question-date-input ' . $this->html_class_prefix . 'question-input';
if( $minimal_theme ){
$minimal_class = $this->html_class_prefix . "minimal-theme-textarea-input " . $this->html_class_prefix."minimal-theme-input-date";
}
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_TIME_html( $question ){
$content = array();
// $minimal_theme = $this->options[ $this->name_prefix . 'is_minimal' ] ? true : false;
$minimal_class = $this->html_class_prefix . 'remove-default-border ' . $this->html_class_prefix . 'question-date-input ' . $this->html_class_prefix . 'question-input';
// if( $minimal_theme ){
// $minimal_class = $this->html_class_prefix . "minimal-theme-textarea-input " . $this->html_class_prefix."minimal-theme-input-date";
// }
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_DATE_TIME_html( $question ){
$content = array();
$minimal_class = $this->html_class_prefix . 'remove-default-border ' . $this->html_class_prefix . 'question-date-input ' . $this->html_class_prefix . 'question-input';
$minimal_theme = $this->options[ $this->name_prefix . 'is_minimal' ] ? true : false;
$minimal_date_class = $this->html_class_prefix . 'remove-default-border ' . $this->html_class_prefix . 'question-date-input ' . $this->html_class_prefix . 'question-input';
if( $minimal_theme ){
$minimal_date_class = $this->html_class_prefix . "minimal-theme-textarea-input " . $this->html_class_prefix."minimal-theme-input-date";
}
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_EMAIL_html( $question ){
$content = array();
// Input types placeholders
$survey_input_type_placeholder = isset($question['options']['placeholder']) && $question['options']['placeholder'] != "" ? $question['options']['placeholder'] : '';
$minimal_theme = $this->options[ $this->name_prefix . 'is_minimal' ] ? true : false;
$minimal_class = $this->html_class_prefix . 'remove-default-border ' . $this->html_class_prefix . 'question-email-input ' . $this->html_class_prefix . 'question-input';
if( $minimal_theme ){
$minimal_class = $this->html_class_prefix . "minimal-theme-textarea-input " . $this->html_class_prefix . "question-email-input";
}
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function ays_survey_question_type_NAME_html( $question ){
$content = array();
// Input types placeholders
$survey_input_type_placeholder = isset($question['options']['placeholder']) && $question['options']['placeholder'] != "" ? $question['options']['placeholder'] : '';
$minimal_theme = $this->options[ $this->name_prefix . 'is_minimal' ] ? true : false;
$minimal_class = $this->html_class_prefix . 'remove-default-border ' . $this->html_class_prefix . 'question-input';
if( $minimal_theme ){
$minimal_class = $this->html_class_prefix . "minimal-theme-textarea-input";
}
$content[] = '';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function create_restricted_content( $limit_message ){
$content = array();
$content[] = '';
$content[] = '';
$content[] = '
';
$content = implode( '', $content );
return $content;
}
public function get_styles(){
$content = array();
$content[] = '';
$content = implode( '', $content );
return $content;
}
public function get_custom_css(){
$content = array();
if( $this->options[ $this->name_prefix . 'custom_css' ] != '' ){
$content[] = '';
}
$content = implode( '', $content );
return $content;
}
public function get_encoded_options( $limit ){
$content = array();
if( isset( $this->options[ $this->name_prefix . 'submit_redirect_delay' ] ) ){
$this->options[ $this->name_prefix . 'submit_redirect_seconds'] = Survey_Maker_Data::secondsToWords( intval( $this->options[ $this->name_prefix . 'submit_redirect_delay' ] ) );
}
// Animation Top (px)
$setting_options = Survey_Maker_Data::get_setting_data( 'options' );
$survey_animation_top = ( isset($setting_options[ 'survey_animation_top' ]) && $setting_options[ 'survey_animation_top' ] != '' ) ? intval( $setting_options[ 'survey_animation_top' ] ) : '';
$setting_options['survey_enable_animation_top'] = isset($setting_options['survey_enable_animation_top']) ? $setting_options['survey_enable_animation_top'] : 'on';
$survey_enable_animation_top = ( isset($setting_options[ 'survey_enable_animation_top' ]) && $setting_options[ 'survey_enable_animation_top' ] == 'on' ) ? true : false;
$this->options['is_user_logged_in'] = is_user_logged_in();
$this->options[ $this->name_prefix . 'animation_top'] = $survey_animation_top;
$this->options[ $this->name_prefix . 'enable_animation_top'] = $survey_enable_animation_top;
$options = array();
if( ! $limit ){
foreach( $this->options as $k => $q ){
if( strpos( $k, 'email' ) !== false ){
unset( $this->options[ $k ] );
}
}
$options = $this->options;
}else{
if($this->options[ $this->name_prefix . 'redirect_delay' ] && $this->options[ $this->name_prefix . 'redirect_delay' ] != ''){
if($this->options[ $this->name_prefix . 'redirect_url' ] && $this->options[ $this->name_prefix . 'redirect_url' ] != ''){
if($this->options[ $this->name_prefix . 'limit_users' ]){
$options = array(
$this->name_prefix . 'submit_redirect_seconds' => Survey_Maker_Data::secondsToWords( intval( $this->options[ $this->name_prefix . 'submit_redirect_delay' ] ) ),
$this->name_prefix . 'submit_redirect_delay' => intval( $this->options[ $this->name_prefix . 'submit_redirect_delay' ] ),
$this->name_prefix . 'submit_redirect_url' => $this->options[ $this->name_prefix . 'submit_redirect_url' ],
$this->name_prefix . 'limit_users' => $this->options[ $this->name_prefix . 'limit_users' ],
$this->name_prefix . 'redirect_url' => $this->options[ $this->name_prefix . 'redirect_url' ],
$this->name_prefix . 'redirect_delay' => intval( $this->options[ $this->name_prefix . 'redirect_delay' ] ),
$this->name_prefix . 'redirect_delay_seconds' => Survey_Maker_Data::secondsToWords( intval( $this->options[ $this->name_prefix . 'redirect_delay' ] ) ),
);
}
}
}
$options[ $this->name_prefix . 'enable_survey_start_loader' ] = $this->options[ $this->name_prefix . 'enable_survey_start_loader' ];
}
$content[] = '';
$content = implode( '', $content );
return $content;
}
protected function ays_survey_check_limitations($limit_by, $limit_users_data){
$is_limited = false;
switch($limit_by){
case 'cookie':
// PRO FEATURE
// $started_user_count = Survey_Maker_Data::get_limit_cookie_count( $limit_users_attr );
// if( $quiz_max_pass_count > $started_user_count){
// $limit_users_attr['increase_count'] = true;
// }
$check_cookie = Survey_Maker_Data::ays_survey_check_cookie( $limit_users_data );
$return_false_status_arr = array(
"status" => false,
"message" => __( 'You already passed this survey.', "survey-maker" ),
"limited" => true
);
// PRO FEATURE
// if( $quiz_max_pass_count <= $started_user_count){
// echo json_encode( $return_false_status_arr );
// wp_die();
// }
if( ! $check_cookie ){
$set_cookie = Survey_Maker_Data::ays_survey_set_cookie( $limit_users_data );
$is_limited = true;
}
else{
echo json_encode( $return_false_status_arr );
wp_die();
}
break;
case 'ip_cookie':
$check_user_by_ip = Survey_Maker_Data::get_user_by_ip( $limit_users_data['id'] );
$started_user_count = Survey_Maker_Data::get_limit_cookie_count( $limit_users_data );
$check_cookie = Survey_Maker_Data::ays_survey_check_cookie( $limit_users_data );
if ( ! $check_cookie || $check_user_by_ip <= 0 ) {
if ( ! $check_cookie ) {
$set_cookie = Survey_Maker_Data::ays_survey_set_cookie( $limit_users_data );
}
}
$is_limited = true;
break;
}
return $is_limited;
}
public function ays_survey_get_user_information() {
$output = array();
if(isset($_POST['nonce']) && wp_verify_nonce($_POST['nonce'], 'survey_maker_autofill_nonce')){
if(is_user_logged_in()) {
$output = wp_get_current_user();
} else {
$output = array();
}
}
return $output;
}
public function ays_survey_popup_set_cookie(){
if( isset( $_REQUEST['id'] ) && $_REQUEST['id'] != '' ){
$id = sanitize_text_field( $_REQUEST['id'] );
}else{
$id = null;
}
if( $id === null ){
return array(
'status' => false
);
}
$cookie_name = 'ays_survey_popup_cookie_name_'.$id;
$cookie_value = 'ays_survey_popup_cookie_value_'.$id;
$cookie_expiration = time() + (12 * 30 * 24 * 60 * 60);
setcookie($cookie_name, $cookie_value, $cookie_expiration, '/');
return array(
'status' => true
);
}
public function get_css_mobile_part($mobile_max_width, $mobile_width, $pagination_number_height) {
$content = '';
$question_image_width_mobile = '100%';
if( $this->options[ $this->name_prefix . 'question_image_width_mobile' ] != '' ){
$question_image_width_mobile = $this->options[ $this->name_prefix . 'question_image_width_mobile' ] . 'px';
}
$question_image_height_mobile = 'auto';
if( $this->options[ $this->name_prefix . 'question_image_height_mobile' ] != '' ){
$question_image_height_mobile = $this->options[ $this->name_prefix . 'question_image_height_mobile' ] . 'px';
}
else{
if($this->options[ $this->name_prefix . 'question_image_height' ] != ''){
$question_image_height_mobile = $this->options[ $this->name_prefix . 'question_image_height' ] . 'px';
}
}
switch($this->options[ $this->name_prefix . 'logo_image_position_mobile' ]){
case "right":
$survey_logo_image_position_mobile = "right: 5px;";
break;
case "left":
$survey_logo_image_position_mobile = "left: 5px;";
break;
case "center":
$survey_logo_image_position_mobile = "left: 50%;";
break;
default:
$survey_logo_image_position_mobile = "right: 5px;";
break;
}
switch($this->options[ $this->name_prefix . 'start_page_button_pos_mobile' ]){
case "left":
$survey_start_page_button_pos_mobile = 'justify-content: flex-start;';
break;
case "center":
$survey_start_page_button_pos_mobile = 'justify-content: center;';
break;
case "right":
$survey_start_page_button_pos_mobile = 'justify-content: flex-end;';
break;
}
$survey_pagination_positioning_mobile = isset($this->options[ $this->name_prefix . 'pagination_positioning_mobile' ]) ? $this->options[ $this->name_prefix . 'pagination_positioning_mobile' ] : 'none';
$pagination_positioning_mobile = "row";
// $pagination_number_height = "";
switch ($survey_pagination_positioning_mobile) {
case 'none':
$pagination_positioning_mobile = "row";
break;
case 'reverse':
$pagination_positioning_mobile = "row-reverse";
break;
case 'column':
$pagination_positioning_mobile = "column";
// $pagination_number_height = "line-height: 1;";
break;
case 'column_reverse':
$pagination_positioning_mobile = "column-reverse";
// $pagination_number_height = "line-height: 1;";
break;
default:
$pagination_positioning_mobile = "row";
// $pagination_number_height = "";
break;
}
// Question padding mobile
$question_padding = $this->options[ $this->name_prefix . 'question_padding_mobile' ];
$question_caption_text_display = !$this->options[ $this->name_prefix . 'question_caption_hide_on_mobile' ] ? 'block' : 'none';
$question_border_radius = $this->options[ $this->name_prefix . 'question_border_radius_mobile' ];
$content .= '
@media screen and (max-width: 640px){
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' {
max-width: '. $mobile_max_width .';
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' {
width: ' . $mobile_width . ';
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'question-box{
width: 100%;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'live-bar-main{
flex-wrap: wrap;
flex-direction: '.$pagination_positioning_mobile.';
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'footer-with-live-bar{
flex-direction: column-reverse;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'live-bar-main{
margin-bottom: 10px;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'question-required-icon,
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'question-title {
font-size: ' . $this->options[ $this->name_prefix . 'question_font_size_mobile' ] . 'px;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'question {
' . ( $this->options[ $this->name_prefix . 'logo' ] != '' ? 'padding: '.$question_padding.'px '.$question_padding.'px 0 '.$question_padding.'px;' : 'padding: '.$question_padding.'px;' ) . '
border-radius: ' . $question_border_radius . 'px;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'section-buttons {
margin-top: ' . $this->options[ $this->name_prefix . 'buttons_top_distance_mobile' ] . 'px;
text-align: ' . $this->options[ $this->name_prefix . 'buttons_alignment_mobile' ] . ';
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'section-buttons .' . $this->html_class_prefix . 'section-button-container{
border-radius: ' . $this->options[ $this->name_prefix . 'buttons_border_radius_mobile' ] . 'px;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'section-buttons .' . $this->html_class_prefix . 'section-button-container .' . $this->html_class_prefix . 'section-button-content .' . $this->html_class_prefix . 'section-button{
font-size: ' . $this->options[ $this->name_prefix . 'buttons_mobile_font_size' ] . 'px;
letter-spacing: ' . $this->options[ $this->name_prefix . 'buttons_text_letter_spacing_mobile' ] . 'px;
line-height: 2.5;
white-space: normal;
word-break: break-word;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'title{
text-align: ' . $this->options[ $this->name_prefix . 'title_alignment_mobile' ] . ';
font-size: ' . $this->options[ $this->name_prefix . 'title_font_size_for_mobile' ] . 'px;
letter-spacing: ' . $this->options[ $this->name_prefix . 'title_letter_spacing_mobile' ] . 'px;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'sections .' . $this->html_class_prefix . 'section-title-row-main{
text-align: ' . $this->options[ $this->name_prefix . 'section_title_alignment_mobile' ] . ';
font-size: ' . $this->options[ $this->name_prefix . 'section_title_font_size_mobile' ] . 'px;
letter-spacing: ' . $this->options[ $this->name_prefix . 'section_title_letter_spacing_mobile' ] . 'px;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'sections .' . $this->html_class_prefix . 'section-desc{
text-align: ' . $this->options[ $this->name_prefix . 'section_description_alignment_mobile' ] . ';
font-size: ' . $this->options[ $this->name_prefix . 'section_description_font_size_mobile' ] . 'px;
letter-spacing: ' . $this->options[ $this->name_prefix . 'section_description_letter_spacing_mobile' ] . 'px;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' input.' . $this->html_class_prefix . 'question-input {
font-size: ' . $this->options[ $this->name_prefix . 'answer_font_size_on_mobile' ] . 'px;
letter-spacing: ' . $this->options[ $this->name_prefix . 'answer_letter_spacing_mobile' ] . 'px;
height: auto;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' textarea.' . $this->html_class_prefix . 'question-input {
letter-spacing: ' . $this->options[ $this->name_prefix . 'answer_letter_spacing_mobile' ] . 'px;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'answer {
padding: ' . $this->options[ $this->name_prefix . 'answers_padding_mobile' ] . 'px ' . $this->options[ $this->name_prefix . 'answers_padding_mobile' ] . 'px ' . $this->options[ $this->name_prefix . 'answers_padding_mobile' ] . 'px 0;
margin: ' . $this->options[ $this->name_prefix . 'answers_gap_mobile' ] . 'px ' . $this->options[ $this->name_prefix . 'answers_gap_mobile' ] . 'px ' . $this->options[ $this->name_prefix . 'answers_gap_mobile' ] . 'px 0;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'answer-label-content > span {
font-size: ' . $this->options[ $this->name_prefix . 'answer_font_size_on_mobile' ] . 'px;
letter-spacing: ' . $this->options[ $this->name_prefix . 'answer_letter_spacing_mobile' ] . 'px;
line-height: 1;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'question-select.dropdown div.text,
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'question-select.dropdown div.item {
font-size: ' . $this->options[ $this->name_prefix . 'answer_font_size_on_mobile' ] . 'px !important;
letter-spacing: ' . $this->options[ $this->name_prefix . 'answer_letter_spacing_mobile' ] . 'px;
line-height: 1 !important;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'section.' . $this->html_class_prefix . 'section-start-page .' . $this->html_class_prefix . 'section-header .' . $this->html_class_prefix . 'section-title-row {
justify-content: ' . $this->options[ $this->name_prefix . 'start_page_title_pos_mobile' ] . ';
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'question-select.dropdown div.item {
font-size: ' . $this->options[ $this->name_prefix . 'answer_font_size_on_mobile' ] . 'px !important;
letter-spacing: ' . $this->options[ $this->name_prefix . 'answer_letter_spacing_mobile' ] . 'px;
line-height: 1 !important;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'section .' . $this->html_class_prefix . 'question .' . $this->html_class_prefix . 'image-logo-url{
'.$survey_logo_image_position_mobile.'
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'live-bar-status .' . $this->html_class_prefix . 'live-bar-status-text{
font-size: ' . $this->options[ $this->name_prefix . 'answer_font_size_on_mobile' ] . 'px;
letter-spacing: ' . $this->options[ $this->name_prefix . 'answer_letter_spacing_mobile' ] . 'px;
'.$pagination_number_height.'
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'cover-photo-title-wrap{
height: ' . $this->options[ $this->name_prefix . 'cover_photo_mobile_height' ] . 'px;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'question-image-caption span{
color: '.$this->options[ $this->name_prefix . 'question_caption_text_color_mobile' ].' !important;
font-size: '.$this->options[ $this->name_prefix . 'question_caption_font_size_on_mobile' ].'px;
text-transform: '.$this->options[ $this->name_prefix . 'question_caption_text_transform_mobile' ].' !important;
letter-spacing: '.$this->options[ $this->name_prefix . 'question_caption_letter_spacing_mobile' ].'px !important;
display: '.$question_caption_text_display .';
text-align: ' . $this->options[ $this->name_prefix . 'question_caption_text_alignment_on_mobile' ] . ';
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'live-bar-status .' . $this->html_class_prefix . 'live-bar-status-text{
font-size: ' . $this->options[ $this->name_prefix . 'progress_bar_text_font_size_on_mobile' ] . 'px;
color: ' . $this->options[ $this->name_prefix . 'pagination_text_color_mobile' ] . ';
letter-spacing: ' . $this->options[ $this->name_prefix . 'progress_bar_text_letter_spacing_mobile' ] . 'px;
text-transform: '.$this->options[ $this->name_prefix . 'progress_bar_text_transform_mobile' ].';
line-height: 1;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'question-image {
width: ' . $question_image_width_mobile . ';
height: ' . $question_image_height_mobile . ';
object-fit: ' . $this->options[ $this->name_prefix . 'question_image_sizing_mobile' ] . ';
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'answer-image {
object-fit: ' . $this->options[ $this->name_prefix . 'answers_object_fit_mobile' ] . ';
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'section-start-page .' . $this->html_class_prefix . 'section-buttons {
display: flex;
'.$survey_start_page_button_pos_mobile.'
}
}';
$content .= '
@media screen and (max-width: 580px) {
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . '.' . $this->html_class_prefix . 'container .' . $this->html_class_prefix . 'section .' . $this->html_class_prefix . 'answer-label .' . $this->html_class_prefix . 'answer-image-container{
height: ' . $this->options[ $this->name_prefix . 'answers_image_size_mobile' ] . 'px;
}
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . ' .' . $this->html_class_prefix . 'live-bar-main{
justify-content: center;
}
}';
$content .= '
@media screen and (min-width: 580px) and (max-width: 1024px) {
#' . $this->html_class_prefix . 'container-' . $this->unique_id_in_class . '.' . $this->html_class_prefix . 'container .' . $this->html_class_prefix . 'section .' . $this->html_class_prefix . 'answer-label .' . $this->html_class_prefix . 'answer-image-container{
height: 150px;
}
}';
return $content;
}
public function ays_generate_survey_popup_method( $attr ){
$id = (isset($attr['id'])) ? absint(intval($attr['id'])) : null;
if (is_null($id)) {
return '';
}
$this->enqueue_scripts_popups();
$content = $this->ays_popup_shortcode_content($id, $attr);
return $content ? str_replace( array( "\r\n", "\n", "\r" ), "\n", $content ) : '';
}
public function ays_popup_shortcode_content( $id, $attr ){
global $wpdb;
$post_id = get_the_ID();
$popup_surveys_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "popup_surveys";
$surveys_table = $wpdb->prefix . SURVEY_MAKER_DB_PREFIX . "surveys";
$sql = "SELECT p_s.*, s.options as s_options, s.status as survey_status
FROM {$popup_surveys_table} as p_s
LEFT JOIN {$surveys_table} AS s
ON p_s.survey_id = s.id
WHERE p_s.id = {$id}";
$popup = $wpdb->get_row( $sql, "ARRAY_A" );
if( empty( $popup ) ){
return '';
}
$survey_status = (isset($popup['survey_status'] ) && $popup['survey_status'] != '') ? $popup['survey_status'] : 'published';
$is_elementor_exists = Survey_Maker_Data::ays_survey_is_elementor();
if($survey_status == 'published' && !$is_elementor_exists){
$show_all = $popup['show_all'];
switch($show_all){
case 'all':
$show_popup = true;
break;
case 'selected':
$show_popup = false;
break;
case 'except':
$show_popup = true;
break;
default:
$show_popup = true;
$show_all = 'all';
break;
}
$show = array('selected');
$options = array();
$survey_options = array();
if ($popup['options'] != '' || $popup['options'] != null) {
$options = json_decode( $popup['options'], true );
}
if ($popup['s_options'] != '' || $popup['s_options'] != null) {
$survey_options = json_decode( $popup['s_options'], true );
}
// Title
$popup_title = isset( $popup["title"] ) && $popup["title"] != "" ? stripslashes( esc_attr( $popup["title"] ) ) : "";
// Show popup title
$survey_popup_enable_show_title = (isset($options["popup_enable_show_title"]) && $options["popup_enable_show_title"] == "on") ? true : false;
// Popup title font size
$survey_popup_title_font_size = (isset($options['popup_title_font_size']) && $options['popup_title_font_size'] != '') ? absint ( intval( $options['popup_title_font_size'] ) ) : 25;
// Popup title font size on mobile
$survey_popup_title_mobile_font_size = (isset($options['popup_title_mobile_font_size']) && $options['popup_title_mobile_font_size'] != '') ? absint ( intval( $options['popup_title_mobile_font_size'] ) ) : $survey_popup_title_font_size;
// Popup title bg color
$survey_popup_title_bg_color = (isset($options["popup_title_bg_color"]) && $options["popup_title_bg_color"] != "") ? esc_attr ( $options["popup_title_bg_color"] ) : "#000000";
// Popup title bg color mobile
$options["popup_title_bg_color_mobile"] = isset($options["popup_title_bg_color_mobile"]) ? $options["popup_title_bg_color_mobile"] : $survey_popup_title_bg_color;
$survey_popup_title_bg_color_mobile = (isset($options["popup_title_bg_color_mobile"]) && $options["popup_title_bg_color_mobile"] != "") ? esc_attr ( $options["popup_title_bg_color_mobile"] ) : "#000000";
// Popup title text color
$survey_popup_title_text_color = (isset($options["popup_title_text_color"]) && $options["popup_title_text_color"] != "") ? esc_attr ( $options["popup_title_text_color"] ) : "#000000";
// Popup title text color mobile
$options["popup_title_text_color_mobile"] = isset($options["popup_title_text_color_mobile"]) ? $options["popup_title_text_color_mobile"] : $survey_popup_title_text_color;
$survey_popup_title_text_color_mobile = (isset($options["popup_title_text_color_mobile"]) && $options["popup_title_text_color_mobile"] != "") ? esc_attr ( $options["popup_title_text_color_mobile"] ) : "#000000";
// Popup title alignment
$survey_popup_title_alignment = (isset($options["popup_title_alignment"]) && $options["popup_title_alignment"] != "") ? esc_attr ( $options["popup_title_alignment"] ) : "left";
// Popup title alignment on mobile
$options["popup_title_alignment_on_mobile"] = isset($options["popup_title_alignment_on_mobile"]) ? $options["popup_title_alignment_on_mobile"] : $survey_popup_title_alignment;
$survey_popup_title_alignment_on_mobile = (isset($options["popup_title_alignment_on_mobile"]) && $options["popup_title_alignment_on_mobile"] != "") ? esc_attr ( $options["popup_title_alignment_on_mobile"] ) : "left";
// Popup title transform
$survey_popup_title_transform = (isset($options["popup_title_transform"]) && $options["popup_title_transform"] != "") ? esc_attr ( $options["popup_title_transform"] ) : "none";
// Popup title transform mobile
$options["popup_title_transform_mobile"] = isset($options["popup_title_transform_mobile"]) ? $options["popup_title_transform_mobile"] : $survey_popup_title_transform;
$survey_popup_title_transform_mobile = (isset($options["popup_title_transform_mobile"]) && $options["popup_title_transform_mobile"] != "") ? esc_attr ( $options["popup_title_transform_mobile"] ) : "none";
// Popup title letter spacing
$survey_popup_title_letter_spacing = (isset( $options[ "popup_title_letter_spacing" ] ) && $options["popup_title_letter_spacing"] != '' && $options["popup_title_letter_spacing"] != '0') ? esc_attr( $options["popup_title_letter_spacing"] ) : 0;
// Popup title letter spacing mobile
$options['popup_title_letter_spacing_on_mobile' ] = isset($options['popup_title_letter_spacing_on_mobile' ]) ? $options['popup_title_letter_spacing_on_mobile' ] : $survey_popup_title_letter_spacing;
$survey_popup_title_letter_spacing_on_mobile = (isset( $options['popup_title_letter_spacing_on_mobile' ] ) && $options['popup_title_letter_spacing_on_mobile'] != '' && $options['popup_title_letter_spacing_on_mobile'] != '0') ? esc_attr( $options['popup_title_letter_spacing_on_mobile'] ) : 0;
// Hide popup title on mobile
$survey_popup_hide_title_on_mobile = (isset($options["popup_hide_title_on_mobile"]) && $options["popup_hide_title_on_mobile"] == "on") ? true : false;
// Title border radius
$survey_popup_title_border_radius = (isset($options["popup_title_border_radius"]) && $options["popup_title_border_radius"] != "") ? absint ( intval( $options["popup_title_border_radius"] ) ) : 0;
// Title border radius mobile
$survey_popup_title_border_radius_mobile = (isset($options["popup_title_border_radius_mobile"]) && $options["popup_title_border_radius_mobile"] != "") ? absint ( intval( $options["popup_title_border_radius_mobile"] ) ) : 0;
// Width
$popup_survey_width = (isset($options['width']) && $options['width'] != '') ? absint ( intval( $options['width'] ) ) : 800;
// Mobile width
$options['width_mobile'] = isset($options['width_mobile']) ? $options['width_mobile'] : $popup_survey_width;
$popup_survey_width_mobile = (isset($options['width_mobile']) && $options['width_mobile'] != '') ? absint ( intval( $options['width_mobile'] ) ) : 800;
// Height
$popup_survey_height = (isset($options['height']) && $options['height'] != '') ? absint ( intval( $options['height'] ) ) : 450;
// Height mobile
$options['height_mobile'] = isset($options['height_mobile']) ? $options['height_mobile'] : $popup_survey_height;
$popup_survey_height_mobile = (isset($options['height_mobile']) && $options['height_mobile'] != '') ? absint ( intval( $options['height_mobile'] ) ) : 450;
// Popup Position
$popup_position = (isset($options['popup_position']) && $options['popup_position'] != 'center-center') ? $options['popup_position'] : 'center-center';
// Popup Margin
$popup_margin = (isset($options['popup_margin']) && $options['popup_margin'] != '') ? $options['popup_margin'] : '0';
$hide_popup = (isset($options['hide_popup']) && $options['hide_popup'] == 'on') ? $options['hide_popup'] : 'off';
// Hide popup after close
$hide_popup_after_close = (isset($options['hide_popup_after_close']) && $options['hide_popup_after_close'] == 'on') ? esc_attr($options['hide_popup_after_close']) : 'off';
// Hide popup on mobile
$options['hide_popup_on_mobile'] = isset( $options['hide_popup_on_mobile'] ) ? esc_attr($options['hide_popup_on_mobile']) : "off";
$hide_popup_on_mobile = (isset($options['hide_popup_on_mobile']) && $options['hide_popup_on_mobile'] == 'on') ? true : false;
// Hide popup on PC
$options['hide_popup_on_pc'] = isset( $options['hide_popup_on_pc'] ) ? esc_attr($options['hide_popup_on_pc']) : "off";
$hide_popup_on_pc = (isset($options['hide_popup_on_pc']) && $options['hide_popup_on_pc'] == 'on') ? true : false;
// Hide popup on tablet
$options['hide_popup_on_tablet'] = isset( $options['hide_popup_on_tablet'] ) ? esc_attr($options['hide_popup_on_tablet']) : "off";
$hide_popup_on_tablet = (isset($options['hide_popup_on_tablet']) && $options['hide_popup_on_tablet'] == 'on') ? true : false;
// Close by clicking outside the box
$close_popup_overlay_outside_click = (isset($options['close_popup_overlay_outside_click']) && $options['close_popup_overlay_outside_click'] == 'on') ? esc_attr($options['close_popup_overlay_outside_click']) : 'off';
// $survey_bg = (isset($survey_options['survey_background_color']) && $survey_options['survey_background_color'] != '') ? $survey_options['survey_background_color'] : '#ffffff';
// $survey_theme = (isset($survey_options['survey_theme']) && $survey_options['survey_theme'] != '') ? $survey_options['survey_theme'] : 'classic_light';
// $is_minimal = $survey_theme == 'minimal' ? true : false;
// $is_modern = $survey_theme == 'modern' ? true : false;
// if( $is_minimal || $is_modern){
// $survey_bg = '#ffffff';
// }
// $survey_text_color = (isset($survey_options['survey_text_color']) && $survey_options['survey_text_color'] != '') ? $survey_options['survey_text_color'] : '#ffffff';
// // Popup full screen mode
$survey_popup_full_screen = (isset($options["full_screen_mode"]) && $options["full_screen_mode"] == "on") ? true : false;
// // Popup background color
$popup_bg_color = (isset($options['popup_bg_color']) && $options['popup_bg_color'] != '') ? $options['popup_bg_color'] : '#ffffff';
// Popup background color | Mobile
$popup_bg_color_mobile = (isset($options['popup_bg_color_mobile']) && $options['popup_bg_color_mobile'] != '') ? esc_attr($options['popup_bg_color_mobile']) : $popup_bg_color;
// // Popup trigger type
$popup_trigger_type = (isset($options["popup_trigger"]) && $options["popup_trigger"] != "") ? esc_attr($options["popup_trigger"]) : "on_load";
// Popup close after finish
$survey_enable_popup_close_after_finish = (isset($options["enable_popup_close_after_finish"]) && $options["enable_popup_close_after_finish"] == "on") ? true : false;
$survey_popup_close_after_finish_delay = (isset($options[ 'popup_close_after_finish_delay' ]) && $options[ 'popup_close_after_finish_delay' ] != '') ? absint ( intval( $options[ 'popup_close_after_finish_delay' ] ) ) : '';
// Popup selector
$popup_selector = (isset($options["popup_selector"]) && $options["popup_selector"] != "") ? stripslashes( esc_attr($options["popup_selector"])) : "";
// Close by pressing the ESC
$survey_popup_enable_close_by_esc = (isset($options["popup_enable_close_by_esc"]) && $options["popup_enable_close_by_esc"] != '') ? $options["popup_enable_close_by_esc"] : 'off';
// if($show_all != 'all'){
// if($post_id != false){
// $post = get_post( $post_id );
// $this_post_title = strval( $post->ID );
// $except_posts = array();
// $except_post_types = array();
// $postType = $post->post_type;
// if (isset($options['except_posts']) && !empty($options['except_posts'])) {
// $except_posts = $options['except_posts'];
// }
// if (isset($options['except_post_types']) && !empty($options['except_post_types'])) {
// $except_post_types = $options['except_post_types'];
// }
// $except_all_post_types = ( isset( $options['all_posts'] ) && ! empty( $options['all_posts'] ) ) ? $options['all_posts'] : array();
// if ( is_front_page() ) {
// if( isset($options['show_on_home_page']) && $options['show_on_home_page'] == 'on' ){
// $show_popup = true;
// }else{
// $show_popup = false;
// }
// }
// if( in_array( $post_id . "", $except_posts ) ){
// if( in_array( $show_all, $show ) ){
// $show_popup = true;
// }else{
// $show_popup = false;
// }
// }elseif( !in_array( $this_post_title, $except_posts ) && in_array( $postType, $except_all_post_types ) ) {
// if( in_array( $show_all, $show ) ){
// $show_popup = true;
// }else{
// $show_popup = false;
// }
// }
// }
// }
if($hide_popup_on_mobile){
if(Survey_Maker_Data::ays_survey_pb_detect_mobile_device() === true){
$show_popup = false;
}
}
if($hide_popup_on_pc){
if(Survey_Maker_Data::ays_survey_pb_detect_mobile_device() === false && Survey_Maker_Data::ays_survey_pb_detect_tablet_device() === false){
$show_popup = false;
}
}
if($hide_popup_on_tablet){
if(Survey_Maker_Data::ays_survey_pb_detect_tablet_device() === true){
$show_popup = false;
}
}
switch($popup_trigger_type){
case 'on_click':
$display_popup_on_load = 'display_none_not_important';
break;
case 'on_load':
default:
$display_popup_on_load = '';
break;
}
if( ! isset( $_COOKIE[ 'ays_survey_popup_cookie_name_' . $popup['id'] ] ) && ! isset( $_COOKIE[ 'ays_survey_popup_hide_after_click_close_' . $popup['id'] ] ) ){
if ($show_popup) {
$shortcode2 = '[ays_survey id="'. $popup['survey_id'] .'"]';
// $popup_survey_view = "