Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/sitepres.../classes/utilitie...
File: class-wpml-global-ajax.php
<?php
[0] Fix | Delete
[1] Fix | Delete
class WPML_Global_AJAX extends WPML_SP_User {
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* WPML_Global_AJAX constructor.
[5] Fix | Delete
*
[6] Fix | Delete
* @param SitePress $sitepress
[7] Fix | Delete
*/
[8] Fix | Delete
public function __construct( &$sitepress ) {
[9] Fix | Delete
parent::__construct( $sitepress );
[10] Fix | Delete
add_action( 'wp_ajax_save_language_negotiation_type', array( $this, 'save_language_negotiation_type_action' ) );
[11] Fix | Delete
}
[12] Fix | Delete
[13] Fix | Delete
public function save_language_negotiation_type_action() {
[14] Fix | Delete
$errors = array();
[15] Fix | Delete
$response = false;
[16] Fix | Delete
$nonce = filter_input( INPUT_POST, 'nonce' );
[17] Fix | Delete
$action = filter_input( INPUT_POST, 'action' );
[18] Fix | Delete
$is_valid_nonce = wp_verify_nonce( $nonce, $action );
[19] Fix | Delete
[20] Fix | Delete
if ( $is_valid_nonce ) {
[21] Fix | Delete
$icl_language_negotiation_type = filter_input( INPUT_POST, 'icl_language_negotiation_type', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE );
[22] Fix | Delete
$language_domains = filter_input( INPUT_POST, 'language_domains', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_REQUIRE_ARRAY | FILTER_NULL_ON_FAILURE );
[23] Fix | Delete
$use_directory = filter_input( INPUT_POST, 'use_directory', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE );
[24] Fix | Delete
$show_on_root = filter_input( INPUT_POST, 'show_on_root', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE );
[25] Fix | Delete
$root_html_file_path = filter_input( INPUT_POST, 'root_html_file_path', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE );
[26] Fix | Delete
$hide_language_switchers = filter_input( INPUT_POST, 'hide_language_switchers', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE );
[27] Fix | Delete
$icl_xdomain_data = filter_input( INPUT_POST, 'xdomain', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE );
[28] Fix | Delete
$sso_enabled = filter_input( INPUT_POST, 'sso_enabled', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE );
[29] Fix | Delete
[30] Fix | Delete
if ( $icl_language_negotiation_type ) {
[31] Fix | Delete
$this->sitepress->set_setting( 'language_negotiation_type', $icl_language_negotiation_type );
[32] Fix | Delete
$response = true;
[33] Fix | Delete
[34] Fix | Delete
if ( ! empty( $language_domains ) ) {
[35] Fix | Delete
$this->sitepress->set_setting( 'language_domains', $language_domains );
[36] Fix | Delete
}
[37] Fix | Delete
if ( 1 === (int) $icl_language_negotiation_type ) {
[38] Fix | Delete
$urls = $this->sitepress->get_setting( 'urls' );
[39] Fix | Delete
$urls['directory_for_default_language'] = $use_directory ? true : 0;
[40] Fix | Delete
if ( $use_directory ) {
[41] Fix | Delete
$urls['show_on_root'] = $use_directory ? $show_on_root : '';
[42] Fix | Delete
if ( 'html_file' === $show_on_root ) {
[43] Fix | Delete
$root_page_url = $root_html_file_path ? $root_html_file_path : '';
[44] Fix | Delete
$response = $this->validateRootPageUrl( $root_page_url, $errors );
[45] Fix | Delete
if ( $response ) {
[46] Fix | Delete
$urls['root_html_file_path'] = $root_page_url;
[47] Fix | Delete
}
[48] Fix | Delete
} else {
[49] Fix | Delete
$urls['hide_language_switchers'] = $hide_language_switchers ? $hide_language_switchers : 0;
[50] Fix | Delete
}
[51] Fix | Delete
}
[52] Fix | Delete
$this->sitepress->set_setting( 'urls', $urls );
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
$this->sitepress->set_setting( 'xdomain_data', $icl_xdomain_data );
[56] Fix | Delete
$this->sitepress->set_setting( 'language_per_domain_sso_enabled', $sso_enabled );
[57] Fix | Delete
$this->sitepress->save_settings();
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
if ( $response ) {
[61] Fix | Delete
$permalinks_settings_url = get_admin_url( null, 'options-permalink.php' );
[62] Fix | Delete
$save_permalinks_link = '<a href="' . $permalinks_settings_url . '">' . _x( 're-save the site permalinks', 'You may need to {re-save the site permalinks} - 2/2', 'sitepress' ) . '</a>';
[63] Fix | Delete
$save_permalinks_message = sprintf( _x( 'You may need to %s.', 'You may need to {re-save the site permalinks} - 1/2', 'sitepress' ), $save_permalinks_link );
[64] Fix | Delete
wp_send_json_success( $save_permalinks_message );
[65] Fix | Delete
} else {
[66] Fix | Delete
if ( ! $errors ) {
[67] Fix | Delete
$errors[] = __( 'Error', 'sitepress' );
[68] Fix | Delete
}
[69] Fix | Delete
wp_send_json_error( $errors );
[70] Fix | Delete
}
[71] Fix | Delete
}
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* @param string $url
[76] Fix | Delete
* @param array $errors
[77] Fix | Delete
*
[78] Fix | Delete
* @return bool
[79] Fix | Delete
*/
[80] Fix | Delete
private function validateRootPageUrl( $url, array &$errors ) {
[81] Fix | Delete
$wp_http = new WP_HTTP();
[82] Fix | Delete
if ( '' === trim( $url ) ) {
[83] Fix | Delete
$errors[] = __( 'The URL of the HTML file is required', 'sitepress' );
[84] Fix | Delete
[85] Fix | Delete
return false;
[86] Fix | Delete
}
[87] Fix | Delete
if ( 0 !== strpos( $url, 'http' ) ) {
[88] Fix | Delete
$url = get_site_url( null, $url );
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
if ( $this->is_external( $url ) ) {
[92] Fix | Delete
$errors[] = __( 'You are trying to use an external URL: this is not allowed.', 'sitepress' );
[93] Fix | Delete
[94] Fix | Delete
return false;
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
try {
[98] Fix | Delete
$response = $wp_http->get( $url );
[99] Fix | Delete
if ( is_wp_error( $response ) ) {
[100] Fix | Delete
$errors[] = $response->get_error_code() . ' - ' . $response->get_error_message( $response->get_error_code() );
[101] Fix | Delete
[102] Fix | Delete
return false;
[103] Fix | Delete
}
[104] Fix | Delete
if ( 200 !== (int) $response['response']['code'] ) {
[105] Fix | Delete
$errors[] = __( 'An attempt to open the URL specified as a root page failed with the following error:', 'sitepress' );
[106] Fix | Delete
$errors[] = $response['response']['code'] . ': ' . $response['response']['message'];
[107] Fix | Delete
[108] Fix | Delete
return false;
[109] Fix | Delete
}
[110] Fix | Delete
} catch ( Exception $ex ) {
[111] Fix | Delete
$errors[] = $ex->getMessage();
[112] Fix | Delete
[113] Fix | Delete
return false;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
return true;
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
function is_external( $url ) {
[120] Fix | Delete
$site_url = get_site_url();
[121] Fix | Delete
$site_components = wp_parse_url( $site_url );
[122] Fix | Delete
$site_host = strtolower( $site_components['host'] );
[123] Fix | Delete
[124] Fix | Delete
$url_components = wp_parse_url( $url );
[125] Fix | Delete
$url_host = strtolower( $url_components['host'] );
[126] Fix | Delete
[127] Fix | Delete
if ( empty( $url_host ) || 0 === strcasecmp( $url_host, $site_host ) ) {
[128] Fix | Delete
return false;
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
$site_host = $this->remove_www_prefix( $site_host );
[132] Fix | Delete
[133] Fix | Delete
$subdomain_position = strrpos( $url_host, '.' . $site_host );
[134] Fix | Delete
$subdomain_length = strlen( $url_host ) - strlen( '.' . $site_host );
[135] Fix | Delete
[136] Fix | Delete
return $subdomain_position !== $subdomain_length; // check if the url host is a subdomain
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* @param $site_host
[141] Fix | Delete
*
[142] Fix | Delete
* @return string
[143] Fix | Delete
*/
[144] Fix | Delete
function remove_www_prefix( $site_host ) {
[145] Fix | Delete
$site_host_levels = explode( '.', $site_host );
[146] Fix | Delete
if ( 2 > count( $site_host_levels ) && 'www' === $site_host_levels[0] ) {
[147] Fix | Delete
$site_host_levels = array_slice( $site_host_levels, - ( count( $site_host_levels ) - 1 ) );
[148] Fix | Delete
$site_host = implode( '.', $site_host_levels );
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
return $site_host;
[152] Fix | Delete
}
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function