Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw merge of qtranslate-slug 1.1.18 as qtranslate-xt module #1060

Merged
merged 6 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions admin/qtx_admin_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public static function check_module( $module_def, $func_is_active = 'is_plugin_a
break;
}
}
} else if ( is_bool( $integration_plugin ) ) {
$active = $integration_plugin;
} else {
$active = call_user_func( $func_is_active, $integration_plugin );
}
Expand Down
49 changes: 46 additions & 3 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 @@ -253,9 +255,14 @@ private function add_sections( $nonce_action ) {
$admin_sections[ $key ] = $value;
}

$admin_sections['integration'] = __( 'Integration', 'qtranslate' );
$admin_sections['import'] = __( 'Import', 'qtranslate' ) . '/' . __( 'Export', 'qtranslate' );
$admin_sections['languages'] = __( 'Languages', 'qtranslate' );
$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 +279,11 @@ 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 @@ -743,6 +755,19 @@ class="qtranxs_explanation"><?php _e( 'The built-in integration modules are auto
</table>
</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 activates the slug translation module. ', 'qtranslate' );
echo '&nbsp;' . __( 'Attention! This module is still experimental. It is subject to bugs and limitations.', 'qtranslate' ) ?>
</p>
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'Configuration Files', 'qtranslate' ) ?></th>
<td><label for="qtranxs_config_files"
Expand Down Expand Up @@ -827,6 +852,24 @@ class="qtranxs_explanation"><?php
<?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' ); ?>
<table class="form-table qtranxs-form-table" id="qtranxs_troubleshooting_config">
Expand Down
21 changes: 20 additions & 1 deletion 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 @@ -29,6 +32,17 @@ public static function load_modules_enabled() {
}
}

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

// TODO: workaround to enable slugs from option checkbox, could be generalized to any module for user control
if ( $q_config['slugs_enabled'] && $options_modules['slugs'] != QTX_MODULE_STATUS_ACTIVE ) {
$options_modules['slugs'] = QTX_MODULE_STATUS_ACTIVE;
update_option( 'qtranslate_modules', $options_modules );
}
}

/**
* Retrieve the definitions of the built-in integration modules.
* Each module is defined by:
Expand Down Expand Up @@ -89,8 +103,13 @@ 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 (experimental)',
'plugin' => true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rather enable that if the user checks "enable experimental slugs", so the other way around.
But I see why it is easier like this for now. The module has still the legacy code of the plugin, so the init sequence should be refactored.

'incompatible' => 'qtranslate-slug/qtranslate-slug.php'
)
);
}

}
22 changes: 22 additions & 0 deletions modules/slugs/assets/css/qts-default.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.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.

59 changes: 59 additions & 0 deletions modules/slugs/assets/css/qts-settings.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*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.

165 changes: 165 additions & 0 deletions modules/slugs/assets/js/qts-nav-menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
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