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/themify-.../includes/plugin-c...
File: wpml-translation.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPML Translation compatibility
[2] Fix | Delete
*
[3] Fix | Delete
* @package Themify_Builder
[4] Fix | Delete
* @subpackage Themify_Builder/classes
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
// WPML string types: 'LINE', 'TEXTAREA', 'VISUAL', 'LINK'
[8] Fix | Delete
[9] Fix | Delete
class Themify_Builder_WPML_Integration {
[10] Fix | Delete
[11] Fix | Delete
/* cached wpml $package_data during register_strings */
[12] Fix | Delete
private static $package_data;
[13] Fix | Delete
[14] Fix | Delete
/* cached string translations */
[15] Fix | Delete
private static $translations;
[16] Fix | Delete
[17] Fix | Delete
static function init() {
[18] Fix | Delete
add_filter( 'wpml_page_builder_support_required', [ __CLASS__, 'wpml_page_builder_support_required' ] );
[19] Fix | Delete
add_action( 'wpml_page_builder_register_strings', [ __CLASS__, 'wpml_page_builder_register_strings' ], 10, 2 );
[20] Fix | Delete
add_action( 'wpml_page_builder_string_translated', [ __CLASS__, 'wpml_page_builder_string_translated' ], 10, 5 );
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
/* register Builder package */
[24] Fix | Delete
static function wpml_page_builder_support_required( $plugins ) {
[25] Fix | Delete
$plugins[] = 'Themify Builder';
[26] Fix | Delete
[27] Fix | Delete
return $plugins;
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
static function wpml_page_builder_register_strings( $post, $package_data ) {
[31] Fix | Delete
if ( 'Themify Builder' === $package_data['kind'] ) {
[32] Fix | Delete
$builder_data = ThemifyBuilder_Data_Manager::get_data( $post->ID );
[33] Fix | Delete
self::$package_data = $package_data;
[34] Fix | Delete
do_action( 'wpml_start_string_package_registration', $package_data );
[35] Fix | Delete
if ( is_array( $builder_data ) ) {
[36] Fix | Delete
foreach ( $builder_data as $row ) {
[37] Fix | Delete
self::recursive_register_row_translatable_fields( $row );
[38] Fix | Delete
}
[39] Fix | Delete
}
[40] Fix | Delete
do_action( 'wpml_delete_unused_package_strings', $package_data );
[41] Fix | Delete
}
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
static function wpml_page_builder_string_translated(
[45] Fix | Delete
$package_kind,
[46] Fix | Delete
$translated_post_id,
[47] Fix | Delete
$original_post,
[48] Fix | Delete
$string_translations,
[49] Fix | Delete
$lang
[50] Fix | Delete
) {
[51] Fix | Delete
// Make sure the package is for our plugin
[52] Fix | Delete
if ( 'Themify Builder' === $package_kind ) {
[53] Fix | Delete
$builder_data = ThemifyBuilder_Data_Manager::get_data( $original_post->ID );
[54] Fix | Delete
if ( ! empty( $builder_data ) && is_array( $builder_data ) ) {
[55] Fix | Delete
self::$translations = self::group_string_translation_by_elementid( $string_translations, $lang );
[56] Fix | Delete
foreach ( $builder_data as $index => $row ) {
[57] Fix | Delete
$builder_data[ $index ] = self::recursive_translate_fields( $row );
[58] Fix | Delete
}
[59] Fix | Delete
}
[60] Fix | Delete
ThemifyBuilder_Data_Manager::save_data( $builder_data, $translated_post_id );
[61] Fix | Delete
}
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
private static function group_string_translation_by_elementid( $string_translations, $lang ) {
[65] Fix | Delete
$result = [];
[66] Fix | Delete
if ( ! empty( $string_translations ) ) {
[67] Fix | Delete
foreach ( $string_translations as $key => $value ) {
[68] Fix | Delete
if ( isset( $value[ $lang ]['value'] ) ) { /* just being cautios */
[69] Fix | Delete
list( $post_id, $element_id, $option_id ) = explode( '/', $key );
[70] Fix | Delete
$result[ $element_id ][ $option_id ] = $value[ $lang ]['value'];
[71] Fix | Delete
}
[72] Fix | Delete
}
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
return $result;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
public static function recursive_translate_fields( $row ) {
[79] Fix | Delete
if ( ! empty( $row['styling'] ) ) {
[80] Fix | Delete
$row['styling'] = self::translate_shared_fields( $row['styling'], $row['element_id'] );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
if ( ! empty( $row['cols'] ) ) {
[84] Fix | Delete
foreach ( $row['cols'] as &$col ) {
[85] Fix | Delete
if ( ! empty( $col['styling'] ) ) {
[86] Fix | Delete
$col['styling'] = self::translate_shared_fields( $col['styling'], $col['element_id'] );
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
if ( ! empty( $col['modules'] ) ) {
[90] Fix | Delete
foreach ( $col['modules'] as &$mod ) {
[91] Fix | Delete
if ( isset( $mod['mod_name'], $mod['element_id'], $mod['mod_settings'] )
[92] Fix | Delete
/* modules with nested Builder content are always sent for translation */
[93] Fix | Delete
&& ( isset( self::$translations[ $mod['element_id'] ] ) || in_array( $mod['mod_name'], [ 'tab', 'accordion', 'toggle' ], true ) )
[94] Fix | Delete
) {
[95] Fix | Delete
$module = self::get_module( $mod['mod_name'] );
[96] Fix | Delete
if ( $module ) {
[97] Fix | Delete
$mod = $module::translate_module( $mod, self::$translations[ $mod['element_id'] ] );
[98] Fix | Delete
$mod['mod_settings'] = self::translate_shared_fields( $mod['mod_settings'], $mod['element_id'] );
[99] Fix | Delete
}
[100] Fix | Delete
}
[101] Fix | Delete
$mod = self::recursive_translate_fields( $mod ); // for subrows
[102] Fix | Delete
}
[103] Fix | Delete
}
[104] Fix | Delete
}
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
return $row;
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
public static function recursive_register_row_translatable_fields( $row ) {
[111] Fix | Delete
if ( ! empty( $row['styling'] ) ) {
[112] Fix | Delete
self::register_translatable_shared_fields( $row['styling'], $row['element_id'] );
[113] Fix | Delete
}
[114] Fix | Delete
if ( ! empty( $row['cols'] ) ) {
[115] Fix | Delete
foreach ( $row['cols'] as $col ) {
[116] Fix | Delete
if ( ! empty( $col['styling'] ) ) {
[117] Fix | Delete
self::register_translatable_shared_fields( $col['styling'], $col['element_id'] );
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
if ( ! empty( $col['modules'] ) ) {
[121] Fix | Delete
foreach ( $col['modules'] as $mod ) {
[122] Fix | Delete
if ( isset( $mod['mod_name'] ) ) {
[123] Fix | Delete
$module = self::get_module( $mod['mod_name'] );
[124] Fix | Delete
if ( $module ) {
[125] Fix | Delete
$translatable_fields = $module::get_translatable_fields( $mod, $module );
[126] Fix | Delete
self::register( $translatable_fields, $mod['element_id'] );
[127] Fix | Delete
if ( ! empty( $mod['mod_settings'] ) ) {
[128] Fix | Delete
self::register_translatable_shared_fields( $mod['mod_settings'], $mod['element_id'] );
[129] Fix | Delete
}
[130] Fix | Delete
}
[131] Fix | Delete
}
[132] Fix | Delete
self::recursive_register_row_translatable_fields( $mod ); // for subrows
[133] Fix | Delete
}
[134] Fix | Delete
}
[135] Fix | Delete
}
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Register fields that exist in all components and can be translated
[141] Fix | Delete
*/
[142] Fix | Delete
private static function register_translatable_shared_fields( $component, $component_id ) {
[143] Fix | Delete
$fields = [];
[144] Fix | Delete
if ( isset( $component['_tooltip'] ) ) {
[145] Fix | Delete
$fields[] = [
[146] Fix | Delete
'value' => $component['_tooltip'],
[147] Fix | Delete
'id' => '_tooltip'
[148] Fix | Delete
];
[149] Fix | Delete
}
[150] Fix | Delete
if ( isset( $component['_link'] ) ) {
[151] Fix | Delete
$fields[] = [
[152] Fix | Delete
'value' => $component['_link'],
[153] Fix | Delete
'id' => '_link'
[154] Fix | Delete
];
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
if ( ! empty( $fields ) ) {
[158] Fix | Delete
self::register( $fields, $component_id );
[159] Fix | Delete
}
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
/**
[163] Fix | Delete
* Translate shared fields that exist in all components
[164] Fix | Delete
*/
[165] Fix | Delete
private static function translate_shared_fields( $component, $component_id ) {
[166] Fix | Delete
if ( isset( self::$translations[ $component_id ]['_tooltip'] ) ) {
[167] Fix | Delete
$component['_tooltip'] = self::$translations[ $component_id ]['_tooltip'];
[168] Fix | Delete
}
[169] Fix | Delete
if ( isset( self::$translations[ $component_id ]['_link'] ) ) {
[170] Fix | Delete
$component['_link'] = self::$translations[ $component_id ]['_link'];
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
return $component;
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
public static function get_module( $name ) {
[177] Fix | Delete
$m = Themify_Builder_Component_Module::load_modules( $name );
[178] Fix | Delete
if ( is_object( $m ) ) {
[179] Fix | Delete
return get_class( $m );
[180] Fix | Delete
} else if ( is_string( $m ) ) {
[181] Fix | Delete
return $m;
[182] Fix | Delete
}
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
private static function register( $translatable_fields, $element_id ) {
[186] Fix | Delete
if ( ! empty( $translatable_fields ) ) {
[187] Fix | Delete
foreach ( $translatable_fields as $field ) {
[188] Fix | Delete
do_action(
[189] Fix | Delete
'wpml_register_string',
[190] Fix | Delete
$field['value'],
[191] Fix | Delete
self::$package_data['post_id'] . '/' . $element_id . '/' . $field['id'],
[192] Fix | Delete
self::$package_data,
[193] Fix | Delete
isset( $field['title'] ) ? $field['title'] : '',
[194] Fix | Delete
isset( $field['type'] ) ? $field['type'] : 'LINE'
[195] Fix | Delete
);
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
}
[199] Fix | Delete
}
[200] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function