Advertisement
htdat

php-errors-from-wpml-config-class-php

Mar 26th, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 24.52 KB | None | 0 0
  1. <?php
  2.  
  3. require ICL_PLUGIN_PATH . "/inc/taxonomy-term-translation/wpml-term-language-sychronization.class.php";
  4.  
  5. class WPML_Config
  6. {
  7.     static $wpml_config_files = array();
  8.     static $active_plugins = array();
  9.  
  10.     public static function load_config()
  11.     {
  12.         global $pagenow;
  13.  
  14.         if ( !( is_admin() && !wpml_is_ajax() && ( !isset( $_POST[ 'action' ] ) || $_POST[ 'action' ] != 'heartbeat' ) ) ) {
  15.             return;
  16.         }
  17.  
  18.         $white_list_pages = array(
  19.             'theme_options',
  20.             'plugins.php',
  21.             'themes.php',
  22.             ICL_PLUGIN_FOLDER . '/menu/languages.php',
  23.             ICL_PLUGIN_FOLDER . '/menu/theme-localization.php',
  24.             ICL_PLUGIN_FOLDER . '/menu/translation-options.php',
  25.         );
  26.         if (defined('WPML_ST_FOLDER')) {
  27.             $white_list_pages[] = WPML_ST_FOLDER . '/menu/string-translation.php';
  28.         }
  29.         if(defined('WPML_TM_FOLDER')) {
  30.             $white_list_pages[] = WPML_TM_FOLDER . '/menu/main.php';
  31.         }
  32.  
  33.         //Runs the load config process only on specific pages
  34.         $current_page = isset($_GET[ 'page' ]) ? $_GET[ 'page' ] : null;
  35.         if((isset( $current_page ) && in_array( $current_page, $white_list_pages)) || (isset($pagenow) && in_array($pagenow, $white_list_pages))) {
  36.             self::load_config_run();
  37.         }
  38.     }
  39.  
  40.     static function load_config_run() {
  41.         global $sitepress;
  42.         self::load_config_pre_process();
  43.         self::load_plugins_wpml_config();
  44.         self::load_theme_wpml_config();
  45.         self::parse_wpml_config_files();
  46.         self::load_config_post_process();
  47.         $sitepress->save_settings();
  48.     }
  49.  
  50.     static function load_config_pre_process()
  51.     {
  52.         global $iclTranslationManagement;
  53.         $tm_settings = $iclTranslationManagement->settings;
  54.  
  55.         $tm_settings[ '__custom_types_readonly_config_prev' ] = ( isset( $tm_settings[ 'custom_types_readonly_config' ] ) && is_array( $tm_settings[ 'custom_types_readonly_config' ] ) ) ? $tm_settings[ 'custom_types_readonly_config' ] : array();
  56.         $tm_settings[ 'custom_types_readonly_config' ]        = array();
  57.  
  58.         $tm_settings[ '__custom_fields_readonly_config_prev' ] = ( isset( $tm_settings[ 'custom_fields_readonly_config' ] ) && is_array( $tm_settings[ 'custom_fields_readonly_config' ] ) ) ? $tm_settings[ 'custom_fields_readonly_config' ] : array();
  59.         $tm_settings[ 'custom_fields_readonly_config' ]        = array();
  60.     }
  61.  
  62.     static function load_plugins_wpml_config()
  63.     {
  64.         if ( is_multisite() ) {
  65.             // Get multi site plugins
  66.             $plugins = get_site_option( 'active_sitewide_plugins' );
  67.             if ( !empty( $plugins ) ) {
  68.                 foreach ( $plugins as $p => $dummy ) {
  69.                     if(!self::check_on_config_file($dummy)){
  70.                         continue;
  71.                     }
  72.                     $plugin_slug = dirname( $p );
  73.                     $config_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/wpml-config.xml';
  74.                     if ( trim( $plugin_slug, '\/.' ) && file_exists( $config_file ) ) {
  75.                         self::$wpml_config_files[ ] = $config_file;
  76.                     }
  77.                 }
  78.             }
  79.         }
  80.  
  81.         // Get single site or current blog active plugins
  82.         $plugins = get_option( 'active_plugins' );
  83.         if ( !empty( $plugins ) ) {
  84.             foreach ( $plugins as $p ) {
  85.                 if(!self::check_on_config_file($p)){
  86.                     continue;
  87.                 }
  88.  
  89.                 $plugin_slug = dirname( $p );
  90.                 $config_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/wpml-config.xml';
  91.                 if ( trim( $plugin_slug, '\/.' ) && file_exists( $config_file ) ) {
  92.                     self::$wpml_config_files[ ] = $config_file;
  93.                 }
  94.             }
  95.         }
  96.  
  97.         // Get the must-use plugins
  98.         $mu_plugins = wp_get_mu_plugins();
  99.  
  100.         if ( !empty( $mu_plugins ) ) {
  101.             foreach ( $mu_plugins as $mup ) {
  102.                 if(!self::check_on_config_file($mup)){
  103.                     continue;
  104.                 }
  105.  
  106.                 $plugin_dir_name  = dirname( $mup );
  107.                 $plugin_base_name = basename( $mup, ".php" );
  108.                 $plugin_sub_dir   = $plugin_dir_name . '/' . $plugin_base_name;
  109.                 if ( file_exists( $plugin_sub_dir . '/wpml-config.xml' ) ) {
  110.                     $config_file                = $plugin_sub_dir . '/wpml-config.xml';
  111.                     self::$wpml_config_files[ ] = $config_file;
  112.                 }
  113.             }
  114.         }
  115.  
  116.         return self::$wpml_config_files;
  117.     }
  118.  
  119.     static function check_on_config_file( $name ){
  120.  
  121.         if(empty(self::$active_plugins)){
  122.             if ( ! function_exists( 'get_plugins' ) ) {
  123.                 require_once ABSPATH . 'wp-admin/includes/plugin.php';
  124.             }
  125.             self::$active_plugins = get_plugins();
  126.         }
  127.         $config_index_file_data = maybe_unserialize(get_option('wpml_config_index'));
  128.         $config_files_arr = maybe_unserialize(get_option('wpml_config_files_arr'));
  129.  
  130.         if(!$config_index_file_data || !$config_files_arr){
  131.             return true;
  132.         }
  133.  
  134.  
  135.         if(isset(self::$active_plugins[$name])){
  136.             $plugin_info = self::$active_plugins[$name];
  137.             $plugin_slug = dirname( $name );
  138.             $name = $plugin_info['Name'];
  139.             $config_data = $config_index_file_data->plugins;
  140.             $config_files_arr = $config_files_arr->plugins;
  141.             $config_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/wpml-config.xml';
  142.             $type = 'plugin';
  143.  
  144.         }else{
  145.             $config_data = $config_index_file_data->themes;
  146.             $config_files_arr = $config_files_arr->themes;
  147.             $config_file = get_template_directory() . '/wpml-config.xml';
  148.             $type = 'theme';
  149.         }
  150.  
  151.         foreach($config_data as $item){
  152.             if($name == $item->name && isset($config_files_arr[$item->name])){
  153.                 if($item->override_local || !file_exists( $config_file )){
  154.                     end(self::$wpml_config_files);
  155.                     $key = key(self::$wpml_config_files)+1;
  156.                     self::$wpml_config_files[$key] = new stdClass();
  157.                     self::$wpml_config_files[$key]->config = icl_xml2array($config_files_arr[$item->name]);
  158.                     self::$wpml_config_files[$key]->type = $type;
  159.                     self::$wpml_config_files[$key]->admin_text_context = basename( dirname( $config_file ) );;
  160.                     return false;
  161.                 }else{
  162.                     return true;
  163.                 }
  164.             }
  165.         }
  166.  
  167.         return true;
  168.  
  169.     }
  170.  
  171.     static function load_theme_wpml_config()
  172.     {
  173.         $theme_data = wp_get_theme();
  174.         if(!self::check_on_config_file($theme_data->get('Name'))){
  175.             return self::$wpml_config_files;
  176.         }
  177.  
  178.         if ( get_template_directory() != get_stylesheet_directory() ) {
  179.             $config_file = get_stylesheet_directory() . '/wpml-config.xml';
  180.             if ( file_exists( $config_file ) ) {
  181.                 self::$wpml_config_files[ ] = $config_file;
  182.             }
  183.         }
  184.  
  185.         $config_file = get_template_directory() . '/wpml-config.xml';
  186.         if ( file_exists( $config_file ) ) {
  187.             self::$wpml_config_files[ ] = $config_file;
  188.         }
  189.  
  190.         return self::$wpml_config_files;
  191.     }
  192.  
  193.     static function parse_wpml_config_files()
  194.     {
  195.         if ( !empty( self::$wpml_config_files ) ) {
  196.  
  197.             $config_all[ 'wpml-config' ] = array(
  198.                 'custom-fields'              => array(),
  199.                 'custom-types'               => array(),
  200.                 'taxonomies'                 => array(),
  201.                 'admin-texts'                => array(),
  202.                 'language-switcher-settings' => array()
  203.             );
  204.  
  205.             foreach ( self::$wpml_config_files as $file ) {
  206.                 if(is_object($file)){
  207.                     $config = $file->config;
  208.                     $type = $file->type;
  209.                     $admin_text_context = $file->admin_text_context;
  210. /***** https://wpml.org/errata/php-errors-from-wpml-config-class-php/
  211.                 }else{
  212.                 $config = icl_xml2array( file_get_contents( $file ) );
  213.                 }
  214. */
  215.                 }else{
  216.                 $config = icl_xml2array( file_get_contents( $file ) );
  217.                 $type = ( dirname( $file ) == get_template_directory() || dirname( $file ) == get_stylesheet_directory() ) ? 'theme' : 'plugin';
  218.                 $admin_text_context = basename( dirname( $file ) );
  219.                 }
  220.                 if ( isset( $config[ 'wpml-config' ] ) ) {
  221.  
  222.                     //custom-fields
  223.                     if ( isset( $config[ 'wpml-config' ][ 'custom-fields' ][ 'custom-field' ] ) ) {
  224.                         if ( isset( $config[ 'wpml-config' ][ 'custom-fields' ][ 'custom-field' ][ 'value' ] ) ) { //single
  225.                             $config_all[ 'wpml-config' ][ 'custom-fields' ][ 'custom-field' ][ ] = $config[ 'wpml-config' ][ 'custom-fields' ][ 'custom-field' ];
  226.                         } else {
  227.                             foreach ( (array) $config[ 'wpml-config' ][ 'custom-fields' ][ 'custom-field' ] as $cf ) {
  228.                                 $config_all[ 'wpml-config' ][ 'custom-fields' ][ 'custom-field' ][ ] = $cf;
  229.                             }
  230.                         }
  231.                     }
  232.  
  233.                     //custom-types
  234.                     if ( isset( $config[ 'wpml-config' ][ 'custom-types' ][ 'custom-type' ] ) ) {
  235.                         if ( isset( $config[ 'wpml-config' ][ 'custom-types' ][ 'custom-type' ][ 'value' ] ) ) { //single
  236.                             $config_all[ 'wpml-config' ][ 'custom-types' ][ 'custom-type' ][ ] = $config[ 'wpml-config' ][ 'custom-types' ][ 'custom-type' ];
  237.                         } else {
  238.                             foreach ( (array) $config[ 'wpml-config' ][ 'custom-types' ][ 'custom-type' ] as $cf ) {
  239.                                 $config_all[ 'wpml-config' ][ 'custom-types' ][ 'custom-type' ][ ] = $cf;
  240.                             }
  241.                         }
  242.                     }
  243.  
  244.                     //taxonomies
  245.                     if ( isset( $config[ 'wpml-config' ][ 'taxonomies' ][ 'taxonomy' ] ) ) {
  246.                         if ( isset( $config[ 'wpml-config' ][ 'taxonomies' ][ 'taxonomy' ][ 'value' ] ) ) { //single
  247.                             $config_all[ 'wpml-config' ][ 'taxonomies' ][ 'taxonomy' ][ ] = $config[ 'wpml-config' ][ 'taxonomies' ][ 'taxonomy' ];
  248.                         } else {
  249.                             foreach ( (array) $config[ 'wpml-config' ][ 'taxonomies' ][ 'taxonomy' ] as $cf ) {
  250.                                 $config_all[ 'wpml-config' ][ 'taxonomies' ][ 'taxonomy' ][ ] = $cf;
  251.                             }
  252.                         }
  253.                     }
  254.  
  255.                     //admin-texts
  256.                     if ( isset( $config[ 'wpml-config' ][ 'admin-texts' ][ 'key' ] ) ) {
  257. /**** https://wpml.org/errata/php-errors-from-wpml-config-class-php/
  258.                         $type = ( dirname( $file ) == get_template_directory() || dirname( $file ) == get_stylesheet_directory() ) ? 'theme' : 'plugin';
  259.  
  260.                         $admin_text_context = basename( dirname( $file ) );
  261. */
  262.  
  263.                         if ( ! is_numeric( key( @current( $config[ 'wpml-config' ][ 'admin-texts' ] ) ) ) ) { //single
  264.                             $config[ 'wpml-config' ][ 'admin-texts' ][ 'key' ][ 'type' ]    = $type;
  265.                             $config[ 'wpml-config' ][ 'admin-texts' ][ 'key' ][ 'context' ] = $admin_text_context;
  266.                             $config_all[ 'wpml-config' ][ 'admin-texts' ][ 'key' ][ ]       = $config[ 'wpml-config' ][ 'admin-texts' ][ 'key' ];
  267.                         } else {
  268.                             foreach ( (array) $config[ 'wpml-config' ][ 'admin-texts' ][ 'key' ] as $cf ) {
  269.                                 $cf[ 'type' ]                                             = $type;
  270.                                 $cf[ 'context' ]                                          = $admin_text_context;
  271.                                 $config_all[ 'wpml-config' ][ 'admin-texts' ][ 'key' ][ ] = $cf;
  272.                             }
  273.                         }
  274.                     }
  275.  
  276.                     //language-switcher-settings
  277.                     if ( isset( $config[ 'wpml-config' ][ 'language-switcher-settings' ][ 'key' ] ) ) {
  278.                         if ( !is_numeric( key( $config[ 'wpml-config' ][ 'language-switcher-settings' ][ 'key' ] ) ) ) { //single
  279.                             $config_all[ 'wpml-config' ][ 'language-switcher-settings' ][ 'key' ][ ] = $config[ 'wpml-config' ][ 'language-switcher-settings' ][ 'key' ];
  280.                         } else {
  281.                             foreach ( $config[ 'wpml-config' ][ 'language-switcher-settings' ][ 'key' ] as $cf ) {
  282.                                 $config_all[ 'wpml-config' ][ 'language-switcher-settings' ][ 'key' ][ ] = $cf;
  283.                             }
  284.                         }
  285.                     }
  286.                 }
  287.             }
  288.  
  289.             $config_all = apply_filters( 'icl_wpml_config_array', $config_all );
  290.  
  291.             self::parse_wpml_config( $config_all );
  292.         }
  293.     }
  294.  
  295.     static function load_config_post_process()
  296.     {
  297.         global $iclTranslationManagement;
  298.  
  299.         $changed = false;
  300.         if ( isset( $iclTranslationManagement->settings[ '__custom_types_readonly_config_prev' ] ) ) {
  301.             foreach ( $iclTranslationManagement->settings[ '__custom_types_readonly_config_prev' ] as $pk => $pv ) {
  302.                 if ( !isset( $iclTranslationManagement->settings[ 'custom_types_readonly_config' ][ $pk ] ) || $iclTranslationManagement->settings[ 'custom_types_readonly_config' ][ $pk ] != $pv ) {
  303.                     $changed = true;
  304.                     break;
  305.                 }
  306.             }
  307.         }
  308.         if ( isset( $iclTranslationManagement->settings[ 'custom_types_readonly_config' ] ) ) {
  309.             foreach ( $iclTranslationManagement->settings[ 'custom_types_readonly_config' ] as $pk => $pv ) {
  310.                 if ( !isset( $iclTranslationManagement->settings[ '__custom_types_readonly_config_prev' ][ $pk ] ) || $iclTranslationManagement->settings[ '__custom_types_readonly_config_prev' ][ $pk ] != $pv ) {
  311.                     $changed = true;
  312.                     break;
  313.                 }
  314.             }
  315.         }
  316.         if ( isset( $iclTranslationManagement->settings[ 'custom_fields_readonly_config' ]  ) && isset($iclTranslationManagement->settings[ '__custom_fields_readonly_config_prev' ]) ) {
  317.             foreach ( $iclTranslationManagement->settings[ '__custom_fields_readonly_config_prev' ] as $cf ) {
  318.                 if ( !in_array( $cf, $iclTranslationManagement->settings[ 'custom_fields_readonly_config' ] ) ) {
  319.                     $changed = true;
  320.                     break;
  321.                 }
  322.             }
  323.  
  324.             foreach ( $iclTranslationManagement->settings[ 'custom_fields_readonly_config' ] as $cf ) {
  325.                 if ( !in_array( $cf, $iclTranslationManagement->settings[ '__custom_fields_readonly_config_prev' ] ) ) {
  326.                     $changed = true;
  327.                     break;
  328.                 }
  329.             }
  330.         }
  331.  
  332.         if ( $changed ) {
  333.             $iclTranslationManagement->save_settings();
  334.         }
  335.  
  336.  
  337.     }
  338.  
  339.     static function parse_wpml_config( $config )
  340.     {
  341.         global $sitepress, $sitepress_settings, $iclTranslationManagement;
  342.  
  343.         // custom fields
  344.         self::parse_custom_fields( $config );
  345.  
  346.         // custom types
  347.         self::parse_custom_types( $config );
  348.  
  349.         // taxonomies
  350.         self::parse_taxonomies( $config );
  351.  
  352.         // admin texts
  353.         self::parse_admin_texts( $config );
  354.  
  355.         // language-switcher-settings
  356.         if ( empty( $sitepress_settings[ 'language_selector_initialized' ] ) || ( isset( $_GET[ 'restore_ls_settings' ] ) && $_GET[ 'restore_ls_settings' ] == 1 ) ) {
  357.             if ( !empty( $config[ 'wpml-config' ][ 'language-switcher-settings' ] ) ) {
  358.  
  359.                 if ( !is_numeric( key( $config[ 'wpml-config' ][ 'language-switcher-settings' ][ 'key' ] ) ) ) {
  360.                     $cfgsettings[ 0 ] = $config[ 'wpml-config' ][ 'language-switcher-settings' ][ 'key' ];
  361.                 } else {
  362.                     $cfgsettings = $config[ 'wpml-config' ][ 'language-switcher-settings' ][ 'key' ];
  363.                 }
  364.                 $iclsettings = $iclTranslationManagement->_read_settings_recursive( $cfgsettings );
  365.  
  366.                 $iclsettings[ 'language_selector_initialized' ] = 1;
  367.  
  368.                 $sitepress->save_settings( $iclsettings );
  369.  
  370.                 if ( !empty( $sitepress_settings[ 'setup_complete' ] ) && !empty( $_GET[ 'page' ] ) ) {
  371.                     wp_redirect( admin_url( 'admin.php?page=' . $_GET[ 'page' ] . '&icl_ls_reset=default#icl_save_language_switcher_options' ) );
  372.                 }
  373.             }
  374.         }
  375.     }
  376.  
  377.     /**
  378.      * @param $config
  379.      *
  380.      * @return mixed
  381.      */
  382.     protected static function parse_custom_fields( $config )
  383.     {
  384.         global $iclTranslationManagement;
  385.         if ( !empty( $config[ 'wpml-config' ][ 'custom-fields' ] ) ) {
  386.             if ( !is_numeric( key( current( $config[ 'wpml-config' ][ 'custom-fields' ] ) ) ) ) {
  387.                 $cf[ 0 ] = $config[ 'wpml-config' ][ 'custom-fields' ][ 'custom-field' ];
  388.             } else {
  389.                 $cf = $config[ 'wpml-config' ][ 'custom-fields' ][ 'custom-field' ];
  390.             }
  391.             foreach ( $cf as $c ) {
  392.                 if ( $c[ 'attr' ][ 'action' ] == 'translate' ) {
  393.                     $action = 2;
  394.                 } elseif ( $c[ 'attr' ][ 'action' ] == 'copy' ) {
  395.                     $action = 1;
  396.                 } else {
  397.                     $action = 0;
  398.                 }
  399.                 $iclTranslationManagement->settings[ 'custom_fields_translation' ][ $c[ 'value' ] ] = $action;
  400.                 if (isset($iclTranslationManagement->settings[ 'custom_fields_readonly_config' ]) && is_array( $iclTranslationManagement->settings[ 'custom_fields_readonly_config' ] ) && !in_array( $c[ 'value' ], $iclTranslationManagement->settings[ 'custom_fields_readonly_config' ] ) ) {
  401.                     $iclTranslationManagement->settings[ 'custom_fields_readonly_config' ][ ] = $c[ 'value' ];
  402.                 }
  403.  
  404.             }
  405.         }
  406.  
  407.     }
  408.  
  409.     /**
  410.      * @param $config
  411.      *
  412.      * @return array
  413.      */
  414.     protected static function parse_custom_types( $config )
  415.     {
  416.         global $sitepress, $iclTranslationManagement;
  417.         $cf = array();
  418.         $custom_posts_sync_option = array();
  419.  
  420.         if ( !empty( $config[ 'wpml-config' ][ 'custom-types' ] ) ) {
  421.             if ( !is_numeric( key( current( $config[ 'wpml-config' ][ 'custom-types' ] ) ) ) ) {
  422.                 $cf[ 0 ] = $config[ 'wpml-config' ][ 'custom-types' ][ 'custom-type' ];
  423.             } else {
  424.                 $cf = $config[ 'wpml-config' ][ 'custom-types' ][ 'custom-type' ];
  425.             }
  426.  
  427.             foreach ( $cf as $c ) {
  428.  
  429.                 $translate = intval( $c[ 'attr' ][ 'translate' ] );
  430.                 $iclTranslationManagement->settings[ 'custom_types_readonly_config' ][ $c[ 'value' ] ]  = $translate;
  431.                 $custom_posts_sync_option[ 'custom_posts_sync_option' ][ $c[ 'value' ] ]                = $translate;
  432.  
  433.                 if ( $translate == 1) {
  434.                     $sitepress->verify_post_translations( $c[ 'value' ] );
  435.                     $iclTranslationManagement->save_settings();
  436.                 }
  437.  
  438.             }
  439.  
  440.             $sitepress->save_settings( $custom_posts_sync_option );
  441.  
  442.             // add_filter( 'get_translatable_documents', array( $iclTranslationManagement, '_override_get_translatable_documents' ) );
  443.         }
  444.  
  445.  
  446.         // custom post types - check what's been removed
  447.         if ( !empty( $iclTranslationManagement->settings[ 'custom_types_readonly_config' ] ) ) {
  448.             $config_values = array();
  449.             foreach ( $cf as $config_value ) {
  450.                 $config_values[ $config_value[ 'value' ] ] = $config_value[ 'attr' ][ 'translate' ];
  451.             }
  452.             $do_save = false;
  453.             foreach ( $iclTranslationManagement->settings[ 'custom_types_readonly_config' ] as $tconf => $tconf_val ) {
  454.                 if ( !isset( $config_values[ $tconf ] ) ) {
  455.                     unset( $iclTranslationManagement->settings[ 'custom_types_readonly_config' ][ $tconf ] );
  456.                     $do_save = true;
  457.                 }
  458.             }
  459.             if ( $do_save ) {
  460.                 $iclTranslationManagement->save_settings();
  461.             }
  462.         }
  463.  
  464.  
  465.  
  466.     }
  467.  
  468.     /**
  469.      * @param $config
  470.      *
  471.      * @return array
  472.      */
  473.     protected static function parse_taxonomies( $config ) {
  474.         global $sitepress, $iclTranslationManagement;
  475.  
  476.         $cf                     = array();
  477.         $taxonomies_sync_option = $sitepress->get_setting( 'taxonomies_sync_option', array() );
  478.  
  479.         if ( !empty( $config[ 'wpml-config' ][ 'taxonomies' ] ) ) {
  480.             if ( !is_numeric( key( current( $config[ 'wpml-config' ][ 'taxonomies' ] ) ) ) ) {
  481.                 $cf[ 0 ] = $config[ 'wpml-config' ][ 'taxonomies' ][ 'taxonomy' ];
  482.             } else {
  483.                 $cf = $config[ 'wpml-config' ][ 'taxonomies' ][ 'taxonomy' ];
  484.             }
  485.  
  486.             foreach ( $cf as $c ) {
  487.                 $sync_existing_setting = isset( $taxonomies_sync_option[ $c[ 'value' ] ] ) ? $taxonomies_sync_option[ $c[ 'value' ] ] : false;
  488.                 $translate                                                                           = intval( $c[ 'attr' ][ 'translate' ] );
  489.                 $iclTranslationManagement->settings[ 'taxonomies_readonly_config' ][ $c[ 'value' ] ] = $translate;
  490.                 $taxonomies_sync_option[ $c[ 'value' ] ]                                             = $translate;
  491.  
  492.                 // this has just changed. save.
  493.                 if ( $translate == 1 && !$sync_existing_setting ) {
  494.                     $sitepress->verify_taxonomy_translations( $c[ 'value' ] );
  495.                     $iclTranslationManagement->save_settings();
  496.                 }
  497.             }
  498.  
  499.             $sitepress->set_setting( '$taxonomies_sync_option', $taxonomies_sync_option );
  500.  
  501.             add_filter(
  502.                 'get_translatable_taxonomies',
  503.                 array( $iclTranslationManagement, '_override_get_translatable_taxonomies' )
  504.             );
  505.         }
  506.  
  507.         // taxonomies - check what's been removed
  508.         if ( !empty( $iclTranslationManagement->settings[ 'taxonomies_readonly_config' ] ) ) {
  509.             $config_values = array();
  510.             foreach ( $cf as $config_value ) {
  511.                 $config_values[ $config_value[ 'value' ] ] = $config_value[ 'attr' ][ 'translate' ];
  512.             }
  513.             $do_save = false;
  514.             foreach ( $iclTranslationManagement->settings[ 'taxonomies_readonly_config' ] as $tconf => $tconf_val ) {
  515.                 if ( !isset( $config_values[ $tconf ] ) ) {
  516.                     unset( $iclTranslationManagement->settings[ 'taxonomies_readonly_config' ][ $tconf ] );
  517.                     $do_save = true;
  518.                 }
  519.             }
  520.             if ( $do_save ) {
  521.                 $iclTranslationManagement->save_settings();
  522.             }
  523.         }
  524.     }
  525.  
  526.     /**
  527.      * @param $config
  528.      *
  529.      * @return array
  530.      */
  531.     protected static function parse_admin_texts( $config )
  532.     {
  533.         global $iclTranslationManagement;
  534.  
  535.         if ( function_exists( 'icl_register_string' ) ) {
  536.             $admin_texts = array();
  537.             if ( !empty( $config[ 'wpml-config' ][ 'admin-texts' ] ) ) {
  538.  
  539.                 if ( !is_numeric( key( @current( $config[ 'wpml-config' ][ 'admin-texts' ] ) ) ) ) {
  540.                     $admin_texts[ 0 ] = $config[ 'wpml-config' ][ 'admin-texts' ][ 'key' ];
  541.                 } else {
  542.                     $admin_texts = $config[ 'wpml-config' ][ 'admin-texts' ][ 'key' ];
  543.                 }
  544.  
  545.                 $type               = 'plugin';
  546.                 $admin_text_context = '';
  547.  
  548.                 foreach ( $admin_texts as $a ) {
  549.  
  550.                     if ( isset( $a[ 'type' ] ) ) {
  551.                         $type = $a[ 'type' ];
  552.                     }
  553.                     if ( isset( $a[ 'context' ] ) ) {
  554.                         $admin_text_context = $a[ 'context' ];
  555.                     }
  556.                     if ( !isset( $type ) ) {
  557.                         $type = 'plugin';
  558.                     }
  559.                     if ( !isset( $admin_text_context ) ) {
  560.                         $admin_text_context = '';
  561.                     }
  562.  
  563.                     $keys = array();
  564.                     if ( !isset( $a[ 'key' ]) ) {
  565.                         $arr[ $a[ 'attr' ][ 'name' ] ] = 1;
  566.                         $arr_context[ $a[ 'attr' ][ 'name' ] ] = $admin_text_context;
  567.                         $arr_type[ $a[ 'attr' ][ 'name' ] ] = $type;
  568.                         continue;
  569.                     } elseif ( !is_numeric( key( $a[ 'key' ] ) ) ) {
  570.                         $keys[ 0 ] = $a[ 'key' ];
  571.                     } else {
  572.                         $keys = $a[ 'key' ];
  573.                     }
  574.  
  575.                     foreach ( $keys as $key ) {
  576.                         if ( isset( $key[ 'key' ] ) ) {
  577.                             $arr[ $a[ 'attr' ][ 'name' ] ][ $key[ 'attr' ][ 'name' ] ] = self::read_admin_texts_recursive( $key[ 'key' ], $admin_text_context, $type, $arr_context, $arr_type );
  578.                         } else {
  579.                             $arr[ $a[ 'attr' ][ 'name' ] ][ $key[ 'attr' ][ 'name' ] ] = 1;
  580.                         }
  581.                         $arr_context[ $a[ 'attr' ][ 'name' ] ] = $admin_text_context;
  582.                         $arr_type[ $a[ 'attr' ][ 'name' ] ] = $type;
  583.                     }
  584.                 }
  585.  
  586.                 if ( isset( $arr ) ) {
  587.                     $iclTranslationManagement->admin_texts_to_translate = array_merge( $iclTranslationManagement->admin_texts_to_translate, $arr );
  588.                 }
  589.  
  590.                 $_icl_admin_option_names = get_option( '_icl_admin_option_names' );
  591.  
  592.                 $arr_options = array();
  593.                 if ( isset( $arr ) && is_array( $arr ) ) {
  594.                     foreach ( $arr as $key => $v ) {
  595.                         remove_filter( 'option_' . $key, 'icl_st_translate_admin_string' ); // dont try to translate this one below
  596.                         $value = get_option( $key );
  597.                         add_filter( 'option_' . $key, 'icl_st_translate_admin_string' ); // put the filter back on
  598.  
  599.                         $value = maybe_unserialize( $value );
  600.                         $admin_text_context  = isset($arr_context[$key]) ? $arr_context[$key] : '';
  601.                         $type = isset($arr_type[$key]) ? $arr_type[$key] : '';
  602.  
  603.                         if ( false === $value ) {
  604.  
  605.                             // wildcard? register all matching options in wp_options
  606.                             global $wpdb;
  607.                             $src     = str_replace( '*', '%', wpml_like_escape( $key ) );
  608.                             $matches = $wpdb->get_results( "SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE '{$src}'" );
  609.                             foreach ( $matches as $match ) {
  610.                                 icl_register_string( 'admin_texts_' . $type . '_' . $admin_text_context, $match->option_name, $match->option_value );
  611.  
  612.                                 $_icl_admin_option_names[ $type ][ $admin_text_context ][ ] = $match->option_name;
  613.                             }
  614.                             unset( $arr[ $key ] );
  615.  
  616.                         }
  617.                         if ( is_scalar( $value ) ) {
  618.                             icl_register_string( 'admin_texts_' . $type . '_' . $admin_text_context, $key, $value );
  619.                         } else {
  620.                             if ( is_object( $value ) ) {
  621.                                 $value = (array)$value;
  622.                             }
  623.                             if ( !empty( $value ) ) {
  624.                                 $iclTranslationManagement->_register_string_recursive( $key, $value, $arr[ $key ], '', $type . '_' . $admin_text_context );
  625.                             }
  626.                         }
  627.                         $arr_options[$type][$admin_text_context][$key] = $v;
  628.                     }
  629.  
  630.                     if(is_array($_icl_admin_option_names)) {
  631.                         $_icl_admin_option_names = @array_merge( (array)$_icl_admin_option_names, $arr_options );
  632.                     } else {
  633.                         $_icl_admin_option_names = $arr_options ;
  634.                     }
  635.                 }
  636.  
  637.                 //$_icl_admin_option_names[ $type ][ $admin_text_context ] = __array_unique_recursive( $_icl_admin_option_names[ $type ][ $admin_text_context ] );
  638.  
  639.                 update_option( '_icl_admin_option_names', $_icl_admin_option_names );
  640.  
  641.             }
  642.         }
  643.  
  644.     }
  645.  
  646.     private static function read_admin_texts_recursive( $keys, $admin_text_context, $type, &$arr_context, &$arr_type )
  647.     {
  648.         if ( !is_numeric( key( $keys ) ) ) {
  649.             $_keys = array( $keys );
  650.             $keys  = $_keys;
  651.             unset( $_keys );
  652.         }
  653.         $arr = false;
  654.         if ( $keys ) {
  655.             foreach ( $keys as $key ) {
  656.                 if ( isset( $key[ 'key' ] ) ) {
  657.                     $arr[ $key[ 'attr' ][ 'name' ] ] = self::read_admin_texts_recursive( $key[ 'key' ], $admin_text_context, $type, $arr_context, $arr_type );
  658.                 } else {
  659.                     $arr[ $key[ 'attr' ][ 'name' ] ] = 1;
  660.                     $arr_context[ $key[ 'attr' ][ 'name' ] ] = $admin_text_context;
  661.                     $arr_type[ $key[ 'attr' ][ 'name' ] ] = $type;
  662.                 }
  663.             }
  664.         }
  665.  
  666.         return $arr;
  667.     }
  668. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement