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_home_url();
             $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}' ");
                     $pay_per_use_increment = 0;
                     foreach ($v as $k => $v) {
                         $pay_per_use_increment++;
                         $english_to = $wpdb->get_var("SELECT english_name FROM {$wpdb->prefix}icl_languages WHERE code='{$k}' ");
                         $lang_pairs['from_language' . $pay_per_use_increment] = ICL_Pro_Translation::server_languages_map($english_fr);
                         $lang_pairs['to_language' . $pay_per_use_increment] = ICL_Pro_Translation::server_languages_map($english_to);
                         if ($pay_per_use) {
                             $lang_pairs['pay_per_use' . $pay_per_use_increment] = 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();
             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)
         $q = "SELECT code FROM {$wpdb->prefix}icl_locale_map WHERE code=%s";
         $q_prepared = $wpdb->prepare($q, $_POST['icl_initial_language_code']);
         if (!$wpdb->get_var($q_prepared)) {
             $q = "SELECT default_locale FROM {$wpdb->prefix}icl_languages WHERE code=%s";
             $q_prepared = $wpdb->prepare($q, $_POST['icl_initial_language_code']);
             $default_locale = $wpdb->get_var($q_prepared);
             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();
             }
         }
     }
 }
Exemple #2
0
            $user['project_kind'] = 2;
            $user['pickup_type'] = intval($sitepress_settings['translation_pickup_method']);
            $notifications = 0;
            if (!empty($sitepress_settings['icl_notify_complete'])) {
                $notifications += 1;
            }
            if ($sitepress_settings['alert_delay']) {
                $notifications += 2;
            }
            $user['notifications'] = $notifications;
            $user['ignore_languages'] = 0;
            $user['from_language1'] = isset($_GET['lang_from']) ? $_GET['lang_from'] : 'English';
            $user['to_language1'] = isset($_GET['lang_to']) ? $_GET['lang_to'] : 'French';
        }
        define('ICL_DEB_SHOW_ICL_RAW_RESPONSE', true);
        $resp = $icl_query->createAccount($user);
        echo '<textarea style="width:100%;height:400px;font-size:9px;">';
        if (defined('ICL_API_ENDPOINT')) {
            echo ICL_API_ENDPOINT . "\r\n\r\n";
        }
        echo __('Data', 'sitepress') . "\n----------------------------------------\n" . print_r($user, 1) . __('Response', 'sitepress') . "\n----------------------------------------\n" . print_r($resp, 1) . '</textarea>';
        ?>

		<?php 
    }
    ?>
		<a class="button" href="admin.php?page=<?php 
    echo ICL_PLUGIN_FOLDER;
    ?>
