/** * goes through all the options, sanitizing, verifying and returning for storage what needs to be there */ function addthis_parse_options($data) { global $addthis_styles, $addthis_new_styles; global $addThisConfigs; $styles = array_merge($addthis_styles, $addthis_new_styles); $below_custom_styles = $above_custom_styles = ''; $options = $addThisConfigs->getConfigs(); if (!is_array($data)) { return $options; } if (isset($data['show_below'])) { $options['below'] = 'none'; } elseif (isset($data['below'], $styles[$data['below']])) { $options['below'] = $data['below']; } elseif ($data['below'] == 'disable') { $options['below'] = $data['below']; } elseif ($data['below'] == 'none') { $options['below'] = 'none'; } elseif ($data['below'] == 'custom') { $options['below_do_custom_services'] = isset($data['below_do_custom_services']); $options['below_do_custom_preferred'] = isset($data['below_do_custom_preferred']); $options['below'] = 'custom'; if ($data['below_custom_size'] == 16 || $data['below_custom_size'] == 32) { $options['below_custom_size'] = $data['below_custom_size']; } else { $options['below_custom_size'] = ''; } $options['below_custom_services'] = sanitize_text_field($data['below_custom_services']); $options['below_custom_preferred'] = sanitize_text_field($data['below_custom_preferred']); $options['below_custom_more'] = isset($data['below_custom_more']); } elseif ($data['below'] == 'custom_string') { $options['below'] = 'custom_string'; if (strpos($data['below_custom_string'], "style=") != false) { $custom_style = explode('style=', $data['below_custom_string']); $custom_style = explode('>', $custom_style[1]); $custom_style = explode(' ', $custom_style[0]); $below_custom_styles = " style={$custom_style['0']}"; } $options['below_custom_string'] = addthis_kses($data['below_custom_string'], $below_custom_styles); } if (isset($data['wpfooter'])) { $options['wpfooter'] = (bool) $data['wpfooter']; } if (isset($styles[$data['above']])) { $options['above'] = $data['above']; } elseif ($data['above'] == 'disable') { $options['above'] = $data['above']; } elseif ($data['above'] == 'none') { $options['above'] = 'none'; } elseif ($data['above'] == 'custom') { $options['above_do_custom_services'] = isset($data['above_do_custom_services']); $options['above_do_custom_preferred'] = isset($data['above_do_custom_preferred']); $options['above'] = 'custom'; if ($data['above_custom_size'] == 16 || $data['above_custom_size'] == 32) { $options['above_custom_size'] = $data['above_custom_size']; } else { $options['above_custom_size'] = ''; } $options['above_custom_services'] = sanitize_text_field($data['above_custom_services']); $options['above_custom_preferred'] = (int) $data['above_custom_preferred']; $options['above_custom_more'] = isset($data['above_custom_more']); } elseif ($data['above'] == 'custom_string') { //[addthis_twitter_template] if (isset($data['addthis_twitter_template']) && strlen($data['addthis_twitter_template']) != 0) { //Parse the first twitter username to be used with via $options['addthis_twitter_template'] = sanitize_text_field($data['addthis_twitter_template']); } $options['above'] = 'custom_string'; if (strpos($data['above_custom_string'], "style=")) { $custom_style = explode('style=', $data['above_custom_string']); $custom_style = explode('>', $custom_style[1]); $custom_style = explode(' ', $custom_style[0]); $above_custom_styles = " style={$custom_style['0']}"; } $options['above_custom_string'] = addthis_kses($data['above_custom_string'], $above_custom_styles); } if (isset($data['addthis_profile'])) { $options['addthis_profile'] = sanitize_text_field($data['addthis_profile']); } if (isset($styles[$data['below']])) { $options['below'] = $data['below']; } elseif ($data['below'] == 'disable') { $options['below'] = $data['below']; } elseif ($data['below'] == 'none') { $options['below'] = 'none'; } elseif ($data['below'] == 'custom') { $options['below_do_custom_services'] = isset($data['below_do_custom_services']); $options['below_do_custom_preferred'] = isset($data['below_do_custom_preferred']); $options['below'] = 'custom'; if ($data['below_custom_size'] == 16 || $data['below_custom_size'] == 32) { $options['below_custom_size'] = $data['below_custom_size']; } else { $options['below_custom_size'] = ''; } $options['below_custom_services'] = sanitize_text_field($data['below_custom_services']); $options['below_custom_preferred'] = sanitize_text_field($data['below_custom_preferred']); $options['below_custom_more'] = isset($data['below_custom_more']); } elseif ($data['below'] == 'custom_string') { $options['below'] = 'custom_string'; if (strpos($data['below_custom_string'], "style=")) { $custom_style = explode('style=', $data['below_custom_string']); $custom_style = explode('>', $custom_style[1]); $custom_style = explode(' ', $custom_style[0]); $below_custom_styles = " style={$custom_style['0']}"; } $options['below_custom_string'] = addthis_kses($data['below_custom_string'], $below_custom_styles); } // All the checkbox fields $checkboxFields = array('addthis_508', 'addthis_addressbar', 'addthis_append_data', 'addthis_asynchronous_loading', 'addthis_bitly', 'addthis_per_post_enabled', 'above_auto_services', 'addthis_above_enabled', 'addthis_aftertitle', 'addthis_beforecomments', 'addthis_below_enabled', 'addthis_sidebar_enabled', 'below_auto_services'); // add all share button location template settings to list of checkbox fields $locationTemplateFields = $addThisConfigs->getFieldsForContentTypeSharingLocations(); foreach ($locationTemplateFields as $field) { $optionName = $field['fieldName']; $checkboxFields[] = $optionName; } foreach ($checkboxFields as $field) { if (isset($data[$field]) && $data[$field]) { $options[$field] = true; } else { $options[$field] = false; } } $checkAndSanitize = array('addthis_config_json', 'addthis_environment', 'addthis_language', 'addthis_layers_json', 'addthis_plugin_controls', 'addthis_profile', 'addthis_rate_us', 'addthis_share_json', 'addthis_twitter_template', 'atversion', 'atversion_update_status', 'credential_validation_status', 'data_ga_property', 'addthis_sidebar_count', 'addthis_sidebar_position', 'addthis_sidebar_theme'); foreach ($checkAndSanitize as $field) { if (isset($data[$field])) { $options[$field] = sanitize_text_field($data[$field]); } } if (!empty($data['above_chosen_list'])) { $options['above_chosen_list'] = sanitize_text_field($data['above_chosen_list']); } else { $options['above_chosen_list'] = ""; } if (!empty($data['below_chosen_list'])) { $options['below_chosen_list'] = sanitize_text_field($data['below_chosen_list']); } else { $options['below_chosen_list'] = ""; } if (isset($data['addthis_rate_us']) && $options['addthis_rate_us'] != $data['addthis_rate_us']) { $options['addthis_rate_us_timestamp'] = time(); } return $options; }
/** * goes through all the options, sanitizing, verifying and returning for storage what needs to be there */ function addthis_parse_options($data) { require_once 'addthis_settings_functions.php'; global $addthis_styles, $addthis_new_styles; $styles = array_merge($addthis_styles, $addthis_new_styles); $below_custom_styles = $above_custom_styles = ''; $options = array(); // Sanitize profile, username and password if (isset($data['addthis_username'])) { $options['username'] = sanitize_text_field($data['addthis_username']); } if (isset($data['addthis_profile'])) { $options['profile'] = sanitize_text_field($data['addthis_profile']); } if (isset($data['addthis_password'])) { $options['password'] = sanitize_text_field($data['addthis_password']); } if (isset($data['username'])) { $options['username'] = sanitize_text_field($data['username']); } if (isset($data['profile'])) { $options['profile'] = sanitize_text_field($data['profile']); } if (isset($data['password'])) { $options['password'] = sanitize_text_field($data['password']); } if (isset($data['wpfooter'])) { $options['wpfooter'] = (bool) $data['wpfooter']; } if (isset($data['show_above'])) { $options['above'] = 'none'; } elseif (isset($styles[$data['above']])) { $options['above'] = $data['above']; } elseif ($data['above'] == 'disable') { $options['above'] = $data['above']; } elseif ($data['above'] == 'none') { $options['above'] = 'none'; } elseif ($data['above'] == 'custom') { $options['above_do_custom_services'] = isset($data['above_do_custom_services']); $options['above_do_custom_preferred'] = isset($data['above_do_custom_preferred']); $options['above'] = 'custom'; $options['above_custom_size'] = $data['above_custom_size'] == '16' || $data['above_custom_size'] == 32 ? $data['above_custom_size'] : ''; $options['above_custom_services'] = sanitize_text_field($data['above_custom_services']); $options['above_custom_preferred'] = (int) $data['above_custom_preferred']; $options['above_custom_more'] = isset($data['above_custom_more']); } elseif ($data['above'] == 'custom_string') { $options['above'] = 'custom_string'; if (strpos($data['above_custom_string'], "style=") != false) { $custom_style = explode('style=', $data['above_custom_string']); $custom_style = explode('>', $custom_style[1]); $custom_style = explode(' ', $custom_style[0]); $above_custom_styles = " style={$custom_style['0']}"; } $options['above_custom_string'] = addthis_kses($data['above_custom_string'], $above_custom_styles); } if (isset($data['show_below'])) { $options['below'] = 'none'; } elseif (isset($styles[$data['below']])) { $options['below'] = $data['below']; } elseif ($data['below'] == 'disable') { $options['below'] = $data['below']; } elseif ($data['below'] == 'none') { $options['below'] = 'none'; } elseif ($data['below'] == 'custom') { $options['below_do_custom_services'] = isset($data['below_do_custom_services']); $options['below_do_custom_preferred'] = isset($data['below_do_custom_preferred']); $options['below'] = 'custom'; $options['below_custom_size'] = $data['below_custom_size'] == '16' || $data['below_custom_size'] == 32 ? $data['below_custom_size'] : ''; $options['below_custom_services'] = sanitize_text_field($data['below_custom_services']); $options['below_custom_preferred'] = sanitize_text_field($data['below_custom_preferred']); $options['below_custom_more'] = isset($data['below_custom_more']); } elseif ($data['below'] == 'custom_string') { $options['below'] = 'custom_string'; if (strpos($data['below_custom_string'], "style=") != false) { $custom_style = explode('style=', $data['below_custom_string']); $custom_style = explode('>', $custom_style[1]); $custom_style = explode(' ', $custom_style[0]); $below_custom_styles = " style={$custom_style['0']}"; } $options['below_custom_string'] = addthis_kses($data['below_custom_string'], $below_custom_styles); } if (isset($data['addthis_copytrackingremove']) && $data['addthis_copytrackingremove'] == true) { unset($data['addthis_copytracking1']); } // All the checkbox fields foreach (array('addthis_show_stats', 'addthis_append_data', 'addthis_showonhome', 'addthis_showonpages', 'addthis_showonarchives', 'addthis_showoncats', 'addthis_showonexcerpts', 'addthis_aftertitle', 'addthis_beforecomments', 'addthis_addressbar', 'addthis_508', 'addthis_copytracking2') as $field) { if (isset($data[$field]) && $data[$field] == true) { $options[$field] = true; } else { $options[$field] = false; } } if (isset($data['data_ga_property']) && strlen($data['data_ga_property']) != 0) { $options['data_ga_property'] = sanitize_text_field($data['data_ga_property']); } //[addthis_twitter_template] if (isset($data['addthis_twitter_template']) && strlen($data['addthis_twitter_template']) != 0) { //Parse the first twitter username to be used with via $options['addthis_twitter_template'] = get_first_twitter_username(sanitize_text_field($data['addthis_twitter_template'])); } if (isset($data['addthis_bitly_login']) && strlen($data['addthis_bitly_login']) != 0) { $options['addthis_bitly_login'] = sanitize_text_field($data['addthis_bitly_login']); } if (isset($data['addthis_bitly_key']) && strlen($data['addthis_bitly_key']) != 0) { $options['addthis_bitly_key'] = sanitize_text_field($data['addthis_bitly_key']); } //[addthis_brand] => if (isset($data['addthis_brand']) && strlen($data['addthis_brand']) != 0) { $options['addthis_brand'] = sanitize_text_field($data['addthis_brand']); } //[addthis_options] => if (isset($data['addthis_options']) && strlen($data['addthis_options']) != 0) { $options['addthis_options'] = str_replace(' ', '', esc_js(strtolower($data['addthis_options']))); } //[addthis_language] => if (isset($data['addthis_language'])) { $options['addthis_language'] = sanitize_text_field($data['addthis_language']); } //[atversion]=> if (isset($data['atversion'])) { $options['atversion'] = sanitize_text_field($data['atversion']); } //[atversion_update_status]=> if (isset($data['atversion_update_status'])) { $options['atversion_update_status'] = sanitize_text_field($data['atversion_update_status']); } if (isset($data['credential_validation_status'])) { $options['credential_validation_status'] = sanitize_text_field($data['credential_validation_status']); } if (isset($data['addthis_header_background']) && strlen($data['addthis_header_background']) != 0) { if (!strpos($data['addthis_header_background'], '#') === 0) { $options['addthis_header_background'] = '#' . sanitize_text_field($data['addthis_header_background']); } else { $options['addthis_header_background'] = sanitize_text_field($data['addthis_header_background']); } } if (isset($data['addthis_header_color']) && strlen($data['addthis_header_color']) != 0) { if (!strpos($data['addthis_header_color'], '#') === 0) { $options['addthis_header_color'] = '#' . sanitize_text_field($data['addthis_header_color']); } else { $options['addthis_header_color'] = sanitize_text_field($data['addthis_header_color']); } } if (isset($data['addthis_config_json']) && strlen($data['addthis_config_json']) != 0) { $options['addthis_config_json'] = sanitize_text_field($data['addthis_config_json']); } if (isset($data['addthis_share_json']) && strlen($data['addthis_share_json']) != 0) { $options['addthis_share_json'] = sanitize_text_field($data['addthis_share_json']); } if (isset($data['above_chosen_list']) && strlen($data['above_chosen_list']) != 0) { $options['above_chosen_list'] = sanitize_text_field($data['above_chosen_list']); } else { $options['above_chosen_list'] = ""; } if (isset($data['below_chosen_list']) && strlen($data['below_chosen_list']) != 0) { $options['below_chosen_list'] = sanitize_text_field($data['below_chosen_list']); } else { $options['below_chosen_list'] = ""; } return $options; }