Qtranslate Slug - Version 1.1.15

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.15
Comparing to
See all releases

Code changes from version 1.1.13 to 1.1.15

includes/class-qtranslate-slug.php CHANGED
@@ -55,6 +55,11 @@ class QtranslateSlug {
55
  */
56
  private $current_lang = false;
57
 
 
 
 
 
 
58
  /**
59
  * Array of enabled languages
60
  *
@@ -153,6 +158,7 @@ class QtranslateSlug {
153
  $this->set_options();
154
  return $this->options;
155
  }
 
156
  /**
157
  * Returns the correct prefix for the function names of the different supported translation plugins.
158
  * Will return 'qtranxf_' if qtranslate-x is used, 'qtrans_' otherwise.
@@ -160,6 +166,7 @@ class QtranslateSlug {
160
  * @return string the function name prefix for translation functions from other plugins
161
  * @since 1.1.9
162
  */
 
163
  private function get_plugin_prefix(){
164
 
165
  return $this->plugin_prefix;
@@ -200,13 +207,12 @@ class QtranslateSlug {
200
  }
201
  }
202
  }
 
203
  /**
204
- * Returns the correct prefix for the function names of the different supported translation plugins.
205
- * Will return 'qtranxf_' if qtranslate-x is used, 'qtrans_' otherwise.
206
  *
207
- * @return string the function name prefix for translation functions from other plugins
208
- * @since 1.1.9
209
  */
 
