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.../compatib.../divi
File: dynamic-content.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPML\Compatibility\Divi;
[2] Fix | Delete
[3] Fix | Delete
use SitePress;
[4] Fix | Delete
[5] Fix | Delete
class DynamicContent implements \IWPML_DIC_Action, \IWPML_Backend_Action {
[6] Fix | Delete
[7] Fix | Delete
const ENCODED_CONTENT_START = '@ET-DC@';
[8] Fix | Delete
const ENCODED_CONTENT_END = '@';
[9] Fix | Delete
[10] Fix | Delete
/** @var $positions */
[11] Fix | Delete
private $positions = [ 'before', 'after' ];
[12] Fix | Delete
[13] Fix | Delete
/** @var SitePress */
[14] Fix | Delete
private $sitepress;
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* @param SitePress $sitepress
[18] Fix | Delete
*/
[19] Fix | Delete
public function __construct( SitePress $sitepress ) {
[20] Fix | Delete
$this->sitepress = $sitepress;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Add filters and actions.
[25] Fix | Delete
*/
[26] Fix | Delete
public function add_hooks() {
[27] Fix | Delete
if ( $this->sitepress->is_setup_complete() ) {
[28] Fix | Delete
add_filter( 'wpml_pb_shortcode_decode', [ $this, 'decode_dynamic_content' ], 10, 2 );
[29] Fix | Delete
add_filter( 'wpml_pb_shortcode_encode', [ $this, 'encode_dynamic_content' ], 10, 2 );
[30] Fix | Delete
}
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Sets 'before' and 'after' dynamic content settings to translatable.
[35] Fix | Delete
*
[36] Fix | Delete
* @param string $string The decoded string so far.
[37] Fix | Delete
* @param string $encoding The encoding used.
[38] Fix | Delete
* @return array
[39] Fix | Delete
*/
[40] Fix | Delete
public function decode_dynamic_content( $string, $encoding ) {
[41] Fix | Delete
if ( $this->is_dynamic_content( $string ) ) {
[42] Fix | Delete
$field = $this->decode_field( $string );
[43] Fix | Delete
[44] Fix | Delete
$string = [
[45] Fix | Delete
'et-dynamic-content' => [
[46] Fix | Delete
'value' => $string,
[47] Fix | Delete
'translate' => false,
[48] Fix | Delete
],
[49] Fix | Delete
];
[50] Fix | Delete
[51] Fix | Delete
foreach ( $this->positions as $position ) {
[52] Fix | Delete
if ( ! empty( $field['settings'][ $position ] ) ) {
[53] Fix | Delete
$string[ $position ] = [
[54] Fix | Delete
'value' => $field['settings'][ $position ],
[55] Fix | Delete
'translate' => true,
[56] Fix | Delete
];
[57] Fix | Delete
}
[58] Fix | Delete
}
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
return $string;
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Rebuilds dynamic content with translated strings.
[66] Fix | Delete
*
[67] Fix | Delete
* @param array $string The field array.
[68] Fix | Delete
* @param string $encoding The encoding used.
[69] Fix | Delete
* @return string
[70] Fix | Delete
*/
[71] Fix | Delete
public function encode_dynamic_content( $string, $encoding ) {
[72] Fix | Delete
if ( is_array( $string ) && isset( $string['et-dynamic-content'] ) ) {
[73] Fix | Delete
$field = $this->decode_field( $string['et-dynamic-content'] );
[74] Fix | Delete
[75] Fix | Delete
foreach ( $this->positions as $position ) {
[76] Fix | Delete
if ( isset( $string[ $position ] ) ) {
[77] Fix | Delete
$field['settings'][ $position ] = $string[ $position ];
[78] Fix | Delete
}
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
$string = $this->encode_field( $field );
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
return $string;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Check if a certain field contains dynamic content.
[89] Fix | Delete
*
[90] Fix | Delete
* @param string $string The string to check.
[91] Fix | Delete
*/
[92] Fix | Delete
private function is_dynamic_content( $string ) {
[93] Fix | Delete
return substr( $string, 0, strlen( self::ENCODED_CONTENT_START ) ) === self::ENCODED_CONTENT_START;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* Decode a dynamic-content field.
[98] Fix | Delete
*
[99] Fix | Delete
* @param string $string The string to decode.
[100] Fix | Delete
* @return array
[101] Fix | Delete
*/
[102] Fix | Delete
private function decode_field( $string ) {
[103] Fix | Delete
$start = strlen( self::ENCODED_CONTENT_START );
[104] Fix | Delete
$end = strlen( self::ENCODED_CONTENT_END );
[105] Fix | Delete
[106] Fix | Delete
// phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
[107] Fix | Delete
return json_decode( base64_decode( substr( $string, $start, -$end ) ), true );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Encodes a dynamic-content field.
[112] Fix | Delete
*
[113] Fix | Delete
* @param array $field The field to encode.
[114] Fix | Delete
* @return string
[115] Fix | Delete
*/
[116] Fix | Delete
private function encode_field( $field ) {
[117] Fix | Delete
// phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
[118] Fix | Delete
return self::ENCODED_CONTENT_START
[119] Fix | Delete
. base64_encode( wp_json_encode( $field ) )
[120] Fix | Delete
. self::ENCODED_CONTENT_END;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function