Файловый менеджер - Редактировать - /var/www/xthruster/html/wp-content/uploads/flags/admin-texts.tar
Назад
class-wpml-st-admin-option-translation.php 0000644 00000004653 14721542441 0014727 0 ustar 00 <?php class WPML_ST_Admin_Option_Translation extends WPML_SP_User { /** @var WPML_String_Translation $st_instance */ private $st_instance; /** @var string $option_name */ private $option_name; /** @var string $option_name */ private $language; /** * WPML_ST_Admin_Option constructor. * * @param SitePress $sitepress * @param WPML_String_Translation $st_instance * @param string $option_name * @param string $language */ public function __construct( &$sitepress, &$st_instance, $option_name, $language = '' ) { if ( ! $option_name || ! is_scalar( $option_name ) ) { throw new InvalidArgumentException( 'Not a valid option name, received: ' . serialize( $option_name ) ); } parent::__construct( $sitepress ); $this->st_instance = &$st_instance; $this->option_name = $option_name; $this->language = $language ? $language : $this->st_instance->get_current_string_language( $option_name ); } /** * * @param string $option_name * @param string|array $new_value * @param int|bool $status * @param int $translator_id * @param int $rec_level * * @return boolean|mixed */ public function update_option( $option_name = '', $new_value = null, $status = false, $translator_id = null, $rec_level = 0 ) { $option_name = $option_name ? $option_name : $this->option_name; $new_value = (array) $new_value; $updated = array(); foreach ( $new_value as $index => $value ) { if ( is_array( $value ) ) { $name = '[' . $option_name . '][' . $index . ']'; $result = $this->update_option( $name, $value, $status, $translator_id, $rec_level + 1 ); $updated[] = array_sum( explode( ',', $result ) ); } else { if ( is_string( $index ) ) { $name = ( $rec_level == 0 ? '[' . $option_name . ']' : $option_name ) . $index; } else { $name = $option_name; } $string = $this->st_instance->string_factory()->find_admin_by_name( $name ); $string_id = $string->string_id(); if ( $string_id ) { if ( $this->language !== $string->get_language() ) { $updated[] = $string->set_translation( $this->language, $value, $status, $translator_id ); } else { $string->update_value( $value ); } } } } return array_sum( $updated ) > 0 ? join( ',', $updated ) : false; } } class-wpml-st-admin-blog-option.php 0000644 00000002757 14721542441 0013317 0 ustar 00 <?php class WPML_ST_Admin_Blog_Option extends WPML_SP_User { /** @var WPML_ST_Admin_Option_Translation $admin_option */ private $admin_option; /** * WPML_ST_Admin_Blog_Option constructor. * * @param SitePress $sitepress * @param WPML_String_Translation $st_instance * @param string $option_name */ public function __construct( &$sitepress, &$st_instance, $option_name ) { if ( ! WPML_ST_Blog_Name_And_Description_Hooks::is_string( $option_name ) ) { throw new InvalidArgumentException( $option_name . ' Is not a valid blog option that is handled by this class, allowed values are "Tagline" and "Blog Title"' ); } parent::__construct( $sitepress ); $this->admin_option = $st_instance->get_admin_option( $option_name ); } /** * @param string|array $old_value * @param string|array $new_value * * @return mixed */ public function pre_update_filter( $old_value, $new_value ) { $wp_api = $this->sitepress->get_wp_api(); if ( $wp_api->is_multisite() && $wp_api->ms_is_switched() && ! $this->sitepress->get_setting( 'setup_complete' ) ) { throw new RuntimeException( 'You cannot update blog option translations while switched to a blog on which the WPML setup is not complete! You are currently using blog ID:' . $this->sitepress->get_wp_api()->get_current_blog_id() ); } WPML_Config::load_config_run(); return $this->admin_option->update_option( '', $new_value, ICL_TM_COMPLETE ) ? $old_value : $new_value; } } wpml-admin-text-functionality.class.php 0000644 00000007633 14721564437 0014324 0 ustar 00 <?php abstract class WPML_Admin_Text_Functionality { final public function is_blacklisted( $option_name ) { global $wp_taxonomies; $black_list = array_fill_keys( /** * Manipulate the list of blacklisted options. * * The options in this array should not be translated for different reasons. This filter * allows other plugins to avoid certain options from being translated. * * @since 3.2.3 * * @param string[] $options */ apply_filters( 'wpml_st_blacklisted_options', [ 'active_plugins', 'wp_user_roles', '_wpml_media', 'users_can_register', 'admin_email', 'start_of_week', 'use_balanceTags', 'use_smilies', 'require_name_email', 'comments_notify', 'posts_per_rss', 'sticky_posts', 'page_for_post', '_wcml_settings', '_wcml_version', 'page_on_front', 'default_post_format', 'link_manager_enabled', 'icl_sitepress_settings', 'wpml_config_index', 'wpml_config_index_updated', 'wpml_config_files_arr', 'icl_admin_messages', 'wpml-package-translation-db-updates-run', 'wpml_media', 'wpml_ta_settings', '_icl_admin_option_names', '_icl_cache', 'icl_sitepress_version', 'rewrite_rules', 'recently_activated', 'wpml_tm_version', 'wp_installer_settings', 'icl_adl_settings', 'rss_use_excerpt', 'template', 'stylesheet', 'comment_whitelist', 'comment_registration', 'html_type', 'use_trackback', 'default_role', 'db_version', 'siteurl', 'home', 'blogname', 'blogdescription', 'mailserver_url', 'mailserver_login', 'mailserver_pass', 'mailserver_port', 'default_category', 'default_comment_status', 'default_ping_status', 'default_pingback_flag', 'comment_moderation', 'moderation_notify', 'permalink_structure', 'gzipcompression', 'hack_file', 'blog_charset', 'ping_sites', 'advanced_edit', 'comment_max_links', 'gmt_offset', 'default_email_category', 'uploads_use_yearmonth_folders', 'upload_path', 'blog_public', 'default_link_category', 'tag_base', 'show_avatars', 'avatar_rating', 'WPLANG', 'wp_icl_translators_cached', 'cron', '_transient_WPML_ST_MO_Downloader_lang_map', 'icl_translation_jobs_basket', ] ), 1 ); $tax_prefixes = array_keys( $wp_taxonomies ); foreach ( $tax_prefixes as &$tax_name ) { $tax_name .= '_children'; } $blacklist_prefixes = array_merge( $tax_prefixes, array( '_transient_', '_site_transient_' ) ); $matcher = '#^' . join( '|^', $blacklist_prefixes ) . '#'; return array_key_exists( $option_name, $black_list ) || preg_match( $matcher, $option_name ) === 1; } protected function read_admin_texts_recursive( $keys, $admin_text_context, $type, &$arr_context, &$arr_type ) { $keys = ! empty( $keys ) && isset( $keys ['attr']['name'] ) ? array( $keys ) : $keys; foreach ( $keys as $key ) { $key_name = $key['attr']['name']; if ( ! empty( $key['key'] ) ) { $arr[ $key_name ] = $this->read_admin_texts_recursive( $key['key'], $admin_text_context, $type, $arr_context, $arr_type ); } else { $arr[ $key_name ] = 1; $arr_context[ $key_name ] = $admin_text_context; $arr_type[ $key_name ] = $type; } } return isset( $arr ) ? $arr : false; } /** * @param string $key Name of option to retrieve. Expected to not be SQL-escaped. * @param mixed $default Value to return in case the string does not exists. * * @return mixed Value set for the option. */ public function get_option_without_filtering( $key, $default = false ) { global $wpdb; $value = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", $key ) ); return isset( $value ) ? $value : $default; } } wpml-admin-text-import.class.php 0000644 00000013156 14721564437 0012743 0 ustar 00 <?php require_once dirname( __FILE__ ) . '/wpml-admin-text-configuration.php'; require_once dirname( __FILE__ ) . '/wpml-admin-text-functionality.class.php'; class WPML_Admin_Text_Import extends WPML_Admin_Text_Functionality { /** @var WPML_ST_Records $st_records */ private $st_records; /** @var WPML_WP_API $wp_api */ private $wp_api; function __construct( WPML_ST_Records $st_records, WPML_WP_API $wp_api ) { $this->st_records = $st_records; $this->wp_api = $wp_api; } /** * @param array $admin_texts * @param string $config_handler_hash */ function parse_config( array $admin_texts, $config_handler_hash ) { $admin_texts_hash = md5( serialize( $admin_texts ) ); $transient_name = 'wpml_admin_text_import:parse_config:' . $config_handler_hash; if ( $this->wp_api->is_string_translation_page() || get_transient( $transient_name ) !== $admin_texts_hash ) { global $iclTranslationManagement, $sitepress; foreach ( $admin_texts as $a ) { $type = isset( $a['type'] ) ? $a['type'] : 'plugin'; $admin_text_context = isset( $a['context'] ) ? $a['context'] : ''; $admin_string_name = $a['attr']['name']; if ( $this->is_blacklisted( $admin_string_name ) ) { continue; } if ( ! empty( $a['key'] ) ) { foreach ( $a['key'] as $key ) { $arr[ $admin_string_name ][ $key['attr']['name'] ] = isset( $key['key'] ) ? $this->read_admin_texts_recursive( $key['key'], $admin_text_context, $type, $arr_context, $arr_type ) : 1; $arr_context[ $admin_string_name ] = $admin_text_context; $arr_type[ $admin_string_name ] = $type; } } else { $arr[ $admin_string_name ] = 1; $arr_context[ $admin_string_name ] = $admin_text_context; $arr_type[ $admin_string_name ] = $type; } } if ( isset( $arr ) ) { $iclTranslationManagement->admin_texts_to_translate = array_merge( $iclTranslationManagement->admin_texts_to_translate, $arr ); } $_icl_admin_option_names = get_option( '_icl_admin_option_names' ); $arr_options = array(); if ( isset( $arr ) && is_array( $arr ) ) { foreach ( $arr as $key => $v ) { $value = maybe_unserialize( (string) $this->get_option_without_filtering( (string) $key ) ); $value = is_array( $value ) && is_array( $v ) ? array_intersect_key( $value, $v ) : $value; $admin_text_context = isset( $arr_context[ $key ] ) ? $arr_context[ $key ] : ''; $type = isset( $arr_type[ $key ] ) ? $arr_type[ $key ] : ''; $req_upgrade = ! $sitepress->get_setting( 'admin_text_3_2_migration_complete_' . $admin_texts_hash, false ); if ( (bool) $value === true ) { $this->register_string_recursive( $key, $value, $arr[ $key ], '', $key, $req_upgrade, $type, $admin_text_context ); } $arr_options[ $key ] = $v; } $_icl_admin_option_names = is_array( $_icl_admin_option_names ) ? array_replace_recursive( $_icl_admin_option_names, $arr_options ) : $arr_options; } update_option( '_icl_admin_option_names', $_icl_admin_option_names, 'no' ); set_transient( $transient_name, $admin_texts_hash ); $sitepress->set_setting( 'admin_text_3_2_migration_complete_' . $admin_texts_hash, true, true ); } } private function register_string_recursive( $key, $value, $arr, $prefix, $suffix, $requires_upgrade, $type, $admin_text_context_old ) { if ( is_scalar( $value ) ) { /** @phpstan-ignore-next-line */ icl_register_string( WPML_Admin_Texts::DOMAIN_NAME_PREFIX . $suffix, $prefix . $key, $value, true ); if ( $requires_upgrade ) { $this->migrate_3_2( $type, $admin_text_context_old, $suffix, $prefix . $key ); } } elseif ( ! is_null( $value ) ) { foreach ( $value as $sub_key => $sub_value ) { if ( isset( $arr[ $sub_key ] ) ) { $this->register_string_recursive( $sub_key, $sub_value, $arr[ $sub_key ], $prefix . '[' . $key . ']', $suffix, $requires_upgrade, $type, $admin_text_context_old ); } } } } private function migrate_3_2( $type, $old_admin_text_context, $new_admin_text_context, $key ) { global $wpdb; $old_string_id = icl_st_is_registered_string( WPML_Admin_Texts::DOMAIN_NAME_PREFIX . $type . '_' . $old_admin_text_context, $key ); if ( $old_string_id ) { $new_string_id = icl_st_is_registered_string( WPML_Admin_Texts::DOMAIN_NAME_PREFIX . $new_admin_text_context, $key ); if ( $new_string_id ) { $wpdb->update( $wpdb->prefix . 'icl_string_translations', array( 'string_id' => $new_string_id ), array( 'string_id' => $old_string_id ) ); $this->st_records->icl_strings_by_string_id( $new_string_id ) ->update( array( 'status' => $this->st_records ->icl_strings_by_string_id( $old_string_id ) ->status() ) ); } } } } UI.php 0000644 00000002422 14721564437 0005607 0 ustar 00 <?php namespace WPML\ST\AdminTexts; use WPML\Ajax\ST\AdminText\Register; use WPML\Collect\Support\Collection; use WPML\FP\Obj; use WPML\FP\Fns; use WPML\ST\WP\App\Resources; use function WPML\Container\make; use WPML\LIB\WP\Hooks as WPHooks; use function WPML\FP\pipe; class UI implements \IWPML_Backend_Action_Loader { // shouldShow :: Collection -> bool public static function shouldShow( Collection $data ) { if ( ! current_user_can( 'manage_options' ) ) { return false; } return $data->get( 'page' ) === WPML_ST_FOLDER . '/menu/string-translation.php' && (int) $data->get( 'trop' ) === 1; } public static function localize( Collection $model ) { $esc_value = Obj::over( Obj::lensProp( 'value' ), 'esc_js' ); return [ 'name' => 'wpml_admin_strings', 'data' => [ 'model' => $model->map( $esc_value )->toArray(), 'endpoint' => Register::class, ], ]; } /** * @return callable|null */ public function create() { if ( self::shouldShow( wpml_collect( $_GET ) ) ) { return function() { WPHooks::onAction( 'admin_enqueue_scripts' ) ->then( [ make( \WPML_Admin_Texts::class ), 'getModelForRender' ] ) ->then( [ self::class, 'localize' ] ) ->then( Resources::enqueueApp( 'admin-strings' ) ); }; } return null; } } wpml-admin-text-configuration.php 0000644 00000012503 14721564437 0013167 0 ustar 00 <?php require_once dirname( __FILE__ ) . '/wpml-admin-text-functionality.class.php'; class WPML_Admin_Text_Configuration extends WPML_Admin_Text_Functionality { /** @var array $config */ private $config; /** * @param string|stdClass $file_or_object */ function __construct( $file_or_object = '' ) { if ( is_object( $file_or_object ) ) { $config = $file_or_object->config; $type = $file_or_object->type; $admin_text_context = $file_or_object->admin_text_context; } elseif ( $this->can_handle_custom_xml( $file_or_object ) ) { $validate = new WPML_XML_Config_Validate( WPML_PLUGIN_PATH . '/res/xsd/wpml-config.xsd' ); $transform = new WPML_XML2Array(); $xml_config_file = new WPML_XML_Config_Read_File( $file_or_object, $validate, $transform ); $config = $xml_config_file->get(); $type = ( dirname( $file_or_object ) === get_template_directory() || dirname( $file_or_object ) === get_stylesheet_directory() ) ? 'theme' : 'plugin'; $admin_text_context = basename( dirname( $file_or_object ) ); } $admin_text_config = isset( $config['wpml-config']['admin-texts'] ) ? $config['wpml-config']['admin-texts'] : array(); $wpml_config_all = array(); if ( isset( $type, $admin_text_context, $admin_text_config['key'] ) ) { if ( isset( $admin_text_config['key']['attr'] ) ) { // single $admin_text_config['key']['type'] = $type; $admin_text_config['key']['context'] = $admin_text_context; $wpml_config_all[] = $admin_text_config['key']; } else { foreach ( (array) $admin_text_config['key'] as $cf ) { $cf['type'] = $type; $cf['context'] = $admin_text_context; $wpml_config_all[] = $cf; } } } $this->config = $this->fill_wildcards( $wpml_config_all ); } function get_config_array() { return $this->config; } private function fill_wildcards( array $config_array ) { return ( ! isset( $config_array['attr']['name'] ) || $config_array['attr']['name'] !== '*' ) && ( ! isset( $config_array[0]['attr']['name'] ) || $config_array[0]['attr']['name'] !== '*' ) ? $this->remove_unmatched( $config_array, $this->all_strings_array( $this->get_top_level_filters( $config_array ) ) ) : array(); } private function get_top_level_filters( array $config_array ) { $ret = array(); $config_array = isset( $config_array['attr']['name'] ) ? array( $config_array ) : $config_array; foreach ( $config_array as $option ) { if ( isset( $option['attr']['name'] ) ) { $ret[] = $option['attr']['name']; } } return $ret; } private function remove_unmatched( array $input, array $all_possibilities ) { $ret = array(); $input = isset( $input['attr'] ) ? array( $input ) : $input; foreach ( $input as $val ) { $name_matcher = $this->wildcard_to_matcher( $val['attr']['name'] ); foreach ( $all_possibilities as $a_val ) { if ( preg_match( $name_matcher, $a_val['attr']['name'] ) === 1 ) { $match = $val; $match['attr']['name'] = $a_val['attr']['name']; $has_sub_filter = ! empty( $val['key'] ); $match['key'] = $has_sub_filter ? $this->remove_unmatched( $val['key'], $a_val['key'] ) : $a_val['key']; if ( $has_sub_filter === false || ! empty( $match['key'] ) ) { $ret[] = $match; } } } } return $ret; } /** * Creates a regex matcher from a wildcard string name definition * * @param string $wildcard * * @return string */ private function wildcard_to_matcher( $wildcard ) { return '#^' . str_replace( '\*', '.+', preg_quote( $wildcard, '#' ) ) . '$#'; } private function all_strings_array( array $top_level_filters ) { global $wpdb; if ( (bool) $top_level_filters === false ) { return array(); } foreach ( $top_level_filters as $key => $filter ) { $like = strpos( $filter, '*' ) !== false; $comparator = $like ? ' LIKE ' : '='; $top_level_filters[ $key ] = $wpdb->prepare( ' option_name ' . $comparator . ' %s ', $like ? str_replace( '*', '%', $wpdb->esc_like( $filter ) ) : $filter ); } $where = ' AND ( ' . join( ' OR ', $top_level_filters ) . ' )'; $strings = $wpdb->get_results( "SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name NOT LIKE '_transient%' AND option_name NOT LIKE '_site_transient%' {$where} AND LENGTH(option_value) < 1000000" ); $all_options = array(); foreach ( $strings as $data_pair ) { if ( $this->is_blacklisted( $data_pair->option_name ) === false ) { $all_options[ $data_pair->option_name ] = maybe_unserialize( $data_pair->option_value ); } } return $this->reformat_array( $all_options ); } private function reformat_array( $option_value ) { $ret = array(); if ( is_array( $option_value ) ) { foreach ( $option_value as $key => $value ) { $ret[] = array( 'attr' => array( 'name' => $key ), 'key' => $this->reformat_array( $value ), ); } } return $ret; } /** * @param string $file_path * * @return bool */ private function can_handle_custom_xml( $file_path ) { return is_string( $file_path ) && '' !== $file_path && file_exists( $file_path ) && class_exists( 'WPML_XML_Config_Validate' ); } } wpml-admin-texts.class.php 0000644 00000034274 14721564437 0011622 0 ustar 00 <?php use WPML\Collect\Support\Collection; use WPML\FP\Either; use \WPML\FP\Obj; use function WPML\Container\make; use function \WPML\FP\partial; use function \WPML\FP\invoke; use function \WPML\FP\flip; class WPML_Admin_Texts extends WPML_Admin_Text_Functionality { const DOMAIN_NAME_PREFIX = 'admin_texts_'; /** @var array $cache - A cache for each option translation */ private $cache = []; /** @var array $option_names - The option names from Admin texts settings */ private $option_names = []; /** @var TranslationManagement $tm_instance */ private $tm_instance; /** @var WPML_String_Translation $st_instance */ private $st_instance; /** @var bool $lock */ private $lock = false; /** @var array - A cache for each option value in the original language to allow restore after it was translated. */ private $cache_option_values_in_def_lang_by_id = []; /** * @param TranslationManagement $tm_instance * @param WPML_String_Translation $st_instance */ public function __construct( &$tm_instance, &$st_instance ) { add_action( 'plugins_loaded', [ $this, 'icl_st_set_admin_options_filters' ], 10 ); add_filter( 'wpml_unfiltered_admin_string', flip( [ $this, 'get_option_without_filtering' ] ), 10, 2 ); add_action( 'wpml_st_force_translate_admin_options', [ $this, 'force_translate_admin_options' ] ); $this->tm_instance = &$tm_instance; $this->st_instance = &$st_instance; } /** * @param mixed $value * * @return array|mixed|object */ private static function object_to_array( $value ) { return is_object( $value ) ? object_to_array( $value ) : $value; } public function icl_register_admin_options( $array, $key = '', $option = array() ) { $option = self::object_to_array( $option ); foreach ( $array as $k => $v ) { $option = $key === '' ? array( $k => maybe_unserialize( $this->get_option_without_filtering( $k ) ) ) : $option; if ( is_array( $v ) ) { $this->icl_register_admin_options( $v, $key . '[' . $k . ']', $option[ $k ] ); } else { $context = $this->get_context( $key, $k ); $opt_keys = self::findKeys( (string) $key ); if ( $v === '' ) { icl_unregister_string( $context, $key . $k ); } elseif ( isset( $option[ $k ] ) && ( $key === '' || $opt_keys ) ) { icl_register_string( $context, $key . $k, $option[ $k ], true ); $vals = array( $k => 1 ); $opt_keys = array_reverse( $opt_keys ); foreach ( $opt_keys as $opt ) { $vals = array( $opt => $vals ); } update_option( '_icl_admin_option_names', array_merge_recursive( (array) get_option( '_icl_admin_option_names' ), $vals ), 'no' ); $this->option_names = []; } } } } public function getModelForRender() { return $this->getModel( $this->getOptions() ); } /** * @param Collection $options * * @return Collection */ public function getModel( Collection $options ) { $stringNamesPerContext = $this->getStringNamesPerContext(); $isRegistered = function ( $context, $name ) use ( $stringNamesPerContext ) { return $stringNamesPerContext->has( $context ) && $stringNamesPerContext->get( $context )->contains( $name ); }; $getItems = partial( [ $this, 'getItemModel' ], $isRegistered ); return $options->map( $getItems ) ->filter() ->values() ->reduce( [ $this, 'flattenModelItems' ], wpml_collect() ); } /** * @param Collection $flattened * @param array $item * * @return Collection */ public function flattenModelItems( Collection $flattened, array $item ) { if ( empty( $item ) ) { return $flattened; } if ( isset( $item['items'] ) ) { return $flattened->merge( $item['items']->reduce( [ $this, 'flattenModelItems' ], wpml_collect() ) ); } return $flattened->push( $item ); } /** * @param callable $isRegistered - string -> string -> bool. * @param mixed $value * @param string $name * @param string $key * @param array $stack * * @return array */ public function getItemModel( callable $isRegistered, $value, $name, $key = '', $stack = [] ) { $sub_key = $this->getSubKey( $key, $name ); $result = []; if ( $this->isMultiValue( $value ) ) { $stack[] = $value; $getSubItem = function ( $v, $key ) use ( $isRegistered, $sub_key, $stack ) { return $this->getItemModel( $isRegistered, $v, $key, $sub_key, $stack ); }; $result['items'] = wpml_collect( $value ) ->reject( $this->isOnStack( $stack ) ) ->map( $getSubItem ); } elseif ( is_string( $value ) || is_numeric( $value ) ) { $context = $this->get_context( $key, $name ); $stringName = $this->getDBStringName( $key, $name ); $result['value'] = $value; $result['fixed'] = $this->is_sub_key_fixed( $sub_key ); $result['name'] = $sub_key; $result['registered'] = $isRegistered( $context, $stringName ); $result['hasTranslations'] = ! $result['fixed'] && $result['registered'] && icl_st_string_has_translations( $context, $stringName ); } return $result; } private function isOnStack( array $stack ) { return function ( $item ) use ( $stack ) { return \wpml_collect( $stack )->first( function ( $currentItem ) use ( $item ) { return $currentItem === $item; } ) !== null; }; } private function is_sub_key_fixed( $sub_key ) { $fixed = false; $keys = self::findKeys( $sub_key ); if ( $keys ) { $fixed = true; $fixed_settings = $this->tm_instance->admin_texts_to_translate; foreach ( $keys as $m ) { $fixed = isset( $fixed_settings[ $m ] ); if ( $fixed ) { $fixed_settings = $fixed_settings[ $m ]; } else { break; } } } return $fixed; } private function get_context( $option_key, $option_name ) { $keys = self::findKeys( (string) $option_key ); return self::DOMAIN_NAME_PREFIX . ( $keys ? reset( $keys ) : $option_name ); } public function getOptions() { return wpml_collect( wp_load_alloptions() ) ->reject( flip( [ $this, 'is_blacklisted' ] ) ) ->map( 'maybe_unserialize' ); } public function icl_st_set_admin_options_filters() { $option_names = $this->getOptionNames(); $isAdmin = is_admin() && ! wpml_is_ajax(); foreach ( $option_names as $option_key => $option ) { if ( $this->is_blacklisted( $option_key ) ) { unset( $option_names[ $option_key ] ); update_option( '_icl_admin_option_names', $option_names, 'no' ); } elseif ( $option_key !== 'theme' && $option_key !== 'plugin' ) { // theme and plugin are an obsolete format before 3.2. /** * We don't want to translate admin strings in admin panel because it causes a lot of confusion * when a value is displayed inside the form input. */ if ( ! $isAdmin ) { $this->add_filter_for( $option_key ); } add_action( 'update_option_' . $option_key, array( $this, 'on_update_original_value' ), 10, 3 ); } } } /** * @param array $options */ public function force_translate_admin_options( $options ) { wpml_collect( $options )->each( [ $this, 'add_filter_for' ] ); } /** * @param string $option */ public function add_filter_for( $option ) { add_filter( 'option_' . $option, [ $this, 'icl_st_translate_admin_string' ] ); } public function icl_st_translate_admin_string( $option_value, $key = '', $name = '', $root_level = true ) { if ( $root_level && $this->lock ) { return $option_value; } if ( $root_level && is_array( $option_value ) ) { foreach ( $option_value as $id => $value ) { $this->cache_option_values_in_def_lang_by_id[ $id ] = $value; } } $this->lock = true; $lang = $this->st_instance->get_current_string_language( $name ); $option_name = substr( current_filter(), 7 ); $name = $name === '' ? $option_name : $name; $blog_id = get_current_blog_id(); if ( isset( $this->cache[ $blog_id ][ $lang ][ $name ] ) ) { $this->lock = false; return $this->cache[ $blog_id ][ $lang ][ $name ]; } $is_serialized = is_serialized( $option_value ); $option_value = $is_serialized ? unserialize( $option_value ) : $option_value; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize if ( is_array( $option_value ) || is_object( $option_value ) ) { $option_value = $this->translate_multiple( $option_value, $key, $name ); } else { $option_value = $this->translate_single( $option_value, $key, $name, $option_name ); } $option_value = $is_serialized ? serialize( $option_value ) : $option_value; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize if ( $root_level ) { $this->lock = false; $this->cache[ $blog_id ][ $lang ][ $name ] = $option_value; } return $option_value; } /** * @param string $key - string like '[key1][key2]'. * @param string $name * * @return bool */ private function isAdminText( $key, $name ) { return null !== Either::of( $this->getSubKey( $key, $name ) ) ->map( [ self::class, 'getKeysParts' ] ) ->tryCatch( invoke( 'reduce' )->with( flip( Obj::prop() ), $this->getOptionNames() ) ) ->getOrElse( null ); } /** * Signature: getKeys :: string [key1][key2][name] => Collection [key1, key2, name]. * * @param string $option * * @return Collection */ public static function getKeysParts( $option ) { return wpml_collect( self::findKeys( $option ) ); } /** * @param string $string * * @return array */ private static function findKeys( $string ) { return array_filter( explode( '][', preg_replace( '/^\[(.*)\]$/', '$1', $string ) ), 'strlen' ); } public function clear_cache_for_option( $option_name ) { $blog_id = get_current_blog_id(); if ( isset( $this->cache[ $blog_id ] ) ) { foreach ( $this->cache[ $blog_id ] as $lang_code => &$cache_data ) { if ( array_key_exists( $option_name, $cache_data ) ) { unset( $cache_data[ $option_name ] ); } } } } /** * @param string|array $old_value * @param string|array $value * @param string $option_name * @param string $name * @param string $sub_key */ public function on_update_original_value( $old_value, $value, $option_name, $name = '', $sub_key = '' ) { // We receive translated $old_value here after add_filter_for execution so need to restore $old_value in the default language. if ( '' === $sub_key ) { if ( is_array( $old_value ) && is_array( $value ) && count( $old_value ) === count( $value ) ) { foreach ( $value as $option_id => $option_value ) { if ( ! array_key_exists( $option_id, $this->cache_option_values_in_def_lang_by_id ) ) { continue; } foreach ( $old_value as $old_option_id => &$old_option_value ) { if ( $old_option_id === $option_id ) { $old_option_value = $this->cache_option_values_in_def_lang_by_id[ $option_id ]; } } } } } $name = $name ? $name : $option_name; $value = self::object_to_array( $value ); $old_value = self::object_to_array( $old_value ); if ( is_array( $value ) ) { foreach ( array_keys( $value ) as $key ) { $this->on_update_original_value( isset( $old_value[ $key ] ) ? $old_value[ $key ] : '', $value[ $key ], $option_name, $key, $this->getSubKey( $sub_key, $name ) ); } } else { if ( $this->isAdminText( $sub_key, $name ) ) { icl_st_update_string_actions( self::DOMAIN_NAME_PREFIX . $option_name, $this->getDBStringName( $sub_key, $name ), $old_value, $value ); } } if ( $sub_key === '' ) { $this->clear_cache_for_option( $option_name ); } } public function migrate_original_values() { $migrate = function ( $option_name ) { $option_value = maybe_unserialize( $this->get_option_without_filtering( $option_name ) ); $this->on_update_original_value( '', $option_value, $option_name ); }; wpml_collect( $this->getOptionNames() ) ->keys() ->filter() ->each( $migrate ); } /** * Returns a function to lazy load the migration * * @return Closure */ public static function get_migrator() { return function () { wpml_st_load_admin_texts()->migrate_original_values(); }; } /** * @param mixed $option_value * @param string $key * @param string $name * * @return array|mixed */ private function translate_multiple( $option_value, $key, $name ) { $subKey = $this->getSubKey( $key, $name ); foreach ( $option_value as $k => &$value ) { $value = $this->icl_st_translate_admin_string( $value, $subKey, $k, false ); } return $option_value; } /** * @param string $option_value * @param string $key * @param string $name * @param string $option_name * * @return string */ private function translate_single( $option_value, $key, $name, $option_name ) { if ( $option_value !== '' && $this->isAdminText( $key, $name ) ) { $option_value = icl_translate( self::DOMAIN_NAME_PREFIX . $option_name, $key . $name, $option_value ); } return $option_value; } /** * @return array */ private function getOptionNames() { if ( empty( $this->option_names ) ) { $this->option_names = get_option( '_icl_admin_option_names' ); if ( ! is_array( $this->option_names ) ) { $this->option_names = []; } } return $this->option_names; } /** * Signature: getSubKeys :: string [key1][key2] -> string name => string [key1][key2][name] * * @param string $key - [key1][key2]. * @param string $name * * @return string */ private function getSubKey( $key, $name ) { return $key . '[' . $name . ']'; } /** * Signature: getSubKeys :: string [key1][key2] -> string name => string [key1][key2]name * * @param string $key * @param string $name * * @return string */ private function getDBStringName( $key, $name ) { return $key . $name; } /** * @return Collection * @throws \WPML\Auryn\InjectionException - Throws an exception in case of errors. */ private function getStringNamesPerContext() { $strings = make( WPML_ST_DB_Mappers_Strings::class ) ->get_all_by_context( self::DOMAIN_NAME_PREFIX . '%' ); return wpml_collect( $strings ) ->groupBy( 'context' ) ->map( invoke( 'pluck' )->with( 'name' ) ); } /** * @param mixed $value * * @return bool */ private function isMultiValue( $value ) { return is_array( $value ) || ( is_object( $value ) && '__PHP_Incomplete_Class' !== get_class( $value ) ); } } Register.php 0000644 00000002760 14721564437 0007063 0 ustar 00 <?php namespace WPML\Ajax\ST\AdminText; use WPML\Ajax\IHandler; use WPML\Collect\Support\Collection; use WPML\FP\Either; use WPML\FP\Fns; use function WPML\FP\partial; use function WPML\FP\pipe; class Register implements IHandler { /** @var \WPML_Admin_Texts */ private $adminTexts; public function __construct( \WPML_Admin_Texts $adminTexts ) { $this->adminTexts = $adminTexts; } /** * Registers or Unregisters an option for translation depending * on the `state` data. * * @param Collection $data * * @return Either */ public function run( Collection $data ) { $state = $data->get( 'state' ) ? 'on' : ''; $applyState = partial( [ self::class, 'flatToHierarchical' ], $state ); $register = pipe( 'wpml_collect', Fns::map( $applyState ), Fns::reduce( 'array_replace_recursive', [] ), [ $this->adminTexts, 'icl_register_admin_options' ] ); $register( $data->get( 'selected', [] ) ); return Either::right( true ); } /** * string $state -> string [key1][key2][name] -> array [ key1 => [ key2 => [ name => $state ] ] ] * * @param string $state * @param string $option * * @return array */ public static function flatToHierarchical( $state, $option ) { // string $value -> mixed $key -> array [ $key => $value ] $makeArrayWithStringKey = function ( $value, $key ) { return [ (string) $key => $value ]; }; return \WPML_Admin_Texts::getKeysParts( $option ) ->reverse() ->reduce( $makeArrayWithStringKey, $state ); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.3-4ubuntu2.24 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка