Skip to content

Commit

Permalink
3.2.9.9.4 WPBakery Visual Composer & qTranslate-X
Browse files Browse the repository at this point in the history
  • Loading branch information
johnclause committed Apr 21, 2015
1 parent 6581c60 commit 03d8a16
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 79 deletions.
20 changes: 0 additions & 20 deletions admin/js/edit-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,6 @@ qTranslateConfig.js={

qtx.addLanguageSwitchAfterListener(this.setSlugLanguage);

//co('window.vc: ',window.vc);
if(window.vc && !qTranslateConfig.plugin_js_composer_off){//Visual Composer
qtx.addLanguageSwitchAfterListener(this.onTabSwitchVisualComposer);
}

return true;
}
/*
,
onTabSwitch: function(lang)
{
qTranslateConfig.js.setSlugLanguage(lang);
}
*/
,
onTabSwitchVisualComposer: function(lang)
{
if(!window.vc) return;
if(!vc.app) return;
if (vc.app.status != 'shown') return;
vc.app.show();
}
};
2 changes: 1 addition & 1 deletion admin/js/edit-post.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions admin/qtx_activation_hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ function qtranxf_admin_notices_plugin_integration()

$cnt += qtranxf_admin_notice_plugin_integration('wordpress-seo/wp-seo.php', 'Wordpress SEO & qTranslate‑X', 'wp-seo-qtranslate-x/wordpress-seo-qtranslate-x.php');

$cnt += qtranxf_admin_notice_plugin_integration('js_composer/js_composer.php', 'WPBakery Visual Composer & qTranslate‑X', 'js-composer-qtranslate-x/js-composer-qtranslate-x.php');

if($cnt>0){
qtranxf_admin_notice_dismiss_script();
}
Expand Down
9 changes: 5 additions & 4 deletions admin/qtx_admin_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function qtranxf_admin_set_default_options(&$ops)

$ops['admin']['bool']=array(
'auto_update_mo' => true,// automatically update .mo files
'plugin_js_composer_off' => false
//'plugin_js_composer_off' => false
);

//single line options
Expand Down Expand Up @@ -94,6 +94,7 @@ function qtranxf_reset_config()
delete_option('qtranslate_next_update_mo');

// obsolete options
delete_option('qtranslate_plugin_js_composer_off');
delete_option('qtranslate_widget_css');
delete_option('qtranslate_version');
delete_option('qtranslate_disable_header_css');
Expand Down Expand Up @@ -439,9 +440,9 @@ function qtranxf_updateSettings()
$_POST['lsb_style_active_class'] = '';
}

if(!(isset($_POST['plugin_js_composer']) && $_POST['plugin_js_composer']=='1')){
$_POST['plugin_js_composer_off'] = '1';
}
//if(!(isset($_POST['plugin_js_composer']) && $_POST['plugin_js_composer']=='1')){
// $_POST['plugin_js_composer_off'] = '1';
//}

qtranxf_parse_post_type_excluded();

Expand Down
26 changes: 25 additions & 1 deletion admin/qtx_admin_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,33 @@ function qtranxf_edit_terms($term_id, $taxonomy){
//qtranxf_dbg_log('qtranxf_edit_terms: $name='.$name);
}
add_action('edit_terms','qtranxf_edit_terms');
//function qtranxf_gettext($translated_text, $text, $domain) {
function qtranxf_gettext($translated_text) {
//same as qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage
$blocks = qtranxf_get_language_blocks($translated_text);
if(count($blocks)<=1)//no language is encoded in the $text, the most frequent case
return $translated_text;
global $q_config;
//qtranxf_dbg_log('qtranxf_gettext: $translated_text=',$translated_text,true);
return $translated_text;
//return qtranxf_use_block($q_config['language'], $blocks);
//return qtranxf_use($q_config['language'], $translated_text, false);
}
//function qtranxf_gettext_with_context($translated_text, $text, $context, $domain) {
function qtranxf_gettext_with_context($translated_text) {
return qtranxf_gettext($translated_text);
}
add_filter('gettext', 'qtranxf_gettext',0);
add_filter('gettext_with_context', 'qtranxf_gettext_with_context',0);
*/

function qtranxf_getLanguageEdit() {
global $q_config;
return isset($_COOKIE['qtrans_edit_language']) ? $_COOKIE['qtrans_edit_language'] : $q_config['language'];
}

