本文整理汇总了PHP中qtrans_split函数的典型用法代码示例。如果您正苦于以下问题:PHP qtrans_split函数的具体用法?PHP qtrans_split怎么用?PHP qtrans_split使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qtrans_split函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: split
/**
* Extract a language from a multilingual string.
* Mostly uses qtrans_split, but ensures that it is available
*
* @param string $value The value to be splitted
* @param string $language The code of the required language
* @return mixed The splitted value or the original if it is not multilingual
*/
public function split($value, $language = null)
{
global $q_config;
# qTranslate is not available
if (!function_exists('qtrans_split')) {
return $value;
}
# If there is no language passed, use the active one
if (!$language) {
$language = $q_config['language'];
}
# Check if values are actually multilingual
if (!is_string($value)) {
return $value;
}
# Split the values
$values = apply_filters('uf_ml_q_before_split', $value, $language);
$values = qtrans_split($value);
$values = apply_filters('uf_ml_q_after_split', $values, $language);
if (isset($values[$language])) {
$nice = array();
foreach ($values as $lang => $data) {
$nice[$lang] = maybe_unserialize($data);
}
return apply_filters('uf_ml_q_split', $nice[$language], $value, $language);
} else {
return apply_filters('uf_ml_q_split', $value, $value, $language);
}
}
示例2: load_meta
function load_meta($post_id)
{
$meta = array();
foreach ($this->field_names as $field => $field_label) {
$field_id = "qtrans_meta:{$field}";
$field_data = get_post_meta($post_id, $field_id, true);
$meta[$field] = qtrans_split($field_data);
}
return $meta;
}
示例3: transform
/**
*
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
{
module_load_include('inc', 'donkeymedia_migrate', 'qtranslate_parser');
$result = array();
$available_languages = array('en', 'de');
$default_language = 'en';
$available_content = qtrans_split($value, $available_languages);
foreach ($available_languages as $lang) {
if (isset($available_content[$lang]) && strlen(trim($available_content[$lang])) > 1) {
$result[] = $lang;
}
}
return $result;
}
示例4: render_field
function render_field($field)
{
global $q_config;
$languages = qtrans_getSortedLanguages(true);
$values = qtrans_split($field['value'], $quicktags = true);
$currentLanguage = $this->plugin->get_active_language();
// vars
$o = array('id', 'class', 'name', 'placeholder', 'rows');
$s = array('readonly', 'disabled');
$e = '';
// maxlength
if ($field['maxlength'] !== '') {
$o[] = 'maxlength';
}
// rows
if (empty($field['rows'])) {
$field['rows'] = 8;
}
// populate atts
$atts = array();
foreach ($o as $k) {
$atts[$k] = $field[$k];
}
// special atts
foreach ($s as $k) {
if ($field[$k]) {
$atts[$k] = $k;
}
}
// render
$e .= '<div class="acf-input-wrap multi-language-field">';
foreach ($languages as $language) {
$class = $language === $currentLanguage ? 'wp-switch-editor current-language' : 'wp-switch-editor';
$e .= '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
}
foreach ($languages as $language) {
$atts['class'] = $field['class'];
if ($language === $currentLanguage) {
$atts['class'] .= ' current-language';
}
$atts['name'] = $field['name'] . "[{$language}]";
$atts['data-language'] = $language;
$e .= '<textarea ' . acf_esc_attr($atts) . ' >';
$e .= esc_textarea($values[$language]);
$e .= '</textarea>';
}
$e .= '</div>';
// return
echo $e;
}
示例5: qtrans_getAvailableLanguages
function qtrans_getAvailableLanguages($text)
{
global $q_config;
$result = array();
$content = qtrans_split($text);
foreach ($content as $language => $lang_text) {
$lang_text = trim($lang_text);
if (!empty($lang_text)) {
$result[] = $language;
}
}
if (sizeof($result) == 0) {
// add default language to keep default URL
$result[] = $q_config['language'];
}
return $result;
}
示例6: create_field
function create_field($field)
{
global $q_config;
$languages = qtrans_getSortedLanguages(true);
$values = qtrans_split($field['value'], $quicktags = true);
$currentLanguage = $this->plugin->get_active_language();
echo '<div class="multi-language-field">';
foreach ($languages as $language) {
$class = $language === $currentLanguage ? 'wp-switch-editor current-language' : 'wp-switch-editor';
echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
}
foreach ($languages as $language) {
$class = $language === $currentLanguage ? $field['class'] . ' current-language' : $field['class'];
echo '<textarea data-language="' . esc_attr($language) . '" id="' . esc_attr($field['id']) . '" rows="4" class="' . esc_attr($class) . '" name="' . esc_attr($field['name'] . "[{$language}]") . '">' . esc_textarea($values[$language]) . '</textarea>';
}
echo '</div>';
}
示例7: create_field
function create_field($field)
{
if (!acf_qtranslate_enabled()) {
acf_field_textarea::create_field($field);
return;
}
global $q_config;
$languages = qtrans_getSortedLanguages(true);
$values = qtrans_split($field['value'], $quicktags = true);
echo '<div class="multi-language-field">';
foreach ($languages as $language) {
$class = $language === end($languages) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
}
foreach ($languages as $language) {
$class = $language === end($languages) ? $field['class'] . ' current-language' : $field['class'];
echo '<textarea data-language="' . esc_attr($language) . '" id="' . esc_attr($field['id']) . '" rows="4" class="' . esc_attr($class) . '" name="' . esc_attr($field['name'] . "[{$language}]") . '">' . esc_textarea($values[$language]) . '</textarea>';
}
echo '</div>';
}
示例8: nxs_doQTrans
function nxs_doQTrans($txt, $lng = '')
{
if (!function_exists(qtrans_split) || strpos($txt, '<!--:') === false) {
return $txt;
} else {
$tta = qtrans_split($txt);
if ($lng != '') {
return $tta[$lng];
} else {
return reset($tta);
}
}
}
示例9: render_field
function render_field($field)
{
// enqueue
acf_enqueue_uploader();
// vars
$id = uniqid('acf-editor-');
//$id = $field['id'] . '-' . uniqid();
$mode = 'html';
$show_tabs = true;
// get height
$height = acf_get_user_setting('wysiwyg_height', 300);
$height = max($height, 300);
// minimum height is 300
// detect mode
// case: visual tab only
if ($field['tabs'] == 'visual') {
$mode = 'tmce';
$show_tabs = false;
} elseif ($field['tabs'] == 'text') {
$show_tabs = false;
} elseif (wp_default_editor() == 'tinymce') {
$mode = 'tmce';
}
// mode
$switch_class = $mode . '-active';
// filter value for editor
remove_all_filters('acf_the_editor_content');
if ($mode == 'tmce') {
add_filter('acf_the_editor_content', 'wp_richedit_pre');
} else {
add_filter('acf_the_editor_content', 'wp_htmledit_pre');
}
global $q_config, $wp_version;
$languages = qtrans_getSortedLanguages(true);
$values = qtrans_split($field['value'], $quicktags = true);
$currentLanguage = $this->plugin->get_active_language();
echo '<div class="multi-language-field multi-language-field-wysiwyg">';
foreach ($languages as $language) {
$class = $language === $currentLanguage ? 'wp-switch-editor current-language' : 'wp-switch-editor';
echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
}
$uid = uniqid('acf-editor-');
foreach ($languages as $language) {
$value = apply_filters('acf_the_editor_content', $values[$language]);
$id = $uid . "-{$language}";
$name = $field['name'] . "[{$language}]";
$class = $switch_class;
if ($language === $currentLanguage) {
$class .= ' current-language';
}
?>
<div id="wp-<?php
echo $id;
?>
-wrap" class="acf-editor-wrap wp-core-ui wp-editor-wrap <?php
echo $class;
?>
" data-toolbar="<?php
echo $field['toolbar'];
?>
" data-upload="<?php
echo $field['media_upload'];
?>
" data-language="<?php
echo $language;
?>
">
<div id="wp-<?php
echo $id;
?>
-editor-tools" class="wp-editor-tools hide-if-no-js">
<?php
if ($field['media_upload']) {
?>
<div id="wp-<?php
echo $id;
?>
-media-buttons" class="wp-media-buttons">
<?php
do_action('media_buttons');
?>
</div>
<?php
}
?>
<?php
if (user_can_richedit() && $show_tabs) {
?>
<div class="wp-editor-tabs">
<button id="<?php
echo $id;
?>
-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);" type="button"><?php
echo __('Visual', 'acf');
?>
</button>
<button id="<?php
echo $id;
?>
-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);" type="button"><?php
//.........这里部分代码省略.........
示例10: nxs_doQTrans
function nxs_doQTrans($txt, $lng = '')
{
if (!function_exists("qtrans_split") && !function_exists("qtranxf_split")) {
return $txt;
}
$txt = str_ireplace('<3', '<3', $txt);
$txt = str_ireplace('<(', '<(', $txt);
//$txt = preg_replace('/\[caption\s[^\]]*\]/', '', $txt);
$txt = preg_replace('/\\[caption[\\s]{0,}(.*?)\\][\\s]{0,}(<a[\\s]{0,}.*?<\\/a>)[\\s]{0,}(.*?)\\[\\/caption\\]/ims', '<p $1> $2 <snap class="wpimgcaption">$3</snap> </p>', $txt);
// WP Image with Caption fix
if (function_exists("qtrans_split") && strpos($txt, '<!--:') !== false) {
$tta = qtrans_split($txt);
if ($lng != '') {
return $tta[$lng];
} else {
return reset($tta);
}
}
if (function_exists("qtranxf_split") && (strpos($txt, '<!--:') !== false || strpos($txt, '[:') !== false)) {
$tta = qtranxf_split($txt);
if ($lng != '') {
return $tta[$lng];
} else {
return reset($tta);
}
}
}
示例11: qTrans_compatibility
function qTrans_compatibility($post_title)
{
if (function_exists('qtrans_split')) {
$post_title = qtrans_split($post_title);
//explode the string in a array $_array_[lang_code]=content
$post_title = $post_title[qtrans_getLanguage()];
//get the content from array with actual language
}
return $post_title;
}
示例12: create_field
function create_field($field)
{
global $q_config;
$languages = qtrans_getSortedLanguages(true);
$values = qtrans_split($field['value'], $quicktags = true);
$currentLanguage = $this->plugin->get_active_language();
echo '<div class="multi-language-field multi-language-field-file">';
foreach ($languages as $language) {
$class = 'wp-switch-editor';
if ($language === $currentLanguage) {
$class .= ' current-language';
}
echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
}
$base_class = $field['class'];
$base_name = $field['name'];
foreach ($languages as $language) {
$value = $values[$language];
$o = array('class' => '', 'icon' => '', 'title' => '', 'size' => '', 'url' => '', 'name' => '');
if ($value && is_numeric($value)) {
$file = get_post($value);
if ($file) {
$o['class'] = 'active';
$o['icon'] = wp_mime_type_icon($file->ID);
$o['title'] = $file->post_title;
$o['size'] = size_format(filesize(get_attached_file($file->ID)));
$o['url'] = wp_get_attachment_url($file->ID);
$explode = explode('/', $o['url']);
$o['name'] = end($explode);
}
}
$field['class'] = $base_class;
if ($language === $currentLanguage) {
$field['class'] .= ' current-language';
$o['class'] .= ' current-language';
}
$field['name'] = $base_name . '[' . $language . ']';
?>
<div class="acf-file-uploader clearfix <?php
echo $o['class'];
?>
" data-library="<?php
echo $field['library'];
?>
" data-language="<?php
echo $language;
?>
">
<input class="acf-file-value" type="hidden" name="<?php
echo $field['name'];
?>
" value="<?php
echo $value;
?>
" />
<div class="has-file">
<ul class="hl clearfix">
<li>
<img class="acf-file-icon" src="<?php
echo $o['icon'];
?>
" alt=""/>
<div class="hover">
<ul class="bl">
<li><a href="#" class="acf-button-delete ir">Remove</a></li>
<li><a href="#" class="acf-button-edit ir">Edit</a></li>
</ul>
</div>
</li>
<li>
<p>
<strong class="acf-file-title"><?php
echo $o['title'];
?>
</strong>
</p>
<p>
<strong><?php
_e('Name', 'acf');
?>
:</strong>
<a class="acf-file-name" href="<?php
echo $o['url'];
?>
" target="_blank"><?php
echo $o['name'];
?>
</a>
</p>
<p>
<strong><?php
_e('Size', 'acf');
?>
:</strong>
<span class="acf-file-size"><?php
echo $o['size'];
?>
</span>
</p>
//.........这里部分代码省略.........
示例13: qtrans_use
function qtrans_use($lang, $text, $show_available = false)
{
global $q_config;
// return full string if language is not enabled
if (!qtrans_isEnabled($lang)) {
return $text;
}
if (is_array($text)) {
// handle arrays recursively
foreach ($text as $key => $t) {
$text[$key] = qtrans_use($lang, $text[$key], $show_available);
}
return $text;
}
if (is_object($text) || @get_class($text) == '__PHP_Incomplete_Class') {
foreach (get_object_vars($text) as $key => $t) {
$text->{$key} = qtrans_use($lang, $text->{$key}, $show_available);
}
return $text;
}
// prevent filtering weird data types and save some resources
if (!is_string($text) || $text == '') {
return $text;
}
// get content
$content = qtrans_split($text);
// find available languages
$available_languages = array();
foreach ($content as $language => $lang_text) {
$lang_text = trim($lang_text);
if (!empty($lang_text)) {
$available_languages[] = $language;
}
}
// if no languages available show full text
if (sizeof($available_languages) == 0) {
return $text;
}
// if content is available show the content in the requested language
if (!empty($content[$lang])) {
return $content[$lang];
}
// content not available in requested language (bad!!) what now?
if (!$show_available) {
// check if content is available in default language, if not return first language found. (prevent empty result)
if ($lang != $q_config['default_language']) {
return "(" . $q_config['language_name'][$q_config['default_language']] . ") " . qtrans_use($q_config['default_language'], $text, $show_available);
}
foreach ($content as $language => $lang_text) {
$lang_text = trim($lang_text);
if (!empty($lang_text)) {
return "(" . $q_config['language_name'][$language] . ") " . $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_seperator = $match[1];
$end_seperator = $match[2];
// build available languages string backward
$i = 0;
foreach ($available_languages as $language) {
if ($i == 1) {
$language_list = $end_seperator . $language_list;
}
if ($i > 1) {
$language_list = $normal_seperator . $language_list;
}
$language_list = "<a href=\"" . qtrans_convertURL('', $language) . "\">" . $q_config['language_name'][$language] . "</a>" . $language_list;
$i++;
}
}
return "<p>" . preg_replace('/%LANG:([^:]*):([^%]*)%/', $language_list, $q_config['not_available'][$lang]) . "</p>";
}
示例14: render_field
function render_field($field)
{
global $q_config;
$languages = qtrans_getSortedLanguages(true);
$values = qtrans_split($field['value'], $quicktags = true);
$currentLanguage = $this->plugin->get_active_language();
// enqueue
acf_enqueue_uploader();
// vars
$o = array('icon' => '', 'title' => '', 'size' => '', 'url' => '', 'name' => '');
$div = array('class' => 'acf-file-uploader acf-cf', 'data-library' => $field['library'], 'data-mime_types' => $field['mime_types']);
$input_atts = array('type' => 'hidden', 'name' => $field['name'], 'value' => $field['value'], 'data-name' => 'value-id');
$url = '';
echo '<div class="multi-language-field multi-language-field-image">';
foreach ($languages as $language) {
$class = 'wp-switch-editor';
if ($language === $currentLanguage) {
$class .= ' current-language';
}
echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
}
foreach ($languages as $language) {
$input_atts['name'] = $field['name'] . '[' . $language . ']';
$field['value'] = $values[$language];
$div['data-language'] = $language;
$div['class'] = 'acf-file-uploader acf-cf';
// has value?
if ($field['value'] && is_numeric($field['value'])) {
$file = get_post($field['value']);
if ($file) {
$div['class'] .= ' has-value';
$o['icon'] = wp_mime_type_icon($file->ID);
$o['title'] = $file->post_title;
$o['size'] = @size_format(filesize(get_attached_file($file->ID)));
$o['url'] = wp_get_attachment_url($file->ID);
$explode = explode('/', $o['url']);
$o['name'] = end($explode);
}
}
// basic?
$basic = !current_user_can('upload_files');
if ($basic) {
$div['class'] .= ' basic';
}
if ($language === $currentLanguage) {
$div['class'] .= ' current-language';
}
?>
<div <?php
acf_esc_attr_e($div);
?>
>
<div class="acf-hidden">
<?php
acf_hidden_input(array('name' => $input_atts['name'], 'value' => $field['value'], 'data-name' => 'id'));
?>
</div>
<div class="show-if-value file-wrap acf-soh">
<div class="file-icon">
<img data-name="icon" src="<?php
echo $o['icon'];
?>
" alt=""/>
</div>
<div class="file-info">
<p>
<strong data-name="title"><?php
echo $o['title'];
?>
</strong>
</p>
<p>
<strong><?php
_e('File Name', 'acf');
?>
:</strong>
<a data-name="name" href="<?php
echo $o['url'];
?>
" target="_blank"><?php
echo $o['name'];
?>
</a>
</p>
<p>
<strong><?php
_e('File Size', 'acf');
?>
:</strong>
<span data-name="size"><?php
echo $o['size'];
?>
</span>
</p>
<ul class="acf-hl acf-soh-target">
<?php
if (!$basic) {
?>
<li><a class="acf-icon dark" data-name="edit" href="#"><i class="acf-sprite-edit"></i></a></li>
//.........这里部分代码省略.........
示例15: qtranslate_conf
//.........这里部分代码省略.........
$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 = qtrans_split($post->post_content);
$title = qtrans_split($post->post_title);
foreach ($q_config['enabled_languages'] as $language) {
if ($language != $q_config['default_language']) {
$content[$language] = "";
$title[$language] = "";
}
}
$content = qtrans_join($content);
$title = qtrans_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
qtrans_disableLanguage($_GET['delete']);