210
  private function set_url_path_mode(){
211
  if ('' === $this->url_path_mode){
212
  if (is_plugin_active('qtranslate-x/qtranslate.php')){
@@ -503,7 +509,8 @@ class QtranslateSlug {
503
 
504
  // until we get a proper function, this will make it for it.
505
  $this->current_lang = $q_config['language'];
506
- $this->enabled_languages = $q_config['enabled_languages'];
 
507
  $this->set_plugin_prefix();
508
  $this->set_url_path_mode();
509
 
@@ -555,7 +562,12 @@ class QtranslateSlug {
555
 
556
  // remove from qtranslate the discouraged meta http-equiv, inline styles
557
  // (including flag URLs) and wrong hreflang links
 
558
  remove_action('wp_head', $this->get_plugin_prefix() . 'header');
 
 
 
 
559
  // add proper hreflang links
560
  add_action('wp_head',array(&$this, 'qtranslate_slug_header_extended'));
561
 
@@ -606,8 +618,10 @@ class QtranslateSlug {
606
  public function qtranslate_slug_header_extended(){
607
  if(is_404()) return;
608
 
609
-
 
610
  foreach($this->get_enabled_languages() as $language) {
 
611
  if($language != $this->get_currentlang() )
612
  echo '<link hreflang="'.$language.'" href="'.$this->get_current_url($language).'" rel="alternate" />'."\n";
613
  }
@@ -653,112 +667,13 @@ class QtranslateSlug {
653
  public function qts_quickuse( $text,$lang='' ){
654
  global $q_config;
655
  $lang = '' == $lang ? $q_config['language'] : $lang;
656
- $parsed_text = $this->qts_split($text);
657
  if( !empty($parsed_text[$lang])){
658
  return $parsed_text[$lang];
659
  }
660
  }
661
- /**
662
- * Quickly splits text in the different languages, either by
663
- * long tags "<!--:en-->text<!--:-->", or
664
- * ~short tags "[:en]text"~ <- dont support any more.
665
- * NOTE: this is different behaviour from qtrans_split. don't mix long and short
666
- * ANOTHER NOTE: don't mix <!--:en-->text<!--:-->more text.
667
- * @param $text the whole text
668
- * @param bool $quicktag
669
- *
670
- * @package Qtranslate Slug
671
- * @since 1.1.9
672
- */
673
- public function qts_split($text, $quicktags = false ) {
674
-
675
- $result = array();
676
- /* if( $quicktags ) {
677
- $split_regex = "#\[(:[a-z]{2})\]#ism";
678
- $split_texts = preg_split($split_regex, $text, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
679
- $max = count( $split_texts);
680
- for( $i=0 ; $i < $max; $i+=2) {
681
- $result[$split_texts[$i]] = $split_texts[$i+1];
682
- }
683
- return $result;
684
- } else {*/
685
- $split_texts = explode('<!--:-->', $text);
686
- foreach ($split_texts as $split_text) {
687
- if(preg_match("#<!--:([a-z]{2})-->(.*)#i", $split_text, $matches)) {
688
- $result[$matches[1]] = $matches[2];
689
- }
690
- }
691
- //}
692
- return $result;
693
- }
694
 
695
-
696
- /**
697
- *
698
- * Splits and returns the text in the right language.
699
- * Based on https://github.com/xhaleera/mqtranslate
700
- * and https://wordpress.org/support/topic/evidence-on-how-slow-and-inefficient-qtranslate-is-please-do-something
701
- * @param string $lang the language to extr
702
- */
703
- public function qts_use($lang, $text, $show_available=false) {
704
- if (empty($text) || !call_user_func($this->get_plugin_prefix() . 'isEnabled',$lang))
705
- return $text;
706
-
707
- $re = '/<!--:[a-z]{2}-->/i';
708
- // dropping quicktags like a boss
709
- if (is_string($text) && !preg_match($re, $text))
710
- return $text;
711
-
712
- if (is_array($text) || is_object($text)) {
713
- foreach ($text as &$t)
714
- if ($t && ((is_string($t) && preg_match($re, $t)) || is_array($t) || is_object($t)))
715
- $t = $this->qts_use($lang, $t, $show_available);
716
- return $text;
717
- }
718
-
719
-
720
-
721
- // get content
722
- $content = $this->qts_split($text);
723
- // find available languages
724
- $available_languages = array();
725
- foreach($content as $language => $lang_text) {
726
- $lang_text = trim($lang_text);
727
- if(!empty($lang_text)) {
728
- $available_languages[] = $language;
729
- }
730
- }
731
- // if no languages available show full text
732
- if (empty($available_languages))
733
- return $text;
734
-
735
- // if content is available, show the content in the requested language
736
- if (!empty($content[$lang]))
737
- return $content[$lang];
738
- if( $show_available ) {
739
- global $q_config;
740
- // display selection for available languages
741
- $language_list = "";
742
- // Not Available Message + separators
743
- $language_notavailable = explode(":", $q_config['not_available'][$lang] );
744
- if (empty($language_notavailable )) {
745
- $language_url = get_the_permalink();
746
- $normal_separator = $language_notavailable[1];
747
- $end_separator = $language_notavailable[2];
748
- // build available languages string backward
749
- foreach ($available_languages as $k => $language) {
750
- if ($k == 1)
751
- $language_list = $end_separator.$language_list;
752
- else if ($k > 1)
753
- $language_list = $normal_separator.$language_list;
754
- $language_list = "<a href=\"". call_user_func($this->get_plugin_prefix() . 'convertURL',$language_url, $language)."\">".$q_config['language_name'][$language]."</a>".$language_list;
755
- }
756
- }//TODO: fix this! the link isn't updated.
757
- return "<p>".sprintf( $q_config['not_available'][$lang], $language_list)."</p>";
758
- }
759
- return "";
760
-
761
- }
762
  /**
763
  * Adds news rules to translate the URL bases,
764
  * this function must be called on flush_rewrite or 'flush_rewrite_rules'
@@ -888,7 +803,7 @@ class QtranslateSlug {
888
  */
889
  public function parse_url_args( $url ) {
890
  global $q_config;
891
-
892
  if (is_admin()) {
893
  return $url;
894
  }
@@ -901,6 +816,7 @@ class QtranslateSlug {
901
 
902
  if ( empty($this->permalink_structure) || $q_config['url_mode'] == 1 ) {
903
  $base_args['lang'] = $this->get_lang();
 
904
  }
905
 
906
  // rebuild query with all args
@@ -908,7 +824,7 @@ class QtranslateSlug {
908
 
909
  $url = str_replace('/?', '?', $url); // TODO: hack: improve this code
910
  $url = str_replace('?', '/?', $url); // TODO: hack: improve this code
911
-
912
  return $url;
913
  }
914
 
@@ -1376,7 +1292,6 @@ class QtranslateSlug {
1376
  * @since 1.0
1377
  */
1378
  public function home_url($url, $path, $scheme, $blog_id) {
1379
-
1380
  if ( !in_array( $scheme, array( 'http', 'https' ) ) ) {
1381
  $scheme = is_ssl() && !is_admin() ? 'https' : 'http';
1382
  }
@@ -1390,17 +1305,18 @@ class QtranslateSlug {
1390
  if ( 'http' != $scheme ) {
1391
  $url = str_replace( 'http://', "$scheme://", $url );
1392
  }
1393
-
1394
  $ignore_caller = $this->ignore_rewrite_caller();
1395
-
1396
  if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) {
1397
  $url .= '/' . ltrim( $path, '/' );
1398
  }
1399
-
1400
  if ( !$ignore_caller ) {
1401
  $url = call_user_func($this->get_plugin_prefix() . 'convertURL', $url, $this->get_lang(), true);
1402
  }
1403
-
 
1404
  return $url;
1405
  }
1406
 
@@ -2064,7 +1980,7 @@ class QtranslateSlug {
2064
  */
2065
  public function validate_post_slug( $slug, $post, $lang ) {
2066
 
2067
- $post_title = trim($this->qts_use($lang, $_POST['post_title']));
2068
  $post_name = get_post_meta($post->ID, $this->get_meta_key($lang), true);
2069
  if (!$post_name) {
2070
  $post_name = $post->post_name;
@@ -2477,7 +2393,7 @@ class QtranslateSlug {
2477
  ";
2478
  }
2479
 
2480
- if($language == $q_config['default_language']) {
2481
  $html .="
2482
  i.onchange = function() {
2483
  var il = document.getElementsByTagName('input'),
@@ -2686,6 +2602,7 @@ class QtranslateSlug {
2686
  public function language_menu( $type = "text", $args = array() ) {
2687
  global $q_config;
2688
 
 
2689
  // default arguments
2690
  $defaults = array(
2691
  'id' => "qts-lang-menu",
@@ -2710,7 +2627,12 @@ class QtranslateSlug {
2710
  foreach( $languages as $index => $lang ):
2711
 
2712
  $url = $this->get_current_url($lang);
2713
-
 
 
 
 
 
2714
  $item_class = array();
2715
  if ( (string)$q_config['language'] == (string)$lang ) $item_class[] = 'current-menu-item';
2716
  if ( $index == ( $num_languages - 1) ) $item_class[] = 'last-child';
@@ -2738,7 +2660,8 @@ class QtranslateSlug {
2738
  //43LC: hardcoding height and width
2739
  $link_flag = "<img widht=\"18\" height=\"12\" src=\"$link_flag_url\" alt=\"$language_name\" />";
2740
  }
2741
- echo "<li$item_class><a href=\"$url\" lang=\"$lang\" hreflang=\"$lang\"$link_class>$link_flag$link_content</a></li>" . PHP_EOL;
 
2742
 
2743
  endforeach;
2744
 
55
  */
56
  private $current_lang = false;
57
 
58
+ /**
59
+ * variable for default language
60
+ */
61
+ private $default_language = false;
62
+
63
  /**
64
  * Array of enabled languages
65
  *
158
  $this->set_options();
159
  return $this->options;
160
  }
161
+
162
  /**
163
  * Returns the correct prefix for the function names of the different supported translation plugins.
164
  * Will return 'qtranxf_' if qtranslate-x is used, 'qtrans_' otherwise.
166
  * @return string the function name prefix for translation functions from other plugins
167
  * @since 1.1.9
168
  */
169
+
170
  private function get_plugin_prefix(){
171
 
172
  return $this->plugin_prefix;
207
  }
208
  }
209
  }
210
+
211
  /**
212
+ * Sets the url path mode based on the qtranslate or fork settings.
 
213
  *
 
 
214
  */
215
+
216
  private function set_url_path_mode(){
217
  if ('' === $this->url_path_mode){
218
  if (is_plugin_active('qtranslate-x/qtranslate.php')){
509
 
510
  // until we get a proper function, this will make it for it.
511
  $this->current_lang = $q_config['language'];
512
+ $this->enabled_languages = $q_config['enabled_languages'];
513
+ $this->default_language = $q_config['default_language'];
514
  $this->set_plugin_prefix();
515
  $this->set_url_path_mode();
516
 
562
 
563
  // remove from qtranslate the discouraged meta http-equiv, inline styles
564
  // (including flag URLs) and wrong hreflang links
565
+
566
  remove_action('wp_head', $this->get_plugin_prefix() . 'header');
567
+ if( "qtranxf_" === $this->get_plugin_prefix() ) {
568
+ remove_action('wp_head', $this->get_plugin_prefix() . 'head');
569
+ }
570
+
571
  // add proper hreflang links
572
  add_action('wp_head',array(&$this, 'qtranslate_slug_header_extended'));
573
 
618
  public function qtranslate_slug_header_extended(){
619
  if(is_404()) return;
620
 
621
+ //taken from qtx
622
+ echo '<link hreflang="x-default" href="'.$this->get_current_url($this->default_language) .'" rel="alternate" />'.PHP_EOL;
623
  foreach($this->get_enabled_languages() as $language) {
624
+
625
  if($language != $this->get_currentlang() )
626
  echo '<link hreflang="'.$language.'" href="'.$this->get_current_url($language).'" rel="alternate" />'."\n";
627
  }
667
  public function qts_quickuse( $text,$lang='' ){
668
  global $q_config;
669
  $lang = '' == $lang ? $q_config['language'] : $lang;
670
+ $parsed_text = call_user_func($this->get_plugin_prefix() . 'getSortedLanguages',$text);
671
  if( !empty($parsed_text[$lang])){
672
  return $parsed_text[$lang];
673
  }
674
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
675
 
676
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
677
  /**
678
  * Adds news rules to translate the URL bases,
679
  * this function must be called on flush_rewrite or 'flush_rewrite_rules'
803
  */
804
  public function parse_url_args( $url ) {
805
  global $q_config;
806
+
807
  if (is_admin()) {
808
  return $url;
809
  }
816
 
817
  if ( empty($this->permalink_structure) || $q_config['url_mode'] == 1 ) {
818
  $base_args['lang'] = $this->get_lang();
819
+
820
  }
821
 
822
  // rebuild query with all args
824
 
825
  $url = str_replace('/?', '?', $url); // TODO: hack: improve this code
826
  $url = str_replace('?', '/?', $url); // TODO: hack: improve this code
827
+
828
  return $url;
829
  }
830
 
1292
  * @since 1.0
1293
  */
1294
  public function home_url($url, $path, $scheme, $blog_id) {
 
1295
  if ( !in_array( $scheme, array( 'http', 'https' ) ) ) {
1296
  $scheme = is_ssl() && !is_admin() ? 'https' : 'http';
1297
  }
1305
  if ( 'http' != $scheme ) {
1306
  $url = str_replace( 'http://', "$scheme://", $url );
1307
  }
1308
+
1309
  $ignore_caller = $this->ignore_rewrite_caller();
1310
+
1311
  if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) {
1312
  $url .= '/' . ltrim( $path, '/' );
1313
  }
1314
+
1315
  if ( !$ignore_caller ) {
1316
  $url = call_user_func($this->get_plugin_prefix() . 'convertURL', $url, $this->get_lang(), true);
1317
  }
1318
+ // if($this->default_language === $this->current_lang){ $url.="/en/" . ltrim( $path, '/' ); }
1319
+
1320
  return $url;
1321
  }
1322
 
1980
  */
1981
  public function validate_post_slug( $slug, $post, $lang ) {
1982
 
1983
+ $post_title = trim(call_user_func($this->get_plugin_prefix() . 'use',$lang, $_POST['post_title']));
1984
  $post_name = get_post_meta($post->ID, $this->get_meta_key($lang), true);
1985
  if (!$post_name) {
1986
  $post_name = $post->post_name;
2393
  ";
2394
  }
2395
 
2396
+ if($language == $this->default_language) {
2397
  $html .="
2398
  i.onchange = function() {
2399
  var il = document.getElementsByTagName('input'),
2602
  public function language_menu( $type = "text", $args = array() ) {
2603
  global $q_config;
2604
 
2605
+
2606
  // default arguments
2607
  $defaults = array(
2608
  'id' => "qts-lang-menu",
2627
  foreach( $languages as $index => $lang ):
2628
 
2629
  $url = $this->get_current_url($lang);
2630
+ // 43LC: hack to play nice with qtranslate-x
2631
+ if( "qtranxf_" === $this->plugin_prefix && $this->default_language === $lang ) {
2632
+ $home_url_default = get_home_url();
2633
+ $home_full_lang = $home_url_default."/$lang";
2634
+ $url = str_replace($home_url_default,$home_full_lang ,$url);
2635
+ }
2636
  $item_class = array();
2637
  if ( (string)$q_config['language'] == (string)$lang ) $item_class[] = 'current-menu-item';
2638
  if ( $index == ( $num_languages - 1) ) $item_class[] = 'last-child';
2660
  //43LC: hardcoding height and width
2661
  $link_flag = "<img widht=\"18\" height=\"12\" src=\"$link_flag_url\" alt=\"$language_name\" />";
2662
  }
2663
+
2664
+ echo "<li $item_class><a href=\"$url\" lang=\"$lang\" hreflang=\"$lang\"$link_class>$link_flag$link_content</a></li>" . PHP_EOL;
2665
 
2666
  endforeach;
2667
 
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.13
7
  Author: Carlos Sanz Garcia, Pedro Carvalho
8
  Author URI: http://github.com/not-only-code
9
  */
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.15
7
  Author: Carlos Sanz Garcia, Pedro Carvalho
8
  Author URI: http://github.com/not-only-code
9
  */
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.13
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -21,28 +21,27 @@ 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 or qtranslate-x ( 2.9.1 )
23
 
 
 
24
 
25
- = New in 1.1.13 =
26
 
27
- Thanks to returning @pedro-mendonca for these commits:
 
28
 
 
 
29
  * Cleaned duplicated label in widget
30
  * Bug fix in "Slug (%s)" string translation
31
  * Changed text strings with no text-domain and with text-domain 'qtranlate' to text-domain 'qts'
32
  * pot catalog updated with current strings, including last found is "More information about".
33
-
34
- Thanks to @johnclause for these :
35
-
36
  * Convenience links in notice_dependences
37
  * Menu compatibility with qTranslate-X
38
  * Fixed extra characters in widget
39
-
40
- Thanks to vbkun for casting the much wanted function to get a slug based on an id and language
41
-
42
  * Added a global qts_get_slug( $id, $lang)
43
-
44
- and sadly:
45
-
46
  * removed the menu admin box until better implementation
47
 
48
 
@@ -70,8 +69,7 @@ Thanks for use this plugin!
70
 
71
 
72
  == Installation ==
73
- **This plugins requires [Qtranslate](http://wordpress.org/extend/plugins/qtranslate/) or [mqTranslate](https://wordpress.org/plugins/mqtranslate/)
74
- ir [qtranslate-X](https://wordpress.org/plugins/qtranslate-x/) installed previously, if not, it will not activate.**
75
 
76
  1. Upload `qtranslate-slug` to the `/wp-content/plugins/` directory.
77
  1. Activate the plugin through the 'Plugins' menu in WordPress.
4
  Tags: qtranslate, slug, multilanguage, widget
5
  Requires at least: 3.3
6
  Tested up to: 4.1
7
+ Stable tag: 1.1.15
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
21
  * Wordpress 3.3 (PHP 5.4 and MySQL 5)
22
  * mQtranslate 2.6.2.4 or Qtranslate 2.5.8 or qtranslate-x ( 2.9.1 )
23
 
24
+ = New in 1.1.15 =
25
+ * Fixes the duplicated hreflang links in <head>
26
 
27
+ = New in 1.1.14 =
28
 
29
+ The menu widget didn't allow the visitors to change to the default language if qtranslate-x was being used. So, adjusted the Language Menu widget to play nice with qtranslate-x.
30
+ Hope to bring some nice changes that were made in the github repository in the next version. For now, enjoy.
31
 
32
+ = New in 1.1.13 =
33
+ == Thanks to returning @pedro-mendonca for these commits: ==
34
  * Cleaned duplicated label in widget
35
  * Bug fix in "Slug (%s)" string translation
36
  * Changed text strings with no text-domain and with text-domain 'qtranlate' to text-domain 'qts'
37
  * pot catalog updated with current strings, including last found is "More information about".
38
+ == Thanks to @johnclause for these : ==
 
 
39
  * Convenience links in notice_dependences
40
  * Menu compatibility with qTranslate-X
41
  * Fixed extra characters in widget
42
+ ### Thanks to vbkun for casting the much wanted function to get a slug based on an id and language
 
 
43
  * Added a global qts_get_slug( $id, $lang)
44
+ ### and sadly:
 
 
45
  * removed the menu admin box until better implementation
46
 
47
 
69
 
70
 
71
  == Installation ==
72
+ **This plugins requires [Qtranslate](http://wordpress.org/extend/plugins/qtranslate/) or [mqTranslate](https://wordpress.org/plugins/mqtranslate/) installed previously, if not, it will not activate.**
 
73
 
74
  1. Upload `qtranslate-slug` to the `/wp-content/plugins/` directory.
75
  1. Activate the plugin through the 'Plugins' menu in WordPress.
version.txt CHANGED
@@ -1,4 +1,13 @@
1
 
 
 
 
 
 
 
 
 
 
2
  = 1.1.13 =
3
  == Thanks to returning @pedro-mendonca for these commits: ==
4
  * Cleaned duplicated label in widget
1
 
2
+ = New in 1.1.15 =
3
+ * Fixes the duplicated hreflang links in <head>
4
+
5
+ = New in 1.1.14 =
6
+
7
+ The menu widget didn't allow the visitors to change to the default language if qtranslate-x was being used. So, adjusted the Language Menu widget to play nice with qtranslate-x.
8
+ Hope to bring some nice changes that were made in the github repository in the next version. For now, enjoy.
9
+
10
+
11
  = 1.1.13 =
12
  == Thanks to returning @pedro-mendonca for these commits: ==
13
  * Cleaned duplicated label in widget