Qtranslate Slug - Version 1.1.12

Version Description

= 1.0 = Major version, the plugin has been rewritten. Better performance, and some enhancements.

= 0.9 = This version fix some bugs and allow multilanguage in nav-menus.

= 0.8 = A lot of slugs content allowed

= 0.7 = This version allows TLD domain option for a different Qtranslate fork maded by Zappo

Download this release

Release Info

Developer pedroghandi
Plugin Icon wp plugin Qtranslate Slug
Version 1.1.12
Comparing to
See all releases

Code changes from version 1.1.11 to 1.1.12

includes/class-qtranslate-slug.php CHANGED
@@ -2172,12 +2172,10 @@ class QtranslateSlug {
2172
  || (!current_user_can($post_type_object->cap->edit_post, $post_id))) { // check permission
2173
  return $post_id;
2174
  }
2175
-
2176
  foreach ($this->get_enabled_languages() as $lang) {
2177
 
2178
  $meta_name = $this->get_meta_key($lang);
2179
  $meta_value = apply_filters( 'qts_validate_post_slug', $_POST["qts_{$lang}_slug"], $post, $lang);
2180
-
2181
  delete_post_meta($post_id, $meta_name);
2182
  update_post_meta($post_id, $meta_name, $meta_value);
2183
 
@@ -2209,7 +2207,7 @@ class QtranslateSlug {
2209
  $value = ( $slug ) ? htmlspecialchars( $slug , ENT_QUOTES ) : '';
2210
 
2211
  echo "<tr class=\"form-field form-required\">" . PHP_EOL;
2212
- echo "<th scope=\"row\" valig=\"top\"><label for=\"qts_term_{$lang}_slug\">Slug (".__($q_config['language_name'][$lang], 'qtranslate').")</label></th>" . PHP_EOL;
2213
  echo "<td><input type=\"text\" name=\"qts_{$lang}_slug\" value=\"$value\" /></td></tr>" . PHP_EOL;
2214
 
2215
  }
@@ -2230,7 +2228,7 @@ class QtranslateSlug {
2230
 
2231
 
2232
  echo "<label for=\"qts_{$lang}_slug\">Slug (".__($q_config['language_name'][$lang], 'qtranslate').")</label>" . PHP_EOL;
2233
- echo "<input type=\"text\" name=\"qts_term_{$lang}_slug\" value=\"$value\" aria-required=\"true\">" . PHP_EOL;
2234
 
2235
  echo '</div>';
2236
 
@@ -2291,7 +2289,7 @@ class QtranslateSlug {
2291
  public function unique_term_slug($slug, $term, $lang) {
2292
 
2293
  global $wpdb;
2294
-
2295
  $meta_key_name = $this->get_meta_key($lang);
2296
  $query = $wpdb->prepare("SELECT term_id FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s' AND term_id != %d ", $meta_key_name, $slug, $term->term_id);
2297
  $exists_slug = $wpdb->get_results($query);
@@ -2336,14 +2334,13 @@ class QtranslateSlug {
2336
  $cur_screen = get_current_screen();
2337
  if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) // check autosave
2338
  || ( !current_user_can('edit_posts') ) // check permission
2339
- || ( $cur_screen->id === "nav-menus")
2340
  ) {
2341
  return $term_id;
2342
  }
2343
 
2344
  $term = get_term( $term_id, $taxonomy);
2345
  foreach( $this->get_enabled_languages() as $lang ) {
2346
-
2347
  $meta_name = $this->get_meta_key($lang);
2348
 
2349
  //43LC: when at the post edit screen and creating a new tag
@@ -2379,6 +2376,133 @@ class QtranslateSlug {
2379
 
2380
 
2381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2382
  /**
2383
  * adds support for qtranslate in taxonomies
2384
  *
@@ -2390,8 +2514,8 @@ class QtranslateSlug {
2390
 
2391
  if ($taxonomies) {
2392
  foreach ($taxonomies as $taxonomy ) {
2393
- add_action( $taxonomy->name.'_add_form', $this->get_plugin_prefix() . 'modifyTermFormFor');
2394
- add_action( $taxonomy->name.'_edit_form', $this->get_plugin_prefix() . 'modifyTermFormFor');
2395
  add_action( $taxonomy->name.'_add_form', array(&$this, 'show_term_fields'));
2396
  add_action( $taxonomy->name.'_edit_form_fields', array(&$this, 'show_term_fields') );
2397
  add_filter('manage_edit-'.$taxonomy->name.'_columns', array(&$this, 'taxonomy_columns'));
2172
  || (!current_user_can($post_type_object->cap->edit_post, $post_id))) { // check permission
2173
  return $post_id;
2174
  }
 
2175
  foreach ($this->get_enabled_languages() as $lang) {
2176
 
2177
  $meta_name = $this->get_meta_key($lang);
2178
  $meta_value = apply_filters( 'qts_validate_post_slug', $_POST["qts_{$lang}_slug"], $post, $lang);
 
2179
  delete_post_meta($post_id, $meta_name);
2180
  update_post_meta($post_id, $meta_name, $meta_value);
2181
 
2207
  $value = ( $slug ) ? htmlspecialchars( $slug , ENT_QUOTES ) : '';
2208
 
2209
  echo "<tr class=\"form-field form-required\">" . PHP_EOL;
2210
+ echo "<th scope=\"row\" valig=\"top\"><label for=\"qts_{$lang}_slug\">Slug (".__($q_config['language_name'][$lang], 'qtranslate').")</label></th>" . PHP_EOL;
2211
  echo "<td><input type=\"text\" name=\"qts_{$lang}_slug\" value=\"$value\" /></td></tr>" . PHP_EOL;
2212
 
2213
  }
2228
 
2229
 
2230
  echo "<label for=\"qts_{$lang}_slug\">Slug (".__($q_config['language_name'][$lang], 'qtranslate').")</label>" . PHP_EOL;
2231
+ echo "<input type=\"text\" name=\"qts_{$lang}_slug\" value=\"$value\" aria-required=\"true\">" . PHP_EOL;
2232
 
2233
  echo '</div>';
2234
 
2289
  public function unique_term_slug($slug, $term, $lang) {
2290
 
2291
  global $wpdb;
2292
+
2293
  $meta_key_name = $this->get_meta_key($lang);
2294
  $query = $wpdb->prepare("SELECT term_id FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s' AND term_id != %d ", $meta_key_name, $slug, $term->term_id);
2295
  $exists_slug = $wpdb->get_results($query);
2334
  $cur_screen = get_current_screen();
2335
  if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) // check autosave
2336
  || ( !current_user_can('edit_posts') ) // check permission
2337
+ || ( isset($cur_screen) && $cur_screen->id === "nav-menus")
2338
  ) {
2339
  return $term_id;
2340
  }
2341
 
2342
  $term = get_term( $term_id, $taxonomy);
2343
  foreach( $this->get_enabled_languages() as $lang ) {
 
2344
  $meta_name = $this->get_meta_key($lang);
2345
 
2346
  //43LC: when at the post edit screen and creating a new tag
2376
 
2377
 
2378
 
2379
+ /**
2380
+ * creates and prints the forms and hides the default fields
2381
+ * @param object $term the term object
2382
+ * @since 1.1.12
2383
+ *
2384
+ * TODO: merge with our own form.
2385
+ * TODO: move code into js file
2386
+ *
2387
+ */
2388
+ public function qts_modify_term_form($term) {
2389
+ echo "<script type=\"text/javascript\">\n// <![CDATA[\r\n";
2390
+ if(is_object($term)&&isset($term->name)) {
2391
+ $termname = $term->name;
2392
+ } else {
2393
+ $termname = "";
2394
+ }
2395
+ if(isset($_GET['action']) && $_GET['action']=='edit') {
2396
+ foreach($this->get_enabled_languages() as $language) {
2397
+ echo $this->qts_insert_term_input('name', __('Name','qts'), $termname, $language,"edit");
2398
+ }
2399
+ } else {
2400
+ foreach($this->get_enabled_languages() as $language) {
2401
+ echo $this->qts_insert_term_input('tag-name', __('Name','qts'), $termname, $language,"new");
2402
+ }
2403
+ }
2404
+ // hide real category text
2405
+ echo "if (ins != null) ins.style.display='none';\n";
2406
+ echo "// ]]>\n</script>\n";
2407
+ }
2408
+
2409
+ /**
2410
+ * Helper for qts_modify_term_form_for
2411
+ * @param string $id the term id
2412
+ * @param object #term the term
2413
+ * @param string $language the term name
2414
+ * @param string $action the term name
2415
+ * @return string $html the new input fields
2416
+ * @since 1.1.12
2417
+ * TODO: use DocumentFragment
2418
+ */
2419
+ private function qts_insert_term_input($id,$name, $language,$action){
2420
+ global $q_config;
2421
+
2422
+ if( $action === "new") {
2423
+ $html ="
2424
+ var il = document.getElementsByTagName('input'),
2425
+ d = document.createElement('div'),
2426
+ l = document.createTextNode('".$name." (".$q_config['language_name'][$language].")'),
2427
+ ll = document.createElement('label'),
2428
+ i = document.createElement('input'),
2429
+ ins = null;
2430
+ for(var j = 0; j < il.length; j++) {
2431
+ if(il[j].id=='".$id."') {
2432
+ ins = il[j];
2433
+ break;
2434
+ }
2435
+ }
2436
+ i.type = 'text';
2437
+ i.id = i.name = ll.htmlFor ='qtrans_term_".$language."';
2438
+ ";
2439
+ } elseif ( $action === "edit") {
2440
+ $html ="
2441
+ var tr = document.createElement('tr'),
2442
+ th = document.createElement('th'),
2443
+ ll = document.createElement('label'),
2444
+ l = document.createTextNode('".$name." (".$q_config['language_name'][$language].")'),
2445
+ td = document.createElement('td'),
2446
+ i = document.createElement('input'),
2447
+ ins = document.getElementById('".$id."');
2448
+ i.type = 'text';
2449
+ i.id = i.name = ll.htmlFor ='qtrans_term_".$language."';
2450
+ ";
2451
+ }
2452
+ if(isset($q_config['term_name'][$termname][$language])) {
2453
+ $html .="
2454
+ i.value = '".addslashes(htmlspecialchars_decode($q_config['term_name'][$termname][$language], ENT_QUOTES))."';";
2455
+ //43LC: applied ENT_QUOTES to both edit and new forms.
2456
+ } else {
2457
+ $html .="
2458
+ if (ins != null)
2459
+ i.value = ins.value;
2460
+ ";
2461
+ }
2462
+
2463
+ if($language == $q_config['default_language']) {
2464
+ $html .="
2465
+ i.onchange = function() {
2466
+ var il = document.getElementsByTagName('input'),
2467
+ ins = null;
2468
+ for(var j = 0; j < il.length; j++) {
2469
+ if(il[j].id=='".$id."') {
2470
+ ins = il[j];
2471
+ break;
2472
+ }
2473
+ }
2474
+ if (ins != null)
2475
+ ins.value = document.getElementById('qtrans_term_".$language."').value;
2476
+ };
2477
+ ";
2478
+ }
2479
+ if( $action === "new") {
2480
+ $html .="
2481
+ if (ins != null)
2482
+ ins = ins.parentNode;
2483
+ d.className = 'form-field form-required';
2484
+ ll.appendChild(l);
2485
+ d.appendChild(ll);
2486
+ d.appendChild(i);
2487
+ if (ins != null)
2488
+ ins.parentNode.insertBefore(d,ins);
2489
+ ";
2490
+ } elseif ( $action === "edit") {
2491
+ $html .="
2492
+ ins = ins.parentNode.parentNode;
2493
+ tr.className = 'form-field form-required';
2494
+ th.scope = 'row';
2495
+ th.vAlign = 'top';
2496
+ ll.appendChild(l);
2497
+ th.appendChild(ll);
2498
+ tr.appendChild(th);
2499
+ td.appendChild(i);
2500
+ tr.appendChild(td);
2501
+ ins.parentNode.insertBefore(tr,ins);
2502
+ ";
2503
+ }
2504
+ return $html;
2505
+ }
2506
  /**
2507
  * adds support for qtranslate in taxonomies
2508
  *
2514
 
2515
  if ($taxonomies) {
2516
  foreach ($taxonomies as $taxonomy ) {
2517
+ add_action( $taxonomy->name.'_add_form', array(&$this, 'qts_modify_term_form'));
2518
+ add_action( $taxonomy->name.'_edit_form', array(&$this, 'qts_modify_term_form'));
2519
  add_action( $taxonomy->name.'_add_form', array(&$this, 'show_term_fields'));
2520
  add_action( $taxonomy->name.'_edit_form_fields', array(&$this, 'show_term_fields') );
2521
  add_filter('manage_edit-'.$taxonomy->name.'_columns', array(&$this, 'taxonomy_columns'));
includes/qtranslate-slug-settings.php CHANGED
@@ -754,7 +754,8 @@ function qts_validate_options($input) {
754
 
755
  case 'qts-slug':
756
  // strip all html tags and white-space.
757
- $type_ = end( explode('_', $option['id']) );
 
758
  $input[$option['id'] . '|' . $v]= sanitize_title( sanitize_text_field( $input[$option['id'] . '|' . $v] ) );
759
  $input[$option['id'] . '|' . $v]= addslashes($input[$option['id'] . '|' . $v]);
760
  break;
754
 
755
  case 'qts-slug':
756
  // strip all html tags and white-space.
757
+ $exploded_types = explode('_', $option['id']);
758
+ $type_ = end($exploded_types );
759
  $input[$option['id'] . '|' . $v]= sanitize_title( sanitize_text_field( $input[$option['id'] . '|' . $v] ) );
760
  $input[$option['id'] . '|' . $v]= addslashes($input[$option['id'] . '|' . $v]);
761
  break;
qtranslate-slug.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: qTranslate slug
4
  Plugin URI: http://not-only-code.github.com/qtranslate-slug/
5
  Description: Allows to define a slug for each language and some qTranslate bug fixes
6
- Version: 1.1.11
7
  Author: Carlos Sanz Garcia, Pedro Carvalho
8
  Author URI: http://github.com/not-only-code
9
  */
@@ -50,7 +50,7 @@ include_once(dirname(__FILE__).'/includes/class-qtranslate-slug.php');
50
  *
51
  * @since 1.0
52
  */
53
- if (!defined("QTS_VERSION")) define("QTS_VERSION", '1.1.8');
54
  if (!defined("QTS_PREFIX")) define("QTS_PREFIX", '_qts_');
55
  if (!defined("QTS_PAGE_BASENAME")) define('QTS_PAGE_BASENAME', 'qtranslate-slug-settings');
56
  if (!defined("QTS_OPTIONS_NAME")) define("QTS_OPTIONS_NAME", 'qts_options');
3
  Plugin Name: qTranslate slug
4
  Plugin URI: http://not-only-code.github.com/qtranslate-slug/
5
  Description: Allows to define a slug for each language and some qTranslate bug fixes
6
+ Version: 1.1.12
7
  Author: Carlos Sanz Garcia, Pedro Carvalho
8
  Author URI: http://github.com/not-only-code
9
  */
50
  *
51
  * @since 1.0
52
  */
53
+ if (!defined("QTS_VERSION")) define("QTS_VERSION", '1.1.12');
54
  if (!defined("QTS_PREFIX")) define("QTS_PREFIX", '_qts_');
55
  if (!defined("QTS_PAGE_BASENAME")) define('QTS_PAGE_BASENAME', 'qtranslate-slug-settings');
56
  if (!defined("QTS_OPTIONS_NAME")) define("QTS_OPTIONS_NAME", 'qts_options');
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: qtranslate, slug, multilanguage, widget
5
  Requires at least: 3.3
6
  Tested up to: 4.1
7
- Stable tag: 1.1.11
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -12,7 +12,7 @@ Adds support for permalink translations and fix some QTranslate deficiencies sin
12
 
13
  == Description ==
14
 
15
- [Qtranslate](http://wordpress.org/extend/plugins/qtranslate/) is a nice plugin but unfortunately today is **outdated**. **Qtranslate Slug** is an addon to QTranslate, which adds support for permalinks translations and fix some QTranslate deficiencies since wordpress 3.0. Check out all the new forks from qtranslate!
16
 
17
  **Version 1.0** has been written from scratch using OOP. The code has been structured better, the functions have been marked and commented and everything is better integrated with Wordpress API.
18
 
@@ -21,6 +21,11 @@ Adds support for permalink translations and fix some QTranslate deficiencies sin
21
  * Wordpress 3.3 (PHP 5.4 and MySQL 5)
22
  * mQtranslate 2.6.2.4 or Qtranslate 2.5.8 ( soon qtranslate-x too )
23
 
 
 
 
 
 
24
  = New in Versions 1.1.10 and 1.1.11 =
25
 
26
  * Fixing wrong commit to wp.org
@@ -101,6 +106,11 @@ In the admin go to *Settings/Permalinks* or *Settings/Slug options* and save.
101
 
102
  That's because language selector metabox is hidden, if you are in admin *nav menus* screen, press the button **Screen options** (on top and right) and after, check the option *Languages*. It will appear a **Language** meta box on top of the left sidebar.
103
 
 
 
 
 
 
104
  == Screenshots ==
105
 
106
  1. Edit page for: post / page / post_type, you can see the meta box for translated slugs on top and right.
4
  Tags: qtranslate, slug, multilanguage, widget
5
  Requires at least: 3.3
6
  Tested up to: 4.1
7
+ Stable tag: 1.1.12
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
12
 
13
  == Description ==
14
 
15
+ [Qtranslate](http://wordpress.org/plugins/qtranslate/) is a nice plugin but unfortunately today is **outdated**. **Qtranslate Slug** is an addon to QTranslate, which adds support for permalinks translations and fix some QTranslate deficiencies since wordpress 3.0. Check out all the new forks from qtranslate!
16
 
17
  **Version 1.0** has been written from scratch using OOP. The code has been structured better, the functions have been marked and commented and everything is better integrated with Wordpress API.
18
 
21
  * Wordpress 3.3 (PHP 5.4 and MySQL 5)
22
  * mQtranslate 2.6.2.4 or Qtranslate 2.5.8 ( soon qtranslate-x too )
23
 
24
+ = New in Versions 1.1.12 =
25
+
26
+ * fixed warnings in settings
27
+ * replace qtranslate with our own for taxonomies
28
+
29
  = New in Versions 1.1.10 and 1.1.11 =
30
 
31
  * Fixing wrong commit to wp.org
106
 
107
  That's because language selector metabox is hidden, if you are in admin *nav menus* screen, press the button **Screen options** (on top and right) and after, check the option *Languages*. It will appear a **Language** meta box on top of the left sidebar.
108
 
109
+ = How to get the current url in a specific language? =
110
+
111
+ You can use `qts_get_url()` or the awkwardly named `qTranslateSlug_getSelfUrl()` which is an alias for the first one.
112
+
113
+
114
  == Screenshots ==
115
 
116
  1. Edit page for: post / page / post_type, you can see the meta box for translated slugs on top and right.
version.txt CHANGED
@@ -1,8 +1,13 @@
 
 
 
 
 
1
  = 1.1.10 and 1.1.11 =
2
  * Fixing wrong commit to wp.org
3
  * Clean deleted files
4
 
5
- = 1.1.9 and 1.1.10 =
6
 
7
  Lots of bug fixes! Thanks again to everyone that contributed to this project, with commits, bug reports and suggestions.
8
 
@@ -14,7 +19,7 @@ Lots of bug fixes! Thanks again to everyone that contributed to this project, wi
14
  * Fixed taxonomies slugs ( thanks to [eirikv's bug report](https://wordpress.org/support/topic/categories-slug-dont-work) )
15
  * Fixed many warnings ( thanks piffpaffpuff, issue #78 and to [pedrodu1](https://wordpress.org/support/topic/warnings-qtranslate-slugphp) )
16
  * Changed the behaviour of "Quick Edit", from the wp forums [1](https://wordpress.org/support/topic/categories-tags-and-quick-edit-dont-show-in-admin) [2](https://wordpress.org/support/topic/quick-edit-inhibited-by-qtranslate-slug-with-wp-41-mqtranslate) ( thanks everyone!! )
17
- * Fixed the menus! Now you can properly use one menu for every language. Use the dropdown section "Languages", and for each item, change the "Navigation Label" and "Title Attribute". Select "All languages", to make sure everything is awesome! All these features were a consequence of fixing all the warnings based on [Gery's bug report)[https://wordpress.org/support/topic/qtranslate-slug-conflicting-with-ubermenu).
18
  * Minor fixes, etc.
19
 
20
  See you next Version!
1
+ = 1.1.12 =
2
+
3
+ * fixed warnings in settings
4
+ * replace qtranslate with our own for taxonomies
5
+
6
  = 1.1.10 and 1.1.11 =
7
  * Fixing wrong commit to wp.org
8
  * Clean deleted files
9
 
10
+ = 1.1.9 =
11
 
12
  Lots of bug fixes! Thanks again to everyone that contributed to this project, with commits, bug reports and suggestions.
13
 
19
  * Fixed taxonomies slugs ( thanks to [eirikv's bug report](https://wordpress.org/support/topic/categories-slug-dont-work) )
20
  * Fixed many warnings ( thanks piffpaffpuff, issue #78 and to [pedrodu1](https://wordpress.org/support/topic/warnings-qtranslate-slugphp) )
21
  * Changed the behaviour of "Quick Edit", from the wp forums [1](https://wordpress.org/support/topic/categories-tags-and-quick-edit-dont-show-in-admin) [2](https://wordpress.org/support/topic/quick-edit-inhibited-by-qtranslate-slug-with-wp-41-mqtranslate) ( thanks everyone!! )
22
+ * Fixed the menus! Now you can properly use one menu for every language. Use the dropdown section "Languages", and for each item, change the "Navigation Label" and "Title Attribute". Select "All languages", to make sure everything is awesome! All these features were a consequence of fixing all the warnings based on [Gery's bug report](https://wordpress.org/support/topic/qtranslate-slug-conflicting-with-ubermenu).
23
  * Minor fixes, etc.
24
 
25
  See you next Version!