'\""; } else { $filter_string = " \t\n\r\0\x0B\xA0�.,/`~!@#\$€£%^&*():;-_=+[]{}\\|?/<>1234567890'\""; } if ( strip_tags( $string ) === '' || // phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags -- Cheap pre-check in a very hot path (runs for every string); the untrimmed strip_tags() result is intended, wp_strip_all_tags() adds regex passes and trimming. trim( $string, $filter_string ) === '' ) { // Needs decoding otherwise some strings with special characters won't get detected. // Example in Hebrew: אוכל ותרבות // Placed inside the "if" to avoid calling html_entity_decode so often as this is a very used function $decoded_string = html_entity_decode( $string ); if ( trim( $decoded_string, $filter_string ) === '' ) { $string = ''; } } return $string; } function translangated_sort_dictionary_by_original( $dictionaries, $type, $group, $languageForId ){ $array = array(); foreach( $dictionaries as $language => $dictionary ){ if ( isset( $dictionary['default-language'] ) && $dictionary['default-language'] == true ){ continue; } foreach( $dictionary as $string ) { $string = (object)$string; if ( isset( $string->original ) ){ $found = false; $string->editedTranslation = $string->translated; foreach( $array as $key => $row ){ if ( $row['original'] == $string->original ){ if ( !isset( $string->domain ) || ( isset($row['originalId']) && $row['originalId'] == $string->ot_id && $row['pluralForm'] == (int)$string->plural_form ) /*|| ( $string->plural_form == 0 && $string->domain == $row['description'] )*/ ) { $array[ $key ]['translationsArray'][ $language ] = $string; unset( $array[ $key ]['translationsArray'][ $language ]->original ); $found = true; if ( isset($string->domain) ){ $array[ $key ]['description'] = $string->domain; $array[ $key ]['domain'] = $string->domain; } if ( $language == $languageForId ){ $array[ $key ][ 'dbID' ] = $string->id; } break; } } } if ( ! $found ){ $new_entry = array( 'type' => $type, 'group' => $group, 'translationsArray' => array( $language => $string ), 'original' => $string->original ); unset($string->original); if ( isset( $string->domain ) ){ $new_entry['description'] = $string->domain; } if ( isset( $string->original_plural ) ){ $new_entry['originalPlural'] = $string->original_plural; } if ( isset( $string->context ) ){ $new_entry['context'] = $string->context; } if ( $type === 'gettext' ){ $new_entry['pluralForm'] = ( isset( $string->plural_form) ) ? $string->plural_form : 0; } if ( isset( $string->ot_id ) ){ $new_entry['originalId'] = $string->ot_id; } if ( $language == $languageForId ){ $new_entry['dbID'] = $string->id; } if ( isset( $new_entry['translationsArray'][$language]->block_type ) ){ $new_entry['blockType'] = $new_entry['translationsArray'][$language]->block_type; } $array[] = $new_entry; } } } } return $array; } function translangated_is_valid_language_code( $language_code ){ // allowed characters A-Z a-z 0-9 - _ if ( empty($language_code) || preg_match('/[^A-Za-z0-9\-_]/i', $language_code ) ) { return false; }else{ return true; } }