function qtranxf_language_columns($columns) {
return array(
'code' => _x('Code', 'Two-letter Language Code meant.', 'qtranslate'),
Expand Down Expand Up @@ -473,7 +498,6 @@ function qtranxf_languageColumn($column) {
$available_languages_name[] = $language_name;
}
$available_languages_names = join(', ', $available_languages_name);

echo apply_filters('qtranslate_available_languages_names',$available_languages_names);
}
do_action('qtranslate_languageColumn', $available_languages, $missing_languages);
Expand Down
65 changes: 53 additions & 12 deletions admin/qtx_configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function qtranxf_collect_translations( &$qfields, &$request, $edit_lang ) {
function qtranxf_collect_translations_posted() {
//qtranxf_dbg_log('qtranxf_collect_translations_posted: REQUEST: ',$_REQUEST);
if(!isset($_REQUEST['qtranslate-fields'])) return;
$edit_lang = isset($_COOKIE['qtrans_edit_language']) ? $_COOKIE['qtrans_edit_language'] : qtranxf_getLanguage();
//$edit_lang = isset($_COOKIE['qtrans_edit_language']) ? $_COOKIE['qtrans_edit_language'] : qtranxf_getLanguage();
$edit_lang = qtranxf_getLanguageEdit();
foreach($_REQUEST['qtranslate-fields'] as $nm => &$qfields){
//qtranxf_dbg_log('qtranxf_collect_translations_posted: REQUEST[qtranslate-fields]['.$nm.']: ',$qfields);
qtranxf_collect_translations($qfields,$_REQUEST[$nm],$edit_lang);
Expand Down Expand Up @@ -222,7 +223,17 @@ function qtranxf_load_admin_page_config() {
else $page_config['forms'] = array_merge($page_config['forms'],$pgcfg['forms']);
}

break;
if( isset($pgcfg['js-conf']) && !empty($pgcfg['js-conf']) ){
if( !isset($page_config['js-conf']) ) $page_config['js-conf'] = $pgcfg['js-conf'];
else $page_config['js-conf'] = array_merge($page_config['js-conf'],$pgcfg['js-conf']);
}

if( isset($pgcfg['js-exec']) && !empty($pgcfg['js-exec']) ){
if( !isset($page_config['js-exec']) ) $page_config['js-exec'] = $pgcfg['js-exec'];
else $page_config['js-exec'] = array_merge($page_config['js-exec'],$pgcfg['js-exec']);
}

break;//each $pgcfg should not have more than one configuration for the same page
}
}
return $page_config;
Expand Down Expand Up @@ -251,21 +262,40 @@ function qtranxf_add_admin_footer_js ( $enqueue_script=false ) {
wp_deregister_script( 'autosave' );//autosave script saves the active language only and messes it up later in a hard way

if( $enqueue_script ){
//wp_register_script( 'qtranslate-admin-utils', plugins_url( 'js/utils.min.js', __FILE__ ), array(), QTX_VERSION );
//wp_register_script( 'qtranslate-admin-utils', plugins_url( 'js/utils.min.js', __FILE__ ), array(), QTX_VERSION, true );
//wp_enqueue_script( 'qtranslate-admin-utils' );
$deps = array();
if($script_file) $deps[] = 'qtranslate-admin-edit';
if(isset($page_config['scripts'])){
foreach($page_config['scripts'] as $js){
if(isset($page_config['js-conf'])){
$cnt=0;
foreach($page_config['js-conf'] as $js){
if(!isset($js['src'])) continue;
$handle = isset($js['handle']) ? $js['handle'] : 'qtranslate-admin-js-conf-'.(++$cnt);
$ver = isset($js['ver']) ? $js['ver'] : QTX_VERSION;
wp_register_script( $handle, plugins_url($js['src']), $deps, $ver, true);
$deps[] = $handle;
wp_enqueue_script( $handle );
}
}
wp_register_script( 'qtranslate-admin-common', plugins_url( 'js/common.min.js', __FILE__ ), $deps, QTX_VERSION );
wp_register_script( 'qtranslate-admin-common', plugins_url( 'js/common.min.js', __FILE__ ), $deps, QTX_VERSION, true);
wp_enqueue_script( 'qtranslate-admin-common' );
if(isset($page_config['js-exec'])){
$deps[] = 'qtranslate-admin-common';
$cnt=0;
foreach($page_config['js-exec'] as $js){
if(!isset($js['src'])) continue;
$handle = isset($js['handle']) ? $js['handle'] : 'qtranslate-admin-js-exec-'.(++$cnt);
$ver = isset($js['ver']) ? $js['ver'] : QTX_VERSION;
wp_register_script( $handle, plugins_url($js['src']), $deps, $ver, true);
$deps[] = $handle;
wp_enqueue_script( $handle );
}
}
}

$config=array();
// since 3.2.9.9.0 'enabled_languages' is replaced with 'language_config' structure
$keys=array('default_language', 'language', 'url_mode', 'lsb_style_wrap_class', 'lsb_style_active_class', 'plugin_js_composer_off');//,'term_name'
$keys=array('default_language', 'language', 'url_mode', 'lsb_style_wrap_class', 'lsb_style_active_class'); // ,'term_name', 'plugin_js_composer_off'
foreach($keys as $key){
$config[$key]=$q_config[$key];
}
Expand Down Expand Up @@ -301,10 +331,20 @@ function qtranxf_add_admin_footer_js ( $enqueue_script=false ) {
echo 'var qTranslateConfig='.json_encode($config).';'.PHP_EOL;
if(!$enqueue_script){
if($script_file) readfile($script_file);
$plugin_dir_path=plugin_dir_path(__FILE__);
if(isset($page_config['js-conf'])){
$plugins_dir = WP_CONTENT_DIR.'/plugins/';
foreach($page_config['js-conf'] as $js){
if(!isset($js['src'])) continue;
readfile($plugins_dir.$js['src']);
}
}
$plugin_dir_path = plugin_dir_path(__FILE__);
readfile($plugin_dir_path.'js/common.min.js');
if(isset($page_config['scripts'])){
foreach($page_config['scripts'] as $js){
if(isset($page_config['js-exec'])){
$plugins_dir = WP_CONTENT_DIR.'/plugins/';
foreach($page_config['js-exec'] as $js){
if(!isset($js['src'])) continue;
readfile($plugins_dir.$js['src']);
}
}
}
Expand Down Expand Up @@ -467,6 +507,7 @@ function qtranxf_admin_head() {

function qtranxf_admin_footer() {
$enqueue_script = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG);
//$enqueue_script = false;
qtranxf_add_admin_footer_js( $enqueue_script );
}
add_action('admin_footer', 'qtranxf_admin_footer',999);
Expand Down Expand Up @@ -1232,7 +1273,7 @@ function qtranxf_conf() {
<small><?php printf(__('Some plugins and themes use direct calls to the functions listed, which are defined in former %s plugin and some of its forks. Turning this flag on will enable those function to exists, which will make the dependent plugins and themes to work. WordPress policy prohibits to define functions with the same names as in other plugins, since it generates user-unfriendly fatal errors, when two conflicting plugins are activated simultaneously. Before turning this option on, you have to make sure that there are no other plugins active, which define those functions.', 'qtranslate'), '<a href="https://wordpress.org/plugins/qtranslate/" target="_blank">qTranslate</a>'); ?></small>
</td>
</tr>
<?php if ( defined( 'WPB_VC_VERSION' ) ) { ?>
<?php /* if ( defined( 'WPB_VC_VERSION' ) ) { ?>
<tr valign="top">
<th scope="row"><?php _e('3rd-party plugins', 'qtranslate') ?></th>
<td><?php _e('Below is a list of plugins which have a way to auto-integrate with qTranslate-X.', 'qtranslate') ?>
Expand All @@ -1245,7 +1286,7 @@ function qtranxf_conf() {
<p><small><?php printf(__('If %s implements its own integration, this will need to be turned off.', 'qtranslate'), 'WPBakery'); ?></small></p>
</td>
</tr>
<?php } ?>
<?php } */ ?>
</table>
<?php qtranxf_admin_section_end('integration'); ?>
<?php do_action('qtranslate_configuration', $clean_uri); ?>
Expand Down
4 changes: 2 additions & 2 deletions qtranslate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: qTranslate-X
Plugin URI: http://wordpress.org/plugins/qtranslate-x/
Description: Adds user-friendly and database-friendly multilingual content support.
Version: 3.2.9.9.3
Version: 3.2.9.9.4
Author: qTranslate Team
Author URI: http://qtranslatexteam.wordpress.com/about
Tags: multilingual, multi, language, admin, tinymce, Polyglot, bilingual, widget, switcher, professional, human, translation, service, qTranslate, zTranslate, mqTranslate, qTranslate Plus, WPML
Expand Down Expand Up @@ -108,7 +108,7 @@
define( 'QTRANSLATE_FILE', __FILE__ );
}

define('QTX_VERSION','3.2.9.9.3');
define('QTX_VERSION','3.2.9.9.4');

require_once(dirname(__FILE__).'/qtranslate_options.php');
require_once(dirname(__FILE__).'/qtranslate_utils.php');
Expand Down
54 changes: 45 additions & 9 deletions qtranslate_core.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ function qtranxf_init_language() {
if(!isset($url_info['doredirect']) && $url_orig != $url_lang){
$url_info['doredirect'] = '$url_orig != $url_lang';
}
//if( isset($url_info['query']) && $url_info['query'] == ''){
// unset($url_info['doredirect']);
//}
if(isset($url_info['doredirect'])){
$target = apply_filters('qtranslate_language_detect_redirect', $url_lang, $url_orig, $url_info);
//qtranxf_dbg_log('qtranxf_init_language: doredirect to '.$lang.PHP_EOL.'urlorg:'.$url_orig.PHP_EOL.'target:'.$target);
Expand All @@ -96,7 +93,6 @@ function qtranxf_init_language() {
}elseif(isset($url_info['doredirect'])){
$url_info['doredirect'] .= ' - cancelled by can_redirect';
}
//qtranxf_dbg_log('qtranxf_init_language: done url_info: ',$url_info);

// fix url to prevent xss - how does this prevents xss?
//$q_config['url_info']['url'] = qtranxf_convertURL(add_query_arg('lang',$q_config['default_language'],$q_config['url_info']['url']));
Expand Down Expand Up @@ -305,11 +301,11 @@ function qtranxf_parse_language_info(&$url_info, $link=false) {
if($lang){
$url_info['lang_query'] = $lang;
qtranxf_del_query_arg($url_info['query'],'lang');
if(isset($url_info['lang_url'])){
if($lang !== $lang_url) $doredirect=true;
}elseif(!defined('WP_ADMIN')){
if( $q_config['url_mode'] != QTX_URL_QUERY ) $doredirect=true;
}
//if(isset($url_info['lang_url'])){
// if($lang !== $url_info['lang_url']) $doredirect=true;
//}elseif(!defined('WP_ADMIN')){
if( $q_config['url_mode'] != QTX_URL_QUERY ) $doredirect=true;
//}
}else if(isset($url_info['lang_url'])){
$lang = $url_info['lang_url'];
if($q_config['hide_default_language'] && $lang == $q_config['default_language']) $doredirect=true;
Expand Down Expand Up @@ -1164,6 +1160,46 @@ function qtranxf_split_blocks($blocks) {
}
return $result;
}

/**
* gets only part with encoded languages
*/
function qtranxf_split_languages($blocks) {
global $q_config;
$result = array();
$current_language = false;
foreach($blocks as $block) {
// detect c-tags
if(preg_match("#^<!--:([a-z]{2})-->$#ism", $block, $matches)) {
$current_language = $matches[1];
continue;
// detect b-tags
}elseif(preg_match("#^\[:([a-z]{2})\]$#ism", $block, $matches)) {
$current_language = $matches[1];
continue;
}
switch($block){
case '[:]':
case '<!--:-->':
$current_language = false;
break;
default:
// correctly categorize text block
if($current_language){
if(!isset($result[$current_language])) $result[$current_language]='';
$result[$current_language] .= $block;
$current_language = false;
}
break;
}
}
//it gets trimmed later in qtranxf_getAvailableLanguages() anyway, better to do it here
foreach($result as $lang => $text){
$result[$lang]=trim($text);
}
return $result;
}

/*
function qtranxf_split($text, $quicktags = true) {
global $q_config;
Expand Down
26 changes: 26 additions & 0 deletions qtranslate_frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,35 @@ function qtranxf_convertBlogInfoURL($url, $what) {
}
add_filter('bloginfo_url', 'qtranxf_convertBlogInfoURL',10,2);

//function qtranxf_gettext($translated_text, $text, $domain) {
function qtranxf_gettext($translated_text) {
//same as qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage
global $q_config;
//if(!isset($q_config['language'])){
// //qtranxf_dbg_log('$q_config[language] is not set:',debug_backtrace());
// return $translated_text;
//}
return qtranxf_use($q_config['language'], $translated_text, false);
}

//function qtranxf_gettext_with_context($translated_text, $text, $context, $domain) {
function qtranxf_gettext_with_context($translated_text) {
//same as qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage
global $q_config;
//if(!isset($q_config['language'])){
// //qtranxf_dbg_log('$q_config[language] is not set:',debug_backtrace());
// return $translated_text;
//}
return qtranxf_use($q_config['language'], $translated_text, false);
}

//qtranxf_optionFilter();
//add_filter('wp_head', 'qtranxf_add_css');

// Hooks (execution time critical filters)
add_filter('gettext', 'qtranxf_gettext',0);
add_filter('gettext_with_context', 'qtranxf_gettext_with_context',0);

// Compability with Default Widgets
add_filter('widget_title', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
add_filter('widget_text', 'qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage',0);
Expand Down
Loading

0 comments on commit 03d8a16

Please sign in to comment.