function ppqtrans_showAllSeperated($text) { if (empty($text)) { return $text; } global $q_config; $result = ""; foreach (ppqtrans_getSortedLanguages() as $language) { $result .= $q_config['language_name'][$language] . ":\n" . ppqtrans_use($language, $text) . "\n\n"; } return $result; }
function ppqtrans_generateLanguageSelectCode($style = '', $id = '') { global $q_config; if ($style == '') { $style = 'text'; } if (is_bool($style) && $style) { $style = 'image'; } if (is_404()) { $url = get_option('home'); } else { $url = ''; } if ($id == '') { $id = 'qtranslate'; } $id .= '-chooser'; switch ($style) { case 'image': case 'text': case 'dropdown': echo '<ul class="ppqtrans_language_chooser" id="' . $id . '">'; foreach (ppqtrans_getSortedLanguages() as $language) { $classes = array('lang-' . $language); if ($language == $q_config['language']) { $classes[] = 'active'; } echo '<li class="' . implode(' ', $classes) . '"><a href="' . ppqtrans_convertURL($url, $language) . '"'; // set hreflang echo ' hreflang="' . $language . '" title="' . $q_config['language_name'][$language] . '"'; if ($style == 'image') { echo ' class="ppqtrans_flag ppqtrans_flag_' . $language . '"'; } echo '><span'; if ($style == 'image') { echo ' style="display:none"'; } echo '>' . $q_config['language_name'][$language] . '</span></a></li>'; } echo "</ul><div class=\"ppqtrans_widget_end\"></div>"; if ($style == 'dropdown') { echo "<script type=\"text/javascript\">\n// <![CDATA[\r\n"; echo "var lc = document.getElementById('" . $id . "');\n"; echo "var s = document.createElement('select');\n"; echo "s.id = 'ppqtrans_select_" . $id . "';\n"; echo "lc.parentNode.insertBefore(s,lc);"; // create dropdown fields for each language foreach (ppqtrans_getSortedLanguages() as $language) { echo ppqtrans_insertDropDownElement($language, ppqtrans_convertURL($url, $language), $id); } // hide html language chooser text echo "s.onchange = function() { document.location.href = this.value;}\n"; echo "lc.style.display='none';\n"; echo "// ]]>\n</script>\n"; } break; case 'both': echo '<ul class="ppqtrans_language_chooser" id="' . $id . '">'; foreach (ppqtrans_getSortedLanguages() as $language) { echo '<li'; if ($language == $q_config['language']) { echo ' class="active"'; } echo '><a href="' . ppqtrans_convertURL($url, $language) . '"'; echo ' class="ppqtrans_flag_' . $language . ' ppqtrans_flag_and_text" title="' . $q_config['language_name'][$language] . '"'; echo '><span>' . $q_config['language_name'][$language] . '</span></a></li>'; } echo "</ul><div class=\"ppqtrans_widget_end\"></div>"; break; } }
function qs_service() { global $q_config, $qs_public_key, $qs_error_messages; if (!isset($_REQUEST['post'])) { echo '<script type="text/javascript">document.location="edit.php";</script>'; printf(__('To translate a post, please go to the <a href="%s">edit posts overview</a>.', 'qtranslate'), 'edit.php'); exit; } $post_id = intval($_REQUEST['post']); $confirm = isset($_GET['confirm']) ? true : false; $translate_from = ''; $translate_to = ''; $translate_from_name = ''; $translate_to_name = ''; if (isset($_REQUEST['source_language']) && ppqtrans_isEnabled($_REQUEST['source_language'])) { $translate_from = $_REQUEST['source_language']; } if (isset($_REQUEST['target_language']) && ppqtrans_isEnabled($_REQUEST['target_language'])) { $translate_to = $_REQUEST['target_language']; } if ($translate_to == $translate_from) { $translate_to = ''; } $post =& get_post($post_id); if (!$post) { printf(__('Post with id "%s" not found!', 'qtranslate'), $post_id); return; } $default_service = intval(get_option('qs_default_service')); $service_settings = get_option('qs_service_settings'); // Detect available Languages and possible target languages $available_languages = ppqtrans_getAvailableLanguages($post->post_content); if (sizeof($available_languages) == 0) { $error = __('The requested Post has no content, no Translation possible.', 'qtranslate'); } // try to guess source and target language if (!in_array($translate_from, $available_languages)) { $translate_from = ''; } $missing_languages = array_diff($q_config['enabled_languages'], $available_languages); if (empty($translate_from) && in_array($q_config['default_language'], $available_languages) && $translate_to != $q_config['default_language']) { $translate_from = $q_config['default_language']; } if (empty($translate_to) && sizeof($missing_languages) == 1) { $translate_to = $missing_languages[0]; } if (in_array($translate_to, $available_languages)) { $message = __('The Post already has content for the selected target language. If a translation request is send, the current text for the target language will be overwritten.', 'qtranslate'); } if (sizeof($available_languages) == 1) { if ($available_languages[0] == $translate_to) { unset($translate_to); } $translate_from = $available_languages[0]; } elseif ($translate_from == '' && sizeof($available_languages) > 1) { $languages = ppqtrans_getSortedLanguages(); foreach ($languages as $language) { if ($language != $translate_to && in_array($language, $available_languages)) { $translate_from = $language; break; } } } // link to current page with get variables $url_link = add_query_arg('post', $post_id); if (!empty($translate_to)) { $url_link = add_query_arg('target_language', $translate_to, $url_link); } if (!empty($translate_from)) { $url_link = add_query_arg('source_language', $translate_from, $url_link); } // get correct title and content $post_title = ppqtrans_use($translate_from, $post->post_title); $post_content = ppqtrans_use($translate_from, $post->post_content); $post_excerpt = ppqtrans_use($translate_from, $post->post_excerpt); if (!empty($translate_from)) { $translate_from_name = $q_config['language_name'][$translate_from]; } if (!empty($translate_to)) { $translate_to_name = $q_config['language_name'][$translate_to]; } if (!empty($translate_from) && !empty($translate_to)) { $title = sprintf('Translate "%1$s" from %2$s to %3$s', htmlspecialchars($post_title), $translate_from_name, $translate_to_name); } elseif (!empty($translate_from)) { $title = sprintf('Translate "%1$s" from %2$s', htmlspecialchars($post_title), $translate_from_name); } else { $title = sprintf('Translate "%1$s"', htmlspecialchars($post_title)); } // Check data if (isset($_POST['service_id'])) { $service_id = intval($_POST['service_id']); $default_service = $service_id; update_option('qs_default_service', $service_id); $order_key = substr(md5(time() . AUTH_KEY), 0, 20); $request = array('order_service_id' => $service_id, 'order_url' => get_option('home'), 'order_key' => $order_key, 'order_title' => $post_title, 'order_text' => $post_content, 'order_excerpt' => $post_excerpt, 'order_source_language' => $translate_from, 'order_source_locale' => $q_config['locale'][$translate_from], 'order_target_language' => $translate_to, 'order_target_locale' => $q_config['locale'][$translate_to]); // check for additional fields if (isset($service_settings[$service_id]) && is_array($service_settings[$service_id])) { $request['order_required_field'] = array(); foreach ($service_settings[$service_id] as $setting => $value) { $request['order_required_field'][$setting] = $value; } } if (isset($_POST['token'])) { $request['order_token'] = $_POST['token']; } $answer = qs_queryQS(QS_INIT_TRANSLATION, $request); if (isset($answer['error'])) { $error = sprintf(__('An error occured: %s', 'qtranslate'), $qs_error_messages[$answer['error']]); if ($answer['message'] != '') { $error .= '<br />' . sprintf(__('Additional information: %s', 'qtranslate'), ppqtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($answer['message'])); } } if (isset($answer['order_id'])) { $orders = get_option('qs_orders'); if (!is_array($orders)) { $orders = array(); } $orders[] = array('post_id' => $post_id, 'service_id' => $service_id, 'source_language' => $translate_from, 'target_language' => $translate_to, 'order' => array('order_key' => $order_key, 'order_id' => $answer['order_id'])); update_option('qs_orders', $orders); if (empty($answer['message'])) { $order_completed_message = ''; } else { $order_completed_message = htmlspecialchars($answer['message']); } qs_UpdateOrder($answer['order_id']); } } if (isset($error)) { ?> <div class="wrap"> <h2><?php _e('qTranslate Services', 'qtranslate'); ?> </h2> <div id="message" class="error fade"><p><?php echo $error; ?> </p></div> <p><?php printf(__('An serious error occured and qTranslate Services cannot proceed. For help, please visit the <a href="%s">Support Forum</a>', 'qtranslate'), 'http://www.qianqin.de/qtranslate/forum/'); ?> </p> </div> <?php return; } if (isset($order_completed_message)) { ?> <div class="wrap"> <h2><?php _e('qTranslate Services', 'qtranslate'); ?> </h2> <div id="message" class="updated fade"><p><?php _e('Order successfully sent.', 'qtranslate'); ?> </p></div> <p><?php _e('Your translation order has been successfully transfered to the selected service.', 'qtranslate'); ?> </p> <?php if (!empty($order_completed_message)) { ?> <p><?php printf(__('The service returned this message: %s', 'qtranslate'), $order_completed_message); ?> </p> <?php } ?> <p><?php _e('Feel free to choose an action:', 'qtranslate'); ?> </p> <ul> <li><a href="<?php echo add_query_arg('target_language', null, $url_link); ?> "><?php _e('Translate this post to another language.', 'qtranslate'); ?> </a></li> <li><a href="edit.php"><?php _e('Translate a different post.', 'qtranslate'); ?> </a></li> <li><a href="options-general.php?page=qtranslate#ppqtranslate_service_settings"><?php _e('View all open orders.', 'qtranslate'); ?> </a></li> <li><a href="options-general.php?page=qtranslate&qs_cron=true#ppqtranslate_service_settings"><?php _e('Let qTranslate Services check if any open orders are finished.', 'qtranslate'); ?> </a></li> <li><a href="<?php echo get_permalink($post_id); ?> "><?php _e('View this post.', 'qtranslate'); ?> </a></li> </ul> </div> <?php return; } ?> <div class="wrap"> <h2><?php _e('qTranslate Services', 'qtranslate'); ?> </h2> <?php if (!empty($message)) { ?> <div id="message" class="updated fade"><p><?php echo $message; ?> </p></div> <?php } ?> <h3><?php echo $title; ?> </h3> <form action="edit.php?page=ppqtranslate_services" method="post" id="qtranslate-services-translate"> <p><?php if (sizeof($available_languages) > 1) { $available_languages_name = array(); foreach (array_diff($available_languages, array($translate_from)) as $language) { $available_languages_name[] = '<a href="' . add_query_arg('source_language', $language, $url_link) . '">' . $q_config['language_name'][$language] . '</a>'; } $available_languages_names = join(", ", $available_languages_name); printf(__('Your article is available in multiple languages. If you do not want to translate from %1$s, you can switch to one of the following languages: %2$s', 'qtranslate'), $q_config['language_name'][$translate_from], $available_languages_names); } ?> </p> <input type="hidden" name="post" value="<?php echo $post_id; ?> "/> <input type="hidden" name="source_language" value="<?php echo $translate_from; ?> "/> <?php if (empty($translate_to)) { ?> <p><?php _e('Please choose the language you want to translate to:', 'qtranslate'); ?> </p> <ul> <?php foreach ($q_config['enabled_languages'] as $language) { if ($translate_from == $language) { continue; } ?> <li><label><input type="radio" name="target_language" value="<?php echo $language; ?> " /> <?php echo $q_config['language_name'][$language]; ?> </li> <?php } ?> </ul> <p class="submit"> <input type="submit" name="submit" class="button-primary" value="<?php _e('Continue', 'qtranslate'); ?> " /> </p> <?php } else { ?> <input type="hidden" name="target_language" value="<?php echo $translate_to; ?> "/> <?php if ($confirm) { ?> <input type="hidden" name="service_id" value="<?php echo $_REQUEST['service_id']; ?> "/> <input type="hidden" name="token" value="<?php echo $_REQUEST['token']; ?> "/> <div id="submitboxcontainer" class="metabox-holder"> <div id="submitdiv" class="postbox"> <h3 class="hndle"><?php _e('Confirm Order', 'qtranslate'); ?> </h3> <div class="inside"> <p><?php _e('Please confirm your order.', 'qtranslate'); ?> </p> <div class="qs_submit"><a class="button-primary" onclick="sendorder();"><?php _e('Confirm Order', 'qtranslate'); ?> </a></div> </div> </div> </div> <?php } else { ?> <div id="submitboxcontainer" class="metabox-holder"> <div id="submitdiv" class="postbox"> <h3 class="hndle"><?php _e('Request Translation', 'qtranslate'); ?> </h3> <div class="inside request"> <noscript><?php _e('Javascript is required for qTranslate Services', 'qtranslate'); ?> </noscript> <p><?php _e('Please choose a service first', 'qtranslate'); ?> </p> </div> </div> </div> <?php } $timestamp = time(); if ($timestamp != qs_queryQS(QS_VERIFY, $timestamp)) { ?> <p class="error"><?php _e('ERROR: Could not connect to qTranslate Services. Please try again later.', 'qtranslate'); ?> </p> <?php return; } ?> <div id="qs_boxes" class="metabox-holder"> <div class="postbox"> <h3 class="hndle"><?php _e('Translation Service', 'qtranslate'); ?> </h3> <div class="inside"> <ul> <?php if ($services = qs_queryQS(QS_GET_SERVICES)) { foreach ($services as $service_id => $service) { // check if we have data for all required fields $requirements_matched = true; foreach ($service['service_required_fields'] as $field) { if (!isset($service_settings[$service_id][$field['name']]) || $service_settings[$service_id][$field['name']] == '') { $requirements_matched = false; } } if (!$requirements_matched) { ?> <li> <label><input type="radio" name="service_id" disabled="disabled" /> <b><?php echo ppqtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($service['service_name']); ?> </b> ( <a href="<?php echo $service['service_url']; ?> " target="_blank"><?php _e('Website', 'qtranslate'); ?> </a> )</label> <p class="error"><?php printf(__('Cannot use this service, not all <a href="%s">required fields</a> filled in for this service.', 'qtranslate'), 'options-general.php?page=qtranslate#qs_service_' . $service_id); ?> </p> <p class="service_description"><?php echo ppqtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($service['service_description']); ?> </p> </li> <?php } else { ?> <li><label><input type="radio" id="qs_service_<?php echo $service['service_id']; ?> " onclick="chooseservice(this.value)" value="<?php echo $service['service_id']; ?> " <?php echo $confirm ? 'disabled="disabled"' : 'name="service_id"'; ?> /> <b><?php echo ppqtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($service['service_name']); ?> </b> ( <a href="<?php echo $service['service_url']; ?> " target="_blank"><?php _e('Website', 'qtranslate'); ?> </a> )</label><p class="service_description"><?php echo ppqtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($service['service_description']); ?> </p></li> <?php } } ?> </ul> <script type="text/javascript"> function chooseservice(id) { jQuery('#qs_service_'+id).attr('checked','checked'); jQuery('#submitdiv .request').html('<?php _e('<p><img src="images/wpspin_light.gif"> Getting Quote...</p>', 'qtranslate'); ?> '); jQuery.post(ajaxurl, { action: 'qs_quote', translate_from: '<?php echo $translate_from; ?> ', translate_to: '<?php echo $translate_to; ?> ', service_id: id, post_id: '<?php echo $post_id; ?> '}, function(response) { eval(response); }); } function sendorder() { jQuery("#qtranslate-services-translate").submit(); } chooseservice('<?php echo isset($_REQUEST['service_id']) ? $_REQUEST['service_id'] : $default_service; ?> '); </script> </div> </div> <div class="postbox closed"> <div class="handlediv" title="<?php _e('Click to toggle'); ?> " onclick="jQuery(this).parent().removeClass('closed');jQuery(this).hide();"><br></div> <h3 class="hndle"><?php _e('Review Article', 'qtranslate'); ?> </h3> <div class="inside"> <textarea name="qs_content_preview" id="qs_content_preview" readonly="readonly"><?php echo $post_content; ?> </textarea> </div> </div> <p><?php _e('Your article will be SSL encrypted and securly sent to qTranslate Services, which will forward your text to the chosen Translation Service. Once qTranslate Services receives the translated text, it will automatically appear on your blog.', 'qtranslate'); ?> </p> <?php } ?> </div> <?php } ?> </div> </form> <?php }
function qtrans_getSortedLanguages($reverse = false) { return ppqtrans_getSortedLanguages($reverse); }
function ppqtranslate_conf() { global $q_config, $wpdb; // do redirection for dashboard if (isset($_GET['godashboard'])) { echo '<h2>' . __('Switching Language', 'qtranslate') . '</h2>' . sprintf(__('Switching language to %1$s... If the Dashboard isn\'t loading, use this <a href="%2$s" title="Dashboard">link</a>.', 'qtranslate'), $q_config['language_name'][ppqtrans_getLanguage()], admin_url()) . '<script type="text/javascript">document.location="' . admin_url() . '";</script>'; exit; } // init some needed variables $error = ''; $original_lang = ''; $language_code = ''; $language_name = ''; $language_locale = ''; $language_date_format = ''; $language_time_format = ''; $language_na_message = ''; $language_flag = ''; $language_default = ''; $altered_table = false; $message = apply_filters('ppqtranslate_configuration_pre', ''); // check for action if (isset($_POST['ppqtranslate_reset']) && isset($_POST['ppqtranslate_reset2'])) { $message = __('qTranslate has been reset.', 'qtranslate'); } elseif (isset($_POST['default_language'])) { // save settings ppqtrans_checkSetting('default_language', true, QT_LANGUAGE); ppqtrans_checkSetting('flag_location', true, QT_URL); ppqtrans_checkSetting('ignore_file_types', true, QT_STRING); ppqtrans_checkSetting('detect_browser_language', true, QT_BOOLEAN); ppqtrans_checkSetting('hide_untranslated', true, QT_BOOLEAN); ppqtrans_checkSetting('use_strftime', true, QT_INTEGER); ppqtrans_checkSetting('url_mode', true, QT_INTEGER); ppqtrans_checkSetting('auto_update_mo', true, QT_BOOLEAN); ppqtrans_checkSetting('hide_default_language', true, QT_BOOLEAN); if (isset($_POST['update_mo_now']) && $_POST['update_mo_now'] == '1' && ppqtrans_updateGettextDatabases(true)) { $message = __('Gettext databases updated.', 'qtranslate'); } } if (isset($_POST['original_lang'])) { // validate form input if ($_POST['language_na_message'] == '') { $error = __('The Language must have a Not-Available Message!', 'qtranslate'); } if (strlen($_POST['language_locale']) < 2) { $error = __('The Language must have a Locale!', 'qtranslate'); } if ($_POST['language_name'] == '') { $error = __('The Language must have a name!', 'qtranslate'); } if (strlen($_POST['language_code']) != 2) { $error = __('Language Code has to be 2 characters long!', 'qtranslate'); } if ($_POST['original_lang'] == '' && $error == '') { // new language if (isset($q_config['language_name'][$_POST['language_code']])) { $error = __('There is already a language with the same Language Code!', 'qtranslate'); } } if ($_POST['original_lang'] != '' && $error == '') { // language update if ($_POST['language_code'] != $_POST['original_lang'] && isset($q_config['language_name'][$_POST['language_code']])) { $error = __('There is already a language with the same Language Code!', 'qtranslate'); } else { // remove old language unset($q_config['language_name'][$_POST['original_lang']]); unset($q_config['flag'][$_POST['original_lang']]); unset($q_config['locale'][$_POST['original_lang']]); unset($q_config['date_format'][$_POST['original_lang']]); unset($q_config['time_format'][$_POST['original_lang']]); unset($q_config['not_available'][$_POST['original_lang']]); if (in_array($_POST['original_lang'], $q_config['enabled_languages'])) { // was enabled, so set modified one to enabled too for ($i = 0; $i < sizeof($q_config['enabled_languages']); $i++) { if ($q_config['enabled_languages'][$i] == $_POST['original_lang']) { $q_config['enabled_languages'][$i] = $_POST['language_code']; } } } if ($_POST['original_lang'] == $q_config['default_language']) { // was default, so set modified the default $q_config['default_language'] = $_POST['language_code']; } } } if (get_magic_quotes_gpc()) { if (isset($_POST['language_date_format'])) { $_POST['language_date_format'] = stripslashes($_POST['language_date_format']); } if (isset($_POST['language_time_format'])) { $_POST['language_time_format'] = stripslashes($_POST['language_time_format']); } } if ($error == '') { // everything is fine, insert language $q_config['language_name'][$_POST['language_code']] = $_POST['language_name']; $q_config['flag'][$_POST['language_code']] = $_POST['language_flag']; $q_config['locale'][$_POST['language_code']] = $_POST['language_locale']; $q_config['date_format'][$_POST['language_code']] = $_POST['language_date_format']; $q_config['time_format'][$_POST['language_code']] = $_POST['language_time_format']; $q_config['not_available'][$_POST['language_code']] = $_POST['language_na_message']; } if ($error != '' || isset($_GET['edit'])) { // get old values in the form $original_lang = $_POST['original_lang']; $language_code = $_POST['language_code']; $language_name = $_POST['language_name']; $language_locale = $_POST['language_locale']; $language_date_format = $_POST['language_date_format']; $language_time_format = $_POST['language_time_format']; $language_na_message = $_POST['language_na_message']; $language_flag = $_POST['language_flag']; $language_default = $_POST['language_default']; } } elseif (isset($_GET['convert'])) { // update language tags global $wpdb; $wpdb->show_errors(); foreach ($q_config['enabled_languages'] as $lang) { $wpdb->query('UPDATE ' . $wpdb->posts . ' set post_title = REPLACE(post_title, "[lang_' . $lang . ']","<!--:' . $lang . '-->")'); $wpdb->query('UPDATE ' . $wpdb->posts . ' set post_title = REPLACE(post_title, "[/lang_' . $lang . ']","<!--:-->")'); $wpdb->query('UPDATE ' . $wpdb->posts . ' set post_content = REPLACE(post_content, "[lang_' . $lang . ']","<!--:' . $lang . '-->")'); $wpdb->query('UPDATE ' . $wpdb->posts . ' set post_content = REPLACE(post_content, "[/lang_' . $lang . ']","<!--:-->")'); } $message = "Database Update successful!"; } elseif (isset($_GET['markdefault'])) { // update language tags global $wpdb; $wpdb->show_errors(); $result = $wpdb->get_results('SELECT ID, post_title, post_content FROM ' . $wpdb->posts . ' WHERE NOT (post_content LIKE "%<!--:-->%" OR post_title LIKE "%<!--:-->%")'); foreach ($result as $post) { $content = ppqtrans_split($post->post_content); $title = ppqtrans_split($post->post_title); foreach ($q_config['enabled_languages'] as $language) { if ($language != $q_config['default_language']) { $content[$language] = ""; $title[$language] = ""; } } $content = ppqtrans_join($content); $title = ppqtrans_join($title); $wpdb->query('UPDATE ' . $wpdb->posts . ' set post_content = "' . mysql_escape_string($content) . '", post_title = "' . mysql_escape_string($title) . '" WHERE ID=' . $post->ID); } $message = "All Posts marked as default language!"; } elseif (isset($_GET['edit'])) { $original_lang = $_GET['edit']; $language_code = $_GET['edit']; $language_name = $q_config['language_name'][$_GET['edit']]; $language_locale = $q_config['locale'][$_GET['edit']]; $language_date_format = $q_config['date_format'][$_GET['edit']]; $language_time_format = $q_config['time_format'][$_GET['edit']]; $language_na_message = $q_config['not_available'][$_GET['edit']]; $language_flag = $q_config['flag'][$_GET['edit']]; } elseif (isset($_GET['delete'])) { // validate delete (protect code) if ($q_config['default_language'] == $_GET['delete']) { $error = 'Cannot delete Default Language!'; } if (!isset($q_config['language_name'][$_GET['delete']]) || strtolower($_GET['delete']) == 'code') { $error = 'No such language!'; } if ($error == '') { // everything seems fine, delete language ppqtrans_disableLanguage($_GET['delete']); unset($q_config['language_name'][$_GET['delete']]); unset($q_config['flag'][$_GET['delete']]); unset($q_config['locale'][$_GET['delete']]); unset($q_config['date_format'][$_GET['delete']]); unset($q_config['time_format'][$_GET['delete']]); unset($q_config['not_available'][$_GET['delete']]); } } elseif (isset($_GET['enable'])) { // enable validate if (!ppqtrans_enableLanguage($_GET['enable'])) { $error = __('Language is already enabled or invalid!', 'qtranslate'); } } elseif (isset($_GET['disable'])) { // enable validate if ($_GET['disable'] == $q_config['default_language']) { $error = __('Cannot disable Default Language!', 'qtranslate'); } if (!ppqtrans_isEnabled($_GET['disable'])) { if (!isset($q_config['language_name'][$_GET['disable']])) { $error = __('No such language!', 'qtranslate'); } } // everything seems fine, disable language if ($error == '' && !ppqtrans_disableLanguage($_GET['disable'])) { $error = __('Language is already disabled!', 'qtranslate'); } } elseif (isset($_GET['moveup'])) { $languages = ppqtrans_getSortedLanguages(); $message = __('No such language!', 'qtranslate'); foreach ($languages as $key => $language) { if ($language == $_GET['moveup']) { if ($key == 0) { $message = __('Language is already first!', 'qtranslate'); break; } $languages[$key] = $languages[$key - 1]; $languages[$key - 1] = $language; $q_config['enabled_languages'] = $languages; $message = __('New order saved.', 'qtranslate'); break; } } } elseif (isset($_GET['movedown'])) { $languages = ppqtrans_getSortedLanguages(); $message = __('No such language!', 'qtranslate'); foreach ($languages as $key => $language) { if ($language == $_GET['movedown']) { if ($key == sizeof($languages) - 1) { $message = __('Language is already last!', 'qtranslate'); break; } $languages[$key] = $languages[$key + 1]; $languages[$key + 1] = $language; $q_config['enabled_languages'] = $languages; $message = __('New order saved.', 'qtranslate'); break; } } } $everything_fine = (isset($_POST['submit']) || isset($_GET['delete']) || isset($_GET['enable']) || isset($_GET['disable']) || isset($_GET['moveup']) || isset($_GET['movedown'])) && $error == ''; if ($everything_fine) { // settings might have changed, so save ppqtrans_saveConfig(); if (empty($message)) { $message = __('Options saved.', 'qtranslate'); } } if ($q_config['auto_update_mo']) { if (!is_dir(WP_LANG_DIR) || !($ll = @fopen(trailingslashit(WP_LANG_DIR) . 'qtranslate.test', 'a'))) { $error = sprintf(__('Could not write to "%s", Gettext Databases could not be downloaded!', 'qtranslate'), WP_LANG_DIR); } else { @fclose($ll); @unlink(trailingslashit(WP_LANG_DIR) . 'qtranslate.test'); } } // don't accidently delete/enable/disable twice $clean_uri = preg_replace("/&(delete|enable|disable|convert|markdefault|moveup|movedown)=[^&#]*/i", "", $_SERVER['REQUEST_URI']); $clean_uri = apply_filters('ppqtranslate_clean_uri', $clean_uri); // Generate XHTML if ($message) { ?> <div id="message" class="updated fade"><p><strong><?php echo $message; ?> </strong></p></div> <?php } if ($error != '') { ?> <div id="message" class="error fade"><p><strong><?php echo $error; ?> </strong></p></div> <?php } ?> <?php if (isset($_GET['edit'])) { ?> <div class="wrap"> <h2><?php _e('Edit Language', 'qtranslate'); ?> </h2> <form action="" method="post" id="qtranslate-edit-language"> <?php ppqtranslate_language_form($language_code, $language_code, $language_name, $language_locale, $language_date_format, $language_time_format, $language_flag, $language_na_message, $language_default, $original_lang); ?> <p class="submit"><input type="submit" name="submit" value="<?php _e('Save Changes »', 'qtranslate'); ?> " /></p> </form> </div> <?php } else { ?> <div class="wrap"> <h2><?php _e('Language Management (qTranslate Configuration)', 'qtranslate'); ?> </h2> <div class="tablenav"><?php printf(__('For help on how to configure qTranslate correctly, take a look at the <a href="%1$s">qTranslate FAQ</a> and the <a href="%2$s">Support Forum</a>.', 'qtranslate'), 'http://www.qianqin.de/qtranslate/faq/', 'http://www.qianqin.de/qtranslate/forum/viewforum.php?f=3'); ?> </div> <form action="<?php echo $clean_uri; ?> " method="post"> <h3><?php _e('General Settings', 'qtranslate'); ?> </h3> <table class="form-table"> <tr> <th scope="row"><?php _e('Default Language / Order', 'qtranslate'); ?> </th> <td> <fieldset><legend class="hidden"><?php _e('Default Language', 'qtranslate'); ?> </legend> <?php foreach (ppqtrans_getSortedLanguages() as $key => $language) { echo "\t<label title='" . $q_config['language_name'][$language] . "'><input type='radio' name='default_language' value='" . $language . "'"; if ($language == $q_config['default_language']) { echo " checked='checked'"; } echo ' />'; echo ' <a href="' . add_query_arg('moveup', $language, $clean_uri) . '"><img src="' . WP_PLUGIN_URL . '/' . basename(__DIR__) . '/arrowup.png" alt="up" /></a>'; echo ' <a href="' . add_query_arg('movedown', $language, $clean_uri) . '"><img src="' . WP_PLUGIN_URL . '/' . basename(__DIR__) . '/arrowdown.png" alt="down" /></a>'; echo ' <img src="' . trailingslashit(WP_CONTENT_URL) . $q_config['flag_location'] . $q_config['flag'][$language] . '" alt="' . $q_config['language_name'][$language] . '" /> '; echo ' ' . $q_config['language_name'][$language] . "</label><br />\n"; } ?> </br> <?php printf(__('Choose the default language of your blog. This is the language which will be shown on %s. You can also change the order the languages by clicking on the arrows above.', 'qtranslate'), get_bloginfo('url')); ?> </fieldset> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Hide Untranslated Content', 'qtranslate'); ?> </th> <td> <label for="hide_untranslated"><input type="checkbox" name="hide_untranslated" id="hide_untranslated" value="1"<?php echo $q_config['hide_untranslated'] ? ' checked="checked"' : ''; ?> /> <?php _e('Hide Content which is not available for the selected language.', 'qtranslate'); ?> </label> <br/> <?php _e('When checked, posts will be hidden if the content is not available for the selected language. If unchecked, a message will appear showing all the languages the content is available in.', 'qtranslate'); ?> <?php _e('This function will not work correctly if you installed qTranslate on a blog with existing entries. In this case you will need to take a look at "Convert Database" under "Advanced Settings".', 'qtranslate'); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Detect Browser Language', 'qtranslate'); ?> </th> <td> <label for="detect_browser_language"><input type="checkbox" name="detect_browser_language" id="detect_browser_language" value="1"<?php echo $q_config['detect_browser_language'] ? ' checked="checked"' : ''; ?> /> <?php _e('Detect the language of the browser and redirect accordingly.', 'qtranslate'); ?> </label> <br/> <?php _e('When the frontpage is visited via bookmark/external link/type-in, the visitor will be forwarded to the correct URL for the language specified by his browser.', 'qtranslate'); ?> </td> </tr> </table> <h3><?php _e('Advanced Settings', 'qtranslate'); ?> <span id="qtranslate-show-advanced" style="display:none"> (<a name="advanced_settings" href="#advanced_settings" onclick="showAdvanced();"><?php _e('Show', 'qtranslate'); ?> </a>)</span></h3> <table class="form-table" id="qtranslate-advanced"> <tr> <th scope="row"><?php _e('URL Modification Mode', 'qtranslate'); ?> </th> <td> <fieldset><legend class="hidden"><?php _e('URL Modification Mode', 'qtranslate'); ?> </legend> <label title="Query Mode"><input type="radio" name="url_mode" value="<?php echo QT_URL_QUERY; ?> " <?php echo $q_config['url_mode'] == QT_URL_QUERY ? "checked=\"checked\"" : ""; ?> /> <?php _e('Use Query Mode (?lang=en)', 'qtranslate'); ?> </label><br /> <label title="Pre-Path Mode"><input type="radio" name="url_mode" value="<?php echo QT_URL_PATH; ?> " <?php echo $q_config['url_mode'] == QT_URL_PATH ? "checked=\"checked\"" : ""; ?> /> <?php _e('Use Pre-Path Mode (Default, puts /en/ in front of URL)', 'qtranslate'); ?> </label><br /> <label title="Pre-Domain Mode"><input type="radio" name="url_mode" value="<?php echo QT_URL_DOMAIN; ?> " <?php echo $q_config['url_mode'] == QT_URL_DOMAIN ? "checked=\"checked\"" : ""; ?> /> <?php _e('Use Pre-Domain Mode (uses http://en.yoursite.com)', 'qtranslate'); ?> </label><br /> </fieldset><br/> <?php _e('Pre-Path and Pre-Domain mode will only work with mod_rewrite/pretty permalinks. Additional Configuration is needed for Pre-Domain mode!', 'qtranslate'); ?> <br/> <label for="hide_default_language"><input type="checkbox" name="hide_default_language" id="hide_default_language" value="1"<?php echo $q_config['hide_default_language'] ? ' checked="checked"' : ''; ?> /> <?php _e('Hide URL language information for default language.', 'qtranslate'); ?> </label> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Flag Image Path', 'qtranslate'); ?> </th> <td> <?php echo trailingslashit(WP_CONTENT_URL); ?> <input type="text" name="flag_location" id="flag_location" value="<?php echo $q_config['flag_location']; ?> " style="width:50%"/> <br/> <?php _e('Path to the flag images under wp-content, with trailing slash. (Default: plugins/qtranslate/flags/)', 'qtranslate'); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Ignore Links', 'qtranslate'); ?> </th> <td> <input type="text" name="ignore_file_types" id="ignore_file_types" value="<?php echo $q_config['ignore_file_types']; ?> " style="width:100%"/> <br/> <?php _e('Don\'t convert Links to files of the given file types. (Default: gif,jpg,jpeg,png,pdf,swf,tif,rar,zip,7z,mpg,divx,mpeg,avi,css,js)', 'qtranslate'); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Update Gettext Databases', 'qtranslate'); ?> </th> <td> <label for="auto_update_mo"><input type="checkbox" name="auto_update_mo" id="auto_update_mo" value="1"<?php echo $q_config['auto_update_mo'] ? ' checked="checked"' : ''; ?> /> <?php _e('Automatically check for .mo-Database Updates of installed languages.', 'qtranslate'); ?> </label> <br/> <label for="update_mo_now"><input type="checkbox" name="update_mo_now" id="update_mo_now" value="1" /> <?php _e('Update Gettext databases now.', 'qtranslate'); ?> </label> <br/> <?php _e('qTranslate will query the Wordpress Localisation Repository every week and download the latest Gettext Databases (.mo Files).', 'qtranslate'); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Date / Time Conversion', 'qtranslate'); ?> </th> <td> <label><input type="radio" name="use_strftime" value="<?php echo QT_DATE; ?> " <?php echo $q_config['use_strftime'] == QT_DATE ? ' checked="checked"' : ''; ?> /> <?php _e('Use emulated date function.', 'qtranslate'); ?> </label><br /> <label><input type="radio" name="use_strftime" value="<?php echo QT_DATE_OVERRIDE; ?> " <?php echo $q_config['use_strftime'] == QT_DATE_OVERRIDE ? ' checked="checked"' : ''; ?> /> <?php _e('Use emulated date function and replace formats with the predefined formats for each language.', 'qtranslate'); ?> </label><br /> <label><input type="radio" name="use_strftime" value="<?php echo QT_STRFTIME; ?> " <?php echo $q_config['use_strftime'] == QT_STRFTIME ? ' checked="checked"' : ''; ?> /> <?php _e('Use strftime instead of date.', 'qtranslate'); ?> </label><br /> <label><input type="radio" name="use_strftime" value="<?php echo QT_STRFTIME_OVERRIDE; ?> " <?php echo $q_config['use_strftime'] == QT_STRFTIME_OVERRIDE ? ' checked="checked"' : ''; ?> /> <?php _e('Use strftime instead of date and replace formats with the predefined formats for each language.', 'qtranslate'); ?> </label><br /> <?php _e('Depending on the mode selected, additional customizations of the theme may be needed.', 'qtranslate'); ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Reset qTranslate', 'qtranslate'); ?> </th> <td> <label for="ppqtranslate_reset"><input type="checkbox" name="ppqtranslate_reset" id="ppqtranslate_reset" value="1"/> <?php _e('Check this box and click Save Changes to reset all qTranslate settings.', 'qtranslate'); ?> </label> <br/> <label for="ppqtranslate_reset2"><input type="checkbox" name="ppqtranslate_reset2" id="ppqtranslate_reset2" value="1"/> <?php _e('Yes, I really want to reset qTranslate.', 'qtranslate'); ?> </label> <br/> <label for="ppqtranslate_reset3"><input type="checkbox" name="ppqtranslate_reset3" id="ppqtranslate_reset3" value="1"/> <?php _e('Also delete Translations for Categories/Tags/Link Categories.', 'qtranslate'); ?> </label> <br/> <?php _e('If something isn\'t working correctly, you can always try to reset all qTranslate settings. A Reset won\'t delete any posts but will remove all settings (including all languages added).', 'qtranslate'); ?> </td> </tr> <tr> <th scope="row"><?php _e('Convert Database', 'qtranslate'); ?> </th> <td> <?php printf(__('If you are updating from qTranslate 1.x or Polyglot, <a href="%s">click here</a> to convert posts to the new language tag format.', 'qtranslate'), $clean_uri . '&convert=true'); ?> <?php printf(__('If you have installed qTranslate for the first time on a Wordpress with existing posts, you can either go through all your posts manually and save them in the correct language or <a href="%s">click here</a> to mark all existing posts as written in the default language.', 'qtranslate'), $clean_uri . '&markdefault=true'); ?> <?php _e('Both processes are <b>irreversible</b>! Be sure to make a full database backup before clicking one of the links.', 'qtranslate'); ?> </td> </tr> <tr> <th scope="row"><?php _e('Debugging Information', 'qtranslate'); ?> </th> <td> <p><?php printf(__('If you encounter any problems and you are unable to solve them yourself, you can visit the <a href="%s">Support Forum</a>. Posting the following Content will help other detect any misconfigurations.', 'qtranslate'), 'http://www.qianqin.de/qtranslate/forum/'); ?> </p> <textarea readonly="readonly" id="ppqtranslate_debug"><?php $q_config_copy = $q_config; // remove information to keep data anonymous and other not needed things unset($q_config_copy['url_info']); unset($q_config_copy['js']); unset($q_config_copy['windows_locale']); unset($q_config_copy['pre_domain']); unset($q_config_copy['term_name']); echo htmlspecialchars(print_r($q_config_copy, true)); ?> </textarea> </td> </tr> </table> <script type="text/javascript"> // <![CDATA[ function showAdvanced() { document.getElementById('qtranslate-advanced').style.display='block'; document.getElementById('qtranslate-show-advanced').style.display='none'; return false; } if(location.hash!='#advanced_settings') { document.getElementById('qtranslate-show-advanced').style.display='inline'; document.getElementById('qtranslate-advanced').style.display='none'; } // ]]> </script> <?php do_action('ppqtranslate_configuration', $clean_uri); ?> <p class="submit"> <input type="submit" name="submit" class="button-primary" value="<?php _e('Save Changes', 'qtranslate'); ?> " /> </p> </form> </div> <div class="wrap"> <h2><?php _e('Languages', 'qtranslate'); ?> </h2> <div id="col-container"> <div id="col-right"> <div class="col-wrap"> <table class="widefat"> <thead> <tr> <?php print_column_headers('language'); ?> </tr> </thead> <tfoot> <tr> <?php print_column_headers('language', false); ?> </tr> </tfoot> <tbody id="the-list" class="list:cat"> <?php foreach ($q_config['language_name'] as $lang => $language) { if ($lang != 'code') { ?> <tr> <td><img src="<?php echo trailingslashit(WP_CONTENT_URL) . $q_config['flag_location'] . $q_config['flag'][$lang]; ?> " alt="<?php echo $language; ?> Flag"></td> <td><?php echo $language; ?> </td> <td><?php if (in_array($lang, $q_config['enabled_languages'])) { ?> <a class="edit" href="<?php echo $clean_uri; ?> &disable=<?php echo $lang; ?> "><?php _e('Disable', 'qtranslate'); ?> </a><?php } else { ?> <a class="edit" href="<?php echo $clean_uri; ?> &enable=<?php echo $lang; ?> "><?php _e('Enable', 'qtranslate'); ?> </a><?php } ?> </td> <td><a class="edit" href="<?php echo $clean_uri; ?> &edit=<?php echo $lang; ?> "><?php _e('Edit', 'qtranslate'); ?> </a></td> <td><?php if ($q_config['default_language'] == $lang) { _e('Default', 'qtranslate'); } else { ?> <a class="delete" href="<?php echo $clean_uri; ?> &delete=<?php echo $lang; ?> "><?php _e('Delete', 'qtranslate'); ?> </a><?php } ?> </td> </tr> <?php } } ?> </tbody> </table> <p><?php _e('Enabling a language will cause qTranslate to update the Gettext-Database for the language, which can take a while depending on your server\'s connection speed.', 'qtranslate'); ?> </p> </div> </div><!-- /col-right --> <div id="col-left"> <div class="col-wrap"> <div class="form-wrap"> <h3><?php _e('Add Language', 'qtranslate'); ?> </h3> <form name="addcat" id="addcat" method="post" class="add:the-list: validate"> <?php ppqtranslate_language_form($language_code, $language_code, $language_name, $language_locale, $language_date_format, $language_time_format, $language_flag, $language_default, $language_na_message); ?> <p class="submit"><input type="submit" name="submit" value="<?php _e('Add Language »', 'qtranslate'); ?> " /></p> </form></div> </div> </div><!-- /col-left --> </div><!-- /col-container --> <?php } }
function ppqtrans_modifyExcerpt() { global $q_config; echo "<script type=\"text/javascript\">\n// <![CDATA[\n"; echo "if(jQuery('#excerpt').size()>0) {"; echo $q_config['js']['ppqtrans_is_array']; echo $q_config['js']['ppqtrans_xsplit']; echo $q_config['js']['ppqtrans_split']; echo $q_config['js']['ppqtrans_integrate']; echo $q_config['js']['ppqtrans_switch_postbox']; echo $q_config['js']['ppqtrans_use']; $el = ppqtrans_getSortedLanguages(); foreach ($el as $language) { echo ppqtrans_createTitlebarButton('postexcerpt', $language, 'excerpt', 'ppqtrans_switcher_postexcerpt_' . $language); echo ppqtrans_createTextArea('postexcerpt', $language, 'excerpt', 'ppqtrans_switcher_postexcerpt_' . $language); } echo "ppqtrans_switch_postbox('postexcerpt','excerpt','" . $q_config['default_language'] . "', false);"; echo "jQuery('#excerpt').hide();"; echo "}"; echo "// ]]>\n</script>\n"; }