function process_forms() { global $wpdb; require_once ICL_PLUGIN_PATH . '/lib/Snoopy.class.php'; require_once ICL_PLUGIN_PATH . '/lib/xml2array.php'; require_once ICL_PLUGIN_PATH . '/lib/icl_api.php'; if (isset($_POST['icl_post_action'])) { switch ($_POST['icl_post_action']) { case 'save_theme_localization': $locales = array(); foreach ($_POST as $k => $v) { if (0 !== strpos($k, 'locale_file_name_') || !trim($v)) { continue; } $locales[str_replace('locale_file_name_', '', $k)] = $v; } if (!empty($locales)) { $this->set_locale_file_names($locales); } break; } return; } $create_account = isset($_POST['icl_create_account_nonce']) && $_POST['icl_create_account_nonce'] == wp_create_nonce('icl_create_account'); $create_account_and_transfer = isset($_POST['icl_create_account_and_transfer_nonce']) && $_POST['icl_create_account_and_transfer_nonce'] == wp_create_nonce('icl_create_account_and_transfer'); $config_account = isset($_POST['icl_configure_account_nonce']) && $_POST['icl_configure_account_nonce'] == wp_create_nonce('icl_configure_account'); $create_support_account = isset($_POST['icl_create_support_account_nonce']) && $_POST['icl_create_support_account_nonce'] == wp_create_nonce('icl_create_support_account'); $config_support_account = isset($_POST['icl_configure_support_account_nonce']) && $_POST['icl_configure_support_account_nonce'] == wp_create_nonce('icl_configure_support_account'); $use_existing_account = isset($_POST['icl_use_account_nonce']) && $_POST['icl_use_account_nonce'] == wp_create_nonce('icl_use_account'); $transfer_to_account = isset($_POST['icl_transfer_account_nonce']) && $_POST['icl_transfer_account_nonce'] == wp_create_nonce('icl_transfer_account'); if ($create_account || $config_account || $create_support_account || $config_support_account) { if (isset($_POST['icl_content_trans_setup_back_2'])) { // back button in wizard mode. $this->settings['content_translation_setup_wizard_step'] = 2; $this->save_settings(); } else { $user = $_POST['user']; $user['create_account'] = isset($_POST['icl_create_account_nonce']) || isset($_POST['icl_create_support_account_nonce']) ? 1 : 0; $user['platform_kind'] = 2; $user['cms_kind'] = 1; $user['blogid'] = $wpdb->blogid ? $wpdb->blogid : 1; $user['url'] = get_option('home'); $user['title'] = get_option('blogname'); $user['description'] = $this->settings['icl_site_description']; $user['is_verified'] = 1; if ($user['create_account'] && defined('ICL_AFFILIATE_ID') && defined('ICL_AFFILIATE_KEY')) { $user['affiliate_id'] = ICL_AFFILIATE_ID; $user['affiliate_key'] = ICL_AFFILIATE_KEY; } $user['interview_translators'] = $this->settings['interview_translators']; $user['project_kind'] = $this->settings['website_kind']; /* if(is_null($user['project_kind']) || $user['project_kind']==''){ $_POST['icl_form_errors'] = __('Please select the kind of website','sitepress'); return; } */ $user['pickup_type'] = intval($this->settings['translation_pickup_method']); $notifications = 0; if ($this->settings['icl_notify_complete']) { $notifications += 1; } if ($this->settings['alert_delay']) { $notifications += 2; } $user['notifications'] = $notifications; // prepare language pairs $pay_per_use = $this->settings['translator_choice'] == 1; $language_pairs = $this->settings['language_pairs']; $lang_pairs = array(); if (isset($language_pairs)) { foreach ($language_pairs as $k => $v) { $english_fr = $wpdb->get_var("SELECT english_name FROM {$wpdb->prefix}icl_languages WHERE code='{$k}' "); foreach ($v as $k => $v) { $incr++; $english_to = $wpdb->get_var("SELECT english_name FROM {$wpdb->prefix}icl_languages WHERE code='{$k}' "); $lang_pairs['from_language' . $incr] = ICL_Pro_Translation::server_languages_map($english_fr); $lang_pairs['to_language' . $incr] = ICL_Pro_Translation::server_languages_map($english_to); if ($pay_per_use) { $lang_pairs['pay_per_use' . $incr] = 1; } } } } $icl_query = new ICanLocalizeQuery(); list($site_id, $access_key) = $icl_query->createAccount(array_merge($user, $lang_pairs)); if (!$site_id) { $user['pickup_type'] = ICL_PRO_TRANSLATION_PICKUP_POLLING; list($site_id, $access_key) = $icl_query->createAccount(array_merge($user, $lang_pairs)); } if (!$site_id) { if ($access_key) { $_POST['icl_form_errors'] = $access_key; } else { $_POST['icl_form_errors'] = __('An unknown error has occurred when communicating with the ICanLocalize server. Please try again.', 'sitepress'); // We will force the next try to be http. update_option('_force_mp_post_http', 1); } } else { if ($create_account || $config_account) { $iclsettings['site_id'] = $site_id; $iclsettings['access_key'] = $access_key; $iclsettings['icl_account_email'] = $user['email']; // set the support data the same. $iclsettings['support_site_id'] = $site_id; $iclsettings['support_access_key'] = $access_key; $iclsettings['support_icl_account_email'] = $user['email']; } else { $iclsettings['support_site_id'] = $site_id; $iclsettings['support_access_key'] = $access_key; $iclsettings['support_icl_account_email'] = $user['email']; } if (isset($user['pickup_type']) && $user['pickup_type'] == ICL_PRO_TRANSLATION_PICKUP_POLLING) { $iclsettings['translation_pickup_method'] = ICL_PRO_TRANSLATION_PICKUP_POLLING; } $this->save_settings($iclsettings); if ($user['create_account'] == 1) { $_POST['icl_form_success'] = __('A project on ICanLocalize has been created.', 'sitepress') . '<br />'; } else { $_POST['icl_form_success'] = __('Project added', 'sitepress'); } $this->get_icl_translator_status($iclsettings); $this->save_settings($iclsettings); } if (!$create_support_account && !$config_support_account && intval($site_id) > 0 && $access_key && $this->settings['content_translation_setup_complete'] == 0 && $this->settings['content_translation_setup_wizard_step'] == 3 && !isset($_POST['icl_form_errors'])) { // we are running the wizard, so we can finish it now. $this->settings['content_translation_setup_complete'] = 1; $this->settings['content_translation_setup_wizard_step'] = 0; $this->save_settings(); } } } elseif ($use_existing_account || $transfer_to_account || $create_account_and_transfer) { if (isset($_POST['icl_content_trans_setup_back_2'])) { // back button in wizard mode. $this->settings['content_translation_setup_wizard_step'] = 2; $this->save_settings(); } else { if ($transfer_to_account) { $_POST['user']['email'] = $_POST['user']['email2']; } // we will be using the support account for the icl_account $this->settings['site_id'] = $this->settings['support_site_id']; $this->settings['access_key'] = $this->settings['support_access_key']; $this->settings['icl_account_email'] = $this->settings['support_icl_account_email']; $this->save_settings(); update_icl_account(); if ($transfer_to_account || $create_account_and_transfer) { if (!$this->transfer_icl_account($create_account_and_transfer)) { return; } } // we are running the wizard, so we can finish it now. $this->settings['content_translation_setup_complete'] = 1; $this->settings['content_translation_setup_wizard_step'] = 0; $this->save_settings(); $iclsettings['site_id'] = $this->settings['site_id']; $iclsettings['access_key'] = $this->settings['access_key']; $this->get_icl_translator_status($iclsettings); $this->save_settings($iclsettings); } } elseif (isset($_POST['icl_initial_languagenonce']) && $_POST['icl_initial_languagenonce'] == wp_create_nonce('icl_initial_language')) { $this->prepopulate_translations($_POST['icl_initial_language_code']); $wpdb->update($wpdb->prefix . 'icl_languages', array('active' => '1'), array('code' => $_POST['icl_initial_language_code'])); $blog_default_cat = get_option('default_category'); $blog_default_cat_tax_id = $wpdb->get_var("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id='{$blog_default_cat}' AND taxonomy='category'"); if (isset($_POST['save_one_language'])) { $this->settings['setup_wizard_step'] = 0; $this->settings['setup_complete'] = 1; } else { $this->settings['setup_wizard_step'] = 2; } $this->settings['default_categories'] = array($_POST['icl_initial_language_code'] => $blog_default_cat_tax_id); $this->settings['existing_content_language_verified'] = 1; $this->settings['default_language'] = $_POST['icl_initial_language_code']; $this->settings['admin_default_language'] = $this->admin_language = $_POST['icl_initial_language_code']; // set the locale in the icl_locale_map (if it's not set) if (!$wpdb->get_var("SELECT code FROM {$wpdb->prefix}icl_locale_map WHERE code='{$_POST['icl_initial_language_code']}'")) { $default_locale = $wpdb->get_var("SELECT default_locale FROM {$wpdb->prefix}icl_languages WHERE code='{$_POST['icl_initial_language_code']}'"); if ($default_locale) { $wpdb->insert($wpdb->prefix . 'icl_locale_map', array('code' => $_POST['icl_initial_language_code'], 'locale' => $default_locale)); } } $this->save_settings(); global $sitepress_settings; $sitepress_settings = $this->settings; $this->get_active_languages(true); //refresh active languages list do_action('icl_initial_language_set'); } elseif (isset($_POST['icl_language_pairs_formnounce']) && $_POST['icl_language_pairs_formnounce'] == wp_create_nonce('icl_language_pairs_form')) { $this->save_language_pairs(); $this->settings['content_translation_languages_setup'] = 1; // Move onto the site description page $this->settings['content_translation_setup_wizard_step'] = 2; $this->settings['website_kind'] = 2; $this->settings['interview_translators'] = 1; $this->save_settings(); } elseif (isset($_POST['icl_site_description_wizardnounce']) && $_POST['icl_site_description_wizardnounce'] == wp_create_nonce('icl_site_description_wizard')) { if (isset($_POST['icl_content_trans_setup_back_2'])) { // back button. $this->settings['content_translation_languages_setup'] = 0; $this->settings['content_translation_setup_wizard_step'] = 1; $this->save_settings(); } elseif (isset($_POST['icl_content_trans_setup_next_2']) || isset($_POST['icl_content_trans_setup_next_2_enter'])) { // next button. $description = $_POST['icl_description']; if ($description == "") { $_POST['icl_form_errors'] = __('Please provide a short description of the website so that translators know what background is required from them.', 'sitepress'); } else { $this->settings['icl_site_description'] = $description; $this->settings['content_translation_setup_wizard_step'] = 3; $this->save_settings(); } } } }
$langs = $iclsettings['language_pairs']; $active_languages = $this->get_active_languages(); $result = ''; foreach ($langs as $from_lang => $targets) { foreach ($targets as $to_lang => $to_status) { if ($to_status) { $result .= $from_lang . '~' . $to_lang . '~' . $this->get_language_status_text($from_lang, $to_lang) . "\n"; } } } echo "1|" . $result; break; case 'save_site_description': $iclsettings['icl_site_description'] = $_POST['icl_description']; $this->save_settings($iclsettings); $ret = update_icl_account(); if ($ret) { echo '1| (' . __('Not updated on ICanLocalize: ', 'sitepress') . $ret . ')'; break; } echo '1|' . __('Your site description has been saved.', 'sitepress'); break; case 'do_account_transfer': if ($_POST['icl_new'] != '1') { $_POST['user']['email'] = $_POST['user']['email2']; } if ($_POST['user']['email'] == '') { echo '0|' . __('Please enter an email address', 'sitepress'); break; } if (!$this->transfer_icl_account($_POST['icl_new'] == '1')) {