Qtranslate Slug - Version 1.1.10

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

Code changes from version 1.1.9 to 1.1.10

README.txt DELETED
@@ -1,213 +0,0 @@
1
- === Qtranslate Slug ===
2
- Contributors: Carlos Sanz García
3
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SYC46KSLRC4Q8
4
- Tags: qtranslate, slug, multilanguage
5
- Requires at least: 3.3
6
- Tested up to: 4.1.0
7
- Stable tag: 1.1.8
8
- License: GPLv2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
-
11
- Adds support for permalink translations and fix some QTranslate deficiencies since wordpress 3.0
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.
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
-
19
- = Requirements: =
20
-
21
- * Wordpress 3.3 (PHP 5.2 and MySQL 5)
22
- * mQtranslate 2.6.2.4 or Qtranslate 2.5.8 ( soon qtranslate-x too )
23
-
24
- = New in version 1.1.8 =
25
-
26
- Many thanks to everyone that contributed to this update, for their commits, bug reports and for simply using it
27
-
28
- * Portuguese translation and fixed some translation bugs ( thanks pedro-mendonca )
29
- * removed mqtranslate switcher widget hook
30
- * Updated the plugin structure and coding style
31
- * solve some conflicts with search and pagination queries
32
- * Settings php errors, syntax indent and fixed settings assets url
33
- * Change titles when there is a click on pagination on show all pages tab ( thanks juanfran-granados )
34
- * Formatted dependency notice message ( thanks arildm )
35
- * Updated the deprecated jquery 'live' function and solve php strict standards error ( thanks rafitaFCB )
36
- * Fixed error showing if PHP was newer than 5.3 ( thanks rafitaFCB )
37
- * Strict standard advise prevented ( thanks rafitaFCB )
38
- * php notices are prevented in post edit, when using adding new translated tags ( thanks rafitaFCB )
39
- * fixed the hreflang issue! 'bout time!
40
- * As discussed in issue #25, the flags are now img tags, intead of background-url.
41
- * Added another option to include the css style in a minified file. ( and also showing in the option screen the styles we would use.)
42
-
43
-
44
- **Advice: If you're using a multisite installation, you will must activate qtranslate plugins by separately on each site.**
45
-
46
- You can also check the [project website](http://not-only-code.github.com/qtranslate-slug/) hosted on [GitHub](http://not-only-code.github.com).
47
- Thanks for use this plugin!
48
-
49
- = Contributors =
50
-
51
- * [Pedro de Carvalho](https://github.com/LC43/)
52
- * [Risto Niinemets](https://github.com/RistoNiinemets)
53
- * [Pedro Mendonça](https://github.com/pedro-mendonca)
54
- * [codep0et](https://github.com/codep0et)
55
- * [Giraldi Maggio](https://github.com/bedex78)
56
- * [jinoOM](https://github.com/jinoOM)
57
- * [Juanfran](https://github.com/juanfran-granados)
58
- * [Arild](https://github.com/arildm)
59
- * [Rafa Aguilar](https://github.com/rafitaFCB)
60
-
61
-
62
- == Installation ==
63
- **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.**
64
-
65
- 1. Upload `qtranslate-slug` to the `/wp-content/plugins/` directory.
66
- 1. Activate the plugin through the 'Plugins' menu in WordPress.
67
- 1. That's all!
68
-
69
- = Changing base permastructs =
70
-
71
- 1. In admin: navigate to *Settings/Slug options*.
72
- 1. Set the base permastructs for **post types** and **taxonomies** (If you setup a base permastruct for *categories* or *tags* in *Settings/Permalinks*, these will be overwritten by the translated ones).
73
- 1. Save settings and that's all!
74
-
75
- == Frequently Asked Questions ==
76
-
77
- = It works with posts and pages, but with other content type? =
78
-
79
- This plugin allows to translate slugs of: posts, pages, custom post types, categories, tags and custom taxonomies.
80
-
81
- = Do I have to configure anything? =
82
-
83
- If you want to translate also the base permastructs (ex. *category*, *tag*, etc). Visit the plugin settings page in the admin *Settings/Slug options*
84
-
85
- = How can i insert a language selector in my theme ? =
86
-
87
- You can choose to:
88
- * use **Qtranslate Slug Widget** in your sidebar.
89
- * place in your template `<?php if (function_exists('qts_language_menu') ) qts_language_menu('text'); ?>`. Options are: `dropdown`, `text`, `image`, and `both`.
90
-
91
- = Appears an error 404, what can i do? =
92
-
93
- In the admin go to *Settings/Permalinks* or *Settings/Slug options* and save.
94
-
95
- = I can't manage translations in Nav Menus. =
96
-
97
- 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.
98
-
99
- == Screenshots ==
100
-
101
- 1. Edit page for: post / page / post_type, you can see the meta box for translated slugs on top and right.
102
- 2. Add new taxonomy page
103
- 3. Edit taxonomy page
104
- 4. Qtranslate Slug options page for translate base permastructs of post_types and taxonomies.
105
-
106
- == Changelog ==
107
-
108
- = 1.1.8 =
109
-
110
- Many thanks to everyone that contributed to this update, for their commits, bug reports and for simply using it
111
-
112
- * Portuguese translation and fixed some translation bugs ( thanks pedro-mendonca )
113
- * removed mqtranslate switcher widget hook
114
- * Updated the plugin structure and coding style
115
- * solve some conflicts with search and pagination queries
116
- * Settings php errors, syntax indent and fixed settings assets url
117
- * Change titles when there is a click on pagination on show all pages tab ( thanks juanfran-granados )
118
- * Formatted dependency notice message ( thanks arildm )
119
- * Updated the deprecated jquery 'live' function and solve php strict standards error ( thanks rafitaFCB )
120
- * Fixed error showing if PHP was newer than 5.3 ( thanks rafitaFCB )
121
- * Strict standard advise prevented ( thanks rafitaFCB )
122
- * php notices are prevented in post edit, when using adding new translated tags ( thanks rafitaFCB )
123
- * fixed the hreflang issue! 'bout time!
124
- * As discussed in issue #25, the flags are now img tags, intead of background-url.
125
- * Added another option to include the css style in a minified file. ( and also showing in the option screen the styles we would use.)
126
-
127
- = 1.1.7 =
128
- * removed styles from html elements and added options to use .css file or print inline styles
129
- * fixed tag creation on post edit.
130
- * fixed earlier bad post slug introduced in 1.1.6
131
-
132
- = 1.1.6 =
133
- * compatible with mqtranslate
134
- * php5.4+ compatible
135
-
136
- = 1.1.5 =
137
- * bugfixes
138
-
139
- = 1.1 =
140
- * added multisite support
141
- * fixed some parse url bugs
142
- * fixed slug bases validation
143
-
144
- = 1.0 =
145
- * **works** with any permalink combination and qtranslate mode.
146
- * new branch, the plugin has been rewritten: now the code is commented and wrapped inside a class, much code has change and the performance has been increased (use caches).
147
- * data system changed, no ID for slug type, then it don't needs install `qtrasnlate_slug` table. That means slugs now are stored on meta tables and installation creates a termmeta table with some new *core functions* to access/save data, based on [simple term meta](http://wordpress.org/extend/plugins/simple-term-meta/). Upgrade process when the plugin updates from older versions.
148
- * the plugin generates translated slug automatically from title in empty cases.
149
- * the plugin checks if the slug already exists (per each language and `post_type`/`taxonomy`), and adds a progressive number in this case. Works on ajax requests for example when new taxonomies are created in edit post page.
150
- * possibility to translate the base of permastructs for *post_types* and *taxonomies*, uses [$wp_rewrite](http://codex.wordpress.org/Class_Reference/WP_Rewrite). New admin options page for save the base permastructs.
151
- * added some filters, see in [other notes](http://wordpress.org/extend/plugins/qtranslate-slug/other_notes/).
152
- * added plugin language textdomain (.pot file).
153
- * updated **Language selector Widget**, and some new conventions like accessible functions for templating.
154
- * some bug fixes.
155
- * some Qtranslate patches.
156
-
157
- = 0.9 =
158
- * some wordpress qTranslate bug fixes
159
- * adds a javascript solution for qTranslate Nav Menus
160
-
161
- = 0.8 =
162
- * added support por Categories
163
- * added support por Tags
164
- * added support por Taxonomies
165
- * added support por Custom Post Types
166
-
167
- = 0.7 = [Zapo](http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=4&t=1049&start=50#p7499)
168
- * added suport for qTranslate TLD domain mode (en: domain.com | fr: domain.fr) visit
169
-
170
- = 0.5 and 0.6 enhanched by Marco Del Percio =
171
-
172
- == Upgrade Notice ==
173
-
174
- = 1.0 =
175
- Major version, the plugin has been rewritten. Better performance, and some enhancements.
176
-
177
- = 0.9 =
178
- This version fix some bugs and allow multilanguage in nav-menus.
179
-
180
- = 0.8 =
181
- A lot of slugs content allowed
182
-
183
- = 0.7 =
184
- This version allows TLD domain option for a different Qtranslate fork maded by Zappo
185
-
186
-
187
- == Other notes ==
188
-
189
- Plugin filters reference:
190
-
191
- = qts_validate_post_slug =
192
- filter to process the post slug before is saved on the database.
193
- `args: $post (object), $slug (string), $lang (string)`
194
-
195
- = qts_validate_term_slug =
196
- filter to process the term slug before is saved on the database.
197
- `args: $term (object), $slug (string), $lang (string)`
198
-
199
- = qts_url_args =
200
- filter to process the entire url after it has been generated.
201
- `args: $url (string), $lang (string)`
202
-
203
- = qts_permastruct =
204
- filter to process the permastruct, used for change the base.
205
- `args: $permastruct (string), $name (string)`
206
-
207
-
208
- = Todo =
209
-
210
- * detect Slug for each language and redirect accordingly in parse_query.
211
- * expand qtranslate for translate attachment names and descriptions ( useful for galleries )
212
- * translate other slugs like attachments.
213
- * qtranslate integration with other plugins like Jigoshop, e-commerce, etc. Addapt **$wp_rewrite**.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/js/qts-nav-menu-min.js CHANGED
@@ -1 +1 @@
1
- jQuery(document).ready(function(t){function i(){t(".item-title").each(function(){n[t(this).closest("li").attr("id")]=[],n[t(this).closest("li").attr("id")].Title=t(this).find("span").html(),"undefined"==typeof n[t(this).closest("li").attr("id")].Original&&(n[t(this).closest("li").attr("id")].Original=n[t(this).closest("li").attr("id")].Title)}),t(".menu-item").each(function(){this_label=t(this).find("input.edit-menu-item-title"),this_title=t(this).find("input.edit-menu-item-attr-title"),n[t(this).attr("id")][this_label.attr("id")]=this_label.val(),n[t(this).attr("id")][this_title.attr("id")]=this_title.val()})}function e(){regexp=new RegExp("<!--:"+d+"-->(.*?)<!--:-->","i"),t(".item-title").each(function(){(matches=n[t(this).closest("li").attr("id")].Original.match(regexp))&&t(this).closest("li").find(".link-to-original a").text(matches[1])}),regexp2=new RegExp("<!--:"+d+"-->(.*?)<!--:-->","i"),t(".menu-item").each(function(){this_label=t(this).find("input.edit-menu-item-title"),this_title=t(this).find("input.edit-menu-item-attr-title"),"all"===d?(this_label.val(n[t(this).attr("id")][this_label.attr("id")]),this_title.val(n[t(this).attr("id")][this_title.attr("id")])):((matches=n[t(this).attr("id")][this_label.attr("id")].match(regexp2))&&this_label.val(matches[1]),(matches2=n[t(this).attr("id")][this_title.attr("id")].match(regexp2))&&this_title.val(matches2[1]))})}function a(){t(".menu-item").each(function(){this_label=t(this).find("input.edit-menu-item-title"),this_title=t(this).find("input.edit-menu-item-attr-title"),this_label.val(n[t(this).attr("id")][this_label.attr("id")]),this_title.val(n[t(this).attr("id")][this_title.attr("id")]),t(this).find(".link-to-original a").text(n[t(this).closest("li").attr("id")].Original)})}var n=[],s=wpNavMenu.addMenuItemToBottom;wpNavMenu.addMenuItemToBottom=function(t,a){s(t,a),i(),e()};var l=wpNavMenu.addMenuItemToTop;wpNavMenu.addMenuItemToTop=function(t,a){l(t,a),i(),e()};var d=t("#qt-languages :radio:checked").val();i(),e(),t(document).ajaxComplete(function(){d=t("#qt-languages :radio:checked").val(),e()}),t("#qt-languages :radio").change(function(){d=t("#qt-languages :radio:checked").val(),e()}),t(".submit-add-to-menu").click(function(){d=t("#qt-languages :radio:checked").val(),e()}),t(document.body).on("change","input.edit-menu-item-title",null,function(){regexp=new RegExp("<!--:"+d+"-->(.*?)<!--:-->","i");var i=n[t(this).closest("li").attr("id")][t(this).attr("id")],e=t(this).val();regexp.test(i)&&(n[t(this).closest("li").attr("id")][t(this).attr("id")]=i.replace(regexp,"<!--:"+d+"-->"+e+"<!--:-->"))}),t(document.body).on("change","input.edit-menu-item-attr-title",null,function(){regexp=new RegExp("<!--:"+d+"-->(.*?)<!--:-->","i");var i=n[t(this).closest("li").attr("id")][t(this).attr("id")],e=t(this).val();qts_new_string="<!--:"+d+"-->"+e+"<!--:-->","undefined"==typeof i||""==i?(n[t(this).closest("li").attr("id")][t(this).attr("id")]=qts_new_string,t(this).val(qts_new_string)):regexp.test(i)?n[t(this).closest("li").attr("id")][t(this).attr("id")]=i.replace(regexp,qts_new_string):(t(this).val(i+qts_new_string),n[t(this).closest("li").attr("id")][t(this).attr("id")]=i+qts_new_string)}),t(".menu-save").click(function(){a()}),window.onbeforeunload=function(){a()}});
1
+ jQuery(document).ready(function(t){function e(){regexp=new RegExp("&lt;!--:"+u+"--&gt;(.*?)&lt;!--:--&gt;","i"),t(".item-title").each(function(){void 0==t(this).data("qt-value")&&t(this).data("qt-value",t(this).html()),(matches=t(this).data("qt-value").match(regexp))&&(t(this).html(matches[1]),t(this).closest("li").find(".link-to-original a").text(matches[1]))}),regexp=new RegExp("<!--:"+u+"-->(.*?)<!--:-->","i"),t("input.edit-menu-item-title").each(function(){void 0==t(this).data("qt-value")&&t(this).data("qt-value",t(this).val()),(matches=t(this).data("qt-value").match(regexp))&&t(this).val(matches[1])}),t("label.menu-item-title").each(function(){var e=t(this).contents().get(1);void 0==t(this).data("qt-value")&&t(this).data("qt-value",e.nodeValue),(matches=t(this).data("qt-value").match(regexp))&&(e.nodeValue=" "+matches[1])})}function a(){t("input.edit-menu-item-title").each(function(){t(this).val(t(this).data("qt-value"))})}var i=wpNavMenu.addMenuItemToBottom;wpNavMenu.addMenuItemToBottom=function(t,a){i(t,a),e()};var n=wpNavMenu.addMenuItemToTop;wpNavMenu.addMenuItemToTop=function(t,a){n(t,a),e()};var u=t("#qt-languages :radio:checked").val();e(),t(document).ajaxComplete(function(){u=t("#qt-languages :radio:checked").val(),e()}),t("#qt-languages :radio").change(function(){u=t("#qt-languages :radio:checked").val(),e()}),t(".submit-add-to-menu").click(function(){u=t("#qt-languages :radio:checked").val(),e()}),t(document.body).on("change","input.edit-menu-item-title",null,function(){regexp=new RegExp("(<!--:"+u+"-->)(.*?)(<!--:-->)","i"),regexp.test(t(this).data("qt-value"))?t(this).data("qt-value",t(this).data("qt-value").replace(regexp,"$1"+t(this).val()+"$3")):t(this).data("qt-value",t(this).val())}),t(".menu-save").click(function(){a()}),window.onbeforeunload=function(){a()}});
assets/js/qts-nav-menu.js CHANGED
@@ -1,39 +1,35 @@
1
  jQuery(document).ready(function($){
2
- var qts_menuitemlang = [];
3
  // Change titles (and values) when user add new item to the menu:
4
  var oldAddMenuItemToBottom = wpNavMenu.addMenuItemToBottom;
5
  wpNavMenu.addMenuItemToBottom = function( menuMarkup, req ) {
6
  oldAddMenuItemToBottom( menuMarkup, req );
7
- saveLang();
8
  changeTitles();
9
  };
10
  var oldAddMenuItemToTop = wpNavMenu.addMenuItemToTop;
11
  wpNavMenu.addMenuItemToTop = function( menuMarkup, req ) {
12
  oldAddMenuItemToTop( menuMarkup, req );
13
- saveLang();
14
  changeTitles();
15
  };
16
 
17
  // Change titles (and values) when document is ready:
18
  var lang = $('#qt-languages :radio:checked').val();
19
- saveLang();
20
  changeTitles();
21
 
22
- /**
23
- * Change titles when there is a click on pagination
24
- * on show all pages tab.
25
- *
26
- * It happens when there are a large number of pages.
27
- */
28
- $( document ).ajaxComplete(function() {
29
- lang = $('#qt-languages :radio:checked').val();
30
- changeTitles();
31
- });
32
 
33
  // Change titles (and values) when language is changed:
34
  $('#qt-languages :radio').change( function() {
35
  lang = $('#qt-languages :radio:checked').val();
36
-
37
  changeTitles();
38
  });
39
 
@@ -45,112 +41,49 @@ jQuery(document).ready(function($){
45
 
46
  // Update original value when user changed a value:
47
  $(document.body).on('change', 'input.edit-menu-item-title', null, function() {
48
- regexp = new RegExp('<!--:' + lang + '-->(.*?)<!--:-->', 'i');
49
-
50
-
51
- var qts_old_value = qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")],
52
- qts_new_value = $(this).val();
53
-
54
- if( regexp.test(qts_old_value ) ) {
55
- qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")] = qts_old_value.replace( regexp,'<!--:' + lang + '-->' + qts_new_value + '<!--:-->');
56
- }
57
-
58
- });
59
-
60
-
61
-
62
-
63
- // Update original title="" value when user changed a value:
64
- $(document.body).on('change', 'input.edit-menu-item-attr-title', null, function() {
65
- regexp = new RegExp('<!--:' + lang + '-->(.*?)<!--:-->', 'i');
66
- var qts_old_value = qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")],
67
- qts_new_value = $(this).val();
68
- qts_new_string = '<!--:' + lang + '-->'+ qts_new_value + '<!--:-->';
69
- if(typeof qts_old_value === "undefined" || qts_old_value == "" ) {
70
- qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")] = qts_new_string;
71
- $(this).val( qts_new_string );
72
- } else if( regexp.test(qts_old_value ) ) {
73
- qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")] = qts_old_value.replace( regexp,qts_new_string);
74
- } else {
75
- $(this).val( qts_old_value + qts_new_string );
76
- qts_menuitemlang[ $(this).closest("li").attr("id") ][ $(this).attr("id")] = qts_old_value + qts_new_string;
77
- }
78
-
79
  });
80
 
81
-
82
-
83
- // Change titles (and values):
84
- function saveLang() {
85
- $('.item-title').each( function() {
86
- qts_menuitemlang[ $(this).closest("li").attr("id") ] = [];
87
- qts_menuitemlang[ $(this).closest("li").attr("id") ]['Title'] = $(this).find("span").html();
88
-
89
- if( typeof qts_menuitemlang[ $(this).closest("li").attr("id") ]['Original'] === "undefined" ) {
90
- qts_menuitemlang[ $(this).closest("li").attr("id") ]['Original'] = qts_menuitemlang[ $(this).closest("li").attr("id") ]['Title'];
91
- }
92
- });
93
- $('.menu-item').each( function() {
94
-
95
- this_label = $(this).find('input.edit-menu-item-title');
96
- this_title = $(this).find('input.edit-menu-item-attr-title');
97
-
98
- qts_menuitemlang[ $(this).attr("id") ][this_label.attr("id") ] = this_label.val();
99
- qts_menuitemlang[ $(this).attr("id") ][this_title.attr("id") ] = this_title.val();
100
-
101
- });
102
-
103
- }
104
  // Change titles (and values):
105
  function changeTitles() {
106
  // Change menu item titles and links (on the right side):
107
- // TODO: review, and dump
108
- regexp = new RegExp('<!--:' + lang + '-->(.*?)<!--:-->', 'i');
109
  $('.item-title').each( function() {
110
- if (matches = qts_menuitemlang[ $(this).closest("li").attr("id") ]['Original'].match(regexp)) {
111
- $(this).closest('li').find('.link-to-original a').text( matches[1] );
112
- }
113
-
 
114
  });
115
- // Change menu item title inputs (on the right side): Navigation Label, Title Attribute...
116
- regexp2 = new RegExp('<!--:' + lang + '-->(.*?)<!--:-->', 'i');
117
- $('.menu-item').each( function() {
118
- this_label = $(this).find('input.edit-menu-item-title');
119
- this_title = $(this).find('input.edit-menu-item-attr-title');
120
- if( lang === "all") {
121
- this_label.val(qts_menuitemlang[ $(this).attr("id") ][this_label.attr("id") ] );
122
- this_title.val(qts_menuitemlang[ $(this).attr("id") ][this_title.attr("id") ] );
123
- } else {
124
-
125
- if (matches = qts_menuitemlang[ $(this).attr("id") ][this_label.attr("id") ].match(regexp2)) {
126
- this_label.val( matches[1] );
127
- }
128
-
129
- if (matches2 = qts_menuitemlang[ $(this).attr("id") ][this_title.attr("id") ].match(regexp2)) {
130
- this_title.val( matches2[1] );
131
- }
132
  }
133
  });
134
 
135
  // Change menu item checkbox labels (on the left side):
136
- // TODO: fix this, not a show stopper
137
- /*$('label.menu-item-title').each( function() {
138
  var textNode = $(this).contents().get(1);
139
- });*/
 
 
 
 
140
  }
141
 
142
  // Restore the original input values:
143
  function restoreValues(){
144
-
145
- $('.menu-item').each( function() {
146
-
147
- this_label = $(this).find('input.edit-menu-item-title');
148
- this_title = $(this).find('input.edit-menu-item-attr-title');
149
-
150
- this_label.val( qts_menuitemlang[ $(this).attr("id") ][this_label.attr("id") ] );
151
- this_title.val( qts_menuitemlang[ $(this).attr("id") ][this_title.attr("id") ] );
152
- $(this).find('.link-to-original a').text( qts_menuitemlang[ $(this).closest("li").attr("id") ]['Original']);
153
- });
154
  }
155
 
156
  // Just before saving restore the original input values:
1
  jQuery(document).ready(function($){
2
+
3
  // Change titles (and values) when user add new item to the menu:
4
  var oldAddMenuItemToBottom = wpNavMenu.addMenuItemToBottom;
5
  wpNavMenu.addMenuItemToBottom = function( menuMarkup, req ) {
6
  oldAddMenuItemToBottom( menuMarkup, req );
 
7
  changeTitles();
8
  };
9
  var oldAddMenuItemToTop = wpNavMenu.addMenuItemToTop;
10
  wpNavMenu.addMenuItemToTop = function( menuMarkup, req ) {
11
  oldAddMenuItemToTop( menuMarkup, req );
 
12
  changeTitles();
13
  };
14
 
15
  // Change titles (and values) when document is ready:
16
  var lang = $('#qt-languages :radio:checked').val();
 
17
  changeTitles();
18
 
19
+ /**
20
+ * Change titles when there is a click on pagination
21
+ * on show all pages tab.
22
+ *
23
+ * It happens when there are a large number of pages.
24
+ */
25
+ $( document ).ajaxComplete(function() {
26
+ lang = $('#qt-languages :radio:checked').val();
27
+ changeTitles();
28
+ });
29
 
30
  // Change titles (and values) when language is changed:
31
  $('#qt-languages :radio').change( function() {
32
  lang = $('#qt-languages :radio:checked').val();
 
33
  changeTitles();
34
  });
35
 
41
 
42
  // Update original value when user changed a value:
43
  $(document.body).on('change', 'input.edit-menu-item-title', null, function() {
44
+ regexp = new RegExp('(<!--:' + lang + '-->)(.*?)(<!--:-->)', 'i');
45
+ if( regexp.test( $(this).data( 'qt-value' ) ) )
46
+ $(this).data( 'qt-value', $(this).data('qt-value').replace( regexp, '$1' + $(this).val() + '$3' ) );
47
+ else
48
+ $(this).data( 'qt-value', $(this).val() );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  });
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  // Change titles (and values):
52
  function changeTitles() {
53
  // Change menu item titles and links (on the right side):
54
+ regexp = new RegExp('&lt;!--:' + lang + '--&gt;(.*?)&lt;!--:--&gt;', 'i');
 
55
  $('.item-title').each( function() {
56
+ if ($(this).data('qt-value') == undefined) $(this).data('qt-value', $(this).html());
57
+ if (matches = $(this).data('qt-value').match(regexp)) {
58
+ $(this).html( matches[1] );
59
+ $(this).closest('li').find('.link-to-original a').text( matches[1] );
60
+ }
61
  });
62
+
63
+ // Change menu item title inputs (on the right side):
64
+ regexp = new RegExp('<!--:' + lang + '-->(.*?)<!--:-->', 'i');
65
+ $('input.edit-menu-item-title').each( function() {
66
+ if ($(this).data('qt-value') == undefined) $(this).data('qt-value', $(this).val());
67
+ if (matches = $(this).data('qt-value').match(regexp)) {
68
+ $(this).val( matches[1] );
 
 
 
 
 
 
 
 
 
 
69
  }
70
  });
71
 
72
  // Change menu item checkbox labels (on the left side):
73
+ $('label.menu-item-title').each( function() {
 
74
  var textNode = $(this).contents().get(1);
75
+ if ($(this).data('qt-value') == undefined) $(this).data('qt-value', textNode.nodeValue);
76
+ if (matches = $(this).data('qt-value').match(regexp)) {
77
+ textNode.nodeValue = ' ' + matches[1];
78
+ }
79
+ });
80
  }
81
 
82
  // Restore the original input values:
83
  function restoreValues(){
84
+ $('input.edit-menu-item-title').each( function() {
85
+ $(this).val( $(this).data( 'qt-value') );
86
+ });
 
 
 
 
 
 
 
87
  }
88
 
89
  // Just before saving restore the original input values:
includes/class-qtranslate-slug-widget.php CHANGED
@@ -8,7 +8,7 @@
8
  class QtranslateSlugWidget extends WP_Widget {
9
 
10
  function QtranslateSlugWidget() {
11
- $widget_ops = array('classname' => 'qts_widget', 'description' => __('Allows your visitors to choose a Language.','qts') );
12
  $this->WP_Widget('qtranslateslug', __('Language selector', 'qts'), $widget_ops);
13
  }
14
 
8
  class QtranslateSlugWidget extends WP_Widget {
9
 
10
  function QtranslateSlugWidget() {
11
+ $widget_ops = array('classname' => 'qts_widget', 'description' => __('Allows your visitors to choose a Language.','qtranslate') );
12
  $this->WP_Widget('qtranslateslug', __('Language selector', 'qts'), $widget_ops);
13
  }
14
 
includes/class-qtranslate-slug.php CHANGED
@@ -49,29 +49,7 @@ class QtranslateSlug {
49
  * @since 1.0
50
  */
51
  private $lang = false;
52
-
53
- /**
54
- * variable for current language
55
- */
56
- private $current_lang = false;
57
 
58
- /**
59
- * Array of enabled languages
60
- *
61
- * @var array
62
- *
63
- * @since 1.0
64
- */
65
- private $enabled_languages = array();
66
- /**
67
- * Array of enabled languages
68
- *
69
- * @var array
70
- *
71
- * @since 1.0
72
- */
73
- private $url_path_mode = "";
74
-
75
 
76
 
77
  /**
@@ -95,16 +73,7 @@ class QtranslateSlug {
95
  private $current_url = array();
96
 
97
 
98
- /**
99
- * Variable that contains the prefix for base plugin function names (qtranslate/qtranslate-x)
100
- *
101
- * @var string
102
- *
103
- * @since ?
104
- */
105
- private $plugin_prefix = "";
106
-
107
-
108
  /**
109
  * return the current / temp language
110
  *
@@ -115,33 +84,7 @@ class QtranslateSlug {
115
 
116
  return ($this->lang) ? $this->lang : $q_config['language'];
117
  }
118
- /**
119
- * return the current / temp language
120
- * we store and use it all the way!
121
- *
122
- * @since 1.1.9
123
- */
124
- private function get_currentlang() {
125
- return $this->current_lang;
126
- }
127
- /**
128
- * return the enabled languages
129
- * we store and use it all the way!
130
- *
131
- * @since 1.1.9
132
- */
133
- private function get_enabled_languages() {
134
- return $this->enabled_languages;
135
- }
136
- /**
137
- * return the enabled languages
138
- * we store and use it all the way!
139
- *
140
- * @since 1.1.9
141
- */
142
- private function get_url_path_mode() {
143
- return $this->url_path_mode;
144
- }
145
 
146
 
147
  /**
@@ -153,17 +96,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.
159
- *
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;
166
- }
167
 
168
 
169
  /**
@@ -186,36 +119,7 @@ class QtranslateSlug {
186
  }
187
  }
188
 
189
- /**
190
- * Sets the prefix for the active fork. See get_plugin_prefix
191
- * @since 1.1.9
192
- *
193
- */
194
- private function set_plugin_prefix(){
195
- if ('' === $this->plugin_prefix){
196
- if (is_plugin_active('qtranslate-x/qtranslate.php')){
197
- $this->plugin_prefix = 'qtranxf_';
198
- } else {
199
- $this->plugin_prefix = 'qtrans_';
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')){
213
- $this->url_path_mode = QTX_URL_PATH;
214
- } else {
215
- $this->url_path_mode = QT_URL_PATH;
216
- }
217
- }
218
- }
219
 
220
  /**
221
  * setter: options | permalink_structure
@@ -266,16 +170,10 @@ class QtranslateSlug {
266
 
267
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
268
 
269
- return (
270
- version_compare($wp_version, "3.3", "<" ) ||
271
- ( !is_plugin_active('qtranslate/qtranslate.php') &&
272
- !is_plugin_active('mqtranslate/mqtranslate.php') &&
273
- !is_plugin_active('qtranslate-x/qtranslate.php'))
274
- );
275
  }
276
 
277
 
278
-
279
 
280
  /**
281
  * check if exists qtranslate and do the installation, support multisite
@@ -483,7 +381,7 @@ class QtranslateSlug {
483
  */
484
  function init() {
485
 
486
- load_plugin_textdomain( 'qts', false, basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages' );
487
 
488
  // checking plugin activate
489
  if ( self::block_activate() ) {
@@ -496,18 +394,9 @@ class QtranslateSlug {
496
  // caching qts options
497
  $this->set_options();
498
 
499
- global $q_config;
500
-
501
- // until we get a proper function, this will make it for it.
502
- $this->current_lang = $q_config['language'];
503
- $this->enabled_languages = $q_config['enabled_languages'];
504
- $this->set_plugin_prefix();
505
- $this->set_url_path_mode();
506
-
507
  if ( is_admin() ) {
508
 
509
  $this->check_old_versions();
510
-
511
 
512
  // add filters
513
  add_filter( 'qts_validate_post_slug', array(&$this, 'validate_post_slug'), 0, 3 );
@@ -551,15 +440,15 @@ class QtranslateSlug {
551
 
552
  // remove from qtranslate the discouraged meta http-equiv, inline styles
553
  // (including flag URLs) and wrong hreflang links
554
- remove_action('wp_head', $this->get_plugin_prefix() . 'header');
555
  // add proper hreflang links
556
  add_action('wp_head',array(&$this, 'qtranslate_slug_header_extended'));
557
 
558
  // remove some Qtranslate filters
559
- remove_filter( 'page_link', $this->get_plugin_prefix() . 'convertURL' );
560
- remove_filter( 'post_link', $this->get_plugin_prefix() . 'convertURL' );
561
- remove_filter( 'category_link', $this->get_plugin_prefix() . 'convertURL' );
562
- remove_filter( 'tag_link', $this->get_plugin_prefix() . 'convertURL' );
563
 
564
  add_filter( 'qts_permastruct' , array(&$this, 'get_extra_permastruct'), 0, 2);
565
  add_filter( 'qts_url_args', array(&$this, 'parse_url_args'), 0, 1);
@@ -569,26 +458,13 @@ class QtranslateSlug {
569
  add_filter( '_get_page_link', array(&$this, '_get_page_link'), 0, 2 );
570
  add_filter( 'term_link', array(&$this, 'term_link'), 600, 3 );
571
 
572
- add_filter( 'single_term_title', $this->get_plugin_prefix() . 'useTermLib', 805 );
573
  add_filter( 'get_blogs_of_user', array(&$this, 'blog_names'), 1 );
574
  add_action( 'widgets_init', array(&$this, 'widget_init'), 100 );
575
  // Add specific CSS class to body class based on current lang
576
  add_filter('body_class', array($this, 'qts_body_class'), 600, 1 );
577
-
578
- add_filter( 'nav_menu_attr_title', array($this, 'qts_filter_attr_title'), 0, 3 );
579
-
580
-
581
  }
582
-
583
- /**
584
- * Filters menu link attribute
585
- *
586
- * @since 1.1.9
587
- */
588
- function qts_filter_attr_title( $attr_title ) {
589
- return $this->qts_quickuse($attr_title);
590
- }
591
-
592
 
593
  /**
594
  * Adds proper links to the content with available translations.
@@ -600,12 +476,13 @@ class QtranslateSlug {
600
  * @since 1.1.8
601
  */
602
  public function qtranslate_slug_header_extended(){
603
- if(is_404()) return;
604
-
605
-
606
- foreach($this->get_enabled_languages() as $language) {
607
- if($language != $this->get_currentlang() )
608
- echo '<link hreflang="'.$language.'" href="'.$this->get_current_url($language).'" rel="alternate" />'."\n";
 
609
  }
610
  }
611
 
@@ -616,131 +493,12 @@ class QtranslateSlug {
616
  */
617
  public function qts_body_class( $classes ) {
618
  // add 'class-name' to the $classes array
619
- $classes[] = call_user_func($this->get_plugin_prefix() . 'getLanguage');
620
 
621
  // return the $classes array
622
  return $classes;
623
  }
624
 
625
- // TODO: properly test this
626
- /**
627
- * Get text in $lang, or in the current lang
628
- *
629
- * @package Qtranslate Slug
630
- * @since 1.1.9
631
- * @param string $text the whole text
632
- * @param string $lang (optional) get the text in this language, or if empty, the current
633
- * @return array the text in the required language
634
- */
635
- public function qts_quickuse( $text,$lang='' ){
636
- global $q_config;
637
- $lang = '' == $lang ? $q_config['language'] : $lang;
638
- $parsed_text = $this->qts_split($text);
639
- if( !empty($parsed_text[$lang])){
640
- return $parsed_text[$lang];
641
- }
642
- }
643
- /**
644
- * Quickly splits text in the different languages, either by
645
- * long tags "<!--:en-->text<!--:-->", or
646
- * ~short tags "[:en]text"~ <- dont support any more.
647
- * NOTE: this is different behaviour from qtrans_split. don't mix long and short
648
- * ANOTHER NOTE: don't mix <!--:en-->text<!--:-->more text.
649
- * @param $text the whole text
650
- * @param bool $quicktag
651
- *
652
- * @package Qtranslate Slug
653
- * @since 1.1.9
654
- */
655
- public function qts_split($text, $quicktags = false ) {
656
-
657
- $result = array();
658
- /* if( $quicktags ) {
659
- $split_regex = "#\[(:[a-z]{2})\]#ism";
660
- $split_texts = preg_split($split_regex, $text, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
661
- $max = count( $split_texts);
662
- for( $i=0 ; $i < $max; $i+=2) {
663
- $result[$split_texts[$i]] = $split_texts[$i+1];
664
- }
665
- return $result;
666
- } else {*/
667
- $split_texts = explode('<!--:-->', $text);
668
- foreach ($split_texts as $split_text) {
669
- if(preg_match("#<!--:([a-z]{2})-->(.*)#i", $split_text, $matches)) {
670
- $result[$matches[1]] = $matches[2];
671
- }
672
- }
673
- //}
674
- return $result;
675
- }
676
-
677
-
678
- /**
679
- *
680
- * Splits and returns the text in the right language.
681
- * Based on https://github.com/xhaleera/mqtranslate
682
- * and https://wordpress.org/support/topic/evidence-on-how-slow-and-inefficient-qtranslate-is-please-do-something
683
- * @param string $lang the language to extr
684
- */
685
- public function qts_use($lang, $text, $show_available=false) {
686
- if (empty($text) || !call_user_func($this->get_plugin_prefix() . 'isEnabled',$lang))
687
- return $text;
688
-
689
- $re = '/<!--:[a-z]{2}-->/i';
690
- // dropping quicktags like a boss
691
- if (is_string($text) && !preg_match($re, $text))
692
- return $text;
693
-
694
- if (is_array($text) || is_object($text)) {
695
- foreach ($text as &$t)
696
- if ($t && ((is_string($t) && preg_match($re, $t)) || is_array($t) || is_object($t)))
697
- $t = $this->qts_use($lang, $t, $show_available);
698
- return $text;
699
- }
700
-
701
-
702
-
703
- // get content
704
- $content = $this->qts_split($text);
705
- // find available languages
706
- $available_languages = array();
707
- foreach($content as $language => $lang_text) {
708
- $lang_text = trim($lang_text);
709
- if(!empty($lang_text)) {
710
- $available_languages[] = $language;
711
- }
712
- }
713
- // if no languages available show full text
714
- if (empty($available_languages))
715
- return $text;
716
-
717
- // if content is available, show the content in the requested language
718
- if (!empty($content[$lang]))
719
- return $content[$lang];
720
- if( $show_available ) {
721
- global $q_config;
722
- // display selection for available languages
723
- $language_list = "";
724
- // Not Available Message + separators
725
- $language_notavailable = explode(":", $q_config['not_available'][$lang] );
726
- if (empty($language_notavailable )) {
727
- $language_url = get_the_permalink();
728
- $normal_separator = $language_notavailable[1];
729
- $end_separator = $language_notavailable[2];
730
- // build available languages string backward
731
- foreach ($available_languages as $k => $language) {
732
- if ($k == 1)
733
- $language_list = $end_separator.$language_list;
734
- else if ($k > 1)
735
- $language_list = $normal_separator.$language_list;
736
- $language_list = "<a href=\"". call_user_func($this->get_plugin_prefix() . 'convertURL',$language_url, $language)."\">".$q_config['language_name'][$language]."</a>".$language_list;
737
- }
738
- }//TODO: fix this! the link isn't updated.
739
- return "<p>".sprintf( $q_config['not_available'][$lang], $language_list)."</p>";
740
- }
741
- return "";
742
-
743
- }
744
  /**
745
  * Adds news rules to translate the URL bases,
746
  * this function must be called on flush_rewrite or 'flush_rewrite_rules'
@@ -750,8 +508,7 @@ class QtranslateSlug {
750
  * @since 1.0
751
  */
752
  public function modify_rewrite_rules() {
753
- // do we need this global?
754
- //global $wp_rewrite;
755
 
756
  // post types rules
757
  $post_types = get_post_types( array('_builtin' => false ), 'objects');
@@ -777,9 +534,9 @@ class QtranslateSlug {
777
  * @since 1.0
778
  */
779
  private function generate_extra_rules( $name = false ) {
780
- global $wp_rewrite;
781
 
782
- foreach ($this->get_enabled_languages() as $lang):
783
 
784
  if ( $base = $this->get_base_slug( $name, $lang) ):
785
 
@@ -833,8 +590,10 @@ class QtranslateSlug {
833
  return false;
834
  }
835
 
836
- if (isset($qts_options[$option_name][$lang])) {
837
- return $qts_options[$option_name][$lang];
 
 
838
  }
839
 
840
  return false;
@@ -946,7 +705,7 @@ class QtranslateSlug {
946
  $req_uri = trim($req_uri, '/');
947
  $req_uri = preg_replace("|^$home_path|", '', $req_uri);
948
  $req_uri = trim($req_uri, '/');
949
- if ($GLOBALS['q_config']['url_mode'] == $this->get_url_path_mode()) {
950
  $req_uri = preg_replace("/^{$GLOBALS['q_config']['language']}(\/|$)/", '', $req_uri);
951
  }
952
  $pathinfo = trim($pathinfo, '/');
@@ -1049,7 +808,8 @@ class QtranslateSlug {
1049
  * @since 1.0
1050
  */
1051
  function filter_request( $query ) {
1052
- global $wp_query, $wp;
 
1053
  if ((isset($wp->matched_query) || empty($query)) && ! isset($query['s']) ) {
1054
  $query = wp_parse_args($wp->matched_query);
1055
  }
@@ -1171,7 +931,7 @@ class QtranslateSlug {
1171
  if ( isset($function) ) {
1172
 
1173
  // parse all languages links
1174
- foreach( $this->get_enabled_languages() as $lang ) {
1175
 
1176
  $this->lang = $lang;
1177
  $this->current_url[$lang] = apply_filters('qts_url_args', call_user_func($function, $id));
@@ -1194,6 +954,7 @@ class QtranslateSlug {
1194
  * @since 1.0
1195
  */
1196
  public function get_current_url( $lang = false ) {
 
1197
 
1198
  if (!$lang) {
1199
  $lang = $this->get_lang();
@@ -1380,7 +1141,7 @@ class QtranslateSlug {
1380
  }
1381
 
1382
  if ( !$ignore_caller ) {
1383
- $url = call_user_func($this->get_plugin_prefix() . 'convertURL', $url, $this->get_lang(), true);
1384
  }
1385
 
1386
  return $url;
@@ -1866,27 +1627,25 @@ class QtranslateSlug {
1866
 
1867
  global $pagenow;
1868
 
1869
-
 
 
 
 
1870
  if ( $pagenow != 'admin-ajax.php' ) {
1871
 
1872
  $meta = get_option('qtranslate_term_name');
1873
- $lang = call_user_func($this->get_plugin_prefix() . 'getLanguage');
1874
-
1875
 
1876
  if ( !empty( $terms ) ) {
1877
- foreach ($terms as $term_index => $term) {
1878
- // after saving, dont do anything
1879
- if( ( isset($_POST['action'] ) && $_POST['action'] == "editedtag") ||
1880
- !is_object( $term ) ) {
1881
- return $terms;
1882
- }
1883
- $termname = $term->name;
1884
- if( isset( $meta[$termname][$lang] ) ) {
1885
- $term->name = $meta[$termname][$lang];
1886
  }
1887
  };
1888
  };
1889
  }
 
1890
  return $terms;
1891
  }
1892
 
@@ -1921,7 +1680,7 @@ class QtranslateSlug {
1921
  $tax = str_replace("'", "", $taxonomy);
1922
 
1923
  $meta = get_option('qtranslate_term_name');
1924
- $lang = call_user_func($this->get_plugin_prefix() . 'getLanguage');
1925
 
1926
  if ( !empty( $terms ) ) {
1927
  foreach ($terms as $term) {
@@ -1938,14 +1697,14 @@ class QtranslateSlug {
1938
 
1939
 
1940
  /**
1941
- * hide quickedit slug
1942
  *
1943
  * @since 1.0
1944
  */
1945
  public function hide_quick_edit() {
1946
  echo "<!-- QTS remove quick edit box -->" . PHP_EOL;
1947
  echo "<style type=\"text/css\" media=\"screen\">" . PHP_EOL;
1948
- echo " .inline-edit-row fieldset.inline-edit-col-left .inline-edit-col *:first-child + label + label { display: none !important }" . PHP_EOL;
1949
  echo "</style>" . PHP_EOL;
1950
  }
1951
 
@@ -2046,7 +1805,7 @@ class QtranslateSlug {
2046
  */
2047
  public function validate_post_slug( $slug, $post, $lang ) {
2048
 
2049
- $post_title = trim($this->qts_use($lang, $_POST['post_title']));
2050
  $post_name = get_post_meta($post->ID, $this->get_meta_key($lang), true);
2051
  if (!$post_name) {
2052
  $post_name = $post->post_name;
@@ -2162,6 +1921,7 @@ class QtranslateSlug {
2162
  * @since 1.0
2163
  */
2164
  public function save_postdata( $post_id, $post ) {
 
2165
 
2166
  $post_type_object = get_post_type_object( $post->post_type);
2167
 
@@ -2173,7 +1933,7 @@ class QtranslateSlug {
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);
@@ -2332,29 +2092,28 @@ class QtranslateSlug {
2332
  * @since 1.0
2333
  */
2334
  public function save_term( $term_id, $tt_id, $taxonomy ) {
2335
-
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
2350
  // the $slug comes from $_POST with the value of the post slug,
2351
  // not with the term slug.
2352
- if ($_POST['action'] == "editpost") {
2353
  // so we use the slug wp gave it
2354
  $term_slug = $term->slug;
2355
  } else {
2356
  // otherwise, its the edit term screen
2357
- $term_slug = $_POST["qts_{$lang}_slug"];
2358
  }
2359
 
2360
  $meta_value = apply_filters( 'qts_validate_term_slug', $term_slug, $term, $lang);
@@ -2390,8 +2149,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'));
@@ -2466,13 +2225,6 @@ class QtranslateSlug {
2466
  if (class_exists('mqTranslateWidget')) {
2467
  unregister_widget('mqTranslateWidget');
2468
  }
2469
- if (class_exists('ppqTranslateWidget')) {
2470
- unregister_widget('ppqTranslateWidget');
2471
- }
2472
-
2473
- if (class_exists('qTranslateXWidget')) {
2474
- unregister_widget('qTranslateXWidget');
2475
- }
2476
 
2477
  register_widget('QtranslateSlugWidget');
2478
  }
@@ -2525,10 +2277,6 @@ class QtranslateSlug {
2525
  echo __($q_config['language_name'][$language], 'qtranslate');
2526
  echo '</label></p>';
2527
  }
2528
- echo '<p style="margin:0 0 5px 0"><input type="radio" style="margin-right:5px" name="wa_qt_lang" value="all" id="wa_gt_lang_999" />';
2529
- echo '<label for="wa_gt_lang_999">';
2530
- echo __('All languages', 'qts');
2531
- echo '</label></p>';
2532
  echo '</p>';
2533
  }
2534
 
@@ -2553,7 +2301,7 @@ class QtranslateSlug {
2553
  );
2554
  $args = wp_parse_args( $args, $defaults );
2555
 
2556
- $languages = call_user_func($this->get_plugin_prefix() . 'getSortedLanguages');
2557
 
2558
  // every type
2559
  switch ( $type ) {
@@ -2588,7 +2336,6 @@ class QtranslateSlug {
2588
  } else {
2589
  $link_class = '';
2590
  $link_content = $language_name;
2591
- $link_flag ='';
2592
  }
2593
  if( $type == 'image' || $type == 'both' ) {
2594
  $link_flag_url = $baseurl . '/'.$q_config['flag_location'].$q_config['flag'][$lang];
49
  * @since 1.0
50
  */
51
  private $lang = false;
 
 
 
 
 
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
 
55
  /**
73
  private $current_url = array();
74
 
75
 
76
+
 
 
 
 
 
 
 
 
 
77
  /**
78
  * return the current / temp language
79
  *
84
 
85
  return ($this->lang) ? $this->lang : $q_config['language'];
86
  }
87
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
 
90
  /**
96
  $this->set_options();
97
  return $this->options;
98
  }
99
+
 
 
 
 
 
 
 
 
 
 
100
 
101
 
102
  /**
119
  }
120
  }
121
 
122
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
 
124
  /**
125
  * setter: options | permalink_structure
170
 
171
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
172
 
173
+ return ( version_compare($wp_version, "3.3", "<" ) || (!is_plugin_active('qtranslate/qtranslate.php') && !is_plugin_active('mqtranslate/mqtranslate.php')) );
 
 
 
 
 
174
  }
175
 
176
 
 
177
 
178
  /**
179
  * check if exists qtranslate and do the installation, support multisite
381
  */
382
  function init() {
383
 
384
+ load_plugin_textdomain( 'qts', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
385
 
386
  // checking plugin activate
387
  if ( self::block_activate() ) {
394
  // caching qts options
395
  $this->set_options();
396
 
 
 
 
 
 
 
 
 
397
  if ( is_admin() ) {
398
 
399
  $this->check_old_versions();
 
400
 
401
  // add filters
402
  add_filter( 'qts_validate_post_slug', array(&$this, 'validate_post_slug'), 0, 3 );
440
 
441
  // remove from qtranslate the discouraged meta http-equiv, inline styles
442
  // (including flag URLs) and wrong hreflang links
443
+ remove_action('wp_head','qtrans_header');
444
  // add proper hreflang links
445
  add_action('wp_head',array(&$this, 'qtranslate_slug_header_extended'));
446
 
447
  // remove some Qtranslate filters
448
+ remove_filter( 'page_link', 'qtrans_convertURL' );
449
+ remove_filter( 'post_link', 'qtrans_convertURL' );
450
+ remove_filter( 'category_link', 'qtrans_convertURL' );
451
+ remove_filter( 'tag_link', 'qtrans_convertURL' );
452
 
453
  add_filter( 'qts_permastruct' , array(&$this, 'get_extra_permastruct'), 0, 2);
454
  add_filter( 'qts_url_args', array(&$this, 'parse_url_args'), 0, 1);
458
  add_filter( '_get_page_link', array(&$this, '_get_page_link'), 0, 2 );
459
  add_filter( 'term_link', array(&$this, 'term_link'), 600, 3 );
460
 
461
+ add_filter( 'single_term_title', 'qtrans_useTermLib', 805 );
462
  add_filter( 'get_blogs_of_user', array(&$this, 'blog_names'), 1 );
463
  add_action( 'widgets_init', array(&$this, 'widget_init'), 100 );
464
  // Add specific CSS class to body class based on current lang
465
  add_filter('body_class', array($this, 'qts_body_class'), 600, 1 );
 
 
 
 
466
  }
467
+
 
 
 
 
 
 
 
 
 
468
 
469
  /**
470
  * Adds proper links to the content with available translations.
476
  * @since 1.1.8
477
  */
478
  public function qtranslate_slug_header_extended(){
479
+ global $qtranslate_slug;
480
+ global $q_config;
481
+ if(is_404()) return;
482
+
483
+ foreach($q_config['enabled_languages'] as $language) {
484
+ if($language != $q_config['language'] )
485
+ echo '<link hreflang="'.$language.'" href="'.$qtranslate_slug->get_current_url($language).'" rel="alternate" />'."\n";
486
  }
487
  }
488
 
493
  */
494
  public function qts_body_class( $classes ) {
495
  // add 'class-name' to the $classes array
496
+ $classes[] = qtrans_getLanguage();
497
 
498
  // return the $classes array
499
  return $classes;
500
  }
501
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502
  /**
503
  * Adds news rules to translate the URL bases,
504
  * this function must be called on flush_rewrite or 'flush_rewrite_rules'
508
  * @since 1.0
509
  */
510
  public function modify_rewrite_rules() {
511
+ global $wp_rewrite;
 
512
 
513
  // post types rules
514
  $post_types = get_post_types( array('_builtin' => false ), 'objects');
534
  * @since 1.0
535
  */
536
  private function generate_extra_rules( $name = false ) {
537
+ global $wp_rewrite, $q_config;
538
 
539
+ foreach ($q_config['enabled_languages'] as $lang):
540
 
541
  if ( $base = $this->get_base_slug( $name, $lang) ):
542
 
590
  return false;
591
  }
592
 
593
+ $option = $qts_options[$option_name][$lang];
594
+
595
+ if (isset($option)) {
596
+ return $option;
597
  }
598
 
599
  return false;
705
  $req_uri = trim($req_uri, '/');
706
  $req_uri = preg_replace("|^$home_path|", '', $req_uri);
707
  $req_uri = trim($req_uri, '/');
708
+ if ($GLOBALS['q_config']['url_mode'] == QT_URL_PATH) {
709
  $req_uri = preg_replace("/^{$GLOBALS['q_config']['language']}(\/|$)/", '', $req_uri);
710
  }
711
  $pathinfo = trim($pathinfo, '/');
808
  * @since 1.0
809
  */
810
  function filter_request( $query ) {
811
+ global $q_config, $wp_query, $wp;
812
+
813
  if ((isset($wp->matched_query) || empty($query)) && ! isset($query['s']) ) {
814
  $query = wp_parse_args($wp->matched_query);
815
  }
931
  if ( isset($function) ) {
932
 
933
  // parse all languages links
934
+ foreach( $q_config['enabled_languages'] as $lang ) {
935
 
936
  $this->lang = $lang;
937
  $this->current_url[$lang] = apply_filters('qts_url_args', call_user_func($function, $id));
954
  * @since 1.0
955
  */
956
  public function get_current_url( $lang = false ) {
957
+ global $q_config;
958
 
959
  if (!$lang) {
960
  $lang = $this->get_lang();
1141
  }
1142
 
1143
  if ( !$ignore_caller ) {
1144
+ $url = qtrans_convertURL($url, $this->get_lang(), true);
1145
  }
1146
 
1147
  return $url;
1627
 
1628
  global $pagenow;
1629
 
1630
+ // Although in post edit page the tags in 'most
1631
+ // used' list are translated, but when saving the
1632
+ // post Wordpress considers the translated tags as
1633
+ // new tags. Due to this issue I skip this 'hack'
1634
+ // for tags in post edit page.
1635
  if ( $pagenow != 'admin-ajax.php' ) {
1636
 
1637
  $meta = get_option('qtranslate_term_name');
1638
+ $lang = qtrans_getLanguage();
 
1639
 
1640
  if ( !empty( $terms ) ) {
1641
+ foreach ($terms as $term) {
1642
+ if( isset( $meta[$term->name][$lang] ) ) {
1643
+ $term->name = $meta[$term->name][$lang];
 
 
 
 
 
 
1644
  }
1645
  };
1646
  };
1647
  }
1648
+
1649
  return $terms;
1650
  }
1651
 
1680
  $tax = str_replace("'", "", $taxonomy);
1681
 
1682
  $meta = get_option('qtranslate_term_name');
1683
+ $lang = qtrans_getLanguage();
1684
 
1685
  if ( !empty( $terms ) ) {
1686
  foreach ($terms as $term) {
1697
 
1698
 
1699
  /**
1700
+ * hide quickedit button ( functionality not supported by qTranslate )
1701
  *
1702
  * @since 1.0
1703
  */
1704
  public function hide_quick_edit() {
1705
  echo "<!-- QTS remove quick edit box -->" . PHP_EOL;
1706
  echo "<style type=\"text/css\" media=\"screen\">" . PHP_EOL;
1707
+ echo " .row-actions .inline.inline.hide-if-no-js { display: none !important }" . PHP_EOL;
1708
  echo "</style>" . PHP_EOL;
1709
  }
1710
 
1805
  */
1806
  public function validate_post_slug( $slug, $post, $lang ) {
1807
 
1808
+ $post_title = trim(qtrans_use($lang, $_POST['post_title']));
1809
  $post_name = get_post_meta($post->ID, $this->get_meta_key($lang), true);
1810
  if (!$post_name) {
1811
  $post_name = $post->post_name;
1921
  * @since 1.0
1922
  */
1923
  public function save_postdata( $post_id, $post ) {
1924
+ global $q_config;
1925
 
1926
  $post_type_object = get_post_type_object( $post->post_type);
1927
 
1933
  return $post_id;
1934
  }
1935
 
1936
+ foreach ($q_config['enabled_languages'] as $lang) {
1937
 
1938
  $meta_name = $this->get_meta_key($lang);
1939
  $meta_value = apply_filters( 'qts_validate_post_slug', $_POST["qts_{$lang}_slug"], $post, $lang);
2092
  * @since 1.0
2093
  */
2094
  public function save_term( $term_id, $tt_id, $taxonomy ) {
2095
+ global $q_config;
2096
+
2097
+ if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) // check autosave
2098
+ || ( !current_user_can('edit_posts') ) ) { // check permission
 
 
2099
  return $term_id;
2100
  }
2101
 
2102
  $term = get_term( $term_id, $taxonomy);
2103
+
2104
+ foreach( $q_config['enabled_languages'] as $lang ) {
2105
 
2106
  $meta_name = $this->get_meta_key($lang);
2107
 
2108
+ //LC43: when at the post edit screen and creating a new tag
2109
  // the $slug comes from $_POST with the value of the post slug,
2110
  // not with the term slug.
2111
+ if ($_POST['action'] == "editpost") {
2112
  // so we use the slug wp gave it
2113
  $term_slug = $term->slug;
2114
  } else {
2115
  // otherwise, its the edit term screen
2116
+ $term_slug = $_POST["qts_term_{$lang}_slug"];
2117
  }
2118
 
2119
  $meta_value = apply_filters( 'qts_validate_term_slug', $term_slug, $term, $lang);
2149
 
2150
  if ($taxonomies) {
2151
  foreach ($taxonomies as $taxonomy ) {
2152
+ add_action( $taxonomy->name.'_add_form', 'qtrans_modifyTermFormFor');
2153
+ add_action( $taxonomy->name.'_edit_form', 'qtrans_modifyTermFormFor');
2154
  add_action( $taxonomy->name.'_add_form', array(&$this, 'show_term_fields'));
2155
  add_action( $taxonomy->name.'_edit_form_fields', array(&$this, 'show_term_fields') );
2156
  add_filter('manage_edit-'.$taxonomy->name.'_columns', array(&$this, 'taxonomy_columns'));
2225
  if (class_exists('mqTranslateWidget')) {
2226
  unregister_widget('mqTranslateWidget');
2227
  }
 
 
 
 
 
 
 
2228
 
2229
  register_widget('QtranslateSlugWidget');
2230
  }
2277
  echo __($q_config['language_name'][$language], 'qtranslate');
2278
  echo '</label></p>';
2279
  }
 
 
 
 
2280
  echo '</p>';
2281
  }
2282
 
2301
  );
2302
  $args = wp_parse_args( $args, $defaults );
2303
 
2304
+ $languages = qtrans_getSortedLanguages();
2305
 
2306
  // every type
2307
  switch ( $type ) {
2336
  } else {
2337
  $link_class = '';
2338
  $link_content = $language_name;
 
2339
  }
2340
  if( $type == 'image' || $type == 'both' ) {
2341
  $link_flag_url = $baseurl . '/'.$q_config['flag_location'].$q_config['flag'][$lang];
includes/qtranslate-slug-settings-options.php CHANGED
@@ -55,6 +55,8 @@ function get_multi_txt_choices($name = false) {
55
  * @return array
56
  */
57
  function qts_options_page_styles() {
 
 
58
 
59
 
60
  $options[] = array(
@@ -70,10 +72,10 @@ function qts_options_page_styles() {
70
  "type" => "multi-radio",
71
  'class' => 'qts-style',
72
  "choices" => array(
73
- __("file", "qts"),
74
- __("minified", "qts"),
75
- __("inline", "qts"),
76
- __("none", "qts")
77
  ),
78
  "std" => "file"
79
  );
@@ -93,6 +95,7 @@ function qts_options_page_styles() {
93
  * @return array
94
  */
95
  function qts_options_page_fields() {
 
96
 
97
  $post_types = get_post_types( array('_builtin' => false, 'public' => true ), 'objects');
98
 
55
  * @return array
56
  */
57
  function qts_options_page_styles() {
58
+ global $q_config;
59
+
60
 
61
 
62
  $options[] = array(
72
  "type" => "multi-radio",
73
  'class' => 'qts-style',
74
  "choices" => array(
75
+ "file",
76
+ "minified",
77
+ "inline",
78
+ "none"
79
  ),
80
  "std" => "file"
81
  );
95
  * @return array
96
  */
97
  function qts_options_page_fields() {
98
+ global $q_config;
99
 
100
  $post_types = get_post_types( array('_builtin' => false, 'public' => true ), 'objects');
101
 
includes/qtranslate-slug-settings.php CHANGED
@@ -583,7 +583,7 @@ function qts_show_settings_page() {
583
 
584
 
585
  ?>
586
- <p><?php _e('If you selected "none", copy and use these styles as you see fit:','qts'); ?> </p>
587
  <textarea name="textarea" rows="10" cols="80"><?php echo $file_styles; ?></textarea>;
588
  <p class="submit">
589
  <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes','qts'); ?>" />
583
 
584
 
585
  ?>
586
+ <p>If you selected "none", copy and use these styles as you see fit:</p>
587
  <textarea name="textarea" rows="10" cols="80"><?php echo $file_styles; ?></textarea>;
588
  <p class="submit">
589
  <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes','qts'); ?>" />
languages/qts-pt_PT.mo CHANGED
Binary file
languages/qts-pt_PT.po CHANGED
@@ -2,17 +2,17 @@
2
  # This file is distributed under the same license as the qTranslate slug package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: qTranslate slug\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/qtranslate-slug\n"
7
  "POT-Creation-Date: 2012-05-27 20:27:55+00:00\n"
8
- "PO-Revision-Date: 2015-01-07 13:02-0000\n"
9
  "Last-Translator: Pedro Mendonça <ped.gaspar@gmail.com>\n"
10
  "Language-Team: Pedro Mendonça <ped.gaspar@gmail.com>\n"
11
  "Language: pt_PT\n"
12
  "MIME-Version: 1.0\n"
13
  "Content-Type: text/plain; charset=UTF-8\n"
14
  "Content-Transfer-Encoding: 8bit\n"
15
- "X-Generator: Poedit 1.7.1\n"
16
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
  "X-Poedit-SourceCharset: UTF-8\n"
18
 
@@ -113,8 +113,8 @@ msgstr "Actualize os seus dados"
113
 
114
  #: qtranslate-slug-settings.php
115
  msgid ""
116
- "There are slugs stored with old data system. Please upgrade your data pressing "
117
- "upgrade button:"
118
  msgstr ""
119
  "Existem URLs com sistema de dados antigo. Por favor actualize os seus dados "
120
  "através do botão actualizar:"
@@ -153,29 +153,31 @@ msgstr ""
153
  #: qtranslate-slug-settings.php
154
  msgid ""
155
  "If you activated previously the <a href=\"options-permalink.php\">pretty "
156
- "permalinks</a>, in this section you can translate the <abbr title=\"en inglés, "
157
- "Universal Resource Locator\">URLs</abbr> <strong>bases</strong> for <a href="
158
- "\"http://codex.wordpress.org/Function_Reference/register_post_type#Arguments"
159
- "\">public</a> post_types, categories, tags and taxonomies."
 
160
  msgstr ""
161
  "Se activou previamente as <a href=\"options-permalink.php\">ligações "
162
  "permanentes</a>, nesta secção poderá traduzir as <strong>bases</strong> das "
163
  "<abbr title=\"em inglês, Universal Resource Locator\">URLs</abbr> para tipos "
164
- "de artigo, categorias, etiquetas e taxonomias <a href=\"http://codex.wordpress."
165
- "org/Function_Reference/register_post_type#Arguments\">públicas</a>."
166
 
167
  #: qtranslate-slug-settings.php
168
  msgid ""
169
- "For example, the post_type <kbd>books</kbd>, in Spanish would be displayed as "
170
- "<code>http://example.org/es/libros/post-type-name/</code>. If you leave this "
171
- "blank will use the default option when you <a href=\"http://codex.wordpress."
172
- "org/Function_Reference/register_post_type\">registered</a> the post_type."
 
173
  msgstr ""
174
  "Por exemplo, o tipo de artigo <kbd>livros</kbd>, em português seria mostrado "
175
  "como <code>http://exemplo.org/pt/livros/nome-de-tipo-de-artigo/</code>. Se "
176
  "deixar isto em branco, será usada a opção por omissão <a href=\"http://codex."
177
- "wordpress.org/Function_Reference/register_post_type\">registada</a> no tipo de "
178
- "artigo."
179
 
180
  #: qtranslate-slug-settings.php
181
  msgid ""
@@ -183,70 +185,15 @@ msgid ""
183
  "as <code>http://example.org/es/categoria/taxonomy-name/</code>. If you leave "
184
  "this blank will use the default option when you <a href=\"http://codex."
185
  "wordpress.org/Function_Reference/register_taxonomy\">registered</a> the "
186
- "taxonomy (if you previously setup a base permastruct for <u>categories</u> or "
187
- "<u>tags</u> in <a href=\"options-permalink.php\">permalinks</a> page, these "
188
- "bases will be overwritten by the translated ones)."
189
  msgstr ""
190
  "Por exemplo, a taxonomia <kbd>categoria</kbd>, em português seria mostrado "
191
  "como <code>http://exemplo.org/pt/categoria/nome-de-taxonomia/</code>. Se "
192
  "deixar isto em branco, será usada a opção por omissão <a href=\"http://codex."
193
  "wordpress.org/Function_Reference/register_taxonomy\">registada</a> na "
194
  "taxonomia (se previamente configurou a base das ligações permanentes para "
195
- "<u>categorias</u> ou <u>etiquetas</u> na página <a href=\"options-permalink.php"
196
- "\">ligações permanentes</a>, estas bases serão sobrepostas pelas traduzidas)."
197
-
198
- #: qtranslate-slug-settings-options.php
199
- msgid "Styles"
200
- msgstr "Estilos"
201
-
202
- #: qtranslate-slug-settings.php
203
- msgid "The default styles are very minimal, and you can include them or not."
204
- msgstr "Os estilos padrão são mínimos, pode incluí-los ou não."
205
-
206
- #: qtranslate-slug-settings-options.php
207
- msgid "Change styles type"
208
- msgstr "Alterar o tipo de estilos"
209
-
210
- #: qtranslate-slug-settings-options.php
211
- msgid "file"
212
- msgstr "ficheiro"
213
-
214
- #: qtranslate-slug-settings-options.php
215
- msgid "minified"
216
- msgstr "minimizado"
217
-
218
- #: qtranslate-slug-settings-options.php
219
- msgid "inline"
220
- msgstr "em linha"
221
-
222
- #: qtranslate-slug-settings-options.php
223
- msgid "none"
224
- msgstr "nenhum"
225
-
226
- #: qtranslate-slug-settings-options.php
227
- msgid "adds a file (qts-default.css) to the theme's header."
228
- msgstr "adiciona um ficheiro (qts-default.css) ao cabeçalho do tema."
229
-
230
- #: qtranslate-slug-settings-options.php
231
- msgid ""
232
- "adds a minified ( slighlty faster) file (qts-default.min.css) to the theme's "
233
- "header."
234
- msgstr ""
235
- "adiciona um ficheiro minimizado (qts-default.min.css), ligeiramente mais "
236
- "rápido, ao cabeçalho do tema."
237
-
238
- #: qtranslate-slug-settings-options.php
239
- msgid "prints the styles directly into the theme's header."
240
- msgstr "exibe os estilos directamente no cabeçalho do tema."
241
-
242
- #: qtranslate-slug-settings-options.php
243
- msgid "neither include not print the default style."
244
- msgstr "nem incluir nem exibir o estilo padrão."
245
-
246
- #: qtranslate-slug-settings.php
247
- msgid "If you selected \"none\", copy and use these styles as you see fit:"
248
- msgstr "Se escolher \"nenhum\", copie e utilize estes estilos como entender:"
249
-
250
- #: class-qtranslate-slug-widget.php
251
- msgid "Allows your visitors to choose a Language."
252
- msgstr "Permite aos visitantes escolher o seu Idioma."
2
  # This file is distributed under the same license as the qTranslate slug package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: qTranslate slug 1.0\n"
6
  "Report-Msgid-Bugs-To: http://wordpress.org/tag/qtranslate-slug\n"
7
  "POT-Creation-Date: 2012-05-27 20:27:55+00:00\n"
8
+ "PO-Revision-Date: 2014-05-22 12:29-0000\n"
9
  "Last-Translator: Pedro Mendonça <ped.gaspar@gmail.com>\n"
10
  "Language-Team: Pedro Mendonça <ped.gaspar@gmail.com>\n"
11
  "Language: pt_PT\n"
12
  "MIME-Version: 1.0\n"
13
  "Content-Type: text/plain; charset=UTF-8\n"
14
  "Content-Transfer-Encoding: 8bit\n"
15
+ "X-Generator: Poedit 1.6.4\n"
16
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
  "X-Poedit-SourceCharset: UTF-8\n"
18
 
113
 
114
  #: qtranslate-slug-settings.php
115
  msgid ""
116
+ "There are slugs stored with old data system. Please upgrade your data "
117
+ "pressing upgrade button:"
118
  msgstr ""
119
  "Existem URLs com sistema de dados antigo. Por favor actualize os seus dados "
120
  "através do botão actualizar:"
153
  #: qtranslate-slug-settings.php
154
  msgid ""
155
  "If you activated previously the <a href=\"options-permalink.php\">pretty "
156
+ "permalinks</a>, in this section you can translate the <abbr title=\"en "
157
+ "inglés, Universal Resource Locator\">URLs</abbr> <strong>bases</strong> for "
158
+ "<a href=\"http://codex.wordpress.org/Function_Reference/"
159
+ "register_post_type#Arguments\">public</a> post_types, categories, tags and "
160
+ "taxonomies."
161
  msgstr ""
162
  "Se activou previamente as <a href=\"options-permalink.php\">ligações "
163
  "permanentes</a>, nesta secção poderá traduzir as <strong>bases</strong> das "
164
  "<abbr title=\"em inglês, Universal Resource Locator\">URLs</abbr> para tipos "
165
+ "de artigo, categorias, etiquetas e taxonomias <a href=\"http://codex."
166
+ "wordpress.org/Function_Reference/register_post_type#Arguments\">públicas</a>."
167
 
168
  #: qtranslate-slug-settings.php
169
  msgid ""
170
+ "For example, the post_type <kbd>books</kbd>, in Spanish would be displayed "
171
+ "as <code>http://example.org/es/libros/post-type-name/</code>. If you leave "
172
+ "this blank will use the default option when you <a href=\"http://codex."
173
+ "wordpress.org/Function_Reference/register_post_type\">registered</a> the "
174
+ "post_type."
175
  msgstr ""
176
  "Por exemplo, o tipo de artigo <kbd>livros</kbd>, em português seria mostrado "
177
  "como <code>http://exemplo.org/pt/livros/nome-de-tipo-de-artigo/</code>. Se "
178
  "deixar isto em branco, será usada a opção por omissão <a href=\"http://codex."
179
+ "wordpress.org/Function_Reference/register_post_type\">registada</a> no tipo "
180
+ "de artigo."
181
 
182
  #: qtranslate-slug-settings.php
183
  msgid ""
185
  "as <code>http://example.org/es/categoria/taxonomy-name/</code>. If you leave "
186
  "this blank will use the default option when you <a href=\"http://codex."
187
  "wordpress.org/Function_Reference/register_taxonomy\">registered</a> the "
188
+ "taxonomy (if you previously setup a base permastruct for <u>categories</u> "
189
+ "or <u>tags</u> in <a href=\"options-permalink.php\">permalinks</a> page, "
190
+ "these bases will be overwritten by the translated ones)."
191
  msgstr ""
192
  "Por exemplo, a taxonomia <kbd>categoria</kbd>, em português seria mostrado "
193
  "como <code>http://exemplo.org/pt/categoria/nome-de-taxonomia/</code>. Se "
194
  "deixar isto em branco, será usada a opção por omissão <a href=\"http://codex."
195
  "wordpress.org/Function_Reference/register_taxonomy\">registada</a> na "
196
  "taxonomia (se previamente configurou a base das ligações permanentes para "
197
+ "<u>categorias</u> ou <u>etiquetas</u> na página <a href=\"options-permalink."
198
+ "php\">ligações permanentes</a>, estas bases serão sobrepostas pelas "
199
+ "traduzidas)."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
languages/qts.pot CHANGED
@@ -143,55 +143,3 @@ msgstr ""
143
  #: qtranslate-slug-settings.php
144
  msgid "For example, the taxonomy <kbd>category</kbd>, in Spanish would be displayed as <code>http://example.org/es/categoria/taxonomy-name/</code>. If you leave this blank will use the default option when you <a href=\"http://codex.wordpress.org/Function_Reference/register_taxonomy\">registered</a> the taxonomy (if you previously setup a base permastruct for <u>categories</u> or <u>tags</u> in <a href=\"options-permalink.php\">permalinks</a> page, these bases will be overwritten by the translated ones)."
145
  msgstr ""
146
-
147
- #: qtranslate-slug-settings-options.php
148
- msgid "Styles"
149
- msgstr ""
150
-
151
- #: qtranslate-slug-settings.php
152
- msgid "The default styles are very minimal, and you can include them or not."
153
- msgstr ""
154
-
155
- #: qtranslate-slug-settings-options.php
156
- msgid "Change styles type"
157
- msgstr ""
158
-
159
- #: qtranslate-slug-settings-options.php
160
- msgid "file"
161
- msgstr ""
162
-
163
- #: qtranslate-slug-settings-options.php
164
- msgid "minified"
165
- msgstr ""
166
-
167
- #: qtranslate-slug-settings-options.php
168
- msgid "inline"
169
- msgstr ""
170
-
171
- #: qtranslate-slug-settings-options.php
172
- msgid "none"
173
- msgstr ""
174
-
175
- #: qtranslate-slug-settings-options.php
176
- msgid "adds a file (qts-default.css) to the theme's header."
177
- msgstr ""
178
-
179
- #: qtranslate-slug-settings-options.php
180
- msgid "adds a minified ( slighlty faster) file (qts-default.min.css) to the theme's header."
181
- msgstr ""
182
-
183
- #: qtranslate-slug-settings-options.php
184
- msgid "prints the styles directly into the theme's header."
185
- msgstr ""
186
-
187
- #: qtranslate-slug-settings-options.php
188
- msgid "neither include not print the default style."
189
- msgstr ""
190
-
191
- #: qtranslate-slug-settings.php
192
- msgid "If you selected \"none\", copy and use these styles as you see fit:"
193
- msgstr ""
194
-
195
- #: class-qtranslate-slug-widget.php
196
- msgid "Allows your visitors to choose a Language."
197
- msgstr ""
143
  #: qtranslate-slug-settings.php
144
  msgid "For example, the taxonomy <kbd>category</kbd>, in Spanish would be displayed as <code>http://example.org/es/categoria/taxonomy-name/</code>. If you leave this blank will use the default option when you <a href=\"http://codex.wordpress.org/Function_Reference/register_taxonomy\">registered</a> the taxonomy (if you previously setup a base permastruct for <u>categories</u> or <u>tags</u> in <a href=\"options-permalink.php\">permalinks</a> page, these bases will be overwritten by the translated ones)."
145
  msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
phpunit.xml DELETED
@@ -1,14 +0,0 @@
1
- <phpunit
2
- bootstrap="tests/bootstrap.php"
3
- backupGlobals="false"
4
- colors="true"
5
- convertErrorsToExceptions="true"
6
- convertNoticesToExceptions="true"
7
- convertWarningsToExceptions="true"
8
- >
9
- <testsuites>
10
- <testsuite>
11
- <directory prefix="test-" suffix=".php">./tests</directory>
12
- </testsuite>
13
- </testsuites>
14
- </phpunit>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
qtranslate-slug-settings-options.php DELETED
@@ -1,178 +0,0 @@
1
- <?php
2
- /**
3
- * Define our settings sections
4
- *
5
- * @package Qtranslate Slug
6
- * @subpackage Settings
7
- * @version 1.0
8
- *
9
- * @return array key=$id, array value=$title in: add_settings_section( $id, $title, $callback, $page );
10
- */
11
- function qts_options_page_sections() {
12
-
13
- $sections = array();
14
- $sections['post_types'] = __('Post types', 'qts');
15
- $sections['taxonomies'] = __('Taxonomies', 'qts');
16
- $sections['styles'] = __('Styles', 'qts');
17
-
18
- return $sections;
19
- }
20
-
21
-
22
-
23
- /**
24
- * Helper for create arrays of choices
25
- *
26
- * @package Qtranslate Slug
27
- * @subpackage Settings
28
- * @version 1.0
29
- *
30
- * @return array
31
- */
32
- function get_multi_txt_choices($name = false) {
33
- global $q_config;
34
-
35
- if (!$name) return array();
36
-
37
- $choices = array();
38
- foreach( $q_config['enabled_languages'] as $key => $lang) {
39
- $label = sprintf( __('Slug (%s)', 'qts'), $q_config['language_name'][$lang] );
40
- $choices[] = "$label|$lang"; // prints: 'Slug (English)|en' ( $name = books )
41
- }
42
-
43
- return $choices;
44
- }
45
-
46
-
47
-
48
- /**
49
- * Define our form fields (settings) for displaying the default styles
50
- *
51
- * @package Qtranslate Slug
52
- * @subpackage Settings
53
- * @version 1.1.7
54
- *
55
- * @return array
56
- */
57
- function qts_options_page_styles() {
58
- global $q_config;
59
-
60
- $options[] = array(
61
- "section" => "styles",
62
- "id" => QTS_PREFIX . "styles",
63
- "title" => __('Change styles type', 'qts'),
64
- "desc" => array(
65
- __("adds a file (qts-default.css) file to the theme's header.", "qts"),
66
- __("prints the styles directly into the theme's header.", "qts"),
67
- __("neither include not print the default style.", "qts")
68
- ),
69
- "type" => "multi-radio",
70
- 'class' => 'qts-style',
71
- "choices" => array(
72
- "file",
73
- "inline",
74
- "none"
75
- ),
76
- "std" => "file"
77
- );
78
-
79
- return $options;
80
- }
81
-
82
-
83
-
84
- /**
85
- * Define our form fields (settings)
86
- *
87
- * @package Qtranslate Slug
88
- * @subpackage Settings
89
- * @version 1.0
90
- *
91
- * @return array
92
- */
93
- function qts_options_page_fields() {
94
- global $q_config;
95
-
96
- $post_types = get_post_types( array('_builtin' => false, 'public' => true ), 'objects');
97
-
98
- // each post type
99
- foreach ($post_types as $post_type):
100
-
101
- $options[] = array(
102
- "section" => "post_types",
103
- "id" => QTS_PREFIX . "post_type_" . $post_type->name,
104
- "title" => $post_type->labels->singular_name,
105
- "desc" => sprintf( __( '<code>http://example.org/<u>%s</u>/some-%s/</code>', 'qts' ), $post_type->name, $post_type->name),
106
- 'class' => 'qts-slug',
107
- "type" => "multi-text",
108
- "choices" => get_multi_txt_choices( $post_type->name),
109
- "std" => ""
110
- );
111
-
112
- endforeach;
113
- // end each post type
114
-
115
- $options[] = array(
116
- "section" => "taxonomies",
117
- "id" => QTS_PREFIX . "taxonomy_category",
118
- "title" => __('Categories'),
119
- "desc" => __( '<code>http://example.org/<u>category</u>/some-category/</code>', 'qts' ),
120
- "type" => "multi-text",
121
- 'class' => 'qts-slug',
122
- "choices" => get_multi_txt_choices('category'),
123
- "std" => ""
124
- );
125
-
126
- $options[] = array(
127
- "section" => "taxonomies",
128
- "id" => QTS_PREFIX . "taxonomy_post_tag",
129
- "title" => __('Tags'),
130
- "desc" => __( '<code>http://example.org/<u>tag</u>/some-tag/</code>', 'qts' ),
131
- "type" => "multi-text",
132
- 'class' => 'qts-slug',
133
- "choices" => get_multi_txt_choices('post_tag'),
134
- "std" => ""
135
- );
136
-
137
-
138
- $taxonomies = get_taxonomies( array( 'public' => true, 'show_ui' => true, '_builtin' => false ), 'object' );
139
-
140
- // each extra taxonomy
141
- foreach ($taxonomies as $taxonomy):
142
-
143
- $options[] = array(
144
- "section" => "taxonomies",
145
- "id" => QTS_PREFIX . "taxonomy_" . $taxonomy->name,
146
- "title" => $taxonomy->labels->singular_name,
147
- "desc" => sprintf( __( '<code>http://example.org/<u>%s</u>/some-%s/</code>', 'qts' ), $taxonomy->name, $taxonomy->name ),
148
- "type" => "multi-text",
149
- 'class' => 'qts-slug',
150
- "choices" => get_multi_txt_choices( $taxonomy->name),
151
- "std" => ""
152
- );
153
-
154
- endforeach;
155
- // end each extra taxonomy
156
-
157
-
158
- return $options;
159
- }
160
-
161
-
162
-
163
- /**
164
- * Contextual Help
165
- *
166
- * @package Qtranslate Slug
167
- * @subpackage Settings
168
- * @version 1.0
169
- *
170
- */
171
- function qts_options_page_contextual_help() {
172
-
173
-
174
- $text = "<h3>" . __('Qtranslate Settings - Contextual Help','qts') . "</h3>";
175
- $text .= "<p>" . __('Contextual help goes here. You may want to use different html elements to format your text as you want.','qts') . "</p>";
176
-
177
- return $text;
178
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
qtranslate-slug-settings.php DELETED
@@ -1,972 +0,0 @@
1
- <?php
2
-
3
- // page settings sections & fields as well as the contextual help text.
4
- include_once('qtranslate-slug-settings-options.php');
5
-
6
-
7
- /**
8
- * Prints upgrade form in Qtranslate Slug admin page
9
- *
10
- * @package Qtranslate Slug
11
- * @subpackage Settings
12
- * @version 1.0
13
- *
14
- * @return array
15
- */
16
- function qts_upgrade() {
17
- global $qtranslate_slug;
18
-
19
- if ( !$qtranslate_slug->check_old_data() ) return;
20
-
21
- echo "<div id=\"qts-upgrade-box\" class=\"updated\" style=\"margin: 15px 0; margin-bottom:25px; padding: 10px\">" . PHP_EOL;
22
-
23
- echo "<h3>" . __('Upgrade your data', 'qts') . "</h3>" . PHP_EOL;
24
- echo "<p>" . __('There are slugs stored with old data system. Please upgrade your data pressing upgrade button:', 'qts') . "</p>" . PHP_EOL;
25
-
26
- echo "<div id=\"qts-upgrade-form\">" . PHP_EOL;
27
- echo "<input type=\"hidden\" id=\"qts-upgrade-action\" name=\"qts-upgrade-action\" value=\"qts-upgrade-check\" />" .PHP_EOL;
28
- echo "<input type=\"hidden\" id=\"qts-upgrade-nonce\" name=\"qts-upgrade-nonce\" value=\"". wp_create_nonce('qts-upgrade') . "\" />" .PHP_EOL;
29
- echo "<p><a id=\"qts-upgrade-button\" href=\"#\" class=\"button-primary\">" . __('upgrade now', 'qts') . "</a><img src=\"".admin_url('images/wpspin_light.gif')."\" class=\"qts-loading\" id=\"qts-loading\" alt=\"\"></p>" . PHP_EOL;
30
- echo "</div></div>" . PHP_EOL;
31
- }
32
-
33
-
34
- /**
35
- * AJAX: upgrade old database to new system
36
- *
37
- * @package Qtranslate Slug
38
- * @subpackage Settings
39
- * @version 1.0
40
- *
41
- * @return boolean
42
- */
43
- function qts_process_old_data( $old_data = null, $type = 'post' ) {
44
- global $wpdb, $qtranslate_slug;
45
-
46
- if ( is_null($old_data) || empty($old_data) ) return 0;
47
- foreach ($old_data as $row) {
48
- switch ($row->qts_type) {
49
- case 1:
50
- case 2:
51
- update_post_meta( $row->qts_id, $qtranslate_slug->get_meta_key($row->qts_lang), $row->qts_slug);
52
- break;
53
- case 3:
54
- case 4:
55
- update_term_meta( $row->qts_id, $qtranslate_slug->get_meta_key($row->qts_lang), $row->qts_slug);
56
- break;
57
- case 5:
58
- if ($type == 'post')
59
- update_post_meta( $row->qts_id, $qtranslate_slug->get_meta_key($row->qts_lang), $row->qts_slug);
60
-
61
- if ($type == 'term')
62
- update_term_meta( $row->qts_id, $qtranslate_slug->get_meta_key($row->qts_lang), $row->qts_slug);
63
- break;
64
- };
65
- }
66
- $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}qtranslate_slug");
67
-
68
- return 1;
69
- }
70
-
71
- function qts_upgrade_response($type = 0, $slug = null) {
72
- switch ( $type ) {
73
- default:
74
- case 0:
75
- $response = array(
76
- 'status' => 0,
77
- 'message' => __('Sorry, some error happened. Refresh this page and try again please.', 'qts'),
78
- );
79
- break;
80
-
81
- case 1:
82
- $response = array(
83
- 'status' => 1,
84
- 'message' => __('Congratulations, your data has been upgraded, you are up to date.', 'qts'),
85
- );
86
- break;
87
- case 2:
88
- $response = array(
89
- 'status' => 2,
90
- 'message' => sprintf(__('One step more, select what type of slug is this: <strong>%s</strong>', 'qts'), $slug),
91
- 'options' => array( 'post' => __('Post, Page or Custom post type', 'qts'), 'term' => __('Category, tag or custom taxonomy') )
92
- );
93
- break;
94
- }
95
-
96
- return $response;
97
- }
98
-
99
-
100
-
101
- /**
102
- * AJAX: upgrade old database to new system
103
- *
104
- * @package Qtranslate Slug
105
- * @subpackage Settings
106
- * @version 1.0
107
- *
108
- * @return JSON object
109
- */
110
- function qts_upgrade_check() {
111
- global $qtranslate_slug;
112
-
113
- $old_data = $qtranslate_slug->check_old_data();
114
-
115
- if ( wp_verify_nonce( $_POST['nonce'], 'qts-upgrade') ):
116
-
117
- // if data process to save...
118
- if ($old_data) {
119
-
120
- // if defined data type 5, process to upgrade
121
- if ( isset($_POST['type']) ):
122
-
123
- $res = qts_process_old_data($old_data, $_POST['type']);
124
-
125
- $response = qts_upgrade_response($res);
126
-
127
- else :
128
-
129
- // define wich type of data is 5
130
- $array_of_5 = array();
131
- foreach ( $old_data as $row )
132
- if ( $row->qts_type == 5 ) $array_of_5[] = $row->qts_slug;
133
-
134
- if (!empty($array_of_5)) $response = qts_upgrade_response(2, implode(', ', $array_of_5));
135
-
136
- // if no data type 5, process to upgrade
137
- if (!isset($response)) {
138
- $res = qts_process_old_data($old_data);
139
- $response = qts_upgrade_response($res);
140
- }
141
-
142
- endif;
143
-
144
-
145
- // if not continue
146
- } else {
147
-
148
- $response = qts_upgrade_response();
149
-
150
- }
151
-
152
- else:
153
-
154
- $response = qts_upgrade_response();
155
-
156
- endif;
157
-
158
- // response output
159
- header( "Content-Type: application/json" );
160
- echo json_encode($response);
161
- exit;
162
- }
163
- add_action('wp_ajax_qts-upgrade-check', 'qts_upgrade_check');
164
-
165
-
166
-
167
- /**
168
- * Helper function for defining variables for the current page
169
- *
170
- * @package Qtranslate Slug
171
- * @subpackage Settings
172
- * @version 1.0
173
- *
174
- * @return array
175
- */
176
- function qts_get_settings() {
177
-
178
- $output = array();
179
-
180
- // put together the output array
181
- $output['qts_option_name'] = QTS_OPTIONS_NAME; // the option name as used in the get_option() call.
182
- $output['qts_page_title'] = __('Qtranslate Slug options', 'qts'); // the settings page title
183
- $output['qts_page_sections'] = qts_options_page_sections(); // the settings sections
184
- $output['qts_page_fields'] = qts_options_page_fields(); // the settings fields
185
- $output['qts_page_styles'] = qts_options_page_styles(); // the settings for style
186
-
187
-
188
- $output['qts_contextual_help'] = qts_options_page_contextual_help(); // the contextual help
189
-
190
- return $output;
191
- }
192
-
193
-
194
-
195
- /**
196
- * Helper function for registering our form field settings
197
- *
198
- * @package Qtranslate Slug
199
- * @subpackage Settings
200
- * @version 1.0
201
- *
202
- * src: http://alisothegeek.com/2011/01/wordpress-settings-api-tutorial-1/
203
- * @param (array) $args The array of arguments to be used in creating the field
204
- * @return function call
205
- */
206
- function qts_create_settings_field( $args = array() ) {
207
- // default array to overwrite when calling the function
208
- $defaults = array(
209
- 'id' => 'default_field', // the ID of the setting in our options array, and the ID of the HTML form element
210
- 'title' => 'Default Field', // the label for the HTML form element
211
- 'desc' => 'This is a default description.', // the description displayed under the HTML form element
212
- 'std' => '', // the default value for this setting
213
- 'type' => 'text', // the HTML form element to use
214
- 'section' => 'main_section', // the section this setting belongs to must match the array key of a section in qts_options_page_sections()
215
- 'choices' => array(), // (optional): the values in radio buttons or a drop-down menu
216
- 'class' => '' // the HTML form element class. Is used for validation purposes and may be also use for styling if needed.
217
- );
218
-
219
- // "extract" to be able to use the array keys as variables in our function output below
220
- extract( wp_parse_args( $args, $defaults ) );
221
-
222
- // additional arguments for use in form field output in the function qts_show_form_field!
223
- $field_args = array(
224
- 'type' => $type,
225
- 'id' => $id,
226
- 'desc' => $desc,
227
- 'std' => $std,
228
- 'choices' => $choices,
229
- 'label_for' => $id,
230
- 'class' => $class
231
- );
232
-
233
-
234
-
235
- add_settings_field( $id, $title, 'qts_show_form_field', __FILE__, $section, $field_args );
236
-
237
- }
238
-
239
-
240
-
241
- /**
242
- * Register our setting, settings sections and settings fields
243
- *
244
- * @package Qtranslate Slug
245
- * @subpackage Settings
246
- * @version 1.0
247
- *
248
- */
249
- function qts_register_settings(){
250
-
251
- // get the settings sections array
252
- $settings_output = qts_get_settings();
253
- $qts_option_name = $settings_output['qts_option_name'];
254
-
255
- //setting
256
- register_setting($qts_option_name, $qts_option_name, 'qts_validate_options' );
257
-
258
- //sections
259
- if(!empty($settings_output['qts_page_sections'])){
260
- // call the "add_settings_section" for each!
261
- foreach ( $settings_output['qts_page_sections'] as $id => $title ) {
262
- add_settings_section( $id, $title, 'qts_section_fn', __FILE__);
263
- }
264
- }
265
-
266
- //fields
267
- if(!empty($settings_output['qts_page_fields'])){
268
- // call the "add_settings_field" for each!
269
- foreach ($settings_output['qts_page_fields'] as $option) {
270
- qts_create_settings_field($option);
271
- }
272
- }
273
- //style
274
- if(!empty($settings_output['qts_page_styles'])){
275
- // call the "add_settings_field" for each
276
- foreach ($settings_output['qts_page_styles'] as $styleoption) {
277
- qts_create_settings_field($styleoption);
278
- }
279
- }
280
- }
281
- add_action( 'admin_init', 'qts_register_settings' );
282
-
283
-
284
-
285
- /**
286
- * Group scripts (js & css)
287
- *
288
- * @package Qtranslate Slug
289
- * @subpackage Settings
290
- * @version 1.0
291
- *
292
- */
293
- function qts_settings_scripts() {
294
- global $qtranslate_slug;
295
-
296
- wp_enqueue_style('qts_theme_settings_css', plugins_url( 'assets/css/qts-settings.css' , __FILE__ ) );
297
- wp_enqueue_script( 'qts_theme_settings_js', plugins_url( 'assets/js/qts-settings.js' , __FILE__ ), array('jquery'));
298
-
299
- if ($qtranslate_slug->check_old_data())
300
- wp_enqueue_script('qts_theme_settings_upgrade_js', plugins_url( 'assets/js/qts-settings-upgrade.js' , __FILE__ ), array('jquery') );
301
- }
302
-
303
-
304
-
305
- /**
306
- * The Admin menu page
307
- *
308
- * @package Qtranslate Slug
309
- * @subpackage Settings
310
- * @version 1.0
311
- *
312
- */
313
- function qts_add_menu() {
314
- global $current_screen;
315
-
316
- $settings_output = qts_get_settings();
317
- // collect our contextual help text
318
- $qts_contextual_help = $settings_output['qts_contextual_help'];
319
-
320
- // Display Settings Page link under the "Appearance" Admin Menu
321
- $qts_settings_page = add_options_page(__('Qtranslate Slug options', 'qts'), __('Slug options', 'qts'), 'manage_options', QTS_PAGE_BASENAME, 'qts_show_settings_page');
322
- // contextual help
323
- /*
324
- if ($qts_settings_page) {
325
- $current_screen = get_current_screen();
326
- //$current_screen->add_help_tab( array( $qts_settings_page, $qts_contextual_help ));
327
- }
328
- */
329
- // css & js
330
- add_action( 'load-'. $qts_settings_page, 'qts_settings_scripts' );
331
- }
332
- add_action( 'admin_menu', 'qts_add_menu' );
333
-
334
-
335
-
336
- ////////////////////////////////////////////////////////////////////////////////////////
337
-
338
- // Callback functions
339
-
340
-
341
-
342
- /**
343
- * Section HTML, displayed before the first option
344
- *
345
- * @package Qtranslate Slug
346
- * @subpackage Settings
347
- * @version 1.0
348
- *
349
- * @return echoes output
350
- */
351
- function qts_section_fn($page_section = false) {
352
-
353
- if ( !$page_section || !isset($page_section['id']) ) return;
354
-
355
- switch ($page_section['id']) {
356
- case 'post_types':
357
-
358
- echo "<p>" . __('For example, the post_type <kbd>books</kbd>, in Spanish would be displayed as <code>http://example.org/es/libros/post-type-name/</code>. If you leave this blank will use the default option when you <a href="http://codex.wordpress.org/Function_Reference/register_post_type">registered</a> the post_type.', 'qts') . "</p>";
359
- break;
360
-
361
- case 'taxonomies':
362
-
363
- echo "<p>" . __('For example, the taxonomy <kbd>category</kbd>, in Spanish would be displayed as <code>http://example.org/es/categoria/taxonomy-name/</code>. If you leave this blank will use the default option when you <a href="http://codex.wordpress.org/Function_Reference/register_taxonomy">registered</a> the taxonomy (if you previously setup a base permastruct for <u>categories</u> or <u>tags</u> in <a href="options-permalink.php">permalinks</a> page, these bases will be overwritten by the translated ones).', 'qts') . "</p>";
364
- break;
365
- case 'styles':
366
-
367
- echo "<p>" . __('The default styles are very minimal, and you can include them or not.', 'qts') . "</p>\n";
368
- break;
369
- }
370
- }
371
-
372
-
373
-
374
- /**
375
- * Form Fields HTML: all form field types share the same function
376
- *
377
- * @package Qtranslate Slug
378
- * @subpackage Settings
379
- * @version 1.0
380
- *
381
- * @return echoes output
382
- */
383
- function qts_show_form_field($args = array()) {
384
- global $qtranslate_slug;
385
-
386
- extract( $args );
387
-
388
- // get the settings sections array
389
- $settings_output = qts_get_settings();
390
- $options = $qtranslate_slug->get_options();
391
-
392
- // pass the standard value if the option is not yet set in the database
393
- if ( !isset( $options[$id] ) && 'type' != 'checkbox' ) {
394
- $options[$id] = $std;
395
- }
396
-
397
- // additional field class. output only if the class is defined in the create_setting arguments
398
- $field_class = ($class != '') ? ' ' . $class : '';
399
-
400
- // switch html display based on the setting type.
401
- switch ( $type ) {
402
- case 'text':
403
- $options[$id] = stripslashes($options[$id]);
404
- $options[$id] = esc_attr( $options[$id]);
405
- echo "<input class='regular-text$field_class' type='text' id='$id' name='" . QTS_OPTIONS_NAME . "[$id]' value='$options[$id]' />";
406
- echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
407
- break;
408
-
409
- case "multi-text":
410
- foreach($choices as $item) {
411
-
412
- $item = explode("|",$item); // cat_name|cat_slug
413
- $item[0] = esc_html__($item[0], 'qts');
414
-
415
- if (!empty($options[$id])) {
416
- foreach ($options[$id] as $option_key => $option_val){
417
- if ($item[1] == $option_key) {
418
- $value = $option_val;
419
- }
420
- }
421
- } else {
422
- $value = '';
423
- }
424
-
425
- echo "<span>$item[0]:</span> <input class='$field_class' type='text' id='$id|$item[1]' name='" . QTS_OPTIONS_NAME . "[$id|$item[1]]' value='$value' /><br/>";
426
- }
427
- echo ($desc != '') ? "<span class='description'>$desc</span>" : "";
428
- break;
429
-
430
- case 'textarea':
431
- $options[$id] = stripslashes($options[$id]);
432
- $options[$id] = esc_html( $options[$id]);
433
- echo "<textarea class='textarea$field_class' type='text' id='$id' name='" . QTS_OPTIONS_NAME . "[$id]' rows='5' cols='30'>$options[$id]</textarea>";
434
- echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
435
- break;
436
-
437
- case 'select':
438
- echo "<select id='$id' class='select$field_class' name='" . QTS_OPTIONS_NAME . "[$id]'>";
439
- foreach($choices as $item) {
440
- $value = esc_attr($item, 'qts');
441
- $item = esc_html($item, 'qts');
442
-
443
- $selected = ($options[$id]==$value) ? 'selected="selected"' : '';
444
- echo "<option value='$value' $selected>$item</option>";
445
- }
446
- echo "</select>";
447
- echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
448
- break;
449
-
450
- case 'select2':
451
- echo "<select id='$id' class='select$field_class' name='" . QTS_OPTIONS_NAME . "[$id]'>";
452
- foreach($choices as $item) {
453
-
454
- $item = explode("|",$item);
455
- $item[0] = esc_html($item[0], 'qts');
456
-
457
- $selected = ($options[$id]==$item[1]) ? 'selected="selected"' : '';
458
- echo "<option value='$item[1]' $selected>$item[0]</option>";
459
- }
460
- echo "</select>";
461
- echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
462
- break;
463
-
464
- case 'checkbox':
465
- echo "<input class='checkbox$field_class' type='checkbox' id='$id' name='" . QTS_OPTIONS_NAME . "[$id]' value='1' " . checked( $options[$id], 1, false ) . " />";
466
- echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
467
- break;
468
-
469
- case "multi-checkbox":
470
- foreach($choices as $item) {
471
-
472
- $item = explode("|",$item);
473
- $item[0] = esc_html($item[0], 'qts');
474
-
475
- $checked = '';
476
-
477
- if ( isset($options[$id][$item[1]]) ) {
478
- if ( $options[$id][$item[1]] == 'true') {
479
- $checked = 'checked="checked"';
480
- }
481
- }
482
-
483
- echo "<input class='checkbox$field_class' type='checkbox' id='$id|$item[1]' name='" . QTS_OPTIONS_NAME . "[$id|$item[1]]' value='1' $checked /> $item[0] <br/>";
484
- }
485
- echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
486
- break;
487
-
488
- case "multi-radio":
489
- foreach($choices as $index => $item) {
490
-
491
- $item = explode("|",$item);
492
- $item_key = (count($item) > 1) ? esc_html($item[0], 'qts') : esc_html(end($item), 'qts');
493
- $item_value = (count($item) > 1) ? esc_html($item[1], 'qts') : esc_html(end($item), 'qts');
494
-
495
- $checked = '';
496
-
497
- if ( isset($options[$id]) && $options[$id] === $item_value) {
498
- $checked = 'checked="checked"';
499
- }
500
-
501
- echo "<label for='$id|$item_value'><input class='radio$field_class' type='radio' id='$id|$item_value' name='" . QTS_OPTIONS_NAME . "[$id]' value='$item_value' $checked /> <strong>$item_key</strong>";
502
- if (isset($desc[$index]) && !empty($desc[$index])) {
503
- echo ": " . $desc[$index];
504
- }
505
- echo "</label>";
506
- }
507
- echo (!is_array($desc) && $desc != '') ? "<br /><span class='description'>$desc</span>" : "";
508
- break;
509
- }
510
- }
511
-
512
-
513
-
514
- /**
515
- * Validates base slugs per 'type' (post_type | taxonomy) and 'language'
516
- *
517
- * @package Qtranslate Slug
518
- * @subpackage Settings
519
- * @version 1.0
520
- *
521
- */
522
- function qts_sanitize_bases($base_slugs = false) {
523
-
524
- if ( !$base_slugs || empty($base_slugs) ) return;
525
-
526
- $base_slugs_processed = array();
527
- $base_founded = array();
528
-
529
- // changing array structure
530
- foreach ($base_slugs as $type => $base) {
531
- foreach ($base as $lang => $value) {
532
- if ($value != ""):
533
- $base_value = $value;
534
- $count = 2;
535
- while (in_array($value, $base_founded)) {
536
- $value = "$base_value-$count";
537
- $count++;
538
- }
539
- $base_founded[] = $base_slugs[$type][$lang] = $value;
540
- endif;
541
- }
542
- }
543
-
544
- return $base_slugs;
545
- }
546
-
547
-
548
-
549
- /**
550
- * Admin Settings Page HTML
551
- *
552
- * @package Qtranslate Slug
553
- * @subpackage Settings
554
- * @version 1.0
555
- *
556
- * @return echoes output
557
- */
558
- function qts_show_settings_page() {
559
- // get the settings sections array
560
- $settings_output = qts_get_settings();
561
- ?>
562
- <div class="wrap">
563
- <div class="icon32" id="icon-options-general"></div>
564
- <h2><?php echo $settings_output['qts_page_title']; ?></h2>
565
-
566
- <p><?php _e('If you activated previously the <a href="options-permalink.php">pretty permalinks</a>, in this section you can translate the <abbr title="en inglés, Universal Resource Locator">URLs</abbr> <strong>bases</strong> for <a href="http://codex.wordpress.org/Function_Reference/register_post_type#Arguments">public</a> post_types, categories, tags and taxonomies.', 'qts'); ?> </p>
567
-
568
- <form action="options.php" method="post">
569
- <?php
570
- // upgrade notify
571
- qts_upgrade();
572
- // http://codex.wordpress.org/Function_Reference/settings_fields
573
- settings_fields($settings_output['qts_option_name']);
574
-
575
- // http://codex.wordpress.org/Function_Reference/do_settings_sections
576
- do_settings_sections(__FILE__);
577
- // rewrite rules
578
- flush_rewrite_rules();
579
- ?>
580
-
581
- <p class="submit">
582
- <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes','qts'); ?>" />
583
- </p>
584
-
585
- </form>
586
- </div><!-- wrap -->
587
- <?php }
588
-
589
-
590
-
591
- /**
592
- * Validate input
593
- *
594
- * @package Qtranslate Slug
595
- * @subpackage Settings
596
- * @version 1.0
597
- *
598
- * @return array
599
- */
600
- function qts_validate_options($input) {
601
-
602
- // for enhanced security, create a new empty array
603
- $valid_input = array();
604
-
605
- // collect only the values we expect and fill the new $valid_input array
606
- // i.e. whitelist our option IDs
607
-
608
- // get the settings sections array
609
- $settings_output = qts_get_settings();
610
-
611
- $styleoptions = $settings_output['qts_page_styles'];
612
-
613
- $slugoptions = $settings_output['qts_page_fields'];
614
-
615
- $options = array_merge($styleoptions,$slugoptions);
616
-
617
- // run a foreach and switch on option type
618
- foreach ($options as $option):
619
-
620
- switch ( $option['type'] ):
621
- case 'text':
622
- //switch validation based on the class!
623
- switch ( $option['class'] ) {
624
- //for numeric
625
- case 'numeric':
626
- //accept the input only when numeric!
627
- $input[$option['id']] = trim($input[$option['id']]); // trim whitespace
628
- $valid_input[$option['id']] = (is_numeric($input[$option['id']])) ? $input[$option['id']] : 'Expecting a Numeric value!';
629
-
630
- // register error
631
- if(is_numeric($input[$option['id']]) == FALSE) {
632
- add_settings_error(
633
- $option['id'], // setting title
634
- QTS_PREFIX . '_txt_numeric_error', // error ID
635
- __('Expecting a Numeric value! Please fix.', 'qts'), // error message
636
- 'error' // type of message
637
- );
638
- }
639
- break;
640
-
641
- //for multi-numeric values (separated by a comma)
642
- case 'multinumeric':
643
- //accept the input only when the numeric values are comma separated
644
- $input[$option['id']] = trim($input[$option['id']]); // trim whitespace
645
-
646
- if($input[$option['id']] !=''){
647
- // /^-?\d+(?:,\s?-?\d+)*$/ matches: -1 | 1 | -12,-23 | 12,23 | -123, -234 | 123, 234 | etc.
648
- $valid_input[$option['id']] = (preg_match('/^-?\d+(?:,\s?-?\d+)*$/', $input[$option['id']]) == 1) ? $input[$option['id']] : __('Expecting comma separated numeric values','qts');
649
- }else{
650
- $valid_input[$option['id']] = $input[$option['id']];
651
- }
652
-
653
- // register error
654
- if($input[$option['id']] !='' && preg_match('/^-?\d+(?:,\s?-?\d+)*$/', $input[$option['id']]) != 1) {
655
- add_settings_error(
656
- $option['id'], // setting title
657
- QTS_PREFIX . '_txt_multinumeric_error', // error ID
658
- __('Expecting comma separated numeric values! Please fix.','qts'), // error message
659
- 'error' // type of message
660
- );
661
- }
662
- break;
663
-
664
- //for no html
665
- case 'nohtml':
666
- //accept the input only after stripping out all html, extra white space etc!
667
- $input[$option['id']] = sanitize_text_field($input[$option['id']]); // need to add slashes still before sending to the database
668
- $valid_input[$option['id']] = addslashes($input[$option['id']]);
669
- break;
670
-
671
- //for url
672
- case 'url':
673
- //accept the input only when the url has been sanited for database usage with esc_url_raw()
674
- $input[$option['id']] = trim($input[$option['id']]); // trim whitespace
675
- $valid_input[$option['id']] = esc_url_raw($input[$option['id']]);
676
- break;
677
-
678
- //for email
679
- case 'email':
680
- //accept the input only after the email has been validated
681
- $input[$option['id']] = trim($input[$option['id']]); // trim whitespace
682
- if($input[$option['id']] != ''){
683
- $valid_input[$option['id']] = (is_email($input[$option['id']])!== FALSE) ? $input[$option['id']] : __('Invalid email', 'qts');
684
- }elseif($input[$option['id']] == ''){
685
- $valid_input[$option['id']] = __('This setting field cannot be empty! Please enter a valid email address.', 'qts');
686
- }
687
-
688
- // register error
689
- if(is_email($input[$option['id']])== FALSE || $input[$option['id']] == '') {
690
- add_settings_error(
691
- $option['id'], // setting title
692
- QTS_PREFIX . '_txt_email_error', // error ID
693
- __('Please enter a valid email address.', 'qts'), // error message
694
- 'error' // type of message
695
- );
696
- }
697
- break;
698
-
699
- // a "cover-all" fall-back when the class argument is not set
700
- default:
701
- // accept only a few inline html elements
702
- $allowed_html = array(
703
- 'a' => array('href' => array (),'title' => array ()),
704
- 'b' => array(),
705
- 'em' => array (),
706
- 'i' => array (),
707
- 'strong' => array()
708
- );
709
- // trim whitespace
710
- $input[$option['id']] = trim($input[$option['id']]);
711
- // find incorrectly nested or missing closing tags and fix markup
712
- $input[$option['id']] = force_balance_tags($input[$option['id']]);
713
- // need to add slashes still before sending to the database
714
- $input[$option['id']] = wp_kses( $input[$option['id']], $allowed_html);
715
-
716
- $valid_input[$option['id']] = addslashes($input[$option['id']]);
717
- break;
718
- }
719
- break;
720
-
721
- case "multi-text":
722
- // this will hold the text values as an array of 'key' => 'value'
723
- unset($textarray);
724
-
725
- $text_values = array();
726
- foreach ($option['choices'] as $k => $v ) {
727
- // explode the connective
728
- $pieces = explode("|", $v);
729
-
730
- $text_values[] = $pieces[1];
731
- }
732
-
733
- foreach ($text_values as $v ) {
734
-
735
- // Check that the option isn't empty
736
- if (!empty($input[$option['id'] . '|' . $v])) {
737
- // If it's not null, make sure it's sanitized, add it to an array
738
- switch ($option['class']) {
739
- // different sanitation actions based on the class create you own cases as you need them
740
-
741
- //for numeric input
742
- case 'numeric':
743
- //accept the input only if is numberic!
744
- $input[$option['id'] . '|' . $v]= trim($input[$option['id'] . '|' . $v]); // trim whitespace
745
- $input[$option['id'] . '|' . $v]= (is_numeric($input[$option['id'] . '|' . $v])) ? $input[$option['id'] . '|' . $v] : '';
746
- break;
747
-
748
- case 'qts-slug':
749
- // strip all html tags and white-space.
750
- $type_ = end( explode('_', $option['id']) );
751
- $input[$option['id'] . '|' . $v]= sanitize_title( sanitize_text_field( $input[$option['id'] . '|' . $v] ) );
752
- $input[$option['id'] . '|' . $v]= addslashes($input[$option['id'] . '|' . $v]);
753
- break;
754
-
755
- // a "cover-all" fall-back when the class argument is not set
756
- default:
757
- // strip all html tags and white-space.
758
- $input[$option['id'] . '|' . $v]= sanitize_text_field($input[$option['id'] . '|' . $v]); // need to add slashes still before sending to the database
759
- $input[$option['id'] . '|' . $v]= addslashes($input[$option['id'] . '|' . $v]);
760
- break;
761
- }
762
- // pass the sanitized user input to our $textarray array
763
- $textarray[$v] = $input[$option['id'] . '|' . $v];
764
-
765
- } else {
766
- $textarray[$v] = '';
767
- }
768
- }
769
- // pass the non-empty $textarray to our $valid_input array
770
- if (!empty($textarray)) {
771
- $valid_input[$option['id']] = $textarray;
772
- }
773
- break;
774
-
775
- case 'textarea':
776
- //switch validation based on the class!
777
- switch ( $option['class'] ) {
778
- //for only inline html
779
- case 'inlinehtml':
780
- // accept only inline html
781
- // trim whitespace
782
- $input[$option['id']] = trim($input[$option['id']]);
783
- // find incorrectly nested or missing closing tags and fix markup
784
- $input[$option['id']] = force_balance_tags($input[$option['id']]);
785
- //wp_filter_kses expects content to be escaped!
786
- $input[$option['id']] = addslashes($input[$option['id']]);
787
- //calls stripslashes then addslashes
788
- $valid_input[$option['id']] = wp_filter_kses($input[$option['id']]);
789
- break;
790
-
791
- //for no html
792
- case 'nohtml':
793
- //accept the input only after stripping out all html, extra white space etc!
794
- // need to add slashes still before sending to the database
795
- $input[$option['id']] = sanitize_text_field($input[$option['id']]);
796
- $valid_input[$option['id']] = addslashes($input[$option['id']]);
797
- break;
798
-
799
- //for allowlinebreaks
800
- case 'allowlinebreaks':
801
- //accept the input only after stripping out all html, extra white space etc!
802
- // need to add slashes still before sending to the database
803
- $input[$option['id']] = wp_strip_all_tags($input[$option['id']]);
804
- $valid_input[$option['id']] = addslashes($input[$option['id']]);
805
- break;
806
-
807
- // a "cover-all" fall-back when the class argument is not set
808
- default:
809
- // accept only limited html
810
- //my allowed html
811
- $allowed_html = array(
812
- 'a' => array('href' => array (),'title' => array ()),
813
- 'b' => array(),
814
- 'blockquote' => array('cite' => array ()),
815
- 'br' => array(),
816
- 'dd' => array(),
817
- 'dl' => array(),
818
- 'dt' => array(),
819
- 'em' => array (),
820
- 'i' => array (),
821
- 'li' => array(),
822
- 'ol' => array(),
823
- 'p' => array(),
824
- 'q' => array('cite' => array ()),
825
- 'strong' => array(),
826
- 'ul' => array(),
827
- 'h1' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
828
- 'h2' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
829
- 'h3' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
830
- 'h4' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
831
- 'h5' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
832
- 'h6' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ())
833
- );
834
-
835
- $input[$option['id']] = trim($input[$option['id']]); // trim whitespace
836
- $input[$option['id']] = force_balance_tags($input[$option['id']]); // find incorrectly nested or missing closing tags and fix markup
837
- $input[$option['id']] = wp_kses( $input[$option['id']], $allowed_html); // need to add slashes still before sending to the database
838
- $valid_input[$option['id']] = addslashes($input[$option['id']]);
839
- break;
840
- }
841
- break;
842
-
843
- case 'select':
844
- // check to see if the selected value is in our approved array of values!
845
- $valid_input[$option['id']] = (in_array( $input[$option['id']], $option['choices']) ? $input[$option['id']] : '' );
846
- break;
847
-
848
- case 'select2':
849
- // process $select_values
850
- $select_values = array();
851
- foreach ($option['choices'] as $k => $v) {
852
- // explode the connective
853
- $pieces = explode("|", $v);
854
-
855
- $select_values[] = $pieces[1];
856
- }
857
- // check to see if selected value is in our approved array of values!
858
- $valid_input[$option['id']] = (in_array( $input[$option['id']], $select_values) ? $input[$option['id']] : '' );
859
- break;
860
-
861
- case 'checkbox':
862
- // if it's not set, default to null!
863
- if (!isset($input[$option['id']])) {
864
- $input[$option['id']] = null;
865
- }
866
- // Our checkbox value is either 0 or 1
867
- $valid_input[$option['id']] = ( $input[$option['id']] == 1 ? 1 : 0 );
868
- break;
869
-
870
- case 'multi-checkbox':
871
- unset($checkboxarray);
872
- $check_values = array();
873
- foreach ($option['choices'] as $k => $v ) {
874
- // explode the connective
875
- $pieces = explode("|", $v);
876
-
877
- $check_values[] = $pieces[1];
878
- }
879
-
880
- foreach ($check_values as $v ) {
881
-
882
- // Check that the option isn't null
883
- if (!empty($input[$option['id'] . '|' . $v])) {
884
- // If it's not null, make sure it's true, add it to an array
885
- $checkboxarray[$v] = 'true';
886
- }
887
- else {
888
- $checkboxarray[$v] = 'false';
889
- }
890
- }
891
- // Take all the items that were checked, and set them as the main option
892
- if (!empty($checkboxarray)) {
893
- $valid_input[$option['id']] = $checkboxarray;
894
- }
895
- break;
896
-
897
- case 'multi-radio':
898
- $valid_input[$option['id']] = $input[$option['id']];
899
- break;
900
-
901
- endswitch;
902
-
903
- if( $valid_input[$option['class']] === "qts-slug" )
904
- $valid_input = qts_sanitize_bases($valid_input);
905
- else
906
- $valid_input= $valid_input;
907
-
908
- endforeach;
909
-
910
-
911
-
912
- return $valid_input;
913
- }
914
-
915
-
916
-
917
- /**
918
- * Helper function for creating admin messages
919
- *
920
- * @package Qtranslate Slug
921
- * @subpackage Settings
922
- * @version 1.0
923
- *
924
- * src: http://www.wprecipes.com/how-to-show-an-urgent-message-in-the-wordpress-admin-area
925
- *
926
- * @param (string) $message The message to echo
927
- * @param (string) $msgclass The message class
928
- * @return echoes the message
929
- */
930
- function qts_show_msg($message, $msgclass = 'info') {
931
- echo "<div id='message' class='$msgclass'>$message</div>";
932
- }
933
-
934
-
935
-
936
- /**
937
- * Callback function for displaying admin messages
938
- *
939
- * @package Qtranslate Slug
940
- * @subpackage Settings
941
- * @version 1.0
942
- *
943
- * @return calls qts_show_msg()
944
- */
945
- function qts_admin_msgs() {
946
- global $current_screen;
947
-
948
- // check for our settings page - need this in conditional further down
949
- $qts_settings_pg = isset($_GET['page']) ? strpos($_GET['page'], QTS_PAGE_BASENAME) : '';
950
- // collect setting errors/notices:
951
- // http://codex.wordpress.org/Function_Reference/get_settings_errors
952
- $set_errors = get_settings_errors();
953
-
954
- // display admin message only for the admin to see, only on our settings page
955
- // and only when setting errors/notices are returned!
956
- if(current_user_can ('manage_options') && $qts_settings_pg !== false && !empty($set_errors)){
957
-
958
- // have our settings succesfully been updated?
959
- if($set_errors[0]['code'] == 'settings_updated' && isset($_GET['settings-updated'])){
960
- qts_show_msg("<p>" . $set_errors[0]['message'] . "</p>", 'updated');
961
-
962
- // have errors been found?
963
- }else{
964
- // there maybe more than one so run a foreach loop.
965
- foreach($set_errors as $set_error){
966
- // set the title attribute to match the error "setting title" - need this in js file
967
- qts_show_msg("<p class='setting-error-message' title='" . $set_error['setting'] . "'>" . $set_error['message'] . "</p>", 'error');
968
- }
969
- }
970
- }
971
- }
972
- add_action('admin_notices', 'qts_admin_msgs');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.9
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.10
7
  Author: Carlos Sanz Garcia, Pedro Carvalho
8
  Author URI: http://github.com/not-only-code
9
  */
readme.md DELETED
@@ -1,209 +0,0 @@
1
- # Qtranslate Slug
2
-
3
- ![Qtranslate Slug logo](http://codingsomething.files.wordpress.com/2013/01/qts-logo.png?w=200)
4
-
5
- Adds support for permalink translations and fix some QTranslate deficiencies since wordpress 3.0
6
-
7
- ## Description
8
-
9
- [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.
10
-
11
- **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 integrated with Wordpress API.
12
-
13
- **Requirements:**
14
-
15
- * Wordpress 3.3 (PHP 5.2 and MySQL 5)
16
- * mQtranslate 2.6.2.4 or Qtranslate 2.5.8
17
-
18
- ## New in Version 1.1.8
19
-
20
- Many thanks to everyone that contributed to this update, for their commits, bug reports and for simply using it
21
-
22
- * Portuguese translation and fixed some translation bugs ( thanks pedro-mendonca )
23
- * removed mqtranslate switcher widget hook
24
- * Updated the plugin structure and coding style
25
- * solve some conflicts with search and pagination queries
26
- * Settings php errors, syntax indent and fixed settings assets url
27
- * Change titles when there is a click on pagination on show all pages tab ( thanks juanfran-granados )
28
- * Formatted dependency notice message ( thanks arildm )
29
- * Updated the deprecated jquery 'live' function and solve php strict standards error ( thanks rafitaFCB )
30
- * Fixed error showing if PHP was newer than 5.3 ( thanks rafitaFCB )
31
- * Strict standard advise prevented ( thanks rafitaFCB )
32
- * php notices are prevented in post edit, when using adding new translated tags ( thanks rafitaFCB )
33
- * fixed the hreflang issue! 'bout time!
34
- * As discussed in issue #25, the flags are now img tags, intead of background-url.
35
- * Added another option to include the css style in a minified file. ( and also showing in the option screen the styles we would use.)
36
-
37
- ## New in version 1.1.7
38
- * removed styles from html elements and added options to use .css file or print inline styles
39
- * fixed tag creation on post edit.
40
- * fixed earlier bad post slug introduced in 1.1.6
41
-
42
- **Advice: If you're using a multisite installation, you will must activate qtranslate plugins by separately on each site.**
43
-
44
- You can also check the [project website](http://not-only-code.github.com/qtranslate-slug/) hosted on [GitHub](http://not-only-code.github.com).
45
- Thanks for use this plugin!
46
-
47
- ## Contributors
48
-
49
- * [Pedro de Carvalho](https://github.com/LC43/)
50
- * [Risto Niinemets](https://github.com/RistoNiinemets)
51
- * [Pedro Mendonça](https://github.com/pedro-mendonca)
52
- * [codep0et](https://github.com/codep0et)
53
- * [Giraldi Maggio](https://github.com/gmaggio)
54
- * [jinoOM](https://github.com/jinoOM)
55
- * [Juanfran](https://github.com/juanfran-granados)
56
- * [Arild](https://github.com/arildm)
57
- * [Rafa Aguilar](https://github.com/rafitaFCB)
58
-
59
-
60
- ## Installation
61
-
62
- **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.**
63
-
64
- 1. Upload `qtranslate-slug` to the `/wp-content/plugins/` directory.
65
- 1. Activate the plugin through the 'Plugins' menu in WordPress.
66
- 1. That's all!
67
-
68
- ## Testing
69
-
70
- 1. Install [wp-cli](http://wp-cli.org/)
71
- 1. Follow this instrucctions **ommiting 2nd step**: [Plugin Unit Tests](https://github.com/wp-cli/wp-cli/wiki/Plugin-Unit-Tests).
72
-
73
- ## Changing base permastructs
74
-
75
- 1. In admin: navigate to *Settings/Slug options*.
76
- 1. Set the base permastructs for **post types** and **taxonomies** (If you setup a base permastruct for *categories* or *tags* in *Settings/Permalinks*, these will be overwritten by the translated ones).
77
- 1. Save settings and that's all!
78
-
79
- ## Frequently Asked Questions
80
-
81
- **It works with posts and pages, but with other content type?**
82
-
83
- This plugin allows to translate slugs of: posts, pages, custom post types, categories, tags and custom taxonomies.
84
-
85
- **Do I have to configure anything?**
86
-
87
- If you want to translate also the base permastructs (ex. *category*, *tag*, etc). Visit the plugin settings page in the admin *Settings/Slug options*
88
-
89
- **How can i insert a language selector in my theme ?**
90
-
91
- You can choose to:
92
- * use **Qtranslate Slug Widget** in your sidebar.
93
- * place in your template `<?php if (function_exists('qts_language_menu') ) qts_language_menu('text'); ?>`. Options are: `dropdown`, `text`, `image`, and `both`.
94
-
95
- **Appears an error 404, what can i do?**
96
-
97
- In the admin go to *Settings/Permalinks* or *Settings/Slug options* and save.
98
-
99
- **I can't manage translations in Nav Menus.**
100
-
101
- 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.
102
-
103
- ## Screenshots
104
-
105
- ![Edit page](https://github.com/not-only-code/qtranslate-slug/raw/trunk/screenshot-1.png)
106
- *Edit page for: post / page / post_type, you can see the meta box for translated slugs on top and right*
107
-
108
- ![Taxonomy page](https://github.com/not-only-code/qtranslate-slug/raw/trunk/screenshot-2.png)
109
- *Add new taxonomy page*
110
-
111
- ![Edit taxonomy page](https://github.com/not-only-code/qtranslate-slug/raw/trunk/screenshot-3.png)
112
- *Edit taxonomy page*
113
-
114
- ![Options page](https://github.com/not-only-code/qtranslate-slug/raw/trunk/screenshot-4.png)
115
- *Qtranslate Slug options page for translate base permastructs of post_types and taxonomies*
116
-
117
- ## Changelog
118
-
119
- **1.1.7**
120
- * removed styles from html elements and added options to use .css file or print inline styles
121
- * fixed tag creation on post edit.
122
- * fixed earlier bad post slug introduced in 1.1.6
123
-
124
- **1.1.6**
125
- * compatible with mqtranslate
126
- * php5.4+ compatible
127
-
128
- **1.1.5**
129
- * bugfixes
130
-
131
- **1.1**
132
- * added multisite support
133
- * fixed some parse url bugs
134
- * fixed slug bases validation
135
-
136
- **1.0**
137
- * **works** with any permalink combination and qtranslate mode.
138
- * new branch, the plugin has been rewritten: now the code is commented and wrapped inside a class, much code has change and the performance has been increased (use caches).
139
- * data system changed, no ID for slug type, then it don't needs install `qtrasnlate_slug` table. That means slugs now are stored on meta tables and installation creates a termmeta table with some new *core functions* to access/save data, based on [simple term meta](http://wordpress.org/extend/plugins/simple-term-meta/). Upgrade process when the plugin updates from older versions.
140
- * the plugin generates translated slug automatically from title in empty cases.
141
- * the plugin checks if the slug already exists (per each language and `post_type`/`taxonomy`), and adds a progressive number in this case. Works on ajax requests for example when new taxonomies are created in edit post page.
142
- * possibility to translate the base of permastructs for *post_types* and *taxonomies*, uses [$wp_rewrite](http://codex.wordpress.org/Class_Reference/WP_Rewrite). New admin options page for save the base permastructs.
143
- * added some filters, see in [other notes](http://wordpress.org/extend/plugins/qtranslate-slug/other_notes/).
144
- * added plugin language textdomain (.pot file).
145
- * updated **Language selector Widget**, and some new conventions like accessible functions for templating.
146
- * some bug fixes.
147
- * some Qtranslate patches.
148
-
149
- **0.9**
150
- * some wordpress qTranslate bug fixes
151
- * adds a javascript solution for qTranslate Nav Menus
152
-
153
- **0.8**
154
- * added support por Categories
155
- * added support por Tags
156
- * added support por Taxonomies
157
- * added support por Custom Post Types
158
-
159
- **0.7** [Zapo](http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=4&t=1049&start=50#p7499)
160
- * added suport for qTranslate TLD domain mode (en: domain.com | fr: domain.fr) visit
161
-
162
- **0.5 and 0.6 enhanched by Marco Del Percio**
163
-
164
- ## Upgrade Notice
165
-
166
- **1.0**
167
- Major version, the plugin has been rewritten. Better performance, and some enhancements.
168
-
169
- **0.9**
170
- This version fix some bugs and allow multilanguage in nav-menus.
171
-
172
- **0.8**
173
- A lot of slugs content allowed
174
-
175
- **0.7**
176
- This version allows TLD domain option for a different Qtranslate fork maded by Zappo
177
-
178
-
179
- ## Other notes
180
-
181
- Plugin filters reference:
182
-
183
- **qts_validate_post_slug**
184
- filter to process the post slug before is saved on the database.
185
-
186
- args: $post (object), $slug (string), $lang (string)
187
-
188
- **qts_validate_term_slug**
189
- filter to process the term slug before is saved on the database.
190
-
191
- args: $term (object), $slug (string), $lang (string)
192
-
193
- **qts_url_args**
194
- filter to process the entire url after it has been generated.
195
-
196
- args: $url (string), $lang (string)
197
-
198
- **qts_permastruct**
199
- filter to process the permastruct, used for change the base.
200
-
201
- args: $permastruct (string), $name (string)
202
-
203
-
204
- **Todo**
205
-
206
- * detect Slug for each language and redirect accordingly in parse_query.
207
- * expand qtranslate for translate attachment names and descriptions ( useful for galleries )
208
- * translate other slugs like attachments.
209
- * qtranslate integration with other plugins like Jigoshop, e-commerce, etc. Addapt **$wp_rewrite**.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
5
  Requires at least: 3.3
6
  Tested up to: 4.1
7
- Stable tag: 1.1.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -21,7 +21,7 @@ Adds support for permalink translations and fix some QTranslate deficiencies sin
21
  * Wordpress 3.3 (PHP 5.2 and MySQL 5)
22
  * mQtranslate 2.6.2.4 or Qtranslate 2.5.8 ( soon qtranslate-x too )
23
 
24
- = New in Version 1.1.9 =
25
 
26
  Lots of bug fixes! Thanks again to everyone that contributed to this project, with commits, bug reports and suggestions.
27
 
@@ -33,7 +33,7 @@ Lots of bug fixes! Thanks again to everyone that contributed to this project, wi
33
  * Fixed taxonomies slugs ( thanks to [eirikv's bug report](https://wordpress.org/support/topic/categories-slug-dont-work) )
34
  * Fixed many warnings ( thanks piffpaffpuff, issue #78 and to [pedrodu1](https://wordpress.org/support/topic/warnings-qtranslate-slugphp) )
35
  * 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!! )
36
- * 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).
37
  * Minor fixes, etc.
38
 
39
  See you next Version!
4
  Tags: qtranslate, slug, multilanguage
5
  Requires at least: 3.3
6
  Tested up to: 4.1
7
+ Stable tag: 1.1.10
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
21
  * Wordpress 3.3 (PHP 5.2 and MySQL 5)
22
  * mQtranslate 2.6.2.4 or Qtranslate 2.5.8 ( soon qtranslate-x too )
23
 
24
+ = New in Version 1.1.9 and 1.1.10 =
25
 
26
  Lots of bug fixes! Thanks again to everyone that contributed to this project, with commits, bug reports and suggestions.
27
 
33
  * Fixed taxonomies slugs ( thanks to [eirikv's bug report](https://wordpress.org/support/topic/categories-slug-dont-work) )
34
  * Fixed many warnings ( thanks piffpaffpuff, issue #78 and to [pedrodu1](https://wordpress.org/support/topic/warnings-qtranslate-slugphp) )
35
  * 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!! )
36
+ * 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).
37
  * Minor fixes, etc.
38
 
39
  See you next Version!
termmeta-core.php DELETED
@@ -1,222 +0,0 @@
1
- <?php
2
- /**
3
- * Install Term meta table - setup table, store db version for future updates
4
- */
5
- if ( !function_exists('install_term_meta_table') ):
6
- function install_term_meta_table() {
7
- global $wpdb;
8
-
9
- $collate = '';
10
- if($wpdb->supports_collation()) {
11
- if(!empty($wpdb->charset)) $collate = "DEFAULT CHARACTER SET $wpdb->charset";
12
- if(!empty($wpdb->collate)) $collate .= " COLLATE $wpdb->collate";
13
- }
14
-
15
- $sql = "CREATE TABLE IF NOT EXISTS ". $wpdb->prefix . "termmeta" ." (
16
- `meta_id` bigint(20) NOT NULL AUTO_INCREMENT,
17
- `term_id` bigint(20) NOT NULL DEFAULT '0',
18
- `meta_key` varchar(255) NULL,
19
- `meta_value` longtext NULL,
20
- PRIMARY KEY id (`meta_id`)) $collate;";
21
- $wpdb->query($sql);
22
- }
23
- endif;
24
-
25
-
26
-
27
- function simple_post_meta_define_table() {
28
- global $wpdb;
29
- $wpdb->termmeta = $wpdb->prefix . 'termmeta';
30
- }
31
- add_action( 'init', 'simple_post_meta_define_table' );
32
-
33
-
34
-
35
- /**
36
- * Updates metadata cache for list of term IDs.
37
- *
38
- * Performs SQL query to retrieve the metadata for the term IDs and updates the
39
- * metadata cache for the terms. Therefore, the functions, which call this
40
- * function, do not need to perform SQL queries on their own.
41
- *
42
- * @param array $term_ids List of post IDs.
43
- * @return bool|array Returns false if there is nothing to update or an array of metadata.
44
- */
45
- if ( !function_exists('update_termmeta_cache') ):
46
- function update_termmeta_cache($term_ids) {
47
- return update_meta_cache('term', $term_ids);
48
- }
49
- endif;
50
-
51
-
52
-
53
- /**
54
- * Add meta data field to a term.
55
- *
56
- * @param int $term_id Term ID.
57
- * @param string $key Metadata name.
58
- * @param mixed $value Metadata value.
59
- * @param bool $unique Optional, default is false. Whether the same key should not be added.
60
- * @return bool False for failure. True for success.
61
- */
62
- if ( !function_exists('add_term_meta') ):
63
- function add_term_meta( $term_id, $meta_key, $meta_value, $unique = false ) {
64
- return add_metadata('term', $term_id, $meta_key, $meta_value, $unique);
65
- }
66
- endif;
67
-
68
-
69
-
70
- /**
71
- * Remove metadata matching criteria from a term.
72
- *
73
- * You can match based on the key, or key and value. Removing based on key and
74
- * value, will keep from removing duplicate metadata with the same key. It also
75
- * allows removing all metadata matching key, if needed.
76
- *
77
- * @param int $term_id Term ID
78
- * @param string $meta_key Metadata name.
79
- * @param mixed $meta_value Optional. Metadata value.
80
- * @return bool False for failure. True for success.
81
- */
82
- if ( !function_exists('delete_term_meta') ):
83
- function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
84
- return delete_metadata('term', $term_id, $meta_key, $meta_value);
85
- }
86
- endif;
87
-
88
-
89
-
90
- /**
91
- * Retrieve term meta field for a term.
92
- *
93
- * @param int $term_id Term ID.
94
- * @param string $key The meta key to retrieve.
95
- * @param bool $single Whether to return a single value.
96
- * @return mixed Will be an array if $single is false. Will be value of meta data field if $single
97
- * is true.
98
- */
99
- if ( !function_exists('get_term_meta') ):
100
- function get_term_meta( $term_id, $key, $single = false ) {
101
- return get_metadata('term', $term_id, $key, $single);
102
- }
103
- endif;
104
-
105
-
106
-
107
- /**
108
- * Update term meta field based on term ID.
109
- *
110
- * Use the $prev_value parameter to differentiate between meta fields with the
111
- * same key and term ID.
112
- *
113
- * If the meta field for the term does not exist, it will be added.
114
- *
115
- * @param int $term_id Term ID.
116
- * @param string $key Metadata key.
117
- * @param mixed $value Metadata value.
118
- * @param mixed $prev_value Optional. Previous value to check before removing.
119
- * @return bool False on failure, true if success.
120
- */
121
- if ( !function_exists('update_term_meta') ):
122
- function update_term_meta( $term_id, $meta_key, $meta_value, $prev_value = '' ) {
123
- return update_metadata('term', $term_id, $meta_key, $meta_value, $prev_value);
124
- }
125
- endif;
126
-
127
-
128
-
129
- /**
130
- * Delete everything from term meta matching meta key.
131
- *
132
- * @param string $term_meta_key Key to search for when deleting.
133
- * @return bool Whether the term meta key was deleted from the database
134
- */
135
- if ( !function_exists('delete_term_meta_by_key') ):
136
- function delete_term_meta_by_key($term_meta_key) {
137
- if ( !$term_meta_key )
138
- return false;
139
-
140
- global $wpdb;
141
- $term_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT term_id FROM $wpdb->termmeta WHERE meta_key = %s", $term_meta_key));
142
- if ( $term_ids ) {
143
- $termmetaids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->termmeta WHERE meta_key = %s", $term_meta_key ) );
144
- $in = implode( ',', array_fill(1, count($termmetaids), '%d'));
145
- do_action( 'delete_termmeta', $termmetaids );
146
- $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->termmeta WHERE meta_id IN($in)", $termmetaids ));
147
- do_action( 'deleted_termmeta', $termmetaids );
148
- foreach ( $term_ids as $term_id )
149
- wp_cache_delete($term_id, 'term_meta');
150
- return true;
151
- }
152
- return false;
153
- }
154
- endif;
155
-
156
-
157
-
158
- /**
159
- * Retrieve term meta fields, based on term ID.
160
- *
161
- * The term meta fields are retrieved from the cache, so the function is
162
- * optimized to be called more than once. It also applies to the functions, that
163
- * use this function.
164
- *
165
- * @param int $term_id term ID
166
- * @return array
167
- */
168
- if ( !function_exists('add_term_meta') ):
169
- function get_term_custom( $term_id ) {
170
- $term_id = (int) $term_id;
171
-
172
- if ( ! wp_cache_get($term_id, 'term_meta') )
173
- update_termmeta_cache($term_id);
174
-
175
- return wp_cache_get($term_id, 'term_meta');
176
- }
177
- endif;
178
-
179
-
180
-
181
- /**
182
- * Retrieve meta field names for a term.
183
- *
184
- * If there are no meta fields, then nothing (null) will be returned.
185
- *
186
- * @param int $term_id term ID
187
- * @return array|null Either array of the keys, or null if keys could not be retrieved.
188
- */
189
- if ( !function_exists('get_term_custom_keys') ):
190
- function get_term_custom_keys( $term_id ) {
191
- $custom = get_term_custom( $term_id );
192
-
193
- if ( !is_array($custom) )
194
- return;
195
-
196
- if ( $keys = array_keys($custom) )
197
- return $keys;
198
- }
199
- endif;
200
-
201
-
202
-
203
- /**
204
- * Retrieve values for a custom term field.
205
- *
206
- * The parameters must not be considered optional. All of the term meta fields
207
- * will be retrieved and only the meta field key values returned.
208
- *
209
- * @param string $key Meta field key.
210
- * @param int $term_id Term ID
211
- * @return array Meta field values.
212
- */
213
- if ( !function_exists('get_term_custom_values') ):
214
- function get_term_custom_values( $key = '', $term_id ) {
215
- if ( !$key )
216
- return null;
217
-
218
- $custom = get_term_custom($term_id);
219
-
220
- return isset($custom[$key]) ? $custom[$key] : null;
221
- }
222
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
version.txt CHANGED
@@ -1,3 +1,5 @@
 
 
1
  = 1.1.9 =
2
 
3
  Lots of bug fixes! Thanks again to everyone that contributed to this project, with commits, bug reports and suggestions.
1
+ = 1.1.10 =
2
+
3
  = 1.1.9 =
4
 
5
  Lots of bug fixes! Thanks again to everyone that contributed to this project, with commits, bug reports and suggestions.