Skip to content

Commit

Permalink
fixes for slugs implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
johnclause committed Jun 16, 2015
1 parent af3ee1a commit a046fa0
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 82 deletions.
57 changes: 40 additions & 17 deletions admin/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ qtranxj_split_blocks = function(blocks)
var matches;
for(var i = 0;i<blocks.length;++i){
var b=blocks[i];
//c('blocks['+i+']='+b);
if(!b.length) continue;
matches = clang_regex.exec(b); clang_regex.lastIndex=0;
if(matches!=null){
Expand All @@ -104,7 +103,8 @@ qtranxj_split_blocks = function(blocks)
continue;
}
if(lang){
result[lang] += b;
if(!result[lang]) result[lang] = b;
else result[lang] += b;
lang = false;
}else{ //keep neutral text
for(var key in result){
Expand Down Expand Up @@ -291,6 +291,14 @@ var qTranslateX=function(pg)
//updateFusedValueHooked(h);
}

/**
* Designed as interface for other plugin integration. The documentation is available at
* https://qtranslatexteam.wordpress.com/integration/
*
* @since 3.3.4
*/
this.hasContentHook=function(id){ return contentHooks[id]; }

/**
* Designed as interface for other plugin integration. The documentation is available at
* https://qtranslatexteam.wordpress.com/integration/
Expand Down Expand Up @@ -335,11 +343,25 @@ var qTranslateX=function(pg)
var contents = qtranxj_split(inpField.value);//keep neutral text from older times, just in case.
//inpField.tagName
inpField.value = contents[h.lang];
var qtx_prefix;
if(separator){
switch(separator){
case 'slug': qtx_prefix = 'qtranslate-slugs['; break;
default: qtx_prefix = 'qtranslate-fields['; break;
}
}else{
//if(inpField.tagName==='TEXTAREA')
// separator='<';
//else
separator = '[';//since 3.1 we get rid of <--:--> encoding
qtx_prefix = 'qtranslate-fields[';
}

var bfnm, sfnm, p = h.name.indexOf('[');
if(p<0){
bfnm = 'qtranslate-fields['+h.name+']';
bfnm = qtx_prefix + h.name+']';
}else{
bfnm = 'qtranslate-fields['+h.name.substring(0,p)+']';
bfnm = qtx_prefix + h.name.substring(0,p)+']';
if(h.name.lastIndexOf('[]') < 0){
bfnm += h.name.substring(p);
}else{
Expand All @@ -357,15 +379,12 @@ var qTranslateX=function(pg)
h.fields[lang] = f;
inpField.parentNode.insertBefore(f,inpField);
}
if(!separator){
//if(inpField.tagName==='TEXTAREA')
// separator='<';
//else
separator='[';//since 3.1 we get rid of <--:--> encoding
}

// since 3.2.9.8 - h.contents -> h.fields
h.sepfield = qtranxj_ce('input', {name: bfnm+'[qtranslate-separator]', type: 'hidden', className: 'hidden', value: separator });
inpField.parentNode.insertBefore(h.sepfield,inpField);
if(separator != 'slug'){
h.sepfield = qtranxj_ce('input', {name: bfnm+'[qtranslate-separator]', type: 'hidden', className: 'hidden', value: separator });
inpField.parentNode.insertBefore(h.sepfield,inpField);
}
h.separator=separator;

/**
Expand Down Expand Up @@ -1188,18 +1207,22 @@ var qTranslateX=function(pg)
}
if (qTranslateConfig.activeLanguage)
{
var ok2switch = true;
var onTabSwitchFunctionsSave = qTranslateConfig.onTabSwitchFunctionsSave;
for(var i=0; i<onTabSwitchFunctionsSave.length; ++i)
{
var ok = onTabSwitchFunctionsSave[i].call(qTranslateConfig.qtx,qTranslateConfig.activeLanguage,lang);
if(ok === false) ok2switch = false;
}
if(!ok2switch)
return;//cancel button switch, if one of onTabSwitchFunctionsSave returned 'false'.
var tabSwitches = qTranslateConfig.tabSwitches[qTranslateConfig.activeLanguage];
for(var i=0; i < tabSwitches.length; ++i){
tabSwitches[i].classList.remove(qTranslateConfig.lsb_style_active_class);
//tabSwitches[i].classList.remove('active');
//tabSwitches[i].classList.remove('wp-ui-highlight');
}
//tabSwitches[qTranslateConfig.activeLanguage].classList.remove('active');
var onTabSwitchFunctionsSave = qTranslateConfig.onTabSwitchFunctionsSave;
for(var i=0; i<onTabSwitchFunctionsSave.length; ++i)
{
onTabSwitchFunctionsSave[i].call(qTranslateConfig.qtx,qTranslateConfig.activeLanguage,lang);
}
}
var langFrom = qTranslateConfig.activeLanguage;
qTranslateConfig.activeLanguage=lang;
Expand Down
2 changes: 1 addition & 1 deletion admin/js/common.min.js

Large diffs are not rendered by default.

34 changes: 26 additions & 8 deletions admin/js/post-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/wp-admin/post-new.php
*/
jQuery(document).ready(
function(){
function($){
var qtx = qTranslateConfig.js.get_qtx();
//co('post.php: qtx: ',qtx);

Expand All @@ -14,29 +14,33 @@ function(){
{
case '1':
if (url.search){
url.search+="&lang="+lang;
url.search += '&lang='+lang;
}else{
url.search="?lang="+lang;
url.search = '?lang='+lang;
}
break;
case '2':
//if( !qTranslateConfig.hide_default_language || qTranslateConfig.default_language != lang){
var homepath=qTranslateConfig.url_info_home;
var i=url.pathname.indexOf(homepath);
url.pathname=homepath+lang+url.pathname.substring(i+homepath.length-1);
//}
break;
case '3':
url.host=lang+'.'+url.host;
url.host = lang+'.'+url.host;
break;
case '4':
url.host=qTranslateConfig.domains[lang];
url.host = qTranslateConfig.domains[lang];
break;
}
}

var btnViewPostA;//a node of 'View Page/Post' link.
var origUrl, langUrl;
var origUrl, langUrl, origUrlQ;
var slugSamplePermalink;//'sample-permalink' node
var origSamplePermalink;
var view_link;
var permalink_query_field;
var setSlugLanguage=function(lang)
{
if(!btnViewPostA){
Expand All @@ -46,6 +50,7 @@ function(){
if(btnViewPostA.tagName != 'A') return;
origUrl=btnViewPostA.href;
langUrl=qtranxj_ce('a',{});
origUrlQ = origUrl.search(/\?/) > 0;
}

langUrl.href=origUrl;
Expand All @@ -55,10 +60,10 @@ function(){
var btnPreviewAction=document.getElementById('preview-action');
if (btnPreviewAction && btnPreviewAction.children.length)
{
btnPreviewAction.children[0].href=langUrl.href;
btnPreviewAction.children[0].href = langUrl.href;
}

if(qTranslateConfig.url_mode!=1){//!QTX_URL_QUERY
if(qTranslateConfig.url_mode!=1){// !QTX_URL_QUERY
if(!slugSamplePermalink){
var slugEl=document.getElementById('sample-permalink');
if (slugEl && slugEl.childNodes.length){
Expand All @@ -72,6 +77,19 @@ function(){
convertURL(langUrl,lang);
slugSamplePermalink.nodeValue=langUrl.href;
}
}else{// QTX_URL_QUERY
if(!permalink_query_field){
$('#sample-permalink').append('<span id="sample-permalink-lang-query"></span>');
permalink_query_field = $('#sample-permalink-lang-query');
}
if(permalink_query_field){
permalink_query_field.text( (origUrl.search(/\?/) < 0 ? '/?lang=' : '&lang=')+lang );
}
}

if(!view_link) view_link = document.getElementById('wp-admin-bar-view');
if(view_link && view_link.children.length){
view_link.children[0].href = langUrl.href;
}
}

Expand Down
2 changes: 1 addition & 1 deletion admin/js/post-exec.min.js

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

43 changes: 32 additions & 11 deletions admin/qtx_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ function qtranxf_collect_translations( &$qfields, &$request, $edit_lang ) {

function qtranxf_collect_translations_posted() {
//qtranxf_dbg_log('qtranxf_collect_translations_posted: REQUEST_TIME_FLOAT: ', $_SERVER['REQUEST_TIME_FLOAT']);
//qtranxf_dbg_log('qtranxf_collect_translations_posted: REQUEST: ',$_REQUEST);
//qtranxf_dbg_log('qtranxf_collect_translations_posted: POST: ',$_POST);
//qtranxf_dbg_log('qtranxf_collect_translations_posted: REQUEST: ', $_REQUEST);
//qtranxf_dbg_log('qtranxf_collect_translations_posted: POST: ', $_POST);
$edit_lang = null;
if(isset($_REQUEST['qtranslate-fields'])){
//$edit_lang = isset($_COOKIE['qtrans_edit_language']) ? $_COOKIE['qtrans_edit_language'] : qtranxf_getLanguage();
Expand All @@ -46,14 +46,8 @@ function qtranxf_collect_translations_posted() {
//qtranxf_dbg_log('qtranxf_collect_translations_posted: REQUEST[qtranslate-fields]['.$nm.']: ',$qfields);
qtranxf_collect_translations($qfields,$_REQUEST[$nm],$edit_lang);
//qtranxf_dbg_log('qtranxf_collect_translations_posted: collected REQUEST['.$nm.']: ',$_REQUEST[$nm]);
if(isset($_POST[$nm])){
//qtranxf_dbg_log('qtranxf_collect_translations_posted: POST['.$nm.']: ',$_POST[$nm]);
$_POST[$nm] = $_REQUEST[$nm];
}
if(isset($_GET[$nm])){
//qtranxf_dbg_log('qtranxf_collect_translations_posted: GET['.$nm.']: ',$_GET[$nm]);
$_GET[$nm] = $_REQUEST[$nm];
}
if(isset($_POST[$nm])) $_POST[$nm] = $_REQUEST[$nm];
if(isset($_GET[$nm])) $_GET[$nm] = $_REQUEST[$nm];
}
unset($_REQUEST['qtranslate-fields']);
unset($_POST['qtranslate-fields']);
Expand All @@ -80,6 +74,27 @@ function qtranxf_collect_translations_posted() {
if(isset($_GET[$nm]) ) $_GET [$nm] = $q;
}
}
if(isset($_REQUEST['qtranslate-slugs'])){
//ensure REQUEST has the value of the default language
//multilingual slug values will be processed later
if(!$edit_lang) $edit_lang = qtranxf_getLanguageEdit();
global $q_config;
$default_lang = $q_config['default_language'];
if($default_lang != $edit_lang){
foreach($_REQUEST['qtranslate-slugs'] as $nm => $val){
$_REQUEST['qtranslate-slugs'][$nm][$edit_lang] = $_REQUEST[$nm];
$_REQUEST[$nm] = $val[$default_lang];
if(isset($_POST[$nm])){
$_POST[$nm] = $_REQUEST[$nm];
$_POST['qtranslate-slugs'][$nm][$edit_lang] = $_REQUEST['qtranslate-slugs'][$nm][$edit_lang];
}
if(isset($_GET[$nm])){
$_GET[$nm] = $_REQUEST[$nm];
$_GET['qtranslate-slugs'][$nm][$edit_lang] = $_REQUEST['qtranslate-slugs'][$nm][$edit_lang];
}
}
}
}
}
add_action('plugins_loaded', 'qtranxf_collect_translations_posted', 5);

Expand All @@ -92,6 +107,7 @@ function qtranxf_admin_init(){

if ( current_user_can('manage_options')
&& $pagenow == 'options-general.php'
&& isset($q_config['url_info']['query'])
&& strpos($q_config['url_info']['query'], 'page=qtranslate-x') !== false
//&& !empty($_POST) //todo run this only if one of the forms or actions submitted
){
Expand Down Expand Up @@ -182,6 +198,8 @@ function qtranxf_get_admin_page_config_post_type($post_type) {
}
//qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: pagenow: '.$pagenow.'; post_type: ', $post_type);
$page_configs = qtranxf_get_admin_page_config();
//$page_configs = apply_filters('i18n_admin_config_post_type', $page_configs, $post_type);

//qtranxf_dbg_log('qtranxf_get_admin_page_config_post_type: $page_configs: ', $page_configs);
$page_config = isset($page_configs['']) ? $page_configs[''] : array();
if($post_type){
Expand Down Expand Up @@ -216,6 +234,9 @@ function qtranxf_get_admin_page_config_post_type($post_type) {
//unset($page_config['forms'][$form_id]['fields'][$k]);
unset($frm['fields'][$k]);
}
if($post_type && !empty($f['post-type-excluded']) && preg_match('/'.$f['post-type-excluded'].'/',$post_type)){
unset($frm['fields'][$k]);
}
}
foreach($frm as $k => $token){
if(empty($token)) unset($frm[$k]);
Expand Down Expand Up @@ -299,7 +320,7 @@ function qtranxf_add_admin_footer_js ( $enqueue_script=false ) {

$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'); // ,'term_name'
$keys=array('default_language', 'language', 'url_mode', 'lsb_style_wrap_class', 'lsb_style_active_class', 'hide_default_language'); // ,'term_name'
foreach($keys as $key){
$config[$key]=$q_config[$key];
}
Expand Down
4 changes: 2 additions & 2 deletions admin/qtx_admin_options_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function qtranxf_editConfig(){
elseif(isset($_GET['convert'])){
// update language tags
global $wpdb;
$wpdb->show_errors();
$wpdb->show_errors(); @set_time_limit(0);
$cnt = 0;
//this will not work correctly if set of languages is different
foreach($q_config['enabled_languages'] as $lang) {
Expand All @@ -120,7 +120,7 @@ function qtranxf_editConfig(){
elseif(isset($_GET['markdefault'])){
// update language tags
global $wpdb;
$wpdb->show_errors();
$wpdb->show_errors(); @set_time_limit(0);
$result = $wpdb->get_results('SELECT ID, post_content, post_title, post_excerpt, post_type FROM '.$wpdb->posts.' WHERE post_status = \'publish\' AND (post_type = \'post\' OR post_type = \'page\') AND NOT (post_content LIKE \'%<!--:-->%\' OR post_title LIKE \'%<!--:-->%\' OR post_content LIKE \'%![:!]%\' ESCAPE \'!\' OR post_title LIKE \'%![:!]%\' ESCAPE \'!\')');
if(is_array($result)){
$cnt_page = 0;
Expand Down
12 changes: 10 additions & 2 deletions admin/qtx_admin_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ function qtranxf_convert_to_b_no_closing_deep($text) {

function qtranxf_convert_database($action){
global $wpdb;
@set_time_limit(0);
$wpdb->show_errors();
$wpdb->show_errors(); @set_time_limit(0);
qtranxf_convert_database_options($action);
qtranxf_convert_database_posts($action);
qtranxf_convert_database_postmeta($action);
Expand Down Expand Up @@ -806,6 +805,15 @@ function qtranxf_json_encode($o){
return json_encode($o);
}

/**
* @since 3.4
* return reference to $page_config['forms'][$nm]['fields']
*/
function qtranxf_config_add_form( &$page_config, $nm){
if(!isset($page_config['forms'][$nm])) $page_config['forms'][$nm] = array('fields' => array());
else if(!isset($page_config['forms'][$nm]['fields'])) $page_config['forms'][$nm]['fields'] = array();
}

add_filter('manage_language_columns', 'qtranxf_language_columns');
add_filter('manage_posts_columns', 'qtranxf_languageColumnHeader');
add_filter('manage_posts_custom_column', 'qtranxf_languageColumn');
Expand Down
1 change: 0 additions & 1 deletion qTranslateX.json

This file was deleted.

9 changes: 5 additions & 4 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.3.8.4
Version: 3.3.8.5
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 @@ -117,7 +117,7 @@
* Designed as interface for other plugin integration. The documentation is available at
* https://qtranslatexteam.wordpress.com/integration/
*/
define('QTX_VERSION','3.3.8.4');
define('QTX_VERSION','3.3.8.5');

if ( ! defined( 'QTRANSLATE_FILE' ) ) {
define( 'QTRANSLATE_FILE', __FILE__ );
Expand All @@ -129,12 +129,13 @@
if(is_admin() ){ // && !(defined('DOING_AJAX') && DOING_AJAX)
require_once(QTRANSLATE_DIR.'/admin/qtx_activation_hook.php');
register_activation_hook(__FILE__, 'qtranxf_activation_hook');
register_deactivation_hook( __FILE__, 'qtranxf_deactivation_hook' );
}

// load additional functionalities

if(file_exists(QTRANSLATE_DIR.'/slugs'))
require_once(QTRANSLATE_DIR.'/slugs/qtx_slug.php');
//if(file_exists(QTRANSLATE_DIR.'/slugs'))
// require_once(QTRANSLATE_DIR.'/slugs/qtx_slug.php');

// load qTranslate Services if available // disabled since 3.1
//if(file_exists(QTRANSLATE_DIR.'/qtranslate_services.php'))
Expand Down
Loading

0 comments on commit a046fa0

Please sign in to comment.