| 1 |
<?php |
| 2 |
class Survey_Maker_Settings_Actions { |
| 3 |
private $plugin_name; |
| 4 |
|
| 5 |
public function __construct($plugin_name) { |
| 6 |
$this->plugin_name = $plugin_name; |
| 7 |
} |
| 8 |
|
| 9 |
public function store_data(){ |
| 10 |
global $wpdb; |
| 11 |
$settings_table = $wpdb->prefix . "ayssurvey_settings"; |
| 12 |
$name_prefix = 'ays_'; |
| 13 |
if( isset($_REQUEST["settings_action"]) && wp_verify_nonce( sanitize_text_field( $_REQUEST["settings_action"] ), 'settings_action' ) ){ |
| 14 |
$success = 0; |
| 15 |
|
| 16 |
$roles = (isset($_REQUEST['ays_user_roles']) && !empty($_REQUEST['ays_user_roles'])) ? array_map( 'sanitize_text_field', $_REQUEST['ays_user_roles'] ) : array('administrator'); |
| 17 |
|
| 18 |
$fields = array(); |
| 19 |
|
| 20 |
// Survey Question default type |
| 21 |
$survey_default_type = (isset($_REQUEST[$name_prefix .'survey_default_type']) && $_REQUEST[$name_prefix .'survey_default_type'] != '') ? sanitize_text_field($_REQUEST[$name_prefix .'survey_default_type']) : ''; |
| 22 |
$survey_answer_default_count = (isset($_REQUEST[$name_prefix . 'survey_answer_default_count']) && $_REQUEST[$name_prefix . 'survey_answer_default_count'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_answer_default_count'] ) ) : 3; |
| 23 |
|
| 24 |
// Textarea height (public) |
| 25 |
$survey_textarea_height = (isset($_REQUEST[$name_prefix . 'survey_textarea_height']) && $_REQUEST[$name_prefix . 'survey_textarea_height'] != '' && $_REQUEST[$name_prefix . 'survey_textarea_height'] != 0 ) ? absint( sanitize_text_field($_REQUEST[$name_prefix . 'survey_textarea_height']) ) : 100; |
| 26 |
|
| 27 |
// WP Editor height |
| 28 |
$survey_wp_editor_height = (isset($_REQUEST[$name_prefix . 'survey_wp_editor_height']) && $_REQUEST[$name_prefix . 'survey_wp_editor_height'] != '' && $_REQUEST[$name_prefix . 'survey_wp_editor_height'] != 0) ? absint( sanitize_text_field($_REQUEST[$name_prefix . 'survey_wp_editor_height']) ) : 100 ; |
| 29 |
|
| 30 |
// Make question required |
| 31 |
$survey_make_questions_required = (isset($_REQUEST[$name_prefix . 'survey_make_questions_required']) && $_REQUEST[$name_prefix . 'survey_make_questions_required'] == 'on') ? sanitize_text_field( $_REQUEST[$name_prefix . 'survey_make_questions_required'] ) : 'off'; |
| 32 |
|
| 33 |
// Lazy loading for images |
| 34 |
$survey_lazy_loading_for_images = (isset($_REQUEST[$name_prefix . 'survey_lazy_loading_for_images']) && $_REQUEST[$name_prefix . 'survey_lazy_loading_for_images'] == 'on') ? sanitize_text_field( $_REQUEST[$name_prefix . 'survey_lazy_loading_for_images'] ) : 'off'; |
| 35 |
|
| 36 |
// Do not store IP addresses |
| 37 |
$survey_disable_user_ip = (isset($_REQUEST[$name_prefix . 'survey_disable_user_ip']) && $_REQUEST[$name_prefix . 'survey_disable_user_ip'] == 'on') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_disable_user_ip'] ) ) : ''; |
| 38 |
|
| 39 |
// Do not store User Names |
| 40 |
$survey_disable_user_name = (isset($_REQUEST[$name_prefix . 'survey_disable_user_name']) && $_REQUEST[$name_prefix . 'survey_disable_user_name'] == 'on') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_disable_user_name'] ) ) : 'off'; |
| 41 |
|
| 42 |
// Do not store User Emails |
| 43 |
$survey_disable_user_email = (isset($_REQUEST[$name_prefix . 'survey_disable_user_email']) && $_REQUEST[$name_prefix . 'survey_disable_user_email'] == 'on') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_disable_user_email'] ) ) : 'off'; |
| 44 |
|
| 45 |
$survey_submissions_title_length = (isset($_REQUEST[$name_prefix . 'survey_submissions_title_length']) && $_REQUEST[$name_prefix . 'survey_submissions_title_length'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_submissions_title_length'] ) ) : 5; |
| 46 |
$survey_title_length = (isset($_REQUEST[$name_prefix . 'survey_title_length']) && $_REQUEST[$name_prefix . 'survey_title_length'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_title_length'] ) ) : 5; |
| 47 |
|
| 48 |
$survey_categories_title_length = (isset($_REQUEST[$name_prefix . 'survey_categories_title_length']) && $_REQUEST[$name_prefix . 'survey_categories_title_length'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_categories_title_length'] ) ) : 5; |
| 49 |
$survey_popups_title_length = (isset($_REQUEST[$name_prefix . 'survey_popups_title_length']) && $_REQUEST[$name_prefix . 'survey_popups_title_length'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_popups_title_length'] ) ) : 5; |
| 50 |
|
| 51 |
//Animation top |
| 52 |
$survey_animation_top = (isset($_REQUEST[$name_prefix . 'survey_animation_top']) && $_REQUEST[$name_prefix . 'survey_animation_top'] != '') ? absint( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_animation_top'] ) ) : 200; |
| 53 |
$survey_enable_animation_top = (isset( $_REQUEST['ays_survey_enable_animation_top'] ) && $_REQUEST['ays_survey_enable_animation_top'] ) == 'on' ? 'on' : 'off'; |
| 54 |
|
| 55 |
// Disable Survey Maker menu item notification |
| 56 |
$survey_disable_survey_menu_notification = ( isset( $_REQUEST[ $name_prefix . 'survey_disable_survey_menu_notification'] ) && $_REQUEST[$name_prefix . 'survey_disable_survey_menu_notification'] ) == 'on' ? 'on' : 'off'; |
| 57 |
|
| 58 |
// Disable Submissions menu item notification |
| 59 |
$survey_disable_submission_menu_notification = ( isset( $_REQUEST[ $name_prefix . 'survey_disable_submission_menu_notification'] ) && $_REQUEST[$name_prefix . 'survey_disable_submission_menu_notification'] ) == 'on' ? 'on' : 'off'; |
| 60 |
|
| 61 |
// Default texts | Start |
| 62 |
$wrong_shortcode_text = (isset($_REQUEST[$name_prefix . 'survey_wrong_shortcode_text']) && $_REQUEST[$name_prefix . 'survey_wrong_shortcode_text'] != '') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_wrong_shortcode_text'] )) : 'Wrong shortcode initialized'; |
| 63 |
$email_validation_error_text = (isset($_REQUEST[$name_prefix . 'survey_email_validation_error_text']) && $_REQUEST[$name_prefix . 'survey_email_validation_error_text'] != '') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_email_validation_error_text'] )) : 'Must be a valid email address'; |
| 64 |
$redirecting_after_text = (isset($_REQUEST[$name_prefix . 'survey_redirecting_after_text']) && $_REQUEST[$name_prefix . 'survey_redirecting_after_text'] != '') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix . 'survey_redirecting_after_text'] )) : 'Redirecting after'; |
| 65 |
// Default texts | End |
| 66 |
|
| 67 |
$default_texts = array( |
| 68 |
'wrong_shortcode_text' => $wrong_shortcode_text, |
| 69 |
'email_validation_error_text' => $email_validation_error_text, |
| 70 |
'redirecting_after_text' => $redirecting_after_text, |
| 71 |
); |
| 72 |
// Default texts | End |
| 73 |
|
| 74 |
$next_button = (isset($_REQUEST[$name_prefix .'survey_next_button']) && $_REQUEST[$name_prefix .'survey_next_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_next_button']) ) : 'Next'; |
| 75 |
$prev_button = (isset($_REQUEST[$name_prefix .'survey_previous_button']) && $_REQUEST[$name_prefix .'survey_previous_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_previous_button']) ) : 'Prev'; |
| 76 |
$restart_button = (isset($_REQUEST[$name_prefix .'survey_restart_button']) && $_REQUEST[$name_prefix .'survey_restart_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_restart_button']) ) : 'Restart'; |
| 77 |
$clear_button = (isset($_REQUEST[$name_prefix .'survey_clear_button']) && $_REQUEST[$name_prefix .'survey_clear_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_clear_button']) ) : 'Clear selection'; |
| 78 |
$finish_button = (isset($_REQUEST[$name_prefix .'survey_finish_button']) && $_REQUEST[$name_prefix .'survey_finish_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_finish_button']) ) : 'Finish'; |
| 79 |
$exit_button = (isset($_REQUEST[$name_prefix .'survey_exit_button']) && $_REQUEST[$name_prefix .'survey_exit_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_exit_button']) ) : 'Exit'; |
| 80 |
$login_button = (isset($_REQUEST[$name_prefix .'survey_login_button']) && $_REQUEST[$name_prefix .'survey_login_button'] != '') ? stripslashes( sanitize_text_field($_REQUEST[$name_prefix .'survey_login_button']) ) : 'Log in'; |
| 81 |
$start_button = (isset($_REQUEST[$name_prefix .'survey_start_button']) && $_REQUEST[$name_prefix .'survey_start_button'] != '') ? stripslashes( sanitize_text_field( $_REQUEST[$name_prefix .'survey_start_button'] )) : 'Start'; |
| 82 |
|
| 83 |
$buttons_texts = array( |
| 84 |
'next_button' => $next_button, |
| 85 |
'prev_button' => $prev_button, |
| 86 |
'restart_button' => $restart_button, |
| 87 |
'clear_button' => $clear_button, |
| 88 |
'finish_button' => $finish_button, |
| 89 |
'exit_button' => $exit_button, |
| 90 |
'login_button' => $login_button, |
| 91 |
'start_button' => $start_button, |
| 92 |
); |
| 93 |
|
| 94 |
$options = array( |
| 95 |
"survey_default_type" => $survey_default_type, |
| 96 |
"survey_answer_default_count" => $survey_answer_default_count, |
| 97 |
"survey_textarea_height" => $survey_textarea_height, |
| 98 |
"survey_wp_editor_height" => $survey_wp_editor_height, |
| 99 |
"survey_make_questions_required" => $survey_make_questions_required, |
| 100 |
"survey_lazy_loading_for_images" => $survey_lazy_loading_for_images, |
| 101 |
|
| 102 |
"survey_disable_user_ip" => $survey_disable_user_ip, |
| 103 |
"survey_disable_user_name" => $survey_disable_user_name, |
| 104 |
"survey_disable_user_email" => $survey_disable_user_email, |
| 105 |
|
| 106 |
"survey_submissions_title_length" => $survey_submissions_title_length, |
| 107 |
"survey_title_length" => $survey_title_length, |
| 108 |
"survey_categories_title_length" => $survey_categories_title_length, |
| 109 |
"survey_popups_title_length" => $survey_popups_title_length, |
| 110 |
|
| 111 |
"survey_animation_top" => $survey_animation_top, |
| 112 |
"survey_enable_animation_top" => $survey_enable_animation_top, |
| 113 |
"survey_disable_survey_menu_notification" => $survey_disable_survey_menu_notification, |
| 114 |
"survey_disable_submission_menu_notification" => $survey_disable_submission_menu_notification, |
| 115 |
); |
| 116 |
|
| 117 |
$fields['user_roles'] = $roles; |
| 118 |
$fields['options'] = $options; |
| 119 |
$fields['default_texts'] = $default_texts; |
| 120 |
$fields['buttons_texts'] = $buttons_texts; |
| 121 |
|
| 122 |
// $fields = apply_filters( 'ays_sm_settings_page_integrations_saves', $fields, $data ); |
| 123 |
|
| 124 |
foreach ($fields as $key => $value) { |
| 125 |
$result = $this->ays_update_setting( $key, json_encode( $value ) ); |
| 126 |
if( $result ){ |
| 127 |
$success++; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
$message = "saved"; |
| 132 |
if($success > 0){ |
| 133 |
$tab = ""; |
| 134 |
if( isset( $_REQUEST['ays_survey_tab'] ) ){ |
| 135 |
$tab = "&ays_survey_tab=".sanitize_text_field($_REQUEST['ays_survey_tab']); |
| 136 |
} |
| 137 |
$url = admin_url('admin.php') . "?page=survey-maker-settings" . $tab . '&status=' . $message; |
| 138 |
wp_redirect( $url ); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
} |
| 143 |
|
| 144 |
public function get_db_data(){ |
| 145 |
global $wpdb; |
| 146 |
$settings_table = $wpdb->prefix . "ayssurvey_settings"; |
| 147 |
$sql = "SELECT * FROM ".$settings_table; |
| 148 |
$results = $wpdb->get_results($sql, ARRAY_A); |
| 149 |
if(count($results) > 0){ |
| 150 |
return $results; |
| 151 |
}else{ |
| 152 |
return array(); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
public function check_settings_meta($metas){ |
| 157 |
global $wpdb; |
| 158 |
$settings_table = $wpdb->prefix . "ayssurvey_settings"; |
| 159 |
foreach($metas as $meta_key){ |
| 160 |
$sql = "SELECT COUNT(*) FROM ".$settings_table." WHERE meta_key = '". esc_sql( $meta_key ) ."'"; |
| 161 |
$result = $wpdb->get_var($sql); |
| 162 |
if(intval($result) == 0){ |
| 163 |
$this->ays_add_setting($meta_key, "", "", ""); |
| 164 |
} |
| 165 |
} |
| 166 |
return false; |
| 167 |
} |
| 168 |
|
| 169 |
public function check_setting_user_roles(){ |
| 170 |
global $wpdb; |
| 171 |
$settings_table = $wpdb->prefix . "ayssurvey_settings"; |
| 172 |
$sql = "SELECT COUNT(*) FROM ".$settings_table." WHERE meta_key = 'user_roles'"; |
| 173 |
$result = $wpdb->get_var($sql); |
| 174 |
if(intval($result) == 0){ |
| 175 |
$roles = json_encode(array('administrator')); |
| 176 |
$this->ays_add_setting("user_roles", $roles, "", ""); |
| 177 |
} |
| 178 |
return false; |
| 179 |
} |
| 180 |
|
| 181 |
public function ays_get_setting($meta_key){ |
| 182 |
global $wpdb; |
| 183 |
$settings_table = $wpdb->prefix . "ayssurvey_settings"; |
| 184 |
$sql = "SELECT meta_value FROM ".$settings_table." WHERE meta_key = '".$meta_key."'"; |
| 185 |
$result = $wpdb->get_var($sql); |
| 186 |
if($result != ""){ |
| 187 |
return $result; |
| 188 |
} |
| 189 |
return false; |
| 190 |
} |
| 191 |
|
| 192 |
public function ays_add_setting($meta_key, $meta_value, $note = "", $options = ""){ |
| 193 |
global $wpdb; |
| 194 |
$settings_table = $wpdb->prefix . "ayssurvey_settings"; |
| 195 |
$result = $wpdb->insert( |
| 196 |
$settings_table, |
| 197 |
array( |
| 198 |
'meta_key' => $meta_key, |
| 199 |
'meta_value' => $meta_value, |
| 200 |
'note' => $note, |
| 201 |
'options' => $options |
| 202 |
), |
| 203 |
array( '%s', '%s', '%s', '%s' ) |
| 204 |
); |
| 205 |
if($result >= 0){ |
| 206 |
return true; |
| 207 |
} |
| 208 |
return false; |
| 209 |
} |
| 210 |
|
| 211 |
public function ays_update_setting($meta_key, $meta_value, $note = null, $options = null){ |
| 212 |
global $wpdb; |
| 213 |
$settings_table = $wpdb->prefix . "ayssurvey_settings"; |
| 214 |
$value = array( |
| 215 |
'meta_value' => $meta_value, |
| 216 |
); |
| 217 |
$value_s = array( '%s' ); |
| 218 |
if($note != null){ |
| 219 |
$value['note'] = $note; |
| 220 |
$value_s[] = '%s'; |
| 221 |
} |
| 222 |
if($options != null){ |
| 223 |
$value['options'] = $options; |
| 224 |
$value_s[] = '%s'; |
| 225 |
} |
| 226 |
$result = $wpdb->update( |
| 227 |
$settings_table, |
| 228 |
$value, |
| 229 |
array( 'meta_key' => $meta_key, ), |
| 230 |
$value_s, |
| 231 |
array( '%s' ) |
| 232 |
); |
| 233 |
if($result >= 0){ |
| 234 |
return true; |
| 235 |
} |
| 236 |
return false; |
| 237 |
} |
| 238 |
|
| 239 |
public function ays_delete_setting($meta_key){ |
| 240 |
global $wpdb; |
| 241 |
$settings_table = $wpdb->prefix . "ayssurvey_settings"; |
| 242 |
$wpdb->delete( |
| 243 |
$settings_table, |
| 244 |
array( 'meta_key' => $meta_key ), |
| 245 |
array( '%s' ) |
| 246 |
); |
| 247 |
} |
| 248 |
|
| 249 |
public function survey_settings_notices($status){ |
| 250 |
|
| 251 |
if ( empty( $status ) ) |
| 252 |
return; |
| 253 |
|
| 254 |
if ( 'saved' == $status ) |
| 255 |
$updated_message = __( 'Changes saved.', "survey-maker" ); |
| 256 |
elseif ( 'updated' == $status ) |
| 257 |
$updated_message = __( 'Quiz attribute .', "survey-maker" ); |
| 258 |
elseif ( 'deleted' == $status ) |
| 259 |
$updated_message = __( 'Quiz attribute deleted.', "survey-maker" ); |
| 260 |
elseif ( 'duration_updated' == $status ) |
| 261 |
$updated_message = __( 'Duration old data is successfully updated.', "survey-maker" ); |
| 262 |
|
| 263 |
if ( empty( $updated_message ) ) |
| 264 |
return; |
| 265 |
|
| 266 |
?> |
| 267 |
<div class="ays-survey-admin-notice notice notice-success is-dismissible"> |
| 268 |
<p> <?php echo esc_html($updated_message); ?> </p> |
| 269 |
</div> |
| 270 |
<?php |
| 271 |
} |
| 272 |
|
| 273 |
public function message_variables_section($message_variables, $with_flags = true){ |
| 274 |
if( isset($message_variables) && !empty($message_variables) ){ |
| 275 |
$content = array(); |
| 276 |
foreach($message_variables as $message_variable_box_key => $message_variable_box_value){ |
| 277 |
$content[] = '<fieldset>'; |
| 278 |
$content[] = '<legend> |
| 279 |
<h5>'.esc_html__( ucwords(str_replace('_', ' ', $message_variable_box_key)) ,"survey-maker").'</h5> |
| 280 |
</legend>'; |
| 281 |
foreach($message_variable_box_value as $message_variable => $description){ |
| 282 |
$message_variable_input = $with_flags ? '%%' . $message_variable . '%%' : $message_variable; |
| 283 |
$content[] = '<p class="vmessage">'; |
| 284 |
$content[] = '<strong> |
| 285 |
<input type="text" onClick="this.setSelectionRange(0, this.value.length)" readonly value="'.esc_attr($message_variable_input).'"/> |
| 286 |
</strong>'; |
| 287 |
$content[] = '<span> - </span>'; |
| 288 |
$content[] = '<span style="font-size:18px;"> |
| 289 |
'. $description .' |
| 290 |
</span>'; |
| 291 |
$content[] = '</p>'; |
| 292 |
} |
| 293 |
$content[] = '</fieldset>'; |
| 294 |
} |
| 295 |
return implode('' , $content); |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
} |
| 300 |
|