Skip to content

Commit

Permalink
Raw merge of qtranslate-slug 1.1.8 as qtranslate-xt module
Browse files Browse the repository at this point in the history
Initial merge with minimal modifications to both qtranslate-xt core and qtranslate-slug to incorporate the latter as a module.
Module can be enabled through a checkbox in qtranslate-xt advanced settings.
Heavy code cleanup and harmonization yet to be performed.
Settings page also to be incorporated in qtranslate-xt page
  • Loading branch information
spleen1981 committed Aug 31, 2021
1 parent a2d30c8 commit b1bf3aa
Show file tree
Hide file tree
Showing 25 changed files with 5,830 additions and 8 deletions.
4 changes: 3 additions & 1 deletion admin/qtx_admin_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public static function check_module( $module_def, $func_is_active = 'is_plugin_a
break;
}
}
} else {
} else if (is_bool($integration_plugin)){
$active = $integration_plugin;
} else {
$active = call_user_func( $func_is_active, $integration_plugin );
}

Expand Down
39 changes: 39 additions & 0 deletions admin/qtx_admin_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ private function add_configuration_inspector() {
}

private function add_sections( $nonce_action ) {
global $q_config;

$admin_sections = array();
$admin_sections['general'] = __( 'General', 'qtranslate' );
$admin_sections['advanced'] = __( 'Advanced', 'qtranslate' );
Expand All @@ -256,6 +258,10 @@ private function add_sections( $nonce_action ) {
$admin_sections['integration'] = __( 'Integration', 'qtranslate' );
$admin_sections['import'] = __( 'Import', 'qtranslate' ) . '/' . __( 'Export', 'qtranslate' );
$admin_sections['languages'] = __( 'Languages', 'qtranslate' );

if ($q_config['slugs_enabled'])
$admin_sections['slugs'] = __( 'Slugs', 'qtranslate' );

$admin_sections['troubleshooting'] = __( 'Troubleshooting', 'qtranslate' );

?>
Expand All @@ -272,6 +278,10 @@ private function add_sections( $nonce_action ) {
$this->add_general_section();
$this->add_advanced_section();
$this->add_integration_section();

if ($q_config['slugs_enabled'])
$this->add_slugs_section();

$this->add_troubleshooting_section();
// Allow to load additional services
do_action( 'qtranslate_configuration', $this->options_uri );
Expand Down Expand Up @@ -693,6 +703,17 @@ private function add_advanced_section() {
printf( __( 'The color in use is taken from your profile option %s, the third color.', 'qtranslate' ), '"<a href="' . admin_url( '/profile.php' ) . '">' . qtranxf_translate_wp( 'Admin Color Scheme' ) . '</a>"' ) ?></p>
</td>
</tr>
<tr id="option_slugs_enabled">
<th scope="row"><?php _e( 'Slugs translation', 'qtranslate' ) ?></th>
<td>
<label for="slugs_enabled">
<input type="checkbox" name="slugs_enabled"
id="slugs_enabled"
value="1"<?php checked( $q_config['slugs_enabled']) ?>/>&nbsp;<?php _e( 'Enable slugs translation.', 'qtranslate' ) ?>
</label>
<p class="qtranxs-notes"><?php echo __( 'This will activate the slug translation module (experimental feature). ', 'qtranslate' )?></p>
</td>
</tr>
</table>
<?php
$this->close_section( 'advanced' );
Expand Down Expand Up @@ -826,6 +847,24 @@ class="qtranxs_explanation"><?php
</table>
<?php $this->close_section( 'integration' );
}

private function add_slugs_section() {
global $q_config;
$this->open_section( 'slugs' ); ?>

<table class="form-table qtranxs-form-table" id="qtranxs_slugs_config">
<tr>
<th scope="row"><?php _e( 'Slugs translation', 'qtranslate' ) ?></th>
<td>
<p class="qtranxs_explanation"><?php printf( __( 'Placeholder, settings for slugs translation are still available <a href="%s">here</a>.', 'qtranslate' ), get_admin_url().'options-general.php?page=qtranslate-slug-settings' ) ?></p>
</td>
</tr>
</table>


<?php
$this->close_section( 'slugs', false );
}

private function add_troubleshooting_section() {
$this->open_section( 'troubleshooting' ); ?>
Expand Down
21 changes: 19 additions & 2 deletions modules/qtx_modules_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public static function load_modules_enabled() {
if ( ! is_array( $options_modules ) ) {
return null;
}

self::update_manual_enabled_modules();

foreach ( $def_modules as $def_module ) {
if ( ! array_key_exists( $def_module['id'], $options_modules ) ) {
continue;
Expand All @@ -28,6 +31,16 @@ public static function load_modules_enabled() {
}
}
}

public static function update_manual_enabled_modules() {
global $q_config;
$options_modules = get_option( 'qtranslate_modules', array() );

if ($q_config['slugs_enabled'] && $options_modules['slugs']!=1){
$options_modules['slugs']=1;
update_option( 'qtranslate_modules', $options_modules );
}
}

/**
* Retrieve the definitions of the built-in integration modules.
Expand Down Expand Up @@ -89,8 +102,12 @@ public static function get_modules_defs() {
'name' => 'Yoast SEO',
'plugin' => 'wordpress-seo/wp-seo.php',
'incompatible' => 'wp-seo-qtranslate-x/wordpress-seo-qtranslate-x.php'
)
);
),
array( 'id' => 'slugs',
'name' => 'Slugs',
'plugin' => true,
'incompatible' => 'qtranslate-slug/qtranslate-slug.php'
));
}

}
16 changes: 16 additions & 0 deletions modules/slugs/assets/css/qts-default.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.qts_type_image .qts_lang_item {
float: left;
margin-right: 7px;
}
.qts_type_image .qts_lang_item.last-child {
margin-right: 0;
}
.qts_lang_item{
margin-top: 7px;
margin-bottom: 7px;
}
.qts_both {
white-space: nowrap;
line-height:1em;
}
.qts_both img { margin-right: 4px }
1 change: 1 addition & 0 deletions modules/slugs/assets/css/qts-default.min.css

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

53 changes: 53 additions & 0 deletions modules/slugs/assets/css/qts-settings.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*messages*/
.error {color:#cc0000;}

.settings_page_qtranslate-slug-settings .form-table th {
width: 15%;
min-width: 15% !important;
}

.settings_page_qtranslate-slug-settings .form-table td > span {
display: inline-block;
min-width: 100px;
}

.settings_page_qtranslate-slug-settings .form-table label {
display: block;
margin-bottom: 8px;
}

.settings_page_qtranslate-slug-settings .qts-slug {
width: 35%;
}

#qts-loading {
display: none;
position: relative;
margin-left: 5px;
vertical-align: middle;
}

div.updated.success{
border-color: #298e00;
background-color: #D4EDC9;
}

.error a.button-primary {
color: white !important;
text-decoration: none !important;
}

.ko {
color: #c00;
}
/* v1.1.18 */
#edittag #qts_term_slugs { display: none; }
.term-slug-wrap .qts_term_block input {
width: 86.5%;
}

.qts_term_block label {
display: inline-block;
min-width: 120px;
}

1 change: 1 addition & 0 deletions modules/slugs/assets/js/qts-nav-menu-min.js

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

167 changes: 167 additions & 0 deletions modules/slugs/assets/js/qts-nav-menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
jQuery(document).ready(function($){
var qts_menuitemlang = [];
// Change titles (and values) when user add new item to the menu:
var oldAddMenuItemToBottom = wpNavMenu.addMenuItemToBottom;
wpNavMenu.addMenuItemToBottom = function( menuMarkup, req ) {
oldAddMenuItemToBottom( menuMarkup, req );
saveLang();
changeTitles();
};
var oldAddMenuItemToTop = wpNavMenu.addMenuItemToTop;
wpNavMenu.addMenuItemToTop = function( menuMarkup, req ) {
oldAddMenuItemToTop( menuMarkup, req );
saveLang();
changeTitles();
};

// Change titles (and values) when document is ready:
var lang = $('#qt-languages :radio:checked').val();
saveLang();
changeTitles();

/**
* Change titles when there is a click on pagination
* on show all pages tab.
*
* It happens when there are a large number of pages.
*/
$( document ).ajaxComplete(function() {
lang = $('#qt-languages :radio:checked').val();
changeTitles();
});

// Change titles (and values) when language is changed:
$('#qt-languages :radio').change( function() {
lang = $('#qt-languages :radio:checked').val();

changeTitles();
});

// Change titles (and values) when new menu is added:
$('.submit-add-to-menu').click( function() {
lang = $('#qt-languages :radio:checked').val();
changeTitles();
});

// Update original value when user changed a value:
$(document.body).on('change', 'input.edit-menu-item-title', null, function() {
regexp = new RegExp('<!--:' + lang + '-->(.*?)<!--:-->', 'i');


var qts_old_value = qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")],
qts_new_value = $(this).val();

if( regexp.test(qts_old_value ) ) {
qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")] = qts_old_value.replace( regexp,'<!--:' + lang + '-->' + qts_new_value + '<!--:-->');
}

});




// Update original title="" value when user changed a value:
$(document.body).on('change', 'input.edit-menu-item-attr-title', null, function() {
regexp = new RegExp('<!--:' + lang + '-->(.*?)<!--:-->', 'i');
var qts_old_value = qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")],
qts_new_value = $(this).val();
qts_new_string = '<!--:' + lang + '-->'+ qts_new_value + '<!--:-->';
if(typeof qts_old_value === "undefined" || qts_old_value == "" ) {
qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")] = qts_new_string;
$(this).val( qts_new_string );
} else if( regexp.test(qts_old_value ) ) {
qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")] = qts_old_value.replace( regexp,qts_new_string);
} else {
$(this).val( qts_old_value + qts_new_string );
qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")] = qts_old_value + qts_new_string;
}

});



// Change titles (and values):
function saveLang() {
$('.item-title').each( function() {
qts_menuitemlang[ $(this).closest("li").attr("id") ] = [];
qts_menuitemlang[ $(this).closest("li").attr("id") ]['Title'] = $(this).find("span").html();

if( typeof qts_menuitemlang[ $(this).closest("li").attr("id") ]['Original'] === "undefined" ) {
qts_menuitemlang[ $(this).closest("li").attr("id") ]['Original'] = qts_menuitemlang[ $(this).closest("li").attr("id") ]['Title'];
}
});
$('.menu-item').each( function() {

this_label = $(this).find('input.edit-menu-item-title');
this_title = $(this).find('input.edit-menu-item-attr-title');

qts_menuitemlang[ $(this).attr("id") ][this_label.attr("id") ] = this_label.val();
qts_menuitemlang[ $(this).attr("id") ][this_title.attr("id") ] = this_title.val();

});

}
// Change titles (and values):
function changeTitles() {
// Change menu item titles and links (on the right side):
// TODO: review, and dump
regexp = new RegExp('<!--:' + lang + '-->(.*?)<!--:-->', 'i');
$('.item-title').each( function() {
if (matches = qts_menuitemlang[ $(this).closest("li").attr("id") ]['Original'].match(regexp)) {
$(this).closest('li').find('.link-to-original a').text( matches[1] );
}

});
// Change menu item title inputs (on the right side): Navigation Label, Title Attribute...
regexp2 = new RegExp('<!--:' + lang + '-->(.*?)<!--:-->', 'i');
$('.menu-item').each( function() {
this_label = $(this).find('input.edit-menu-item-title');
this_title = $(this).find('input.edit-menu-item-attr-title');
if( lang === "all") {
this_label.val(qts_menuitemlang[ $(this).attr("id") ][this_label.attr("id") ] );
this_title.val(qts_menuitemlang[ $(this).attr("id") ][this_title.attr("id") ] );
} else {

if (matches = qts_menuitemlang[ $(this).attr("id") ][this_label.attr("id") ].match(regexp2)) {
this_label.val( matches[1] );
}

if (matches2 = qts_menuitemlang[ $(this).attr("id") ][this_title.attr("id") ].match(regexp2)) {
this_title.val( matches2[1] );
}
}
});

// Change menu item checkbox labels (on the left side):
// TODO: fix this, not a show stopper
/*$('label.menu-item-title').each( function() {
var textNode = $(this).contents().get(1);
});*/
}

// Restore the original input values:
function restoreValues(){

$('.menu-item').each( function() {

this_label = $(this).find('input.edit-menu-item-title');
this_title = $(this).find('input.edit-menu-item-attr-title');

this_label.val( qts_menuitemlang[ $(this).attr("id") ][this_label.attr("id") ] );
this_title.val( qts_menuitemlang[ $(this).attr("id") ][this_title.attr("id") ] );
$(this).find('.link-to-original a').text( qts_menuitemlang[ $(this).closest("li").attr("id") ]['Original']);
});
}

// Just before saving restore the original input values:
$('.menu-save').click(function() {
restoreValues();
});

// Just before leaving the page (or refresh) restore the original input values:
window.onbeforeunload = function(){
restoreValues();
return;
};

});
Loading

0 comments on commit b1bf3aa

Please sign in to comment.