| 1 |
<?php |
| 2 |
|
| 3 |
// If this file is called directly, abort. |
| 4 |
if ( ! defined( 'WPINC' ) ) { |
| 5 |
die; |
| 6 |
} |
| 7 |
|
| 8 |
|
| 9 |
/** |
| 10 |
* wpLingua OB Callback function : AJAX |
| 11 |
* |
| 12 |
* @param string $output |
| 13 |
* @return string |
| 14 |
*/ |
| 15 |
function wplng_ob_callback_ajax( $output ) { |
| 16 |
|
| 17 |
if ( empty( $_SERVER['HTTP_REFERER'] ) ) { |
| 18 |
return $output; |
| 19 |
} |
| 20 |
|
| 21 |
$referer = sanitize_url( $_SERVER['HTTP_REFERER'] ); |
| 22 |
|
| 23 |
// Check if the referer is clean |
| 24 |
if ( strtolower( esc_url_raw( $referer ) ) !== strtolower( $referer ) ) { |
| 25 |
return $output; |
| 26 |
} |
| 27 |
|
| 28 |
global $wplng_request_uri; |
| 29 |
$wplng_request_uri = wp_make_link_relative( $referer ); |
| 30 |
|
| 31 |
if ( ! wplng_url_is_translatable( $wplng_request_uri ) |
| 32 |
|| wplng_get_language_website_id() === wplng_get_language_current_id() |
| 33 |
) { |
| 34 |
return $output; |
| 35 |
} |
| 36 |
|
| 37 |
$output_translated = wplng_ob_callback_translate( $output ); |
| 38 |
|
| 39 |
// Print debug data in debug.log file |
| 40 |
if ( true === WPLNG_LOG_AJAX_DEBUG ) { |
| 41 |
|
| 42 |
$debug = array( |
| 43 |
'title' => 'wpLingua AJAX debug', |
| 44 |
'request_uri' => $wplng_request_uri, |
| 45 |
'value' => $output, |
| 46 |
'translated' => $output_translated, |
| 47 |
); |
| 48 |
|
| 49 |
error_log( |
| 50 |
var_export( |
| 51 |
$debug, |
| 52 |
true |
| 53 |
) |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
return $output_translated; |
| 58 |
} |
| 59 |
|