本文整理汇总了PHP中qtranxf_isEnabled函数的典型用法代码示例。如果您正苦于以下问题:PHP qtranxf_isEnabled函数的具体用法?PHP qtranxf_isEnabled怎么用?PHP qtranxf_isEnabled使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qtranxf_isEnabled函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: qtranxf_slug_update_translations
/**
* @param (string) $name - urldecoded post name or other single slug (not a path with '/').
*/
function qtranxf_slug_update_translations($name, &$qfields, $default_lang)
{
global $q_config, $wpdb;
if (empty($name)) {
return;
}
//qtranxf_dbg_log('qtranxf_slug_update_translations: $name="'.$name.'", $qfields: ', $qfields);
if (isset($qfields['qtranslate-original-value'])) {
if ($qfields['qtranslate-original-value'] != $name) {
qtranxf_slug_del_translations(qtranxf_slug_encode($qfields['qtranslate-original-value']));
}
unset($qfields['qtranslate-original-value']);
}
unset($qfields[$default_lang]);
//use $post->post_name instead since it may have been adjusted by WP
$name = qtranxf_slug_encode($name);
//qtranxf_dbg_log('qtranxf_slug_update_translations: encoded $name: ', $name);
if (qtranxf_slug_translate_name($name, $default_lang)) {
qtranxf_slug_del_translation($default_lang, $name);
}
//$translations = qtranxf_slug_get_translations($name);
foreach ($qfields as $lang => $slug) {
$translation = qtranxf_slug_translate_name($name, $lang);
$slug = qtranxf_slug_encode($slug);
//qtranxf_dbg_log('qtranxf_slug_update_translations: origin $slug: ', $slug);
if ($name == $slug) {
if ($translation) {
qtranxf_slug_del_translation($lang, $name);
}
continue;
}
$slug = qtranxf_slug_unique($slug, $lang, $name);
//qtranxf_dbg_log('qtranxf_slug_update_translations: unique $slug: ',$slug);
if ($translation) {
$sql = 'UPDATE ' . $wpdb->prefix . 'i18n_slugs SET slug = %s WHERE lang = %s AND name = %s';
} else {
$sql = 'INSERT INTO ' . $wpdb->prefix . 'i18n_slugs (slug, lang, name) VALUES (%s, %s, %s)';
}
$query = $wpdb->prepare($sql, $slug, $lang, $name);
$wpdb->query($query);
if (!isset($q_config['slugs-cache']['names'][$name])) {
$q_config['slugs-cache']['names'][$name] = array();
}
$q_config['slugs-cache']['names'][$name][$lang] = $slug;
}
//cleanup in case a language was disabled
$slugs = qtranxf_slug_get_translations($name);
foreach ($slugs as $lang => $slug) {
if (qtranxf_isEnabled($lang)) {
continue;
}
qtranxf_slug_del_translation($lang, $name);
}
}
示例2: qtranxf_updateGettextDatabasesEx
/**
* return 'true', if no update needed,
* or 'false', if update is impossible to do,
* or 0, if all languages were updated successfully,
* or positive integer number of errors occurred on languages update.
*/
function qtranxf_updateGettextDatabasesEx($force = false, $only_for_language = '')
{
global $q_config;
if ($only_for_language && !qtranxf_isEnabled($only_for_language)) {
return false;
}
if (!is_dir(WP_LANG_DIR)) {
if (!@mkdir(WP_LANG_DIR)) {
return false;
}
}
$next_update = get_option('qtranslate_next_update_mo');
if (time() < $next_update && !$force) {
return true;
}
update_option('qtranslate_next_update_mo', time() + 7 * 24 * 60 * 60);
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
include ABSPATH . WPINC . '/version.php';
// include an unmodified $wp_version
$result = translations_api('core', array('version' => $wp_version));
if (is_wp_error($result)) {
qtranxf_add_error(__('Gettext databases <strong>not</strong> updated:', 'qtranslate') . ' ' . $result->get_error_message());
return false;
}
set_time_limit(300);
$langs = empty($only_for_language) ? $q_config['enabled_languages'] : array($only_for_language);
$errcnt = 0;
foreach ($result['translations'] as $translation) {
$locale = $translation['language'];
$lang = null;
foreach ($langs as $lng) {
if ($q_config['locale'][$lng] != $locale) {
continue;
}
$lang = $lng;
break;
}
if (!$lang) {
continue;
}
$translation = (object) $translation;
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Language_Pack_Upgrader($skin);
$translation->type = 'core';
$result = $upgrader->upgrade($translation, array('clear_update_cache' => false));
if (is_wp_error($result)) {
qtranxf_add_error(sprintf(__('Failed to update gettext database for "%s": %s', 'qtranslate'), $q_config['language_name'][$lang], $result->get_error_message()));
++$errcnt;
}
}
return $errcnt;
}
示例3: qtranxf_enableLanguage
function qtranxf_enableLanguage($lang)
{
global $q_config;
if (qtranxf_isEnabled($lang)) {
// || !isset($q_config['language_name'][$lang]))
return false;
}
$q_config['enabled_languages'][] = $lang;
// force update of .mo files
if ($q_config['auto_update_mo']) {
qtranxf_updateGettextDatabases(true, $lang);
}
qtranxf_load_languages_enabled();
return true;
}
示例4: qtranxf_updateGettextDatabasesEx
function qtranxf_updateGettextDatabasesEx($force = false, $only_for_language = '')
{
global $q_config;
if ($only_for_language && !qtranxf_isEnabled($only_for_language)) {
return false;
}
if (!is_dir(WP_LANG_DIR)) {
if (!@mkdir(WP_LANG_DIR)) {
return false;
}
}
$next_update = get_option('qtranslate_next_update_mo');
if (time() < $next_update && !$force) {
return true;
}
update_option('qtranslate_next_update_mo', time() + 7 * 24 * 60 * 60);
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
include ABSPATH . WPINC . '/version.php';
// include an unmodified $wp_version
$result = translations_api('core', array('version' => $wp_version));
if (is_wp_error($result)) {
return $result;
} else {
foreach ($result['translations'] as $translation) {
$locale = substr($translation['language'], 0, 2);
if (isset($q_config['locale'][$locale]) && $q_config['locale'][$locale] == $translation['language'] && qtranxf_isEnabled($locale)) {
$translation = (object) $translation;
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Language_Pack_Upgrader($skin);
$translation->type = 'core';
$result = $upgrader->upgrade($translation, array('clear_update_cache' => false));
}
}
return true;
}
}
示例5: qtranxf_convertURL
/**
* Encode URL $url with language $lang.
* @param (string) $url URL to be converted.
* @param (string) $lang two-letter language code of the language to convert $url to.
* @param (bool) $forceadmin $url is not converted on admin side, unless $forceadmin is set to true.
* @param (bool) $showDefaultLanguage When set to true, $url is always encoded with a language, otherwise it senses option "Hide URL language information for default language" to keep $url consistent with the currently active language.
*
* If you need a URL to switch the language, set $showDefaultLanguage=true, if you need a URL to keep the current language, set it to false.
*/
function qtranxf_convertURL($url = '', $lang = '', $forceadmin = false, $showDefaultLanguage = false)
{
global $q_config;
if (empty($lang)) {
$lang = $q_config['language'];
}
if (empty($url)) {
if ($q_config['url_info']['doing_front_end'] && defined('QTS_VERSION') && $q_config['url_mode'] != QTX_URL_QUERY) {
//quick workaround, but need a permanent solution
$url = qts_get_url($lang);
//qtranxf_dbg_log('qtranxf_convertURL: qts_get_url: url=', $url);
if (!empty($url)) {
if ($showDefaultLanguage && $q_config['hide_default_language'] && $lang == $q_config['default_language']) {
$url = qtranxf_convertURL($url, $lang, $forceadmin, true);
}
return $url;
}
}
//$url = esc_url($q_config['url_info']['url']);
}
if (!$q_config['url_info']['doing_front_end'] && !$forceadmin) {
return $url;
}
if (!qtranxf_isEnabled($lang)) {
return '';
}
if (!$showDefaultLanguage) {
$showDefaultLanguage = !$q_config['hide_default_language'];
}
$showLanguage = $showDefaultLanguage || $lang != $q_config['default_language'];
//qtranxf_dbg_log('qtranxf_convertURL('.$url.','.$lang.'): showLanguage=',$showLanguage);
$complete = qtranxf_get_url_for_language($url, $lang, $showLanguage);
//qtranxf_dbg_log('qtranxf_convertURL: complete: ',$complete);
return $complete;
}
示例6: qtranxf_conf
//.........这里部分代码省略.........
$lang = $_GET['edit'];
$original_lang = $lang;
$language_code = $lang;
//$langs = $q_config;
$langs = array();
qtranxf_languages_configured($langs);
$language_name = isset($langs['language_name'][$lang]) ? $langs['language_name'][$lang] : '';
$language_locale = isset($langs['locale'][$lang]) ? $langs['locale'][$lang] : '';
$language_date_format = isset($langs['date_format'][$lang]) ? $langs['date_format'][$lang] : '';
$language_time_format = isset($langs['time_format'][$lang]) ? $langs['time_format'][$lang] : '';
$language_na_message = isset($langs['not_available'][$lang]) ? $langs['not_available'][$lang] : '';
$language_flag = isset($langs['flag'][$lang]) ? $langs['flag'][$lang] : '';
} elseif (isset($_GET['delete'])) {
$lang = $_GET['delete'];
// validate delete (protect code)
//if($q_config['default_language']==$lang) $error = 'Cannot delete Default Language!';
//if(!isset($q_config['language_name'][$lang])||strtolower($lang)=='code') $error = __('No such language!', 'qtranslate');
if (empty($error)) {
// everything seems fine, delete language
$error = qtranxf_deleteLanguage($lang);
}
} elseif (isset($_GET['enable'])) {
$lang = $_GET['enable'];
// enable validate
if (!qtranxf_enableLanguage($lang)) {
$error = __('Language is already enabled or invalid!', 'qtranslate');
}
} elseif (isset($_GET['disable'])) {
$lang = $_GET['disable'];
// enable validate
if ($lang == $q_config['default_language']) {
$error = __('Cannot disable Default Language!', 'qtranslate');
}
if (!qtranxf_isEnabled($lang)) {
if (!isset($q_config['language_name'][$lang])) {
$error = __('No such language!', 'qtranslate');
}
}
// everything seems fine, disable language
if ($error == '' && !qtranxf_disableLanguage($lang)) {
$error = __('Language is already disabled!', 'qtranslate');
}
} elseif (isset($_GET['moveup'])) {
$languages = qtranxf_getSortedLanguages();
$msg = __('No such language!', 'qtranslate');
foreach ($languages as $key => $language) {
if ($language != $_GET['moveup']) {
continue;
}
if ($key == 0) {
$msg = __('Language is already first!', 'qtranslate');
break;
}
$languages[$key] = $languages[$key - 1];
$languages[$key - 1] = $language;
$q_config['enabled_languages'] = $languages;
$msg = __('New order saved.', 'qtranslate');
break;
}
$message[] = $msg;
} elseif (isset($_GET['movedown'])) {
$languages = qtranxf_getSortedLanguages();
$msg = __('No such language!', 'qtranslate');
foreach ($languages as $key => $language) {
if ($language != $_GET['movedown']) {
continue;
示例7: qtranxf_use_block
function qtranxf_use_block($lang, $blocks, $show_available = false, $show_empty = false)
{
global $q_config;
$available_langs = array();
//$content = qtranxf_split_blocks($blocks);
$content = qtranxf_split_blocks($blocks, $available_langs);
//qtranxf_dbg_log('qtranxf_use_block: $available_langs: ',$available_langs);
// if content is available show the content in the requested language
//if(!empty($content[$lang])) return $content[$lang];
if (!empty($available_langs[$lang])) {
return $content[$lang];
} elseif ($show_empty) {
return '';
}
// content is not available in requested language (bad!!) what now?
// find available and alternative languages
//if(empty($content[$q_config['default_language']])){
if (empty($available_langs[$q_config['default_language']])) {
$alt_lang = null;
$alt_content = null;
$alt_lang_is_default = false;
foreach ($available_langs as $language => $b) {
if (!qtranxf_isEnabled($language)) {
continue;
}
$alt_lang = $language;
$alt_content = $content[$language];
break;
}
} else {
$alt_lang = $q_config['default_language'];
$alt_content = $content[$alt_lang];
$alt_lang_is_default = true;
}
/*
$available_languages = array();
foreach($content as $language => $lang_text) {
if(empty($lang_text)) continue;
if(!qtranxf_isEnabled($language)) continue;
$available_languages[] = $language;
if(empty($alt_lang)){
$alt_lang = $language;
$alt_content = $lang_text;
}
}
*/
if (!$alt_lang) {
return '';
}
if (!$show_available) {
if ($q_config['show_displayed_language_prefix']) {
return '(' . $q_config['language_name'][$alt_lang] . ') ' . $alt_content;
} else {
return $alt_content;
}
}
//qtranxf_dbg_log('$alt_content=',$alt_content);
// display selection for available languages
$language_list = '';
if (preg_match('/%LANG:([^:]*):([^%]*)%/', $q_config['not_available'][$lang], $match)) {
$normal_separator = $match[1];
$end_separator = $match[2];
// build available languages string backward
$translations = get_translations_for_domain('qtranslate');
$english_names = qtranxf_default_windows_locale();
//todo: load enabled only
$i = 0;
//foreach($available_languages as $language) {
foreach ($available_langs as $language => $b) {
if ($i == 1) {
$language_list = $end_separator . $language_list;
} elseif ($i > 1) {
$language_list = $normal_separator . $language_list;
}
if (!empty($english_names[$language]) && isset($translations->entries[$english_names[$language]])) {
$language_name = $translations->entries[$english_names[$language]]->translations[0];
} else {
$language_name = $q_config['language_name'][$language];
}
$language_list = '<a href="' . qtranxf_convertURL('', $language, false, true) . '" class="qtranxs-available-language-link qtranxs-available-language-link-' . $language . '">' . $language_name . '</a>' . $language_list;
++$i;
}
}
//qtranxf_dbg_log('$language_list=',$language_list);
$msg = '';
if (!empty($q_config['show_alternative_content']) && $q_config['show_alternative_content']) {
// show content in alternative language
//if(sizeof($available_languages) > 1){
if (sizeof($available_langs) > 1) {
if ($alt_lang_is_default) {
//$fmt = __('For the sake of viewer convenience, the content is shown below in this site default language %s.', 'qtranslate');
$msg = __('For the sake of viewer convenience, the content is shown below in this site default language.', 'qtranslate');
} else {
//$fmt = __('For the sake of viewer convenience, the content is shown below in an available alternative language %s.', 'qtranslate');
$msg = __('For the sake of viewer convenience, the content is shown below in one of the available alternative languages.', 'qtranslate');
}
//$msg = sprintf($fmt, '<a href="'.qtranxf_convertURL('', $language, false, true).'">'.$q_config['language_name'][$alt_lang].'</a>');
$msg .= ' ' . __('You may click one of the links to switch the site language to another available language.', 'qtranslate');
} else {
$msg = __('For the sake of viewer convenience, the content is shown below in the alternative language.', 'qtranslate');
//.........这里部分代码省略.........
示例8: qtranxf_updateSetting
function qtranxf_updateSetting($var, $type = QTX_STRING, $def = null)
{
global $q_config, $qtranslate_options;
if (!isset($_POST['submit'])) {
return false;
}
if (!isset($_POST[$var]) && $type != QTX_BOOLEAN) {
return false;
}
if (is_null($def) && isset($qtranslate_options['default_value'][$var])) {
$def = $qtranslate_options['default_value'][$var];
}
if (is_string($def) && function_exists($def)) {
$def = call_user_func($def);
}
switch ($type) {
case QTX_URL:
case QTX_LANGUAGE:
case QTX_STRING:
$val = sanitize_text_field($_POST[$var]);
if ($type == QTX_URL) {
$val = trailingslashit($val);
} else {
if ($type == QTX_LANGUAGE && !qtranxf_isEnabled($val)) {
return false;
}
}
if (isset($q_config[$var])) {
if ($q_config[$var] === $val) {
return false;
}
} elseif (!is_null($def)) {
if (empty($val) || $def === $val) {
return false;
}
}
if (empty($val) && $def) {
$val = $def;
}
$q_config[$var] = $val;
qtranxf_update_option($var, $def);
return true;
case QTX_TEXT:
$val = $_POST[$var];
//standardize multi-line string
$lns = preg_split('/\\r?\\n\\r?/', $val);
foreach ($lns as $key => $ln) {
$lns[$key] = sanitize_text_field($ln);
}
$val = implode(PHP_EOL, $lns);
//qtranxf_dbg_log('qtranxf_updateSetting:QTX_TEXT: $_POST[$var]:'.PHP_EOL, $_POST[$var]);
//qtranxf_dbg_log('qtranxf_updateSetting:QTX_TEXT: $val:'.PHP_EOL, $val);
if (isset($q_config[$var])) {
if ($q_config[$var] === $val) {
return false;
}
} elseif (!is_null($def)) {
if (empty($val) || $def === $val) {
return false;
}
}
if (empty($val) && $def) {
$val = $def;
}
$q_config[$var] = $val;
qtranxf_update_option($var, $def);
return true;
case QTX_ARRAY:
$val = $_POST[$var];
if (!is_array($_POST[$var])) {
$val = sanitize_text_field($val);
$val = preg_split('/[\\s,]+/', $val, null, PREG_SPLIT_NO_EMPTY);
}
if (empty($val) && !is_null($def)) {
if (is_string($def)) {
$val = preg_split('/[\\s,]+/', $def, null, PREG_SPLIT_NO_EMPTY);
} else {
if (is_array($def)) {
$val = $def;
}
}
}
if (isset($q_config[$var]) && qtranxf_array_compare($q_config[$var], $val)) {
return false;
}
$q_config[$var] = $val;
qtranxf_update_option($var, $def);
return true;
case QTX_BOOLEAN:
if (isset($_POST[$var]) && $_POST[$var] == 1) {
if ($q_config[$var]) {
return false;
}
$q_config[$var] = true;
} else {
if (!$q_config[$var]) {
return false;
}
$q_config[$var] = false;
}
//.........这里部分代码省略.........
示例9: qtranxf_getLanguageName
function qtranxf_getLanguageName($lang = '')
{
global $q_config;
if ($lang == '' || !qtranxf_isEnabled($lang)) {
$lang = $q_config['language'];
}
return $q_config['language_name'][$lang];
}
示例10: prepare_items
public function prepare_items()
{
global $q_config;
if (isset($_GET['orderby'])) {
$this->_orderby = $_GET['orderby'];
} else {
$this->_orderby = $_GET['orderby'] = 'name';
}
$langs_preset = qtranxf_langs_preset();
$langs_stored = qtranxf_langs_stored($langs_preset);
$langs_config = qtranxf_langs_config($langs_preset, $langs_stored);
$this->_order = isset($_GET['order']) && 'desc' == $_GET['order'] ? -1 : +1;
$flag_location_url = qtranxf_flag_location();
$flag_location_dir = trailingslashit(WP_CONTENT_DIR) . $q_config['flag_location'];
$flag_location_url_def = content_url(qtranxf_flag_location_default());
$clean_uri = $this->_clean_uri;
$data = array();
foreach ($langs_config as $lang => $props) {
$locale = $props['locale'];
$flag = $props['flag'];
//$flags[$lang];
if (file_exists($flag_location_dir . $flag)) {
$flag_url = $flag_location_url . $flag;
} else {
$flag_url = $flag_location_url_def . $flag;
}
$lang_name = $props['language_name'];
//native name
$admin_name = qtranxf_getLanguageName($lang, $locale, $lang_name);
//name translated to admin language
$action = qtranxf_isEnabled($lang) ? $q_config['default_language'] == $lang ? __('Default', 'qtranslate') : __('Disable', 'qtranslate') : __('Enable', 'qtranslate');
$stored = empty($props['stored']) ? __('Pre-Defined', 'qtranslate') : (isset($langs_preset[$lang]) ? __('Reset', 'qtranslate') : __('Delete', 'qtranslate'));
switch ($this->_orderby) {
default:
case 'locale':
$orderby = $locale;
break;
case 'code':
$orderby = $lang;
break;
case 'flag':
$orderby = $lang_name;
break;
case 'name':
$orderby = $admin_name;
break;
case 'action':
$orderby = $action;
break;
case 'stored':
$orderby = $stored;
break;
}
$edit_url = $clean_uri . '&edit=' . $lang;
$atitle = __('Edit', 'qtranslate') . ' ' . $lang_name . ' (' . $locale . ')';
$data[] = array('locale' => $locale, 'code' => $lang, 'flag' => '<a href="' . $edit_url . '" title="' . $atitle . '"><img src="' . $flag_url . '" alt="' . sprintf(__('%s Flag', 'qtranslate'), $lang_name) . '"></a>', 'name' => '<a href="' . $edit_url . '" title="' . $atitle . '">' . $admin_name . '</a>', 'action' => qtranxf_isEnabled($lang) ? $q_config['default_language'] == $lang ? $action : '<a class="edit" href="' . $clean_uri . '&disable=' . $lang . '#languages">' . $action . '</a>' : '<a class="edit" href="' . $clean_uri . '&enable=' . $lang . '#languages">' . $action . '</a>', 'stored' => empty($props['stored']) ? $stored : '<a class="delete" href="' . $clean_uri . '&delete=' . $lang . '#languages">' . $stored . '</a>', 'admin_name' => $admin_name, 'orderby' => $orderby);
}
uasort($data, array($this, 'compare_items'));
$this->items = $data;
}
示例11: qtranxf_migrate_import_qtranslate_slug
function qtranxf_migrate_import_qtranslate_slug($default_language)
{
//$q_config is not yet available
global $wpdb;
//qtranxf_dbg_log('qtranxf_migrate_import_qtranslate_slug: ');
$nm = '<a href="https://wordpress.org/plugins/qtranslate-slug/" target="_blank"><span style="color:blue"><strong>QTranslate Slug</strong></span></a>';
$wpdb->show_errors();
@set_time_limit(0);
$qts_options = get_option('qts_options');
if (!empty($qts_options)) {
//qtranxf_dbg_log('qtranxf_migrate_import_qtranslate_slug: $qts_options: ', $qts_options);
if (is_array($qts_options)) {
foreach ($qts_options as $k => $v) {
}
} else {
qtranxf_error_log(sprintf(__('Failed to import options from plugin %s.', 'qtranslate'), $nm));
}
}
$sql = 'SELECT ID, post_name, post_type, post_parent, meta_key, meta_value FROM ' . $wpdb->postmeta . ' as m INNER JOIN ' . $wpdb->posts . ' as p ON p.ID = m.post_id WHERE p.post_status = "publish" AND p.post_name != "" AND m.meta_key LIKE "_qts_slug___" AND m.meta_value IS NOT NULL';
$sql .= ' AND NOT EXISTS (SELECT * FROM ' . $wpdb->prefix . 'i18n_slugs WHERE name = p.post_name AND lang = MID(m.meta_key,11))';
$result = $wpdb->get_results($sql);
//qtranxf_dbg_log('qtranxf_migrate_import_qtranslate_slug: $result: ', $result);
//qtranxf_dbg_log('qtranxf_migrate_import_qtranslate_slug: count($result): ', count($result));
if (!is_array($result)) {
qtranxf_error_log(sprintf(__('Failed to import data from plugin %s.', 'qtranslate'), $nm) . ' ' . sprintf(__('It might be a good idea to review %smigration instructions%s, if you have not yet done so.', 'qtranslate'), '<a href="https://qtranslatexteam.wordpress.com/migration/" target="_blank">', '</a>'));
return;
}
foreach ($result as $row) {
$name = $row->post_name;
if (empty($name)) {
continue;
}
$slug = $row->meta_value;
if (empty($slug)) {
continue;
}
$lang = substr($row->meta_key, -2);
if ($lang != $default_language) {
continue;
}
if ($slug == $name) {
continue;
}
//qtranxf_dbg_log('qtranxf_migrate_import_qtranslate_slug: default language $slug('.$slug.') != $name('.$name.')');
$slug = wp_unique_post_slug($slug, $row->ID, 'publish', $row->post_type, $row->post_parent);
$wpdb->query($wpdb->prepare('UPDATE ' . $wpdb->posts . ' SET post_name = %s WHERE ID = %d', $slug, $row->ID));
$row->post_name = $row->meta_value = $slug;
}
$cnt = 0;
$cnt_renamed = 0;
$lst = '';
$sql = 'INSERT INTO ' . $wpdb->prefix . 'i18n_slugs (slug, lang, name) VALUES (%s, %s, %s)';
foreach ($result as $row) {
$lang = substr($row->meta_key, -2);
if ($lang == $default_language) {
continue;
}
$name = $row->post_name;
if (empty($name)) {
continue;
}
$slug = $row->meta_value;
if (empty($slug)) {
continue;
}
if (!qtranxf_isEnabled($lang)) {
continue;
}
$slug = qtranxf_slug_unique($row->meta_value, $lang, $name);
if ($slug != $row->meta_value) {
$lst .= $row->ID . '\\t' . $name . '\\t' . $lang . '\\t' . $row->meta_value . ' => ' . $slug . PHP_EOL;
++$cnt_renamed;
}
//qtranxf_dbg_log('qtranxf_migrate_import_qtranslate_slug: $lang='.$lang.'; row: ', $row);
$query = $wpdb->prepare($sql, $slug, $lang, $row->post_name);
$wpdb->query($query);
++$cnt;
}
$msg = '';
if ($cnt != 0) {
$msg .= sprintf(__('Applicable options and slug data from plugin %s have been imported.', 'qtranslate'), $nm);
}
//if(!empty($lst))){
$upload_dir = wp_upload_dir();
//qtranxf_dbg_log('qtranxf_migrate_import_qtranslate_slug: upload_dir: ',$upload_dir);
$fnm = '/qts-qtx-report-of-renamed.log';
$fn = $upload_dir['basedir'] . $fnm;
//[01-Nov-2015 02:21:57 UTC]
error_log(date('[d-M-Y H:i:s T]') . ': Slugs renamed during import:' . PHP_EOL . "Post_ID\tpost_name\tLANG\tQtranslate Slug => qTranslate-X Slug" . PHP_EOL . $lst . PHP_EOL, 3, $fn);
$url = $upload_dir['baseurl'] . $fnm;
$msg .= ' ' . sprintf(__('A number of post slugs have had to be renamed in order to provide uniqueness. The report of renamed slugs is saved in the file "%s".', 'qtranslate'), '<a href="' . $url . ' target="_blank">' . $url . '</a>');
//}
if (!empty($msg)) {
$msg .= ' ' . sprintf(__('It might be a good idea to review %smigration instructions%s, if you have not yet done so.', 'qtranslate'), '<a href="https://qtranslatexteam.wordpress.com/migration/" target="_blank">', '</a>');
qtranxf_add_message($msg);
}
}
示例12: qts_service
function qts_service()
{
global $q_config, $qts_public_key, $qts_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']) && qtranxf_isEnabled($_REQUEST['source_language'])) {
$translate_from = $_REQUEST['source_language'];
}
if (isset($_REQUEST['target_language']) && qtranxf_isEnabled($_REQUEST['target_language'])) {
$translate_to = $_REQUEST['target_language'];
}
if ($translate_to == $translate_from) {
$translate_to = '';
}
$p = get_post($post_id);
$post =& $p;
if (!$post) {
printf(__('Post with id "%s" not found!', 'qtranslate'), $post_id);
return;
}
$default_service = intval(get_option('qts_default_service'), 5);
$service_settings = get_option('qts_service_settings');
// Detect available Languages and possible target languages
$available_languages = qtranxf_getAvailableLanguages($post->post_content);
if ($available_languages === FALSE && !empty($post->post_content)) {
$available_languages = array($q_config['default_language']);
}
if ($available_languages === FALSE || 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 = qtranxf_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 = qtranxf_use($translate_from, $post->post_title);
$post_content = qtranxf_use($translate_from, $post->post_content);
$post_excerpt = qtranxf_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];
}
$post_title_html = htmlspecialchars($post_title);
$permalink = get_permalink($post_id);
if ($permalink) {
if ($translate_from_name) {
$permalink = qtranxf_convertURL($translate_from_name, $permalink);
}
$post_title_html = '<a href="' . $permalink . '" target="_blank">' . $post_title_html . '</a>';
}
if (!empty($translate_from) && !empty($translate_to)) {
$title = sprintf('Translate "%1$s" from %2$s to %3$s', $post_title_html, $translate_from_name, $translate_to_name);
} elseif (!empty($translate_from)) {
$title = sprintf('Translate "%1$s" from %2$s', $post_title_html, $translate_from_name);
} else {
$title = sprintf('Translate "%1$s"', $post_title_html);
}
//.........这里部分代码省略.........
示例13: qtranxf_use_block
function qtranxf_use_block($lang, $blocks, $show_available = false, $show_empty = false)
{
global $q_config;
$content = qtranxf_split_blocks($blocks);
// if content is available show the content in the requested language
if (!empty($content[$lang])) {
return $content[$lang];
} elseif ($show_empty) {
return '';
}
// content is not available in requested language (bad!!) what now?
// find available and alternative languages
if (empty($content[$q_config['default_language']])) {
$alt_lang = null;
$alt_content = null;
$alt_lang_is_default = false;
} else {
$alt_lang = $q_config['default_language'];
$alt_content = $content[$alt_lang];
$alt_lang_is_default = true;
}
$available_languages = array();
foreach ($content as $language => $lang_text) {
if (empty($lang_text)) {
continue;
}
if (!qtranxf_isEnabled($language)) {
continue;
}
$available_languages[] = $language;
if (empty($alt_lang)) {
$alt_lang = $language;
$alt_content = $lang_text;
}
}
if (!$alt_lang) {
return '';
}
if (!$show_available) {
if ($q_config['show_displayed_language_prefix']) {
return '(' . $q_config['language_name'][$alt_lang] . ') ' . $alt_content;
} else {
return $alt_content;
}
/*
// check if content is available in default language, if not return first language found. (prevent empty result)
$language = $q_config['default_language'];
if(!isset($available_languages[$language])){
}
if($lang!=$q_config['default_language']){
$language = $q_config['default_language'];
$lang_text = $content[$language];
//$lang_text = trim($lang_text);
if(!empty($lang_text)){
if ($q_config['show_displayed_language_prefix'])
return '('.$q_config['language_name'][$language].') '.$lang_text;
else
return $lang_text;
}
}
foreach($content as $language => $lang_text) {
$lang_text = trim($lang_text);
if(empty($lang_text)) continue;
if ($q_config['show_displayed_language_prefix'])
return '('.$q_config['language_name'][$language].') '.$lang_text;
else
return $lang_text;
}
*/
}
// display selection for available languages
//$available_languages = array_unique($available_languages);
$language_list = '';
if (preg_match('/%LANG:([^:]*):([^%]*)%/', $q_config['not_available'][$lang], $match)) {
$normal_separator = $match[1];
$end_separator = $match[2];
// build available languages string backward
$i = 0;
foreach ($available_languages as $language) {
if ($i == 1) {
$language_list = $end_separator . $language_list;
}
if ($i > 1) {
$language_list = $normal_separator . $language_list;
}
$language_list = '<a href="' . qtranxf_convertURL('', $language, false, true) . '">' . $q_config['language_name'][$language] . '</a>' . $language_list;
++$i;
}
}
//qtranxf_dbg_echo('$language_list=',$language_list,true);
//if(isset($post)){
// //qtranxf_dbg_echo('$post='.$post);
//}
if (!empty($q_config['show_alternative_content']) && $q_config['show_alternative_content']) {
// show content in alternative language
if (sizeof($available_languages) > 1) {
if ($alt_lang_is_default) {
//$fmt = __('For the sake of viewer convenience, the content is shown below in this site default language %s.', 'qtranslate');
$msg = __('For the sake of viewer convenience, the content is shown below in this site default language.', 'qtranslate');
//.........这里部分代码省略.........
示例14: language_isenabled
function language_isenabled($language = null)
{
$enabled = false;
if (!empty($language)) {
global $slideshow_languageplugin, ${'slideshow_languageenabled_' . $language};
if (!empty(${'slideshow_languageenabled_' . $language})) {
return ${'slideshow_languageenabled_' . $language};
}
switch ($slideshow_languageplugin) {
case 'qtranslate':
$enabled = qtrans_isEnabled($language);
break;
case 'qtranslate-x':
$enabled = qtranxf_isEnabled($language);
break;
case 'wpml':
if (function_exists('icl_get_languages')) {
$languages = icl_get_languages();
if (!empty($languages[$language])) {
$enabled = true;
}
}
break;
}
}
${'slideshow_languageenabled_' . $language} = $enabled;
return $enabled;
}
示例15: qtranxf_use_block
function qtranxf_use_block($lang, $blocks, $show_available = false, $show_empty = false)
{
global $q_config;
//qtranxf_dbg_log('qtranxf_use_language('.$lang.') $text: ', $text);
//qtranxf_dbg_log('qtranxf_use_language: $blocks: ', $blocks);
$available_langs = array();
$content = qtranxf_split_blocks($blocks, $available_langs);
//qtranxf_dbg_log('qtranxf_use_block: $content: ',$content);
//qtranxf_dbg_log('qtranxf_use_block: $available_langs: ',$available_langs);
// if content is available show the content in the requested language
if (!empty($available_langs[$lang])) {
return $content[$lang];
} elseif ($show_empty) {
return '';
}
// content is not available in requested language (bad!!) what now?
//remove available languages that are not enabled
foreach ($available_langs as $language => $b) {
if (qtranxf_isEnabled($language)) {
continue;
}
unset($available_langs[$language]);
}
// set alternative language
if (empty($available_langs[$q_config['default_language']])) {
$alt_lang = null;
$alt_content = null;
$alt_lang_is_default = false;
foreach ($available_langs as $language => $b) {
$alt_lang = $language;
$alt_content = $content[$language];
break;
}
} else {
$alt_lang = $q_config['default_language'];
$alt_content = $content[$alt_lang];
$alt_lang_is_default = true;
}
if (!$alt_lang) {
return '';
}
if (!$show_available) {
if ($q_config['show_displayed_language_prefix']) {
return '(' . $q_config['language_name'][$alt_lang] . ') ' . $alt_content;
} else {
return $alt_content;
}
}
//qtranxf_dbg_log('$alt_content=',$alt_content);
// display selection for available languages
$language_list = '';
if (preg_match('/%LANG:([^:]*):([^%]*)%/', $q_config['not_available'][$lang], $match)) {
$normal_separator = $match[1];
$end_separator = $match[2];
if (!is_textdomain_loaded('language-names')) {
//is not loaded by default, since this place should not be hit frequently
$locale = $q_config['locale'][$q_config['language']];
load_textdomain('language-names', QTRANSLATE_DIR . '/lang/language-names/language-' . $locale . '.mo');
}
$translations = get_translations_for_domain('language-names');
// build available languages string backward
$i = 0;
foreach ($available_langs as $language => $b) {
if ($i == 1) {
$language_list = $end_separator . $language_list;
} elseif ($i > 1) {
$language_list = $normal_separator . $language_list;
}
$locale = $q_config['locale'][$language];
while (!isset($translations->entries[$locale])) {
if ($locale[2] == '_') {
$locale = substr($locale, 0, 2);
if (isset($translations->entries[$locale])) {
break;
}
}
$locale = null;
break;
}
if ($locale) {
$language_name = $translations->entries[$locale]->translations[0];
$language_name = mb_convert_case($language_name, MB_CASE_TITLE);
} else {
$language_name = $q_config['language_name'][$language];
}
$language_list = '“<a href="' . qtranxf_convertURL('', $language, false, true) . '" class="qtranxs-available-language-link qtranxs-available-language-link-' . $language . '">' . $language_name . '</a>”' . $language_list;
++$i;
}
}
//qtranxf_dbg_log('$language_list=',$language_list);
$msg = '';
if (!empty($q_config['show_alternative_content']) && $q_config['show_alternative_content']) {
// show content in alternative language
if (sizeof($available_langs) > 1) {
if ($alt_lang_is_default) {
//$fmt = __('For the sake of viewer convenience, the content is shown below in this site default language %s.', 'qtranslate');
$msg = __('For the sake of viewer convenience, the content is shown below in this site default language.', 'qtranslate');
} else {
//$fmt = __('For the sake of viewer convenience, the content is shown below in an available alternative language %s.', 'qtranslate');
$msg = __('For the sake of viewer convenience, the content is shown below in one of the available alternative languages.', 'qtranslate');
//.........这里部分代码省略.........