/menu/troubleshooting.php&ts=<?php 
    echo time();
 }
 $user['interview_translators'] = $this->settings['interview_translators'];
 $user['project_kind'] = 2;
 $user['pickup_type'] = intval($this->settings['translation_pickup_method']);
 $notifications = 0;
 if (!empty($this->settings['icl_notify_complete'])) {
     $notifications += 1;
 }
 if ($this->settings['alert_delay']) {
     $notifications += 2;
 }
 $user['notifications'] = $notifications;
 $user['ignore_languages'] = 0;
 $user['from_language1'] = $lang_server[$from_lang];
 $user['to_language1'] = $lang_server[$to_lang];
 list($site_id, $access_key) = $icl_query->createAccount($user);
 if ($site_id && $access_key) {
     $this->settings['site_id'] = $iclsettings['site_id'] = $site_id;
     $this->settings['access_key'] = $iclsettings['access_key'] = $access_key;
     $iclsettings['language_pairs'][$from_lang][$to_lang] = 1;
     $this->save_settings($iclsettings);
 } else {
     $user['pickup_type'] = ICL_PRO_TRANSLATION_PICKUP_POLLING;
     list($site_id, $access_key) = $icl_query->createAccount($user);
     if ($site_id && $access_key) {
         $this->settings['site_id'] = $iclsettings['site_id'] = $site_id;
         $this->settings['access_key'] = $iclsettings['access_key'] = $access_key;
         $iclsettings['language_pairs'][$from_lang][$to_lang] = 1;
         $iclsettings['translation_pickup_method'] = ICL_PRO_TRANSLATION_PICKUP_POLLING;
         $this->save_settings($iclsettings);
     } else {
 function create_icl_account()
 {
     global $sitepress;
     $site_id = false;
     $access_key = false;
     $user = $this->create_user_account();
     require_once ICL_PLUGIN_PATH . '/lib/icl_api.php';
     $icl_query = new ICanLocalizeQuery();
     list($site_id, $access_key) = $icl_query->createAccount($user, TA_URL_ENDPOINT);
     if (!$site_id) {
         $user['pickup_type'] = ICL_PRO_TRANSLATION_PICKUP_POLLING;
         list($site_id, $access_key) = $icl_query->createAccount($user, TA_URL_ENDPOINT);
     }
     if ($site_id) {
         if ($user['pickup_type'] == ICL_PRO_TRANSLATION_PICKUP_POLLING) {
             $sitepress->set_setting('translation_pickup_method', ICL_PRO_TRANSLATION_PICKUP_POLLING);
         }
         $icl_query = new ICanLocalizeQuery($site_id, $access_key);
         $website_details = $icl_query->get_website_details(TA_URL_ENDPOINT);
         TranslationProxy_Translator::get_icl_translator_status($website_details);
     }
     return array($site_id, $access_key);
 }
 /**
  * Create an account for the website.
  * This is used in case the website project has not been set up yet.
  */
 function create_account()
 {
     global $sitepress, $sitepress_settings, $wpdb;
     $user = array();
     $user['create_account'] = 1;
     $user['anon'] = 1;
     $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'] = isset($sitepress_settings['icl_site_description']) ? $sitepress_settings['icl_site_description'] : '';
     $user['is_verified'] = 1;
     $user['interview_translators'] = $sitepress_settings['interview_translators'];
     $user['project_kind'] = isset($sitepress_settings['website_kind']) ? $sitepress_settings['website_kind'] : 2;
     $user['pickup_type'] = intval($sitepress_settings['translation_pickup_method']);
     $user['ignore_languages'] = 1;
     if (defined('ICL_AFFILIATE_ID') && defined('ICL_AFFILIATE_KEY')) {
         $user['affiliate_id'] = ICL_AFFILIATE_ID;
         $user['affiliate_key'] = ICL_AFFILIATE_KEY;
     }
     $notifications = 0;
     if (isset($sitepress_settings['icl_notify_complete'])) {
         if ($sitepress_settings['icl_notify_complete']) {
             $notifications += 1;
         }
         if ($sitepress_settings['alert_delay']) {
             $notifications += 2;
         }
     }
     $user['notifications'] = $notifications;
     require_once ICL_PLUGIN_PATH . '/lib/icl_api.php';
     $icl_query = new ICanLocalizeQuery();
     list($site_id, $access_key) = $icl_query->createAccount($user);
     if (!$site_id) {
         $user['pickup_type'] = ICL_PRO_TRANSLATION_PICKUP_POLLING;
         list($site_id, $access_key) = $icl_query->createAccount($user);
     }
     if ($site_id) {
         if ($user['pickup_type'] == ICL_PRO_TRANSLATION_PICKUP_POLLING) {
             $sitepress_settings['translation_pickup_method'] = ICL_PRO_TRANSLATION_PICKUP_POLLING;
         }
         $sitepress_settings['site_id'] = $site_id;
         $sitepress_settings['access_key'] = $access_key;
         $sitepress_settings['icl_account_email'] = isset($user['email']) ? $user['email'] : '';
         $sitepress->get_icl_translator_status($sitepress_settings);
         $sitepress->save_settings($sitepress_settings);
     }
 }
     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;
             }
         }
     }
 }
 require_once ICL_PLUGIN_PATH . '/lib/icl_api.php';
 $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) {
         // We will force the next try to be http.
         update_option('_force_mp_post_http', 1);
     }
     $saved = $sitepress_settings['quote-get'];
     $saved['step'] = 3;
     $sitepress->save_settings(array('quote-get' => $saved));
     echo __('An unknown error has occurred when communicating with the ICanLocalize server. Please try again.', 'sitepress') . '<br /><br />';
     require_once ICL_PLUGIN_PATH . '/inc/quote/quote-get.php';
     exit;