Version Description
Many thanks to everyone that contributed to this update, for their commits, bug reports and for simply using it
- Portuguese translation and fixed some translation bugs ( thanks pedro-mendonca )
- removed mqtranslate switcher widget hook
- Updated the plugin structure and coding style
- solve some conflicts with search and pagination queries
- Settings php errors, syntax indent and fixed settings assets url
- Change titles when there is a click on pagination on show all pages tab ( thanks juanfran-granados )
- Formatted dependency notice message ( thanks arildm )
- Updated the deprecated jquery 'live' function and solve php strict standards error ( thanks rafitaFCB )
- Fixed error showing if PHP was newer than 5.3 ( thanks rafitaFCB )
- Strict standard advise prevented ( thanks rafitaFCB )
- php notices are prevented in post edit, when using adding new translated tags ( thanks rafitaFCB )
- fixed the hreflang issue! 'bout time!
- As discussed in issue #25, the flags are now img tags, intead of background-url.
- Added another option to include the css style in a minified file. ( and also showing in the option screen the styles we would use.)
Download this release
Release Info
Developer | pedroghandi |
Plugin | Qtranslate Slug |
Version | 1.1.8 |
Comparing to | |
See all releases |
Code changes from version 1.1.7 to 1.1.8
- README.txt +55 -8
- assets/css/qts-default.css +2 -2
- assets/css/qts-default.min.css +1 -0
- assets/js/qts-nav-menu-min.js +1 -4
- assets/js/qts-nav-menu.js +166 -88
- assets/js/qts-settings-upgrade.js +1 -1
- includes/class-qtranslate-slug-widget.php +63 -0
- includes/class-qtranslate-slug.php +2631 -0
- includes/qtranslate-slug-settings-options.php +179 -0
- includes/qtranslate-slug-settings.php +978 -0
- includes/termmeta-core.php +222 -0
- languages/qts-pt_PT.mo +0 -0
- languages/qts-pt_PT.po +252 -0
- languages/qts.pot +60 -11
- phpunit.xml +14 -0
- qtranslate-slug.php +18 -2298
- readme.md +209 -0
- readme.txt +55 -8
- trunk/README.txt +175 -0
- trunk/assets/css/qts-default.css +16 -0
- trunk/assets/css/qts-default.min.css +1 -0
- trunk/assets/css/qts-settings.css +42 -0
- trunk/assets/js/qts-nav-menu-min.js +1 -0
- trunk/assets/js/qts-nav-menu.js +100 -0
- trunk/assets/js/qts-settings-upgrade.js +69 -0
- trunk/assets/js/qts-settings.js +19 -0
- trunk/includes/class-qtranslate-slug-widget.php +63 -0
- trunk/includes/class-qtranslate-slug.php +2378 -0
- trunk/includes/qtranslate-slug-settings-options.php +182 -0
- trunk/includes/qtranslate-slug-settings.php +978 -0
- trunk/includes/termmeta-core.php +222 -0
- trunk/languages/qts-es_ES.mo +0 -0
- trunk/languages/qts-es_ES.po +142 -0
- trunk/languages/qts-pt_PT.mo +0 -0
- trunk/languages/qts-pt_PT.po +199 -0
- trunk/languages/qts.pot +145 -0
- trunk/phpunit.xml +14 -0
- trunk/qtranslate-slug-settings-options.php +178 -0
- trunk/qtranslate-slug-settings.php +972 -0
- trunk/qtranslate-slug.php +184 -0
- trunk/readme.md +209 -0
- trunk/readme.txt +213 -0
- trunk/screenshot-1.png +0 -0
- trunk/screenshot-2.png +0 -0
- trunk/screenshot-3.png +0 -0
- trunk/screenshot-4.png +0 -0
- trunk/termmeta-core.php +222 -0
- trunk/version.txt +71 -0
- version.txt +19 -0
README.txt
CHANGED
@@ -3,8 +3,8 @@ 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:
|
7 |
-
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -19,19 +19,46 @@ Adds support for permalink translations and fix some QTranslate deficiencies sin
|
|
19 |
= Requirements: =
|
20 |
|
21 |
* Wordpress 3.3 (PHP 5.2 and MySQL 5)
|
22 |
-
* mQtranslate 2.6.2.4 or Qtranslate 2.5.8
|
23 |
|
24 |
-
= New in version 1.1.
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
**Advice: If you're using a multisite installation, you will must activate qtranslate plugins by separately on each site.**
|
30 |
|
|
|
31 |
|
32 |
You can also check the [project website](http://not-only-code.github.com/qtranslate-slug/) hosted on [GitHub](http://not-only-code.github.com).
|
33 |
Thanks for use this plugin!
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
== Installation ==
|
36 |
**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.**
|
37 |
|
@@ -77,6 +104,26 @@ That's because language selector metabox is hidden, if you are in admin *nav men
|
|
77 |
4. Qtranslate Slug options page for translate base permastructs of post_types and taxonomies.
|
78 |
|
79 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
= 1.1.7 =
|
81 |
* removed styles from html elements and added options to use .css file or print inline styles
|
82 |
* fixed tag creation on post edit.
|
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 |
|
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 |
|
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.
|
assets/css/qts-default.css
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
margin-bottom: 7px;
|
11 |
}
|
12 |
.qts_both {
|
13 |
-
padding-left: 25px;
|
14 |
white-space: nowrap;
|
15 |
line-height:1em;
|
16 |
-
}
|
|
10 |
margin-bottom: 7px;
|
11 |
}
|
12 |
.qts_both {
|
|
|
13 |
white-space: nowrap;
|
14 |
line-height:1em;
|
15 |
+
}
|
16 |
+
.qts_both img { margin-right: 4px }
|
assets/css/qts-default.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.qts_type_image .qts_lang_item{float:left;margin-right:7px}.qts_type_image .qts_lang_item.last-child{margin-right:0}.qts_lang_item{margin-top:7px;margin-bottom:7px}.qts_both{white-space:nowrap;line-height:1em}.qts_both img{margin-right:4px}
|
assets/js/qts-nav-menu-min.js
CHANGED
@@ -1,4 +1 @@
|
|
1 |
-
jQuery(document).ready(function(
|
2 |
-
a(this).val());(matches=a(this).data("qt-value").match(regexp))&&a(this).val(matches[1])});a("label.menu-item-title").each(function(){var d=a(this).contents().get(1);void 0==a(this).data("qt-value")&&a(this).data("qt-value",d.nodeValue);if(matches=a(this).data("qt-value").match(regexp))d.nodeValue=" "+matches[1]})}function e(){a("input.edit-menu-item-title").each(function(){a(this).val(a(this).data("qt-value"))})}var f=wpNavMenu.addMenuItemToBottom;wpNavMenu.addMenuItemToBottom=function(a,b){f(a,
|
3 |
-
b);c()};var g=wpNavMenu.addMenuItemToTop;wpNavMenu.addMenuItemToTop=function(a,b){g(a,b);c()};var b=a("#qt-languages :radio:checked").val();c();a("#qt-languages :radio").change(function(){b=a("#qt-languages :radio:checked").val();c()});a(".submit-add-to-menu").click(function(){b=a("#qt-languages :radio:checked").val();c()});a("input.edit-menu-item-title").live("change",function(){regexp=RegExp("(<\!--:"+b+"--\>)(.*?)(<\!--:--\>)","i");regexp.test(a(this).data("qt-value"))?a(this).data("qt-value",
|
4 |
-
a(this).data("qt-value").replace(regexp,"$1"+a(this).val()+"$3")):a(this).data("qt-value",a(this).val())});a(".menu-save").click(function(){e()});window.onbeforeunload=function(){e()}});
|
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()}});
|
|
|
|
|
|
assets/js/qts-nav-menu.js
CHANGED
@@ -1,89 +1,167 @@
|
|
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 |
-
|
8 |
-
|
9 |
-
|
10 |
-
wpNavMenu.addMenuItemToTop
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
});
|
39 |
-
|
40 |
-
// Change titles (and values):
|
41 |
-
function
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
//
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
});
|
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 |
+
|
40 |
+
// Change titles (and values) when new menu is added:
|
41 |
+
$('.submit-add-to-menu').click( function() {
|
42 |
+
lang = $('#qt-languages :radio:checked').val();
|
43 |
+
changeTitles();
|
44 |
+
});
|
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:
|
157 |
+
$('.menu-save').click(function() {
|
158 |
+
restoreValues();
|
159 |
+
});
|
160 |
+
|
161 |
+
// Just before leaving the page (or refresh) restore the original input values:
|
162 |
+
window.onbeforeunload = function(){
|
163 |
+
restoreValues();
|
164 |
+
return;
|
165 |
+
};
|
166 |
+
|
167 |
});
|
assets/js/qts-settings-upgrade.js
CHANGED
@@ -63,7 +63,7 @@ jQuery(document).ready(function($) {
|
|
63 |
package_.type = $('#qts-slug-type').val();
|
64 |
|
65 |
$.post(ajaxurl, package_, check_types);
|
66 |
-
}
|
67 |
|
68 |
upgrade_button.bind('click', start_upgrade);
|
69 |
});
|
63 |
package_.type = $('#qts-slug-type').val();
|
64 |
|
65 |
$.post(ajaxurl, package_, check_types);
|
66 |
+
};
|
67 |
|
68 |
upgrade_button.bind('click', start_upgrade);
|
69 |
});
|
includes/class-qtranslate-slug-widget.php
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* QtranslateSlug_Widget class
|
5 |
+
*
|
6 |
+
* @since 1.0
|
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 |
+
|
15 |
+
function widget($args, $instance) {
|
16 |
+
extract($args);
|
17 |
+
|
18 |
+
echo $before_widget;
|
19 |
+
$title = empty($instance['title']) ? __('Language', 'qtranslate') : apply_filters('widget_title', $instance['title']);
|
20 |
+
$hide_title = empty($instance['hide-title']) ? false : 'on';
|
21 |
+
$type = $instance['type'];
|
22 |
+
$short_text = ($instance['short_text'] == 'on') ? true : false ;
|
23 |
+
|
24 |
+
if( $type!='text' && $type!='image' && $type!='both' && $type!='dropdown' ) $type='text';
|
25 |
+
|
26 |
+
if( $hide_title!='on')
|
27 |
+
echo $before_title . $title . $after_title;
|
28 |
+
|
29 |
+
qts_language_menu($type, array( 'id' => $this->id, 'short' => $short_text ) );
|
30 |
+
|
31 |
+
echo $after_widget;
|
32 |
+
}
|
33 |
+
|
34 |
+
function update($new_instance, $old_instance) {
|
35 |
+
$instance = $old_instance;
|
36 |
+
$instance['title'] = $new_instance['title'];
|
37 |
+
$instance['hide-title'] = $new_instance['hide-title'];
|
38 |
+
$instance['type'] = $new_instance['type'];
|
39 |
+
$instance['short_text'] = $new_instance['short_text'];
|
40 |
+
|
41 |
+
return $instance;
|
42 |
+
}
|
43 |
+
|
44 |
+
function form($instance) {
|
45 |
+
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'hide-title' => false, 'type' => 'text' ) );
|
46 |
+
$title = $instance['title'];
|
47 |
+
$hide_title = $instance['hide-title'];
|
48 |
+
$type = $instance['type'];
|
49 |
+
$short_text = $instance['short_text'];
|
50 |
+
?>
|
51 |
+
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'qtranslate'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
|
52 |
+
<p><label for="<?php echo $this->get_field_id('hide-title'); ?>"><?php _e('Hide Title:', 'qtranslate'); ?> <input type="checkbox" id="<?php echo $this->get_field_id('hide-title'); ?>" name="<?php echo $this->get_field_name('hide-title'); ?>" <?php echo ($hide_title=='on')?'checked="checked"':''; ?>/></label></p>
|
53 |
+
<p><?php _e('Display:', 'qtranslate'); ?></p>
|
54 |
+
<p><label for="<?php echo $this->get_field_id('type'); ?>1"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>1" value="text"<?php echo ($type=='text')?' checked="checked"':'' ?>/> <?php _e('Text only', 'qtranslate'); ?></label></p>
|
55 |
+
<p><label for="<?php echo $this->get_field_id('type'); ?>2"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>2" value="image"<?php echo ($type=='image')?' checked="checked"':'' ?>/> <?php _e('Image only', 'qtranslate'); ?></label></p>
|
56 |
+
<p><label for="<?php echo $this->get_field_id('type'); ?>3"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>3" value="both"<?php echo ($type=='both')?' checked="checked"':'' ?>/> <?php _e('Text and Image', 'qtranslate'); ?></label></p>
|
57 |
+
<p><label for="<?php echo $this->get_field_id('type'); ?>4"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>4" value="dropdown"<?php echo ($type=='dropdown')?' checked="checked"':'' ?>/> <?php _e('Dropdown Box', 'qtranslate'); ?></label></p>
|
58 |
+
<p><label for="<?php echo $this->get_field_id('short_text'); ?>"><?php _e('Show short name (en):', 'qts'); ?> <input type="checkbox" id="<?php echo $this->get_field_id('short_text'); ?>" name="<?php echo $this->get_field_name('short_text'); ?>" <?php checked($short_text, 'on') ?>/></label></p>
|
59 |
+
<p><?php _e('Display:', 'qtranslate'); ?></p>
|
60 |
+
|
61 |
+
<?php
|
62 |
+
}
|
63 |
+
}
|
includes/class-qtranslate-slug.php
ADDED
@@ -0,0 +1,2631 @@
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* QtranslateSlug class
|
5 |
+
*
|
6 |
+
* @since 1.0
|
7 |
+
*/
|
8 |
+
class QtranslateSlug {
|
9 |
+
|
10 |
+
|
11 |
+
/**
|
12 |
+
* array with old data system
|
13 |
+
*
|
14 |
+
* @var bool
|
15 |
+
*
|
16 |
+
* @since 1.0
|
17 |
+
*/
|
18 |
+
private $old_data = null;
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
/**
|
23 |
+
* stores permalink_structure option, for save queries to db
|
24 |
+
*
|
25 |
+
* @var string
|
26 |
+
*
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
private $permalink_structure;
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Stores options slugs from database
|
35 |
+
*
|
36 |
+
* @var array
|
37 |
+
*
|
38 |
+
* @since 1.0
|
39 |
+
*/
|
40 |
+
protected $options;
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Variable used to override the language
|
46 |
+
*
|
47 |
+
* @var string
|
48 |
+
*
|
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 |
+
/**
|
78 |
+
* slug in meta_key name in meta tables
|
79 |
+
*
|
80 |
+
* @var string
|
81 |
+
*
|
82 |
+
* @since 1.0
|
83 |
+
*/
|
84 |
+
private $meta_key = "_qts_slug_%s";
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Array of translated versions of the current url
|
90 |
+
*
|
91 |
+
* @var array
|
92 |
+
*
|
93 |
+
* @since 1.0
|
94 |
+
*/
|
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 |
+
*
|
111 |
+
* @since 1.0
|
112 |
+
*/
|
113 |
+
private function get_lang() {
|
114 |
+
global $q_config;
|
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 |
+
/**
|
148 |
+
* getter: options
|
149 |
+
*
|
150 |
+
* @since 1.0
|
151 |
+
*/
|
152 |
+
public function get_options() {
|
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 |
+
/**
|
170 |
+
* setter: options | permalink_structure
|
171 |
+
*
|
172 |
+
* @since 1.0
|
173 |
+
*/
|
174 |
+
public function set_options() {
|
175 |
+
|
176 |
+
if (empty($this->options)) {
|
177 |
+
$this->options = get_option(QTS_OPTIONS_NAME);
|
178 |
+
}
|
179 |
+
|
180 |
+
if (!$this->options) {
|
181 |
+
add_option(QTS_OPTIONS_NAME, array());
|
182 |
+
}
|
183 |
+
|
184 |
+
if (is_null($this->permalink_structure)) {
|
185 |
+
$this->permalink_structure = get_option('permalink_structure');
|
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
|
222 |
+
*
|
223 |
+
* @since 1.0
|
224 |
+
*/
|
225 |
+
public function save_options($new_options = false) {
|
226 |
+
if (!$new_options || empty($new_options)) {
|
227 |
+
return;
|
228 |
+
}
|
229 |
+
|
230 |
+
if (count($this->options) != count($new_options)) {
|
231 |
+
return;
|
232 |
+
}
|
233 |
+
|
234 |
+
update_option(QTS_OPTIONS_NAME, $new_options);
|
235 |
+
$this->options = $new_options;
|
236 |
+
}
|
237 |
+
|
238 |
+
|
239 |
+
|
240 |
+
/**
|
241 |
+
* getter: meta key
|
242 |
+
*
|
243 |
+
* @since 1.0
|
244 |
+
*/
|
245 |
+
public function get_meta_key( $force_lang = false ) {
|
246 |
+
global $q_config;
|
247 |
+
|
248 |
+
$lang = $this->get_lang();
|
249 |
+
|
250 |
+
if ($force_lang) {
|
251 |
+
$lang = $force_lang;
|
252 |
+
}
|
253 |
+
|
254 |
+
return sprintf($this->meta_key, $lang); // returns: _qts_slug_en
|
255 |
+
}
|
256 |
+
|
257 |
+
|
258 |
+
|
259 |
+
/**
|
260 |
+
* check dependences for activation
|
261 |
+
*
|
262 |
+
* @since 1.0
|
263 |
+
*/
|
264 |
+
static function block_activate() {
|
265 |
+
global $wp_version;
|
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
|
282 |
+
*
|
283 |
+
* @since 1.0
|
284 |
+
*/
|
285 |
+
public function install() {
|
286 |
+
global $wpdb;
|
287 |
+
|
288 |
+
if ( self::block_activate() ) {
|
289 |
+
return;
|
290 |
+
}
|
291 |
+
|
292 |
+
if ( function_exists('is_multisite') && is_multisite() ) {
|
293 |
+
|
294 |
+
if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) {
|
295 |
+
|
296 |
+
$old_blog = $wpdb->blogid;
|
297 |
+
$blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs"));
|
298 |
+
foreach ($blogids as $blog_id) {
|
299 |
+
switch_to_blog($blog_id);
|
300 |
+
$this->activate();
|
301 |
+
}
|
302 |
+
switch_to_blog($old_blog);
|
303 |
+
return;
|
304 |
+
}
|
305 |
+
}
|
306 |
+
|
307 |
+
$this->activate();
|
308 |
+
}
|
309 |
+
|
310 |
+
|
311 |
+
|
312 |
+
/**
|
313 |
+
* activates and do the installation
|
314 |
+
*
|
315 |
+
* @since 1.0
|
316 |
+
*/
|
317 |
+
private function activate() {
|
318 |
+
global $wp_rewrite;
|
319 |
+
|
320 |
+
$this->set_options();
|
321 |
+
|
322 |
+
$qts_version = get_option('qts_version');
|
323 |
+
|
324 |
+
// checks version and do the installation
|
325 |
+
if ( !$qts_version || $qts_version != QTS_VERSION ) {
|
326 |
+
|
327 |
+
// install termmeta table using functions from Simple-Term-Meta
|
328 |
+
// ( http://wordpress.org/extend/plugins/simple-term-meta/ )
|
329 |
+
install_term_meta_table();
|
330 |
+
|
331 |
+
// update installed option
|
332 |
+
update_option('qts_version', QTS_VERSION);
|
333 |
+
}
|
334 |
+
|
335 |
+
// regenerate rewrite rules in db
|
336 |
+
add_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
|
337 |
+
flush_rewrite_rules();
|
338 |
+
}
|
339 |
+
|
340 |
+
|
341 |
+
|
342 |
+
/**
|
343 |
+
* register front end styles and enqueue
|
344 |
+
*
|
345 |
+
* @since 1.1.7
|
346 |
+
*/
|
347 |
+
public function register_plugin_styles() {
|
348 |
+
wp_register_style( 'qts_front_styles', plugins_url( '/assets/css/qts-default.css', dirname(__FILE__ ) ) );
|
349 |
+
wp_enqueue_style( 'qts_front_styles' );
|
350 |
+
}
|
351 |
+
/**
|
352 |
+
* register minified front end styles and enqueue
|
353 |
+
* 43LC: easier duplicating the function :|
|
354 |
+
* @since 1.1.8
|
355 |
+
*/
|
356 |
+
public function register_plugin_styles_min() {
|
357 |
+
wp_register_style( 'qts_front_styles', plugins_url( '/assets/css/qts-default.min.css', dirname(__FILE__ ) ) );
|
358 |
+
wp_enqueue_style( 'qts_front_styles' );
|
359 |
+
}
|
360 |
+
|
361 |
+
|
362 |
+
|
363 |
+
/**
|
364 |
+
* print front end styles
|
365 |
+
*
|
366 |
+
* @since 1.1.7
|
367 |
+
*/
|
368 |
+
public function print_plugin_styles() {
|
369 |
+
|
370 |
+
$css_path = dirname(__FILE__).'/assets/css/qts-default.css';
|
371 |
+
|
372 |
+
if (!file_exists($css_path) || !is_readable($css_path)) {
|
373 |
+
return;
|
374 |
+
}
|
375 |
+
|
376 |
+
$default_css_file = file_get_contents($css_path, FILE_USE_INCLUDE_PATH);
|
377 |
+
|
378 |
+
$css = "<style media=\"screen\">\n";
|
379 |
+
$css .= "$default_css_file\n";
|
380 |
+
$css .="</style>\n";
|
381 |
+
echo $css;
|
382 |
+
}
|
383 |
+
|
384 |
+
|
385 |
+
|
386 |
+
/**
|
387 |
+
* actions when deactivating the plugin
|
388 |
+
*
|
389 |
+
* @since 1.0
|
390 |
+
*/
|
391 |
+
public function deactivate() {
|
392 |
+
global $wp_rewrite;
|
393 |
+
|
394 |
+
// regenerate rewrite rules in db
|
395 |
+
remove_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
|
396 |
+
$wp_rewrite->flush_rules();
|
397 |
+
}
|
398 |
+
|
399 |
+
|
400 |
+
|
401 |
+
/**
|
402 |
+
* admin notice: update your old data
|
403 |
+
*
|
404 |
+
* @since 1.0
|
405 |
+
*/
|
406 |
+
function notice_update(){
|
407 |
+
global $current_screen;
|
408 |
+
|
409 |
+
if ($current_screen->id != 'settings_page_qtranslate-slug-settings') {
|
410 |
+
|
411 |
+
echo "<div class=\"updated\">" . PHP_EOL;
|
412 |
+
echo "<p><strong>Qtranslate Slug:</strong></p>" . PHP_EOL;
|
413 |
+
printf("<p>%s <a href=\"%s\" class=\"button\">%s</a></p>", __('Please update your old data to the new system.', 'qts'), add_query_arg(array('page' => 'qtranslate-slug-settings'), 'options-general.php'), __('upgrade now', 'qts')) . PHP_EOL;
|
414 |
+
echo "</div>" . PHP_EOL;
|
415 |
+
}
|
416 |
+
}
|
417 |
+
|
418 |
+
|
419 |
+
|
420 |
+
/**
|
421 |
+
* admin notice: update your old data
|
422 |
+
*
|
423 |
+
* @since 1.0
|
424 |
+
*/
|
425 |
+
function notice_dependences(){
|
426 |
+
global $current_screen;
|
427 |
+
|
428 |
+
echo "<div class=\"error\">" . PHP_EOL;
|
429 |
+
echo "<p><strong>Qtranslate Slug:</strong></p>" . PHP_EOL;
|
430 |
+
echo "<p>" . __('This plugin requires at least <strong>WordPress 3.3</strong> and either <strong>mqTranslate 2.6.2.4 (or newer)</strong> or <strong>qTranslate 2.5.8 (or newer)</strong>', 'qts') . "</p>" . PHP_EOL;
|
431 |
+
echo "</div>" . PHP_EOL;
|
432 |
+
}
|
433 |
+
|
434 |
+
|
435 |
+
|
436 |
+
/**
|
437 |
+
* checks if old table 'qtranslate_slug' exists and is not empty
|
438 |
+
*
|
439 |
+
* @return object | false
|
440 |
+
*
|
441 |
+
* @since 1.0
|
442 |
+
*/
|
443 |
+
public function check_old_data() {
|
444 |
+
global $wpdb;
|
445 |
+
|
446 |
+
if ($this->old_data === false) {
|
447 |
+
return false;
|
448 |
+
}
|
449 |
+
|
450 |
+
$table_name = $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}qtranslate_slug'");
|
451 |
+
|
452 |
+
if (!empty($table_name)) {
|
453 |
+
$this->old_data = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}qtranslate_slug");
|
454 |
+
}
|
455 |
+
|
456 |
+
if ( empty($table_name) || empty($this->old_data) ) {
|
457 |
+
$this->old_data = false;
|
458 |
+
}
|
459 |
+
|
460 |
+
return $this->old_data;
|
461 |
+
}
|
462 |
+
|
463 |
+
|
464 |
+
|
465 |
+
/**
|
466 |
+
* actions when deactivating the plugin
|
467 |
+
*
|
468 |
+
* @since 1.0
|
469 |
+
*/
|
470 |
+
private function check_old_versions() {
|
471 |
+
|
472 |
+
if ( $this->check_old_data() ) {
|
473 |
+
add_action('admin_notices', array(&$this, 'notice_update'));
|
474 |
+
}
|
475 |
+
}
|
476 |
+
|
477 |
+
|
478 |
+
|
479 |
+
/**
|
480 |
+
* Initialise the Class with all hooks
|
481 |
+
*
|
482 |
+
* @since 1.0
|
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() ) {
|
490 |
+
if (is_admin()) {
|
491 |
+
add_action('admin_notices', array(&$this, 'notice_dependences'));
|
492 |
+
}
|
493 |
+
return;
|
494 |
+
}
|
495 |
+
|
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 );
|
514 |
+
add_filter( 'qts_validate_post_slug', array(&$this, 'unique_post_slug'), 1, 3 );
|
515 |
+
add_filter( 'qts_validate_term_slug', array(&$this, 'validate_term_slug'), 0, 3 );
|
516 |
+
add_filter( 'qts_validate_term_slug', array(&$this, 'unique_term_slug'), 1, 3 );
|
517 |
+
add_filter( 'wp_get_object_terms', array(&$this, 'get_object_terms'), 0, 4 );
|
518 |
+
add_filter( 'get_terms', array(&$this, 'get_terms'), 0, 3 );
|
519 |
+
|
520 |
+
// admin actions
|
521 |
+
add_action( 'admin_menu', array(&$this, 'add_slug_meta_box') );
|
522 |
+
add_action( 'save_post', array(&$this, 'save_postdata'), 605, 2 );
|
523 |
+
add_action( 'delete_term', array(&$this, 'delete_term'), 0, 3);
|
524 |
+
add_action( 'created_term', array(&$this, 'save_term'), 605, 3);
|
525 |
+
add_action( 'edited_term', array(&$this, 'save_term'), 605, 3 );
|
526 |
+
add_action( 'admin_head', array(&$this, 'hide_slug_box'), 900 );
|
527 |
+
|
528 |
+
add_action( 'init', array(&$this, 'taxonomies_hooks'), 805 );
|
529 |
+
|
530 |
+
add_action( 'wp_dashboard_setup', array(&$this, 'remove_dashboard_widgets') );
|
531 |
+
add_action( 'admin_head', array(&$this, 'hide_quick_edit'), 600 );
|
532 |
+
add_action( 'admin_init', array(&$this, 'fix_nav_menu') );
|
533 |
+
|
534 |
+
} else {
|
535 |
+
|
536 |
+
add_filter( 'request', array(&$this, 'filter_request') );
|
537 |
+
|
538 |
+
// adds external style file
|
539 |
+
$qts_options = $this->get_options();
|
540 |
+
if ( !isset($qts_options[QTS_PREFIX.'styles']) || $qts_options[QTS_PREFIX.'styles'] == "file" ) {
|
541 |
+
add_action( 'wp_enqueue_scripts', array( &$this, 'register_plugin_styles' ) );
|
542 |
+
} elseif ($qts_options[QTS_PREFIX.'styles'] == "minified" ) {
|
543 |
+
add_action( 'wp_enqueue_scripts', array( &$this, 'register_plugin_styles_min' ) );
|
544 |
+
} elseif ($qts_options[QTS_PREFIX.'styles'] == "inline" ) {
|
545 |
+
add_action( 'wp_print_styles', array( &$this, 'print_plugin_styles' ), 20 );
|
546 |
+
}
|
547 |
+
}
|
548 |
+
|
549 |
+
add_filter( 'query_vars', array(&$this, 'query_vars'));
|
550 |
+
add_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
|
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);
|
566 |
+
add_filter( 'home_url', array(&$this, 'home_url'), 10, 4);
|
567 |
+
add_filter( 'post_type_link', array(&$this, 'post_type_link'), 600, 4 );
|
568 |
+
add_filter( 'post_link', array(&$this, 'post_link'), 0, 3 );
|
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.
|
595 |
+
* Fixes issue #25
|
596 |
+
*
|
597 |
+
* @global $qtranslate_slug used to convert the url
|
598 |
+
* @global $q_config available languages
|
599 |
+
*
|
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 |
+
|
612 |
+
|
613 |
+
/**
|
614 |
+
* Add a class based on the current language
|
615 |
+
* @param array $classes list of classes
|
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'
|
747 |
+
*
|
748 |
+
* @param object $wp_rewrite
|
749 |
+
*
|
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');
|
758 |
+
foreach ( $post_types as $post_type ) {
|
759 |
+
$this->generate_extra_rules( $post_type->name );
|
760 |
+
}
|
761 |
+
|
762 |
+
// taxonomies rules
|
763 |
+
$taxonomies = $this->get_public_taxonomies();
|
764 |
+
foreach ( $taxonomies as $taxonomy ) {
|
765 |
+
$this->generate_extra_rules( $taxonomy->name );
|
766 |
+
}
|
767 |
+
}
|
768 |
+
|
769 |
+
|
770 |
+
|
771 |
+
/**
|
772 |
+
* Helper: news rules to translate the URL bases
|
773 |
+
*
|
774 |
+
* @param string $name name of extra permastruct
|
775 |
+
* @param string $type 'post_type' or 'taxonomy'
|
776 |
+
*
|
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 |
+
|
786 |
+
$struct = $wp_rewrite->extra_permastructs[$name];
|
787 |
+
|
788 |
+
if ( is_array( $struct ) ) {
|
789 |
+
if ( count( $struct ) == 2 )
|
790 |
+
$rules = $wp_rewrite->generate_rewrite_rules( "/$base/%$name%", $struct[1] );
|
791 |
+
else
|
792 |
+
$rules = $wp_rewrite->generate_rewrite_rules( "/$base/%$name%", $struct['ep_mask'], $struct['paged'], $struct['feed'], $struct['forcomments'], $struct['walk_dirs'], $struct['endpoints'] );
|
793 |
+
} else {
|
794 |
+
$rules = $wp_rewrite->generate_rewrite_rules( "/$base/%$name%" );
|
795 |
+
}
|
796 |
+
|
797 |
+
$wp_rewrite->rules = array_merge($rules, $wp_rewrite->rules);
|
798 |
+
|
799 |
+
endif;
|
800 |
+
|
801 |
+
endforeach;
|
802 |
+
}
|
803 |
+
|
804 |
+
|
805 |
+
|
806 |
+
/**
|
807 |
+
* Helper that gets a base slug stored in options
|
808 |
+
*
|
809 |
+
* @param string $name of extra permastruct
|
810 |
+
* @return string base slug for 'post_type' and 'language' or false
|
811 |
+
*
|
812 |
+
* @since 1.0
|
813 |
+
*/
|
814 |
+
public function get_base_slug($name = false, $lang = false) {
|
815 |
+
|
816 |
+
if ( !$name || !$lang ) {
|
817 |
+
return false;
|
818 |
+
}
|
819 |
+
|
820 |
+
if ( taxonomy_exists($name) ) {
|
821 |
+
$type = 'taxonomy';
|
822 |
+
} else if ( post_type_exists($name) ) {
|
823 |
+
$type = 'post_type';
|
824 |
+
} else {
|
825 |
+
return false;
|
826 |
+
}
|
827 |
+
|
828 |
+
$qts_options = $this->get_options();
|
829 |
+
|
830 |
+
$option_name = QTS_PREFIX . $type . '_' . $name;
|
831 |
+
|
832 |
+
if ( !isset($qts_options[$option_name]) || empty($qts_options[$option_name]) ) {
|
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;
|
841 |
+
}
|
842 |
+
|
843 |
+
|
844 |
+
|
845 |
+
/**
|
846 |
+
* Helper: returns public built-in and not built-in taxonomies
|
847 |
+
*
|
848 |
+
* @return array of public taxonomies objects
|
849 |
+
*
|
850 |
+
* @since 1.0
|
851 |
+
*/
|
852 |
+
private function get_public_taxonomies() {
|
853 |
+
|
854 |
+
$builtin = get_taxonomies( array( 'public' => true, 'show_ui' => true, '_builtin' => true ), 'object');
|
855 |
+
$taxonomies = get_taxonomies( array( 'public' => true, 'show_ui' => true, '_builtin' => false ), 'object' );
|
856 |
+
|
857 |
+
return array_merge( $builtin, $taxonomies );
|
858 |
+
}
|
859 |
+
|
860 |
+
|
861 |
+
|
862 |
+
/**
|
863 |
+
* parse and adds $_GET args passed to an url
|
864 |
+
*
|
865 |
+
* @param string $url parameters
|
866 |
+
* @param string $lang processed
|
867 |
+
* @return string converted url
|
868 |
+
*
|
869 |
+
* @since 1.0
|
870 |
+
*/
|
871 |
+
public function parse_url_args( $url ) {
|
872 |
+
global $q_config;
|
873 |
+
|
874 |
+
if (is_admin()) {
|
875 |
+
return $url;
|
876 |
+
}
|
877 |
+
|
878 |
+
$url = preg_replace('/&/', '&', $url);
|
879 |
+
|
880 |
+
// if no permalink structure ads ?lang=en
|
881 |
+
$base_query = parse_url($q_config['url_info']['original_url']);
|
882 |
+
$base_args = isset($base_query['query']) ? wp_parse_args($base_query['query']) : array();
|
883 |
+
|
884 |
+
if ( empty($this->permalink_structure) || $q_config['url_mode'] == 1 ) {
|
885 |
+
$base_args['lang'] = $this->get_lang();
|
886 |
+
}
|
887 |
+
|
888 |
+
// rebuild query with all args
|
889 |
+
$url = add_query_arg($base_args, $url);
|
890 |
+
|
891 |
+
$url = str_replace('/?', '?', $url); // TODO: hack: improve this code
|
892 |
+
$url = str_replace('?', '/?', $url); // TODO: hack: improve this code
|
893 |
+
|
894 |
+
return $url;
|
895 |
+
}
|
896 |
+
|
897 |
+
|
898 |
+
|
899 |
+
/**
|
900 |
+
* Fix get_page_by_path when querying vars
|
901 |
+
*
|
902 |
+
* @param $query_vars objec query vars founded
|
903 |
+
* @return object $query_vars processed
|
904 |
+
*
|
905 |
+
* @since 1.0
|
906 |
+
*/
|
907 |
+
public function query_vars( $query_vars ) {
|
908 |
+
global $wp, $wp_rewrite;
|
909 |
+
|
910 |
+
$wp->query_vars = array();
|
911 |
+
$post_type_query_vars = array();
|
912 |
+
|
913 |
+
// Fetch the rewrite rules.
|
914 |
+
$rewrite = $wp_rewrite->wp_rewrite_rules();
|
915 |
+
|
916 |
+
if ( ! empty($rewrite) ) {
|
917 |
+
// If we match a rewrite rule, this will be cleared.
|
918 |
+
$error = '404';
|
919 |
+
$wp->did_permalink = true;
|
920 |
+
|
921 |
+
if ( isset($_SERVER['PATH_INFO']) ) {
|
922 |
+
$pathinfo = $_SERVER['PATH_INFO'];
|
923 |
+
} else {
|
924 |
+
$pathinfo = '';
|
925 |
+
}
|
926 |
+
$pathinfo_array = explode('?', $pathinfo);
|
927 |
+
$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
|
928 |
+
$req_uri = $_SERVER['REQUEST_URI'];
|
929 |
+
$req_uri_array = explode('?', $req_uri);
|
930 |
+
$req_uri = $req_uri_array[0];
|
931 |
+
$self = $_SERVER['PHP_SELF'];
|
932 |
+
$home_path = parse_url(home_url());
|
933 |
+
|
934 |
+
if ( isset($home_path['path']) ) {
|
935 |
+
$home_path = $home_path['path'];
|
936 |
+
} else {
|
937 |
+
$home_path = '';
|
938 |
+
}
|
939 |
+
$home_path = trim($home_path, '/');
|
940 |
+
|
941 |
+
// Trim path info from the end and the leading home path from the
|
942 |
+
// front. For path info requests, this leaves us with the requesting
|
943 |
+
// filename, if any. For 404 requests, this leaves us with the
|
944 |
+
// requested permalink.
|
945 |
+
$req_uri = str_replace($pathinfo, '', $req_uri);
|
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, '/');
|
953 |
+
$pathinfo = preg_replace("|^$home_path|", '', $pathinfo);
|
954 |
+
$pathinfo = trim($pathinfo, '/');
|
955 |
+
$self = trim($self, '/');
|
956 |
+
$self = preg_replace("|^$home_path|", '', $self);
|
957 |
+
$self = trim($self, '/');
|
958 |
+
|
959 |
+
// The requested permalink is in $pathinfo for path info requests and
|
960 |
+
// $req_uri for other requests.
|
961 |
+
if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
|
962 |
+
$request = $pathinfo;
|
963 |
+
} else {
|
964 |
+
// If the request uri is the index, blank it out so that
|
965 |
+
// we don't try to match it against a rule.
|
966 |
+
if ( $req_uri == $wp_rewrite->index )
|
967 |
+
$req_uri = '';
|
968 |
+
$request = $req_uri;
|
969 |
+
}
|
970 |
+
|
971 |
+
$wp->request = $request;
|
972 |
+
|
973 |
+
// Look for matches.
|
974 |
+
$request_match = $request;
|
975 |
+
if ( empty( $request_match ) ) {
|
976 |
+
// An empty request could only match against ^$ regex
|
977 |
+
if ( isset( $rewrite['$'] ) ) {
|
978 |
+
$wp->matched_rule = '$';
|
979 |
+
$query = $rewrite['$'];
|
980 |
+
$matches = array('');
|
981 |
+
}
|
982 |
+
} else if ( $req_uri != 'wp-app.php' ) {
|
983 |
+
foreach ( (array) $rewrite as $match => $query ) {
|
984 |
+
// If the requesting file is the anchor of the match, prepend it to the path info.
|
985 |
+
if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request ) {
|
986 |
+
$request_match = $req_uri . '/' . $request;
|
987 |
+
}
|
988 |
+
|
989 |
+
if ( preg_match("#^$match#", $request_match, $matches) || preg_match("#^$match#", urldecode($request_match), $matches) ) {
|
990 |
+
|
991 |
+
if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
|
992 |
+
// this is a verbose page match, lets check to be sure about it
|
993 |
+
if ( ! $page_foundid = $this->get_page_by_path( $matches[ $varmatch[1] ] ) ) {
|
994 |
+
continue;
|
995 |
+
} else {
|
996 |
+
wp_cache_set('qts_page_request', $page_foundid); // caching query :)
|
997 |
+
}
|
998 |
+
}
|
999 |
+
|
1000 |
+
// Got a match.
|
1001 |
+
$wp->matched_rule = $match;
|
1002 |
+
break;
|
1003 |
+
}
|
1004 |
+
}
|
1005 |
+
}
|
1006 |
+
|
1007 |
+
if ( isset( $wp->matched_rule ) ) {
|
1008 |
+
// Trim the query of everything up to the '?'.
|
1009 |
+
$query = preg_replace("!^.+\?!", '', $query);
|
1010 |
+
|
1011 |
+
// Substitute the substring matches into the query.
|
1012 |
+
$query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
|
1013 |
+
|
1014 |
+
$wp->matched_query = $query;
|
1015 |
+
|
1016 |
+
// Parse the query.
|
1017 |
+
parse_str($query, $perma_query_vars);
|
1018 |
+
|
1019 |
+
// If we're processing a 404 request, clear the error var
|
1020 |
+
// since we found something.
|
1021 |
+
unset( $_GET['error'] );
|
1022 |
+
unset( $error );
|
1023 |
+
}
|
1024 |
+
|
1025 |
+
// If req_uri is empty or if it is a request for ourself, unset error.
|
1026 |
+
if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
|
1027 |
+
unset( $_GET['error'] );
|
1028 |
+
unset( $error );
|
1029 |
+
|
1030 |
+
if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
|
1031 |
+
unset( $perma_query_vars );
|
1032 |
+
}
|
1033 |
+
|
1034 |
+
$wp->did_permalink = false;
|
1035 |
+
}
|
1036 |
+
}
|
1037 |
+
|
1038 |
+
return count(array_diff($query_vars, $wp->public_query_vars)) > 0 ? $query_vars : $wp->public_query_vars;
|
1039 |
+
}
|
1040 |
+
|
1041 |
+
|
1042 |
+
|
1043 |
+
/**
|
1044 |
+
* Function called when query parameters are processed by Wordpress.
|
1045 |
+
*
|
1046 |
+
* @param $query query parameters
|
1047 |
+
* @return array() $query processed
|
1048 |
+
*
|
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 |
+
}
|
1056 |
+
|
1057 |
+
foreach (get_post_types() as $post_type) {
|
1058 |
+
if ( array_key_exists($post_type, $query) && !in_array($post_type, array('post', 'page')) ) {
|
1059 |
+
$query['post_type'] = $post_type;
|
1060 |
+
}
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
$page_foundit = false;
|
1064 |
+
|
1065 |
+
// -> page
|
1066 |
+
if ( isset($query['pagename']) || isset($query['page_id']) ):
|
1067 |
+
|
1068 |
+
$page = wp_cache_get('qts_page_request');
|
1069 |
+
if (!$page)
|
1070 |
+
$page = isset($query['page_id']) ? get_post($query['page_id']) : $this->get_page_by_path($query['pagename']);
|
1071 |
+
|
1072 |
+
if (!$page) return $query;
|
1073 |
+
$id = $page->ID;
|
1074 |
+
$cache_array = array($page);
|
1075 |
+
update_post_caches($cache_array, 'page'); // caching query :)
|
1076 |
+
wp_cache_delete('qts_page_request');
|
1077 |
+
$query['pagename'] = get_page_uri($page);
|
1078 |
+
$function = 'get_page_link';
|
1079 |
+
|
1080 |
+
// -> custom post type
|
1081 |
+
elseif ( isset($query['post_type']) ):
|
1082 |
+
|
1083 |
+
$page_slug = ( isset($query['name']) && !empty($query['name']) ) ? $query['name'] : $query[$query['post_type']];
|
1084 |
+
$page = $this->get_page_by_path($page_slug, OBJECT, $query['post_type']);
|
1085 |
+
if (!$page) return $query;
|
1086 |
+
$id = $page->ID;
|
1087 |
+
$cache_array = array($page);
|
1088 |
+
update_post_caches($cache_array, $query['post_type']); // caching query :)
|
1089 |
+
$query['name'] = $query[$query['post_type']] = get_page_uri($page);
|
1090 |
+
$function = 'get_post_permalink';
|
1091 |
+
|
1092 |
+
// -> post
|
1093 |
+
elseif ( isset($query['name']) || isset($query['p']) ):
|
1094 |
+
|
1095 |
+
$post = isset($query['p']) ? get_post($query['p']) : $this->get_page_by_path($query['name'], OBJECT, 'post');
|
1096 |
+
if (!$post) {
|
1097 |
+
return $query;
|
1098 |
+
}
|
1099 |
+
$query['name'] = $post->post_name;
|
1100 |
+
$id = $post->ID;
|
1101 |
+
$cache_array = array($post);
|
1102 |
+
update_post_caches($cache_array);
|
1103 |
+
$function = 'get_permalink';
|
1104 |
+
|
1105 |
+
// -> category
|
1106 |
+
elseif ( ( isset($query['category_name']) || isset($query['cat'])) ):
|
1107 |
+
if ( isset($query['category_name']) ) {
|
1108 |
+
$term_slug = $this->get_last_slash( $query['category_name'] );
|
1109 |
+
}
|
1110 |
+
$term = isset($query['cat']) ? get_term($query['cat'], 'category') : $this->get_term_by('slug', $term_slug, 'category');
|
1111 |
+
if (!$term) {
|
1112 |
+
return $query;
|
1113 |
+
}
|
1114 |
+
$cache_array = array($term);
|
1115 |
+
update_term_cache($cache_array, 'category'); // caching query :)
|
1116 |
+
$id = $term->term_id;
|
1117 |
+
$query['category_name'] = $term->slug; // uri
|
1118 |
+
$function = 'get_category_link';
|
1119 |
+
|
1120 |
+
// -> tag
|
1121 |
+
elseif ( isset($query['tag']) ):
|
1122 |
+
|
1123 |
+
$term = $this->get_term_by('slug', $query['tag'], 'post_tag');
|
1124 |
+
if (!$term) {
|
1125 |
+
return $query;
|
1126 |
+
}
|
1127 |
+
$cache_array = array($term);
|
1128 |
+
update_term_cache($cache_array, 'post_tag'); // caching query :)
|
1129 |
+
$id = $term->term_id;
|
1130 |
+
$query['tag'] = $term->slug;
|
1131 |
+
$function = 'get_tag_link';
|
1132 |
+
|
1133 |
+
endif;
|
1134 |
+
|
1135 |
+
|
1136 |
+
// -> taxonomy
|
1137 |
+
$taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
|
1138 |
+
foreach ($taxonomies as $term_name):
|
1139 |
+
if ( isset($query[$term_name]) ) {
|
1140 |
+
|
1141 |
+
$term_slug = $this->get_last_slash( $query[$term_name] );
|
1142 |
+
$term = $this->get_term_by('slug', $term_slug, $term_name);
|
1143 |
+
if (!$term) {
|
1144 |
+
return $query;
|
1145 |
+
}
|
1146 |
+
$cache_array = array($term);
|
1147 |
+
update_term_cache($cache_array, $term_name); // caching query :)
|
1148 |
+
$id = $term;
|
1149 |
+
$query[$term_name] = $term->slug;
|
1150 |
+
$function = 'get_term_link';
|
1151 |
+
|
1152 |
+
}
|
1153 |
+
endforeach;
|
1154 |
+
|
1155 |
+
// -> home url
|
1156 |
+
if ( empty($query) ) {
|
1157 |
+
|
1158 |
+
$function = 'home_url';
|
1159 |
+
$id = '';
|
1160 |
+
|
1161 |
+
}
|
1162 |
+
|
1163 |
+
// -> search
|
1164 |
+
if (isset($query['s'])) {
|
1165 |
+
|
1166 |
+
$id = $query['s'];
|
1167 |
+
$function="get_search_link";
|
1168 |
+
|
1169 |
+
}
|
1170 |
+
|
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));
|
1178 |
+
}
|
1179 |
+
|
1180 |
+
$this->lang = false;
|
1181 |
+
}
|
1182 |
+
|
1183 |
+
return $query;
|
1184 |
+
}
|
1185 |
+
|
1186 |
+
|
1187 |
+
|
1188 |
+
/**
|
1189 |
+
* Parse a hierarquical name and extract the last one
|
1190 |
+
*
|
1191 |
+
* @param string $lang Page path
|
1192 |
+
* @return string
|
1193 |
+
*
|
1194 |
+
* @since 1.0
|
1195 |
+
*/
|
1196 |
+
public function get_current_url( $lang = false ) {
|
1197 |
+
|
1198 |
+
if (!$lang) {
|
1199 |
+
$lang = $this->get_lang();
|
1200 |
+
}
|
1201 |
+
|
1202 |
+
if (isset($this->current_url[$lang]) && !empty($this->current_url[$lang])) {
|
1203 |
+
return $this->current_url[$lang];
|
1204 |
+
}
|
1205 |
+
|
1206 |
+
return '';
|
1207 |
+
}
|
1208 |
+
|
1209 |
+
|
1210 |
+
|
1211 |
+
/**
|
1212 |
+
* Parse a hierarquical name and extract the last one
|
1213 |
+
*
|
1214 |
+
* @param string $slug Page path
|
1215 |
+
* @return string
|
1216 |
+
*
|
1217 |
+
* @since 1.0
|
1218 |
+
*/
|
1219 |
+
private function get_last_slash($slug) {
|
1220 |
+
|
1221 |
+
$slug = rawurlencode( urldecode( $slug ) );
|
1222 |
+
$slug = str_replace('%2F', '/', $slug);
|
1223 |
+
$slug = str_replace('%20', ' ', $slug);
|
1224 |
+
$exploded_slug = explode('/', $slug);
|
1225 |
+
|
1226 |
+
return array_pop( $exploded_slug );
|
1227 |
+
}
|
1228 |
+
|
1229 |
+
|
1230 |
+
|
1231 |
+
/**
|
1232 |
+
* Retrieves a page id given its path.
|
1233 |
+
*
|
1234 |
+
* @param string $page_path Page path
|
1235 |
+
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
|
1236 |
+
* @param string $post_type Optional. Post type. Default page.
|
1237 |
+
* @return mixed Null when complete.
|
1238 |
+
*
|
1239 |
+
* @since 1.0
|
1240 |
+
*/
|
1241 |
+
private function get_page_id_by_path($page_path, $output = OBJECT, $post_type = 'page') {
|
1242 |
+
global $wpdb;
|
1243 |
+
|
1244 |
+
$page_path = rawurlencode(urldecode($page_path));
|
1245 |
+
$page_path = str_replace('%2F', '/', $page_path);
|
1246 |
+
$page_path = str_replace('%20', ' ', $page_path);
|
1247 |
+
$parts = explode( '/', trim( $page_path, '/' ) );
|
1248 |
+
$parts = array_map( 'esc_sql', $parts );
|
1249 |
+
$parts = array_map( 'sanitize_title_for_query', $parts );
|
1250 |
+
$in_string = "'". implode( "','", $parts ) . "'";
|
1251 |
+
$meta_key = $this->get_meta_key();
|
1252 |
+
$post_type_sql = $post_type;
|
1253 |
+
$wpdb->escape_by_ref( $post_type_sql );
|
1254 |
+
|
1255 |
+
$pages = $wpdb->get_results( "SELECT $wpdb->posts.ID, $wpdb->posts.post_parent, $wpdb->postmeta.meta_value FROM $wpdb->posts,$wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value IN ($in_string) AND ($wpdb->posts.post_type = '$post_type_sql' OR $wpdb->posts.post_type = 'attachment')", OBJECT_K );
|
1256 |
+
|
1257 |
+
$revparts = array_reverse( $parts );
|
1258 |
+
|
1259 |
+
$foundid = 0;
|
1260 |
+
foreach ( (array) $pages as $page ) {
|
1261 |
+
if ( $page->meta_value == $revparts[0] ) {
|
1262 |
+
$count = 0;
|
1263 |
+
$p = $page;
|
1264 |
+
while ( $p->post_parent != 0 && isset( $pages[ $p->post_parent ] ) ) {
|
1265 |
+
$count++;
|
1266 |
+
$parent = $pages[ $p->post_parent ];
|
1267 |
+
if ( ! isset( $revparts[ $count ] ) || $parent->meta_value != $revparts[ $count ] ) {
|
1268 |
+
break;
|
1269 |
+
}
|
1270 |
+
$p = $parent;
|
1271 |
+
}
|
1272 |
+
|
1273 |
+
if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->meta_value == $revparts[ $count ] ) {
|
1274 |
+
$foundid = $page->ID;
|
1275 |
+
break;
|
1276 |
+
}
|
1277 |
+
}
|
1278 |
+
}
|
1279 |
+
|
1280 |
+
if ( $foundid ) {
|
1281 |
+
return $foundid;
|
1282 |
+
|
1283 |
+
} else {
|
1284 |
+
|
1285 |
+
$last_part = array_pop($parts);
|
1286 |
+
$page_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_name = '$last_part' AND (post_type = '$post_type_sql' OR post_type = 'attachment')" );
|
1287 |
+
|
1288 |
+
if ( $page_id ) {
|
1289 |
+
return $page_id;
|
1290 |
+
}
|
1291 |
+
}
|
1292 |
+
|
1293 |
+
return null;
|
1294 |
+
}
|
1295 |
+
|
1296 |
+
|
1297 |
+
|
1298 |
+
|
1299 |
+
/**
|
1300 |
+
* Retrieves a page given its path.
|
1301 |
+
*
|
1302 |
+
* @param string $page_path Page path
|
1303 |
+
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
|
1304 |
+
* @param string $post_type Optional. Post type. Default page.
|
1305 |
+
* @return mixed Null when complete.
|
1306 |
+
*
|
1307 |
+
* @since 1.0
|
1308 |
+
*/
|
1309 |
+
private function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') {
|
1310 |
+
|
1311 |
+
$foundid = $this->get_page_id_by_path($page_path, $output, $post_type);
|
1312 |
+
if ( $foundid ) {
|
1313 |
+
return get_post( $foundid, $output );
|
1314 |
+
}
|
1315 |
+
|
1316 |
+
return null;
|
1317 |
+
}
|
1318 |
+
|
1319 |
+
|
1320 |
+
|
1321 |
+
/**
|
1322 |
+
* Ignores if the mod_rewrite func is the caller
|
1323 |
+
*
|
1324 |
+
* @return boolean
|
1325 |
+
*
|
1326 |
+
* @since 1.0
|
1327 |
+
*/
|
1328 |
+
private function ignore_rewrite_caller() {
|
1329 |
+
|
1330 |
+
$backtrace = debug_backtrace();
|
1331 |
+
|
1332 |
+
$ignore_functions = array('mod_rewrite_rules', 'save_mod_rewrite_rules', 'flush_rules', 'rewrite_rules', 'wp_rewrite_rules', 'query_vars');
|
1333 |
+
|
1334 |
+
if ( isset($backtrace['function']) ) {
|
1335 |
+
if (in_array($backtrace['function'], $ignore_functions)) {
|
1336 |
+
return true;
|
1337 |
+
}
|
1338 |
+
} else {
|
1339 |
+
foreach ($backtrace as $trace) {
|
1340 |
+
if ( isset($trace['function']) && in_array($trace['function'], $ignore_functions) ) {
|
1341 |
+
return true;
|
1342 |
+
}
|
1343 |
+
}
|
1344 |
+
}
|
1345 |
+
|
1346 |
+
return false;
|
1347 |
+
}
|
1348 |
+
|
1349 |
+
|
1350 |
+
/**
|
1351 |
+
* Retrieve the home url for a given site.
|
1352 |
+
*
|
1353 |
+
* @param int $blog_id (optional) Blog ID. Defaults to current blog.
|
1354 |
+
* @param string $path (optional) Path relative to the home url.
|
1355 |
+
* @param string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https'.
|
1356 |
+
* @return string Home url link with optional path appended.
|
1357 |
+
*
|
1358 |
+
* @since 1.0
|
1359 |
+
*/
|
1360 |
+
public function home_url($url, $path, $scheme, $blog_id) {
|
1361 |
+
|
1362 |
+
if ( !in_array( $scheme, array( 'http', 'https' ) ) ) {
|
1363 |
+
$scheme = is_ssl() && !is_admin() ? 'https' : 'http';
|
1364 |
+
}
|
1365 |
+
|
1366 |
+
if ( empty( $blog_id ) || !is_multisite() ) {
|
1367 |
+
$url = get_option( 'home' );
|
1368 |
+
} else {
|
1369 |
+
$url = get_blog_option( $blog_id, 'home' );
|
1370 |
+
}
|
1371 |
+
|
1372 |
+
if ( 'http' != $scheme ) {
|
1373 |
+
$url = str_replace( 'http://', "$scheme://", $url );
|
1374 |
+
}
|
1375 |
+
|
1376 |
+
$ignore_caller = $this->ignore_rewrite_caller();
|
1377 |
+
|
1378 |
+
if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) {
|
1379 |
+
$url .= '/' . ltrim( $path, '/' );
|
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;
|
1387 |
+
}
|
1388 |
+
|
1389 |
+
|
1390 |
+
|
1391 |
+
/**
|
1392 |
+
* Filter that changes the permastruct depending
|
1393 |
+
*
|
1394 |
+
* @param string $permastruct default permastruct given b wp_rewrite
|
1395 |
+
* @param string $name the name of the extra permastruct
|
1396 |
+
* @return string processed permastruct
|
1397 |
+
*
|
1398 |
+
* @since 1.0
|
1399 |
+
*/
|
1400 |
+
public function get_extra_permastruct( $permastruct = false, $name = false ) {
|
1401 |
+
|
1402 |
+
if ( !$name || !$permastruct ) {
|
1403 |
+
return '';
|
1404 |
+
}
|
1405 |
+
|
1406 |
+
if ( $base = $this->get_base_slug($name, $this->get_lang()) ) {
|
1407 |
+
return "/$base/%$name%";
|
1408 |
+
}
|
1409 |
+
|
1410 |
+
return $permastruct;
|
1411 |
+
}
|
1412 |
+
|
1413 |
+
|
1414 |
+
|
1415 |
+
/**
|
1416 |
+
* Filter that translates the slug parts in a page link
|
1417 |
+
*
|
1418 |
+
* @param $link the link for the page generated by Wordpress
|
1419 |
+
* @param $id the id of the page
|
1420 |
+
* @return the link translated
|
1421 |
+
*
|
1422 |
+
* @since 1.0
|
1423 |
+
*/
|
1424 |
+
public function post_type_link( $link, $post, $leavename, $sample ) {
|
1425 |
+
global $wp_rewrite;
|
1426 |
+
|
1427 |
+
if ( is_wp_error( $post ) ) {
|
1428 |
+
return $post;
|
1429 |
+
}
|
1430 |
+
|
1431 |
+
$post_link = apply_filters( 'qts_permastruct', $wp_rewrite->get_extra_permastruct($post->post_type), $post->post_type);
|
1432 |
+
|
1433 |
+
$slug = get_post_meta( $post->ID, $this->get_meta_key(), true );
|
1434 |
+
if (!$slug) {
|
1435 |
+
$slug = $post->post_name;
|
1436 |
+
}
|
1437 |
+
|
1438 |
+
$draft_or_pending = isset($post->post_status) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
|
1439 |
+
|
1440 |
+
$post_type = get_post_type_object($post->post_type);
|
1441 |
+
|
1442 |
+
if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) {
|
1443 |
+
if ( ! $leavename ) {
|
1444 |
+
if ( $post_type->hierarchical )
|
1445 |
+
$slug = $this->get_page_uri($post->ID);
|
1446 |
+
$post_link = str_replace("%$post->post_type%", $slug, $post_link);
|
1447 |
+
}
|
1448 |
+
|
1449 |
+
$post_link = home_url( user_trailingslashit($post_link) );
|
1450 |
+
|
1451 |
+
} else {
|
1452 |
+
|
1453 |
+
if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) ) {
|
1454 |
+
$post_link = add_query_arg($post_type->query_var, $slug, '');
|
1455 |
+
} else {
|
1456 |
+
$post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), '');
|
1457 |
+
}
|
1458 |
+
|
1459 |
+
$post_link = home_url($post_link);
|
1460 |
+
}
|
1461 |
+
|
1462 |
+
return $post_link;
|
1463 |
+
}
|
1464 |
+
|
1465 |
+
|
1466 |
+
|
1467 |
+
/**
|
1468 |
+
* Filter that translates the slug in a post link
|
1469 |
+
*
|
1470 |
+
* @param $link the link generated by wordpress
|
1471 |
+
* @param $post the post data
|
1472 |
+
* @param $leavename parameter used by get_permalink. Whether to keep post name or page name.
|
1473 |
+
* @return the link translated
|
1474 |
+
*
|
1475 |
+
* @since 1.0
|
1476 |
+
*/
|
1477 |
+
public function post_link( $link, $post, $leavename ) {
|
1478 |
+
global $q_config;
|
1479 |
+
|
1480 |
+
$rewritecode = array(
|
1481 |
+
'%year%',
|
1482 |
+
'%monthnum%',
|
1483 |
+
'%day%',
|
1484 |
+
'%hour%',
|
1485 |
+
'%minute%',
|
1486 |
+
'%second%',
|
1487 |
+
$leavename? '' : '%postname%',
|
1488 |
+
'%post_id%',
|
1489 |
+
'%category%',
|
1490 |
+
'%author%',
|
1491 |
+
$leavename? '' : '%pagename%',
|
1492 |
+
);
|
1493 |
+
|
1494 |
+
if ( empty($post->ID) ) {
|
1495 |
+
return false;
|
1496 |
+
}
|
1497 |
+
|
1498 |
+
$permalink = $this->permalink_structure;
|
1499 |
+
|
1500 |
+
if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {
|
1501 |
+
$unixtime = strtotime($post->post_date);
|
1502 |
+
|
1503 |
+
$category = '';
|
1504 |
+
if ( strpos($permalink, '%category%') !== false ) {
|
1505 |
+
$cats = get_the_category($post->ID);
|
1506 |
+
if ( $cats ) {
|
1507 |
+
usort($cats, '_usort_terms_by_ID'); // order by ID
|
1508 |
+
|
1509 |
+
$category = get_term_meta($cats[0]->term_id, $this->get_meta_key(), true );
|
1510 |
+
if (!$category) $category = $cats[0]->slug;
|
1511 |
+
|
1512 |
+
if ( $parent = $cats[0]->parent )
|
1513 |
+
$category = $this->get_category_parents($parent, false, '/', true) . $category;
|
1514 |
+
}
|
1515 |
+
// show default category in permalinks, without
|
1516 |
+
// having to assign it explicitly
|
1517 |
+
if ( empty($category) ) {
|
1518 |
+
$default_category = get_category( get_option( 'default_category' ) );
|
1519 |
+
|
1520 |
+
$default_category_slug = get_term_meta($default_category->term_id, $this->get_meta_key(), true );
|
1521 |
+
if (!$default_category_slug) $default_category_slug = $default_category->slug;
|
1522 |
+
|
1523 |
+
$category = is_wp_error( $default_category ) ? '' : $default_category_slug;
|
1524 |
+
}
|
1525 |
+
}
|
1526 |
+
|
1527 |
+
$author = '';
|
1528 |
+
if ( strpos($permalink, '%author%') !== false ) {
|
1529 |
+
$authordata = get_userdata($post->post_author);
|
1530 |
+
$author = $authordata->user_nicename;
|
1531 |
+
}
|
1532 |
+
|
1533 |
+
$date = explode(" ",date('Y m d H i s', $unixtime));
|
1534 |
+
|
1535 |
+
$post_slug = get_post_meta($post->ID, $this->get_meta_key(), true );
|
1536 |
+
if (!$post_slug) {
|
1537 |
+
$post_slug = $post->post_name;
|
1538 |
+
}
|
1539 |
+
|
1540 |
+
$rewritereplace =
|
1541 |
+
array(
|
1542 |
+
$date[0],
|
1543 |
+
$date[1],
|
1544 |
+
$date[2],
|
1545 |
+
$date[3],
|
1546 |
+
$date[4],
|
1547 |
+
$date[5],
|
1548 |
+
$post_slug,
|
1549 |
+
$post->ID,
|
1550 |
+
$category,
|
1551 |
+
$author,
|
1552 |
+
$post_slug,
|
1553 |
+
);
|
1554 |
+
$permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink));
|
1555 |
+
if ($q_config['url_mode'] != 1) {
|
1556 |
+
$permalink = user_trailingslashit($permalink, 'single');
|
1557 |
+
}
|
1558 |
+
} else { // if they're not using the fancy permalink option
|
1559 |
+
$permalink = home_url('?p=' . $post->ID);
|
1560 |
+
}
|
1561 |
+
|
1562 |
+
return $permalink;
|
1563 |
+
}
|
1564 |
+
|
1565 |
+
|
1566 |
+
|
1567 |
+
/**
|
1568 |
+
* Retrieve category parents with separator.
|
1569 |
+
*
|
1570 |
+
* @param int $id Category ID.
|
1571 |
+
* @param bool $link Optional, default is false. Whether to format with link.
|
1572 |
+
* @param string $separator Optional, default is '/'. How to separate categories.
|
1573 |
+
* @param bool $nicename Optional, default is false. Whether to use nice name for display.
|
1574 |
+
* @param array $visited Optional. Already linked to categories to prevent duplicates.
|
1575 |
+
* @return string
|
1576 |
+
*
|
1577 |
+
* @since 1.0
|
1578 |
+
*/
|
1579 |
+
private function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) {
|
1580 |
+
|
1581 |
+
$chain = '';
|
1582 |
+
if(phpversion() >= 5.4) {
|
1583 |
+
$parent = get_category( $id );
|
1584 |
+
} else {
|
1585 |
+
$parent = &get_category( $id );
|
1586 |
+
}
|
1587 |
+
|
1588 |
+
if ( is_wp_error( $parent ) ) {
|
1589 |
+
return $parent;
|
1590 |
+
}
|
1591 |
+
|
1592 |
+
if ( $nicename ) {
|
1593 |
+
|
1594 |
+
$name = get_term_meta($parent->term_id, $this->get_meta_key(), true );
|
1595 |
+
if (!$name) {
|
1596 |
+
$name = $parent->slug;
|
1597 |
+
}
|
1598 |
+
} else {
|
1599 |
+
$name = $parent->name;
|
1600 |
+
}
|
1601 |
+
|
1602 |
+
if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
|
1603 |
+
$visited[] = $parent->parent;
|
1604 |
+
$chain .= $this->get_category_parents( $parent->parent, $link, $separator, $nicename, $visited );
|
1605 |
+
}
|
1606 |
+
|
1607 |
+
if ( $link ) {
|
1608 |
+
$chain .= '<a href="' . get_category_link( $parent->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
|
1609 |
+
} else {
|
1610 |
+
$chain .= $name.$separator;
|
1611 |
+
}
|
1612 |
+
|
1613 |
+
return $chain;
|
1614 |
+
}
|
1615 |
+
|
1616 |
+
|
1617 |
+
|
1618 |
+
|
1619 |
+
|
1620 |
+
/**
|
1621 |
+
* Filter that translates the slug parts in a page link
|
1622 |
+
*
|
1623 |
+
* @param $link the link for the page generated by Wordpress
|
1624 |
+
* @param $id the id of the page
|
1625 |
+
* @return the link translated
|
1626 |
+
*
|
1627 |
+
* @since 1.0
|
1628 |
+
*/
|
1629 |
+
public function _get_page_link( $link, $id ) {
|
1630 |
+
global $post, $wp_rewrite, $q_config;
|
1631 |
+
|
1632 |
+
$current_post = $post;
|
1633 |
+
|
1634 |
+
if ( !$id ) {
|
1635 |
+
$id = (int) $post->ID;
|
1636 |
+
} else {
|
1637 |
+
if(phpversion() >= 5.4) {
|
1638 |
+
$current_post = get_post($id);
|
1639 |
+
} else {
|
1640 |
+
$current_post = &get_post($id);
|
1641 |
+
}
|
1642 |
+
}
|
1643 |
+
|
1644 |
+
$draft_or_pending = in_array( $current_post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
|
1645 |
+
|
1646 |
+
$link = $wp_rewrite->get_page_permastruct();
|
1647 |
+
|
1648 |
+
if ( !empty($link) && ( isset($current_post->post_status) && !$draft_or_pending ) ) {
|
1649 |
+
|
1650 |
+
$link = str_replace('%pagename%', $this->get_page_uri($id), $link);
|
1651 |
+
|
1652 |
+
$link = trim($link, '/'); // hack
|
1653 |
+
$link = home_url("/$link/"); // hack
|
1654 |
+
|
1655 |
+
if ($q_config['url_mode'] != 1)
|
1656 |
+
$link = user_trailingslashit($link, 'page');
|
1657 |
+
|
1658 |
+
} else {
|
1659 |
+
|
1660 |
+
$link = home_url("?page_id=$id");
|
1661 |
+
}
|
1662 |
+
|
1663 |
+
return $link;
|
1664 |
+
}
|
1665 |
+
|
1666 |
+
|
1667 |
+
|
1668 |
+
/**
|
1669 |
+
* Builds URI for a page.
|
1670 |
+
*
|
1671 |
+
* Sub pages will be in the "directory" under the parent page post name.
|
1672 |
+
*
|
1673 |
+
* @param mixed $page Page object or page ID.
|
1674 |
+
* @return string Page URI.
|
1675 |
+
*
|
1676 |
+
* @since 1.0
|
1677 |
+
*/
|
1678 |
+
private function get_page_uri($page) {
|
1679 |
+
|
1680 |
+
if ( ! is_object($page) ) {
|
1681 |
+
$page = get_post($page);
|
1682 |
+
}
|
1683 |
+
|
1684 |
+
$uri = get_post_meta( $page->ID, $this->get_meta_key(), true );
|
1685 |
+
if (!$uri) {
|
1686 |
+
$uri = $page->post_name;
|
1687 |
+
}
|
1688 |
+
|
1689 |
+
// A page cannot be it's own parent.
|
1690 |
+
if ( $page->post_parent == $page->ID ) {
|
1691 |
+
return $uri;
|
1692 |
+
}
|
1693 |
+
|
1694 |
+
while ($page->post_parent != 0) {
|
1695 |
+
$page = get_post($page->post_parent);
|
1696 |
+
|
1697 |
+
$page_name = get_post_meta( $page->ID, $this->get_meta_key(), true );
|
1698 |
+
if (!$page_name) {
|
1699 |
+
$page_name = $page->post_name;
|
1700 |
+
}
|
1701 |
+
|
1702 |
+
$uri = $page_name . "/" . $uri;
|
1703 |
+
}
|
1704 |
+
|
1705 |
+
return $uri;
|
1706 |
+
}
|
1707 |
+
|
1708 |
+
|
1709 |
+
|
1710 |
+
/**
|
1711 |
+
* Filter that translates the slug parts in a term link
|
1712 |
+
*
|
1713 |
+
* @param $link the link for the page generated by Wordpress
|
1714 |
+
* @param $term object
|
1715 |
+
* @param $taxonomy object
|
1716 |
+
* @return the link translated
|
1717 |
+
*
|
1718 |
+
* @since 1.0
|
1719 |
+
*/
|
1720 |
+
public function term_link( $link, $term, $taxonomy ) {
|
1721 |
+
global $wp_rewrite;
|
1722 |
+
|
1723 |
+
// parse normal term names for ?tag=tagname
|
1724 |
+
if (empty($this->permalink_structure)) return $link;
|
1725 |
+
|
1726 |
+
if ( !is_object($term) ) {
|
1727 |
+
if ( is_int($term) ) {
|
1728 |
+
$term = &get_term($term, $taxonomy);
|
1729 |
+
} else {
|
1730 |
+
$term = $this->get_term_by('slug', $term, $taxonomy);
|
1731 |
+
}
|
1732 |
+
}
|
1733 |
+
|
1734 |
+
if ( !is_object($term) ) {
|
1735 |
+
$term = new WP_Error('invalid_term', __('Empty Term'));
|
1736 |
+
}
|
1737 |
+
|
1738 |
+
if ( is_wp_error( $term ) ) {
|
1739 |
+
return $term;
|
1740 |
+
}
|
1741 |
+
|
1742 |
+
$taxonomy = $term->taxonomy;
|
1743 |
+
|
1744 |
+
$termlink = apply_filters( 'qts_permastruct', $wp_rewrite->get_extra_permastruct($taxonomy), $taxonomy);
|
1745 |
+
|
1746 |
+
$slug = get_term_meta( $term->term_id, $this->get_meta_key(), true );
|
1747 |
+
if (!$slug) {
|
1748 |
+
$slug = $term->slug;
|
1749 |
+
}
|
1750 |
+
|
1751 |
+
$t = get_taxonomy($taxonomy);
|
1752 |
+
|
1753 |
+
if ( empty($termlink) ) {
|
1754 |
+
if ( 'category' == $taxonomy )
|
1755 |
+
$termlink = '?cat=' . $term->term_id;
|
1756 |
+
elseif ( $t->query_var )
|
1757 |
+
$termlink = "?$t->query_var=$slug";
|
1758 |
+
else
|
1759 |
+
$termlink = "?taxonomy=$taxonomy&term=$slug";
|
1760 |
+
$termlink = home_url($termlink);
|
1761 |
+
} else {
|
1762 |
+
if ( $t->rewrite['hierarchical'] ) {
|
1763 |
+
$hierarchical_slugs = array();
|
1764 |
+
$ancestors = get_ancestors($term->term_id, $taxonomy);
|
1765 |
+
foreach ( (array)$ancestors as $ancestor ) {
|
1766 |
+
$ancestor_term = get_term($ancestor, $taxonomy);
|
1767 |
+
|
1768 |
+
$ancestor_slug = get_term_meta( $ancestor_term->term_id, $this->get_meta_key(), true );
|
1769 |
+
if (!$ancestor_slug) $ancestor_slug = $ancestor_term->slug;
|
1770 |
+
|
1771 |
+
$hierarchical_slugs[] = $ancestor_slug;
|
1772 |
+
}
|
1773 |
+
$hierarchical_slugs = array_reverse($hierarchical_slugs);
|
1774 |
+
$hierarchical_slugs[] = $slug;
|
1775 |
+
$termlink = str_replace("%$taxonomy%", implode('/', $hierarchical_slugs), $termlink);
|
1776 |
+
} else {
|
1777 |
+
$termlink = str_replace("%$taxonomy%", $slug, $termlink);
|
1778 |
+
}
|
1779 |
+
$termlink = home_url( user_trailingslashit($termlink, 'category') );
|
1780 |
+
}
|
1781 |
+
return $termlink;
|
1782 |
+
}
|
1783 |
+
|
1784 |
+
|
1785 |
+
|
1786 |
+
/**
|
1787 |
+
* Get all Term data from database by Term field and data.
|
1788 |
+
*
|
1789 |
+
* @param (string) $field Either 'slug', 'name', or 'id'
|
1790 |
+
* @param (string|int) $value Search for this term value
|
1791 |
+
* @param (string) $taxonomy Taxonomy Name
|
1792 |
+
* @param (string) $output Constant OBJECT, ARRAY_A, or ARRAY_N
|
1793 |
+
* @param (string) $filter Optional, default is raw or no WordPress defined filter will applied.
|
1794 |
+
* @return (mixed) Term Row from database. Will return false if $taxonomy does not exist or $term was not found.
|
1795 |
+
*
|
1796 |
+
* @since 1.0
|
1797 |
+
*/
|
1798 |
+
private function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') {
|
1799 |
+
global $wpdb;
|
1800 |
+
|
1801 |
+
$original_field = $field;
|
1802 |
+
|
1803 |
+
if ( ! taxonomy_exists($taxonomy) ) {
|
1804 |
+
return false;
|
1805 |
+
}
|
1806 |
+
|
1807 |
+
if ( 'slug' == $field ) {
|
1808 |
+
$field = 'm.meta_key = \''.$this->get_meta_key().'\' AND m.meta_value';
|
1809 |
+
$value = sanitize_title($value);
|
1810 |
+
if ( empty($value) )
|
1811 |
+
return false;
|
1812 |
+
} else if ( 'name' == $field ) {
|
1813 |
+
// Assume already escaped
|
1814 |
+
$value = stripslashes($value);
|
1815 |
+
$field = 't.name';
|
1816 |
+
} else {
|
1817 |
+
$term = get_term( (int) $value, $taxonomy, $output, $filter);
|
1818 |
+
if ( is_wp_error( $term ) )
|
1819 |
+
$term = false;
|
1820 |
+
return $term;
|
1821 |
+
}
|
1822 |
+
|
1823 |
+
$term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t, $wpdb->term_taxonomy AS tt, $wpdb->termmeta AS m WHERE t.term_id = tt.term_id AND tt.term_id = m.term_id AND tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value) );
|
1824 |
+
|
1825 |
+
if ( !$term && 'slug' == $original_field ) {
|
1826 |
+
$field = 't.slug';
|
1827 |
+
$term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value) );
|
1828 |
+
}
|
1829 |
+
|
1830 |
+
if ( !$term ) {
|
1831 |
+
return false;
|
1832 |
+
}
|
1833 |
+
|
1834 |
+
wp_cache_add($term->term_id, $term, $taxonomy);
|
1835 |
+
|
1836 |
+
$term = apply_filters('get_term', $term, $taxonomy);
|
1837 |
+
$term = apply_filters("get_$taxonomy", $term, $taxonomy);
|
1838 |
+
$term = sanitize_term($term, $taxonomy, $filter);
|
1839 |
+
|
1840 |
+
if ( $output == OBJECT ) {
|
1841 |
+
return $term;
|
1842 |
+
} elseif ( $output == ARRAY_A ) {
|
1843 |
+
return get_object_vars($term);
|
1844 |
+
} elseif ( $output == ARRAY_N ) {
|
1845 |
+
return array_values(get_object_vars($term));
|
1846 |
+
} else {
|
1847 |
+
return $term;
|
1848 |
+
}
|
1849 |
+
}
|
1850 |
+
|
1851 |
+
|
1852 |
+
|
1853 |
+
/**
|
1854 |
+
* Fix for:
|
1855 |
+
* - Taxonomy names in Taxonomy Manage page
|
1856 |
+
* - 'Popular Tags' in Taxonomy (Tags) Manage page
|
1857 |
+
* - Category filter dropdown menu in Post Manage page
|
1858 |
+
* - Category list in Post Edit page
|
1859 |
+
* - 'Most Used' tags list in Post Edit page (but have issues when saving)
|
1860 |
+
*
|
1861 |
+
* @param (array) $terms
|
1862 |
+
* @param (string|array) $taxonomy
|
1863 |
+
* @since 1.2
|
1864 |
+
*/
|
1865 |
+
function get_terms($terms, $taxonomy) {
|
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 |
+
|
1893 |
+
|
1894 |
+
|
1895 |
+
/**
|
1896 |
+
* Fix for:
|
1897 |
+
* - Taxonomy & custom taxonomy names in Post Manage page
|
1898 |
+
* - List of tags already added to the post in Post
|
1899 |
+
* - Edit page (but have issues when saving)
|
1900 |
+
*
|
1901 |
+
* @param (array) $terms
|
1902 |
+
* @param (int|array) $obj_id
|
1903 |
+
* @param (string|array) $taxonomy
|
1904 |
+
* @param (array) $taxonomy
|
1905 |
+
* @since 1.2
|
1906 |
+
*/
|
1907 |
+
function get_object_terms($terms, $obj_id, $taxonomy, $args) {
|
1908 |
+
|
1909 |
+
global $pagenow;
|
1910 |
+
|
1911 |
+
// Although in post edit page the tags are translated,
|
1912 |
+
// but when saving/updating the post Wordpress considers
|
1913 |
+
// the translated tags as new tags. Due to this
|
1914 |
+
// issue I limit this 'hack' to the post manage
|
1915 |
+
// page only.
|
1916 |
+
if ( $pagenow == 'edit.php' ) {
|
1917 |
+
|
1918 |
+
// $taxonomy output seems to be wrapped
|
1919 |
+
// in single quotes, thus remove them to
|
1920 |
+
// make the output valid
|
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) {
|
1928 |
+
if( isset( $meta[$term->name][$lang] ) ) {
|
1929 |
+
$term->name = $meta[$term->name][$lang];
|
1930 |
+
}
|
1931 |
+
};
|
1932 |
+
};
|
1933 |
+
|
1934 |
+
}
|
1935 |
+
return $terms;
|
1936 |
+
}
|
1937 |
+
|
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 |
+
|
1952 |
+
|
1953 |
+
|
1954 |
+
/**
|
1955 |
+
* Hide auttomatically the wordpress slug blog in edit posts page
|
1956 |
+
*
|
1957 |
+
* @since 1.0
|
1958 |
+
*/
|
1959 |
+
public function hide_slug_box() {
|
1960 |
+
global $pagenow;
|
1961 |
+
|
1962 |
+
switch ( $pagenow ):
|
1963 |
+
case 'edit-tags.php':
|
1964 |
+
|
1965 |
+
echo "<!-- QTS remove slug box -->" . PHP_EOL;
|
1966 |
+
echo "<script type=\"text/javascript\" charset=\"utf-8\">" . PHP_EOL;
|
1967 |
+
echo " jQuery(document).ready(function($){" . PHP_EOL;
|
1968 |
+
echo " $(\"#tag-slug\").parent().hide();" . PHP_EOL;
|
1969 |
+
echo " $(\".form-field td #slug\").parent().parent().hide();" . PHP_EOL;
|
1970 |
+
echo " });" . PHP_EOL;
|
1971 |
+
echo "</script>" . PHP_EOL;
|
1972 |
+
break;
|
1973 |
+
|
1974 |
+
case 'post.php':
|
1975 |
+
|
1976 |
+
echo "<!-- QTS remove slug box -->" . PHP_EOL;
|
1977 |
+
echo "<style type=\"text/css\" media=\"screen\">" . PHP_EOL;
|
1978 |
+
echo " #edit-slug-box { display: none !important}" . PHP_EOL;
|
1979 |
+
echo "</style>" . PHP_EOL;
|
1980 |
+
break;
|
1981 |
+
endswitch;
|
1982 |
+
}
|
1983 |
+
|
1984 |
+
|
1985 |
+
|
1986 |
+
/**
|
1987 |
+
* Creates a metabox for every post, page and post type avaiable
|
1988 |
+
*
|
1989 |
+
* @since 1.0
|
1990 |
+
*/
|
1991 |
+
public function add_slug_meta_box() {
|
1992 |
+
|
1993 |
+
if ( function_exists( 'add_meta_box' ) ) {
|
1994 |
+
|
1995 |
+
add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), 'post', 'side', 'high');
|
1996 |
+
add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), 'page', 'side', 'high' );
|
1997 |
+
|
1998 |
+
foreach ( get_post_types( array('_builtin' => false ) ) as $ptype )
|
1999 |
+
add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), $ptype, 'side', 'high' );
|
2000 |
+
}
|
2001 |
+
}
|
2002 |
+
|
2003 |
+
|
2004 |
+
|
2005 |
+
/**
|
2006 |
+
* Shows the fields where insert the translated slugs in the post and page edit form.
|
2007 |
+
*
|
2008 |
+
* @param $post (object) current post object
|
2009 |
+
*
|
2010 |
+
* @since 1.0
|
2011 |
+
*/
|
2012 |
+
public function draw_meta_box( $post ) {
|
2013 |
+
global $q_config;
|
2014 |
+
|
2015 |
+
// Use nonce for verification
|
2016 |
+
echo "<table style=\"width:100%\">" . PHP_EOL;
|
2017 |
+
echo "<input type=\"hidden\" name=\"qts_nonce\" id=\"qts_nonce\" value=\"" . wp_create_nonce( 'qts_nonce' ) . "\" />" . PHP_EOL;
|
2018 |
+
|
2019 |
+
foreach ($q_config['enabled_languages'] as $lang):
|
2020 |
+
|
2021 |
+
$slug = get_post_meta( $post->ID, $this->get_meta_key($lang), true);
|
2022 |
+
|
2023 |
+
$value = ( $slug ) ? htmlspecialchars( $slug , ENT_QUOTES ) : '';
|
2024 |
+
|
2025 |
+
echo "<tr>" . PHP_EOL;
|
2026 |
+
echo "<th style=\"text-align:left; width:10%; color:#555 \"><label for=\"qts_{$lang}_slug\">".__($q_config['language_name'][$lang], 'qtranslate')."</label></th>" . PHP_EOL;
|
2027 |
+
echo "<td><input type=\"text\" id=\"qts_{$lang}_slug\" name=\"qts_{$lang}_slug\" value=\"$value\" style=\"width:90%; margin-left:10%; color:#777\" /></td>" . PHP_EOL;
|
2028 |
+
echo "</tr>" . PHP_EOL;
|
2029 |
+
|
2030 |
+
endforeach;
|
2031 |
+
|
2032 |
+
echo '</table>' . PHP_EOL;
|
2033 |
+
}
|
2034 |
+
|
2035 |
+
|
2036 |
+
|
2037 |
+
/**
|
2038 |
+
* Sanitize title as slug, if empty slug
|
2039 |
+
*
|
2040 |
+
* @param $post (object) the post object
|
2041 |
+
* @param $slug (string) the slug name
|
2042 |
+
* @param $lang (string) the language
|
2043 |
+
* @return the slug validated
|
2044 |
+
*
|
2045 |
+
* @since 1.0
|
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;
|
2053 |
+
}
|
2054 |
+
|
2055 |
+
$name = ( $post_title == '' || strlen($post_title) == 0 ) ? $post_name : $post_title;
|
2056 |
+
|
2057 |
+
$slug = trim($slug);
|
2058 |
+
|
2059 |
+
$slug = (empty($slug)) ? sanitize_title($name) : sanitize_title($slug);
|
2060 |
+
|
2061 |
+
|
2062 |
+
|
2063 |
+
return htmlspecialchars( $slug , ENT_QUOTES );
|
2064 |
+
}
|
2065 |
+
|
2066 |
+
|
2067 |
+
|
2068 |
+
/**
|
2069 |
+
* Validates post slug against repetitions per language
|
2070 |
+
*
|
2071 |
+
* @param $post (object) the post object
|
2072 |
+
* @param $slug (string) the slug name
|
2073 |
+
* @param $lang (string) the language
|
2074 |
+
* @return the slug validated
|
2075 |
+
*
|
2076 |
+
* @since 1.0
|
2077 |
+
*/
|
2078 |
+
public function unique_post_slug( $slug, $post, $lang ) {
|
2079 |
+
|
2080 |
+
$original_status = $post->post_status;
|
2081 |
+
|
2082 |
+
if ( in_array($post->post_status, array('draft', 'pending')) ) {
|
2083 |
+
$post->post_status = 'publish';
|
2084 |
+
}
|
2085 |
+
|
2086 |
+
$slug = $this->wp_unique_post_slug( $slug, $post->ID, $post->post_status, $post->post_type, $post->post_parent, $lang );
|
2087 |
+
|
2088 |
+
$post->post_status = $original_status;
|
2089 |
+
|
2090 |
+
return $slug;
|
2091 |
+
}
|
2092 |
+
|
2093 |
+
|
2094 |
+
|
2095 |
+
/**
|
2096 |
+
* Computes a unique slug for the post and language, when given the desired slug and some post details.
|
2097 |
+
*
|
2098 |
+
* @param string $slug the desired slug (post_name)
|
2099 |
+
* @param integer $post_ID
|
2100 |
+
* @param string $post_status no uniqueness checks are made if the post is still draft or pending
|
2101 |
+
* @param string $post_type
|
2102 |
+
* @param integer $post_parent
|
2103 |
+
* @return string unique slug for the post, based on language meta_value (with a -1, -2, etc. suffix)
|
2104 |
+
*
|
2105 |
+
* @since 1.0
|
2106 |
+
*/
|
2107 |
+
public function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $lang ) {
|
2108 |
+
if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
|
2109 |
+
return $slug;
|
2110 |
+
}
|
2111 |
+
|
2112 |
+
global $wpdb, $wp_rewrite;
|
2113 |
+
|
2114 |
+
$feeds = $wp_rewrite->feeds;
|
2115 |
+
if ( ! is_array( $feeds ) ) {
|
2116 |
+
$feeds = array();
|
2117 |
+
}
|
2118 |
+
|
2119 |
+
$meta_key = $this->get_meta_key($lang);
|
2120 |
+
if ( 'attachment' == $post_type ) {
|
2121 |
+
// Attachment slugs must be unique across all types.
|
2122 |
+
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
|
2123 |
+
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) );
|
2124 |
+
|
2125 |
+
if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
|
2126 |
+
$suffix = 2;
|
2127 |
+
do {
|
2128 |
+
$alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
|
2129 |
+
$post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID ) );
|
2130 |
+
$suffix++;
|
2131 |
+
} while ( $post_name_check );
|
2132 |
+
$slug = $alt_post_name;
|
2133 |
+
}
|
2134 |
+
} else {
|
2135 |
+
// Post slugs must be unique across all posts.
|
2136 |
+
$check_sql = "SELECT $wpdb->postmeta.meta_value FROM $wpdb->posts,$wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '%s' AND $wpdb->postmeta.meta_value = '%s' AND $wpdb->posts.post_type = %s AND ID != %d LIMIT 1";
|
2137 |
+
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $meta_key, $slug, $post_type, $post_ID ) );
|
2138 |
+
|
2139 |
+
if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
|
2140 |
+
$suffix = 2;
|
2141 |
+
do {
|
2142 |
+
$alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
|
2143 |
+
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $meta_key, $alt_post_name, $post_type, $post_ID ) );
|
2144 |
+
$suffix++;
|
2145 |
+
} while ( $post_name_check );
|
2146 |
+
$slug = $alt_post_name;
|
2147 |
+
}
|
2148 |
+
}
|
2149 |
+
|
2150 |
+
return $slug;
|
2151 |
+
}
|
2152 |
+
|
2153 |
+
|
2154 |
+
|
2155 |
+
|
2156 |
+
/**
|
2157 |
+
* Saves the translated slug when the page is saved
|
2158 |
+
*
|
2159 |
+
* @param $post_id the post id
|
2160 |
+
* @param $post the post object
|
2161 |
+
*
|
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 |
+
|
2168 |
+
|
2169 |
+
if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) // check autosave
|
2170 |
+
|| (!isset($_POST['post_ID']) || $post_id != $_POST['post_ID']) // check revision
|
2171 |
+
|| (!wp_verify_nonce( $_POST['qts_nonce'], 'qts_nonce')) // verify nonce
|
2172 |
+
|| (!current_user_can($post_type_object->cap->edit_post, $post_id))) { // check permission
|
2173 |
+
return $post_id;
|
2174 |
+
}
|
2175 |
+
|
2176 |
+
foreach ($this->get_enabled_languages() as $lang) {
|
2177 |
+
|
2178 |
+
$meta_name = $this->get_meta_key($lang);
|
2179 |
+
$meta_value = apply_filters( 'qts_validate_post_slug', $_POST["qts_{$lang}_slug"], $post, $lang);
|
2180 |
+
|
2181 |
+
delete_post_meta($post_id, $meta_name);
|
2182 |
+
update_post_meta($post_id, $meta_name, $meta_value);
|
2183 |
+
|
2184 |
+
}
|
2185 |
+
}
|
2186 |
+
|
2187 |
+
|
2188 |
+
|
2189 |
+
/**
|
2190 |
+
* Display multiple input fields, one per language
|
2191 |
+
*
|
2192 |
+
* @param $term the term object
|
2193 |
+
*
|
2194 |
+
* @since 1.0
|
2195 |
+
*/
|
2196 |
+
public function show_term_fields( $term ) {
|
2197 |
+
global $q_config;
|
2198 |
+
|
2199 |
+
// prints the fields in edit page
|
2200 |
+
if (isset($_GET['action']) && $_GET['action'] == 'edit' ):
|
2201 |
+
|
2202 |
+
echo "<table class=\"form-table\">" . PHP_EOL;
|
2203 |
+
echo "<input type=\"hidden\" name=\"qts_nonce\" id=\"qts_nonce\" value=\"" . wp_create_nonce( 'qts_nonce' ) . "\" />" . PHP_EOL;
|
2204 |
+
|
2205 |
+
foreach( $q_config['enabled_languages'] as $lang ) {
|
2206 |
+
|
2207 |
+
$slug = (is_object($term)) ? get_term_meta( $term->term_id, $this->get_meta_key($lang), true ) : '';
|
2208 |
+
|
2209 |
+
$value = ( $slug ) ? htmlspecialchars( $slug , ENT_QUOTES ) : '';
|
2210 |
+
|
2211 |
+
echo "<tr class=\"form-field form-required\">" . PHP_EOL;
|
2212 |
+
echo "<th scope=\"row\" valig=\"top\"><label for=\"qts_term_{$lang}_slug\">Slug (".__($q_config['language_name'][$lang], 'qtranslate').")</label></th>" . PHP_EOL;
|
2213 |
+
echo "<td><input type=\"text\" name=\"qts_{$lang}_slug\" value=\"$value\" /></td></tr>" . PHP_EOL;
|
2214 |
+
|
2215 |
+
}
|
2216 |
+
|
2217 |
+
echo '</table>';
|
2218 |
+
|
2219 |
+
// prints the fields in new page
|
2220 |
+
else:
|
2221 |
+
echo "<input type=\"hidden\" name=\"qts_nonce\" id=\"qts_nonce\" value=\"" . wp_create_nonce( 'qts_nonce' ) . "\" />" . PHP_EOL;
|
2222 |
+
|
2223 |
+
foreach( $q_config['enabled_languages'] as $lang ) {
|
2224 |
+
|
2225 |
+
echo "<div class=\"form-field\">" . PHP_EOL;
|
2226 |
+
|
2227 |
+
$slug = (is_object($term)) ? get_term_meta( $term->term_id, $this->get_meta_key($lang), true ) : '';
|
2228 |
+
|
2229 |
+
$value = ( $slug ) ? htmlspecialchars( $slug , ENT_QUOTES ) : '';
|
2230 |
+
|
2231 |
+
|
2232 |
+
echo "<label for=\"qts_{$lang}_slug\">Slug (".__($q_config['language_name'][$lang], 'qtranslate').")</label>" . PHP_EOL;
|
2233 |
+
echo "<input type=\"text\" name=\"qts_term_{$lang}_slug\" value=\"$value\" aria-required=\"true\">" . PHP_EOL;
|
2234 |
+
|
2235 |
+
echo '</div>';
|
2236 |
+
|
2237 |
+
}
|
2238 |
+
|
2239 |
+
endif;
|
2240 |
+
}
|
2241 |
+
|
2242 |
+
|
2243 |
+
|
2244 |
+
/**
|
2245 |
+
* Sanitize title as slug, if empty slug
|
2246 |
+
*
|
2247 |
+
* @param $term (object) the term object
|
2248 |
+
* @param $slug (string) the slug name
|
2249 |
+
* @param $lang (string) the language
|
2250 |
+
* @return the slug validated
|
2251 |
+
*
|
2252 |
+
* @since 1.0
|
2253 |
+
*/
|
2254 |
+
public function validate_term_slug( $slug, $term, $lang ) {
|
2255 |
+
|
2256 |
+
global $q_config;
|
2257 |
+
|
2258 |
+
$lang_name = $q_config['term_name'][$term->name][$lang];
|
2259 |
+
|
2260 |
+
$ajax_name = 'new' . $term->taxonomy;
|
2261 |
+
|
2262 |
+
$post_name = isset($_POST['name']) ? $_POST['name'] : '';
|
2263 |
+
|
2264 |
+
$term_name = isset($_POST[$ajax_name]) ? trim($_POST[$ajax_name]) : $post_name;
|
2265 |
+
|
2266 |
+
if (empty($term_name)) {
|
2267 |
+
return $slug;
|
2268 |
+
}
|
2269 |
+
|
2270 |
+
$name = ( $lang_name == '' || strlen($lang_name) == 0 ) ? $term_name : $lang_name;
|
2271 |
+
|
2272 |
+
$slug = trim($slug);
|
2273 |
+
|
2274 |
+
$slug = (empty($slug)) ? sanitize_title($name) : sanitize_title($slug);
|
2275 |
+
|
2276 |
+
return htmlspecialchars( $slug , ENT_QUOTES );
|
2277 |
+
}
|
2278 |
+
|
2279 |
+
|
2280 |
+
|
2281 |
+
/**
|
2282 |
+
* Will make slug unique per language, if it isn't already.
|
2283 |
+
*
|
2284 |
+
* @param string $slug The string that will be tried for a unique slug
|
2285 |
+
* @param object $term The term object that the $slug will belong too
|
2286 |
+
* @param object $lang The language reference
|
2287 |
+
* @return string Will return a true unique slug.
|
2288 |
+
*
|
2289 |
+
* @since 1.0
|
2290 |
+
*/
|
2291 |
+
public function unique_term_slug($slug, $term, $lang) {
|
2292 |
+
|
2293 |
+
global $wpdb;
|
2294 |
+
|
2295 |
+
$meta_key_name = $this->get_meta_key($lang);
|
2296 |
+
$query = $wpdb->prepare("SELECT term_id FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s' AND term_id != %d ", $meta_key_name, $slug, $term->term_id);
|
2297 |
+
$exists_slug = $wpdb->get_results($query);
|
2298 |
+
|
2299 |
+
if ( empty($exists_slug) ) {
|
2300 |
+
return $slug;
|
2301 |
+
}
|
2302 |
+
|
2303 |
+
// If we didn't get a unique slug, try appending a number to make it unique.
|
2304 |
+
$query = $wpdb->prepare("SELECT meta_value FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s' AND term_id != %d", $meta_key_name, $slug, $term->term_id);
|
2305 |
+
|
2306 |
+
if ( $wpdb->get_var( $query ) ) {
|
2307 |
+
$num = 2;
|
2308 |
+
do {
|
2309 |
+
$alt_slug = $slug . "-$num";
|
2310 |
+
$num++;
|
2311 |
+
$slug_check = $wpdb->get_var(
|
2312 |
+
$wpdb->prepare(
|
2313 |
+
"SELECT meta_value FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s'",
|
2314 |
+
$meta_key_name,
|
2315 |
+
$alt_slug) );
|
2316 |
+
} while ( $slug_check );
|
2317 |
+
$slug = $alt_slug;
|
2318 |
+
}
|
2319 |
+
|
2320 |
+
return $slug;
|
2321 |
+
}
|
2322 |
+
|
2323 |
+
|
2324 |
+
|
2325 |
+
/**
|
2326 |
+
* Display multiple input fields, one per language
|
2327 |
+
*
|
2328 |
+
* @param $term_id the term id
|
2329 |
+
* @param $tt_id the term taxonomy id
|
2330 |
+
* @param $taxonomy the term object
|
2331 |
+
*
|
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);
|
2361 |
+
|
2362 |
+
delete_term_meta($term_id, $meta_name);
|
2363 |
+
update_term_meta($term_id, $meta_name, $meta_value);
|
2364 |
+
}
|
2365 |
+
}
|
2366 |
+
|
2367 |
+
|
2368 |
+
|
2369 |
+
/**
|
2370 |
+
* deletes termmeta rows associated with the term
|
2371 |
+
*
|
2372 |
+
* @since 1.0
|
2373 |
+
*/
|
2374 |
+
public function delete_term($term_id, $tt_id, $taxonomy) {
|
2375 |
+
global $wpdb;
|
2376 |
+
|
2377 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE term_id = %d", $term_id ) );
|
2378 |
+
}
|
2379 |
+
|
2380 |
+
|
2381 |
+
|
2382 |
+
/**
|
2383 |
+
* adds support for qtranslate in taxonomies
|
2384 |
+
*
|
2385 |
+
* @since 1.0
|
2386 |
+
*/
|
2387 |
+
public function taxonomies_hooks() {
|
2388 |
+
|
2389 |
+
$taxonomies = $this->get_public_taxonomies();
|
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'));
|
2398 |
+
add_filter('manage_'.$taxonomy->name.'_custom_column', array(&$this, 'taxonomy_custom_column'), 0, 3);
|
2399 |
+
}
|
2400 |
+
}
|
2401 |
+
}
|
2402 |
+
|
2403 |
+
|
2404 |
+
|
2405 |
+
/*
|
2406 |
+
* Bug fix for slug column in taxonomies
|
2407 |
+
*
|
2408 |
+
* @since 1.0
|
2409 |
+
*/
|
2410 |
+
public function taxonomy_columns($columns) {
|
2411 |
+
unset($columns['slug']);
|
2412 |
+
unset($columns['posts']);
|
2413 |
+
|
2414 |
+
$columns['qts-slug'] = __('Slug', 'qts');
|
2415 |
+
$columns['posts'] = __('Posts');
|
2416 |
+
|
2417 |
+
return $columns;
|
2418 |
+
}
|
2419 |
+
|
2420 |
+
|
2421 |
+
|
2422 |
+
/*
|
2423 |
+
* Bug fix for slug column in taxonomies
|
2424 |
+
*
|
2425 |
+
* @since 1.0
|
2426 |
+
*/
|
2427 |
+
public function taxonomy_custom_column($str, $column_name, $term_id) {
|
2428 |
+
|
2429 |
+
switch ($column_name) {
|
2430 |
+
case 'qts-slug':
|
2431 |
+
echo get_term_meta($term_id, $this->get_meta_key(), true);
|
2432 |
+
break;
|
2433 |
+
}
|
2434 |
+
return false;
|
2435 |
+
}
|
2436 |
+
|
2437 |
+
|
2438 |
+
|
2439 |
+
|
2440 |
+
/**
|
2441 |
+
* Bug fix for multisite blog names
|
2442 |
+
*
|
2443 |
+
* @since 1.0
|
2444 |
+
*/
|
2445 |
+
public function blog_names($blogs) {
|
2446 |
+
|
2447 |
+
foreach ($blogs as $blog) {
|
2448 |
+
$blog->blogname = __($blog->blogname);
|
2449 |
+
}
|
2450 |
+
|
2451 |
+
return $blogs;
|
2452 |
+
}
|
2453 |
+
|
2454 |
+
|
2455 |
+
|
2456 |
+
/**
|
2457 |
+
* Initialise the Language Widget selector
|
2458 |
+
*
|
2459 |
+
* @since 1.0
|
2460 |
+
*/
|
2461 |
+
public function widget_init() {
|
2462 |
+
|
2463 |
+
if (class_exists('qTranslateWidget')) {
|
2464 |
+
unregister_widget('qTranslateWidget');
|
2465 |
+
}
|
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 |
+
}
|
2479 |
+
|
2480 |
+
|
2481 |
+
|
2482 |
+
/**
|
2483 |
+
* remove some default dashboard Widgets on Desktop
|
2484 |
+
*
|
2485 |
+
* @since 1.0
|
2486 |
+
*/
|
2487 |
+
function remove_dashboard_widgets() {
|
2488 |
+
global $wp_meta_boxes;
|
2489 |
+
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
|
2490 |
+
}
|
2491 |
+
|
2492 |
+
|
2493 |
+
|
2494 |
+
/**
|
2495 |
+
* adds support for qtranslate nav menus
|
2496 |
+
*
|
2497 |
+
* @since 1.0
|
2498 |
+
*/
|
2499 |
+
public function fix_nav_menu() {
|
2500 |
+
global $pagenow;
|
2501 |
+
|
2502 |
+
if( $pagenow != 'nav-menus.php' ) {
|
2503 |
+
return;
|
2504 |
+
}
|
2505 |
+
|
2506 |
+
wp_enqueue_script( 'nav-menu-query', plugins_url( 'assets/js/qts-nav-menu-min.js' , dirname(__FILE__ ) ), 'nav-menu', '1.0' );
|
2507 |
+
add_meta_box( 'qt-languages', __('Languages'), array(&$this, 'nav_menu_meta_box'), 'nav-menus', 'side', 'default' );
|
2508 |
+
}
|
2509 |
+
|
2510 |
+
|
2511 |
+
|
2512 |
+
/**
|
2513 |
+
* draws meta box for select language
|
2514 |
+
*
|
2515 |
+
* @since 1.0
|
2516 |
+
*/
|
2517 |
+
public function nav_menu_meta_box() {
|
2518 |
+
global $q_config;
|
2519 |
+
echo '<p>';
|
2520 |
+
foreach($q_config['enabled_languages'] as $id => $language) {
|
2521 |
+
$checked = ($language == $q_config['language']) ? ' checked="checked"' : '';
|
2522 |
+
echo '<p style="margin:0 0 5px 0"><input type="radio" style="margin-right:5px" name="wa_qt_lang" value="' . $language . '" id="wa_gt_lang_' . $id . '" ' . $checked . '/>';
|
2523 |
+
echo '<label for="wa_gt_lang_' . $id . '">';
|
2524 |
+
echo '<img src="' . trailingslashit(WP_CONTENT_URL).$q_config['flag_location'].$q_config['flag'][$language] . '"/> ';
|
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 |
+
|
2535 |
+
|
2536 |
+
|
2537 |
+
/**
|
2538 |
+
* Language select function for templating
|
2539 |
+
*
|
2540 |
+
* @param $type (string) choose the type of menu: 'text', 'image', 'both', 'dropdown'
|
2541 |
+
* @param $args (array) some args for draw the menu: array( 'id', 'class', 'short' );
|
2542 |
+
*
|
2543 |
+
* @since 1.0
|
2544 |
+
*/
|
2545 |
+
public function language_menu( $type = "text", $args = array() ) {
|
2546 |
+
global $q_config;
|
2547 |
+
|
2548 |
+
// default arguments
|
2549 |
+
$defaults = array(
|
2550 |
+
'id' => "qts-lang-menu",
|
2551 |
+
'class' => "qts-lang-menu",
|
2552 |
+
'short' => false
|
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 ) {
|
2560 |
+
|
2561 |
+
case 'image':
|
2562 |
+
case 'text':
|
2563 |
+
case 'both':
|
2564 |
+
|
2565 |
+
$baseurl = dirname(plugins_url());
|
2566 |
+
$num_languages = count($languages);
|
2567 |
+
echo "<ul id=\"{$args['id']}\" class=\"qts_type_{$type} {$args['class']}\">". PHP_EOL;
|
2568 |
+
|
2569 |
+
foreach( $languages as $index => $lang ):
|
2570 |
+
|
2571 |
+
$url = $this->get_current_url($lang);
|
2572 |
+
|
2573 |
+
$item_class = array();
|
2574 |
+
if ( (string)$q_config['language'] == (string)$lang ) $item_class[] = 'current-menu-item';
|
2575 |
+
if ( $index == ( $num_languages - 1) ) $item_class[] = 'last-child';
|
2576 |
+
|
2577 |
+
|
2578 |
+
$item_class = ' class="qts_lang_item ' . implode(' ', $item_class) . '"';
|
2579 |
+
|
2580 |
+
$language_name = ($args['short']) ? $lang : $q_config['language_name'][$lang];
|
2581 |
+
|
2582 |
+
if ( $type == 'image' ) {
|
2583 |
+
$link_class = " class=\"qtrans_flag qtrans_flag_$lang\"";
|
2584 |
+
$link_content = "<span style=\"display:none\">$language_name</span>";
|
2585 |
+
} else if ( $type == 'both' ) {
|
2586 |
+
$link_class = " class=\"qts_both qtrans_flag qtrans_flag_$lang\"";
|
2587 |
+
$link_content = "$language_name";
|
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];
|
2595 |
+
|
2596 |
+
//TODO: add i18n for alt attribute
|
2597 |
+
//43LC: hardcoding height and width
|
2598 |
+
$link_flag = "<img widht=\"18\" height=\"12\" src=\"$link_flag_url\" alt=\"$language_name\" />";
|
2599 |
+
}
|
2600 |
+
echo "<li$item_class><a href=\"$url\" lang=\"$lang\" hreflang=\"$lang\"$link_class>$link_flag$link_content</a></li>" . PHP_EOL;
|
2601 |
+
|
2602 |
+
endforeach;
|
2603 |
+
|
2604 |
+
echo "</ul>". PHP_EOL;
|
2605 |
+
|
2606 |
+
break;
|
2607 |
+
|
2608 |
+
case 'dropdown':
|
2609 |
+
|
2610 |
+
echo "<select id=\"{$args['id']}\" class=\"{$args['class']}\" onchange=\"window.location.href=this.options[this.selectedIndex].value\">". PHP_EOL;
|
2611 |
+
|
2612 |
+
foreach( $languages as $index => $lang ):
|
2613 |
+
|
2614 |
+
$url = $this->get_current_url($lang);
|
2615 |
+
|
2616 |
+
$item_class = '';
|
2617 |
+
if ( (string)$q_config['language'] == (string)$lang ) $item_class = 'selected="selected"';
|
2618 |
+
|
2619 |
+
$language_name = ($args['short']) ? $lang : $q_config['language_name'][$lang];
|
2620 |
+
|
2621 |
+
echo "<option value=\"$url\" $item_class>$language_name</option>" . PHP_EOL;
|
2622 |
+
|
2623 |
+
endforeach;
|
2624 |
+
|
2625 |
+
echo "</select>". PHP_EOL;
|
2626 |
+
|
2627 |
+
break;
|
2628 |
+
}
|
2629 |
+
|
2630 |
+
}
|
2631 |
+
}
|
includes/qtranslate-slug-settings-options.php
ADDED
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
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) to the theme's header.", "qts"),
|
66 |
+
__("adds a minified ( slighlty faster) file (qts-default.min.css) to the theme's header.", "qts"),
|
67 |
+
__("prints the styles directly into the theme's header.", "qts"),
|
68 |
+
__("neither include not print the default style.", "qts")
|
69 |
+
),
|
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 |
+
);
|
80 |
+
|
81 |
+
return $options;
|
82 |
+
}
|
83 |
+
|
84 |
+
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Define our form fields (settings)
|
88 |
+
*
|
89 |
+
* @package Qtranslate Slug
|
90 |
+
* @subpackage Settings
|
91 |
+
* @version 1.0
|
92 |
+
*
|
93 |
+
* @return array
|
94 |
+
*/
|
95 |
+
function qts_options_page_fields() {
|
96 |
+
|
97 |
+
$post_types = get_post_types( array('_builtin' => false, 'public' => true ), 'objects');
|
98 |
+
|
99 |
+
// each post type
|
100 |
+
foreach ($post_types as $post_type):
|
101 |
+
|
102 |
+
$options[] = array(
|
103 |
+
"section" => "post_types",
|
104 |
+
"id" => QTS_PREFIX . "post_type_" . $post_type->name,
|
105 |
+
"title" => $post_type->labels->singular_name,
|
106 |
+
"desc" => sprintf( __( '<code>http://example.org/<u>%s</u>/some-%s/</code>', 'qts' ), $post_type->name, $post_type->name),
|
107 |
+
'class' => 'qts-slug',
|
108 |
+
"type" => "multi-text",
|
109 |
+
"choices" => get_multi_txt_choices( $post_type->name),
|
110 |
+
"std" => ""
|
111 |
+
);
|
112 |
+
|
113 |
+
endforeach;
|
114 |
+
// end each post type
|
115 |
+
|
116 |
+
$options[] = array(
|
117 |
+
"section" => "taxonomies",
|
118 |
+
"id" => QTS_PREFIX . "taxonomy_category",
|
119 |
+
"title" => __('Categories'),
|
120 |
+
"desc" => __( '<code>http://example.org/<u>category</u>/some-category/</code>', 'qts' ),
|
121 |
+
"type" => "multi-text",
|
122 |
+
'class' => 'qts-slug',
|
123 |
+
"choices" => get_multi_txt_choices('category'),
|
124 |
+
"std" => ""
|
125 |
+
);
|
126 |
+
|
127 |
+
$options[] = array(
|
128 |
+
"section" => "taxonomies",
|
129 |
+
"id" => QTS_PREFIX . "taxonomy_post_tag",
|
130 |
+
"title" => __('Tags'),
|
131 |
+
"desc" => __( '<code>http://example.org/<u>tag</u>/some-tag/</code>', 'qts' ),
|
132 |
+
"type" => "multi-text",
|
133 |
+
'class' => 'qts-slug',
|
134 |
+
"choices" => get_multi_txt_choices('post_tag'),
|
135 |
+
"std" => ""
|
136 |
+
);
|
137 |
+
|
138 |
+
|
139 |
+
$taxonomies = get_taxonomies( array( 'public' => true, 'show_ui' => true, '_builtin' => false ), 'object' );
|
140 |
+
|
141 |
+
// each extra taxonomy
|
142 |
+
foreach ($taxonomies as $taxonomy):
|
143 |
+
|
144 |
+
$options[] = array(
|
145 |
+
"section" => "taxonomies",
|
146 |
+
"id" => QTS_PREFIX . "taxonomy_" . $taxonomy->name,
|
147 |
+
"title" => $taxonomy->labels->singular_name,
|
148 |
+
"desc" => sprintf( __( '<code>http://example.org/<u>%s</u>/some-%s/</code>', 'qts' ), $taxonomy->name, $taxonomy->name ),
|
149 |
+
"type" => "multi-text",
|
150 |
+
'class' => 'qts-slug',
|
151 |
+
"choices" => get_multi_txt_choices( $taxonomy->name),
|
152 |
+
"std" => ""
|
153 |
+
);
|
154 |
+
|
155 |
+
endforeach;
|
156 |
+
// end each extra taxonomy
|
157 |
+
|
158 |
+
|
159 |
+
return $options;
|
160 |
+
}
|
161 |
+
|
162 |
+
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Contextual Help
|
166 |
+
*
|
167 |
+
* @package Qtranslate Slug
|
168 |
+
* @subpackage Settings
|
169 |
+
* @version 1.0
|
170 |
+
*
|
171 |
+
*/
|
172 |
+
function qts_options_page_contextual_help() {
|
173 |
+
|
174 |
+
|
175 |
+
$text = "<h3>" . __('Qtranslate Settings - Contextual Help','qts') . "</h3>";
|
176 |
+
$text .= "<p>" . __('Contextual help goes here. You may want to use different html elements to format your text as you want.','qts') . "</p>";
|
177 |
+
|
178 |
+
return $text;
|
179 |
+
}
|
includes/qtranslate-slug-settings.php
ADDED
@@ -0,0 +1,978 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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' , dirname(__FILE__) ) );
|
297 |
+
wp_enqueue_script( 'qts_theme_settings_js', plugins_url( 'assets/js/qts-settings.js' , dirname(__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' , dirname(__FILE__) ), array('jquery') );
|
301 |
+
}
|
302 |
+
}
|
303 |
+
|
304 |
+
|
305 |
+
|
306 |
+
/**
|
307 |
+
* The Admin menu page
|
308 |
+
*
|
309 |
+
* @package Qtranslate Slug
|
310 |
+
* @subpackage Settings
|
311 |
+
* @version 1.0
|
312 |
+
*
|
313 |
+
*/
|
314 |
+
function qts_add_menu() {
|
315 |
+
global $current_screen;
|
316 |
+
|
317 |
+
$settings_output = qts_get_settings();
|
318 |
+
// collect our contextual help text
|
319 |
+
$qts_contextual_help = $settings_output['qts_contextual_help'];
|
320 |
+
|
321 |
+
// Display Settings Page link under the "Appearance" Admin Menu
|
322 |
+
$qts_settings_page = add_options_page(__('Qtranslate Slug options', 'qts'), __('Slug options', 'qts'), 'manage_options', QTS_PAGE_BASENAME, 'qts_show_settings_page');
|
323 |
+
// contextual help
|
324 |
+
/*
|
325 |
+
if ($qts_settings_page) {
|
326 |
+
$current_screen = get_current_screen();
|
327 |
+
//$current_screen->add_help_tab( array( $qts_settings_page, $qts_contextual_help ));
|
328 |
+
}
|
329 |
+
*/
|
330 |
+
// css & js
|
331 |
+
add_action( 'load-'. $qts_settings_page, 'qts_settings_scripts' );
|
332 |
+
}
|
333 |
+
add_action( 'admin_menu', 'qts_add_menu' );
|
334 |
+
|
335 |
+
|
336 |
+
|
337 |
+
////////////////////////////////////////////////////////////////////////////////////////
|
338 |
+
|
339 |
+
// Callback functions
|
340 |
+
|
341 |
+
|
342 |
+
|
343 |
+
/**
|
344 |
+
* Section HTML, displayed before the first option
|
345 |
+
*
|
346 |
+
* @package Qtranslate Slug
|
347 |
+
* @subpackage Settings
|
348 |
+
* @version 1.0
|
349 |
+
*
|
350 |
+
* @return echoes output
|
351 |
+
*/
|
352 |
+
function qts_section_fn($page_section = false) {
|
353 |
+
|
354 |
+
if ( !$page_section || !isset($page_section['id']) ) return;
|
355 |
+
|
356 |
+
switch ($page_section['id']) {
|
357 |
+
case 'post_types':
|
358 |
+
|
359 |
+
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>";
|
360 |
+
break;
|
361 |
+
|
362 |
+
case 'taxonomies':
|
363 |
+
|
364 |
+
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>";
|
365 |
+
break;
|
366 |
+
case 'styles':
|
367 |
+
|
368 |
+
echo "<p>" . __('The default styles are very minimal, and you can include them or not.', 'qts') . "</p>\n";
|
369 |
+
break;
|
370 |
+
}
|
371 |
+
}
|
372 |
+
|
373 |
+
|
374 |
+
|
375 |
+
/**
|
376 |
+
* Form Fields HTML: all form field types share the same function
|
377 |
+
*
|
378 |
+
* @package Qtranslate Slug
|
379 |
+
* @subpackage Settings
|
380 |
+
* @version 1.0
|
381 |
+
*
|
382 |
+
* @return echoes output
|
383 |
+
*/
|
384 |
+
function qts_show_form_field($args = array()) {
|
385 |
+
global $qtranslate_slug;
|
386 |
+
|
387 |
+
extract( $args );
|
388 |
+
|
389 |
+
// get the settings sections array
|
390 |
+
$settings_output = qts_get_settings();
|
391 |
+
$options = $qtranslate_slug->get_options();
|
392 |
+
|
393 |
+
// pass the standard value if the option is not yet set in the database
|
394 |
+
if ( !isset( $options[$id] ) && 'type' != 'checkbox' ) {
|
395 |
+
$options[$id] = $std;
|
396 |
+
}
|
397 |
+
|
398 |
+
// additional field class. output only if the class is defined in the create_setting arguments
|
399 |
+
$field_class = ($class != '') ? ' ' . $class : '';
|
400 |
+
|
401 |
+
// switch html display based on the setting type.
|
402 |
+
switch ( $type ) {
|
403 |
+
case 'text':
|
404 |
+
$options[$id] = stripslashes($options[$id]);
|
405 |
+
$options[$id] = esc_attr( $options[$id]);
|
406 |
+
echo "<input class='regular-text$field_class' type='text' id='$id' name='" . QTS_OPTIONS_NAME . "[$id]' value='$options[$id]' />";
|
407 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
408 |
+
break;
|
409 |
+
|
410 |
+
case "multi-text":
|
411 |
+
foreach($choices as $item) {
|
412 |
+
|
413 |
+
$item = explode("|",$item); // cat_name|cat_slug
|
414 |
+
$item[0] = esc_html__($item[0], 'qts');
|
415 |
+
|
416 |
+
if (!empty($options[$id])) {
|
417 |
+
foreach ($options[$id] as $option_key => $option_val){
|
418 |
+
if ($item[1] == $option_key) {
|
419 |
+
$value = $option_val;
|
420 |
+
}
|
421 |
+
}
|
422 |
+
} else {
|
423 |
+
$value = '';
|
424 |
+
}
|
425 |
+
|
426 |
+
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/>";
|
427 |
+
}
|
428 |
+
echo ($desc != '') ? "<span class='description'>$desc</span>" : "";
|
429 |
+
break;
|
430 |
+
|
431 |
+
case 'textarea':
|
432 |
+
$options[$id] = stripslashes($options[$id]);
|
433 |
+
$options[$id] = esc_html( $options[$id]);
|
434 |
+
echo "<textarea class='textarea$field_class' type='text' id='$id' name='" . QTS_OPTIONS_NAME . "[$id]' rows='5' cols='30'>$options[$id]</textarea>";
|
435 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
436 |
+
break;
|
437 |
+
|
438 |
+
case 'select':
|
439 |
+
echo "<select id='$id' class='select$field_class' name='" . QTS_OPTIONS_NAME . "[$id]'>";
|
440 |
+
foreach($choices as $item) {
|
441 |
+
$value = esc_attr($item, 'qts');
|
442 |
+
$item = esc_html($item, 'qts');
|
443 |
+
|
444 |
+
$selected = ($options[$id]==$value) ? 'selected="selected"' : '';
|
445 |
+
echo "<option value='$value' $selected>$item</option>";
|
446 |
+
}
|
447 |
+
echo "</select>";
|
448 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
449 |
+
break;
|
450 |
+
|
451 |
+
case 'select2':
|
452 |
+
echo "<select id='$id' class='select$field_class' name='" . QTS_OPTIONS_NAME . "[$id]'>";
|
453 |
+
foreach($choices as $item) {
|
454 |
+
|
455 |
+
$item = explode("|",$item);
|
456 |
+
$item[0] = esc_html($item[0], 'qts');
|
457 |
+
|
458 |
+
$selected = ($options[$id]==$item[1]) ? 'selected="selected"' : '';
|
459 |
+
echo "<option value='$item[1]' $selected>$item[0]</option>";
|
460 |
+
}
|
461 |
+
echo "</select>";
|
462 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
463 |
+
break;
|
464 |
+
|
465 |
+
case 'checkbox':
|
466 |
+
echo "<input class='checkbox$field_class' type='checkbox' id='$id' name='" . QTS_OPTIONS_NAME . "[$id]' value='1' " . checked( $options[$id], 1, false ) . " />";
|
467 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
468 |
+
break;
|
469 |
+
|
470 |
+
case "multi-checkbox":
|
471 |
+
foreach($choices as $item) {
|
472 |
+
|
473 |
+
$item = explode("|",$item);
|
474 |
+
$item[0] = esc_html($item[0], 'qts');
|
475 |
+
|
476 |
+
$checked = '';
|
477 |
+
|
478 |
+
if ( isset($options[$id][$item[1]]) ) {
|
479 |
+
if ( $options[$id][$item[1]] == 'true') {
|
480 |
+
$checked = 'checked="checked"';
|
481 |
+
}
|
482 |
+
}
|
483 |
+
|
484 |
+
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/>";
|
485 |
+
}
|
486 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
487 |
+
break;
|
488 |
+
|
489 |
+
case "multi-radio":
|
490 |
+
foreach($choices as $index => $item) {
|
491 |
+
|
492 |
+
$item = explode("|",$item);
|
493 |
+
$item_key = (count($item) > 1) ? esc_html($item[0], 'qts') : esc_html(end($item), 'qts');
|
494 |
+
$item_value = (count($item) > 1) ? esc_html($item[1], 'qts') : esc_html(end($item), 'qts');
|
495 |
+
|
496 |
+
$checked = '';
|
497 |
+
|
498 |
+
if ( isset($options[$id]) && $options[$id] === $item_value) {
|
499 |
+
$checked = 'checked="checked"';
|
500 |
+
}
|
501 |
+
|
502 |
+
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>";
|
503 |
+
if (isset($desc[$index]) && !empty($desc[$index])) {
|
504 |
+
echo ": " . $desc[$index];
|
505 |
+
}
|
506 |
+
echo "</label>";
|
507 |
+
}
|
508 |
+
echo (!is_array($desc) && $desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
509 |
+
break;
|
510 |
+
}
|
511 |
+
}
|
512 |
+
|
513 |
+
|
514 |
+
|
515 |
+
/**
|
516 |
+
* Validates base slugs per 'type' (post_type | taxonomy) and 'language'
|
517 |
+
*
|
518 |
+
* @package Qtranslate Slug
|
519 |
+
* @subpackage Settings
|
520 |
+
* @version 1.0
|
521 |
+
*
|
522 |
+
*/
|
523 |
+
function qts_sanitize_bases($base_slugs = false) {
|
524 |
+
|
525 |
+
if ( !$base_slugs || empty($base_slugs) ) return;
|
526 |
+
|
527 |
+
$base_slugs_processed = array();
|
528 |
+
$base_founded = array();
|
529 |
+
|
530 |
+
// changing array structure
|
531 |
+
foreach ($base_slugs as $type => $base) {
|
532 |
+
foreach ($base as $lang => $value) {
|
533 |
+
if ($value != ""):
|
534 |
+
$base_value = $value;
|
535 |
+
$count = 2;
|
536 |
+
while (in_array($value, $base_founded)) {
|
537 |
+
$value = "$base_value-$count";
|
538 |
+
$count++;
|
539 |
+
}
|
540 |
+
$base_founded[] = $base_slugs[$type][$lang] = $value;
|
541 |
+
endif;
|
542 |
+
}
|
543 |
+
}
|
544 |
+
|
545 |
+
return $base_slugs;
|
546 |
+
}
|
547 |
+
|
548 |
+
|
549 |
+
|
550 |
+
/**
|
551 |
+
* Admin Settings Page HTML
|
552 |
+
*
|
553 |
+
* @package Qtranslate Slug
|
554 |
+
* @subpackage Settings
|
555 |
+
* @version 1.0
|
556 |
+
*
|
557 |
+
* @return echoes output
|
558 |
+
*/
|
559 |
+
function qts_show_settings_page() {
|
560 |
+
// get the settings sections array
|
561 |
+
$settings_output = qts_get_settings();
|
562 |
+
?>
|
563 |
+
<div class="wrap">
|
564 |
+
<div class="icon32" id="icon-options-general"></div>
|
565 |
+
<h2><?php echo $settings_output['qts_page_title']; ?></h2>
|
566 |
+
|
567 |
+
<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>
|
568 |
+
|
569 |
+
<form action="options.php" method="post">
|
570 |
+
<?php
|
571 |
+
// upgrade notify
|
572 |
+
qts_upgrade();
|
573 |
+
// http://codex.wordpress.org/Function_Reference/settings_fields
|
574 |
+
settings_fields($settings_output['qts_option_name']);
|
575 |
+
|
576 |
+
// http://codex.wordpress.org/Function_Reference/do_settings_sections
|
577 |
+
do_settings_sections(__FILE__);
|
578 |
+
// rewrite rules
|
579 |
+
flush_rewrite_rules();
|
580 |
+
?>
|
581 |
+
<?php $css_path = plugin_dir_url(dirname(__FILE__)).'/assets/css/qts-default.css';
|
582 |
+
$file_styles = file_get_contents($css_path);
|
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'); ?>" />
|
590 |
+
</p>
|
591 |
+
|
592 |
+
</form>
|
593 |
+
</div><!-- wrap -->
|
594 |
+
<?php }
|
595 |
+
|
596 |
+
|
597 |
+
|
598 |
+
/**
|
599 |
+
* Validate input
|
600 |
+
*
|
601 |
+
* @package Qtranslate Slug
|
602 |
+
* @subpackage Settings
|
603 |
+
* @version 1.0
|
604 |
+
*
|
605 |
+
* @return array
|
606 |
+
*/
|
607 |
+
function qts_validate_options($input) {
|
608 |
+
|
609 |
+
// for enhanced security, create a new empty array
|
610 |
+
$valid_input = array();
|
611 |
+
|
612 |
+
// collect only the values we expect and fill the new $valid_input array
|
613 |
+
// i.e. whitelist our option IDs
|
614 |
+
|
615 |
+
// get the settings sections array
|
616 |
+
$settings_output = qts_get_settings();
|
617 |
+
|
618 |
+
$styleoptions = $settings_output['qts_page_styles'];
|
619 |
+
|
620 |
+
$slugoptions = $settings_output['qts_page_fields'];
|
621 |
+
|
622 |
+
$options = array_merge($styleoptions,$slugoptions);
|
623 |
+
|
624 |
+
// run a foreach and switch on option type
|
625 |
+
foreach ($options as $option):
|
626 |
+
|
627 |
+
switch ( $option['type'] ):
|
628 |
+
case 'text':
|
629 |
+
//switch validation based on the class!
|
630 |
+
switch ( $option['class'] ) {
|
631 |
+
//for numeric
|
632 |
+
case 'numeric':
|
633 |
+
//accept the input only when numeric!
|
634 |
+
$input[$option['id']] = trim($input[$option['id']]); // trim whitespace
|
635 |
+
$valid_input[$option['id']] = (is_numeric($input[$option['id']])) ? $input[$option['id']] : 'Expecting a Numeric value!';
|
636 |
+
|
637 |
+
// register error
|
638 |
+
if(is_numeric($input[$option['id']]) == FALSE) {
|
639 |
+
add_settings_error(
|
640 |
+
$option['id'], // setting title
|
641 |
+
QTS_PREFIX . '_txt_numeric_error', // error ID
|
642 |
+
__('Expecting a Numeric value! Please fix.', 'qts'), // error message
|
643 |
+
'error' // type of message
|
644 |
+
);
|
645 |
+
}
|
646 |
+
break;
|
647 |
+
|
648 |
+
//for multi-numeric values (separated by a comma)
|
649 |
+
case 'multinumeric':
|
650 |
+
//accept the input only when the numeric values are comma separated
|
651 |
+
$input[$option['id']] = trim($input[$option['id']]); // trim whitespace
|
652 |
+
|
653 |
+
if($input[$option['id']] !=''){
|
654 |
+
// /^-?\d+(?:,\s?-?\d+)*$/ matches: -1 | 1 | -12,-23 | 12,23 | -123, -234 | 123, 234 | etc.
|
655 |
+
$valid_input[$option['id']] = (preg_match('/^-?\d+(?:,\s?-?\d+)*$/', $input[$option['id']]) == 1) ? $input[$option['id']] : __('Expecting comma separated numeric values','qts');
|
656 |
+
}else{
|
657 |
+
$valid_input[$option['id']] = $input[$option['id']];
|
658 |
+
}
|
659 |
+
|
660 |
+
// register error
|
661 |
+
if($input[$option['id']] !='' && preg_match('/^-?\d+(?:,\s?-?\d+)*$/', $input[$option['id']]) != 1) {
|
662 |
+
add_settings_error(
|
663 |
+
$option['id'], // setting title
|
664 |
+
QTS_PREFIX . '_txt_multinumeric_error', // error ID
|
665 |
+
__('Expecting comma separated numeric values! Please fix.','qts'), // error message
|
666 |
+
'error' // type of message
|
667 |
+
);
|
668 |
+
}
|
669 |
+
break;
|
670 |
+
|
671 |
+
//for no html
|
672 |
+
case 'nohtml':
|
673 |
+
//accept the input only after stripping out all html, extra white space etc!
|
674 |
+
$input[$option['id']] = sanitize_text_field($input[$option['id']]); // need to add slashes still before sending to the database
|
675 |
+
$valid_input[$option['id']] = addslashes($input[$option['id']]);
|
676 |
+
break;
|
677 |
+
|
678 |
+
//for url
|
679 |
+
case 'url':
|
680 |
+
//accept the input only when the url has been sanited for database usage with esc_url_raw()
|
681 |
+
$input[$option['id']] = trim($input[$option['id']]); // trim whitespace
|
682 |
+
$valid_input[$option['id']] = esc_url_raw($input[$option['id']]);
|
683 |
+
break;
|
684 |
+
|
685 |
+
//for email
|
686 |
+
case 'email':
|
687 |
+
//accept the input only after the email has been validated
|
688 |
+
$input[$option['id']] = trim($input[$option['id']]); // trim whitespace
|
689 |
+
if($input[$option['id']] != ''){
|
690 |
+
$valid_input[$option['id']] = (is_email($input[$option['id']])!== FALSE) ? $input[$option['id']] : __('Invalid email', 'qts');
|
691 |
+
}elseif($input[$option['id']] == ''){
|
692 |
+
$valid_input[$option['id']] = __('This setting field cannot be empty! Please enter a valid email address.', 'qts');
|
693 |
+
}
|
694 |
+
|
695 |
+
// register error
|
696 |
+
if(is_email($input[$option['id']])== FALSE || $input[$option['id']] == '') {
|
697 |
+
add_settings_error(
|
698 |
+
$option['id'], // setting title
|
699 |
+
QTS_PREFIX . '_txt_email_error', // error ID
|
700 |
+
__('Please enter a valid email address.', 'qts'), // error message
|
701 |
+
'error' // type of message
|
702 |
+
);
|
703 |
+
}
|
704 |
+
break;
|
705 |
+
|
706 |
+
// a "cover-all" fall-back when the class argument is not set
|
707 |
+
default:
|
708 |
+
// accept only a few inline html elements
|
709 |
+
$allowed_html = array(
|
710 |
+
'a' => array('href' => array (),'title' => array ()),
|
711 |
+
'b' => array(),
|
712 |
+
'em' => array (),
|
713 |
+
'i' => array (),
|
714 |
+
'strong' => array()
|
715 |
+
);
|
716 |
+
// trim whitespace
|
717 |
+
$input[$option['id']] = trim($input[$option['id']]);
|
718 |
+
// find incorrectly nested or missing closing tags and fix markup
|
719 |
+
$input[$option['id']] = force_balance_tags($input[$option['id']]);
|
720 |
+
// need to add slashes still before sending to the database
|
721 |
+
$input[$option['id']] = wp_kses( $input[$option['id']], $allowed_html);
|
722 |
+
|
723 |
+
$valid_input[$option['id']] = addslashes($input[$option['id']]);
|
724 |
+
break;
|
725 |
+
}
|
726 |
+
break;
|
727 |
+
|
728 |
+
case "multi-text":
|
729 |
+
// this will hold the text values as an array of 'key' => 'value'
|
730 |
+
unset($textarray);
|
731 |
+
|
732 |
+
$text_values = array();
|
733 |
+
foreach ($option['choices'] as $k => $v ) {
|
734 |
+
// explode the connective
|
735 |
+
$pieces = explode("|", $v);
|
736 |
+
|
737 |
+
$text_values[] = $pieces[1];
|
738 |
+
}
|
739 |
+
|
740 |
+
foreach ($text_values as $v ) {
|
741 |
+
|
742 |
+
// Check that the option isn't empty
|
743 |
+
if (!empty($input[$option['id'] . '|' . $v])) {
|
744 |
+
// If it's not null, make sure it's sanitized, add it to an array
|
745 |
+
switch ($option['class']) {
|
746 |
+
// different sanitation actions based on the class create you own cases as you need them
|
747 |
+
|
748 |
+
//for numeric input
|
749 |
+
case 'numeric':
|
750 |
+
//accept the input only if is numberic!
|
751 |
+
$input[$option['id'] . '|' . $v]= trim($input[$option['id'] . '|' . $v]); // trim whitespace
|
752 |
+
$input[$option['id'] . '|' . $v]= (is_numeric($input[$option['id'] . '|' . $v])) ? $input[$option['id'] . '|' . $v] : '';
|
753 |
+
break;
|
754 |
+
|
755 |
+
case 'qts-slug':
|
756 |
+
// strip all html tags and white-space.
|
757 |
+
$type_ = end( explode('_', $option['id']) );
|
758 |
+
$input[$option['id'] . '|' . $v]= sanitize_title( sanitize_text_field( $input[$option['id'] . '|' . $v] ) );
|
759 |
+
$input[$option['id'] . '|' . $v]= addslashes($input[$option['id'] . '|' . $v]);
|
760 |
+
break;
|
761 |
+
|
762 |
+
// a "cover-all" fall-back when the class argument is not set
|
763 |
+
default:
|
764 |
+
// strip all html tags and white-space.
|
765 |
+
$input[$option['id'] . '|' . $v]= sanitize_text_field($input[$option['id'] . '|' . $v]); // need to add slashes still before sending to the database
|
766 |
+
$input[$option['id'] . '|' . $v]= addslashes($input[$option['id'] . '|' . $v]);
|
767 |
+
break;
|
768 |
+
}
|
769 |
+
// pass the sanitized user input to our $textarray array
|
770 |
+
$textarray[$v] = $input[$option['id'] . '|' . $v];
|
771 |
+
|
772 |
+
} else {
|
773 |
+
$textarray[$v] = '';
|
774 |
+
}
|
775 |
+
}
|
776 |
+
// pass the non-empty $textarray to our $valid_input array
|
777 |
+
if (!empty($textarray)) {
|
778 |
+
$valid_input[$option['id']] = $textarray;
|
779 |
+
}
|
780 |
+
break;
|
781 |
+
|
782 |
+
case 'textarea':
|
783 |
+
//switch validation based on the class!
|
784 |
+
switch ( $option['class'] ) {
|
785 |
+
//for only inline html
|
786 |
+
case 'inlinehtml':
|
787 |
+
// accept only inline html
|
788 |
+
// trim whitespace
|
789 |
+
$input[$option['id']] = trim($input[$option['id']]);
|
790 |
+
// find incorrectly nested or missing closing tags and fix markup
|
791 |
+
$input[$option['id']] = force_balance_tags($input[$option['id']]);
|
792 |
+
//wp_filter_kses expects content to be escaped!
|
793 |
+
$input[$option['id']] = addslashes($input[$option['id']]);
|
794 |
+
//calls stripslashes then addslashes
|
795 |
+
$valid_input[$option['id']] = wp_filter_kses($input[$option['id']]);
|
796 |
+
break;
|
797 |
+
|
798 |
+
//for no html
|
799 |
+
case 'nohtml':
|
800 |
+
//accept the input only after stripping out all html, extra white space etc!
|
801 |
+
// need to add slashes still before sending to the database
|
802 |
+
$input[$option['id']] = sanitize_text_field($input[$option['id']]);
|
803 |
+
$valid_input[$option['id']] = addslashes($input[$option['id']]);
|
804 |
+
break;
|
805 |
+
|
806 |
+
//for allowlinebreaks
|
807 |
+
case 'allowlinebreaks':
|
808 |
+
//accept the input only after stripping out all html, extra white space etc!
|
809 |
+
// need to add slashes still before sending to the database
|
810 |
+
$input[$option['id']] = wp_strip_all_tags($input[$option['id']]);
|
811 |
+
$valid_input[$option['id']] = addslashes($input[$option['id']]);
|
812 |
+
break;
|
813 |
+
|
814 |
+
// a "cover-all" fall-back when the class argument is not set
|
815 |
+
default:
|
816 |
+
// accept only limited html
|
817 |
+
//my allowed html
|
818 |
+
$allowed_html = array(
|
819 |
+
'a' => array('href' => array (),'title' => array ()),
|
820 |
+
'b' => array(),
|
821 |
+
'blockquote' => array('cite' => array ()),
|
822 |
+
'br' => array(),
|
823 |
+
'dd' => array(),
|
824 |
+
'dl' => array(),
|
825 |
+
'dt' => array(),
|
826 |
+
'em' => array (),
|
827 |
+
'i' => array (),
|
828 |
+
'li' => array(),
|
829 |
+
'ol' => array(),
|
830 |
+
'p' => array(),
|
831 |
+
'q' => array('cite' => array ()),
|
832 |
+
'strong' => array(),
|
833 |
+
'ul' => array(),
|
834 |
+
'h1' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
|
835 |
+
'h2' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
|
836 |
+
'h3' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
|
837 |
+
'h4' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
|
838 |
+
'h5' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
|
839 |
+
'h6' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ())
|
840 |
+
);
|
841 |
+
|
842 |
+
$input[$option['id']] = trim($input[$option['id']]); // trim whitespace
|
843 |
+
$input[$option['id']] = force_balance_tags($input[$option['id']]); // find incorrectly nested or missing closing tags and fix markup
|
844 |
+
$input[$option['id']] = wp_kses( $input[$option['id']], $allowed_html); // need to add slashes still before sending to the database
|
845 |
+
$valid_input[$option['id']] = addslashes($input[$option['id']]);
|
846 |
+
break;
|
847 |
+
}
|
848 |
+
break;
|
849 |
+
|
850 |
+
case 'select':
|
851 |
+
// check to see if the selected value is in our approved array of values!
|
852 |
+
$valid_input[$option['id']] = (in_array( $input[$option['id']], $option['choices']) ? $input[$option['id']] : '' );
|
853 |
+
break;
|
854 |
+
|
855 |
+
case 'select2':
|
856 |
+
// process $select_values
|
857 |
+
$select_values = array();
|
858 |
+
foreach ($option['choices'] as $k => $v) {
|
859 |
+
// explode the connective
|
860 |
+
$pieces = explode("|", $v);
|
861 |
+
|
862 |
+
$select_values[] = $pieces[1];
|
863 |
+
}
|
864 |
+
// check to see if selected value is in our approved array of values!
|
865 |
+
$valid_input[$option['id']] = (in_array( $input[$option['id']], $select_values) ? $input[$option['id']] : '' );
|
866 |
+
break;
|
867 |
+
|
868 |
+
case 'checkbox':
|
869 |
+
// if it's not set, default to null!
|
870 |
+
if (!isset($input[$option['id']])) {
|
871 |
+
$input[$option['id']] = null;
|
872 |
+
}
|
873 |
+
// Our checkbox value is either 0 or 1
|
874 |
+
$valid_input[$option['id']] = ( $input[$option['id']] == 1 ? 1 : 0 );
|
875 |
+
break;
|
876 |
+
|
877 |
+
case 'multi-checkbox':
|
878 |
+
unset($checkboxarray);
|
879 |
+
$check_values = array();
|
880 |
+
foreach ($option['choices'] as $k => $v ) {
|
881 |
+
// explode the connective
|
882 |
+
$pieces = explode("|", $v);
|
883 |
+
|
884 |
+
$check_values[] = $pieces[1];
|
885 |
+
}
|
886 |
+
|
887 |
+
foreach ($check_values as $v ) {
|
888 |
+
|
889 |
+
// Check that the option isn't null
|
890 |
+
if (!empty($input[$option['id'] . '|' . $v])) {
|
891 |
+
// If it's not null, make sure it's true, add it to an array
|
892 |
+
$checkboxarray[$v] = 'true';
|
893 |
+
}
|
894 |
+
else {
|
895 |
+
$checkboxarray[$v] = 'false';
|
896 |
+
}
|
897 |
+
}
|
898 |
+
// Take all the items that were checked, and set them as the main option
|
899 |
+
if (!empty($checkboxarray)) {
|
900 |
+
$valid_input[$option['id']] = $checkboxarray;
|
901 |
+
}
|
902 |
+
break;
|
903 |
+
|
904 |
+
case 'multi-radio':
|
905 |
+
$valid_input[$option['id']] = (empty($input) || !isset($input[$option['id']])) ? $option['std'] : $input[$option['id']];
|
906 |
+
break;
|
907 |
+
|
908 |
+
endswitch;
|
909 |
+
|
910 |
+
if (!empty($valid_input) && $valid_input[$option['id']] === "qts-slug" ) {
|
911 |
+
$valid_input = qts_sanitize_bases($valid_input);
|
912 |
+
} else {
|
913 |
+
$valid_input= $valid_input;
|
914 |
+
}
|
915 |
+
|
916 |
+
endforeach;
|
917 |
+
|
918 |
+
return $valid_input;
|
919 |
+
}
|
920 |
+
|
921 |
+
|
922 |
+
|
923 |
+
/**
|
924 |
+
* Helper function for creating admin messages
|
925 |
+
*
|
926 |
+
* @package Qtranslate Slug
|
927 |
+
* @subpackage Settings
|
928 |
+
* @version 1.0
|
929 |
+
*
|
930 |
+
* src: http://www.wprecipes.com/how-to-show-an-urgent-message-in-the-wordpress-admin-area
|
931 |
+
*
|
932 |
+
* @param (string) $message The message to echo
|
933 |
+
* @param (string) $msgclass The message class
|
934 |
+
* @return echoes the message
|
935 |
+
*/
|
936 |
+
function qts_show_msg($message, $msgclass = 'info') {
|
937 |
+
echo "<div id='message' class='$msgclass'>$message</div>";
|
938 |
+
}
|
939 |
+
|
940 |
+
|
941 |
+
|
942 |
+
/**
|
943 |
+
* Callback function for displaying admin messages
|
944 |
+
*
|
945 |
+
* @package Qtranslate Slug
|
946 |
+
* @subpackage Settings
|
947 |
+
* @version 1.0
|
948 |
+
*
|
949 |
+
* @return calls qts_show_msg()
|
950 |
+
*/
|
951 |
+
function qts_admin_msgs() {
|
952 |
+
global $current_screen;
|
953 |
+
|
954 |
+
// check for our settings page - need this in conditional further down
|
955 |
+
$qts_settings_pg = isset($_GET['page']) ? strpos($_GET['page'], QTS_PAGE_BASENAME) : '';
|
956 |
+
// collect setting errors/notices:
|
957 |
+
// http://codex.wordpress.org/Function_Reference/get_settings_errors
|
958 |
+
$set_errors = get_settings_errors();
|
959 |
+
|
960 |
+
// display admin message only for the admin to see, only on our settings page
|
961 |
+
// and only when setting errors/notices are returned!
|
962 |
+
if(current_user_can ('manage_options') && $qts_settings_pg !== false && !empty($set_errors)){
|
963 |
+
|
964 |
+
// have our settings succesfully been updated?
|
965 |
+
if($set_errors[0]['code'] == 'settings_updated' && isset($_GET['settings-updated'])){
|
966 |
+
qts_show_msg("<p>" . $set_errors[0]['message'] . "</p>", 'updated');
|
967 |
+
|
968 |
+
// have errors been found?
|
969 |
+
}else{
|
970 |
+
// there maybe more than one so run a foreach loop.
|
971 |
+
foreach($set_errors as $set_error){
|
972 |
+
// set the title attribute to match the error "setting title" - need this in js file
|
973 |
+
qts_show_msg("<p class='setting-error-message' title='" . $set_error['setting'] . "'>" . $set_error['message'] . "</p>", 'error');
|
974 |
+
}
|
975 |
+
}
|
976 |
+
}
|
977 |
+
}
|
978 |
+
add_action('admin_notices', 'qts_admin_msgs');
|
includes/termmeta-core.php
ADDED
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
languages/qts-pt_PT.mo
ADDED
Binary file
|
languages/qts-pt_PT.po
ADDED
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2012 qTranslate slug
|
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 |
+
|
19 |
+
#: qtranslate-slug.php
|
20 |
+
msgid "Language selector"
|
21 |
+
msgstr "Selector de idioma"
|
22 |
+
|
23 |
+
#: qtranslate-slug.php
|
24 |
+
msgid "Title:"
|
25 |
+
msgstr "Título:"
|
26 |
+
|
27 |
+
#: qtranslate-slug.php
|
28 |
+
msgid ""
|
29 |
+
"<p style=\"color:red\">This plugin requires qTranslate to be installed and "
|
30 |
+
"activated.</p>"
|
31 |
+
msgstr ""
|
32 |
+
"<p style=\"color:red\">Este plugin necessita do qTranslate instalado e "
|
33 |
+
"activado previamente.</p>"
|
34 |
+
|
35 |
+
#: qtranslate-slug.php
|
36 |
+
msgid "Slug"
|
37 |
+
msgstr "URL"
|
38 |
+
|
39 |
+
#: qtranslate-slug.php
|
40 |
+
msgid "Show short name (en):"
|
41 |
+
msgstr "Mostrar abreviatura (pt):"
|
42 |
+
|
43 |
+
#: qtranslate-slug-settings-options.php
|
44 |
+
msgid "Post types"
|
45 |
+
msgstr "Tipos de artigos"
|
46 |
+
|
47 |
+
#: qtranslate-slug-settings-options.php
|
48 |
+
msgid "Taxonomies"
|
49 |
+
msgstr "Taxonomias"
|
50 |
+
|
51 |
+
#: qtranslate-slug-settings-options.php
|
52 |
+
msgid "Slug (%s)"
|
53 |
+
msgstr "URL (%s)"
|
54 |
+
|
55 |
+
#: qtranslate-slug-settings-options.php
|
56 |
+
msgid "<code>http://example.org/<u>%s</u>/some-%s/</code>"
|
57 |
+
msgstr "<code>http://exemplo.org/<u>%s</u>/qualquer-%s/</code>"
|
58 |
+
|
59 |
+
#: qtranslate-slug-settings-options.php
|
60 |
+
msgid "<code>http://example.org/<u>category</u>/some-category/</code>"
|
61 |
+
msgstr "<code>http://exemplo.org/<u>categoria</u>/qualquer-categoria/</code>"
|
62 |
+
|
63 |
+
#: qtranslate-slug-settings-options.php
|
64 |
+
msgid "<code>http://example.org/<u>tag</u>/some-tag/</code>"
|
65 |
+
msgstr "<code>http://exemplo.org/<u>etiqueta</u>/qualquer-etiqueta/</code>"
|
66 |
+
|
67 |
+
#: qtranslate-slug-settings.php
|
68 |
+
msgid "Qtranslate Slug options"
|
69 |
+
msgstr "Opções do Qtranslate Slug"
|
70 |
+
|
71 |
+
#: qtranslate-slug-settings.php
|
72 |
+
msgid "Slug options"
|
73 |
+
msgstr "Opções do URL"
|
74 |
+
|
75 |
+
#: qtranslate-slug-settings.php
|
76 |
+
msgid "Save Changes"
|
77 |
+
msgstr "Guardar alterações"
|
78 |
+
|
79 |
+
#: qtranslate-slug-settings.php
|
80 |
+
msgid "Expecting a Numeric value! Please fix."
|
81 |
+
msgstr "É necessário um valor numérico! Por favor, corrija."
|
82 |
+
|
83 |
+
#: qtranslate-slug-settings.php
|
84 |
+
msgid "Expecting comma separated numeric values! Please fix."
|
85 |
+
msgstr ""
|
86 |
+
"São necessários valores numéricos separados por vírgulas! Por favor, corrija."
|
87 |
+
|
88 |
+
#: qtranslate-slug-settings.php
|
89 |
+
msgid "Invalid email"
|
90 |
+
msgstr "Email incorrecto"
|
91 |
+
|
92 |
+
#: qtranslate-slug-settings.php
|
93 |
+
msgid "This setting field cannot be empty! Please enter a valid email address."
|
94 |
+
msgstr ""
|
95 |
+
"Este campo não pode estar vazio! Por favor introduza um endereço de email "
|
96 |
+
"válido."
|
97 |
+
|
98 |
+
#: qtranslate-slug-settings.php
|
99 |
+
msgid "Please enter a valid email address."
|
100 |
+
msgstr "Por favor introduza um endereço de email válido."
|
101 |
+
|
102 |
+
#: qtranslate-slug-settings.php
|
103 |
+
msgid "upgrade now"
|
104 |
+
msgstr "actualizar agora"
|
105 |
+
|
106 |
+
#: qtranslate-slug.php
|
107 |
+
msgid "Please update your old data to the new system."
|
108 |
+
msgstr "Por favor actualize os seus dados antigos para o novo sistema."
|
109 |
+
|
110 |
+
#: qtranslate-slug-settings.php
|
111 |
+
msgid "Upgrade your data"
|
112 |
+
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:"
|
121 |
+
|
122 |
+
#: qtranslate-slug-settings.php
|
123 |
+
msgid "Sorry, some error happened. Refresh this page and try again please."
|
124 |
+
msgstr ""
|
125 |
+
"Lamentavelmente mas ocorreu um erro. Por favor refresque esta página e tente "
|
126 |
+
"novamente."
|
127 |
+
|
128 |
+
#: qtranslate-slug-settings.php
|
129 |
+
msgid "Congratulations, your data has been upgraded, you are up to date."
|
130 |
+
msgstr ""
|
131 |
+
"Parabéns, os seus dados foram actualizados e o sistema está agora actual."
|
132 |
+
|
133 |
+
#: qtranslate-slug-settings.php
|
134 |
+
msgid "One step more, select what type of slug is this: <strong>%s</strong>"
|
135 |
+
msgstr "Um passo mais, seleccione que tipo de URL é este: <strong>%s</strong>"
|
136 |
+
|
137 |
+
#: qtranslate-slug-settings.php
|
138 |
+
msgid "Post, Page or Custom post type"
|
139 |
+
msgstr "Artigo, Página ou Tipo de Artigo Personalizado"
|
140 |
+
|
141 |
+
#: qtranslate-slug-settings.php
|
142 |
+
msgid "Category, tag or custom taxonomy"
|
143 |
+
msgstr "Categoria, etiqueta ou taxonomia personalizada"
|
144 |
+
|
145 |
+
#: qtranslate-slug.php
|
146 |
+
msgid ""
|
147 |
+
"This plugin requires at least <strong>Wordpress 3.3</strong> and "
|
148 |
+
"<strong>Qtranslate(2.5.8 or newer)</strong>"
|
149 |
+
msgstr ""
|
150 |
+
"Este plugin requer no mínimo o <strong>Wordpress 3.3</strong> e "
|
151 |
+
"<strong>Qtranslate (2.5.8 ou superior)</strong>"
|
152 |
+
|
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 ""
|
182 |
+
"For example, the taxonomy <kbd>category</kbd>, in Spanish would be displayed "
|
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."
|
languages/qts.pot
CHANGED
@@ -12,6 +12,10 @@ msgstr ""
|
|
12 |
"Last-Translator: Carlos Sanz Garcia <carlos.sanz@gmail.com>\n"
|
13 |
"Language-Team: Carlos Sanz Garcia <carlos.sanz@gmail.com>\n"
|
14 |
|
|
|
|
|
|
|
|
|
15 |
#: qtranslate-slug.php
|
16 |
msgid "Language selector"
|
17 |
msgstr ""
|
@@ -21,11 +25,9 @@ msgid "Title:"
|
|
21 |
msgstr ""
|
22 |
|
23 |
#: qtranslate-slug.php
|
24 |
-
msgid "<p style
|
25 |
msgstr ""
|
26 |
|
27 |
-
#: qtranslate-slug.php
|
28 |
-
#: qtranslate-slug.php
|
29 |
#: qtranslate-slug.php
|
30 |
msgid "Slug"
|
31 |
msgstr ""
|
@@ -58,10 +60,6 @@ msgstr ""
|
|
58 |
msgid "<code>http://example.org/<u>tag</u>/some-tag/</code>"
|
59 |
msgstr ""
|
60 |
|
61 |
-
#: qtranslate-slug-settings-options.php
|
62 |
-
msgid "<code>http://example.org/<u>%s</u>/some-%s/</code>"
|
63 |
-
msgstr ""
|
64 |
-
|
65 |
#: qtranslate-slug-settings.php
|
66 |
msgid "Qtranslate Slug options"
|
67 |
msgstr ""
|
@@ -94,7 +92,6 @@ msgstr ""
|
|
94 |
msgid "Please enter a valid email address."
|
95 |
msgstr ""
|
96 |
|
97 |
-
#: qtranslate-slug-settings.php
|
98 |
#: qtranslate-slug-settings.php
|
99 |
msgid "upgrade now"
|
100 |
msgstr ""
|
@@ -136,7 +133,7 @@ msgid "This plugin requires at least <strong>Wordpress 3.3</strong> and <strong>
|
|
136 |
msgstr ""
|
137 |
|
138 |
#: qtranslate-slug-settings.php
|
139 |
-
msgid "If you activated previously the <a href=\"
|
140 |
msgstr ""
|
141 |
|
142 |
#: qtranslate-slug-settings.php
|
@@ -144,5 +141,57 @@ msgid "For example, the post_type <kbd>books</kbd>, in Spanish would be displaye
|
|
144 |
msgstr ""
|
145 |
|
146 |
#: qtranslate-slug-settings.php
|
147 |
-
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
|
148 |
-
msgstr ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
"Last-Translator: Carlos Sanz Garcia <carlos.sanz@gmail.com>\n"
|
13 |
"Language-Team: Carlos Sanz Garcia <carlos.sanz@gmail.com>\n"
|
14 |
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
#: qtranslate-slug.php
|
20 |
msgid "Language selector"
|
21 |
msgstr ""
|
25 |
msgstr ""
|
26 |
|
27 |
#: qtranslate-slug.php
|
28 |
+
msgid "<p style=\"color:red\">This plugin requires qTranslate to be installed and activated.</p>"
|
29 |
msgstr ""
|
30 |
|
|
|
|
|
31 |
#: qtranslate-slug.php
|
32 |
msgid "Slug"
|
33 |
msgstr ""
|
60 |
msgid "<code>http://example.org/<u>tag</u>/some-tag/</code>"
|
61 |
msgstr ""
|
62 |
|
|
|
|
|
|
|
|
|
63 |
#: qtranslate-slug-settings.php
|
64 |
msgid "Qtranslate Slug options"
|
65 |
msgstr ""
|
92 |
msgid "Please enter a valid email address."
|
93 |
msgstr ""
|
94 |
|
|
|
95 |
#: qtranslate-slug-settings.php
|
96 |
msgid "upgrade now"
|
97 |
msgstr ""
|
133 |
msgstr ""
|
134 |
|
135 |
#: qtranslate-slug-settings.php
|
136 |
+
msgid "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."
|
137 |
msgstr ""
|
138 |
|
139 |
#: qtranslate-slug-settings.php
|
141 |
msgstr ""
|
142 |
|
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 ""
|
phpunit.xml
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.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.
|
7 |
Author: Carlos Sanz Garcia
|
8 |
Author URI: http://github.com/not-only-code
|
9 |
*/
|
@@ -28,2304 +28,19 @@ function _debug( $message ) {
|
|
28 |
endif;
|
29 |
}
|
30 |
endif;
|
31 |
-
////////////////////////////////////////////////////////////////////////////////////////
|
32 |
-
|
33 |
-
// testing push from cloned repo
|
34 |
-
|
35 |
-
|
36 |
-
/**
|
37 |
-
* QtranslateSlugWidget class
|
38 |
-
*
|
39 |
-
* @since 1.0
|
40 |
-
*/
|
41 |
-
class QtranslateSlugWidget extends WP_Widget {
|
42 |
-
|
43 |
-
function QtranslateSlugWidget() {
|
44 |
-
$widget_ops = array('classname' => 'qts_widget', 'description' => __('Allows your visitors to choose a Language.','qtranslate') );
|
45 |
-
$this->WP_Widget('qtranslateslug', __('Language selector', 'qts'), $widget_ops);
|
46 |
-
}
|
47 |
-
|
48 |
-
function widget($args, $instance) {
|
49 |
-
extract($args);
|
50 |
-
|
51 |
-
echo $before_widget;
|
52 |
-
$title = empty($instance['title']) ? __('Language', 'qtranslate') : apply_filters('widget_title', $instance['title']);
|
53 |
-
$hide_title = empty($instance['hide-title']) ? false : 'on';
|
54 |
-
$type = $instance['type'];
|
55 |
-
$short_text = ($instance['short_text'] == 'on') ? true : false ;
|
56 |
-
|
57 |
-
if( $type!='text' && $type!='image' && $type!='both' && $type!='dropdown' ) $type='text';
|
58 |
-
|
59 |
-
if( $hide_title!='on')
|
60 |
-
echo $before_title . $title . $after_title;
|
61 |
-
|
62 |
-
qts_language_menu($type, array( 'id' => $this->id, 'short' => $short_text ) );
|
63 |
-
|
64 |
-
echo $after_widget;
|
65 |
-
}
|
66 |
-
|
67 |
-
function update($new_instance, $old_instance) {
|
68 |
-
$instance = $old_instance;
|
69 |
-
$instance['title'] = $new_instance['title'];
|
70 |
-
$instance['hide-title'] = $new_instance['hide-title'];
|
71 |
-
$instance['type'] = $new_instance['type'];
|
72 |
-
$instance['short_text'] = $new_instance['short_text'];
|
73 |
|
74 |
-
return $instance;
|
75 |
-
}
|
76 |
-
|
77 |
-
function form($instance) {
|
78 |
-
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'hide-title' => false, 'type' => 'text' ) );
|
79 |
-
$title = $instance['title'];
|
80 |
-
$hide_title = $instance['hide-title'];
|
81 |
-
$type = $instance['type'];
|
82 |
-
$short_text = $instance['short_text'];
|
83 |
-
?>
|
84 |
-
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'qtranslate'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
|
85 |
-
<p><label for="<?php echo $this->get_field_id('hide-title'); ?>"><?php _e('Hide Title:', 'qtranslate'); ?> <input type="checkbox" id="<?php echo $this->get_field_id('hide-title'); ?>" name="<?php echo $this->get_field_name('hide-title'); ?>" <?php echo ($hide_title=='on')?'checked="checked"':''; ?>/></label></p>
|
86 |
-
<p><?php _e('Display:', 'qtranslate'); ?></p>
|
87 |
-
<p><label for="<?php echo $this->get_field_id('type'); ?>1"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>1" value="text"<?php echo ($type=='text')?' checked="checked"':'' ?>/> <?php _e('Text only', 'qtranslate'); ?></label></p>
|
88 |
-
<p><label for="<?php echo $this->get_field_id('type'); ?>2"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>2" value="image"<?php echo ($type=='image')?' checked="checked"':'' ?>/> <?php _e('Image only', 'qtranslate'); ?></label></p>
|
89 |
-
<p><label for="<?php echo $this->get_field_id('type'); ?>3"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>3" value="both"<?php echo ($type=='both')?' checked="checked"':'' ?>/> <?php _e('Text and Image', 'qtranslate'); ?></label></p>
|
90 |
-
<p><label for="<?php echo $this->get_field_id('type'); ?>4"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>4" value="dropdown"<?php echo ($type=='dropdown')?' checked="checked"':'' ?>/> <?php _e('Dropdown Box', 'qtranslate'); ?></label></p>
|
91 |
-
<p><label for="<?php echo $this->get_field_id('short_text'); ?>"><?php _e('Show short name (en):', 'qts'); ?> <input type="checkbox" id="<?php echo $this->get_field_id('short_text'); ?>" name="<?php echo $this->get_field_name('short_text'); ?>" <?php checked($short_text, 'on') ?>/></label></p>
|
92 |
-
<p><?php _e('Display:', 'qtranslate'); ?></p>
|
93 |
-
|
94 |
-
<?php
|
95 |
-
}
|
96 |
-
}
|
97 |
////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
99 |
|
100 |
|
101 |
/**
|
102 |
-
*
|
103 |
*
|
104 |
-
* @since 1.
|
105 |
*/
|
106 |
-
class
|
107 |
-
|
108 |
-
|
109 |
-
/**
|
110 |
-
* array with old data system
|
111 |
-
*
|
112 |
-
* @var bool
|
113 |
-
*
|
114 |
-
* @since 1.0
|
115 |
-
*/
|
116 |
-
private $old_data = null;
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
/**
|
121 |
-
* stores permalink_structure option, for save queries to db
|
122 |
-
*
|
123 |
-
* @var string
|
124 |
-
*
|
125 |
-
* @since 1.0
|
126 |
-
*/
|
127 |
-
private $permalink_structure;
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
/**
|
132 |
-
* Stores options slugs from database
|
133 |
-
*
|
134 |
-
* @var array
|
135 |
-
*
|
136 |
-
* @since 1.0
|
137 |
-
*/
|
138 |
-
protected $options;
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
/**
|
143 |
-
* Variable used to override the language
|
144 |
-
*
|
145 |
-
* @var string
|
146 |
-
*
|
147 |
-
* @since 1.0
|
148 |
-
*/
|
149 |
-
private $lang = false;
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
/**
|
154 |
-
* slug in meta_key name in meta tables
|
155 |
-
*
|
156 |
-
* @var string
|
157 |
-
*
|
158 |
-
* @since 1.0
|
159 |
-
*/
|
160 |
-
private $meta_key = "_qts_slug_%s";
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
/**
|
165 |
-
* Array of translated versions of the current url
|
166 |
-
*
|
167 |
-
* @var array
|
168 |
-
*
|
169 |
-
* @since 1.0
|
170 |
-
*/
|
171 |
-
private $current_url = array();
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
/**
|
176 |
-
* return the current / temp language
|
177 |
-
*
|
178 |
-
* @since 1.0
|
179 |
-
*/
|
180 |
-
private function get_lang() {
|
181 |
-
global $q_config;
|
182 |
-
|
183 |
-
return ($this->lang) ? $this->lang : $q_config['language'];
|
184 |
-
}
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
/**
|
189 |
-
* getter: options
|
190 |
-
*
|
191 |
-
* @since 1.0
|
192 |
-
*/
|
193 |
-
public function get_options() {
|
194 |
-
$this->set_options();
|
195 |
-
return $this->options;
|
196 |
-
}
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
/**
|
201 |
-
* setter: options | permalink_structure
|
202 |
-
*
|
203 |
-
* @since 1.0
|
204 |
-
*/
|
205 |
-
public function set_options() {
|
206 |
-
if (empty($this->options)) {
|
207 |
-
$this->options = get_option(QTS_OPTIONS_NAME);
|
208 |
-
}
|
209 |
-
if (!$this->options)
|
210 |
-
add_option(QTS_OPTIONS_NAME, array());
|
211 |
-
|
212 |
-
if (is_null($this->permalink_structure))
|
213 |
-
$this->permalink_structure = get_option('permalink_structure');
|
214 |
-
}
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
/**
|
219 |
-
* setter: options | permalink_structure
|
220 |
-
*
|
221 |
-
* @since 1.0
|
222 |
-
*/
|
223 |
-
public function save_options($new_options = false) {
|
224 |
-
if (!$new_options || empty($new_options)) return;
|
225 |
-
|
226 |
-
if (count($this->options) != count($new_options)) return;
|
227 |
-
|
228 |
-
update_option(QTS_OPTIONS_NAME, $new_options);
|
229 |
-
$this->options = $new_options;
|
230 |
-
}
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
/**
|
235 |
-
* getter: meta key
|
236 |
-
*
|
237 |
-
* @since 1.0
|
238 |
-
*/
|
239 |
-
public function get_meta_key( $force_lang = false ) {
|
240 |
-
global $q_config;
|
241 |
-
|
242 |
-
$lang = $this->get_lang();
|
243 |
-
|
244 |
-
if ($force_lang) $lang = $force_lang;
|
245 |
-
|
246 |
-
return sprintf($this->meta_key, $lang); // returns: _qts_slug_en
|
247 |
-
}
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
/**
|
252 |
-
* check dependences for activation
|
253 |
-
*
|
254 |
-
* @since 1.0
|
255 |
-
*/
|
256 |
-
static function block_activate() {
|
257 |
-
global $wp_version;
|
258 |
-
|
259 |
-
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
260 |
-
|
261 |
-
return ( version_compare($wp_version, "3.3", "<" ) ||
|
262 |
-
(!is_plugin_active('qtranslate/qtranslate.php') &&
|
263 |
-
!is_plugin_active('mqtranslate/mqtranslate.php')) );
|
264 |
-
}
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
/**
|
269 |
-
* check if exists qtranslate and do the installation, support multisite
|
270 |
-
*
|
271 |
-
* @since 1.0
|
272 |
-
*/
|
273 |
-
public function install() {
|
274 |
-
global $wpdb;
|
275 |
-
|
276 |
-
if ( self::block_activate() ) return;
|
277 |
-
|
278 |
-
if ( function_exists('is_multisite') && is_multisite() ) {
|
279 |
-
|
280 |
-
if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) {
|
281 |
-
|
282 |
-
$old_blog = $wpdb->blogid;
|
283 |
-
$blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs"));
|
284 |
-
foreach ($blogids as $blog_id) {
|
285 |
-
switch_to_blog($blog_id);
|
286 |
-
$this->activate();
|
287 |
-
}
|
288 |
-
switch_to_blog($old_blog);
|
289 |
-
return;
|
290 |
-
}
|
291 |
-
}
|
292 |
-
|
293 |
-
$this->activate();
|
294 |
-
}
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
/**
|
299 |
-
* activates and do the installation
|
300 |
-
*
|
301 |
-
* @since 1.0
|
302 |
-
*/
|
303 |
-
private function activate() {
|
304 |
-
global $wp_rewrite;
|
305 |
-
|
306 |
-
$this->set_options();
|
307 |
-
|
308 |
-
$qts_version = get_option('qts_version');
|
309 |
-
|
310 |
-
// checks version and do the installation
|
311 |
-
if ( !$qts_version || $qts_version != QTS_VERSION ) {
|
312 |
-
|
313 |
-
// install termmeta table using functions from Simple-Term-Meta
|
314 |
-
// ( http://wordpress.org/extend/plugins/simple-term-meta/ )
|
315 |
-
install_term_meta_table();
|
316 |
-
|
317 |
-
// update installed option
|
318 |
-
update_option('qts_version', QTS_VERSION);
|
319 |
-
}
|
320 |
-
|
321 |
-
// regenerate rewrite rules in db
|
322 |
-
add_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
|
323 |
-
flush_rewrite_rules();
|
324 |
-
}
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
/**
|
329 |
-
* register front end styles and enqueue
|
330 |
-
*
|
331 |
-
* @since 1.1.7
|
332 |
-
*/
|
333 |
-
public function register_plugin_styles() {
|
334 |
-
wp_register_style( 'qts_front_styles', plugins_url( '/assets/css/qts-default.css', __FILE__ ) );
|
335 |
-
wp_enqueue_style( 'qts_front_styles' );
|
336 |
-
}
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
/**
|
341 |
-
* print front end styles
|
342 |
-
*
|
343 |
-
* @since 1.1.7
|
344 |
-
*/
|
345 |
-
public function print_plugin_styles() {
|
346 |
-
|
347 |
-
$css_path = dirname(__FILE__).'/assets/css/qts-default.css';
|
348 |
-
|
349 |
-
if (!file_exists($css_path) || !is_readable($css_path)) {
|
350 |
-
return;
|
351 |
-
}
|
352 |
-
|
353 |
-
$default_css_file = file_get_contents($css_path, FILE_USE_INCLUDE_PATH);
|
354 |
-
|
355 |
-
$css = "<style media=\"screen\">\n";
|
356 |
-
$css .= "$default_css_file\n";
|
357 |
-
$css .="</style>\n";
|
358 |
-
echo $css;
|
359 |
-
}
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
/**
|
364 |
-
* actions when deactivating the plugin
|
365 |
-
*
|
366 |
-
* @since 1.0
|
367 |
-
*/
|
368 |
-
public function deactivate() {
|
369 |
-
global $wp_rewrite;
|
370 |
-
|
371 |
-
// regenerate rewrite rules in db
|
372 |
-
remove_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
|
373 |
-
$wp_rewrite->flush_rules();
|
374 |
-
}
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
/**
|
379 |
-
* admin notice: update your old data
|
380 |
-
*
|
381 |
-
* @since 1.0
|
382 |
-
*/
|
383 |
-
function notice_update(){
|
384 |
-
global $current_screen;
|
385 |
-
|
386 |
-
if ($current_screen->id != 'settings_page_qtranslate-slug-settings'):
|
387 |
-
|
388 |
-
echo "<div class=\"updated\">" . PHP_EOL;
|
389 |
-
echo "<p><strong>Qtranslate Slug:</strong></p>" . PHP_EOL;
|
390 |
-
printf("<p>%s <a href=\"%s\" class=\"button\">%s</a></p>", __('Please update your old data to the new system.', 'qts'), add_query_arg(array('page' => 'qtranslate-slug-settings'), 'options-general.php'), __('upgrade now', 'qts')) . PHP_EOL;
|
391 |
-
echo "</div>" . PHP_EOL;
|
392 |
-
|
393 |
-
endif;
|
394 |
-
}
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
/**
|
399 |
-
* admin notice: update your old data
|
400 |
-
*
|
401 |
-
* @since 1.0
|
402 |
-
*/
|
403 |
-
function notice_dependences(){
|
404 |
-
global $current_screen;
|
405 |
-
|
406 |
-
echo "<div class=\"error\">" . PHP_EOL;
|
407 |
-
echo "<p><strong>Qtranslate Slug:</strong></p>" . PHP_EOL;
|
408 |
-
echo "<p>" . __('This plugin requires at least <strong>Wordpress 3.3</strong>, <strong>mqtranslate( 2.6.2.4 or newer)</strong> or <strong>Qtranslate(2.5.8 or newer)</strong>', 'qts') . "</p>" . PHP_EOL;
|
409 |
-
echo "</div>" . PHP_EOL;
|
410 |
-
}
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
/**
|
415 |
-
* checks if old table 'qtranslate_slug' exists and is not empty
|
416 |
-
*
|
417 |
-
* @return object | false
|
418 |
-
*
|
419 |
-
* @since 1.0
|
420 |
-
*/
|
421 |
-
public function check_old_data() {
|
422 |
-
global $wpdb;
|
423 |
-
|
424 |
-
if ($this->old_data === false) return false;
|
425 |
-
|
426 |
-
$table_name = $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}qtranslate_slug'");
|
427 |
-
|
428 |
-
if (!empty($table_name))
|
429 |
-
$this->old_data = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}qtranslate_slug");
|
430 |
-
|
431 |
-
if ( empty($table_name) || empty($this->old_data) )
|
432 |
-
$this->old_data = false;
|
433 |
-
|
434 |
-
return $this->old_data;
|
435 |
-
}
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
/**
|
440 |
-
* actions when deactivating the plugin
|
441 |
-
*
|
442 |
-
* @since 1.0
|
443 |
-
*/
|
444 |
-
private function check_old_versions() {
|
445 |
-
|
446 |
-
if ( $this->check_old_data() )
|
447 |
-
add_action('admin_notices', array(&$this, 'notice_update'));
|
448 |
-
}
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
/**
|
453 |
-
* Initialise the Class with all hooks
|
454 |
-
*
|
455 |
-
* @since 1.0
|
456 |
-
*/
|
457 |
-
function init() {
|
458 |
-
|
459 |
-
load_plugin_textdomain( 'qts', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
460 |
-
|
461 |
-
// checking plugin activate
|
462 |
-
if ( self::block_activate() ) {
|
463 |
-
if (is_admin())
|
464 |
-
add_action('admin_notices', array(&$this, 'notice_dependences'));
|
465 |
-
return;
|
466 |
-
}
|
467 |
-
|
468 |
-
// caching qts options
|
469 |
-
$this->set_options();
|
470 |
-
|
471 |
-
if ( is_admin() ) {
|
472 |
-
|
473 |
-
$this->check_old_versions();
|
474 |
-
|
475 |
-
// add filters
|
476 |
-
add_filter( 'qts_validate_post_slug', array(&$this, 'validate_post_slug'), 0, 3 );
|
477 |
-
add_filter( 'qts_validate_post_slug', array(&$this, 'unique_post_slug'), 1, 3 );
|
478 |
-
add_filter( 'qts_validate_term_slug', array(&$this, 'validate_term_slug'), 0, 3 );
|
479 |
-
add_filter( 'qts_validate_term_slug', array(&$this, 'unique_term_slug'), 1, 3 );
|
480 |
-
add_filter( 'wp_get_object_terms', array(&$this, 'get_object_terms'), 0, 4 );
|
481 |
-
add_filter( 'get_terms', array(&$this, 'get_terms'), 0, 3 );
|
482 |
-
|
483 |
-
// admin actions
|
484 |
-
add_action( 'admin_menu', array(&$this, 'add_slug_meta_box') );
|
485 |
-
add_action( 'save_post', array(&$this, 'save_postdata'), 605, 2 );
|
486 |
-
add_action( 'delete_term', array(&$this, 'delete_term'), 0, 3);
|
487 |
-
add_action( 'created_term', array(&$this, 'save_term'), 605, 3);
|
488 |
-
add_action( 'edited_term', array(&$this, 'save_term'), 605, 3 );
|
489 |
-
add_action( 'admin_head', array(&$this, 'hide_slug_box'), 900 );
|
490 |
-
|
491 |
-
add_action( 'init', array(&$this, 'taxonomies_hooks'), 805 );
|
492 |
-
|
493 |
-
add_action( 'wp_dashboard_setup', array(&$this, 'remove_dashboard_widgets') );
|
494 |
-
add_action( 'admin_head', array(&$this, 'hide_quick_edit'), 600 );
|
495 |
-
add_action( 'admin_init', array(&$this, 'fix_nav_menu') );
|
496 |
-
|
497 |
-
} else {
|
498 |
-
|
499 |
-
add_filter( 'request', array(&$this, 'filter_request') );
|
500 |
-
|
501 |
-
// adds external style file
|
502 |
-
$qts_options = $this->get_options();
|
503 |
-
if ( !isset($qts_options[QTS_PREFIX.'styles']) || $qts_options[QTS_PREFIX.'styles'] == "file" ) {
|
504 |
-
add_action( 'wp_enqueue_scripts', array( &$this, 'register_plugin_styles' ) );
|
505 |
-
} elseif ($qts_options[QTS_PREFIX.'styles'] == "inline" ) {
|
506 |
-
add_action( 'wp_print_styles', array( &$this, 'print_plugin_styles' ), 20 );
|
507 |
-
}
|
508 |
-
}
|
509 |
-
|
510 |
-
add_filter( 'query_vars', array(&$this, 'query_vars'));
|
511 |
-
add_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
|
512 |
-
|
513 |
-
// remove some Qtranslate filters
|
514 |
-
remove_filter( 'page_link', 'qtrans_convertURL' );
|
515 |
-
remove_filter( 'post_link', 'qtrans_convertURL' );
|
516 |
-
remove_filter( 'category_link', 'qtrans_convertURL' );
|
517 |
-
remove_filter( 'tag_link', 'qtrans_convertURL' );
|
518 |
-
|
519 |
-
add_filter( 'qts_permastruct' , array(&$this, 'get_extra_permastruct'), 0, 2);
|
520 |
-
add_filter( 'qts_url_args', array(&$this, 'parse_url_args'), 0, 1);
|
521 |
-
add_filter( 'home_url', array(&$this, 'home_url'), 10, 4);
|
522 |
-
add_filter( 'post_type_link', array(&$this, 'post_type_link'), 600, 4 );
|
523 |
-
add_filter( 'post_link', array(&$this, 'post_link'), 0, 3 );
|
524 |
-
add_filter( '_get_page_link', array(&$this, '_get_page_link'), 0, 2 );
|
525 |
-
add_filter( 'term_link', array(&$this, 'term_link'), 600, 3 );
|
526 |
-
|
527 |
-
add_filter( 'single_term_title', 'qtrans_useTermLib', 805 );
|
528 |
-
add_filter( 'get_blogs_of_user', array(&$this, 'blog_names'), 1 );
|
529 |
-
add_action( 'widgets_init', array(&$this, 'widget_init'), 100 );
|
530 |
-
// Add specific CSS class to body class based on current lang
|
531 |
-
add_filter('body_class', array($this, 'qts_body_class'), 600, 1 );
|
532 |
-
}
|
533 |
-
|
534 |
-
|
535 |
-
/**
|
536 |
-
* Add a class based on the current language
|
537 |
-
* @param array $classes list of classes
|
538 |
-
*/
|
539 |
-
public function qts_body_class( $classes ) {
|
540 |
-
// add 'class-name' to the $classes array
|
541 |
-
$classes[] = qtrans_getLanguage();
|
542 |
-
|
543 |
-
// return the $classes array
|
544 |
-
return $classes;
|
545 |
-
}
|
546 |
-
|
547 |
-
/**
|
548 |
-
* Adds news rules to translate the URL bases,
|
549 |
-
* this function must be called on flush_rewrite or 'flush_rewrite_rules'
|
550 |
-
*
|
551 |
-
* @param object $wp_rewrite
|
552 |
-
*
|
553 |
-
* @since 1.0
|
554 |
-
*/
|
555 |
-
public function modify_rewrite_rules() {
|
556 |
-
global $wp_rewrite;
|
557 |
-
|
558 |
-
// post types rules
|
559 |
-
$post_types = get_post_types( array('_builtin' => false ), 'objects');
|
560 |
-
foreach ( $post_types as $post_type )
|
561 |
-
$this->generate_extra_rules( $post_type->name );
|
562 |
-
|
563 |
-
// taxonomies rules
|
564 |
-
$taxonomies = $this->get_public_taxonomies();
|
565 |
-
foreach ( $taxonomies as $taxonomy )
|
566 |
-
$this->generate_extra_rules( $taxonomy->name );
|
567 |
-
}
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
/**
|
572 |
-
* Helper: news rules to translate the URL bases
|
573 |
-
*
|
574 |
-
* @param string $name name of extra permastruct
|
575 |
-
* @param string $type 'post_type' or 'taxonomy'
|
576 |
-
*
|
577 |
-
* @since 1.0
|
578 |
-
*/
|
579 |
-
private function generate_extra_rules( $name = false ) {
|
580 |
-
global $wp_rewrite, $q_config;
|
581 |
-
|
582 |
-
foreach ($q_config['enabled_languages'] as $lang):
|
583 |
-
|
584 |
-
if ( $base = $this->get_base_slug( $name, $lang) ):
|
585 |
-
|
586 |
-
$struct = $wp_rewrite->extra_permastructs[$name];
|
587 |
-
|
588 |
-
if ( is_array( $struct ) ) {
|
589 |
-
if ( count( $struct ) == 2 )
|
590 |
-
$rules = $wp_rewrite->generate_rewrite_rules( "/$base/%$name%", $struct[1] );
|
591 |
-
else
|
592 |
-
$rules = $wp_rewrite->generate_rewrite_rules( "/$base/%$name%", $struct['ep_mask'], $struct['paged'], $struct['feed'], $struct['forcomments'], $struct['walk_dirs'], $struct['endpoints'] );
|
593 |
-
} else {
|
594 |
-
$rules = $wp_rewrite->generate_rewrite_rules( "/$base/%$name%" );
|
595 |
-
}
|
596 |
-
|
597 |
-
$wp_rewrite->rules = array_merge($rules, $wp_rewrite->rules);
|
598 |
-
|
599 |
-
endif;
|
600 |
-
|
601 |
-
endforeach;
|
602 |
-
}
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
/**
|
607 |
-
* Helper that gets a base slug stored in options
|
608 |
-
*
|
609 |
-
* @param string $name of extra permastruct
|
610 |
-
* @return string base slug for 'post_type' and 'language' or false
|
611 |
-
*
|
612 |
-
* @since 1.0
|
613 |
-
*/
|
614 |
-
public function get_base_slug($name = false, $lang = false) {
|
615 |
-
|
616 |
-
if ( !$name || !$lang ) return false;
|
617 |
-
|
618 |
-
if ( taxonomy_exists($name) ) {
|
619 |
-
$type = 'taxonomy';
|
620 |
-
} else if ( post_type_exists($name) ) {
|
621 |
-
$type = 'post_type';
|
622 |
-
} else {
|
623 |
-
return false;
|
624 |
-
}
|
625 |
-
|
626 |
-
$qts_options = $this->get_options();
|
627 |
-
|
628 |
-
$option_name = QTS_PREFIX . $type . '_' . $name;
|
629 |
-
|
630 |
-
if ( !isset($qts_options[$option_name]) || empty($qts_options[$option_name]) ) return false;
|
631 |
-
|
632 |
-
$option = $qts_options[$option_name][$lang];
|
633 |
-
|
634 |
-
if (isset($option)) return $option;
|
635 |
-
|
636 |
-
return false;
|
637 |
-
}
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
/**
|
642 |
-
* Helper: returns public built-in and not built-in taxonomies
|
643 |
-
*
|
644 |
-
* @return array of public taxonomies objects
|
645 |
-
*
|
646 |
-
* @since 1.0
|
647 |
-
*/
|
648 |
-
private function get_public_taxonomies() {
|
649 |
-
|
650 |
-
$builtin = get_taxonomies( array( 'public' => true, 'show_ui' => true, '_builtin' => true ), 'object');
|
651 |
-
$taxonomies = get_taxonomies( array( 'public' => true, 'show_ui' => true, '_builtin' => false ), 'object' );
|
652 |
-
|
653 |
-
return array_merge( $builtin, $taxonomies );
|
654 |
-
}
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
/**
|
659 |
-
* parse and adds $_GET args passed to an url
|
660 |
-
*
|
661 |
-
* @param string $url parameters
|
662 |
-
* @param string $lang processed
|
663 |
-
* @return string converted url
|
664 |
-
*
|
665 |
-
* @since 1.0
|
666 |
-
*/
|
667 |
-
public function parse_url_args( $url ) {
|
668 |
-
global $q_config;
|
669 |
-
|
670 |
-
if (is_admin()) return $url;
|
671 |
-
|
672 |
-
$url = preg_replace('/&/', '&', $url);
|
673 |
-
|
674 |
-
// if no permalink structure ads ?lang=en
|
675 |
-
$base_query = parse_url($q_config['url_info']['original_url']);
|
676 |
-
$base_args = isset($base_query['query']) ? wp_parse_args($base_query['query']) : array();
|
677 |
-
|
678 |
-
if ( empty($this->permalink_structure) || $q_config['url_mode'] == 1 )
|
679 |
-
$base_args['lang'] = $this->get_lang();
|
680 |
-
|
681 |
-
// rebuild query with all args
|
682 |
-
$url = add_query_arg($base_args, $url);
|
683 |
-
|
684 |
-
$url = str_replace('/?', '?', $url); // TODO: hack: improve this code
|
685 |
-
$url = str_replace('?', '/?', $url); // TODO: hack: improve this code
|
686 |
-
|
687 |
-
return $url;
|
688 |
-
}
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
/**
|
693 |
-
* Fix get_page_by_path when querying vars
|
694 |
-
*
|
695 |
-
* @param $query_vars objec query vars founded
|
696 |
-
* @return object $query_vars processed
|
697 |
-
*
|
698 |
-
* @since 1.0
|
699 |
-
*/
|
700 |
-
public function query_vars( $query_vars ) {
|
701 |
-
global $wp, $wp_rewrite;
|
702 |
-
|
703 |
-
$wp->query_vars = array();
|
704 |
-
$post_type_query_vars = array();
|
705 |
-
|
706 |
-
// Fetch the rewrite rules.
|
707 |
-
$rewrite = $wp_rewrite->wp_rewrite_rules();
|
708 |
-
|
709 |
-
if ( ! empty($rewrite) ) {
|
710 |
-
// If we match a rewrite rule, this will be cleared.
|
711 |
-
$error = '404';
|
712 |
-
$wp->did_permalink = true;
|
713 |
-
|
714 |
-
if ( isset($_SERVER['PATH_INFO']) )
|
715 |
-
$pathinfo = $_SERVER['PATH_INFO'];
|
716 |
-
else
|
717 |
-
$pathinfo = '';
|
718 |
-
$pathinfo_array = explode('?', $pathinfo);
|
719 |
-
$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
|
720 |
-
$req_uri = $_SERVER['REQUEST_URI'];
|
721 |
-
$req_uri_array = explode('?', $req_uri);
|
722 |
-
$req_uri = $req_uri_array[0];
|
723 |
-
$self = $_SERVER['PHP_SELF'];
|
724 |
-
$home_path = parse_url(home_url());
|
725 |
-
|
726 |
-
if ( isset($home_path['path']) )
|
727 |
-
$home_path = $home_path['path'];
|
728 |
-
else
|
729 |
-
$home_path = '';
|
730 |
-
$home_path = trim($home_path, '/');
|
731 |
-
|
732 |
-
// Trim path info from the end and the leading home path from the
|
733 |
-
// front. For path info requests, this leaves us with the requesting
|
734 |
-
// filename, if any. For 404 requests, this leaves us with the
|
735 |
-
// requested permalink.
|
736 |
-
$req_uri = str_replace($pathinfo, '', $req_uri);
|
737 |
-
$req_uri = trim($req_uri, '/');
|
738 |
-
$req_uri = preg_replace("|^$home_path|", '', $req_uri);
|
739 |
-
$req_uri = trim($req_uri, '/');
|
740 |
-
if ($GLOBALS['q_config']['url_mode'] == QT_URL_PATH)
|
741 |
-
$req_uri = preg_replace("/^{$GLOBALS['q_config']['language']}(\/|$)/", '', $req_uri);
|
742 |
-
$pathinfo = trim($pathinfo, '/');
|
743 |
-
$pathinfo = preg_replace("|^$home_path|", '', $pathinfo);
|
744 |
-
$pathinfo = trim($pathinfo, '/');
|
745 |
-
$self = trim($self, '/');
|
746 |
-
$self = preg_replace("|^$home_path|", '', $self);
|
747 |
-
$self = trim($self, '/');
|
748 |
-
|
749 |
-
// The requested permalink is in $pathinfo for path info requests and
|
750 |
-
// $req_uri for other requests.
|
751 |
-
if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
|
752 |
-
$request = $pathinfo;
|
753 |
-
} else {
|
754 |
-
// If the request uri is the index, blank it out so that
|
755 |
-
// we don't try to match it against a rule.
|
756 |
-
if ( $req_uri == $wp_rewrite->index )
|
757 |
-
$req_uri = '';
|
758 |
-
$request = $req_uri;
|
759 |
-
}
|
760 |
-
|
761 |
-
$wp->request = $request;
|
762 |
-
|
763 |
-
// Look for matches.
|
764 |
-
$request_match = $request;
|
765 |
-
if ( empty( $request_match ) ) {
|
766 |
-
// An empty request could only match against ^$ regex
|
767 |
-
if ( isset( $rewrite['$'] ) ) {
|
768 |
-
$wp->matched_rule = '$';
|
769 |
-
$query = $rewrite['$'];
|
770 |
-
$matches = array('');
|
771 |
-
}
|
772 |
-
} else if ( $req_uri != 'wp-app.php' ) {
|
773 |
-
foreach ( (array) $rewrite as $match => $query ) {
|
774 |
-
// If the requesting file is the anchor of the match, prepend it to the path info.
|
775 |
-
if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request )
|
776 |
-
$request_match = $req_uri . '/' . $request;
|
777 |
-
|
778 |
-
if ( preg_match("#^$match#", $request_match, $matches) ||
|
779 |
-
preg_match("#^$match#", urldecode($request_match), $matches) ) {
|
780 |
-
|
781 |
-
if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
|
782 |
-
// this is a verbose page match, lets check to be sure about it
|
783 |
-
if ( ! $page_foundid = $this->get_page_by_path( $matches[ $varmatch[1] ] ) ) {
|
784 |
-
continue;
|
785 |
-
} else {
|
786 |
-
wp_cache_set('qts_page_request', $page_foundid); // caching query :)
|
787 |
-
}
|
788 |
-
}
|
789 |
-
|
790 |
-
// Got a match.
|
791 |
-
$wp->matched_rule = $match;
|
792 |
-
break;
|
793 |
-
}
|
794 |
-
}
|
795 |
-
}
|
796 |
-
|
797 |
-
if ( isset( $wp->matched_rule ) ) {
|
798 |
-
// Trim the query of everything up to the '?'.
|
799 |
-
$query = preg_replace("!^.+\?!", '', $query);
|
800 |
-
|
801 |
-
// Substitute the substring matches into the query.
|
802 |
-
$query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
|
803 |
-
|
804 |
-
$wp->matched_query = $query;
|
805 |
-
|
806 |
-
// Parse the query.
|
807 |
-
parse_str($query, $perma_query_vars);
|
808 |
-
|
809 |
-
// If we're processing a 404 request, clear the error var
|
810 |
-
// since we found something.
|
811 |
-
unset( $_GET['error'] );
|
812 |
-
unset( $error );
|
813 |
-
}
|
814 |
-
|
815 |
-
// If req_uri is empty or if it is a request for ourself, unset error.
|
816 |
-
if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
|
817 |
-
unset( $_GET['error'] );
|
818 |
-
unset( $error );
|
819 |
-
|
820 |
-
if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )
|
821 |
-
unset( $perma_query_vars );
|
822 |
-
|
823 |
-
$wp->did_permalink = false;
|
824 |
-
}
|
825 |
-
}
|
826 |
-
|
827 |
-
return count(array_diff($query_vars, $wp->public_query_vars)) > 0 ? $query_vars : $wp->public_query_vars;
|
828 |
-
}
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
/**
|
833 |
-
* Function called when query parameters are processed by Wordpress.
|
834 |
-
*
|
835 |
-
* @param $query query parameters
|
836 |
-
* @return array() $query processed
|
837 |
-
*
|
838 |
-
* @since 1.0
|
839 |
-
*/
|
840 |
-
function filter_request( $query ) {
|
841 |
-
global $q_config, $wp_query, $wp;
|
842 |
-
|
843 |
-
if (isset($wp->matched_query))
|
844 |
-
$query = wp_parse_args($wp->matched_query);
|
845 |
-
|
846 |
-
foreach (get_post_types() as $post_type)
|
847 |
-
if ( array_key_exists($post_type, $query) && !in_array($post_type, array('post', 'page')) ) $query['post_type'] = $post_type;
|
848 |
-
|
849 |
-
$page_foundit = false;
|
850 |
-
|
851 |
-
// -> page
|
852 |
-
if ( isset($query['pagename']) || isset($query['page_id']) ):
|
853 |
-
|
854 |
-
$page = wp_cache_get('qts_page_request');
|
855 |
-
if (!$page)
|
856 |
-
$page = isset($query['page_id']) ? get_post($query['page_id']) : $this->get_page_by_path($query['pagename']);
|
857 |
-
|
858 |
-
if (!$page) return $query;
|
859 |
-
$id = $page->ID;
|
860 |
-
$cache_array = array($page);
|
861 |
-
update_post_caches($cache_array, 'page'); // caching query :)
|
862 |
-
wp_cache_delete('qts_page_request');
|
863 |
-
$query['pagename'] = get_page_uri($page);
|
864 |
-
$function = 'get_page_link';
|
865 |
-
|
866 |
-
// -> custom post type
|
867 |
-
elseif ( isset($query['post_type']) ):
|
868 |
-
|
869 |
-
$page_slug = ( isset($query['name']) && !empty($query['name']) ) ? $query['name'] : $query[$query['post_type']];
|
870 |
-
$page = $this->get_page_by_path($page_slug, OBJECT, $query['post_type']);
|
871 |
-
if (!$page) return $query;
|
872 |
-
$id = $page->ID;
|
873 |
-
$cache_array = array($page);
|
874 |
-
update_post_caches($cache_array, $query['post_type']); // caching query :)
|
875 |
-
$query['name'] = $query[$query['post_type']] = get_page_uri($page);
|
876 |
-
$function = 'get_post_permalink';
|
877 |
-
|
878 |
-
// -> post
|
879 |
-
elseif ( isset($query['name']) || isset($query['p']) ):
|
880 |
-
|
881 |
-
$post = isset($query['p']) ? get_post($query['p']) : $this->get_page_by_path($query['name'], OBJECT, 'post');
|
882 |
-
if (!$post) return $query;
|
883 |
-
$query['name'] = $post->post_name;
|
884 |
-
$id = $post->ID;
|
885 |
-
$cache_array = array($post);
|
886 |
-
update_post_caches($cache_array);
|
887 |
-
$function = 'get_permalink';
|
888 |
-
|
889 |
-
// -> category
|
890 |
-
elseif ( ( isset($query['category_name']) || isset($query['cat'])) ):
|
891 |
-
if ( isset($query['category_name']) )
|
892 |
-
$term_slug = $this->get_last_slash( $query['category_name'] );
|
893 |
-
$term = isset($query['cat']) ? get_term($query['cat'], 'category') : $this->get_term_by('slug', $term_slug, 'category');
|
894 |
-
if (!$term) return $query;
|
895 |
-
$cache_array = array($term);
|
896 |
-
update_term_cache($cache_array, 'category'); // caching query :)
|
897 |
-
$id = $term->term_id;
|
898 |
-
$query['category_name'] = $term->slug; // uri
|
899 |
-
$function = 'get_category_link';
|
900 |
-
|
901 |
-
// -> tag
|
902 |
-
elseif ( isset($query['tag']) ):
|
903 |
-
|
904 |
-
$term = $this->get_term_by('slug', $query['tag'], 'post_tag');
|
905 |
-
if (!$term) return $query;
|
906 |
-
$cache_array = array($term);
|
907 |
-
update_term_cache($cache_array, 'post_tag'); // caching query :)
|
908 |
-
$id = $term->term_id;
|
909 |
-
$query['tag'] = $term->slug;
|
910 |
-
$function = 'get_tag_link';
|
911 |
-
|
912 |
-
endif;
|
913 |
-
|
914 |
-
// -> taxonomy
|
915 |
-
$taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
|
916 |
-
foreach ($taxonomies as $term_name):
|
917 |
-
if ( isset($query[$term_name]) ) {
|
918 |
-
|
919 |
-
$term_slug = $this->get_last_slash( $query[$term_name] );
|
920 |
-
$term = $this->get_term_by('slug', $term_slug, $term_name);
|
921 |
-
if (!$term) return $query;
|
922 |
-
$cache_array = array($term);
|
923 |
-
update_term_cache($cache_array, $term_name); // caching query :)
|
924 |
-
$id = $term;
|
925 |
-
$query[$term_name] = $term->slug;
|
926 |
-
$function = 'get_term_link';
|
927 |
-
|
928 |
-
}
|
929 |
-
endforeach;
|
930 |
-
|
931 |
-
// -> home url
|
932 |
-
if ( empty($query) ):
|
933 |
-
|
934 |
-
$function = 'home_url';
|
935 |
-
$id = '';
|
936 |
-
|
937 |
-
endif;
|
938 |
-
|
939 |
-
// -> search
|
940 |
-
if(isset($query['s'])):
|
941 |
-
|
942 |
-
$id=$query['s'];
|
943 |
-
$function="get_search_link";
|
944 |
-
|
945 |
-
endif;
|
946 |
-
|
947 |
-
if ( isset($function) ):
|
948 |
-
|
949 |
-
// parse all languages links
|
950 |
-
foreach( $q_config['enabled_languages'] as $lang ) {
|
951 |
-
|
952 |
-
$this->lang = $lang;
|
953 |
-
$this->current_url[$lang] = apply_filters('qts_url_args', call_user_func($function, $id));
|
954 |
-
|
955 |
-
}
|
956 |
-
$this->lang = false;
|
957 |
-
|
958 |
-
endif;
|
959 |
-
|
960 |
-
return $query;
|
961 |
-
}
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
/**
|
966 |
-
* Parse a hierarquical name and extract the last one
|
967 |
-
*
|
968 |
-
* @param string $lang Page path
|
969 |
-
* @return string
|
970 |
-
*
|
971 |
-
* @since 1.0
|
972 |
-
*/
|
973 |
-
public function get_current_url( $lang = false ) {
|
974 |
-
global $q_config;
|
975 |
-
|
976 |
-
if (!$lang) $lang = $this->get_lang();
|
977 |
-
|
978 |
-
if (isset($this->current_url[$lang]) && !empty($this->current_url[$lang]))
|
979 |
-
return $this->current_url[$lang];
|
980 |
-
|
981 |
-
return '';
|
982 |
-
}
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
/**
|
987 |
-
* Parse a hierarquical name and extract the last one
|
988 |
-
*
|
989 |
-
* @param string $slug Page path
|
990 |
-
* @return string
|
991 |
-
*
|
992 |
-
* @since 1.0
|
993 |
-
*/
|
994 |
-
private function get_last_slash($slug) {
|
995 |
-
|
996 |
-
$slug = rawurlencode( urldecode( $slug ) );
|
997 |
-
$slug = str_replace('%2F', '/', $slug);
|
998 |
-
$slug = str_replace('%20', ' ', $slug);
|
999 |
-
|
1000 |
-
return array_pop( explode('/', $slug) );
|
1001 |
-
}
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
/**
|
1006 |
-
* Retrieves a page id given its path.
|
1007 |
-
*
|
1008 |
-
* @param string $page_path Page path
|
1009 |
-
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
|
1010 |
-
* @param string $post_type Optional. Post type. Default page.
|
1011 |
-
* @return mixed Null when complete.
|
1012 |
-
*
|
1013 |
-
* @since 1.0
|
1014 |
-
*/
|
1015 |
-
private function get_page_id_by_path($page_path, $output = OBJECT, $post_type = 'page') {
|
1016 |
-
global $wpdb;
|
1017 |
-
|
1018 |
-
$page_path = rawurlencode(urldecode($page_path));
|
1019 |
-
$page_path = str_replace('%2F', '/', $page_path);
|
1020 |
-
$page_path = str_replace('%20', ' ', $page_path);
|
1021 |
-
$parts = explode( '/', trim( $page_path, '/' ) );
|
1022 |
-
$parts = array_map( 'esc_sql', $parts );
|
1023 |
-
$parts = array_map( 'sanitize_title_for_query', $parts );
|
1024 |
-
$in_string = "'". implode( "','", $parts ) . "'";
|
1025 |
-
$meta_key = $this->get_meta_key();
|
1026 |
-
$post_type_sql = $post_type;
|
1027 |
-
$wpdb->escape_by_ref( $post_type_sql );
|
1028 |
-
|
1029 |
-
$pages = $wpdb->get_results( "SELECT $wpdb->posts.ID, $wpdb->posts.post_parent, $wpdb->postmeta.meta_value FROM $wpdb->posts,$wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value IN ($in_string) AND ($wpdb->posts.post_type = '$post_type_sql' OR $wpdb->posts.post_type = 'attachment')", OBJECT_K );
|
1030 |
-
|
1031 |
-
$revparts = array_reverse( $parts );
|
1032 |
-
|
1033 |
-
$foundid = 0;
|
1034 |
-
foreach ( (array) $pages as $page ) {
|
1035 |
-
if ( $page->meta_value == $revparts[0] ) {
|
1036 |
-
$count = 0;
|
1037 |
-
$p = $page;
|
1038 |
-
while ( $p->post_parent != 0 && isset( $pages[ $p->post_parent ] ) ) {
|
1039 |
-
$count++;
|
1040 |
-
$parent = $pages[ $p->post_parent ];
|
1041 |
-
if ( ! isset( $revparts[ $count ] ) || $parent->meta_value != $revparts[ $count ] )
|
1042 |
-
break;
|
1043 |
-
$p = $parent;
|
1044 |
-
}
|
1045 |
-
|
1046 |
-
if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->meta_value == $revparts[ $count ] ) {
|
1047 |
-
$foundid = $page->ID;
|
1048 |
-
break;
|
1049 |
-
}
|
1050 |
-
}
|
1051 |
-
}
|
1052 |
-
|
1053 |
-
if ( $foundid ) {
|
1054 |
-
return $foundid;
|
1055 |
-
|
1056 |
-
} else {
|
1057 |
-
|
1058 |
-
$last_part = array_pop($parts);
|
1059 |
-
$page_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_name = '$last_part' AND (post_type = '$post_type_sql' OR post_type = 'attachment')" );
|
1060 |
-
|
1061 |
-
if ( $page_id )
|
1062 |
-
return $page_id;
|
1063 |
-
}
|
1064 |
-
|
1065 |
-
return null;
|
1066 |
-
}
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
/**
|
1072 |
-
* Retrieves a page given its path.
|
1073 |
-
*
|
1074 |
-
* @param string $page_path Page path
|
1075 |
-
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
|
1076 |
-
* @param string $post_type Optional. Post type. Default page.
|
1077 |
-
* @return mixed Null when complete.
|
1078 |
-
*
|
1079 |
-
* @since 1.0
|
1080 |
-
*/
|
1081 |
-
private function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') {
|
1082 |
-
|
1083 |
-
$foundid = $this->get_page_id_by_path($page_path, $output, $post_type);
|
1084 |
-
if ( $foundid )
|
1085 |
-
return get_post( $foundid, $output );
|
1086 |
-
|
1087 |
-
return null;
|
1088 |
-
}
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
/**
|
1093 |
-
* Ignores if the mod_rewrite func is the caller
|
1094 |
-
*
|
1095 |
-
* @return boolean
|
1096 |
-
*
|
1097 |
-
* @since 1.0
|
1098 |
-
*/
|
1099 |
-
private function ignore_rewrite_caller() {
|
1100 |
-
|
1101 |
-
$backtrace = debug_backtrace();
|
1102 |
-
|
1103 |
-
$ignore_functions = array('mod_rewrite_rules', 'save_mod_rewrite_rules', 'flush_rules', 'rewrite_rules', 'wp_rewrite_rules', 'query_vars');
|
1104 |
-
|
1105 |
-
if ( isset($backtrace['function']) ) {
|
1106 |
-
if (in_array($backtrace['function'], $ignore_functions)) return true;
|
1107 |
-
} else {
|
1108 |
-
foreach ($backtrace as $trace) if ( isset($trace['function']) && in_array($trace['function'], $ignore_functions) ) return true;
|
1109 |
-
}
|
1110 |
-
|
1111 |
-
return false;
|
1112 |
-
}
|
1113 |
-
|
1114 |
-
|
1115 |
-
/**
|
1116 |
-
* Retrieve the home url for a given site.
|
1117 |
-
*
|
1118 |
-
* @param int $blog_id (optional) Blog ID. Defaults to current blog.
|
1119 |
-
* @param string $path (optional) Path relative to the home url.
|
1120 |
-
* @param string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https'.
|
1121 |
-
* @return string Home url link with optional path appended.
|
1122 |
-
*
|
1123 |
-
* @since 1.0
|
1124 |
-
*/
|
1125 |
-
public function home_url($url, $path, $scheme, $blog_id) {
|
1126 |
-
|
1127 |
-
if ( !in_array( $scheme, array( 'http', 'https' ) ) )
|
1128 |
-
$scheme = is_ssl() && !is_admin() ? 'https' : 'http';
|
1129 |
-
|
1130 |
-
if ( empty( $blog_id ) || !is_multisite() )
|
1131 |
-
$url = get_option( 'home' );
|
1132 |
-
else
|
1133 |
-
$url = get_blog_option( $blog_id, 'home' );
|
1134 |
-
|
1135 |
-
if ( 'http' != $scheme )
|
1136 |
-
$url = str_replace( 'http://', "$scheme://", $url );
|
1137 |
-
|
1138 |
-
$ignore_caller = $this->ignore_rewrite_caller();
|
1139 |
-
|
1140 |
-
if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
|
1141 |
-
$url .= '/' . ltrim( $path, '/' );
|
1142 |
-
|
1143 |
-
if ( !$ignore_caller )
|
1144 |
-
$url = qtrans_convertURL($url, $this->get_lang(), true);
|
1145 |
-
|
1146 |
-
return $url;
|
1147 |
-
}
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
/**
|
1152 |
-
* Filter that changes the permastruct depending
|
1153 |
-
*
|
1154 |
-
* @param string $permastruct default permastruct given b wp_rewrite
|
1155 |
-
* @param string $name the name of the extra permastruct
|
1156 |
-
* @return string processed permastruct
|
1157 |
-
*
|
1158 |
-
* @since 1.0
|
1159 |
-
*/
|
1160 |
-
public function get_extra_permastruct( $permastruct = false, $name = false ) {
|
1161 |
-
|
1162 |
-
if ( !$name || !$permastruct ) return '';
|
1163 |
-
|
1164 |
-
if ( $base = $this->get_base_slug($name, $this->get_lang()) )
|
1165 |
-
return "/$base/%$name%";
|
1166 |
-
|
1167 |
-
return $permastruct;
|
1168 |
-
}
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
/**
|
1173 |
-
* Filter that translates the slug parts in a page link
|
1174 |
-
*
|
1175 |
-
* @param $link the link for the page generated by Wordpress
|
1176 |
-
* @param $id the id of the page
|
1177 |
-
* @return the link translated
|
1178 |
-
*
|
1179 |
-
* @since 1.0
|
1180 |
-
*/
|
1181 |
-
public function post_type_link( $link, $post, $leavename, $sample ) {
|
1182 |
-
global $wp_rewrite;
|
1183 |
-
|
1184 |
-
if ( is_wp_error( $post ) )
|
1185 |
-
return $post;
|
1186 |
-
|
1187 |
-
$post_link = apply_filters( 'qts_permastruct', $wp_rewrite->get_extra_permastruct($post->post_type), $post->post_type);
|
1188 |
-
|
1189 |
-
$slug = get_post_meta( $post->ID, $this->get_meta_key(), true );
|
1190 |
-
if (!$slug) $slug = $post->post_name;
|
1191 |
-
|
1192 |
-
$draft_or_pending = isset($post->post_status) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
|
1193 |
-
|
1194 |
-
$post_type = get_post_type_object($post->post_type);
|
1195 |
-
|
1196 |
-
if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) {
|
1197 |
-
if ( ! $leavename ) {
|
1198 |
-
if ( $post_type->hierarchical )
|
1199 |
-
$slug = $this->get_page_uri($post->ID);
|
1200 |
-
$post_link = str_replace("%$post->post_type%", $slug, $post_link);
|
1201 |
-
}
|
1202 |
-
|
1203 |
-
$post_link = home_url( user_trailingslashit($post_link) );
|
1204 |
-
|
1205 |
-
} else {
|
1206 |
-
|
1207 |
-
if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) )
|
1208 |
-
$post_link = add_query_arg($post_type->query_var, $slug, '');
|
1209 |
-
else
|
1210 |
-
$post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), '');
|
1211 |
-
|
1212 |
-
$post_link = home_url($post_link);
|
1213 |
-
}
|
1214 |
-
|
1215 |
-
return $post_link;
|
1216 |
-
}
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
1220 |
-
/**
|
1221 |
-
* Filter that translates the slug in a post link
|
1222 |
-
*
|
1223 |
-
* @param $link the link generated by wordpress
|
1224 |
-
* @param $post the post data
|
1225 |
-
* @param $leavename parameter used by get_permalink. Whether to keep post name or page name.
|
1226 |
-
* @return the link translated
|
1227 |
-
*
|
1228 |
-
* @since 1.0
|
1229 |
-
*/
|
1230 |
-
public function post_link( $link, $post, $leavename ) {
|
1231 |
-
global $q_config;
|
1232 |
-
|
1233 |
-
$rewritecode = array(
|
1234 |
-
'%year%',
|
1235 |
-
'%monthnum%',
|
1236 |
-
'%day%',
|
1237 |
-
'%hour%',
|
1238 |
-
'%minute%',
|
1239 |
-
'%second%',
|
1240 |
-
$leavename? '' : '%postname%',
|
1241 |
-
'%post_id%',
|
1242 |
-
'%category%',
|
1243 |
-
'%author%',
|
1244 |
-
$leavename? '' : '%pagename%',
|
1245 |
-
);
|
1246 |
-
|
1247 |
-
if ( empty($post->ID) )
|
1248 |
-
return false;
|
1249 |
-
|
1250 |
-
$permalink = $this->permalink_structure;
|
1251 |
-
|
1252 |
-
if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {
|
1253 |
-
$unixtime = strtotime($post->post_date);
|
1254 |
-
|
1255 |
-
$category = '';
|
1256 |
-
if ( strpos($permalink, '%category%') !== false ) {
|
1257 |
-
$cats = get_the_category($post->ID);
|
1258 |
-
if ( $cats ) {
|
1259 |
-
usort($cats, '_usort_terms_by_ID'); // order by ID
|
1260 |
-
|
1261 |
-
$category = get_term_meta($cats[0]->term_id, $this->get_meta_key(), true );
|
1262 |
-
if (!$category) $category = $cats[0]->slug;
|
1263 |
-
|
1264 |
-
if ( $parent = $cats[0]->parent )
|
1265 |
-
$category = $this->get_category_parents($parent, false, '/', true) . $category;
|
1266 |
-
}
|
1267 |
-
// show default category in permalinks, without
|
1268 |
-
// having to assign it explicitly
|
1269 |
-
if ( empty($category) ) {
|
1270 |
-
$default_category = get_category( get_option( 'default_category' ) );
|
1271 |
-
|
1272 |
-
$default_category_slug = get_term_meta($default_category->term_id, $this->get_meta_key(), true );
|
1273 |
-
if (!$default_category_slug) $default_category_slug = $default_category->slug;
|
1274 |
-
|
1275 |
-
$category = is_wp_error( $default_category ) ? '' : $default_category_slug;
|
1276 |
-
}
|
1277 |
-
}
|
1278 |
-
|
1279 |
-
$author = '';
|
1280 |
-
if ( strpos($permalink, '%author%') !== false ) {
|
1281 |
-
$authordata = get_userdata($post->post_author);
|
1282 |
-
$author = $authordata->user_nicename;
|
1283 |
-
}
|
1284 |
-
|
1285 |
-
$date = explode(" ",date('Y m d H i s', $unixtime));
|
1286 |
-
|
1287 |
-
$post_slug = get_post_meta($post->ID, $this->get_meta_key(), true );
|
1288 |
-
if(!$post_slug) $post_slug = $post->post_name;
|
1289 |
-
|
1290 |
-
$rewritereplace =
|
1291 |
-
array(
|
1292 |
-
$date[0],
|
1293 |
-
$date[1],
|
1294 |
-
$date[2],
|
1295 |
-
$date[3],
|
1296 |
-
$date[4],
|
1297 |
-
$date[5],
|
1298 |
-
$post_slug,
|
1299 |
-
$post->ID,
|
1300 |
-
$category,
|
1301 |
-
$author,
|
1302 |
-
$post_slug,
|
1303 |
-
);
|
1304 |
-
$permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink));
|
1305 |
-
if ($q_config['url_mode'] != 1)
|
1306 |
-
$permalink = user_trailingslashit($permalink, 'single');
|
1307 |
-
} else { // if they're not using the fancy permalink option
|
1308 |
-
$permalink = home_url('?p=' . $post->ID);
|
1309 |
-
}
|
1310 |
-
|
1311 |
-
return $permalink;
|
1312 |
-
}
|
1313 |
-
|
1314 |
-
|
1315 |
-
|
1316 |
-
/**
|
1317 |
-
* Retrieve category parents with separator.
|
1318 |
-
*
|
1319 |
-
* @param int $id Category ID.
|
1320 |
-
* @param bool $link Optional, default is false. Whether to format with link.
|
1321 |
-
* @param string $separator Optional, default is '/'. How to separate categories.
|
1322 |
-
* @param bool $nicename Optional, default is false. Whether to use nice name for display.
|
1323 |
-
* @param array $visited Optional. Already linked to categories to prevent duplicates.
|
1324 |
-
* @return string
|
1325 |
-
*
|
1326 |
-
* @since 1.0
|
1327 |
-
*/
|
1328 |
-
private function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) {
|
1329 |
-
|
1330 |
-
$chain = '';
|
1331 |
-
$parent = &get_category( $id );
|
1332 |
-
if ( is_wp_error( $parent ) )
|
1333 |
-
return $parent;
|
1334 |
-
|
1335 |
-
if ( $nicename ) {
|
1336 |
-
|
1337 |
-
$name = get_term_meta($parent->term_id, $this->get_meta_key(), true );
|
1338 |
-
if (!$name) $name = $parent->slug;
|
1339 |
-
} else {
|
1340 |
-
$name = $parent->name;
|
1341 |
-
}
|
1342 |
-
|
1343 |
-
if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
|
1344 |
-
$visited[] = $parent->parent;
|
1345 |
-
$chain .= $this->get_category_parents( $parent->parent, $link, $separator, $nicename, $visited );
|
1346 |
-
}
|
1347 |
-
|
1348 |
-
if ( $link )
|
1349 |
-
$chain .= '<a href="' . get_category_link( $parent->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
|
1350 |
-
else
|
1351 |
-
$chain .= $name.$separator;
|
1352 |
-
|
1353 |
-
return $chain;
|
1354 |
-
}
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
/**
|
1361 |
-
* Filter that translates the slug parts in a page link
|
1362 |
-
*
|
1363 |
-
* @param $link the link for the page generated by Wordpress
|
1364 |
-
* @param $id the id of the page
|
1365 |
-
* @return the link translated
|
1366 |
-
*
|
1367 |
-
* @since 1.0
|
1368 |
-
*/
|
1369 |
-
public function _get_page_link( $link, $id ) {
|
1370 |
-
global $post, $wp_rewrite, $q_config;
|
1371 |
-
|
1372 |
-
$current_post = $post;
|
1373 |
-
|
1374 |
-
if ( !$id )
|
1375 |
-
$id = (int) $post->ID;
|
1376 |
-
else
|
1377 |
-
if(phpversion() >= 5.4) {
|
1378 |
-
$current_post = get_post($id);
|
1379 |
-
} else {
|
1380 |
-
$current_post = &get_post($id);
|
1381 |
-
}
|
1382 |
-
|
1383 |
-
$draft_or_pending = in_array( $current_post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
|
1384 |
-
|
1385 |
-
$link = $wp_rewrite->get_page_permastruct();
|
1386 |
-
|
1387 |
-
if ( !empty($link) && ( isset($current_post->post_status) && !$draft_or_pending ) ) {
|
1388 |
-
|
1389 |
-
$link = str_replace('%pagename%', $this->get_page_uri($id), $link);
|
1390 |
-
|
1391 |
-
$link = trim($link, '/'); // hack
|
1392 |
-
$link = home_url("/$link/"); // hack
|
1393 |
-
|
1394 |
-
if ($q_config['url_mode'] != 1)
|
1395 |
-
$link = user_trailingslashit($link, 'page');
|
1396 |
-
|
1397 |
-
} else {
|
1398 |
-
|
1399 |
-
$link = home_url("?page_id=$id");
|
1400 |
-
}
|
1401 |
-
|
1402 |
-
return $link;
|
1403 |
-
}
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
/**
|
1408 |
-
* Builds URI for a page.
|
1409 |
-
*
|
1410 |
-
* Sub pages will be in the "directory" under the parent page post name.
|
1411 |
-
*
|
1412 |
-
* @param mixed $page Page object or page ID.
|
1413 |
-
* @return string Page URI.
|
1414 |
-
*
|
1415 |
-
* @since 1.0
|
1416 |
-
*/
|
1417 |
-
private function get_page_uri($page) {
|
1418 |
-
|
1419 |
-
if ( ! is_object($page) )
|
1420 |
-
$page = get_post($page);
|
1421 |
-
|
1422 |
-
$uri = get_post_meta( $page->ID, $this->get_meta_key(), true );
|
1423 |
-
if (!$uri) $uri = $page->post_name;
|
1424 |
-
|
1425 |
-
// A page cannot be it's own parent.
|
1426 |
-
if ( $page->post_parent == $page->ID )
|
1427 |
-
return $uri;
|
1428 |
-
|
1429 |
-
while ($page->post_parent != 0) {
|
1430 |
-
$page = get_post($page->post_parent);
|
1431 |
-
|
1432 |
-
$page_name = get_post_meta( $page->ID, $this->get_meta_key(), true );
|
1433 |
-
if (!$page_name) $page_name = $page->post_name;
|
1434 |
-
|
1435 |
-
$uri = $page_name . "/" . $uri;
|
1436 |
-
}
|
1437 |
-
|
1438 |
-
return $uri;
|
1439 |
-
}
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
/**
|
1444 |
-
* Filter that translates the slug parts in a term link
|
1445 |
-
*
|
1446 |
-
* @param $link the link for the page generated by Wordpress
|
1447 |
-
* @param $term object
|
1448 |
-
* @param $taxonomy object
|
1449 |
-
* @return the link translated
|
1450 |
-
*
|
1451 |
-
* @since 1.0
|
1452 |
-
*/
|
1453 |
-
public function term_link( $link, $term, $taxonomy ) {
|
1454 |
-
global $wp_rewrite;
|
1455 |
-
|
1456 |
-
// parse normal term names for ?tag=tagname
|
1457 |
-
if (empty($this->permalink_structure)) return $link;
|
1458 |
-
|
1459 |
-
if ( !is_object($term) ) {
|
1460 |
-
if ( is_int($term) ) {
|
1461 |
-
$term = &get_term($term, $taxonomy);
|
1462 |
-
} else {
|
1463 |
-
$term = $this->get_term_by('slug', $term, $taxonomy);
|
1464 |
-
}
|
1465 |
-
}
|
1466 |
-
|
1467 |
-
if ( !is_object($term) )
|
1468 |
-
$term = new WP_Error('invalid_term', __('Empty Term'));
|
1469 |
-
|
1470 |
-
if ( is_wp_error( $term ) )
|
1471 |
-
return $term;
|
1472 |
-
|
1473 |
-
$taxonomy = $term->taxonomy;
|
1474 |
-
|
1475 |
-
$termlink = apply_filters( 'qts_permastruct', $wp_rewrite->get_extra_permastruct($taxonomy), $taxonomy);
|
1476 |
-
|
1477 |
-
$slug = get_term_meta( $term->term_id, $this->get_meta_key(), true );
|
1478 |
-
if (!$slug) $slug = $term->slug;
|
1479 |
-
|
1480 |
-
$t = get_taxonomy($taxonomy);
|
1481 |
-
|
1482 |
-
if ( empty($termlink) ) {
|
1483 |
-
if ( 'category' == $taxonomy )
|
1484 |
-
$termlink = '?cat=' . $term->term_id;
|
1485 |
-
elseif ( $t->query_var )
|
1486 |
-
$termlink = "?$t->query_var=$slug";
|
1487 |
-
else
|
1488 |
-
$termlink = "?taxonomy=$taxonomy&term=$slug";
|
1489 |
-
$termlink = home_url($termlink);
|
1490 |
-
} else {
|
1491 |
-
if ( $t->rewrite['hierarchical'] ) {
|
1492 |
-
$hierarchical_slugs = array();
|
1493 |
-
$ancestors = get_ancestors($term->term_id, $taxonomy);
|
1494 |
-
foreach ( (array)$ancestors as $ancestor ) {
|
1495 |
-
$ancestor_term = get_term($ancestor, $taxonomy);
|
1496 |
-
|
1497 |
-
$ancestor_slug = get_term_meta( $ancestor_term->term_id, $this->get_meta_key(), true );
|
1498 |
-
if (!$ancestor_slug) $ancestor_slug = $ancestor_term->slug;
|
1499 |
-
|
1500 |
-
$hierarchical_slugs[] = $ancestor_slug;
|
1501 |
-
}
|
1502 |
-
$hierarchical_slugs = array_reverse($hierarchical_slugs);
|
1503 |
-
$hierarchical_slugs[] = $slug;
|
1504 |
-
$termlink = str_replace("%$taxonomy%", implode('/', $hierarchical_slugs), $termlink);
|
1505 |
-
} else {
|
1506 |
-
$termlink = str_replace("%$taxonomy%", $slug, $termlink);
|
1507 |
-
}
|
1508 |
-
$termlink = home_url( user_trailingslashit($termlink, 'category') );
|
1509 |
-
}
|
1510 |
-
return $termlink;
|
1511 |
-
}
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
/**
|
1516 |
-
* Get all Term data from database by Term field and data.
|
1517 |
-
*
|
1518 |
-
* @param (string) $field Either 'slug', 'name', or 'id'
|
1519 |
-
* @param (string|int) $value Search for this term value
|
1520 |
-
* @param (string) $taxonomy Taxonomy Name
|
1521 |
-
* @param (string) $output Constant OBJECT, ARRAY_A, or ARRAY_N
|
1522 |
-
* @param (string) $filter Optional, default is raw or no WordPress defined filter will applied.
|
1523 |
-
* @return (mixed) Term Row from database. Will return false if $taxonomy does not exist or $term was not found.
|
1524 |
-
*
|
1525 |
-
* @since 1.0
|
1526 |
-
*/
|
1527 |
-
private function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') {
|
1528 |
-
global $wpdb;
|
1529 |
-
|
1530 |
-
$original_field = $field;
|
1531 |
-
|
1532 |
-
if ( ! taxonomy_exists($taxonomy) )
|
1533 |
-
return false;
|
1534 |
-
|
1535 |
-
if ( 'slug' == $field ) {
|
1536 |
-
$field = 'm.meta_key = \''.$this->get_meta_key().'\' AND m.meta_value';
|
1537 |
-
$value = sanitize_title($value);
|
1538 |
-
if ( empty($value) )
|
1539 |
-
return false;
|
1540 |
-
} else if ( 'name' == $field ) {
|
1541 |
-
// Assume already escaped
|
1542 |
-
$value = stripslashes($value);
|
1543 |
-
$field = 't.name';
|
1544 |
-
} else {
|
1545 |
-
$term = get_term( (int) $value, $taxonomy, $output, $filter);
|
1546 |
-
if ( is_wp_error( $term ) )
|
1547 |
-
$term = false;
|
1548 |
-
return $term;
|
1549 |
-
}
|
1550 |
-
|
1551 |
-
$term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t, $wpdb->term_taxonomy AS tt, $wpdb->termmeta AS m WHERE t.term_id = tt.term_id AND tt.term_id = m.term_id AND tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value) );
|
1552 |
-
|
1553 |
-
if ( !$term && 'slug' == $original_field ) {
|
1554 |
-
$field = 't.slug';
|
1555 |
-
$term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value) );
|
1556 |
-
}
|
1557 |
-
|
1558 |
-
if ( !$term )
|
1559 |
-
return false;
|
1560 |
-
|
1561 |
-
wp_cache_add($term->term_id, $term, $taxonomy);
|
1562 |
-
|
1563 |
-
$term = apply_filters('get_term', $term, $taxonomy);
|
1564 |
-
$term = apply_filters("get_$taxonomy", $term, $taxonomy);
|
1565 |
-
$term = sanitize_term($term, $taxonomy, $filter);
|
1566 |
-
|
1567 |
-
if ( $output == OBJECT ) {
|
1568 |
-
return $term;
|
1569 |
-
} elseif ( $output == ARRAY_A ) {
|
1570 |
-
return get_object_vars($term);
|
1571 |
-
} elseif ( $output == ARRAY_N ) {
|
1572 |
-
return array_values(get_object_vars($term));
|
1573 |
-
} else {
|
1574 |
-
return $term;
|
1575 |
-
}
|
1576 |
-
}
|
1577 |
-
|
1578 |
-
|
1579 |
-
|
1580 |
-
/**
|
1581 |
-
* Fix for:
|
1582 |
-
* - Taxonomy names in Taxonomy Manage page
|
1583 |
-
* - 'Popular Tags' in Taxonomy (Tags) Manage page
|
1584 |
-
* - Category filter dropdown menu in Post Manage page
|
1585 |
-
* - Category list in Post Edit page
|
1586 |
-
* - 'Most Used' tags list in Post Edit page (but have issues when saving)
|
1587 |
-
*
|
1588 |
-
* @param (array) $terms
|
1589 |
-
* @param (string|array) $taxonomy
|
1590 |
-
* @since 1.2
|
1591 |
-
*/
|
1592 |
-
function get_terms($terms, $taxonomy) {
|
1593 |
-
|
1594 |
-
global $pagenow;
|
1595 |
-
|
1596 |
-
// Although in post edit page the tags in 'most
|
1597 |
-
// used' list are translated, but when saving the
|
1598 |
-
// post Wordpress considers the translated tags as
|
1599 |
-
// new tags. Due to this issue I skip this 'hack'
|
1600 |
-
// for tags in post edit page.
|
1601 |
-
if ( $pagenow != 'admin-ajax.php' ) {
|
1602 |
-
|
1603 |
-
$meta = get_option('qtranslate_term_name');
|
1604 |
-
$lang = qtrans_getLanguage();
|
1605 |
-
|
1606 |
-
if ( !empty( $terms ) ) {
|
1607 |
-
foreach ($terms as $term) {
|
1608 |
-
if ($meta[$term->name][$lang]) {
|
1609 |
-
$term->name = $meta[$term->name][$lang];
|
1610 |
-
}
|
1611 |
-
};
|
1612 |
-
};
|
1613 |
-
}
|
1614 |
-
|
1615 |
-
return $terms;
|
1616 |
-
}
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
-
/**
|
1621 |
-
* Fix for:
|
1622 |
-
* - Taxonomy & custom taxonomy names in Post Manage page
|
1623 |
-
* - List of tags already added to the post in Post
|
1624 |
-
* - Edit page (but have issues when saving)
|
1625 |
-
*
|
1626 |
-
* @param (array) $terms
|
1627 |
-
* @param (int|array) $obj_id
|
1628 |
-
* @param (string|array) $taxonomy
|
1629 |
-
* @param (array) $taxonomy
|
1630 |
-
* @since 1.2
|
1631 |
-
*/
|
1632 |
-
function get_object_terms($terms, $obj_id, $taxonomy, $args) {
|
1633 |
-
|
1634 |
-
global $pagenow;
|
1635 |
-
|
1636 |
-
// Although in post edit page the tags are translated,
|
1637 |
-
// but when saving/updating the post Wordpress considers
|
1638 |
-
// the translated tags as new tags. Due to this
|
1639 |
-
// issue I limit this 'hack' to the post manage
|
1640 |
-
// page only.
|
1641 |
-
if ( $pagenow == 'edit.php' ) {
|
1642 |
-
|
1643 |
-
// $taxonomy output seems to be wrapped
|
1644 |
-
// in single quotes, thus remove them to
|
1645 |
-
// make the output valid
|
1646 |
-
$tax = str_replace("'", "", $taxonomy);
|
1647 |
-
|
1648 |
-
$meta = get_option('qtranslate_term_name');
|
1649 |
-
$lang = qtrans_getLanguage();
|
1650 |
-
|
1651 |
-
if ( !empty( $terms ) ) {
|
1652 |
-
foreach ($terms as $term) {
|
1653 |
-
$term->name = $meta[$term->name][$lang];
|
1654 |
-
};
|
1655 |
-
};
|
1656 |
-
|
1657 |
-
}
|
1658 |
-
return $terms;
|
1659 |
-
}
|
1660 |
-
|
1661 |
|
1662 |
-
|
1663 |
-
/**
|
1664 |
-
* hide quickedit button ( functionality not supported by qTranslate )
|
1665 |
-
*
|
1666 |
-
* @since 1.0
|
1667 |
-
*/
|
1668 |
-
public function hide_quick_edit() {
|
1669 |
-
echo "<!-- QTS remove quick edit box -->" . PHP_EOL;
|
1670 |
-
echo "<style type=\"text/css\" media=\"screen\">" . PHP_EOL;
|
1671 |
-
echo " .row-actions .inline.inline.hide-if-no-js { display: none !important }" . PHP_EOL;
|
1672 |
-
echo "</style>" . PHP_EOL;
|
1673 |
-
}
|
1674 |
-
|
1675 |
-
|
1676 |
-
|
1677 |
-
/**
|
1678 |
-
* Hide auttomatically the wordpress slug blog in edit posts page
|
1679 |
-
*
|
1680 |
-
* @since 1.0
|
1681 |
-
*/
|
1682 |
-
public function hide_slug_box() {
|
1683 |
-
global $pagenow;
|
1684 |
-
|
1685 |
-
switch ( $pagenow ):
|
1686 |
-
case 'edit-tags.php':
|
1687 |
-
|
1688 |
-
echo "<!-- QTS remove slug box -->" . PHP_EOL;
|
1689 |
-
echo "<script type=\"text/javascript\" charset=\"utf-8\">" . PHP_EOL;
|
1690 |
-
echo " jQuery(document).ready(function($){" . PHP_EOL;
|
1691 |
-
echo " $(\"#tag-slug\").parent().hide();" . PHP_EOL;
|
1692 |
-
echo " $(\".form-field td #slug\").parent().parent().hide();" . PHP_EOL;
|
1693 |
-
echo " });" . PHP_EOL;
|
1694 |
-
echo "</script>" . PHP_EOL;
|
1695 |
-
break;
|
1696 |
-
|
1697 |
-
case 'post.php':
|
1698 |
-
|
1699 |
-
echo "<!-- QTS remove slug box -->" . PHP_EOL;
|
1700 |
-
echo "<style type=\"text/css\" media=\"screen\">" . PHP_EOL;
|
1701 |
-
echo " #edit-slug-box { display: none !important}" . PHP_EOL;
|
1702 |
-
echo "</style>" . PHP_EOL;
|
1703 |
-
break;
|
1704 |
-
endswitch;
|
1705 |
-
}
|
1706 |
-
|
1707 |
-
|
1708 |
-
|
1709 |
-
/**
|
1710 |
-
* Creates a metabox for every post, page and post type avaiable
|
1711 |
-
*
|
1712 |
-
* @since 1.0
|
1713 |
-
*/
|
1714 |
-
public function add_slug_meta_box() {
|
1715 |
-
|
1716 |
-
if ( function_exists( 'add_meta_box' ) ) {
|
1717 |
-
|
1718 |
-
add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), 'post', 'side', 'high');
|
1719 |
-
add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), 'page', 'side', 'high' );
|
1720 |
-
|
1721 |
-
foreach ( get_post_types( array('_builtin' => false ) ) as $ptype )
|
1722 |
-
add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), $ptype, 'side', 'high' );
|
1723 |
-
}
|
1724 |
-
}
|
1725 |
-
|
1726 |
-
|
1727 |
-
|
1728 |
-
/**
|
1729 |
-
* Shows the fields where insert the translated slugs in the post and page edit form.
|
1730 |
-
*
|
1731 |
-
* @param $post (object) current post object
|
1732 |
-
*
|
1733 |
-
* @since 1.0
|
1734 |
-
*/
|
1735 |
-
public function draw_meta_box( $post ) {
|
1736 |
-
global $q_config;
|
1737 |
-
|
1738 |
-
// Use nonce for verification
|
1739 |
-
echo "<table style=\"width:100%\">" . PHP_EOL;
|
1740 |
-
echo "<input type=\"hidden\" name=\"qts_nonce\" id=\"qts_nonce\" value=\"" . wp_create_nonce( 'qts_nonce' ) . "\" />" . PHP_EOL;
|
1741 |
-
|
1742 |
-
foreach ($q_config['enabled_languages'] as $lang):
|
1743 |
-
|
1744 |
-
$slug = get_post_meta( $post->ID, $this->get_meta_key($lang), true);
|
1745 |
-
|
1746 |
-
$value = ( $slug ) ? htmlspecialchars( $slug , ENT_QUOTES ) : '';
|
1747 |
-
|
1748 |
-
echo "<tr>" . PHP_EOL;
|
1749 |
-
echo "<th style=\"text-align:left; width:10%; color:#555 \"><label for=\"qts_{$lang}_slug\">".__($q_config['language_name'][$lang], 'qtranslate')."</label></th>" . PHP_EOL;
|
1750 |
-
echo "<td><input type=\"text\" id=\"qts_{$lang}_slug\" name=\"qts_{$lang}_slug\" value=\"$value\" style=\"width:90%; margin-left:10%; color:#777\" /></td>" . PHP_EOL;
|
1751 |
-
echo "</tr>" . PHP_EOL;
|
1752 |
-
|
1753 |
-
endforeach;
|
1754 |
-
|
1755 |
-
echo '</table>' . PHP_EOL;
|
1756 |
-
}
|
1757 |
-
|
1758 |
-
|
1759 |
-
|
1760 |
-
/**
|
1761 |
-
* Sanitize title as slug, if empty slug
|
1762 |
-
*
|
1763 |
-
* @param $post (object) the post object
|
1764 |
-
* @param $slug (string) the slug name
|
1765 |
-
* @param $lang (string) the language
|
1766 |
-
* @return the slug validated
|
1767 |
-
*
|
1768 |
-
* @since 1.0
|
1769 |
-
*/
|
1770 |
-
public function validate_post_slug( $slug, $post, $lang ) {
|
1771 |
-
|
1772 |
-
$post_title = trim(qtrans_use($lang, $_POST['post_title']));
|
1773 |
-
$post_name = get_post_meta($post->ID, $this->get_meta_key($lang), true);
|
1774 |
-
if (!$post_name) $post_name = $post->post_name;
|
1775 |
-
|
1776 |
-
$name = ( $post_title == '' || strlen($post_title) == 0 ) ? $post_name : $post_title;
|
1777 |
-
|
1778 |
-
$slug = trim($slug);
|
1779 |
-
|
1780 |
-
$slug = (empty($slug)) ? sanitize_title($name) : sanitize_title($slug);
|
1781 |
-
|
1782 |
-
|
1783 |
-
|
1784 |
-
return htmlspecialchars( $slug , ENT_QUOTES );
|
1785 |
-
}
|
1786 |
-
|
1787 |
-
|
1788 |
-
|
1789 |
-
/**
|
1790 |
-
* Validates post slug against repetitions per language
|
1791 |
-
*
|
1792 |
-
* @param $post (object) the post object
|
1793 |
-
* @param $slug (string) the slug name
|
1794 |
-
* @param $lang (string) the language
|
1795 |
-
* @return the slug validated
|
1796 |
-
*
|
1797 |
-
* @since 1.0
|
1798 |
-
*/
|
1799 |
-
public function unique_post_slug( $slug, $post, $lang ) {
|
1800 |
-
|
1801 |
-
$original_status = $post->post_status;
|
1802 |
-
|
1803 |
-
if ( in_array($post->post_status, array('draft', 'pending')) )
|
1804 |
-
$post->post_status = 'publish';
|
1805 |
-
|
1806 |
-
$slug = $this->wp_unique_post_slug( $slug, $post->ID, $post->post_status, $post->post_type, $post->post_parent, $lang );
|
1807 |
-
|
1808 |
-
$post->post_status = $original_status;
|
1809 |
-
|
1810 |
-
return $slug;
|
1811 |
-
}
|
1812 |
-
|
1813 |
-
|
1814 |
-
|
1815 |
-
/**
|
1816 |
-
* Computes a unique slug for the post and language, when given the desired slug and some post details.
|
1817 |
-
*
|
1818 |
-
* @param string $slug the desired slug (post_name)
|
1819 |
-
* @param integer $post_ID
|
1820 |
-
* @param string $post_status no uniqueness checks are made if the post is still draft or pending
|
1821 |
-
* @param string $post_type
|
1822 |
-
* @param integer $post_parent
|
1823 |
-
* @return string unique slug for the post, based on language meta_value (with a -1, -2, etc. suffix)
|
1824 |
-
*
|
1825 |
-
* @since 1.0
|
1826 |
-
*/
|
1827 |
-
public function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $lang ) {
|
1828 |
-
if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
|
1829 |
-
return $slug;
|
1830 |
-
|
1831 |
-
global $wpdb, $wp_rewrite;
|
1832 |
-
|
1833 |
-
$feeds = $wp_rewrite->feeds;
|
1834 |
-
if ( ! is_array( $feeds ) )
|
1835 |
-
$feeds = array();
|
1836 |
-
|
1837 |
-
$meta_key = $this->get_meta_key($lang);
|
1838 |
-
if ( 'attachment' == $post_type ) {
|
1839 |
-
// Attachment slugs must be unique across all types.
|
1840 |
-
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
|
1841 |
-
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) );
|
1842 |
-
|
1843 |
-
if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
|
1844 |
-
$suffix = 2;
|
1845 |
-
do {
|
1846 |
-
$alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
|
1847 |
-
$post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID ) );
|
1848 |
-
$suffix++;
|
1849 |
-
} while ( $post_name_check );
|
1850 |
-
$slug = $alt_post_name;
|
1851 |
-
}
|
1852 |
-
} else {
|
1853 |
-
// Post slugs must be unique across all posts.
|
1854 |
-
$check_sql = "SELECT $wpdb->postmeta.meta_value FROM $wpdb->posts,$wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '%s' AND $wpdb->postmeta.meta_value = '%s' AND $wpdb->posts.post_type = %s AND ID != %d LIMIT 1";
|
1855 |
-
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $meta_key, $slug, $post_type, $post_ID ) );
|
1856 |
-
|
1857 |
-
if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
|
1858 |
-
$suffix = 2;
|
1859 |
-
do {
|
1860 |
-
$alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
|
1861 |
-
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $meta_key, $alt_post_name, $post_type, $post_ID ) );
|
1862 |
-
$suffix++;
|
1863 |
-
} while ( $post_name_check );
|
1864 |
-
$slug = $alt_post_name;
|
1865 |
-
}
|
1866 |
-
}
|
1867 |
-
|
1868 |
-
return $slug;
|
1869 |
-
}
|
1870 |
-
|
1871 |
-
|
1872 |
-
|
1873 |
-
|
1874 |
-
/**
|
1875 |
-
* Saves the translated slug when the page is saved
|
1876 |
-
*
|
1877 |
-
* @param $post_id the post id
|
1878 |
-
* @param $post the post object
|
1879 |
-
*
|
1880 |
-
* @since 1.0
|
1881 |
-
*/
|
1882 |
-
public function save_postdata( $post_id, $post ) {
|
1883 |
-
global $q_config;
|
1884 |
-
|
1885 |
-
$post_type_object = get_post_type_object( $post->post_type);
|
1886 |
-
|
1887 |
-
|
1888 |
-
if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) // check autosave
|
1889 |
-
|| (!isset($_POST['post_ID']) || $post_id != $_POST['post_ID']) // check revision
|
1890 |
-
|| (!wp_verify_nonce( $_POST['qts_nonce'], 'qts_nonce')) // verify nonce
|
1891 |
-
|| (!current_user_can($post_type_object->cap->edit_post, $post_id))) { // check permission
|
1892 |
-
return $post_id;
|
1893 |
-
}
|
1894 |
-
|
1895 |
-
foreach ($q_config['enabled_languages'] as $lang):
|
1896 |
-
|
1897 |
-
$meta_name = $this->get_meta_key($lang);
|
1898 |
-
$meta_value = apply_filters( 'qts_validate_post_slug', $_POST["qts_{$lang}_slug"], $post, $lang);
|
1899 |
-
|
1900 |
-
delete_post_meta($post_id, $meta_name);
|
1901 |
-
update_post_meta($post_id, $meta_name, $meta_value);
|
1902 |
-
|
1903 |
-
endforeach;
|
1904 |
-
}
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
/**
|
1909 |
-
* Display multiple input fields, one per language
|
1910 |
-
*
|
1911 |
-
* @param $term the term object
|
1912 |
-
*
|
1913 |
-
* @since 1.0
|
1914 |
-
*/
|
1915 |
-
public function show_term_fields( $term ) {
|
1916 |
-
global $q_config;
|
1917 |
-
|
1918 |
-
// prints the fields in edit page
|
1919 |
-
if (isset($_GET['action']) && $_GET['action'] == 'edit' ):
|
1920 |
-
|
1921 |
-
echo "<table class=\"form-table\">" . PHP_EOL;
|
1922 |
-
echo "<input type=\"hidden\" name=\"qts_nonce\" id=\"qts_nonce\" value=\"" . wp_create_nonce( 'qts_nonce' ) . "\" />" . PHP_EOL;
|
1923 |
-
|
1924 |
-
foreach( $q_config['enabled_languages'] as $lang ):
|
1925 |
-
|
1926 |
-
$slug = (is_object($term)) ? get_term_meta( $term->term_id, $this->get_meta_key($lang), true ) : '';
|
1927 |
-
|
1928 |
-
$value = ( $slug ) ? htmlspecialchars( $slug , ENT_QUOTES ) : '';
|
1929 |
-
|
1930 |
-
echo "<tr class=\"form-field form-required\">" . PHP_EOL;
|
1931 |
-
echo "<th scope=\"row\" valig=\"top\"><label for=\"qts_term_{$lang}_slug\">Slug (".__($q_config['language_name'][$lang], 'qtranslate').")</label></th>" . PHP_EOL;
|
1932 |
-
echo "<td><input type=\"text\" name=\"qts_{$lang}_slug\" value=\"$value\" /></td></tr>" . PHP_EOL;
|
1933 |
-
|
1934 |
-
endforeach;
|
1935 |
-
|
1936 |
-
echo '</table>';
|
1937 |
-
|
1938 |
-
// prints the fields in new page
|
1939 |
-
else:
|
1940 |
-
echo "<input type=\"hidden\" name=\"qts_nonce\" id=\"qts_nonce\" value=\"" . wp_create_nonce( 'qts_nonce' ) . "\" />" . PHP_EOL;
|
1941 |
-
|
1942 |
-
foreach( $q_config['enabled_languages'] as $lang ):
|
1943 |
-
|
1944 |
-
echo "<div class=\"form-field\">" . PHP_EOL;
|
1945 |
-
|
1946 |
-
$slug = (is_object($term)) ? get_term_meta( $term->term_id, $this->get_meta_key($lang), true ) : '';
|
1947 |
-
|
1948 |
-
$value = ( $slug ) ? htmlspecialchars( $slug , ENT_QUOTES ) : '';
|
1949 |
-
|
1950 |
-
|
1951 |
-
echo "<label for=\"qts_{$lang}_slug\">Slug (".__($q_config['language_name'][$lang], 'qtranslate').")</label>" . PHP_EOL;
|
1952 |
-
echo "<input type=\"text\" name=\"qts_term_{$lang}_slug\" value=\"$value\" aria-required=\"true\">" . PHP_EOL;
|
1953 |
-
|
1954 |
-
echo '</div>';
|
1955 |
-
|
1956 |
-
endforeach;
|
1957 |
-
|
1958 |
-
endif;
|
1959 |
-
}
|
1960 |
-
|
1961 |
-
|
1962 |
-
|
1963 |
-
/**
|
1964 |
-
* Sanitize title as slug, if empty slug
|
1965 |
-
*
|
1966 |
-
* @param $term (object) the term object
|
1967 |
-
* @param $slug (string) the slug name
|
1968 |
-
* @param $lang (string) the language
|
1969 |
-
* @return the slug validated
|
1970 |
-
*
|
1971 |
-
* @since 1.0
|
1972 |
-
*/
|
1973 |
-
public function validate_term_slug( $slug, $term, $lang ) {
|
1974 |
-
|
1975 |
-
|
1976 |
-
global $q_config;
|
1977 |
-
|
1978 |
-
$lang_name = $q_config['term_name'][$term->name][$lang];
|
1979 |
-
|
1980 |
-
$ajax_name = 'new' . $term->taxonomy;
|
1981 |
-
|
1982 |
-
$post_name = isset($_POST['name']) ? $_POST['name'] : '';
|
1983 |
-
|
1984 |
-
$term_name = isset($_POST[$ajax_name]) ? trim($_POST[$ajax_name]) : $post_name;
|
1985 |
-
|
1986 |
-
if (empty($term_name)) return $slug;
|
1987 |
-
|
1988 |
-
$name = ( $lang_name == '' || strlen($lang_name) == 0 ) ? $term_name : $lang_name;
|
1989 |
-
|
1990 |
-
$slug = trim($slug);
|
1991 |
-
|
1992 |
-
$slug = (empty($slug)) ? sanitize_title($name) : sanitize_title($slug);
|
1993 |
-
|
1994 |
-
return htmlspecialchars( $slug , ENT_QUOTES );
|
1995 |
-
}
|
1996 |
-
|
1997 |
-
|
1998 |
-
|
1999 |
-
/**
|
2000 |
-
* Will make slug unique per language, if it isn't already.
|
2001 |
-
*
|
2002 |
-
* @param string $slug The string that will be tried for a unique slug
|
2003 |
-
* @param object $term The term object that the $slug will belong too
|
2004 |
-
* @param object $lang The language reference
|
2005 |
-
* @return string Will return a true unique slug.
|
2006 |
-
*
|
2007 |
-
* @since 1.0
|
2008 |
-
*/
|
2009 |
-
public function unique_term_slug($slug, $term, $lang) {
|
2010 |
-
|
2011 |
-
global $wpdb;
|
2012 |
-
$meta_key_name = $this->get_meta_key($lang);
|
2013 |
-
$query = $wpdb->prepare("SELECT term_id FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s' AND term_id != %d ",
|
2014 |
-
$meta_key_name,
|
2015 |
-
$slug,
|
2016 |
-
$term->term_id);
|
2017 |
-
$exists_slug = $wpdb->get_results($query);
|
2018 |
-
|
2019 |
-
if ( empty($exists_slug) )
|
2020 |
-
return $slug;
|
2021 |
-
|
2022 |
-
// If we didn't get a unique slug, try appending a number to make it unique.
|
2023 |
-
$query = $wpdb->prepare(
|
2024 |
-
"SELECT meta_value FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s' AND term_id != %d",
|
2025 |
-
$meta_key_name,
|
2026 |
-
$slug,
|
2027 |
-
$term->term_id);
|
2028 |
-
|
2029 |
-
if ( $wpdb->get_var( $query ) ) {
|
2030 |
-
$num = 2;
|
2031 |
-
do {
|
2032 |
-
$alt_slug = $slug . "-$num";
|
2033 |
-
$num++;
|
2034 |
-
$slug_check = $wpdb->get_var(
|
2035 |
-
$wpdb->prepare(
|
2036 |
-
"SELECT meta_value FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s'",
|
2037 |
-
$meta_key_name,
|
2038 |
-
$alt_slug) );
|
2039 |
-
} while ( $slug_check );
|
2040 |
-
$slug = $alt_slug;
|
2041 |
-
}
|
2042 |
-
|
2043 |
-
return $slug;
|
2044 |
-
}
|
2045 |
-
|
2046 |
-
|
2047 |
-
|
2048 |
-
/**
|
2049 |
-
* Display multiple input fields, one per language
|
2050 |
-
*
|
2051 |
-
* @param $term_id the term id
|
2052 |
-
* @param $tt_id the term taxonomy id
|
2053 |
-
* @param $taxonomy the term object
|
2054 |
-
*
|
2055 |
-
* @since 1.0
|
2056 |
-
*/
|
2057 |
-
public function save_term( $term_id, $tt_id, $taxonomy ) {
|
2058 |
-
global $q_config;
|
2059 |
-
|
2060 |
-
if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) // check autosave
|
2061 |
-
|| ( !current_user_can('edit_posts') ) ) { // check permission
|
2062 |
-
return $term_id;
|
2063 |
-
}
|
2064 |
-
|
2065 |
-
$term = get_term( $term_id, $taxonomy);
|
2066 |
-
|
2067 |
-
foreach( $q_config['enabled_languages'] as $lang ):
|
2068 |
-
|
2069 |
-
$meta_name = $this->get_meta_key($lang);
|
2070 |
-
|
2071 |
-
|
2072 |
-
//LC43: when at the post edit screen and creating a new tag
|
2073 |
-
// the $slug comes from $_POST with the value of the post slug,
|
2074 |
-
// not with the term slug.
|
2075 |
-
if( $_POST['action'] == "editpost"){
|
2076 |
-
// so we use the slug wp gave it
|
2077 |
-
$term_slug = $term->slug;
|
2078 |
-
} else {
|
2079 |
-
// otherwise, its the edit term screen
|
2080 |
-
$term_slug = $_POST["qts_term_{$lang}_slug"];
|
2081 |
-
}
|
2082 |
-
$meta_value = apply_filters( 'qts_validate_term_slug', $term_slug, $term, $lang);
|
2083 |
-
|
2084 |
-
delete_term_meta($term_id, $meta_name);
|
2085 |
-
update_term_meta($term_id, $meta_name, $meta_value);
|
2086 |
-
|
2087 |
-
endforeach;
|
2088 |
-
}
|
2089 |
-
|
2090 |
-
|
2091 |
-
|
2092 |
-
/**
|
2093 |
-
* deletes termmeta rows associated with the term
|
2094 |
-
*
|
2095 |
-
* @since 1.0
|
2096 |
-
*/
|
2097 |
-
public function delete_term($term_id, $tt_id, $taxonomy) {
|
2098 |
-
global $wpdb;
|
2099 |
-
|
2100 |
-
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE term_id = %d", $term_id ) );
|
2101 |
-
}
|
2102 |
-
|
2103 |
-
|
2104 |
-
|
2105 |
-
/**
|
2106 |
-
* adds support for qtranslate in taxonomies
|
2107 |
-
*
|
2108 |
-
* @since 1.0
|
2109 |
-
*/
|
2110 |
-
public function taxonomies_hooks() {
|
2111 |
-
|
2112 |
-
$taxonomies = $this->get_public_taxonomies();
|
2113 |
-
|
2114 |
-
if ($taxonomies) {
|
2115 |
-
foreach ($taxonomies as $taxonomy ) {
|
2116 |
-
add_action( $taxonomy->name.'_add_form', 'qtrans_modifyTermFormFor');
|
2117 |
-
add_action( $taxonomy->name.'_edit_form', 'qtrans_modifyTermFormFor');
|
2118 |
-
add_action( $taxonomy->name.'_add_form', array(&$this, 'show_term_fields'));
|
2119 |
-
add_action( $taxonomy->name.'_edit_form_fields', array(&$this, 'show_term_fields') );
|
2120 |
-
add_filter('manage_edit-'.$taxonomy->name.'_columns', array(&$this, 'taxonomy_columns'));
|
2121 |
-
add_filter('manage_'.$taxonomy->name.'_custom_column', array(&$this, 'taxonomy_custom_column'), 0, 3);
|
2122 |
-
}
|
2123 |
-
}
|
2124 |
-
}
|
2125 |
-
|
2126 |
-
|
2127 |
-
|
2128 |
-
/*
|
2129 |
-
* Bug fix for slug column in taxonomies
|
2130 |
-
*
|
2131 |
-
* @since 1.0
|
2132 |
-
*/
|
2133 |
-
public function taxonomy_columns($columns) {
|
2134 |
-
unset($columns['slug']);
|
2135 |
-
unset($columns['posts']);
|
2136 |
-
|
2137 |
-
$columns['qts-slug'] = __('Slug', 'qts');
|
2138 |
-
$columns['posts'] = __('Posts');
|
2139 |
-
|
2140 |
-
return $columns;
|
2141 |
-
}
|
2142 |
-
|
2143 |
-
|
2144 |
-
|
2145 |
-
/*
|
2146 |
-
* Bug fix for slug column in taxonomies
|
2147 |
-
*
|
2148 |
-
* @since 1.0
|
2149 |
-
*/
|
2150 |
-
public function taxonomy_custom_column($str, $column_name, $term_id) {
|
2151 |
-
|
2152 |
-
switch ($column_name) {
|
2153 |
-
case 'qts-slug':
|
2154 |
-
echo get_term_meta($term_id, $this->get_meta_key(), true);
|
2155 |
-
break;
|
2156 |
-
}
|
2157 |
-
return false;
|
2158 |
-
}
|
2159 |
-
|
2160 |
-
|
2161 |
-
|
2162 |
-
|
2163 |
-
/**
|
2164 |
-
* Bug fix for multisite blog names
|
2165 |
-
*
|
2166 |
-
* @since 1.0
|
2167 |
-
*/
|
2168 |
-
public function blog_names($blogs) {
|
2169 |
-
|
2170 |
-
foreach ($blogs as $blog)
|
2171 |
-
$blog->blogname = __($blog->blogname);
|
2172 |
-
|
2173 |
-
return $blogs;
|
2174 |
-
}
|
2175 |
-
|
2176 |
-
|
2177 |
-
|
2178 |
-
/**
|
2179 |
-
* Initialise the Language Widget selector
|
2180 |
-
*
|
2181 |
-
* @since 1.0
|
2182 |
-
*/
|
2183 |
-
public function widget_init() {
|
2184 |
-
|
2185 |
-
if (class_exists('qTranslateWidget'))
|
2186 |
-
unregister_widget('qTranslateWidget');
|
2187 |
-
|
2188 |
-
register_widget('QtranslateSlugWidget');
|
2189 |
-
}
|
2190 |
-
|
2191 |
-
|
2192 |
-
|
2193 |
-
/**
|
2194 |
-
* remove some default dashboard Widgets on Desktop
|
2195 |
-
*
|
2196 |
-
* @since 1.0
|
2197 |
-
*/
|
2198 |
-
function remove_dashboard_widgets() {
|
2199 |
-
global $wp_meta_boxes;
|
2200 |
-
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
|
2201 |
-
}
|
2202 |
-
|
2203 |
-
|
2204 |
-
|
2205 |
-
/**
|
2206 |
-
* adds support for qtranslate nav menus
|
2207 |
-
*
|
2208 |
-
* @since 1.0
|
2209 |
-
*/
|
2210 |
-
public function fix_nav_menu() {
|
2211 |
-
global $pagenow;
|
2212 |
-
|
2213 |
-
if( $pagenow != 'nav-menus.php' ) return;
|
2214 |
-
|
2215 |
-
wp_enqueue_script( 'nav-menu-query', plugins_url( 'assets/js/qts-nav-menu-min.js' , __FILE__ ) , 'nav-menu', '1.0' );
|
2216 |
-
add_meta_box( 'qt-languages', __('Languages'), array(&$this, 'nav_menu_meta_box'), 'nav-menus', 'side', 'default' );
|
2217 |
-
}
|
2218 |
-
|
2219 |
-
|
2220 |
-
|
2221 |
-
/**
|
2222 |
-
* draws meta box for select language
|
2223 |
-
*
|
2224 |
-
* @since 1.0
|
2225 |
-
*/
|
2226 |
-
public function nav_menu_meta_box() {
|
2227 |
-
global $q_config;
|
2228 |
-
echo '<p>';
|
2229 |
-
foreach($q_config['enabled_languages'] as $id => $language) {
|
2230 |
-
$checked = ($language == $q_config['language']) ? ' checked="checked"' : '';
|
2231 |
-
echo '<p style="margin:0 0 5px 0"><input type="radio" style="margin-right:5px" name="wa_qt_lang" value="' . $language . '" id="wa_gt_lang_' . $id . '" ' . $checked . '/>';
|
2232 |
-
echo '<label for="wa_gt_lang_' . $id . '">';
|
2233 |
-
echo '<img src="' . trailingslashit(WP_CONTENT_URL).$q_config['flag_location'].$q_config['flag'][$language] . '"/> ';
|
2234 |
-
echo __($q_config['language_name'][$language], 'qtranslate');
|
2235 |
-
echo '</label></p>';
|
2236 |
-
}
|
2237 |
-
echo '</p>';
|
2238 |
-
}
|
2239 |
-
|
2240 |
-
|
2241 |
-
|
2242 |
-
/**
|
2243 |
-
* Language select function for templating
|
2244 |
-
*
|
2245 |
-
* @param $type (string) choose the type of menu: 'text', 'image', 'both', 'dropdown'
|
2246 |
-
* @param $args (array) some args for draw the menu: array( 'id', 'class', 'short' );
|
2247 |
-
*
|
2248 |
-
* @since 1.0
|
2249 |
-
*/
|
2250 |
-
public function language_menu( $type = "text", $args = array() ) {
|
2251 |
-
global $q_config;
|
2252 |
-
|
2253 |
-
// default arguments
|
2254 |
-
$defaults = array(
|
2255 |
-
'id' => "qts-lang-menu",
|
2256 |
-
'class' => "qts-lang-menu",
|
2257 |
-
'short' => false
|
2258 |
-
);
|
2259 |
-
$args = wp_parse_args( $args, $defaults );
|
2260 |
-
|
2261 |
-
$languages = qtrans_getSortedLanguages();
|
2262 |
-
|
2263 |
-
// every type
|
2264 |
-
switch ( $type ) {
|
2265 |
-
|
2266 |
-
case 'image':
|
2267 |
-
case 'text':
|
2268 |
-
case 'both':
|
2269 |
-
|
2270 |
-
echo "<ul id=\"{$args['id']}\" class=\"qts_type_{$type} {$args['class']}\">". PHP_EOL;
|
2271 |
-
|
2272 |
-
foreach( $languages as $index => $lang ):
|
2273 |
-
|
2274 |
-
$url = $this->get_current_url($lang);
|
2275 |
-
|
2276 |
-
$item_class = array();
|
2277 |
-
if ( (string)$q_config['language'] == (string)$lang ) $item_class[] = 'current-menu-item';
|
2278 |
-
if ( $index == (count($languages) - 1) ) $item_class[] = 'last-child';
|
2279 |
-
|
2280 |
-
|
2281 |
-
$item_class = ' class="qts_lang_item ' . implode(' ', $item_class) . '"';
|
2282 |
-
|
2283 |
-
$language_name = ($args['short']) ? $lang : $q_config['language_name'][$lang];
|
2284 |
-
|
2285 |
-
if ( $type == 'image' ) {
|
2286 |
-
$link_class = " class=\"qtrans_flag qtrans_flag_$lang\"";
|
2287 |
-
$link_content = "<span style=\"display:none\">$language_name</span>";
|
2288 |
-
} else if ( $type == 'both' ) {
|
2289 |
-
$link_class = " class=\"qts_both qtrans_flag qtrans_flag_$lang\"";
|
2290 |
-
$link_content = "$language_name";
|
2291 |
-
|
2292 |
-
} else {
|
2293 |
-
$link_class = '';
|
2294 |
-
$link_content = $language_name;
|
2295 |
-
}
|
2296 |
-
|
2297 |
-
echo "<li$item_class><a href=\"$url\" hreflang=\"$lang\"$link_class>$link_content</a></li>" . PHP_EOL;
|
2298 |
-
|
2299 |
-
endforeach;
|
2300 |
-
|
2301 |
-
echo "</ul>". PHP_EOL;
|
2302 |
-
|
2303 |
-
break;
|
2304 |
-
|
2305 |
-
case 'dropdown':
|
2306 |
-
|
2307 |
-
echo "<select id=\"{$args['id']}\" class=\"{$args['class']}\" onchange=\"window.location.href=this.options[this.selectedIndex].value\">". PHP_EOL;
|
2308 |
-
|
2309 |
-
foreach( $languages as $index => $lang ):
|
2310 |
-
|
2311 |
-
$url = $this->get_current_url($lang);
|
2312 |
-
|
2313 |
-
$item_class = '';
|
2314 |
-
if ( (string)$q_config['language'] == (string)$lang ) $item_class = 'selected="selected"';
|
2315 |
-
|
2316 |
-
$language_name = ($args['short']) ? $lang : $q_config['language_name'][$lang];
|
2317 |
-
|
2318 |
-
echo "<option value=\"$url\" $item_class>$language_name</option>" . PHP_EOL;
|
2319 |
-
|
2320 |
-
endforeach;
|
2321 |
-
|
2322 |
-
echo "</select>". PHP_EOL;
|
2323 |
-
|
2324 |
-
break;
|
2325 |
-
}
|
2326 |
-
|
2327 |
-
}
|
2328 |
-
}
|
2329 |
////////////////////////////////////////////////////////////////////////////////////////
|
2330 |
|
2331 |
|
@@ -2335,11 +50,11 @@ class QtranslateSlug {
|
|
2335 |
*
|
2336 |
* @since 1.0
|
2337 |
*/
|
2338 |
-
if (!defined("QTS_VERSION")) define("QTS_VERSION", '1.1.
|
2339 |
if (!defined("QTS_PREFIX")) define("QTS_PREFIX", '_qts_');
|
2340 |
-
if (!defined("QTS_PAGE_BASENAME"))
|
2341 |
-
if (!defined("QTS_OPTIONS_NAME"))
|
2342 |
-
if (!defined("PHP_EOL"))
|
2343 |
|
2344 |
////////////////////////////////////////////////////////////////////////////////////////
|
2345 |
|
@@ -2350,10 +65,11 @@ if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
|
|
2350 |
*
|
2351 |
* @since 1.0
|
2352 |
*/
|
2353 |
-
if ( is_admin() && !QtranslateSlug::block_activate() )
|
2354 |
-
include_once('qtranslate-slug-settings.php');
|
|
|
2355 |
|
2356 |
-
include_once('termmeta-core.php'); // termmeta install and core functions
|
2357 |
|
2358 |
////////////////////////////////////////////////////////////////////////////////////////
|
2359 |
|
@@ -2406,7 +122,11 @@ function qts_language_menu ($type = "text", $args = array()) {
|
|
2406 |
* @subpackage Core
|
2407 |
* @since 1.1.5
|
2408 |
*/
|
2409 |
-
function qTranslateSlug_getSelfUrl ($lang = false) {
|
|
|
|
|
|
|
|
|
2410 |
global $qtranslate_slug;
|
2411 |
|
2412 |
return $qtranslate_slug->get_current_url($lang);
|
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.8
|
7 |
Author: Carlos Sanz Garcia
|
8 |
Author URI: http://github.com/not-only-code
|
9 |
*/
|
28 |
endif;
|
29 |
}
|
30 |
endif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
////////////////////////////////////////////////////////////////////////////////////////
|
33 |
|
34 |
|
35 |
|
36 |
/**
|
37 |
+
* Includes
|
38 |
*
|
39 |
+
* @since 1.1.8
|
40 |
*/
|
41 |
+
include_once(dirname(__FILE__).'/includes/class-qtranslate-slug-widget.php');
|
42 |
+
include_once(dirname(__FILE__).'/includes/class-qtranslate-slug.php');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
////////////////////////////////////////////////////////////////////////////////////////
|
45 |
|
46 |
|
50 |
*
|
51 |
* @since 1.0
|
52 |
*/
|
53 |
+
if (!defined("QTS_VERSION")) define("QTS_VERSION", '1.1.8');
|
54 |
if (!defined("QTS_PREFIX")) define("QTS_PREFIX", '_qts_');
|
55 |
+
if (!defined("QTS_PAGE_BASENAME")) define('QTS_PAGE_BASENAME', 'qtranslate-slug-settings');
|
56 |
+
if (!defined("QTS_OPTIONS_NAME")) define("QTS_OPTIONS_NAME", 'qts_options');
|
57 |
+
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
|
58 |
|
59 |
////////////////////////////////////////////////////////////////////////////////////////
|
60 |
|
65 |
*
|
66 |
* @since 1.0
|
67 |
*/
|
68 |
+
if ( is_admin() && !QtranslateSlug::block_activate() ) { // setting options page
|
69 |
+
include_once(dirname(__FILE__).'/includes/qtranslate-slug-settings.php');
|
70 |
+
}
|
71 |
|
72 |
+
include_once(dirname(__FILE__).'/includes/termmeta-core.php'); // termmeta install and core functions
|
73 |
|
74 |
////////////////////////////////////////////////////////////////////////////////////////
|
75 |
|
122 |
* @subpackage Core
|
123 |
* @since 1.1.5
|
124 |
*/
|
125 |
+
function qTranslateSlug_getSelfUrl ($lang = false) { // bad naming, I'll keep just in case
|
126 |
+
return qts_get_url($lang);
|
127 |
+
}
|
128 |
+
|
129 |
+
function qts_get_url($lang = false) {
|
130 |
global $qtranslate_slug;
|
131 |
|
132 |
return $qtranslate_slug->get_current_url($lang);
|
readme.md
ADDED
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
@@ -3,8 +3,8 @@ 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:
|
7 |
-
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -19,19 +19,46 @@ Adds support for permalink translations and fix some QTranslate deficiencies sin
|
|
19 |
= Requirements: =
|
20 |
|
21 |
* Wordpress 3.3 (PHP 5.2 and MySQL 5)
|
22 |
-
* mQtranslate 2.6.2.4 or Qtranslate 2.5.8
|
23 |
|
24 |
-
= New in version 1.1.
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
**Advice: If you're using a multisite installation, you will must activate qtranslate plugins by separately on each site.**
|
30 |
|
|
|
31 |
|
32 |
You can also check the [project website](http://not-only-code.github.com/qtranslate-slug/) hosted on [GitHub](http://not-only-code.github.com).
|
33 |
Thanks for use this plugin!
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
== Installation ==
|
36 |
**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.**
|
37 |
|
@@ -77,6 +104,26 @@ That's because language selector metabox is hidden, if you are in admin *nav men
|
|
77 |
4. Qtranslate Slug options page for translate base permastructs of post_types and taxonomies.
|
78 |
|
79 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
= 1.1.7 =
|
81 |
* removed styles from html elements and added options to use .css file or print inline styles
|
82 |
* fixed tag creation on post edit.
|
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 |
|
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 |
|
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.
|
trunk/README.txt
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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: 3.9.1
|
7 |
+
Version: 1.1.7
|
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
|
23 |
+
|
24 |
+
= New in version 1.1.7 =
|
25 |
+
* removed styles from html elements and added options to use .css file or print inline styles
|
26 |
+
* fixed tag creation on post edit.
|
27 |
+
* fixed earlier bad post slug introduced in 1.1.6
|
28 |
+
|
29 |
+
**Advice: If you're using a multisite installation, you will must activate qtranslate plugins by separately on each site.**
|
30 |
+
|
31 |
+
You can also check the [project website](http://not-only-code.github.com/qtranslate-slug/) hosted on [GitHub](http://not-only-code.github.com).
|
32 |
+
Thanks for use this plugin!
|
33 |
+
|
34 |
+
= Contributors =
|
35 |
+
|
36 |
+
* [Pedro de Carvalho](https://github.com/LC43/)
|
37 |
+
* [Risto Niinemets](https://github.com/RistoNiinemets)
|
38 |
+
* [Pedro Mendonça](https://github.com/pedro-mendonca)
|
39 |
+
* [codep0et](https://github.com/codep0et)
|
40 |
+
* [Giraldi Maggio](https://github.com/bedex78)
|
41 |
+
* [jinoOM](https://github.com/jinoOM)
|
42 |
+
|
43 |
+
|
44 |
+
== Installation ==
|
45 |
+
**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.**
|
46 |
+
|
47 |
+
1. Upload `qtranslate-slug` to the `/wp-content/plugins/` directory.
|
48 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress.
|
49 |
+
1. That's all!
|
50 |
+
|
51 |
+
= Changing base permastructs =
|
52 |
+
|
53 |
+
1. In admin: navigate to *Settings/Slug options*.
|
54 |
+
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).
|
55 |
+
1. Save settings and that's all!
|
56 |
+
|
57 |
+
== Frequently Asked Questions ==
|
58 |
+
|
59 |
+
= It works with posts and pages, but with other content type? =
|
60 |
+
|
61 |
+
This plugin allows to translate slugs of: posts, pages, custom post types, categories, tags and custom taxonomies.
|
62 |
+
|
63 |
+
= Do I have to configure anything? =
|
64 |
+
|
65 |
+
If you want to translate also the base permastructs (ex. *category*, *tag*, etc). Visit the plugin settings page in the admin *Settings/Slug options*
|
66 |
+
|
67 |
+
= How can i insert a language selector in my theme ? =
|
68 |
+
|
69 |
+
You can choose to:
|
70 |
+
* use **Qtranslate Slug Widget** in your sidebar.
|
71 |
+
* place in your template `<?php if (function_exists('qts_language_menu') ) qts_language_menu('text'); ?>`. Options are: `dropdown`, `text`, `image`, and `both`.
|
72 |
+
|
73 |
+
= Appears an error 404, what can i do? =
|
74 |
+
|
75 |
+
In the admin go to *Settings/Permalinks* or *Settings/Slug options* and save.
|
76 |
+
|
77 |
+
= I can't manage translations in Nav Menus. =
|
78 |
+
|
79 |
+
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.
|
80 |
+
|
81 |
+
== Screenshots ==
|
82 |
+
|
83 |
+
1. Edit page for: post / page / post_type, you can see the meta box for translated slugs on top and right.
|
84 |
+
2. Add new taxonomy page
|
85 |
+
3. Edit taxonomy page
|
86 |
+
4. Qtranslate Slug options page for translate base permastructs of post_types and taxonomies.
|
87 |
+
|
88 |
+
== Changelog ==
|
89 |
+
= 1.1.7 =
|
90 |
+
* removed styles from html elements and added options to use .css file or print inline styles
|
91 |
+
* fixed tag creation on post edit.
|
92 |
+
* fixed earlier bad post slug introduced in 1.1.6
|
93 |
+
|
94 |
+
= 1.1.6 =
|
95 |
+
* compatible with mqtranslate
|
96 |
+
* php5.4+ compatible
|
97 |
+
|
98 |
+
= 1.1.5 =
|
99 |
+
* bugfixes
|
100 |
+
|
101 |
+
= 1.1 =
|
102 |
+
* added multisite support
|
103 |
+
* fixed some parse url bugs
|
104 |
+
* fixed slug bases validation
|
105 |
+
|
106 |
+
= 1.0 =
|
107 |
+
* **works** with any permalink combination and qtranslate mode.
|
108 |
+
* 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).
|
109 |
+
* 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.
|
110 |
+
* the plugin generates translated slug automatically from title in empty cases.
|
111 |
+
* 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.
|
112 |
+
* 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.
|
113 |
+
* added some filters, see in [other notes](http://wordpress.org/extend/plugins/qtranslate-slug/other_notes/).
|
114 |
+
* added plugin language textdomain (.pot file).
|
115 |
+
* updated **Language selector Widget**, and some new conventions like accessible functions for templating.
|
116 |
+
* some bug fixes.
|
117 |
+
* some Qtranslate patches.
|
118 |
+
|
119 |
+
= 0.9 =
|
120 |
+
* some wordpress qTranslate bug fixes
|
121 |
+
* adds a javascript solution for qTranslate Nav Menus
|
122 |
+
|
123 |
+
= 0.8 =
|
124 |
+
* added support por Categories
|
125 |
+
* added support por Tags
|
126 |
+
* added support por Taxonomies
|
127 |
+
* added support por Custom Post Types
|
128 |
+
|
129 |
+
= 0.7 = [Zapo](http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=4&t=1049&start=50#p7499)
|
130 |
+
* added suport for qTranslate TLD domain mode (en: domain.com | fr: domain.fr) visit
|
131 |
+
|
132 |
+
= 0.5 and 0.6 enhanched by Marco Del Percio =
|
133 |
+
|
134 |
+
== Upgrade Notice ==
|
135 |
+
|
136 |
+
= 1.0 =
|
137 |
+
Major version, the plugin has been rewritten. Better performance, and some enhancements.
|
138 |
+
|
139 |
+
= 0.9 =
|
140 |
+
This version fix some bugs and allow multilanguage in nav-menus.
|
141 |
+
|
142 |
+
= 0.8 =
|
143 |
+
A lot of slugs content allowed
|
144 |
+
|
145 |
+
= 0.7 =
|
146 |
+
This version allows TLD domain option for a different Qtranslate fork maded by Zappo
|
147 |
+
|
148 |
+
|
149 |
+
== Other notes ==
|
150 |
+
|
151 |
+
Plugin filters reference:
|
152 |
+
|
153 |
+
= qts_validate_post_slug =
|
154 |
+
filter to process the post slug before is saved on the database.
|
155 |
+
`args: $post (object), $slug (string), $lang (string)`
|
156 |
+
|
157 |
+
= qts_validate_term_slug =
|
158 |
+
filter to process the term slug before is saved on the database.
|
159 |
+
`args: $term (object), $slug (string), $lang (string)`
|
160 |
+
|
161 |
+
= qts_url_args =
|
162 |
+
filter to process the entire url after it has been generated.
|
163 |
+
`args: $url (string), $lang (string)`
|
164 |
+
|
165 |
+
= qts_permastruct =
|
166 |
+
filter to process the permastruct, used for change the base.
|
167 |
+
`args: $permastruct (string), $name (string)`
|
168 |
+
|
169 |
+
|
170 |
+
= Todo =
|
171 |
+
|
172 |
+
* detect Slug for each language and redirect accordingly in parse_query.
|
173 |
+
* expand qtranslate for translate attachment names and descriptions ( useful for galleries )
|
174 |
+
* translate other slugs like attachments.
|
175 |
+
* qtranslate integration with other plugins like Jigoshop, e-commerce, etc. Addapt **$wp_rewrite**.
|
trunk/assets/css/qts-default.css
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.qts_type_image .qts_lang_item {
|
2 |
+
float: left;
|
3 |
+
margin-right: 7px;
|
4 |
+
}
|
5 |
+
.qts_type_image .qts_lang_item.last-child {
|
6 |
+
margin-right: 0;
|
7 |
+
}
|
8 |
+
.qts_lang_item{
|
9 |
+
margin-top: 7px;
|
10 |
+
margin-bottom: 7px;
|
11 |
+
}
|
12 |
+
.qts_both {
|
13 |
+
white-space: nowrap;
|
14 |
+
line-height:1em;
|
15 |
+
}
|
16 |
+
.qts_both img { margin-right: 4px }
|
trunk/assets/css/qts-default.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.qts_type_image .qts_lang_item{float:left;margin-right:7px}.qts_type_image .qts_lang_item.last-child{margin-right:0}.qts_lang_item{margin-top:7px;margin-bottom:7px}.qts_both{white-space:nowrap;line-height:1em}.qts_both img{margin-right:4px}
|
trunk/assets/css/qts-settings.css
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*messages*/
|
2 |
+
.error {color:#cc0000;}
|
3 |
+
|
4 |
+
.form-table th {
|
5 |
+
width: 15%;
|
6 |
+
min-width: 15% !important;
|
7 |
+
}
|
8 |
+
|
9 |
+
.form-table td > span {
|
10 |
+
display: inline-block;
|
11 |
+
min-width: 100px;
|
12 |
+
}
|
13 |
+
|
14 |
+
.form-table label {
|
15 |
+
display: block;
|
16 |
+
margin-bottom: 8px;
|
17 |
+
}
|
18 |
+
|
19 |
+
.qts-slug {
|
20 |
+
width: 35%;
|
21 |
+
}
|
22 |
+
|
23 |
+
#qts-loading {
|
24 |
+
display: none;
|
25 |
+
position: relative;
|
26 |
+
margin-left: 5px;
|
27 |
+
vertical-align: middle;
|
28 |
+
}
|
29 |
+
|
30 |
+
div.updated.success{
|
31 |
+
border-color: #298e00;
|
32 |
+
background-color: #D4EDC9;
|
33 |
+
}
|
34 |
+
|
35 |
+
.error a.button-primary {
|
36 |
+
color: white !important;
|
37 |
+
text-decoration: none !important;
|
38 |
+
}
|
39 |
+
|
40 |
+
.ko {
|
41 |
+
color: #c00;
|
42 |
+
}
|
trunk/assets/js/qts-nav-menu-min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
jQuery(document).ready(function(t){function e(){regexp=new RegExp("<!--:"+u+"-->(.*?)<!--:-->","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()}});
|
trunk/assets/js/qts-nav-menu.js
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
36 |
+
// Change titles (and values) when new menu is added:
|
37 |
+
$('.submit-add-to-menu').click( function() {
|
38 |
+
lang = $('#qt-languages :radio:checked').val();
|
39 |
+
changeTitles();
|
40 |
+
});
|
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('<!--:' + lang + '-->(.*?)<!--:-->', '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:
|
90 |
+
$('.menu-save').click(function() {
|
91 |
+
restoreValues();
|
92 |
+
});
|
93 |
+
|
94 |
+
// Just before leaving the page (or refresh) restore the original input values:
|
95 |
+
window.onbeforeunload = function(){
|
96 |
+
restoreValues();
|
97 |
+
return;
|
98 |
+
};
|
99 |
+
|
100 |
+
});
|
trunk/assets/js/qts-settings-upgrade.js
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery(document).ready(function($) {
|
2 |
+
|
3 |
+
function _debug(msg) {
|
4 |
+
if(window.console) {
|
5 |
+
console.debug(msg);
|
6 |
+
}
|
7 |
+
}
|
8 |
+
var upgrade_box = $('#qts-upgrade-box'),
|
9 |
+
upgrade_form = $('#qts-upgrade-form'),
|
10 |
+
upgrade_button = $('#qts-upgrade-button'),
|
11 |
+
notice_status = function(_status) {
|
12 |
+
upgrade_box.removeClass().addClass(_status);
|
13 |
+
},
|
14 |
+
block_form = function(_block) {
|
15 |
+
if (_block) {
|
16 |
+
$('#qts-loading').show();
|
17 |
+
upgrade_button.attr('disabled', true);
|
18 |
+
} else {
|
19 |
+
$('#qts-loading').hide();
|
20 |
+
upgrade_button.attr('disabled', false);
|
21 |
+
}
|
22 |
+
|
23 |
+
},
|
24 |
+
check_types = function(_response) {
|
25 |
+
|
26 |
+
block_form(false);
|
27 |
+
upgrade_form.find('.message').remove();
|
28 |
+
|
29 |
+
switch (_response.status) {
|
30 |
+
default:
|
31 |
+
case 0:
|
32 |
+
upgrade_form.prepend('<p class=\'message ko\'>'+_response.message+'</p>');
|
33 |
+
break;
|
34 |
+
case 1:
|
35 |
+
notice_status('updated success');
|
36 |
+
upgrade_form.remove();
|
37 |
+
upgrade_box.append('<p><strong>'+_response.message+'</strong></p>');
|
38 |
+
upgrade_box.delay(2500).fadeTo(1300, 0, function(){ upgrade_box.remove(); });
|
39 |
+
break;
|
40 |
+
case 2:
|
41 |
+
var data_ = '<p class=\'message\'>'+_response.message+'</p>';
|
42 |
+
data_ += '<select id=\'qts-slug-type\' class=\'message\'>';
|
43 |
+
|
44 |
+
for (opt in _response.options)
|
45 |
+
data_ += '<option value=\''+opt+'\'>'+_response.options[opt]+'</option>';
|
46 |
+
data_ += '</select>';
|
47 |
+
|
48 |
+
upgrade_form.prepend(data_);
|
49 |
+
|
50 |
+
break;
|
51 |
+
}
|
52 |
+
},
|
53 |
+
start_upgrade = function(_event) {
|
54 |
+
_event.preventDefault();
|
55 |
+
|
56 |
+
notice_status('updated');
|
57 |
+
block_form(true);
|
58 |
+
|
59 |
+
var package_ = {};
|
60 |
+
package_.action = $('#qts-upgrade-action').val();
|
61 |
+
package_.nonce = $('#qts-upgrade-nonce').val();
|
62 |
+
if ( $('#qts-slug-type').length )
|
63 |
+
package_.type = $('#qts-slug-type').val();
|
64 |
+
|
65 |
+
$.post(ajaxurl, package_, check_types);
|
66 |
+
};
|
67 |
+
|
68 |
+
upgrade_button.bind('click', start_upgrade);
|
69 |
+
});
|
trunk/assets/js/qts-settings.js
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*############### Error messages ######################*/
|
2 |
+
jQuery(function(){
|
3 |
+
|
4 |
+
var error_msg = jQuery("#message p[class='setting-error-message']");
|
5 |
+
// look for admin messages with the "setting-error-message" error class
|
6 |
+
if (error_msg.length != 0) {
|
7 |
+
// get the title
|
8 |
+
var error_setting = error_msg.attr('title');
|
9 |
+
|
10 |
+
// look for the label with the "for" attribute=setting title and give it an "error" class (style this in the css file!)
|
11 |
+
jQuery("label[for='" + error_setting + "']").addClass('error');
|
12 |
+
|
13 |
+
// look for the input with id=setting title and add a red border to it.
|
14 |
+
jQuery("input[id='" + error_setting + "']").attr('style', 'border-color: red');
|
15 |
+
}
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
});
|
trunk/includes/class-qtranslate-slug-widget.php
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* QtranslateSlug_Widget class
|
5 |
+
*
|
6 |
+
* @since 1.0
|
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.','qtranslate') );
|
12 |
+
$this->WP_Widget('qtranslateslug', __('Language selector', 'qts'), $widget_ops);
|
13 |
+
}
|
14 |
+
|
15 |
+
function widget($args, $instance) {
|
16 |
+
extract($args);
|
17 |
+
|
18 |
+
echo $before_widget;
|
19 |
+
$title = empty($instance['title']) ? __('Language', 'qtranslate') : apply_filters('widget_title', $instance['title']);
|
20 |
+
$hide_title = empty($instance['hide-title']) ? false : 'on';
|
21 |
+
$type = $instance['type'];
|
22 |
+
$short_text = ($instance['short_text'] == 'on') ? true : false ;
|
23 |
+
|
24 |
+
if( $type!='text' && $type!='image' && $type!='both' && $type!='dropdown' ) $type='text';
|
25 |
+
|
26 |
+
if( $hide_title!='on')
|
27 |
+
echo $before_title . $title . $after_title;
|
28 |
+
|
29 |
+
qts_language_menu($type, array( 'id' => $this->id, 'short' => $short_text ) );
|
30 |
+
|
31 |
+
echo $after_widget;
|
32 |
+
}
|
33 |
+
|
34 |
+
function update($new_instance, $old_instance) {
|
35 |
+
$instance = $old_instance;
|
36 |
+
$instance['title'] = $new_instance['title'];
|
37 |
+
$instance['hide-title'] = $new_instance['hide-title'];
|
38 |
+
$instance['type'] = $new_instance['type'];
|
39 |
+
$instance['short_text'] = $new_instance['short_text'];
|
40 |
+
|
41 |
+
return $instance;
|
42 |
+
}
|
43 |
+
|
44 |
+
function form($instance) {
|
45 |
+
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'hide-title' => false, 'type' => 'text' ) );
|
46 |
+
$title = $instance['title'];
|
47 |
+
$hide_title = $instance['hide-title'];
|
48 |
+
$type = $instance['type'];
|
49 |
+
$short_text = $instance['short_text'];
|
50 |
+
?>
|
51 |
+
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'qtranslate'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
|
52 |
+
<p><label for="<?php echo $this->get_field_id('hide-title'); ?>"><?php _e('Hide Title:', 'qtranslate'); ?> <input type="checkbox" id="<?php echo $this->get_field_id('hide-title'); ?>" name="<?php echo $this->get_field_name('hide-title'); ?>" <?php echo ($hide_title=='on')?'checked="checked"':''; ?>/></label></p>
|
53 |
+
<p><?php _e('Display:', 'qtranslate'); ?></p>
|
54 |
+
<p><label for="<?php echo $this->get_field_id('type'); ?>1"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>1" value="text"<?php echo ($type=='text')?' checked="checked"':'' ?>/> <?php _e('Text only', 'qtranslate'); ?></label></p>
|
55 |
+
<p><label for="<?php echo $this->get_field_id('type'); ?>2"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>2" value="image"<?php echo ($type=='image')?' checked="checked"':'' ?>/> <?php _e('Image only', 'qtranslate'); ?></label></p>
|
56 |
+
<p><label for="<?php echo $this->get_field_id('type'); ?>3"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>3" value="both"<?php echo ($type=='both')?' checked="checked"':'' ?>/> <?php _e('Text and Image', 'qtranslate'); ?></label></p>
|
57 |
+
<p><label for="<?php echo $this->get_field_id('type'); ?>4"><input type="radio" name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>4" value="dropdown"<?php echo ($type=='dropdown')?' checked="checked"':'' ?>/> <?php _e('Dropdown Box', 'qtranslate'); ?></label></p>
|
58 |
+
<p><label for="<?php echo $this->get_field_id('short_text'); ?>"><?php _e('Show short name (en):', 'qts'); ?> <input type="checkbox" id="<?php echo $this->get_field_id('short_text'); ?>" name="<?php echo $this->get_field_name('short_text'); ?>" <?php checked($short_text, 'on') ?>/></label></p>
|
59 |
+
<p><?php _e('Display:', 'qtranslate'); ?></p>
|
60 |
+
|
61 |
+
<?php
|
62 |
+
}
|
63 |
+
}
|
trunk/includes/class-qtranslate-slug.php
ADDED
@@ -0,0 +1,2378 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
class QtranslateSlug {
|
9 |
+
|
10 |
+
|
11 |
+
/**
|
12 |
+
* array with old data system
|
13 |
+
*
|
14 |
+
* @var bool
|
15 |
+
*
|
16 |
+
* @since 1.0
|
17 |
+
*/
|
18 |
+
private $old_data = null;
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
/**
|
23 |
+
* stores permalink_structure option, for save queries to db
|
24 |
+
*
|
25 |
+
* @var string
|
26 |
+
*
|
27 |
+
* @since 1.0
|
28 |
+
*/
|
29 |
+
private $permalink_structure;
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Stores options slugs from database
|
35 |
+
*
|
36 |
+
* @var array
|
37 |
+
*
|
38 |
+
* @since 1.0
|
39 |
+
*/
|
40 |
+
protected $options;
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Variable used to override the language
|
46 |
+
*
|
47 |
+
* @var string
|
48 |
+
*
|
49 |
+
* @since 1.0
|
50 |
+
*/
|
51 |
+
private $lang = false;
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
/**
|
56 |
+
* slug in meta_key name in meta tables
|
57 |
+
*
|
58 |
+
* @var string
|
59 |
+
*
|
60 |
+
* @since 1.0
|
61 |
+
*/
|
62 |
+
private $meta_key = "_qts_slug_%s";
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Array of translated versions of the current url
|
68 |
+
*
|
69 |
+
* @var array
|
70 |
+
*
|
71 |
+
* @since 1.0
|
72 |
+
*/
|
73 |
+
private $current_url = array();
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
/**
|
78 |
+
* return the current / temp language
|
79 |
+
*
|
80 |
+
* @since 1.0
|
81 |
+
*/
|
82 |
+
private function get_lang() {
|
83 |
+
global $q_config;
|
84 |
+
|
85 |
+
return ($this->lang) ? $this->lang : $q_config['language'];
|
86 |
+
}
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
+
/**
|
91 |
+
* getter: options
|
92 |
+
*
|
93 |
+
* @since 1.0
|
94 |
+
*/
|
95 |
+
public function get_options() {
|
96 |
+
$this->set_options();
|
97 |
+
return $this->options;
|
98 |
+
}
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
/**
|
103 |
+
* setter: options | permalink_structure
|
104 |
+
*
|
105 |
+
* @since 1.0
|
106 |
+
*/
|
107 |
+
public function set_options() {
|
108 |
+
|
109 |
+
if (empty($this->options)) {
|
110 |
+
$this->options = get_option(QTS_OPTIONS_NAME);
|
111 |
+
}
|
112 |
+
|
113 |
+
if (!$this->options) {
|
114 |
+
add_option(QTS_OPTIONS_NAME, array());
|
115 |
+
}
|
116 |
+
|
117 |
+
if (is_null($this->permalink_structure)) {
|
118 |
+
$this->permalink_structure = get_option('permalink_structure');
|
119 |
+
}
|
120 |
+
}
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
+
/**
|
125 |
+
* setter: options | permalink_structure
|
126 |
+
*
|
127 |
+
* @since 1.0
|
128 |
+
*/
|
129 |
+
public function save_options($new_options = false) {
|
130 |
+
if (!$new_options || empty($new_options)) {
|
131 |
+
return;
|
132 |
+
}
|
133 |
+
|
134 |
+
if (count($this->options) != count($new_options)) {
|
135 |
+
return;
|
136 |
+
}
|
137 |
+
|
138 |
+
update_option(QTS_OPTIONS_NAME, $new_options);
|
139 |
+
$this->options = $new_options;
|
140 |
+
}
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
/**
|
145 |
+
* getter: meta key
|
146 |
+
*
|
147 |
+
* @since 1.0
|
148 |
+
*/
|
149 |
+
public function get_meta_key( $force_lang = false ) {
|
150 |
+
global $q_config;
|
151 |
+
|
152 |
+
$lang = $this->get_lang();
|
153 |
+
|
154 |
+
if ($force_lang) {
|
155 |
+
$lang = $force_lang;
|
156 |
+
}
|
157 |
+
|
158 |
+
return sprintf($this->meta_key, $lang); // returns: _qts_slug_en
|
159 |
+
}
|
160 |
+
|
161 |
+
|
162 |
+
|
163 |
+
/**
|
164 |
+
* check dependences for activation
|
165 |
+
*
|
166 |
+
* @since 1.0
|
167 |
+
*/
|
168 |
+
static function block_activate() {
|
169 |
+
global $wp_version;
|
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
|
180 |
+
*
|
181 |
+
* @since 1.0
|
182 |
+
*/
|
183 |
+
public function install() {
|
184 |
+
global $wpdb;
|
185 |
+
|
186 |
+
if ( self::block_activate() ) {
|
187 |
+
return;
|
188 |
+
}
|
189 |
+
|
190 |
+
if ( function_exists('is_multisite') && is_multisite() ) {
|
191 |
+
|
192 |
+
if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) {
|
193 |
+
|
194 |
+
$old_blog = $wpdb->blogid;
|
195 |
+
$blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs"));
|
196 |
+
foreach ($blogids as $blog_id) {
|
197 |
+
switch_to_blog($blog_id);
|
198 |
+
$this->activate();
|
199 |
+
}
|
200 |
+
switch_to_blog($old_blog);
|
201 |
+
return;
|
202 |
+
}
|
203 |
+
}
|
204 |
+
|
205 |
+
$this->activate();
|
206 |
+
}
|
207 |
+
|
208 |
+
|
209 |
+
|
210 |
+
/**
|
211 |
+
* activates and do the installation
|
212 |
+
*
|
213 |
+
* @since 1.0
|
214 |
+
*/
|
215 |
+
private function activate() {
|
216 |
+
global $wp_rewrite;
|
217 |
+
|
218 |
+
$this->set_options();
|
219 |
+
|
220 |
+
$qts_version = get_option('qts_version');
|
221 |
+
|
222 |
+
// checks version and do the installation
|
223 |
+
if ( !$qts_version || $qts_version != QTS_VERSION ) {
|
224 |
+
|
225 |
+
// install termmeta table using functions from Simple-Term-Meta
|
226 |
+
// ( http://wordpress.org/extend/plugins/simple-term-meta/ )
|
227 |
+
install_term_meta_table();
|
228 |
+
|
229 |
+
// update installed option
|
230 |
+
update_option('qts_version', QTS_VERSION);
|
231 |
+
}
|
232 |
+
|
233 |
+
// regenerate rewrite rules in db
|
234 |
+
add_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
|
235 |
+
flush_rewrite_rules();
|
236 |
+
}
|
237 |
+
|
238 |
+
|
239 |
+
|
240 |
+
/**
|
241 |
+
* register front end styles and enqueue
|
242 |
+
*
|
243 |
+
* @since 1.1.7
|
244 |
+
*/
|
245 |
+
public function register_plugin_styles() {
|
246 |
+
wp_register_style( 'qts_front_styles', plugins_url( '/assets/css/qts-default.css', dirname(__FILE__ ) ) );
|
247 |
+
wp_enqueue_style( 'qts_front_styles' );
|
248 |
+
}
|
249 |
+
/**
|
250 |
+
* register minified front end styles and enqueue
|
251 |
+
* 43LC: easier duplicating the function :|
|
252 |
+
* @since 1.1.8
|
253 |
+
*/
|
254 |
+
public function register_plugin_styles_min() {
|
255 |
+
wp_register_style( 'qts_front_styles', plugins_url( '/assets/css/qts-default.min.css', dirname(__FILE__ ) ) );
|
256 |
+
wp_enqueue_style( 'qts_front_styles' );
|
257 |
+
}
|
258 |
+
|
259 |
+
|
260 |
+
|
261 |
+
/**
|
262 |
+
* print front end styles
|
263 |
+
*
|
264 |
+
* @since 1.1.7
|
265 |
+
*/
|
266 |
+
public function print_plugin_styles() {
|
267 |
+
|
268 |
+
$css_path = dirname(__FILE__).'/assets/css/qts-default.css';
|
269 |
+
|
270 |
+
if (!file_exists($css_path) || !is_readable($css_path)) {
|
271 |
+
return;
|
272 |
+
}
|
273 |
+
|
274 |
+
$default_css_file = file_get_contents($css_path, FILE_USE_INCLUDE_PATH);
|
275 |
+
|
276 |
+
$css = "<style media=\"screen\">\n";
|
277 |
+
$css .= "$default_css_file\n";
|
278 |
+
$css .="</style>\n";
|
279 |
+
echo $css;
|
280 |
+
}
|
281 |
+
|
282 |
+
|
283 |
+
|
284 |
+
/**
|
285 |
+
* actions when deactivating the plugin
|
286 |
+
*
|
287 |
+
* @since 1.0
|
288 |
+
*/
|
289 |
+
public function deactivate() {
|
290 |
+
global $wp_rewrite;
|
291 |
+
|
292 |
+
// regenerate rewrite rules in db
|
293 |
+
remove_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
|
294 |
+
$wp_rewrite->flush_rules();
|
295 |
+
}
|
296 |
+
|
297 |
+
|
298 |
+
|
299 |
+
/**
|
300 |
+
* admin notice: update your old data
|
301 |
+
*
|
302 |
+
* @since 1.0
|
303 |
+
*/
|
304 |
+
function notice_update(){
|
305 |
+
global $current_screen;
|
306 |
+
|
307 |
+
if ($current_screen->id != 'settings_page_qtranslate-slug-settings') {
|
308 |
+
|
309 |
+
echo "<div class=\"updated\">" . PHP_EOL;
|
310 |
+
echo "<p><strong>Qtranslate Slug:</strong></p>" . PHP_EOL;
|
311 |
+
printf("<p>%s <a href=\"%s\" class=\"button\">%s</a></p>", __('Please update your old data to the new system.', 'qts'), add_query_arg(array('page' => 'qtranslate-slug-settings'), 'options-general.php'), __('upgrade now', 'qts')) . PHP_EOL;
|
312 |
+
echo "</div>" . PHP_EOL;
|
313 |
+
}
|
314 |
+
}
|
315 |
+
|
316 |
+
|
317 |
+
|
318 |
+
/**
|
319 |
+
* admin notice: update your old data
|
320 |
+
*
|
321 |
+
* @since 1.0
|
322 |
+
*/
|
323 |
+
function notice_dependences(){
|
324 |
+
global $current_screen;
|
325 |
+
|
326 |
+
echo "<div class=\"error\">" . PHP_EOL;
|
327 |
+
echo "<p><strong>Qtranslate Slug:</strong></p>" . PHP_EOL;
|
328 |
+
echo "<p>" . __('This plugin requires at least <strong>WordPress 3.3</strong> and either <strong>mqTranslate 2.6.2.4 (or newer)</strong> or <strong>qTranslate 2.5.8 (or newer)</strong>', 'qts') . "</p>" . PHP_EOL;
|
329 |
+
echo "</div>" . PHP_EOL;
|
330 |
+
}
|
331 |
+
|
332 |
+
|
333 |
+
|
334 |
+
/**
|
335 |
+
* checks if old table 'qtranslate_slug' exists and is not empty
|
336 |
+
*
|
337 |
+
* @return object | false
|
338 |
+
*
|
339 |
+
* @since 1.0
|
340 |
+
*/
|
341 |
+
public function check_old_data() {
|
342 |
+
global $wpdb;
|
343 |
+
|
344 |
+
if ($this->old_data === false) {
|
345 |
+
return false;
|
346 |
+
}
|
347 |
+
|
348 |
+
$table_name = $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}qtranslate_slug'");
|
349 |
+
|
350 |
+
if (!empty($table_name)) {
|
351 |
+
$this->old_data = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}qtranslate_slug");
|
352 |
+
}
|
353 |
+
|
354 |
+
if ( empty($table_name) || empty($this->old_data) ) {
|
355 |
+
$this->old_data = false;
|
356 |
+
}
|
357 |
+
|
358 |
+
return $this->old_data;
|
359 |
+
}
|
360 |
+
|
361 |
+
|
362 |
+
|
363 |
+
/**
|
364 |
+
* actions when deactivating the plugin
|
365 |
+
*
|
366 |
+
* @since 1.0
|
367 |
+
*/
|
368 |
+
private function check_old_versions() {
|
369 |
+
|
370 |
+
if ( $this->check_old_data() ) {
|
371 |
+
add_action('admin_notices', array(&$this, 'notice_update'));
|
372 |
+
}
|
373 |
+
}
|
374 |
+
|
375 |
+
|
376 |
+
|
377 |
+
/**
|
378 |
+
* Initialise the Class with all hooks
|
379 |
+
*
|
380 |
+
* @since 1.0
|
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() ) {
|
388 |
+
if (is_admin()) {
|
389 |
+
add_action('admin_notices', array(&$this, 'notice_dependences'));
|
390 |
+
}
|
391 |
+
return;
|
392 |
+
}
|
393 |
+
|
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 );
|
403 |
+
add_filter( 'qts_validate_post_slug', array(&$this, 'unique_post_slug'), 1, 3 );
|
404 |
+
add_filter( 'qts_validate_term_slug', array(&$this, 'validate_term_slug'), 0, 3 );
|
405 |
+
add_filter( 'qts_validate_term_slug', array(&$this, 'unique_term_slug'), 1, 3 );
|
406 |
+
add_filter( 'wp_get_object_terms', array(&$this, 'get_object_terms'), 0, 4 );
|
407 |
+
add_filter( 'get_terms', array(&$this, 'get_terms'), 0, 3 );
|
408 |
+
|
409 |
+
// admin actions
|
410 |
+
add_action( 'admin_menu', array(&$this, 'add_slug_meta_box') );
|
411 |
+
add_action( 'save_post', array(&$this, 'save_postdata'), 605, 2 );
|
412 |
+
add_action( 'delete_term', array(&$this, 'delete_term'), 0, 3);
|
413 |
+
add_action( 'created_term', array(&$this, 'save_term'), 605, 3);
|
414 |
+
add_action( 'edited_term', array(&$this, 'save_term'), 605, 3 );
|
415 |
+
add_action( 'admin_head', array(&$this, 'hide_slug_box'), 900 );
|
416 |
+
|
417 |
+
add_action( 'init', array(&$this, 'taxonomies_hooks'), 805 );
|
418 |
+
|
419 |
+
add_action( 'wp_dashboard_setup', array(&$this, 'remove_dashboard_widgets') );
|
420 |
+
add_action( 'admin_head', array(&$this, 'hide_quick_edit'), 600 );
|
421 |
+
add_action( 'admin_init', array(&$this, 'fix_nav_menu') );
|
422 |
+
|
423 |
+
} else {
|
424 |
+
|
425 |
+
add_filter( 'request', array(&$this, 'filter_request') );
|
426 |
+
|
427 |
+
// adds external style file
|
428 |
+
$qts_options = $this->get_options();
|
429 |
+
if ( !isset($qts_options[QTS_PREFIX.'styles']) || $qts_options[QTS_PREFIX.'styles'] == "file" ) {
|
430 |
+
add_action( 'wp_enqueue_scripts', array( &$this, 'register_plugin_styles' ) );
|
431 |
+
} elseif ($qts_options[QTS_PREFIX.'styles'] == "minified" ) {
|
432 |
+
add_action( 'wp_enqueue_scripts', array( &$this, 'register_plugin_styles_min' ) );
|
433 |
+
} elseif ($qts_options[QTS_PREFIX.'styles'] == "inline" ) {
|
434 |
+
add_action( 'wp_print_styles', array( &$this, 'print_plugin_styles' ), 20 );
|
435 |
+
}
|
436 |
+
}
|
437 |
+
|
438 |
+
add_filter( 'query_vars', array(&$this, 'query_vars'));
|
439 |
+
add_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
|
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);
|
455 |
+
add_filter( 'home_url', array(&$this, 'home_url'), 10, 4);
|
456 |
+
add_filter( 'post_type_link', array(&$this, 'post_type_link'), 600, 4 );
|
457 |
+
add_filter( 'post_link', array(&$this, 'post_link'), 0, 3 );
|
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.
|
471 |
+
* Fixes issue #25
|
472 |
+
*
|
473 |
+
* @global $qtranslate_slug used to convert the url
|
474 |
+
* @global $q_config available languages
|
475 |
+
*
|
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 |
+
|
489 |
+
|
490 |
+
/**
|
491 |
+
* Add a class based on the current language
|
492 |
+
* @param array $classes list of classes
|
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'
|
505 |
+
*
|
506 |
+
* @param object $wp_rewrite
|
507 |
+
*
|
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');
|
515 |
+
foreach ( $post_types as $post_type ) {
|
516 |
+
$this->generate_extra_rules( $post_type->name );
|
517 |
+
}
|
518 |
+
|
519 |
+
// taxonomies rules
|
520 |
+
$taxonomies = $this->get_public_taxonomies();
|
521 |
+
foreach ( $taxonomies as $taxonomy ) {
|
522 |
+
$this->generate_extra_rules( $taxonomy->name );
|
523 |
+
}
|
524 |
+
}
|
525 |
+
|
526 |
+
|
527 |
+
|
528 |
+
/**
|
529 |
+
* Helper: news rules to translate the URL bases
|
530 |
+
*
|
531 |
+
* @param string $name name of extra permastruct
|
532 |
+
* @param string $type 'post_type' or 'taxonomy'
|
533 |
+
*
|
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 |
+
|
543 |
+
$struct = $wp_rewrite->extra_permastructs[$name];
|
544 |
+
|
545 |
+
if ( is_array( $struct ) ) {
|
546 |
+
if ( count( $struct ) == 2 )
|
547 |
+
$rules = $wp_rewrite->generate_rewrite_rules( "/$base/%$name%", $struct[1] );
|
548 |
+
else
|
549 |
+
$rules = $wp_rewrite->generate_rewrite_rules( "/$base/%$name%", $struct['ep_mask'], $struct['paged'], $struct['feed'], $struct['forcomments'], $struct['walk_dirs'], $struct['endpoints'] );
|
550 |
+
} else {
|
551 |
+
$rules = $wp_rewrite->generate_rewrite_rules( "/$base/%$name%" );
|
552 |
+
}
|
553 |
+
|
554 |
+
$wp_rewrite->rules = array_merge($rules, $wp_rewrite->rules);
|
555 |
+
|
556 |
+
endif;
|
557 |
+
|
558 |
+
endforeach;
|
559 |
+
}
|
560 |
+
|
561 |
+
|
562 |
+
|
563 |
+
/**
|
564 |
+
* Helper that gets a base slug stored in options
|
565 |
+
*
|
566 |
+
* @param string $name of extra permastruct
|
567 |
+
* @return string base slug for 'post_type' and 'language' or false
|
568 |
+
*
|
569 |
+
* @since 1.0
|
570 |
+
*/
|
571 |
+
public function get_base_slug($name = false, $lang = false) {
|
572 |
+
|
573 |
+
if ( !$name || !$lang ) {
|
574 |
+
return false;
|
575 |
+
}
|
576 |
+
|
577 |
+
if ( taxonomy_exists($name) ) {
|
578 |
+
$type = 'taxonomy';
|
579 |
+
} else if ( post_type_exists($name) ) {
|
580 |
+
$type = 'post_type';
|
581 |
+
} else {
|
582 |
+
return false;
|
583 |
+
}
|
584 |
+
|
585 |
+
$qts_options = $this->get_options();
|
586 |
+
|
587 |
+
$option_name = QTS_PREFIX . $type . '_' . $name;
|
588 |
+
|
589 |
+
if ( !isset($qts_options[$option_name]) || empty($qts_options[$option_name]) ) {
|
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;
|
600 |
+
}
|
601 |
+
|
602 |
+
|
603 |
+
|
604 |
+
/**
|
605 |
+
* Helper: returns public built-in and not built-in taxonomies
|
606 |
+
*
|
607 |
+
* @return array of public taxonomies objects
|
608 |
+
*
|
609 |
+
* @since 1.0
|
610 |
+
*/
|
611 |
+
private function get_public_taxonomies() {
|
612 |
+
|
613 |
+
$builtin = get_taxonomies( array( 'public' => true, 'show_ui' => true, '_builtin' => true ), 'object');
|
614 |
+
$taxonomies = get_taxonomies( array( 'public' => true, 'show_ui' => true, '_builtin' => false ), 'object' );
|
615 |
+
|
616 |
+
return array_merge( $builtin, $taxonomies );
|
617 |
+
}
|
618 |
+
|
619 |
+
|
620 |
+
|
621 |
+
/**
|
622 |
+
* parse and adds $_GET args passed to an url
|
623 |
+
*
|
624 |
+
* @param string $url parameters
|
625 |
+
* @param string $lang processed
|
626 |
+
* @return string converted url
|
627 |
+
*
|
628 |
+
* @since 1.0
|
629 |
+
*/
|
630 |
+
public function parse_url_args( $url ) {
|
631 |
+
global $q_config;
|
632 |
+
|
633 |
+
if (is_admin()) {
|
634 |
+
return $url;
|
635 |
+
}
|
636 |
+
|
637 |
+
$url = preg_replace('/&/', '&', $url);
|
638 |
+
|
639 |
+
// if no permalink structure ads ?lang=en
|
640 |
+
$base_query = parse_url($q_config['url_info']['original_url']);
|
641 |
+
$base_args = isset($base_query['query']) ? wp_parse_args($base_query['query']) : array();
|
642 |
+
|
643 |
+
if ( empty($this->permalink_structure) || $q_config['url_mode'] == 1 ) {
|
644 |
+
$base_args['lang'] = $this->get_lang();
|
645 |
+
}
|
646 |
+
|
647 |
+
// rebuild query with all args
|
648 |
+
$url = add_query_arg($base_args, $url);
|
649 |
+
|
650 |
+
$url = str_replace('/?', '?', $url); // TODO: hack: improve this code
|
651 |
+
$url = str_replace('?', '/?', $url); // TODO: hack: improve this code
|
652 |
+
|
653 |
+
return $url;
|
654 |
+
}
|
655 |
+
|
656 |
+
|
657 |
+
|
658 |
+
/**
|
659 |
+
* Fix get_page_by_path when querying vars
|
660 |
+
*
|
661 |
+
* @param $query_vars objec query vars founded
|
662 |
+
* @return object $query_vars processed
|
663 |
+
*
|
664 |
+
* @since 1.0
|
665 |
+
*/
|
666 |
+
public function query_vars( $query_vars ) {
|
667 |
+
global $wp, $wp_rewrite;
|
668 |
+
|
669 |
+
$wp->query_vars = array();
|
670 |
+
$post_type_query_vars = array();
|
671 |
+
|
672 |
+
// Fetch the rewrite rules.
|
673 |
+
$rewrite = $wp_rewrite->wp_rewrite_rules();
|
674 |
+
|
675 |
+
if ( ! empty($rewrite) ) {
|
676 |
+
// If we match a rewrite rule, this will be cleared.
|
677 |
+
$error = '404';
|
678 |
+
$wp->did_permalink = true;
|
679 |
+
|
680 |
+
if ( isset($_SERVER['PATH_INFO']) ) {
|
681 |
+
$pathinfo = $_SERVER['PATH_INFO'];
|
682 |
+
} else {
|
683 |
+
$pathinfo = '';
|
684 |
+
}
|
685 |
+
$pathinfo_array = explode('?', $pathinfo);
|
686 |
+
$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
|
687 |
+
$req_uri = $_SERVER['REQUEST_URI'];
|
688 |
+
$req_uri_array = explode('?', $req_uri);
|
689 |
+
$req_uri = $req_uri_array[0];
|
690 |
+
$self = $_SERVER['PHP_SELF'];
|
691 |
+
$home_path = parse_url(home_url());
|
692 |
+
|
693 |
+
if ( isset($home_path['path']) ) {
|
694 |
+
$home_path = $home_path['path'];
|
695 |
+
} else {
|
696 |
+
$home_path = '';
|
697 |
+
}
|
698 |
+
$home_path = trim($home_path, '/');
|
699 |
+
|
700 |
+
// Trim path info from the end and the leading home path from the
|
701 |
+
// front. For path info requests, this leaves us with the requesting
|
702 |
+
// filename, if any. For 404 requests, this leaves us with the
|
703 |
+
// requested permalink.
|
704 |
+
$req_uri = str_replace($pathinfo, '', $req_uri);
|
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, '/');
|
712 |
+
$pathinfo = preg_replace("|^$home_path|", '', $pathinfo);
|
713 |
+
$pathinfo = trim($pathinfo, '/');
|
714 |
+
$self = trim($self, '/');
|
715 |
+
$self = preg_replace("|^$home_path|", '', $self);
|
716 |
+
$self = trim($self, '/');
|
717 |
+
|
718 |
+
// The requested permalink is in $pathinfo for path info requests and
|
719 |
+
// $req_uri for other requests.
|
720 |
+
if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
|
721 |
+
$request = $pathinfo;
|
722 |
+
} else {
|
723 |
+
// If the request uri is the index, blank it out so that
|
724 |
+
// we don't try to match it against a rule.
|
725 |
+
if ( $req_uri == $wp_rewrite->index )
|
726 |
+
$req_uri = '';
|
727 |
+
$request = $req_uri;
|
728 |
+
}
|
729 |
+
|
730 |
+
$wp->request = $request;
|
731 |
+
|
732 |
+
// Look for matches.
|
733 |
+
$request_match = $request;
|
734 |
+
if ( empty( $request_match ) ) {
|
735 |
+
// An empty request could only match against ^$ regex
|
736 |
+
if ( isset( $rewrite['$'] ) ) {
|
737 |
+
$wp->matched_rule = '$';
|
738 |
+
$query = $rewrite['$'];
|
739 |
+
$matches = array('');
|
740 |
+
}
|
741 |
+
} else if ( $req_uri != 'wp-app.php' ) {
|
742 |
+
foreach ( (array) $rewrite as $match => $query ) {
|
743 |
+
// If the requesting file is the anchor of the match, prepend it to the path info.
|
744 |
+
if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request ) {
|
745 |
+
$request_match = $req_uri . '/' . $request;
|
746 |
+
}
|
747 |
+
|
748 |
+
if ( preg_match("#^$match#", $request_match, $matches) || preg_match("#^$match#", urldecode($request_match), $matches) ) {
|
749 |
+
|
750 |
+
if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
|
751 |
+
// this is a verbose page match, lets check to be sure about it
|
752 |
+
if ( ! $page_foundid = $this->get_page_by_path( $matches[ $varmatch[1] ] ) ) {
|
753 |
+
continue;
|
754 |
+
} else {
|
755 |
+
wp_cache_set('qts_page_request', $page_foundid); // caching query :)
|
756 |
+
}
|
757 |
+
}
|
758 |
+
|
759 |
+
// Got a match.
|
760 |
+
$wp->matched_rule = $match;
|
761 |
+
break;
|
762 |
+
}
|
763 |
+
}
|
764 |
+
}
|
765 |
+
|
766 |
+
if ( isset( $wp->matched_rule ) ) {
|
767 |
+
// Trim the query of everything up to the '?'.
|
768 |
+
$query = preg_replace("!^.+\?!", '', $query);
|
769 |
+
|
770 |
+
// Substitute the substring matches into the query.
|
771 |
+
$query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
|
772 |
+
|
773 |
+
$wp->matched_query = $query;
|
774 |
+
|
775 |
+
// Parse the query.
|
776 |
+
parse_str($query, $perma_query_vars);
|
777 |
+
|
778 |
+
// If we're processing a 404 request, clear the error var
|
779 |
+
// since we found something.
|
780 |
+
unset( $_GET['error'] );
|
781 |
+
unset( $error );
|
782 |
+
}
|
783 |
+
|
784 |
+
// If req_uri is empty or if it is a request for ourself, unset error.
|
785 |
+
if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
|
786 |
+
unset( $_GET['error'] );
|
787 |
+
unset( $error );
|
788 |
+
|
789 |
+
if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
|
790 |
+
unset( $perma_query_vars );
|
791 |
+
}
|
792 |
+
|
793 |
+
$wp->did_permalink = false;
|
794 |
+
}
|
795 |
+
}
|
796 |
+
|
797 |
+
return count(array_diff($query_vars, $wp->public_query_vars)) > 0 ? $query_vars : $wp->public_query_vars;
|
798 |
+
}
|
799 |
+
|
800 |
+
|
801 |
+
|
802 |
+
/**
|
803 |
+
* Function called when query parameters are processed by Wordpress.
|
804 |
+
*
|
805 |
+
* @param $query query parameters
|
806 |
+
* @return array() $query processed
|
807 |
+
*
|
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 |
+
}
|
816 |
+
|
817 |
+
foreach (get_post_types() as $post_type) {
|
818 |
+
if ( array_key_exists($post_type, $query) && !in_array($post_type, array('post', 'page')) ) {
|
819 |
+
$query['post_type'] = $post_type;
|
820 |
+
}
|
821 |
+
}
|
822 |
+
|
823 |
+
$page_foundit = false;
|
824 |
+
|
825 |
+
// -> page
|
826 |
+
if ( isset($query['pagename']) || isset($query['page_id']) ):
|
827 |
+
|
828 |
+
$page = wp_cache_get('qts_page_request');
|
829 |
+
if (!$page)
|
830 |
+
$page = isset($query['page_id']) ? get_post($query['page_id']) : $this->get_page_by_path($query['pagename']);
|
831 |
+
|
832 |
+
if (!$page) return $query;
|
833 |
+
$id = $page->ID;
|
834 |
+
$cache_array = array($page);
|
835 |
+
update_post_caches($cache_array, 'page'); // caching query :)
|
836 |
+
wp_cache_delete('qts_page_request');
|
837 |
+
$query['pagename'] = get_page_uri($page);
|
838 |
+
$function = 'get_page_link';
|
839 |
+
|
840 |
+
// -> custom post type
|
841 |
+
elseif ( isset($query['post_type']) ):
|
842 |
+
|
843 |
+
$page_slug = ( isset($query['name']) && !empty($query['name']) ) ? $query['name'] : $query[$query['post_type']];
|
844 |
+
$page = $this->get_page_by_path($page_slug, OBJECT, $query['post_type']);
|
845 |
+
if (!$page) return $query;
|
846 |
+
$id = $page->ID;
|
847 |
+
$cache_array = array($page);
|
848 |
+
update_post_caches($cache_array, $query['post_type']); // caching query :)
|
849 |
+
$query['name'] = $query[$query['post_type']] = get_page_uri($page);
|
850 |
+
$function = 'get_post_permalink';
|
851 |
+
|
852 |
+
// -> post
|
853 |
+
elseif ( isset($query['name']) || isset($query['p']) ):
|
854 |
+
|
855 |
+
$post = isset($query['p']) ? get_post($query['p']) : $this->get_page_by_path($query['name'], OBJECT, 'post');
|
856 |
+
if (!$post) {
|
857 |
+
return $query;
|
858 |
+
}
|
859 |
+
$query['name'] = $post->post_name;
|
860 |
+
$id = $post->ID;
|
861 |
+
$cache_array = array($post);
|
862 |
+
update_post_caches($cache_array);
|
863 |
+
$function = 'get_permalink';
|
864 |
+
|
865 |
+
// -> category
|
866 |
+
elseif ( ( isset($query['category_name']) || isset($query['cat'])) ):
|
867 |
+
if ( isset($query['category_name']) ) {
|
868 |
+
$term_slug = $this->get_last_slash( $query['category_name'] );
|
869 |
+
}
|
870 |
+
$term = isset($query['cat']) ? get_term($query['cat'], 'category') : $this->get_term_by('slug', $term_slug, 'category');
|
871 |
+
if (!$term) {
|
872 |
+
return $query;
|
873 |
+
}
|
874 |
+
$cache_array = array($term);
|
875 |
+
update_term_cache($cache_array, 'category'); // caching query :)
|
876 |
+
$id = $term->term_id;
|
877 |
+
$query['category_name'] = $term->slug; // uri
|
878 |
+
$function = 'get_category_link';
|
879 |
+
|
880 |
+
// -> tag
|
881 |
+
elseif ( isset($query['tag']) ):
|
882 |
+
|
883 |
+
$term = $this->get_term_by('slug', $query['tag'], 'post_tag');
|
884 |
+
if (!$term) {
|
885 |
+
return $query;
|
886 |
+
}
|
887 |
+
$cache_array = array($term);
|
888 |
+
update_term_cache($cache_array, 'post_tag'); // caching query :)
|
889 |
+
$id = $term->term_id;
|
890 |
+
$query['tag'] = $term->slug;
|
891 |
+
$function = 'get_tag_link';
|
892 |
+
|
893 |
+
endif;
|
894 |
+
|
895 |
+
|
896 |
+
// -> taxonomy
|
897 |
+
$taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
|
898 |
+
foreach ($taxonomies as $term_name):
|
899 |
+
if ( isset($query[$term_name]) ) {
|
900 |
+
|
901 |
+
$term_slug = $this->get_last_slash( $query[$term_name] );
|
902 |
+
$term = $this->get_term_by('slug', $term_slug, $term_name);
|
903 |
+
if (!$term) {
|
904 |
+
return $query;
|
905 |
+
}
|
906 |
+
$cache_array = array($term);
|
907 |
+
update_term_cache($cache_array, $term_name); // caching query :)
|
908 |
+
$id = $term;
|
909 |
+
$query[$term_name] = $term->slug;
|
910 |
+
$function = 'get_term_link';
|
911 |
+
|
912 |
+
}
|
913 |
+
endforeach;
|
914 |
+
|
915 |
+
// -> home url
|
916 |
+
if ( empty($query) ) {
|
917 |
+
|
918 |
+
$function = 'home_url';
|
919 |
+
$id = '';
|
920 |
+
|
921 |
+
}
|
922 |
+
|
923 |
+
// -> search
|
924 |
+
if (isset($query['s'])) {
|
925 |
+
|
926 |
+
$id = $query['s'];
|
927 |
+
$function="get_search_link";
|
928 |
+
|
929 |
+
}
|
930 |
+
|
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));
|
938 |
+
}
|
939 |
+
|
940 |
+
$this->lang = false;
|
941 |
+
}
|
942 |
+
|
943 |
+
return $query;
|
944 |
+
}
|
945 |
+
|
946 |
+
|
947 |
+
|
948 |
+
/**
|
949 |
+
* Parse a hierarquical name and extract the last one
|
950 |
+
*
|
951 |
+
* @param string $lang Page path
|
952 |
+
* @return string
|
953 |
+
*
|
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();
|
961 |
+
}
|
962 |
+
|
963 |
+
if (isset($this->current_url[$lang]) && !empty($this->current_url[$lang])) {
|
964 |
+
return $this->current_url[$lang];
|
965 |
+
}
|
966 |
+
|
967 |
+
return '';
|
968 |
+
}
|
969 |
+
|
970 |
+
|
971 |
+
|
972 |
+
/**
|
973 |
+
* Parse a hierarquical name and extract the last one
|
974 |
+
*
|
975 |
+
* @param string $slug Page path
|
976 |
+
* @return string
|
977 |
+
*
|
978 |
+
* @since 1.0
|
979 |
+
*/
|
980 |
+
private function get_last_slash($slug) {
|
981 |
+
|
982 |
+
$slug = rawurlencode( urldecode( $slug ) );
|
983 |
+
$slug = str_replace('%2F', '/', $slug);
|
984 |
+
$slug = str_replace('%20', ' ', $slug);
|
985 |
+
$exploded_slug = explode('/', $slug);
|
986 |
+
|
987 |
+
return array_pop( $exploded_slug );
|
988 |
+
}
|
989 |
+
|
990 |
+
|
991 |
+
|
992 |
+
/**
|
993 |
+
* Retrieves a page id given its path.
|
994 |
+
*
|
995 |
+
* @param string $page_path Page path
|
996 |
+
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
|
997 |
+
* @param string $post_type Optional. Post type. Default page.
|
998 |
+
* @return mixed Null when complete.
|
999 |
+
*
|
1000 |
+
* @since 1.0
|
1001 |
+
*/
|
1002 |
+
private function get_page_id_by_path($page_path, $output = OBJECT, $post_type = 'page') {
|
1003 |
+
global $wpdb;
|
1004 |
+
|
1005 |
+
$page_path = rawurlencode(urldecode($page_path));
|
1006 |
+
$page_path = str_replace('%2F', '/', $page_path);
|
1007 |
+
$page_path = str_replace('%20', ' ', $page_path);
|
1008 |
+
$parts = explode( '/', trim( $page_path, '/' ) );
|
1009 |
+
$parts = array_map( 'esc_sql', $parts );
|
1010 |
+
$parts = array_map( 'sanitize_title_for_query', $parts );
|
1011 |
+
$in_string = "'". implode( "','", $parts ) . "'";
|
1012 |
+
$meta_key = $this->get_meta_key();
|
1013 |
+
$post_type_sql = $post_type;
|
1014 |
+
$wpdb->escape_by_ref( $post_type_sql );
|
1015 |
+
|
1016 |
+
$pages = $wpdb->get_results( "SELECT $wpdb->posts.ID, $wpdb->posts.post_parent, $wpdb->postmeta.meta_value FROM $wpdb->posts,$wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value IN ($in_string) AND ($wpdb->posts.post_type = '$post_type_sql' OR $wpdb->posts.post_type = 'attachment')", OBJECT_K );
|
1017 |
+
|
1018 |
+
$revparts = array_reverse( $parts );
|
1019 |
+
|
1020 |
+
$foundid = 0;
|
1021 |
+
foreach ( (array) $pages as $page ) {
|
1022 |
+
if ( $page->meta_value == $revparts[0] ) {
|
1023 |
+
$count = 0;
|
1024 |
+
$p = $page;
|
1025 |
+
while ( $p->post_parent != 0 && isset( $pages[ $p->post_parent ] ) ) {
|
1026 |
+
$count++;
|
1027 |
+
$parent = $pages[ $p->post_parent ];
|
1028 |
+
if ( ! isset( $revparts[ $count ] ) || $parent->meta_value != $revparts[ $count ] ) {
|
1029 |
+
break;
|
1030 |
+
}
|
1031 |
+
$p = $parent;
|
1032 |
+
}
|
1033 |
+
|
1034 |
+
if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->meta_value == $revparts[ $count ] ) {
|
1035 |
+
$foundid = $page->ID;
|
1036 |
+
break;
|
1037 |
+
}
|
1038 |
+
}
|
1039 |
+
}
|
1040 |
+
|
1041 |
+
if ( $foundid ) {
|
1042 |
+
return $foundid;
|
1043 |
+
|
1044 |
+
} else {
|
1045 |
+
|
1046 |
+
$last_part = array_pop($parts);
|
1047 |
+
$page_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_name = '$last_part' AND (post_type = '$post_type_sql' OR post_type = 'attachment')" );
|
1048 |
+
|
1049 |
+
if ( $page_id ) {
|
1050 |
+
return $page_id;
|
1051 |
+
}
|
1052 |
+
}
|
1053 |
+
|
1054 |
+
return null;
|
1055 |
+
}
|
1056 |
+
|
1057 |
+
|
1058 |
+
|
1059 |
+
|
1060 |
+
/**
|
1061 |
+
* Retrieves a page given its path.
|
1062 |
+
*
|
1063 |
+
* @param string $page_path Page path
|
1064 |
+
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
|
1065 |
+
* @param string $post_type Optional. Post type. Default page.
|
1066 |
+
* @return mixed Null when complete.
|
1067 |
+
*
|
1068 |
+
* @since 1.0
|
1069 |
+
*/
|
1070 |
+
private function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') {
|
1071 |
+
|
1072 |
+
$foundid = $this->get_page_id_by_path($page_path, $output, $post_type);
|
1073 |
+
if ( $foundid ) {
|
1074 |
+
return get_post( $foundid, $output );
|
1075 |
+
}
|
1076 |
+
|
1077 |
+
return null;
|
1078 |
+
}
|
1079 |
+
|
1080 |
+
|
1081 |
+
|
1082 |
+
/**
|
1083 |
+
* Ignores if the mod_rewrite func is the caller
|
1084 |
+
*
|
1085 |
+
* @return boolean
|
1086 |
+
*
|
1087 |
+
* @since 1.0
|
1088 |
+
*/
|
1089 |
+
private function ignore_rewrite_caller() {
|
1090 |
+
|
1091 |
+
$backtrace = debug_backtrace();
|
1092 |
+
|
1093 |
+
$ignore_functions = array('mod_rewrite_rules', 'save_mod_rewrite_rules', 'flush_rules', 'rewrite_rules', 'wp_rewrite_rules', 'query_vars');
|
1094 |
+
|
1095 |
+
if ( isset($backtrace['function']) ) {
|
1096 |
+
if (in_array($backtrace['function'], $ignore_functions)) {
|
1097 |
+
return true;
|
1098 |
+
}
|
1099 |
+
} else {
|
1100 |
+
foreach ($backtrace as $trace) {
|
1101 |
+
if ( isset($trace['function']) && in_array($trace['function'], $ignore_functions) ) {
|
1102 |
+
return true;
|
1103 |
+
}
|
1104 |
+
}
|
1105 |
+
}
|
1106 |
+
|
1107 |
+
return false;
|
1108 |
+
}
|
1109 |
+
|
1110 |
+
|
1111 |
+
/**
|
1112 |
+
* Retrieve the home url for a given site.
|
1113 |
+
*
|
1114 |
+
* @param int $blog_id (optional) Blog ID. Defaults to current blog.
|
1115 |
+
* @param string $path (optional) Path relative to the home url.
|
1116 |
+
* @param string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https'.
|
1117 |
+
* @return string Home url link with optional path appended.
|
1118 |
+
*
|
1119 |
+
* @since 1.0
|
1120 |
+
*/
|
1121 |
+
public function home_url($url, $path, $scheme, $blog_id) {
|
1122 |
+
|
1123 |
+
if ( !in_array( $scheme, array( 'http', 'https' ) ) ) {
|
1124 |
+
$scheme = is_ssl() && !is_admin() ? 'https' : 'http';
|
1125 |
+
}
|
1126 |
+
|
1127 |
+
if ( empty( $blog_id ) || !is_multisite() ) {
|
1128 |
+
$url = get_option( 'home' );
|
1129 |
+
} else {
|
1130 |
+
$url = get_blog_option( $blog_id, 'home' );
|
1131 |
+
}
|
1132 |
+
|
1133 |
+
if ( 'http' != $scheme ) {
|
1134 |
+
$url = str_replace( 'http://', "$scheme://", $url );
|
1135 |
+
}
|
1136 |
+
|
1137 |
+
$ignore_caller = $this->ignore_rewrite_caller();
|
1138 |
+
|
1139 |
+
if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) {
|
1140 |
+
$url .= '/' . ltrim( $path, '/' );
|
1141 |
+
}
|
1142 |
+
|
1143 |
+
if ( !$ignore_caller ) {
|
1144 |
+
$url = qtrans_convertURL($url, $this->get_lang(), true);
|
1145 |
+
}
|
1146 |
+
|
1147 |
+
return $url;
|
1148 |
+
}
|
1149 |
+
|
1150 |
+
|
1151 |
+
|
1152 |
+
/**
|
1153 |
+
* Filter that changes the permastruct depending
|
1154 |
+
*
|
1155 |
+
* @param string $permastruct default permastruct given b wp_rewrite
|
1156 |
+
* @param string $name the name of the extra permastruct
|
1157 |
+
* @return string processed permastruct
|
1158 |
+
*
|
1159 |
+
* @since 1.0
|
1160 |
+
*/
|
1161 |
+
public function get_extra_permastruct( $permastruct = false, $name = false ) {
|
1162 |
+
|
1163 |
+
if ( !$name || !$permastruct ) {
|
1164 |
+
return '';
|
1165 |
+
}
|
1166 |
+
|
1167 |
+
if ( $base = $this->get_base_slug($name, $this->get_lang()) ) {
|
1168 |
+
return "/$base/%$name%";
|
1169 |
+
}
|
1170 |
+
|
1171 |
+
return $permastruct;
|
1172 |
+
}
|
1173 |
+
|
1174 |
+
|
1175 |
+
|
1176 |
+
/**
|
1177 |
+
* Filter that translates the slug parts in a page link
|
1178 |
+
*
|
1179 |
+
* @param $link the link for the page generated by Wordpress
|
1180 |
+
* @param $id the id of the page
|
1181 |
+
* @return the link translated
|
1182 |
+
*
|
1183 |
+
* @since 1.0
|
1184 |
+
*/
|
1185 |
+
public function post_type_link( $link, $post, $leavename, $sample ) {
|
1186 |
+
global $wp_rewrite;
|
1187 |
+
|
1188 |
+
if ( is_wp_error( $post ) ) {
|
1189 |
+
return $post;
|
1190 |
+
}
|
1191 |
+
|
1192 |
+
$post_link = apply_filters( 'qts_permastruct', $wp_rewrite->get_extra_permastruct($post->post_type), $post->post_type);
|
1193 |
+
|
1194 |
+
$slug = get_post_meta( $post->ID, $this->get_meta_key(), true );
|
1195 |
+
if (!$slug) {
|
1196 |
+
$slug = $post->post_name;
|
1197 |
+
}
|
1198 |
+
|
1199 |
+
$draft_or_pending = isset($post->post_status) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
|
1200 |
+
|
1201 |
+
$post_type = get_post_type_object($post->post_type);
|
1202 |
+
|
1203 |
+
if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) {
|
1204 |
+
if ( ! $leavename ) {
|
1205 |
+
if ( $post_type->hierarchical )
|
1206 |
+
$slug = $this->get_page_uri($post->ID);
|
1207 |
+
$post_link = str_replace("%$post->post_type%", $slug, $post_link);
|
1208 |
+
}
|
1209 |
+
|
1210 |
+
$post_link = home_url( user_trailingslashit($post_link) );
|
1211 |
+
|
1212 |
+
} else {
|
1213 |
+
|
1214 |
+
if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) ) {
|
1215 |
+
$post_link = add_query_arg($post_type->query_var, $slug, '');
|
1216 |
+
} else {
|
1217 |
+
$post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), '');
|
1218 |
+
}
|
1219 |
+
|
1220 |
+
$post_link = home_url($post_link);
|
1221 |
+
}
|
1222 |
+
|
1223 |
+
return $post_link;
|
1224 |
+
}
|
1225 |
+
|
1226 |
+
|
1227 |
+
|
1228 |
+
/**
|
1229 |
+
* Filter that translates the slug in a post link
|
1230 |
+
*
|
1231 |
+
* @param $link the link generated by wordpress
|
1232 |
+
* @param $post the post data
|
1233 |
+
* @param $leavename parameter used by get_permalink. Whether to keep post name or page name.
|
1234 |
+
* @return the link translated
|
1235 |
+
*
|
1236 |
+
* @since 1.0
|
1237 |
+
*/
|
1238 |
+
public function post_link( $link, $post, $leavename ) {
|
1239 |
+
global $q_config;
|
1240 |
+
|
1241 |
+
$rewritecode = array(
|
1242 |
+
'%year%',
|
1243 |
+
'%monthnum%',
|
1244 |
+
'%day%',
|
1245 |
+
'%hour%',
|
1246 |
+
'%minute%',
|
1247 |
+
'%second%',
|
1248 |
+
$leavename? '' : '%postname%',
|
1249 |
+
'%post_id%',
|
1250 |
+
'%category%',
|
1251 |
+
'%author%',
|
1252 |
+
$leavename? '' : '%pagename%',
|
1253 |
+
);
|
1254 |
+
|
1255 |
+
if ( empty($post->ID) ) {
|
1256 |
+
return false;
|
1257 |
+
}
|
1258 |
+
|
1259 |
+
$permalink = $this->permalink_structure;
|
1260 |
+
|
1261 |
+
if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {
|
1262 |
+
$unixtime = strtotime($post->post_date);
|
1263 |
+
|
1264 |
+
$category = '';
|
1265 |
+
if ( strpos($permalink, '%category%') !== false ) {
|
1266 |
+
$cats = get_the_category($post->ID);
|
1267 |
+
if ( $cats ) {
|
1268 |
+
usort($cats, '_usort_terms_by_ID'); // order by ID
|
1269 |
+
|
1270 |
+
$category = get_term_meta($cats[0]->term_id, $this->get_meta_key(), true );
|
1271 |
+
if (!$category) $category = $cats[0]->slug;
|
1272 |
+
|
1273 |
+
if ( $parent = $cats[0]->parent )
|
1274 |
+
$category = $this->get_category_parents($parent, false, '/', true) . $category;
|
1275 |
+
}
|
1276 |
+
// show default category in permalinks, without
|
1277 |
+
// having to assign it explicitly
|
1278 |
+
if ( empty($category) ) {
|
1279 |
+
$default_category = get_category( get_option( 'default_category' ) );
|
1280 |
+
|
1281 |
+
$default_category_slug = get_term_meta($default_category->term_id, $this->get_meta_key(), true );
|
1282 |
+
if (!$default_category_slug) $default_category_slug = $default_category->slug;
|
1283 |
+
|
1284 |
+
$category = is_wp_error( $default_category ) ? '' : $default_category_slug;
|
1285 |
+
}
|
1286 |
+
}
|
1287 |
+
|
1288 |
+
$author = '';
|
1289 |
+
if ( strpos($permalink, '%author%') !== false ) {
|
1290 |
+
$authordata = get_userdata($post->post_author);
|
1291 |
+
$author = $authordata->user_nicename;
|
1292 |
+
}
|
1293 |
+
|
1294 |
+
$date = explode(" ",date('Y m d H i s', $unixtime));
|
1295 |
+
|
1296 |
+
$post_slug = get_post_meta($post->ID, $this->get_meta_key(), true );
|
1297 |
+
if (!$post_slug) {
|
1298 |
+
$post_slug = $post->post_name;
|
1299 |
+
}
|
1300 |
+
|
1301 |
+
$rewritereplace =
|
1302 |
+
array(
|
1303 |
+
$date[0],
|
1304 |
+
$date[1],
|
1305 |
+
$date[2],
|
1306 |
+
$date[3],
|
1307 |
+
$date[4],
|
1308 |
+
$date[5],
|
1309 |
+
$post_slug,
|
1310 |
+
$post->ID,
|
1311 |
+
$category,
|
1312 |
+
$author,
|
1313 |
+
$post_slug,
|
1314 |
+
);
|
1315 |
+
$permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink));
|
1316 |
+
if ($q_config['url_mode'] != 1) {
|
1317 |
+
$permalink = user_trailingslashit($permalink, 'single');
|
1318 |
+
}
|
1319 |
+
} else { // if they're not using the fancy permalink option
|
1320 |
+
$permalink = home_url('?p=' . $post->ID);
|
1321 |
+
}
|
1322 |
+
|
1323 |
+
return $permalink;
|
1324 |
+
}
|
1325 |
+
|
1326 |
+
|
1327 |
+
|
1328 |
+
/**
|
1329 |
+
* Retrieve category parents with separator.
|
1330 |
+
*
|
1331 |
+
* @param int $id Category ID.
|
1332 |
+
* @param bool $link Optional, default is false. Whether to format with link.
|
1333 |
+
* @param string $separator Optional, default is '/'. How to separate categories.
|
1334 |
+
* @param bool $nicename Optional, default is false. Whether to use nice name for display.
|
1335 |
+
* @param array $visited Optional. Already linked to categories to prevent duplicates.
|
1336 |
+
* @return string
|
1337 |
+
*
|
1338 |
+
* @since 1.0
|
1339 |
+
*/
|
1340 |
+
private function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) {
|
1341 |
+
|
1342 |
+
$chain = '';
|
1343 |
+
if(phpversion() >= 5.4) {
|
1344 |
+
$parent = get_category( $id );
|
1345 |
+
} else {
|
1346 |
+
$parent = &get_category( $id );
|
1347 |
+
}
|
1348 |
+
|
1349 |
+
if ( is_wp_error( $parent ) ) {
|
1350 |
+
return $parent;
|
1351 |
+
}
|
1352 |
+
|
1353 |
+
if ( $nicename ) {
|
1354 |
+
|
1355 |
+
$name = get_term_meta($parent->term_id, $this->get_meta_key(), true );
|
1356 |
+
if (!$name) {
|
1357 |
+
$name = $parent->slug;
|
1358 |
+
}
|
1359 |
+
} else {
|
1360 |
+
$name = $parent->name;
|
1361 |
+
}
|
1362 |
+
|
1363 |
+
if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
|
1364 |
+
$visited[] = $parent->parent;
|
1365 |
+
$chain .= $this->get_category_parents( $parent->parent, $link, $separator, $nicename, $visited );
|
1366 |
+
}
|
1367 |
+
|
1368 |
+
if ( $link ) {
|
1369 |
+
$chain .= '<a href="' . get_category_link( $parent->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
|
1370 |
+
} else {
|
1371 |
+
$chain .= $name.$separator;
|
1372 |
+
}
|
1373 |
+
|
1374 |
+
return $chain;
|
1375 |
+
}
|
1376 |
+
|
1377 |
+
|
1378 |
+
|
1379 |
+
|
1380 |
+
|
1381 |
+
/**
|
1382 |
+
* Filter that translates the slug parts in a page link
|
1383 |
+
*
|
1384 |
+
* @param $link the link for the page generated by Wordpress
|
1385 |
+
* @param $id the id of the page
|
1386 |
+
* @return the link translated
|
1387 |
+
*
|
1388 |
+
* @since 1.0
|
1389 |
+
*/
|
1390 |
+
public function _get_page_link( $link, $id ) {
|
1391 |
+
global $post, $wp_rewrite, $q_config;
|
1392 |
+
|
1393 |
+
$current_post = $post;
|
1394 |
+
|
1395 |
+
if ( !$id ) {
|
1396 |
+
$id = (int) $post->ID;
|
1397 |
+
} else {
|
1398 |
+
if(phpversion() >= 5.4) {
|
1399 |
+
$current_post = get_post($id);
|
1400 |
+
} else {
|
1401 |
+
$current_post = &get_post($id);
|
1402 |
+
}
|
1403 |
+
}
|
1404 |
+
|
1405 |
+
$draft_or_pending = in_array( $current_post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
|
1406 |
+
|
1407 |
+
$link = $wp_rewrite->get_page_permastruct();
|
1408 |
+
|
1409 |
+
if ( !empty($link) && ( isset($current_post->post_status) && !$draft_or_pending ) ) {
|
1410 |
+
|
1411 |
+
$link = str_replace('%pagename%', $this->get_page_uri($id), $link);
|
1412 |
+
|
1413 |
+
$link = trim($link, '/'); // hack
|
1414 |
+
$link = home_url("/$link/"); // hack
|
1415 |
+
|
1416 |
+
if ($q_config['url_mode'] != 1)
|
1417 |
+
$link = user_trailingslashit($link, 'page');
|
1418 |
+
|
1419 |
+
} else {
|
1420 |
+
|
1421 |
+
$link = home_url("?page_id=$id");
|
1422 |
+
}
|
1423 |
+
|
1424 |
+
return $link;
|
1425 |
+
}
|
1426 |
+
|
1427 |
+
|
1428 |
+
|
1429 |
+
/**
|
1430 |
+
* Builds URI for a page.
|
1431 |
+
*
|
1432 |
+
* Sub pages will be in the "directory" under the parent page post name.
|
1433 |
+
*
|
1434 |
+
* @param mixed $page Page object or page ID.
|
1435 |
+
* @return string Page URI.
|
1436 |
+
*
|
1437 |
+
* @since 1.0
|
1438 |
+
*/
|
1439 |
+
private function get_page_uri($page) {
|
1440 |
+
|
1441 |
+
if ( ! is_object($page) ) {
|
1442 |
+
$page = get_post($page);
|
1443 |
+
}
|
1444 |
+
|
1445 |
+
$uri = get_post_meta( $page->ID, $this->get_meta_key(), true );
|
1446 |
+
if (!$uri) {
|
1447 |
+
$uri = $page->post_name;
|
1448 |
+
}
|
1449 |
+
|
1450 |
+
// A page cannot be it's own parent.
|
1451 |
+
if ( $page->post_parent == $page->ID ) {
|
1452 |
+
return $uri;
|
1453 |
+
}
|
1454 |
+
|
1455 |
+
while ($page->post_parent != 0) {
|
1456 |
+
$page = get_post($page->post_parent);
|
1457 |
+
|
1458 |
+
$page_name = get_post_meta( $page->ID, $this->get_meta_key(), true );
|
1459 |
+
if (!$page_name) {
|
1460 |
+
$page_name = $page->post_name;
|
1461 |
+
}
|
1462 |
+
|
1463 |
+
$uri = $page_name . "/" . $uri;
|
1464 |
+
}
|
1465 |
+
|
1466 |
+
return $uri;
|
1467 |
+
}
|
1468 |
+
|
1469 |
+
|
1470 |
+
|
1471 |
+
/**
|
1472 |
+
* Filter that translates the slug parts in a term link
|
1473 |
+
*
|
1474 |
+
* @param $link the link for the page generated by Wordpress
|
1475 |
+
* @param $term object
|
1476 |
+
* @param $taxonomy object
|
1477 |
+
* @return the link translated
|
1478 |
+
*
|
1479 |
+
* @since 1.0
|
1480 |
+
*/
|
1481 |
+
public function term_link( $link, $term, $taxonomy ) {
|
1482 |
+
global $wp_rewrite;
|
1483 |
+
|
1484 |
+
// parse normal term names for ?tag=tagname
|
1485 |
+
if (empty($this->permalink_structure)) return $link;
|
1486 |
+
|
1487 |
+
if ( !is_object($term) ) {
|
1488 |
+
if ( is_int($term) ) {
|
1489 |
+
$term = &get_term($term, $taxonomy);
|
1490 |
+
} else {
|
1491 |
+
$term = $this->get_term_by('slug', $term, $taxonomy);
|
1492 |
+
}
|
1493 |
+
}
|
1494 |
+
|
1495 |
+
if ( !is_object($term) ) {
|
1496 |
+
$term = new WP_Error('invalid_term', __('Empty Term'));
|
1497 |
+
}
|
1498 |
+
|
1499 |
+
if ( is_wp_error( $term ) ) {
|
1500 |
+
return $term;
|
1501 |
+
}
|
1502 |
+
|
1503 |
+
$taxonomy = $term->taxonomy;
|
1504 |
+
|
1505 |
+
$termlink = apply_filters( 'qts_permastruct', $wp_rewrite->get_extra_permastruct($taxonomy), $taxonomy);
|
1506 |
+
|
1507 |
+
$slug = get_term_meta( $term->term_id, $this->get_meta_key(), true );
|
1508 |
+
if (!$slug) {
|
1509 |
+
$slug = $term->slug;
|
1510 |
+
}
|
1511 |
+
|
1512 |
+
$t = get_taxonomy($taxonomy);
|
1513 |
+
|
1514 |
+
if ( empty($termlink) ) {
|
1515 |
+
if ( 'category' == $taxonomy )
|
1516 |
+
$termlink = '?cat=' . $term->term_id;
|
1517 |
+
elseif ( $t->query_var )
|
1518 |
+
$termlink = "?$t->query_var=$slug";
|
1519 |
+
else
|
1520 |
+
$termlink = "?taxonomy=$taxonomy&term=$slug";
|
1521 |
+
$termlink = home_url($termlink);
|
1522 |
+
} else {
|
1523 |
+
if ( $t->rewrite['hierarchical'] ) {
|
1524 |
+
$hierarchical_slugs = array();
|
1525 |
+
$ancestors = get_ancestors($term->term_id, $taxonomy);
|
1526 |
+
foreach ( (array)$ancestors as $ancestor ) {
|
1527 |
+
$ancestor_term = get_term($ancestor, $taxonomy);
|
1528 |
+
|
1529 |
+
$ancestor_slug = get_term_meta( $ancestor_term->term_id, $this->get_meta_key(), true );
|
1530 |
+
if (!$ancestor_slug) $ancestor_slug = $ancestor_term->slug;
|
1531 |
+
|
1532 |
+
$hierarchical_slugs[] = $ancestor_slug;
|
1533 |
+
}
|
1534 |
+
$hierarchical_slugs = array_reverse($hierarchical_slugs);
|
1535 |
+
$hierarchical_slugs[] = $slug;
|
1536 |
+
$termlink = str_replace("%$taxonomy%", implode('/', $hierarchical_slugs), $termlink);
|
1537 |
+
} else {
|
1538 |
+
$termlink = str_replace("%$taxonomy%", $slug, $termlink);
|
1539 |
+
}
|
1540 |
+
$termlink = home_url( user_trailingslashit($termlink, 'category') );
|
1541 |
+
}
|
1542 |
+
return $termlink;
|
1543 |
+
}
|
1544 |
+
|
1545 |
+
|
1546 |
+
|
1547 |
+
/**
|
1548 |
+
* Get all Term data from database by Term field and data.
|
1549 |
+
*
|
1550 |
+
* @param (string) $field Either 'slug', 'name', or 'id'
|
1551 |
+
* @param (string|int) $value Search for this term value
|
1552 |
+
* @param (string) $taxonomy Taxonomy Name
|
1553 |
+
* @param (string) $output Constant OBJECT, ARRAY_A, or ARRAY_N
|
1554 |
+
* @param (string) $filter Optional, default is raw or no WordPress defined filter will applied.
|
1555 |
+
* @return (mixed) Term Row from database. Will return false if $taxonomy does not exist or $term was not found.
|
1556 |
+
*
|
1557 |
+
* @since 1.0
|
1558 |
+
*/
|
1559 |
+
private function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') {
|
1560 |
+
global $wpdb;
|
1561 |
+
|
1562 |
+
$original_field = $field;
|
1563 |
+
|
1564 |
+
if ( ! taxonomy_exists($taxonomy) ) {
|
1565 |
+
return false;
|
1566 |
+
}
|
1567 |
+
|
1568 |
+
if ( 'slug' == $field ) {
|
1569 |
+
$field = 'm.meta_key = \''.$this->get_meta_key().'\' AND m.meta_value';
|
1570 |
+
$value = sanitize_title($value);
|
1571 |
+
if ( empty($value) )
|
1572 |
+
return false;
|
1573 |
+
} else if ( 'name' == $field ) {
|
1574 |
+
// Assume already escaped
|
1575 |
+
$value = stripslashes($value);
|
1576 |
+
$field = 't.name';
|
1577 |
+
} else {
|
1578 |
+
$term = get_term( (int) $value, $taxonomy, $output, $filter);
|
1579 |
+
if ( is_wp_error( $term ) )
|
1580 |
+
$term = false;
|
1581 |
+
return $term;
|
1582 |
+
}
|
1583 |
+
|
1584 |
+
$term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t, $wpdb->term_taxonomy AS tt, $wpdb->termmeta AS m WHERE t.term_id = tt.term_id AND tt.term_id = m.term_id AND tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value) );
|
1585 |
+
|
1586 |
+
if ( !$term && 'slug' == $original_field ) {
|
1587 |
+
$field = 't.slug';
|
1588 |
+
$term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value) );
|
1589 |
+
}
|
1590 |
+
|
1591 |
+
if ( !$term ) {
|
1592 |
+
return false;
|
1593 |
+
}
|
1594 |
+
|
1595 |
+
wp_cache_add($term->term_id, $term, $taxonomy);
|
1596 |
+
|
1597 |
+
$term = apply_filters('get_term', $term, $taxonomy);
|
1598 |
+
$term = apply_filters("get_$taxonomy", $term, $taxonomy);
|
1599 |
+
$term = sanitize_term($term, $taxonomy, $filter);
|
1600 |
+
|
1601 |
+
if ( $output == OBJECT ) {
|
1602 |
+
return $term;
|
1603 |
+
} elseif ( $output == ARRAY_A ) {
|
1604 |
+
return get_object_vars($term);
|
1605 |
+
} elseif ( $output == ARRAY_N ) {
|
1606 |
+
return array_values(get_object_vars($term));
|
1607 |
+
} else {
|
1608 |
+
return $term;
|
1609 |
+
}
|
1610 |
+
}
|
1611 |
+
|
1612 |
+
|
1613 |
+
|
1614 |
+
/**
|
1615 |
+
* Fix for:
|
1616 |
+
* - Taxonomy names in Taxonomy Manage page
|
1617 |
+
* - 'Popular Tags' in Taxonomy (Tags) Manage page
|
1618 |
+
* - Category filter dropdown menu in Post Manage page
|
1619 |
+
* - Category list in Post Edit page
|
1620 |
+
* - 'Most Used' tags list in Post Edit page (but have issues when saving)
|
1621 |
+
*
|
1622 |
+
* @param (array) $terms
|
1623 |
+
* @param (string|array) $taxonomy
|
1624 |
+
* @since 1.2
|
1625 |
+
*/
|
1626 |
+
function get_terms($terms, $taxonomy) {
|
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 |
+
|
1652 |
+
|
1653 |
+
|
1654 |
+
/**
|
1655 |
+
* Fix for:
|
1656 |
+
* - Taxonomy & custom taxonomy names in Post Manage page
|
1657 |
+
* - List of tags already added to the post in Post
|
1658 |
+
* - Edit page (but have issues when saving)
|
1659 |
+
*
|
1660 |
+
* @param (array) $terms
|
1661 |
+
* @param (int|array) $obj_id
|
1662 |
+
* @param (string|array) $taxonomy
|
1663 |
+
* @param (array) $taxonomy
|
1664 |
+
* @since 1.2
|
1665 |
+
*/
|
1666 |
+
function get_object_terms($terms, $obj_id, $taxonomy, $args) {
|
1667 |
+
|
1668 |
+
global $pagenow;
|
1669 |
+
|
1670 |
+
// Although in post edit page the tags are translated,
|
1671 |
+
// but when saving/updating the post Wordpress considers
|
1672 |
+
// the translated tags as new tags. Due to this
|
1673 |
+
// issue I limit this 'hack' to the post manage
|
1674 |
+
// page only.
|
1675 |
+
if ( $pagenow == 'edit.php' ) {
|
1676 |
+
|
1677 |
+
// $taxonomy output seems to be wrapped
|
1678 |
+
// in single quotes, thus remove them to
|
1679 |
+
// make the output valid
|
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) {
|
1687 |
+
if( isset( $meta[$term->name][$lang] ) ) {
|
1688 |
+
$term->name = $meta[$term->name][$lang];
|
1689 |
+
}
|
1690 |
+
};
|
1691 |
+
};
|
1692 |
+
|
1693 |
+
}
|
1694 |
+
return $terms;
|
1695 |
+
}
|
1696 |
+
|
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 |
+
|
1711 |
+
|
1712 |
+
|
1713 |
+
/**
|
1714 |
+
* Hide auttomatically the wordpress slug blog in edit posts page
|
1715 |
+
*
|
1716 |
+
* @since 1.0
|
1717 |
+
*/
|
1718 |
+
public function hide_slug_box() {
|
1719 |
+
global $pagenow;
|
1720 |
+
|
1721 |
+
switch ( $pagenow ):
|
1722 |
+
case 'edit-tags.php':
|
1723 |
+
|
1724 |
+
echo "<!-- QTS remove slug box -->" . PHP_EOL;
|
1725 |
+
echo "<script type=\"text/javascript\" charset=\"utf-8\">" . PHP_EOL;
|
1726 |
+
echo " jQuery(document).ready(function($){" . PHP_EOL;
|
1727 |
+
echo " $(\"#tag-slug\").parent().hide();" . PHP_EOL;
|
1728 |
+
echo " $(\".form-field td #slug\").parent().parent().hide();" . PHP_EOL;
|
1729 |
+
echo " });" . PHP_EOL;
|
1730 |
+
echo "</script>" . PHP_EOL;
|
1731 |
+
break;
|
1732 |
+
|
1733 |
+
case 'post.php':
|
1734 |
+
|
1735 |
+
echo "<!-- QTS remove slug box -->" . PHP_EOL;
|
1736 |
+
echo "<style type=\"text/css\" media=\"screen\">" . PHP_EOL;
|
1737 |
+
echo " #edit-slug-box { display: none !important}" . PHP_EOL;
|
1738 |
+
echo "</style>" . PHP_EOL;
|
1739 |
+
break;
|
1740 |
+
endswitch;
|
1741 |
+
}
|
1742 |
+
|
1743 |
+
|
1744 |
+
|
1745 |
+
/**
|
1746 |
+
* Creates a metabox for every post, page and post type avaiable
|
1747 |
+
*
|
1748 |
+
* @since 1.0
|
1749 |
+
*/
|
1750 |
+
public function add_slug_meta_box() {
|
1751 |
+
|
1752 |
+
if ( function_exists( 'add_meta_box' ) ) {
|
1753 |
+
|
1754 |
+
add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), 'post', 'side', 'high');
|
1755 |
+
add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), 'page', 'side', 'high' );
|
1756 |
+
|
1757 |
+
foreach ( get_post_types( array('_builtin' => false ) ) as $ptype )
|
1758 |
+
add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), $ptype, 'side', 'high' );
|
1759 |
+
}
|
1760 |
+
}
|
1761 |
+
|
1762 |
+
|
1763 |
+
|
1764 |
+
/**
|
1765 |
+
* Shows the fields where insert the translated slugs in the post and page edit form.
|
1766 |
+
*
|
1767 |
+
* @param $post (object) current post object
|
1768 |
+
*
|
1769 |
+
* @since 1.0
|
1770 |
+
*/
|
1771 |
+
public function draw_meta_box( $post ) {
|
1772 |
+
global $q_config;
|
1773 |
+
|
1774 |
+
// Use nonce for verification
|
1775 |
+
echo "<table style=\"width:100%\">" . PHP_EOL;
|
1776 |
+
echo "<input type=\"hidden\" name=\"qts_nonce\" id=\"qts_nonce\" value=\"" . wp_create_nonce( 'qts_nonce' ) . "\" />" . PHP_EOL;
|
1777 |
+
|
1778 |
+
foreach ($q_config['enabled_languages'] as $lang):
|
1779 |
+
|
1780 |
+
$slug = get_post_meta( $post->ID, $this->get_meta_key($lang), true);
|
1781 |
+
|
1782 |
+
$value = ( $slug ) ? htmlspecialchars( $slug , ENT_QUOTES ) : '';
|
1783 |
+
|
1784 |
+
echo "<tr>" . PHP_EOL;
|
1785 |
+
echo "<th style=\"text-align:left; width:10%; color:#555 \"><label for=\"qts_{$lang}_slug\">".__($q_config['language_name'][$lang], 'qtranslate')."</label></th>" . PHP_EOL;
|
1786 |
+
echo "<td><input type=\"text\" id=\"qts_{$lang}_slug\" name=\"qts_{$lang}_slug\" value=\"$value\" style=\"width:90%; margin-left:10%; color:#777\" /></td>" . PHP_EOL;
|
1787 |
+
echo "</tr>" . PHP_EOL;
|
1788 |
+
|
1789 |
+
endforeach;
|
1790 |
+
|
1791 |
+
echo '</table>' . PHP_EOL;
|
1792 |
+
}
|
1793 |
+
|
1794 |
+
|
1795 |
+
|
1796 |
+
/**
|
1797 |
+
* Sanitize title as slug, if empty slug
|
1798 |
+
*
|
1799 |
+
* @param $post (object) the post object
|
1800 |
+
* @param $slug (string) the slug name
|
1801 |
+
* @param $lang (string) the language
|
1802 |
+
* @return the slug validated
|
1803 |
+
*
|
1804 |
+
* @since 1.0
|
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;
|
1812 |
+
}
|
1813 |
+
|
1814 |
+
$name = ( $post_title == '' || strlen($post_title) == 0 ) ? $post_name : $post_title;
|
1815 |
+
|
1816 |
+
$slug = trim($slug);
|
1817 |
+
|
1818 |
+
$slug = (empty($slug)) ? sanitize_title($name) : sanitize_title($slug);
|
1819 |
+
|
1820 |
+
|
1821 |
+
|
1822 |
+
return htmlspecialchars( $slug , ENT_QUOTES );
|
1823 |
+
}
|
1824 |
+
|
1825 |
+
|
1826 |
+
|
1827 |
+
/**
|
1828 |
+
* Validates post slug against repetitions per language
|
1829 |
+
*
|
1830 |
+
* @param $post (object) the post object
|
1831 |
+
* @param $slug (string) the slug name
|
1832 |
+
* @param $lang (string) the language
|
1833 |
+
* @return the slug validated
|
1834 |
+
*
|
1835 |
+
* @since 1.0
|
1836 |
+
*/
|
1837 |
+
public function unique_post_slug( $slug, $post, $lang ) {
|
1838 |
+
|
1839 |
+
$original_status = $post->post_status;
|
1840 |
+
|
1841 |
+
if ( in_array($post->post_status, array('draft', 'pending')) ) {
|
1842 |
+
$post->post_status = 'publish';
|
1843 |
+
}
|
1844 |
+
|
1845 |
+
$slug = $this->wp_unique_post_slug( $slug, $post->ID, $post->post_status, $post->post_type, $post->post_parent, $lang );
|
1846 |
+
|
1847 |
+
$post->post_status = $original_status;
|
1848 |
+
|
1849 |
+
return $slug;
|
1850 |
+
}
|
1851 |
+
|
1852 |
+
|
1853 |
+
|
1854 |
+
/**
|
1855 |
+
* Computes a unique slug for the post and language, when given the desired slug and some post details.
|
1856 |
+
*
|
1857 |
+
* @param string $slug the desired slug (post_name)
|
1858 |
+
* @param integer $post_ID
|
1859 |
+
* @param string $post_status no uniqueness checks are made if the post is still draft or pending
|
1860 |
+
* @param string $post_type
|
1861 |
+
* @param integer $post_parent
|
1862 |
+
* @return string unique slug for the post, based on language meta_value (with a -1, -2, etc. suffix)
|
1863 |
+
*
|
1864 |
+
* @since 1.0
|
1865 |
+
*/
|
1866 |
+
public function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $lang ) {
|
1867 |
+
if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
|
1868 |
+
return $slug;
|
1869 |
+
}
|
1870 |
+
|
1871 |
+
global $wpdb, $wp_rewrite;
|
1872 |
+
|
1873 |
+
$feeds = $wp_rewrite->feeds;
|
1874 |
+
if ( ! is_array( $feeds ) ) {
|
1875 |
+
$feeds = array();
|
1876 |
+
}
|
1877 |
+
|
1878 |
+
$meta_key = $this->get_meta_key($lang);
|
1879 |
+
if ( 'attachment' == $post_type ) {
|
1880 |
+
// Attachment slugs must be unique across all types.
|
1881 |
+
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
|
1882 |
+
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) );
|
1883 |
+
|
1884 |
+
if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
|
1885 |
+
$suffix = 2;
|
1886 |
+
do {
|
1887 |
+
$alt_post_name = substr ($slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
|
1888 |
+
$post_name_check = $wpdb->get_var( $wpdb->prepare($check_sql, $alt_post_name, $post_ID ) );
|
1889 |
+
$suffix++;
|
1890 |
+
} while ( $post_name_check );
|
1891 |
+
$slug = $alt_post_name;
|
1892 |
+
}
|
1893 |
+
} else {
|
1894 |
+
// Post slugs must be unique across all posts.
|
1895 |
+
$check_sql = "SELECT $wpdb->postmeta.meta_value FROM $wpdb->posts,$wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '%s' AND $wpdb->postmeta.meta_value = '%s' AND $wpdb->posts.post_type = %s AND ID != %d LIMIT 1";
|
1896 |
+
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $meta_key, $slug, $post_type, $post_ID ) );
|
1897 |
+
|
1898 |
+
if ( $post_name_check || in_array( $slug, $feeds ) || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
|
1899 |
+
$suffix = 2;
|
1900 |
+
do {
|
1901 |
+
$alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
|
1902 |
+
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $meta_key, $alt_post_name, $post_type, $post_ID ) );
|
1903 |
+
$suffix++;
|
1904 |
+
} while ( $post_name_check );
|
1905 |
+
$slug = $alt_post_name;
|
1906 |
+
}
|
1907 |
+
}
|
1908 |
+
|
1909 |
+
return $slug;
|
1910 |
+
}
|
1911 |
+
|
1912 |
+
|
1913 |
+
|
1914 |
+
|
1915 |
+
/**
|
1916 |
+
* Saves the translated slug when the page is saved
|
1917 |
+
*
|
1918 |
+
* @param $post_id the post id
|
1919 |
+
* @param $post the post object
|
1920 |
+
*
|
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 |
+
|
1928 |
+
|
1929 |
+
if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) // check autosave
|
1930 |
+
|| (!isset($_POST['post_ID']) || $post_id != $_POST['post_ID']) // check revision
|
1931 |
+
|| (!wp_verify_nonce( $_POST['qts_nonce'], 'qts_nonce')) // verify nonce
|
1932 |
+
|| (!current_user_can($post_type_object->cap->edit_post, $post_id))) { // check permission
|
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);
|
1940 |
+
|
1941 |
+
delete_post_meta($post_id, $meta_name);
|
1942 |
+
update_post_meta($post_id, $meta_name, $meta_value);
|
1943 |
+
|
1944 |
+
}
|
1945 |
+
}
|
1946 |
+
|
1947 |
+
|
1948 |
+
|
1949 |
+
/**
|
1950 |
+
* Display multiple input fields, one per language
|
1951 |
+
*
|
1952 |
+
* @param $term the term object
|
1953 |
+
*
|
1954 |
+
* @since 1.0
|
1955 |
+
*/
|
1956 |
+
public function show_term_fields( $term ) {
|
1957 |
+
global $q_config;
|
1958 |
+
|
1959 |
+
// prints the fields in edit page
|
1960 |
+
if (isset($_GET['action']) && $_GET['action'] == 'edit' ):
|
1961 |
+
|
1962 |
+
echo "<table class=\"form-table\">" . PHP_EOL;
|
1963 |
+
echo "<input type=\"hidden\" name=\"qts_nonce\" id=\"qts_nonce\" value=\"" . wp_create_nonce( 'qts_nonce' ) . "\" />" . PHP_EOL;
|
1964 |
+
|
1965 |
+
foreach( $q_config['enabled_languages'] as $lang ) {
|
1966 |
+
|
1967 |
+
$slug = (is_object($term)) ? get_term_meta( $term->term_id, $this->get_meta_key($lang), true ) : '';
|
1968 |
+
|
1969 |
+
$value = ( $slug ) ? htmlspecialchars( $slug , ENT_QUOTES ) : '';
|
1970 |
+
|
1971 |
+
echo "<tr class=\"form-field form-required\">" . PHP_EOL;
|
1972 |
+
echo "<th scope=\"row\" valig=\"top\"><label for=\"qts_term_{$lang}_slug\">Slug (".__($q_config['language_name'][$lang], 'qtranslate').")</label></th>" . PHP_EOL;
|
1973 |
+
echo "<td><input type=\"text\" name=\"qts_{$lang}_slug\" value=\"$value\" /></td></tr>" . PHP_EOL;
|
1974 |
+
|
1975 |
+
}
|
1976 |
+
|
1977 |
+
echo '</table>';
|
1978 |
+
|
1979 |
+
// prints the fields in new page
|
1980 |
+
else:
|
1981 |
+
echo "<input type=\"hidden\" name=\"qts_nonce\" id=\"qts_nonce\" value=\"" . wp_create_nonce( 'qts_nonce' ) . "\" />" . PHP_EOL;
|
1982 |
+
|
1983 |
+
foreach( $q_config['enabled_languages'] as $lang ) {
|
1984 |
+
|
1985 |
+
echo "<div class=\"form-field\">" . PHP_EOL;
|
1986 |
+
|
1987 |
+
$slug = (is_object($term)) ? get_term_meta( $term->term_id, $this->get_meta_key($lang), true ) : '';
|
1988 |
+
|
1989 |
+
$value = ( $slug ) ? htmlspecialchars( $slug , ENT_QUOTES ) : '';
|
1990 |
+
|
1991 |
+
|
1992 |
+
echo "<label for=\"qts_{$lang}_slug\">Slug (".__($q_config['language_name'][$lang], 'qtranslate').")</label>" . PHP_EOL;
|
1993 |
+
echo "<input type=\"text\" name=\"qts_term_{$lang}_slug\" value=\"$value\" aria-required=\"true\">" . PHP_EOL;
|
1994 |
+
|
1995 |
+
echo '</div>';
|
1996 |
+
|
1997 |
+
}
|
1998 |
+
|
1999 |
+
endif;
|
2000 |
+
}
|
2001 |
+
|
2002 |
+
|
2003 |
+
|
2004 |
+
/**
|
2005 |
+
* Sanitize title as slug, if empty slug
|
2006 |
+
*
|
2007 |
+
* @param $term (object) the term object
|
2008 |
+
* @param $slug (string) the slug name
|
2009 |
+
* @param $lang (string) the language
|
2010 |
+
* @return the slug validated
|
2011 |
+
*
|
2012 |
+
* @since 1.0
|
2013 |
+
*/
|
2014 |
+
public function validate_term_slug( $slug, $term, $lang ) {
|
2015 |
+
|
2016 |
+
global $q_config;
|
2017 |
+
|
2018 |
+
$lang_name = $q_config['term_name'][$term->name][$lang];
|
2019 |
+
|
2020 |
+
$ajax_name = 'new' . $term->taxonomy;
|
2021 |
+
|
2022 |
+
$post_name = isset($_POST['name']) ? $_POST['name'] : '';
|
2023 |
+
|
2024 |
+
$term_name = isset($_POST[$ajax_name]) ? trim($_POST[$ajax_name]) : $post_name;
|
2025 |
+
|
2026 |
+
if (empty($term_name)) {
|
2027 |
+
return $slug;
|
2028 |
+
}
|
2029 |
+
|
2030 |
+
$name = ( $lang_name == '' || strlen($lang_name) == 0 ) ? $term_name : $lang_name;
|
2031 |
+
|
2032 |
+
$slug = trim($slug);
|
2033 |
+
|
2034 |
+
$slug = (empty($slug)) ? sanitize_title($name) : sanitize_title($slug);
|
2035 |
+
|
2036 |
+
return htmlspecialchars( $slug , ENT_QUOTES );
|
2037 |
+
}
|
2038 |
+
|
2039 |
+
|
2040 |
+
|
2041 |
+
/**
|
2042 |
+
* Will make slug unique per language, if it isn't already.
|
2043 |
+
*
|
2044 |
+
* @param string $slug The string that will be tried for a unique slug
|
2045 |
+
* @param object $term The term object that the $slug will belong too
|
2046 |
+
* @param object $lang The language reference
|
2047 |
+
* @return string Will return a true unique slug.
|
2048 |
+
*
|
2049 |
+
* @since 1.0
|
2050 |
+
*/
|
2051 |
+
public function unique_term_slug($slug, $term, $lang) {
|
2052 |
+
|
2053 |
+
global $wpdb;
|
2054 |
+
|
2055 |
+
$meta_key_name = $this->get_meta_key($lang);
|
2056 |
+
$query = $wpdb->prepare("SELECT term_id FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s' AND term_id != %d ", $meta_key_name, $slug, $term->term_id);
|
2057 |
+
$exists_slug = $wpdb->get_results($query);
|
2058 |
+
|
2059 |
+
if ( empty($exists_slug) ) {
|
2060 |
+
return $slug;
|
2061 |
+
}
|
2062 |
+
|
2063 |
+
// If we didn't get a unique slug, try appending a number to make it unique.
|
2064 |
+
$query = $wpdb->prepare("SELECT meta_value FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s' AND term_id != %d", $meta_key_name, $slug, $term->term_id);
|
2065 |
+
|
2066 |
+
if ( $wpdb->get_var( $query ) ) {
|
2067 |
+
$num = 2;
|
2068 |
+
do {
|
2069 |
+
$alt_slug = $slug . "-$num";
|
2070 |
+
$num++;
|
2071 |
+
$slug_check = $wpdb->get_var(
|
2072 |
+
$wpdb->prepare(
|
2073 |
+
"SELECT meta_value FROM $wpdb->termmeta WHERE meta_key = '%s' AND meta_value = '%s'",
|
2074 |
+
$meta_key_name,
|
2075 |
+
$alt_slug) );
|
2076 |
+
} while ( $slug_check );
|
2077 |
+
$slug = $alt_slug;
|
2078 |
+
}
|
2079 |
+
|
2080 |
+
return $slug;
|
2081 |
+
}
|
2082 |
+
|
2083 |
+
|
2084 |
+
|
2085 |
+
/**
|
2086 |
+
* Display multiple input fields, one per language
|
2087 |
+
*
|
2088 |
+
* @param $term_id the term id
|
2089 |
+
* @param $tt_id the term taxonomy id
|
2090 |
+
* @param $taxonomy the term object
|
2091 |
+
*
|
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);
|
2120 |
+
|
2121 |
+
delete_term_meta($term_id, $meta_name);
|
2122 |
+
update_term_meta($term_id, $meta_name, $meta_value);
|
2123 |
+
}
|
2124 |
+
}
|
2125 |
+
|
2126 |
+
|
2127 |
+
|
2128 |
+
/**
|
2129 |
+
* deletes termmeta rows associated with the term
|
2130 |
+
*
|
2131 |
+
* @since 1.0
|
2132 |
+
*/
|
2133 |
+
public function delete_term($term_id, $tt_id, $taxonomy) {
|
2134 |
+
global $wpdb;
|
2135 |
+
|
2136 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE term_id = %d", $term_id ) );
|
2137 |
+
}
|
2138 |
+
|
2139 |
+
|
2140 |
+
|
2141 |
+
/**
|
2142 |
+
* adds support for qtranslate in taxonomies
|
2143 |
+
*
|
2144 |
+
* @since 1.0
|
2145 |
+
*/
|
2146 |
+
public function taxonomies_hooks() {
|
2147 |
+
|
2148 |
+
$taxonomies = $this->get_public_taxonomies();
|
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'));
|
2157 |
+
add_filter('manage_'.$taxonomy->name.'_custom_column', array(&$this, 'taxonomy_custom_column'), 0, 3);
|
2158 |
+
}
|
2159 |
+
}
|
2160 |
+
}
|
2161 |
+
|
2162 |
+
|
2163 |
+
|
2164 |
+
/*
|
2165 |
+
* Bug fix for slug column in taxonomies
|
2166 |
+
*
|
2167 |
+
* @since 1.0
|
2168 |
+
*/
|
2169 |
+
public function taxonomy_columns($columns) {
|
2170 |
+
unset($columns['slug']);
|
2171 |
+
unset($columns['posts']);
|
2172 |
+
|
2173 |
+
$columns['qts-slug'] = __('Slug', 'qts');
|
2174 |
+
$columns['posts'] = __('Posts');
|
2175 |
+
|
2176 |
+
return $columns;
|
2177 |
+
}
|
2178 |
+
|
2179 |
+
|
2180 |
+
|
2181 |
+
/*
|
2182 |
+
* Bug fix for slug column in taxonomies
|
2183 |
+
*
|
2184 |
+
* @since 1.0
|
2185 |
+
*/
|
2186 |
+
public function taxonomy_custom_column($str, $column_name, $term_id) {
|
2187 |
+
|
2188 |
+
switch ($column_name) {
|
2189 |
+
case 'qts-slug':
|
2190 |
+
echo get_term_meta($term_id, $this->get_meta_key(), true);
|
2191 |
+
break;
|
2192 |
+
}
|
2193 |
+
return false;
|
2194 |
+
}
|
2195 |
+
|
2196 |
+
|
2197 |
+
|
2198 |
+
|
2199 |
+
/**
|
2200 |
+
* Bug fix for multisite blog names
|
2201 |
+
*
|
2202 |
+
* @since 1.0
|
2203 |
+
*/
|
2204 |
+
public function blog_names($blogs) {
|
2205 |
+
|
2206 |
+
foreach ($blogs as $blog) {
|
2207 |
+
$blog->blogname = __($blog->blogname);
|
2208 |
+
}
|
2209 |
+
|
2210 |
+
return $blogs;
|
2211 |
+
}
|
2212 |
+
|
2213 |
+
|
2214 |
+
|
2215 |
+
/**
|
2216 |
+
* Initialise the Language Widget selector
|
2217 |
+
*
|
2218 |
+
* @since 1.0
|
2219 |
+
*/
|
2220 |
+
public function widget_init() {
|
2221 |
+
|
2222 |
+
if (class_exists('qTranslateWidget')) {
|
2223 |
+
unregister_widget('qTranslateWidget');
|
2224 |
+
}
|
2225 |
+
if (class_exists('mqTranslateWidget')) {
|
2226 |
+
unregister_widget('mqTranslateWidget');
|
2227 |
+
}
|
2228 |
+
|
2229 |
+
register_widget('QtranslateSlugWidget');
|
2230 |
+
}
|
2231 |
+
|
2232 |
+
|
2233 |
+
|
2234 |
+
/**
|
2235 |
+
* remove some default dashboard Widgets on Desktop
|
2236 |
+
*
|
2237 |
+
* @since 1.0
|
2238 |
+
*/
|
2239 |
+
function remove_dashboard_widgets() {
|
2240 |
+
global $wp_meta_boxes;
|
2241 |
+
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
|
2242 |
+
}
|
2243 |
+
|
2244 |
+
|
2245 |
+
|
2246 |
+
/**
|
2247 |
+
* adds support for qtranslate nav menus
|
2248 |
+
*
|
2249 |
+
* @since 1.0
|
2250 |
+
*/
|
2251 |
+
public function fix_nav_menu() {
|
2252 |
+
global $pagenow;
|
2253 |
+
|
2254 |
+
if( $pagenow != 'nav-menus.php' ) {
|
2255 |
+
return;
|
2256 |
+
}
|
2257 |
+
|
2258 |
+
wp_enqueue_script( 'nav-menu-query', plugins_url( 'assets/js/qts-nav-menu-min.js' , dirname(__FILE__ ) ), 'nav-menu', '1.0' );
|
2259 |
+
add_meta_box( 'qt-languages', __('Languages'), array(&$this, 'nav_menu_meta_box'), 'nav-menus', 'side', 'default' );
|
2260 |
+
}
|
2261 |
+
|
2262 |
+
|
2263 |
+
|
2264 |
+
/**
|
2265 |
+
* draws meta box for select language
|
2266 |
+
*
|
2267 |
+
* @since 1.0
|
2268 |
+
*/
|
2269 |
+
public function nav_menu_meta_box() {
|
2270 |
+
global $q_config;
|
2271 |
+
echo '<p>';
|
2272 |
+
foreach($q_config['enabled_languages'] as $id => $language) {
|
2273 |
+
$checked = ($language == $q_config['language']) ? ' checked="checked"' : '';
|
2274 |
+
echo '<p style="margin:0 0 5px 0"><input type="radio" style="margin-right:5px" name="wa_qt_lang" value="' . $language . '" id="wa_gt_lang_' . $id . '" ' . $checked . '/>';
|
2275 |
+
echo '<label for="wa_gt_lang_' . $id . '">';
|
2276 |
+
echo '<img src="' . trailingslashit(WP_CONTENT_URL).$q_config['flag_location'].$q_config['flag'][$language] . '"/> ';
|
2277 |
+
echo __($q_config['language_name'][$language], 'qtranslate');
|
2278 |
+
echo '</label></p>';
|
2279 |
+
}
|
2280 |
+
echo '</p>';
|
2281 |
+
}
|
2282 |
+
|
2283 |
+
|
2284 |
+
|
2285 |
+
/**
|
2286 |
+
* Language select function for templating
|
2287 |
+
*
|
2288 |
+
* @param $type (string) choose the type of menu: 'text', 'image', 'both', 'dropdown'
|
2289 |
+
* @param $args (array) some args for draw the menu: array( 'id', 'class', 'short' );
|
2290 |
+
*
|
2291 |
+
* @since 1.0
|
2292 |
+
*/
|
2293 |
+
public function language_menu( $type = "text", $args = array() ) {
|
2294 |
+
global $q_config;
|
2295 |
+
|
2296 |
+
// default arguments
|
2297 |
+
$defaults = array(
|
2298 |
+
'id' => "qts-lang-menu",
|
2299 |
+
'class' => "qts-lang-menu",
|
2300 |
+
'short' => false
|
2301 |
+
);
|
2302 |
+
$args = wp_parse_args( $args, $defaults );
|
2303 |
+
|
2304 |
+
$languages = qtrans_getSortedLanguages();
|
2305 |
+
|
2306 |
+
// every type
|
2307 |
+
switch ( $type ) {
|
2308 |
+
|
2309 |
+
case 'image':
|
2310 |
+
case 'text':
|
2311 |
+
case 'both':
|
2312 |
+
|
2313 |
+
$baseurl = dirname(plugins_url());
|
2314 |
+
$num_languages = count($languages);
|
2315 |
+
echo "<ul id=\"{$args['id']}\" class=\"qts_type_{$type} {$args['class']}\">". PHP_EOL;
|
2316 |
+
|
2317 |
+
foreach( $languages as $index => $lang ):
|
2318 |
+
|
2319 |
+
$url = $this->get_current_url($lang);
|
2320 |
+
|
2321 |
+
$item_class = array();
|
2322 |
+
if ( (string)$q_config['language'] == (string)$lang ) $item_class[] = 'current-menu-item';
|
2323 |
+
if ( $index == ( $num_languages - 1) ) $item_class[] = 'last-child';
|
2324 |
+
|
2325 |
+
|
2326 |
+
$item_class = ' class="qts_lang_item ' . implode(' ', $item_class) . '"';
|
2327 |
+
|
2328 |
+
$language_name = ($args['short']) ? $lang : $q_config['language_name'][$lang];
|
2329 |
+
|
2330 |
+
if ( $type == 'image' ) {
|
2331 |
+
$link_class = " class=\"qtrans_flag qtrans_flag_$lang\"";
|
2332 |
+
$link_content = "<span style=\"display:none\">$language_name</span>";
|
2333 |
+
} else if ( $type == 'both' ) {
|
2334 |
+
$link_class = " class=\"qts_both qtrans_flag qtrans_flag_$lang\"";
|
2335 |
+
$link_content = "$language_name";
|
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];
|
2342 |
+
|
2343 |
+
//TODO: add i18n for alt attribute
|
2344 |
+
//43LC: hardcoding height and width
|
2345 |
+
$link_flag = "<img widht=\"18\" height=\"12\" src=\"$link_flag_url\" alt=\"$language_name\" />";
|
2346 |
+
}
|
2347 |
+
echo "<li$item_class><a href=\"$url\" lang=\"$lang\" hreflang=\"$lang\"$link_class>$link_flag$link_content</a></li>" . PHP_EOL;
|
2348 |
+
|
2349 |
+
endforeach;
|
2350 |
+
|
2351 |
+
echo "</ul>". PHP_EOL;
|
2352 |
+
|
2353 |
+
break;
|
2354 |
+
|
2355 |
+
case 'dropdown':
|
2356 |
+
|
2357 |
+
echo "<select id=\"{$args['id']}\" class=\"{$args['class']}\" onchange=\"window.location.href=this.options[this.selectedIndex].value\">". PHP_EOL;
|
2358 |
+
|
2359 |
+
foreach( $languages as $index => $lang ):
|
2360 |
+
|
2361 |
+
$url = $this->get_current_url($lang);
|
2362 |
+
|
2363 |
+
$item_class = '';
|
2364 |
+
if ( (string)$q_config['language'] == (string)$lang ) $item_class = 'selected="selected"';
|
2365 |
+
|
2366 |
+
$language_name = ($args['short']) ? $lang : $q_config['language_name'][$lang];
|
2367 |
+
|
2368 |
+
echo "<option value=\"$url\" $item_class>$language_name</option>" . PHP_EOL;
|
2369 |
+
|
2370 |
+
endforeach;
|
2371 |
+
|
2372 |
+
echo "</select>". PHP_EOL;
|
2373 |
+
|
2374 |
+
break;
|
2375 |
+
}
|
2376 |
+
|
2377 |
+
}
|
2378 |
+
}
|
trunk/includes/qtranslate-slug-settings-options.php
ADDED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
61 |
+
|
62 |
+
$options[] = array(
|
63 |
+
"section" => "styles",
|
64 |
+
"id" => QTS_PREFIX . "styles",
|
65 |
+
"title" => __('Change styles type', 'qts'),
|
66 |
+
"desc" => array(
|
67 |
+
__("adds a file (qts-default.css) to the theme's header.", "qts"),
|
68 |
+
__("adds a minified ( slighlty faster) file (qts-default.min.css) to the theme's header.", "qts"),
|
69 |
+
__("prints the styles directly into the theme's header.", "qts"),
|
70 |
+
__("neither include not print the default style.", "qts")
|
71 |
+
),
|
72 |
+
"type" => "multi-radio",
|
73 |
+
'class' => 'qts-style',
|
74 |
+
"choices" => array(
|
75 |
+
"file",
|
76 |
+
"minified",
|
77 |
+
"inline",
|
78 |
+
"none"
|
79 |
+
),
|
80 |
+
"std" => "file"
|
81 |
+
);
|
82 |
+
|
83 |
+
return $options;
|
84 |
+
}
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Define our form fields (settings)
|
90 |
+
*
|
91 |
+
* @package Qtranslate Slug
|
92 |
+
* @subpackage Settings
|
93 |
+
* @version 1.0
|
94 |
+
*
|
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 |
+
|
102 |
+
// each post type
|
103 |
+
foreach ($post_types as $post_type):
|
104 |
+
|
105 |
+
$options[] = array(
|
106 |
+
"section" => "post_types",
|
107 |
+
"id" => QTS_PREFIX . "post_type_" . $post_type->name,
|
108 |
+
"title" => $post_type->labels->singular_name,
|
109 |
+
"desc" => sprintf( __( '<code>http://example.org/<u>%s</u>/some-%s/</code>', 'qts' ), $post_type->name, $post_type->name),
|
110 |
+
'class' => 'qts-slug',
|
111 |
+
"type" => "multi-text",
|
112 |
+
"choices" => get_multi_txt_choices( $post_type->name),
|
113 |
+
"std" => ""
|
114 |
+
);
|
115 |
+
|
116 |
+
endforeach;
|
117 |
+
// end each post type
|
118 |
+
|
119 |
+
$options[] = array(
|
120 |
+
"section" => "taxonomies",
|
121 |
+
"id" => QTS_PREFIX . "taxonomy_category",
|
122 |
+
"title" => __('Categories'),
|
123 |
+
"desc" => __( '<code>http://example.org/<u>category</u>/some-category/</code>', 'qts' ),
|
124 |
+
"type" => "multi-text",
|
125 |
+
'class' => 'qts-slug',
|
126 |
+
"choices" => get_multi_txt_choices('category'),
|
127 |
+
"std" => ""
|
128 |
+
);
|
129 |
+
|
130 |
+
$options[] = array(
|
131 |
+
"section" => "taxonomies",
|
132 |
+
"id" => QTS_PREFIX . "taxonomy_post_tag",
|
133 |
+
"title" => __('Tags'),
|
134 |
+
"desc" => __( '<code>http://example.org/<u>tag</u>/some-tag/</code>', 'qts' ),
|
135 |
+
"type" => "multi-text",
|
136 |
+
'class' => 'qts-slug',
|
137 |
+
"choices" => get_multi_txt_choices('post_tag'),
|
138 |
+
"std" => ""
|
139 |
+
);
|
140 |
+
|
141 |
+
|
142 |
+
$taxonomies = get_taxonomies( array( 'public' => true, 'show_ui' => true, '_builtin' => false ), 'object' );
|
143 |
+
|
144 |
+
// each extra taxonomy
|
145 |
+
foreach ($taxonomies as $taxonomy):
|
146 |
+
|
147 |
+
$options[] = array(
|
148 |
+
"section" => "taxonomies",
|
149 |
+
"id" => QTS_PREFIX . "taxonomy_" . $taxonomy->name,
|
150 |
+
"title" => $taxonomy->labels->singular_name,
|
151 |
+
"desc" => sprintf( __( '<code>http://example.org/<u>%s</u>/some-%s/</code>', 'qts' ), $taxonomy->name, $taxonomy->name ),
|
152 |
+
"type" => "multi-text",
|
153 |
+
'class' => 'qts-slug',
|
154 |
+
"choices" => get_multi_txt_choices( $taxonomy->name),
|
155 |
+
"std" => ""
|
156 |
+
);
|
157 |
+
|
158 |
+
endforeach;
|
159 |
+
// end each extra taxonomy
|
160 |
+
|
161 |
+
|
162 |
+
return $options;
|
163 |
+
}
|
164 |
+
|
165 |
+
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Contextual Help
|
169 |
+
*
|
170 |
+
* @package Qtranslate Slug
|
171 |
+
* @subpackage Settings
|
172 |
+
* @version 1.0
|
173 |
+
*
|
174 |
+
*/
|
175 |
+
function qts_options_page_contextual_help() {
|
176 |
+
|
177 |
+
|
178 |
+
$text = "<h3>" . __('Qtranslate Settings - Contextual Help','qts') . "</h3>";
|
179 |
+
$text .= "<p>" . __('Contextual help goes here. You may want to use different html elements to format your text as you want.','qts') . "</p>";
|
180 |
+
|
181 |
+
return $text;
|
182 |
+
}
|
trunk/includes/qtranslate-slug-settings.php
ADDED
@@ -0,0 +1,978 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ings-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' , dirname(__FILE__) ) );
|
297 |
+
wp_enqueue_script( 'qts_theme_settings_js', plugins_url( 'assets/js/qts-settings.js' , dirname(__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' , dirname(__FILE__) ), array('jquery') );
|
301 |
+
}
|
302 |
+
}
|
303 |
+
|
304 |
+
|
305 |
+
|
306 |
+
/**
|
307 |
+
* The Admin menu page
|
308 |
+
*
|
309 |
+
* @package Qtranslate Slug
|
310 |
+
* @subpackage Settings
|
311 |
+
* @version 1.0
|
312 |
+
*
|
313 |
+
*/
|
314 |
+
function qts_add_menu() {
|
315 |
+
global $current_screen;
|
316 |
+
|
317 |
+
$settings_output = qts_get_settings();
|
318 |
+
// collect our contextual help text
|
319 |
+
$qts_contextual_help = $settings_output['qts_contextual_help'];
|
320 |
+
|
321 |
+
// Display Settings Page link under the "Appearance" Admin Menu
|
322 |
+
$qts_settings_page = add_options_page(__('Qtranslate Slug options', 'qts'), __('Slug options', 'qts'), 'manage_options', QTS_PAGE_BASENAME, 'qts_show_settings_page');
|
323 |
+
// contextual help
|
324 |
+
/*
|
325 |
+
if ($qts_settings_page) {
|
326 |
+
$current_screen = get_current_screen();
|
327 |
+
//$current_screen->add_help_tab( array( $qts_settings_page, $qts_contextual_help ));
|
328 |
+
}
|
329 |
+
*/
|
330 |
+
// css & js
|
331 |
+
add_action( 'load-'. $qts_settings_page, 'qts_settings_scripts' );
|
332 |
+
}
|
333 |
+
add_action( 'admin_menu', 'qts_add_menu' );
|
334 |
+
|
335 |
+
|
336 |
+
|
337 |
+
////////////////////////////////////////////////////////////////////////////////////////
|
338 |
+
|
339 |
+
// Callback functions
|
340 |
+
|
341 |
+
|
342 |
+
|
343 |
+
/**
|
344 |
+
* Section HTML, displayed before the first option
|
345 |
+
*
|
346 |
+
* @package Qtranslate Slug
|
347 |
+
* @subpackage Settings
|
348 |
+
* @version 1.0
|
349 |
+
*
|
350 |
+
* @return echoes output
|
351 |
+
*/
|
352 |
+
function qts_section_fn($page_section = false) {
|
353 |
+
|
354 |
+
if ( !$page_section || !isset($page_section['id']) ) return;
|
355 |
+
|
356 |
+
switch ($page_section['id']) {
|
357 |
+
case 'post_types':
|
358 |
+
|
359 |
+
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>";
|
360 |
+
break;
|
361 |
+
|
362 |
+
case 'taxonomies':
|
363 |
+
|
364 |
+
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>";
|
365 |
+
break;
|
366 |
+
case 'styles':
|
367 |
+
|
368 |
+
echo "<p>" . __('The default styles are very minimal, and you can include them or not.', 'qts') . "</p>\n";
|
369 |
+
break;
|
370 |
+
}
|
371 |
+
}
|
372 |
+
|
373 |
+
|
374 |
+
|
375 |
+
/**
|
376 |
+
* Form Fields HTML: all form field types share the same function
|
377 |
+
*
|
378 |
+
* @package Qtranslate Slug
|
379 |
+
* @subpackage Settings
|
380 |
+
* @version 1.0
|
381 |
+
*
|
382 |
+
* @return echoes output
|
383 |
+
*/
|
384 |
+
function qts_show_form_field($args = array()) {
|
385 |
+
global $qtranslate_slug;
|
386 |
+
|
387 |
+
extract( $args );
|
388 |
+
|
389 |
+
// get the settings sections array
|
390 |
+
$settings_output = qts_get_settings();
|
391 |
+
$options = $qtranslate_slug->get_options();
|
392 |
+
|
393 |
+
// pass the standard value if the option is not yet set in the database
|
394 |
+
if ( !isset( $options[$id] ) && 'type' != 'checkbox' ) {
|
395 |
+
$options[$id] = $std;
|
396 |
+
}
|
397 |
+
|
398 |
+
// additional field class. output only if the class is defined in the create_setting arguments
|
399 |
+
$field_class = ($class != '') ? ' ' . $class : '';
|
400 |
+
|
401 |
+
// switch html display based on the setting type.
|
402 |
+
switch ( $type ) {
|
403 |
+
case 'text':
|
404 |
+
$options[$id] = stripslashes($options[$id]);
|
405 |
+
$options[$id] = esc_attr( $options[$id]);
|
406 |
+
echo "<input class='regular-text$field_class' type='text' id='$id' name='" . QTS_OPTIONS_NAME . "[$id]' value='$options[$id]' />";
|
407 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
408 |
+
break;
|
409 |
+
|
410 |
+
case "multi-text":
|
411 |
+
foreach($choices as $item) {
|
412 |
+
|
413 |
+
$item = explode("|",$item); // cat_name|cat_slug
|
414 |
+
$item[0] = esc_html__($item[0], 'qts');
|
415 |
+
|
416 |
+
if (!empty($options[$id])) {
|
417 |
+
foreach ($options[$id] as $option_key => $option_val){
|
418 |
+
if ($item[1] == $option_key) {
|
419 |
+
$value = $option_val;
|
420 |
+
}
|
421 |
+
}
|
422 |
+
} else {
|
423 |
+
$value = '';
|
424 |
+
}
|
425 |
+
|
426 |
+
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/>";
|
427 |
+
}
|
428 |
+
echo ($desc != '') ? "<span class='description'>$desc</span>" : "";
|
429 |
+
break;
|
430 |
+
|
431 |
+
case 'textarea':
|
432 |
+
$options[$id] = stripslashes($options[$id]);
|
433 |
+
$options[$id] = esc_html( $options[$id]);
|
434 |
+
echo "<textarea class='textarea$field_class' type='text' id='$id' name='" . QTS_OPTIONS_NAME . "[$id]' rows='5' cols='30'>$options[$id]</textarea>";
|
435 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
436 |
+
break;
|
437 |
+
|
438 |
+
case 'select':
|
439 |
+
echo "<select id='$id' class='select$field_class' name='" . QTS_OPTIONS_NAME . "[$id]'>";
|
440 |
+
foreach($choices as $item) {
|
441 |
+
$value = esc_attr($item, 'qts');
|
442 |
+
$item = esc_html($item, 'qts');
|
443 |
+
|
444 |
+
$selected = ($options[$id]==$value) ? 'selected="selected"' : '';
|
445 |
+
echo "<option value='$value' $selected>$item</option>";
|
446 |
+
}
|
447 |
+
echo "</select>";
|
448 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
449 |
+
break;
|
450 |
+
|
451 |
+
case 'select2':
|
452 |
+
echo "<select id='$id' class='select$field_class' name='" . QTS_OPTIONS_NAME . "[$id]'>";
|
453 |
+
foreach($choices as $item) {
|
454 |
+
|
455 |
+
$item = explode("|",$item);
|
456 |
+
$item[0] = esc_html($item[0], 'qts');
|
457 |
+
|
458 |
+
$selected = ($options[$id]==$item[1]) ? 'selected="selected"' : '';
|
459 |
+
echo "<option value='$item[1]' $selected>$item[0]</option>";
|
460 |
+
}
|
461 |
+
echo "</select>";
|
462 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
463 |
+
break;
|
464 |
+
|
465 |
+
case 'checkbox':
|
466 |
+
echo "<input class='checkbox$field_class' type='checkbox' id='$id' name='" . QTS_OPTIONS_NAME . "[$id]' value='1' " . checked( $options[$id], 1, false ) . " />";
|
467 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
468 |
+
break;
|
469 |
+
|
470 |
+
case "multi-checkbox":
|
471 |
+
foreach($choices as $item) {
|
472 |
+
|
473 |
+
$item = explode("|",$item);
|
474 |
+
$item[0] = esc_html($item[0], 'qts');
|
475 |
+
|
476 |
+
$checked = '';
|
477 |
+
|
478 |
+
if ( isset($options[$id][$item[1]]) ) {
|
479 |
+
if ( $options[$id][$item[1]] == 'true') {
|
480 |
+
$checked = 'checked="checked"';
|
481 |
+
}
|
482 |
+
}
|
483 |
+
|
484 |
+
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/>";
|
485 |
+
}
|
486 |
+
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
487 |
+
break;
|
488 |
+
|
489 |
+
case "multi-radio":
|
490 |
+
foreach($choices as $index => $item) {
|
491 |
+
|
492 |
+
$item = explode("|",$item);
|
493 |
+
$item_key = (count($item) > 1) ? esc_html($item[0], 'qts') : esc_html(end($item), 'qts');
|
494 |
+
$item_value = (count($item) > 1) ? esc_html($item[1], 'qts') : esc_html(end($item), 'qts');
|
495 |
+
|
496 |
+
$checked = '';
|
497 |
+
|
498 |
+
if ( isset($options[$id]) && $options[$id] === $item_value) {
|
499 |
+
$checked = 'checked="checked"';
|
500 |
+
}
|
501 |
+
|
502 |
+
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>";
|
503 |
+
if (isset($desc[$index]) && !empty($desc[$index])) {
|
504 |
+
echo ": " . $desc[$index];
|
505 |
+
}
|
506 |
+
echo "</label>";
|
507 |
+
}
|
508 |
+
echo (!is_array($desc) && $desc != '') ? "<br /><span class='description'>$desc</span>" : "";
|
509 |
+
break;
|
510 |
+
}
|
511 |
+
}
|
512 |
+
|
513 |
+
|
514 |
+
|
515 |
+
/**
|
516 |
+
* Validates base slugs per 'type' (post_type | taxonomy) and 'language'
|
517 |
+
*
|
518 |
+
* @package Qtranslate Slug
|
519 |
+
* @subpackage Settings
|
520 |
+
* @version 1.0
|
521 |
+
*
|
522 |
+
*/
|
523 |
+
function qts_sanitize_bases($base_slugs = false) {
|
524 |
+
|
525 |
+
if ( !$base_slugs || empty($base_slugs) ) return;
|
526 |
+
|
527 |
+
$base_slugs_processed = array();
|
528 |
+
$base_founded = array();
|
529 |
+
|
530 |
+
// changing array structure
|
531 |
+
foreach ($base_slugs as $type => $base) {
|
532 |
+
foreach ($base as $lang => $value) {
|
533 |
+
if ($value != ""):
|
534 |
+
$base_value = $value;
|
535 |
+
$count = 2;
|
536 |
+
while (in_array($value, $base_founded)) {
|
537 |
+
$value = "$base_value-$count";
|
538 |
+
$count++;
|
539 |
+
}
|
540 |
+
$base_founded[] = $base_slugs[$type][$lang] = $value;
|
541 |
+
endif;
|
542 |
+
}
|
543 |
+
}
|
544 |
+
|
545 |
+
return $base_slugs;
|
546 |
+
}
|
547 |
+
|
548 |
+
|
549 |
+
|
550 |
+
/**
|
551 |
+
* Admin Settings Page HTML
|
552 |
+
*
|
553 |
+
* @package Qtranslate Slug
|
554 |
+
* @subpackage Settings
|
555 |
+
* @version 1.0
|
556 |
+
*
|
557 |
+
* @return echoes output
|
558 |
+
*/
|
559 |
+
function qts_show_settings_page() {
|
560 |
+
// get the settings sections array
|
561 |
+
$settings_output = qts_get_settings();
|
562 |
+
?>
|
563 |
+
<div class="wrap">
|
564 |
+
<div class="icon32" id="icon-options-general"></div>
|
565 |
+
<h2><?php echo $settings_output['qts_page_title']; ?></h2>
|
566 |
+
|
567 |
+
<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>
|
568 |
+
|
569 |
+
<form action="options.php" method="post">
|
570 |
+
<?php
|
571 |
+
// upgrade notify
|
572 |
+
qts_upgrade();
|
573 |
+
// http://codex.wordpress.org/Function_Reference/settings_fields
|
574 |
+
settings_fields($settings_output['qts_option_name']);
|
575 |
+
|
576 |
+
// http://codex.wordpress.org/Function_Reference/do_settings_sections
|
577 |
+
do_settings_sections(__FILE__);
|
578 |
+
// rewrite rules
|
579 |
+
flush_rewrite_rules();
|
580 |
+
?>
|
581 |
+
<?php $css_path = plugin_dir_url(dirname(__FILE__)).'/assets/css/qts-default.css';
|
582 |
+
$file_styles = file_get_contents($css_path);
|
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'); ?>" />
|
590 |
+
</p>
|
591 |
+
|
592 |
+
</form>
|
593 |
+
</div><!-- wrap -->
|
594 |
+
<?php }
|
595 |
+
|
596 |
+
|
597 |
+
|
598 |
+
/**
|
599 |
+
* Validate input
|
600 |
+
*
|
601 |
+
* @package Qtranslate Slug
|
602 |
+
* @subpackage Settings
|
603 |
+
* @version 1.0
|
604 |
+
*
|
605 |
+
* @return array
|
606 |
+
*/
|
607 |
+
function qts_validate_options($input) {
|
608 |
+
|
609 |
+
// for enhanced security, create a new empty array
|
610 |
+
$valid_input = array();
|
611 |
+
|
612 |
+
// collect only the values we expect and fill the new $valid_input array
|
613 |
+
// i.e. whitelist our option IDs
|
614 |
+
|
615 |
+
// get the settings sections array
|
616 |
+
$settings_output = qts_get_settings();
|
617 |
+
|
618 |
+
$styleoptions = $settings_output['qts_page_styles'];
|
619 |
+
|
620 |
+
$slugoptions = $settings_output['qts_page_fields'];
|
621 |
+
|
622 |
+
$options = array_merge($styleoptions,$slugoptions);
|
623 |
+
|
624 |
+
// run a foreach and switch on option type
|
625 |
+
foreach ($options as $option):
|
626 |
+
|
627 |
+
switch ( $option['type'] ):
|
628 |
+
case 'text':
|
629 |
+
//switch validation based on the class!
|
630 |
+
switch ( $option['class'] ) {
|
631 |
+
//for numeric
|
632 |
+
case 'numeric':
|
633 |
+
//accept the input only when numeric!
|
634 |
+
$input[$option['id']] = trim($input[$option['id']]); // trim whitespace
|
635 |
+
$valid_input[$option['id']] = (is_numeric($input[$option['id']])) ? $input[$option['id']] : 'Expecting a Numeric value!';
|
636 |
+
|
637 |
+
// register error
|
638 |
+
if(is_numeric($input[$option['id']]) == FALSE) {
|
639 |
+
add_settings_error(
|
640 |
+
$option['id'], // setting title
|
641 |
+
QTS_PREFIX . '_txt_numeric_error', // error ID
|
642 |
+
__('Expecting a Numeric value! Please fix.', 'qts'), // error message
|
643 |
+
'error' // type of message
|
644 |
+
);
|
645 |
+
}
|
646 |
+
break;
|
647 |
+
|
648 |
+
//for multi-numeric values (separated by a comma)
|
649 |
+
case 'multinumeric':
|
650 |
+
//accept the input only when the numeric values are comma separated
|
651 |
+
$input[$option['id']] = trim($input[$option['id']]); // trim whitespace
|
652 |
+
|
653 |
+
if($input[$option['id']] !=''){
|
654 |
+
// /^-?\d+(?:,\s?-?\d+)*$/ matches: -1 | 1 | -12,-23 | 12,23 | -123, -234 | 123, 234 | etc.
|
655 |
+
$valid_input[$option['id']] = (preg_match('/^-?\d+(?:,\s?-?\d+)*$/', $input[$option['id']]) == 1) ? $input[$option['id']] : __('Expecting comma separated numeric values','qts');
|
656 |
+
}else{
|
657 |
+
$valid_input[$option['id']] = $input[$option['id']];
|
658 |
+
}
|
659 |
+
|
660 |
+
// register error
|
661 |
+
if($input[$option['id']] !='' && preg_match('/^-?\d+(?:,\s?-?\d+)*$/', $input[$option['id']]) != 1) {
|
662 |
+
add_settings_error(
|
663 |
+
$option['id'], // setting title
|
664 |
+
QTS_PREFIX . '_txt_multinumeric_error', // error ID
|
665 |
+
__('Expecting comma separated numeric values! Please fix.','qts'), // error message
|
666 |
+
'error' // type of message
|
667 |
+
);
|
668 |
+
}
|
669 |
+
break;
|
670 |
+
|
671 |
+
//for no html
|
672 |
+
case 'nohtml':
|
673 |
+
//accept the input only after stripping out all html, extra white space etc!
|
674 |
+
$input[$option['id']] = sanitize_text_field($input[$option['id']]); // need to add slashes still before sending to the database
|
675 |
+
$valid_input[$option['id']] = addslashes($input[$option['id']]);
|
676 |
+
break;
|
677 |
+
|
678 |
+
//for url
|
679 |
+
case 'url':
|
680 |
+
//accept the input only when the url has been sanited for database usage with esc_url_raw()
|
681 |
+
$input[$option['id']] = trim($input[$option['id']]); // trim whitespace
|
682 |
+
$valid_input[$option['id']] = esc_url_raw($input[$option['id']]);
|
683 |
+
break;
|
684 |
+
|
685 |
+
//for email
|
686 |
+
case 'email':
|
687 |
+
//accept the input only after the email has been validated
|
688 |
+
$input[$option['id']] = trim($input[$option['id']]); // trim whitespace
|
689 |
+
if($input[$option['id']] != ''){
|
690 |
+
$valid_input[$option['id']] = (is_email($input[$option['id']])!== FALSE) ? $input[$option['id']] : __('Invalid email', 'qts');
|
691 |
+
}elseif($input[$option['id']] == ''){
|
692 |
+
$valid_input[$option['id']] = __('This setting field cannot be empty! Please enter a valid email address.', 'qts');
|
693 |
+
}
|
694 |
+
|
695 |
+
// register error
|
696 |
+
if(is_email($input[$option['id']])== FALSE || $input[$option['id']] == '') {
|
697 |
+
add_settings_error(
|
698 |
+
$option['id'], // setting title
|
699 |
+
QTS_PREFIX . '_txt_email_error', // error ID
|
700 |
+
__('Please enter a valid email address.', 'qts'), // error message
|
701 |
+
'error' // type of message
|
702 |
+
);
|
703 |
+
}
|
704 |
+
break;
|
705 |
+
|
706 |
+
// a "cover-all" fall-back when the class argument is not set
|
707 |
+
default:
|
708 |
+
// accept only a few inline html elements
|
709 |
+
$allowed_html = array(
|
710 |
+
'a' => array('href' => array (),'title' => array ()),
|
711 |
+
'b' => array(),
|
712 |
+
'em' => array (),
|
713 |
+
'i' => array (),
|
714 |
+
'strong' => array()
|
715 |
+
);
|
716 |
+
// trim whitespace
|
717 |
+
$input[$option['id']] = trim($input[$option['id']]);
|
718 |
+
// find incorrectly nested or missing closing tags and fix markup
|
719 |
+
$input[$option['id']] = force_balance_tags($input[$option['id']]);
|
720 |
+
// need to add slashes still before sending to the database
|
721 |
+
$input[$option['id']] = wp_kses( $input[$option['id']], $allowed_html);
|
722 |
+
|
723 |
+
$valid_input[$option['id']] = addslashes($input[$option['id']]);
|
724 |
+
break;
|
725 |
+
}
|
726 |
+
break;
|
727 |
+
|
728 |
+
case "multi-text":
|
729 |
+
// this will hold the text values as an array of 'key' => 'value'
|
730 |
+
unset($textarray);
|
731 |
+
|
732 |
+
$text_values = array();
|
733 |
+
foreach ($option['choices'] as $k => $v ) {
|
734 |
+
// explode the connective
|
735 |
+
$pieces = explode("|", $v);
|
736 |
+
|
737 |
+
$text_values[] = $pieces[1];
|
738 |
+
}
|
739 |
+
|
740 |
+
foreach ($text_values as $v ) {
|
741 |
+
|
742 |
+
// Check that the option isn't empty
|
743 |
+
if (!empty($input[$option['id'] . '|' . $v])) {
|
744 |
+
// If it's not null, make sure it's sanitized, add it to an array
|
745 |
+
switch ($option['class']) {
|
746 |
+
// different sanitation actions based on the class create you own cases as you need them
|
747 |
+
|
748 |
+
//for numeric input
|
749 |
+
case 'numeric':
|
750 |
+
//accept the input only if is numberic!
|
751 |
+
$input[$option['id'] . '|' . $v]= trim($input[$option['id'] . '|' . $v]); // trim whitespace
|
752 |
+
$input[$option['id'] . '|' . $v]= (is_numeric($input[$option['id'] . '|' . $v])) ? $input[$option['id'] . '|' . $v] : '';
|
753 |
+
break;
|
754 |
+
|
755 |
+
case 'qts-slug':
|
756 |
+
// strip all html tags and white-space.
|
757 |
+
$type_ = end( explode('_', $option['id']) );
|
758 |
+
$input[$option['id'] . '|' . $v]= sanitize_title( sanitize_text_field( $input[$option['id'] . '|' . $v] ) );
|
759 |
+
$input[$option['id'] . '|' . $v]= addslashes($input[$option['id'] . '|' . $v]);
|
760 |
+
break;
|
761 |
+
|
762 |
+
// a "cover-all" fall-back when the class argument is not set
|
763 |
+
default:
|
764 |
+
// strip all html tags and white-space.
|
765 |
+
$input[$option['id'] . '|' . $v]= sanitize_text_field($input[$option['id'] . '|' . $v]); // need to add slashes still before sending to the database
|
766 |
+
$input[$option['id'] . '|' . $v]= addslashes($input[$option['id'] . '|' . $v]);
|
767 |
+
break;
|
768 |
+
}
|
769 |
+
// pass the sanitized user input to our $textarray array
|
770 |
+
$textarray[$v] = $input[$option['id'] . '|' . $v];
|
771 |
+
|
772 |
+
} else {
|
773 |
+
$textarray[$v] = '';
|
774 |
+
}
|
775 |
+
}
|
776 |
+
// pass the non-empty $textarray to our $valid_input array
|
777 |
+
if (!empty($textarray)) {
|
778 |
+
$valid_input[$option['id']] = $textarray;
|
779 |
+
}
|
780 |
+
break;
|
781 |
+
|
782 |
+
case 'textarea':
|
783 |
+
//switch validation based on the class!
|
784 |
+
switch ( $option['class'] ) {
|
785 |
+
//for only inline html
|
786 |
+
case 'inlinehtml':
|
787 |
+
// accept only inline html
|
788 |
+
// trim whitespace
|
789 |
+
$input[$option['id']] = trim($input[$option['id']]);
|
790 |
+
// find incorrectly nested or missing closing tags and fix markup
|
791 |
+
$input[$option['id']] = force_balance_tags($input[$option['id']]);
|
792 |
+
//wp_filter_kses expects content to be escaped!
|
793 |
+
$input[$option['id']] = addslashes($input[$option['id']]);
|
794 |
+
//calls stripslashes then addslashes
|
795 |
+
$valid_input[$option['id']] = wp_filter_kses($input[$option['id']]);
|
796 |
+
break;
|
797 |
+
|
798 |
+
//for no html
|
799 |
+
case 'nohtml':
|
800 |
+
//accept the input only after stripping out all html, extra white space etc!
|
801 |
+
// need to add slashes still before sending to the database
|
802 |
+
$input[$option['id']] = sanitize_text_field($input[$option['id']]);
|
803 |
+
$valid_input[$option['id']] = addslashes($input[$option['id']]);
|
804 |
+
break;
|
805 |
+
|
806 |
+
//for allowlinebreaks
|
807 |
+
case 'allowlinebreaks':
|
808 |
+
//accept the input only after stripping out all html, extra white space etc!
|
809 |
+
// need to add slashes still before sending to the database
|
810 |
+
$input[$option['id']] = wp_strip_all_tags($input[$option['id']]);
|
811 |
+
$valid_input[$option['id']] = addslashes($input[$option['id']]);
|
812 |
+
break;
|
813 |
+
|
814 |
+
// a "cover-all" fall-back when the class argument is not set
|
815 |
+
default:
|
816 |
+
// accept only limited html
|
817 |
+
//my allowed html
|
818 |
+
$allowed_html = array(
|
819 |
+
'a' => array('href' => array (),'title' => array ()),
|
820 |
+
'b' => array(),
|
821 |
+
'blockquote' => array('cite' => array ()),
|
822 |
+
'br' => array(),
|
823 |
+
'dd' => array(),
|
824 |
+
'dl' => array(),
|
825 |
+
'dt' => array(),
|
826 |
+
'em' => array (),
|
827 |
+
'i' => array (),
|
828 |
+
'li' => array(),
|
829 |
+
'ol' => array(),
|
830 |
+
'p' => array(),
|
831 |
+
'q' => array('cite' => array ()),
|
832 |
+
'strong' => array(),
|
833 |
+
'ul' => array(),
|
834 |
+
'h1' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
|
835 |
+
'h2' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
|
836 |
+
'h3' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
|
837 |
+
'h4' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
|
838 |
+
'h5' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ()),
|
839 |
+
'h6' => array('align' => array (),'class' => array (),'id' => array (), 'style' => array ())
|
840 |
+
);
|
841 |
+
|
842 |
+
$input[$option['id']] = trim($input[$option['id']]); // trim whitespace
|
843 |
+
$input[$option['id']] = force_balance_tags($input[$option['id']]); // find incorrectly nested or missing closing tags and fix markup
|
844 |
+
$input[$option['id']] = wp_kses( $input[$option['id']], $allowed_html); // need to add slashes still before sending to the database
|
845 |
+
$valid_input[$option['id']] = addslashes($input[$option['id']]);
|
846 |
+
break;
|
847 |
+
}
|
848 |
+
break;
|
849 |
+
|
850 |
+
case 'select':
|
851 |
+
// check to see if the selected value is in our approved array of values!
|
852 |
+
$valid_input[$option['id']] = (in_array( $input[$option['id']], $option['choices']) ? $input[$option['id']] : '' );
|
853 |
+
break;
|
854 |
+
|
855 |
+
case 'select2':
|
856 |
+
// process $select_values
|
857 |
+
$select_values = array();
|
858 |
+
foreach ($option['choices'] as $k => $v) {
|
859 |
+
// explode the connective
|
860 |
+
$pieces = explode("|", $v);
|
861 |
+
|
862 |
+
$select_values[] = $pieces[1];
|
863 |
+
}
|
864 |
+
// check to see if selected value is in our approved array of values!
|
865 |
+
$valid_input[$option['id']] = (in_array( $input[$option['id']], $select_values) ? $input[$option['id']] : '' );
|
866 |
+
break;
|
867 |
+
|
868 |
+
case 'checkbox':
|
869 |
+
// if it's not set, default to null!
|
870 |
+
if (!isset($input[$option['id']])) {
|
871 |
+
$input[$option['id']] = null;
|
872 |
+
}
|
873 |
+
// Our checkbox value is either 0 or 1
|
874 |
+
$valid_input[$option['id']] = ( $input[$option['id']] == 1 ? 1 : 0 );
|
875 |
+
break;
|
876 |
+
|
877 |
+
case 'multi-checkbox':
|
878 |
+
unset($checkboxarray);
|
879 |
+
$check_values = array();
|
880 |
+
foreach ($option['choices'] as $k => $v ) {
|
881 |
+
// explode the connective
|
882 |
+
$pieces = explode("|", $v);
|
883 |
+
|
884 |
+
$check_values[] = $pieces[1];
|
885 |
+
}
|
886 |
+
|
887 |
+
foreach ($check_values as $v ) {
|
888 |
+
|
889 |
+
// Check that the option isn't null
|
890 |
+
if (!empty($input[$option['id'] . '|' . $v])) {
|
891 |
+
// If it's not null, make sure it's true, add it to an array
|
892 |
+
$checkboxarray[$v] = 'true';
|
893 |
+
}
|
894 |
+
else {
|
895 |
+
$checkboxarray[$v] = 'false';
|
896 |
+
}
|
897 |
+
}
|
898 |
+
// Take all the items that were checked, and set them as the main option
|
899 |
+
if (!empty($checkboxarray)) {
|
900 |
+
$valid_input[$option['id']] = $checkboxarray;
|
901 |
+
}
|
902 |
+
break;
|
903 |
+
|
904 |
+
case 'multi-radio':
|
905 |
+
$valid_input[$option['id']] = (empty($input) || !isset($input[$option['id']])) ? $option['std'] : $input[$option['id']];
|
906 |
+
break;
|
907 |
+
|
908 |
+
endswitch;
|
909 |
+
|
910 |
+
if (!empty($valid_input) && $valid_input[$option['id']] === "qts-slug" ) {
|
911 |
+
$valid_input = qts_sanitize_bases($valid_input);
|
912 |
+
} else {
|
913 |
+
$valid_input= $valid_input;
|
914 |
+
}
|
915 |
+
|
916 |
+
endforeach;
|
917 |
+
|
918 |
+
return $valid_input;
|
919 |
+
}
|
920 |
+
|
921 |
+
|
922 |
+
|
923 |
+
/**
|
924 |
+
* Helper function for creating admin messages
|
925 |
+
*
|
926 |
+
* @package Qtranslate Slug
|
927 |
+
* @subpackage Settings
|
928 |
+
* @version 1.0
|
929 |
+
*
|
930 |
+
* src: http://www.wprecipes.com/how-to-show-an-urgent-message-in-the-wordpress-admin-area
|
931 |
+
*
|
932 |
+
* @param (string) $message The message to echo
|
933 |
+
* @param (string) $msgclass The message class
|
934 |
+
* @return echoes the message
|
935 |
+
*/
|
936 |
+
function qts_show_msg($message, $msgclass = 'info') {
|
937 |
+
echo "<div id='message' class='$msgclass'>$message</div>";
|
938 |
+
}
|
939 |
+
|
940 |
+
|
941 |
+
|
942 |
+
/**
|
943 |
+
* Callback function for displaying admin messages
|
944 |
+
*
|
945 |
+
* @package Qtranslate Slug
|
946 |
+
* @subpackage Settings
|
947 |
+
* @version 1.0
|
948 |
+
*
|
949 |
+
* @return calls qts_show_msg()
|
950 |
+
*/
|
951 |
+
function qts_admin_msgs() {
|
952 |
+
global $current_screen;
|
953 |
+
|
954 |
+
// check for our settings page - need this in conditional further down
|
955 |
+
$qts_settings_pg = isset($_GET['page']) ? strpos($_GET['page'], QTS_PAGE_BASENAME) : '';
|
956 |
+
// collect setting errors/notices:
|
957 |
+
// http://codex.wordpress.org/Function_Reference/get_settings_errors
|
958 |
+
$set_errors = get_settings_errors();
|
959 |
+
|
960 |
+
// display admin message only for the admin to see, only on our settings page
|
961 |
+
// and only when setting errors/notices are returned!
|
962 |
+
if(current_user_can ('manage_options') && $qts_settings_pg !== false && !empty($set_errors)){
|
963 |
+
|
964 |
+
// have our settings succesfully been updated?
|
965 |
+
if($set_errors[0]['code'] == 'settings_updated' && isset($_GET['settings-updated'])){
|
966 |
+
qts_show_msg("<p>" . $set_errors[0]['message'] . "</p>", 'updated');
|
967 |
+
|
968 |
+
// have errors been found?
|
969 |
+
}else{
|
970 |
+
// there maybe more than one so run a foreach loop.
|
971 |
+
foreach($set_errors as $set_error){
|
972 |
+
// set the title attribute to match the error "setting title" - need this in js file
|
973 |
+
qts_show_msg("<p class='setting-error-message' title='" . $set_error['setting'] . "'>" . $set_error['message'] . "</p>", 'error');
|
974 |
+
}
|
975 |
+
}
|
976 |
+
}
|
977 |
+
}
|
978 |
+
add_action('admin_notices', 'qts_admin_msgs');
|
trunk/includes/termmeta-core.php
ADDED
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
trunk/languages/qts-es_ES.mo
ADDED
Binary file
|
trunk/languages/qts-es_ES.po
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2012 qTranslate slug
|
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 |
+
"MIME-Version: 1.0\n"
|
9 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
+
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"PO-Revision-Date: 2012-06-17 03:37+0100\n"
|
12 |
+
"Last-Translator: Carlos Sanz <carlos.sanz@gmail.com>\n"
|
13 |
+
"Language-Team: Carlos Sanz Garcia <carlos.sanz@gmail.com>\n"
|
14 |
+
|
15 |
+
# qtranslate-slug.php
|
16 |
+
msgid "Language selector"
|
17 |
+
msgstr "Selector de idioma"
|
18 |
+
|
19 |
+
# qtranslate-slug.php
|
20 |
+
msgid "Title:"
|
21 |
+
msgstr "Título:"
|
22 |
+
|
23 |
+
# qtranslate-slug.php
|
24 |
+
msgid "<p style=\"color:red\">This plugin requires qTranslate to be installed and activated.</p>"
|
25 |
+
msgstr "<p style=\"color:red\">Este plugin necesita qTranslate instalado y activado previamente.</p>"
|
26 |
+
|
27 |
+
# qtranslate-slug.php
|
28 |
+
msgid "Slug"
|
29 |
+
msgstr "Enlace permanente"
|
30 |
+
|
31 |
+
# qtranslate-slug.php
|
32 |
+
msgid "Show short name (en):"
|
33 |
+
msgstr "Mostrar nombre corto (en):"
|
34 |
+
|
35 |
+
# qtranslate-slug-settings-options.php
|
36 |
+
msgid "Post types"
|
37 |
+
msgstr "Post types"
|
38 |
+
|
39 |
+
# qtranslate-slug-settings-options.php
|
40 |
+
msgid "Taxonomies"
|
41 |
+
msgstr "Taxonomias"
|
42 |
+
|
43 |
+
# qtranslate-slug-settings-options.php
|
44 |
+
msgid "Slug (%s)"
|
45 |
+
msgstr "URL (%s)"
|
46 |
+
|
47 |
+
# qtranslate-slug-settings-options.php
|
48 |
+
msgid "<code>http://example.org/<u>%s</u>/some-%s/</code>"
|
49 |
+
msgstr "<code>http://ejemplo.org/<u>%s</u>/algun-%s/</code>"
|
50 |
+
|
51 |
+
# qtranslate-slug-settings-options.php
|
52 |
+
msgid "<code>http://example.org/<u>category</u>/some-category/</code>"
|
53 |
+
msgstr "<code>http://ejemplo.org/<u>categoria</u>/alguna-categoria/</code>"
|
54 |
+
|
55 |
+
# qtranslate-slug-settings-options.php
|
56 |
+
msgid "<code>http://example.org/<u>tag</u>/some-tag/</code>"
|
57 |
+
msgstr "<code>http://ejemplo.org/<u>etiqueta</u>/alguna-etiqueta/</code>"
|
58 |
+
|
59 |
+
# qtranslate-slug-settings.php
|
60 |
+
msgid "Qtranslate Slug options"
|
61 |
+
msgstr "Opciones de Qtranslate Slug"
|
62 |
+
|
63 |
+
# qtranslate-slug-settings.php
|
64 |
+
msgid "Slug options"
|
65 |
+
msgstr "Opciones de URL"
|
66 |
+
|
67 |
+
# qtranslate-slug-settings.php
|
68 |
+
msgid "Save Changes"
|
69 |
+
msgstr "Guardar cambios"
|
70 |
+
|
71 |
+
# qtranslate-slug-settings.php
|
72 |
+
msgid "Expecting a Numeric value! Please fix."
|
73 |
+
msgstr "Se espera un valor numérico! Por favor, corrígelo."
|
74 |
+
|
75 |
+
# qtranslate-slug-settings.php
|
76 |
+
msgid "Expecting comma separated numeric values! Please fix."
|
77 |
+
msgstr "Se esperan valores numéricos separados por coma! Por favor, corrígelo."
|
78 |
+
|
79 |
+
# qtranslate-slug-settings.php
|
80 |
+
msgid "Invalid email"
|
81 |
+
msgstr "E-mail incorrecto"
|
82 |
+
|
83 |
+
# qtranslate-slug-settings.php
|
84 |
+
msgid "This setting field cannot be empty! Please enter a valid email address."
|
85 |
+
msgstr "Este campo no puede estar vacío! Por favor introduce una dirección de e-mail válida."
|
86 |
+
|
87 |
+
# qtranslate-slug-settings.php
|
88 |
+
msgid "Please enter a valid email address."
|
89 |
+
msgstr "Por favor introduce una dirección de e-mail válida."
|
90 |
+
|
91 |
+
# qtranslate-slug-settings.php
|
92 |
+
msgid "upgrade now"
|
93 |
+
msgstr "actualizar ahora"
|
94 |
+
|
95 |
+
# qtranslate-slug.php
|
96 |
+
msgid "Please update your old data to the new system."
|
97 |
+
msgstr "Por favor actualiza tu antiguo sistema de datos al nuevo."
|
98 |
+
|
99 |
+
# qtranslate-slug-settings.php
|
100 |
+
msgid "Upgrade your data"
|
101 |
+
msgstr "Actualiza tus datos"
|
102 |
+
|
103 |
+
# qtranslate-slug-settings.php
|
104 |
+
msgid "There are slugs stored with old data system. Please upgrade your data pressing upgrade button:"
|
105 |
+
msgstr "Hay slugs almacenados en el antiguo sistema. Por favor actualiza tus datos aprentando el botón actualizar:"
|
106 |
+
|
107 |
+
# qtranslate-slug-settings.php
|
108 |
+
msgid "Sorry, some error happened. Refresh this page and try again please."
|
109 |
+
msgstr "Lo sentimos, algún tipo de error ha ocurrido. Por favor recarga esta página y prueba otra vez."
|
110 |
+
|
111 |
+
# qtranslate-slug-settings.php
|
112 |
+
msgid "Congratulations, your data has been upgraded, you are up to date."
|
113 |
+
msgstr "Felicidades, tus datos se han actualizado, ahora estás al día."
|
114 |
+
|
115 |
+
# qtranslate-slug-settings.php
|
116 |
+
msgid "One step more, select what type of slug is this: <strong>%s</strong>"
|
117 |
+
msgstr "Un paso más, selecction qué tipo de slug es este: <strong>%s</strong>"
|
118 |
+
|
119 |
+
# qtranslate-slug-settings.php
|
120 |
+
msgid "Post, Page or Custom post type"
|
121 |
+
msgstr "Entrada, Página o Custom post type"
|
122 |
+
|
123 |
+
# qtranslate-slug-settings.php
|
124 |
+
msgid "Category, tag or custom taxonomy"
|
125 |
+
msgstr "Categoria, tag o taxonomía"
|
126 |
+
|
127 |
+
# qtranslate-slug.php
|
128 |
+
msgid "This plugin requires at least <strong>Wordpress 3.3</strong> and <strong>Qtranslate(2.5.8 or newer)</strong>"
|
129 |
+
msgstr "Este plugin requiere al menos <strong>Wordpress 3.3</strong> y <strong>Qtranslate(2.5.8 o mayor)</strong>"
|
130 |
+
|
131 |
+
# qtranslate-slug-settings.php
|
132 |
+
msgid "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."
|
133 |
+
msgstr "Si has activado previamente los <a href=\"options-permalink.php\">enlaces permanentes</a>, en esta sección podrás traducir las <strong>bases</strong> de las <abbr title=\"en inglés, Universal Resource Locator\">URLs</abbr> para post_types, categorías, etiquetas y taxonomias <a href=\"http://codex.wordpress.org/Function_Reference/register_post_type#Arguments\">públicas</a>."
|
134 |
+
|
135 |
+
# qtranslate-slug-settings.php
|
136 |
+
msgid "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."
|
137 |
+
msgstr "Por ejemplo, para el post_type <kbd>books</kbd> en Español se mostraría como <code>http://example.org/es/libros/post-type-name/</code>. Si dejas esto en blanco se usará la opción predeterminada cuando <a href=\"http://codex.wordpress.org/Function_Reference/register_post_type\">registraste</a> el post_type."
|
138 |
+
|
139 |
+
# qtranslate-slug-settings.php
|
140 |
+
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)."
|
141 |
+
msgstr "Por ejemplo, la taxonomia <kbd>category</kbd>, en Español se mostraría como <code>http://example.org/es/categoria/taxonomy-name/</code>. Si dejas esto en blanco se usará la opción predeterminada cuando <a href=\"http://codex.wordpress.org/Function_Reference/register_taxonomy\">registraste</a> la texonomia (si previamente configuraste la base de las estructuraas de <u>categorías</u> o <u>tags</u> en la página <a href=\"options-permalink.php\">enlaces permanentes</a>, estas bases serán reemplazadas por las traducidas)."
|
142 |
+
|
trunk/languages/qts-pt_PT.mo
ADDED
Binary file
|
trunk/languages/qts-pt_PT.po
ADDED
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2012 qTranslate slug
|
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 |
+
|
19 |
+
#: qtranslate-slug.php
|
20 |
+
msgid "Language selector"
|
21 |
+
msgstr "Selector de idioma"
|
22 |
+
|
23 |
+
#: qtranslate-slug.php
|
24 |
+
msgid "Title:"
|
25 |
+
msgstr "Título:"
|
26 |
+
|
27 |
+
#: qtranslate-slug.php
|
28 |
+
msgid ""
|
29 |
+
"<p style=\"color:red\">This plugin requires qTranslate to be installed and "
|
30 |
+
"activated.</p>"
|
31 |
+
msgstr ""
|
32 |
+
"<p style=\"color:red\">Este plugin necessita do qTranslate instalado e "
|
33 |
+
"activado previamente.</p>"
|
34 |
+
|
35 |
+
#: qtranslate-slug.php
|
36 |
+
msgid "Slug"
|
37 |
+
msgstr "URL"
|
38 |
+
|
39 |
+
#: qtranslate-slug.php
|
40 |
+
msgid "Show short name (en):"
|
41 |
+
msgstr "Mostrar abreviatura (pt):"
|
42 |
+
|
43 |
+
#: qtranslate-slug-settings-options.php
|
44 |
+
msgid "Post types"
|
45 |
+
msgstr "Tipos de artigos"
|
46 |
+
|
47 |
+
#: qtranslate-slug-settings-options.php
|
48 |
+
msgid "Taxonomies"
|
49 |
+
msgstr "Taxonomias"
|
50 |
+
|
51 |
+
#: qtranslate-slug-settings-options.php
|
52 |
+
msgid "Slug (%s)"
|
53 |
+
msgstr "URL (%s)"
|
54 |
+
|
55 |
+
#: qtranslate-slug-settings-options.php
|
56 |
+
msgid "<code>http://example.org/<u>%s</u>/some-%s/</code>"
|
57 |
+
msgstr "<code>http://exemplo.org/<u>%s</u>/qualquer-%s/</code>"
|
58 |
+
|
59 |
+
#: qtranslate-slug-settings-options.php
|
60 |
+
msgid "<code>http://example.org/<u>category</u>/some-category/</code>"
|
61 |
+
msgstr "<code>http://exemplo.org/<u>categoria</u>/qualquer-categoria/</code>"
|
62 |
+
|
63 |
+
#: qtranslate-slug-settings-options.php
|
64 |
+
msgid "<code>http://example.org/<u>tag</u>/some-tag/</code>"
|
65 |
+
msgstr "<code>http://exemplo.org/<u>etiqueta</u>/qualquer-etiqueta/</code>"
|
66 |
+
|
67 |
+
#: qtranslate-slug-settings.php
|
68 |
+
msgid "Qtranslate Slug options"
|
69 |
+
msgstr "Opções do Qtranslate Slug"
|
70 |
+
|
71 |
+
#: qtranslate-slug-settings.php
|
72 |
+
msgid "Slug options"
|
73 |
+
msgstr "Opções do URL"
|
74 |
+
|
75 |
+
#: qtranslate-slug-settings.php
|
76 |
+
msgid "Save Changes"
|
77 |
+
msgstr "Guardar alterações"
|
78 |
+
|
79 |
+
#: qtranslate-slug-settings.php
|
80 |
+
msgid "Expecting a Numeric value! Please fix."
|
81 |
+
msgstr "É necessário um valor numérico! Por favor, corrija."
|
82 |
+
|
83 |
+
#: qtranslate-slug-settings.php
|
84 |
+
msgid "Expecting comma separated numeric values! Please fix."
|
85 |
+
msgstr ""
|
86 |
+
"São necessários valores numéricos separados por vírgulas! Por favor, corrija."
|
87 |
+
|
88 |
+
#: qtranslate-slug-settings.php
|
89 |
+
msgid "Invalid email"
|
90 |
+
msgstr "Email incorrecto"
|
91 |
+
|
92 |
+
#: qtranslate-slug-settings.php
|
93 |
+
msgid "This setting field cannot be empty! Please enter a valid email address."
|
94 |
+
msgstr ""
|
95 |
+
"Este campo não pode estar vazio! Por favor introduza um endereço de email "
|
96 |
+
"válido."
|
97 |
+
|
98 |
+
#: qtranslate-slug-settings.php
|
99 |
+
msgid "Please enter a valid email address."
|
100 |
+
msgstr "Por favor introduza um endereço de email válido."
|
101 |
+
|
102 |
+
#: qtranslate-slug-settings.php
|
103 |
+
msgid "upgrade now"
|
104 |
+
msgstr "actualizar agora"
|
105 |
+
|
106 |
+
#: qtranslate-slug.php
|
107 |
+
msgid "Please update your old data to the new system."
|
108 |
+
msgstr "Por favor actualize os seus dados antigos para o novo sistema."
|
109 |
+
|
110 |
+
#: qtranslate-slug-settings.php
|
111 |
+
msgid "Upgrade your data"
|
112 |
+
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 "
|
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:"
|
121 |
+
|
122 |
+
#: qtranslate-slug-settings.php
|
123 |
+
msgid "Sorry, some error happened. Refresh this page and try again please."
|
124 |
+
msgstr ""
|
125 |
+
"Lamentavelmente mas ocorreu um erro. Por favor refresque esta página e tente "
|
126 |
+
"novamente."
|
127 |
+
|
128 |
+
#: qtranslate-slug-settings.php
|
129 |
+
msgid "Congratulations, your data has been upgraded, you are up to date."
|
130 |
+
msgstr ""
|
131 |
+
"Parabéns, os seus dados foram actualizados e o sistema está agora actual."
|
132 |
+
|
133 |
+
#: qtranslate-slug-settings.php
|
134 |
+
msgid "One step more, select what type of slug is this: <strong>%s</strong>"
|
135 |
+
msgstr "Um passo mais, seleccione que tipo de URL é este: <strong>%s</strong>"
|
136 |
+
|
137 |
+
#: qtranslate-slug-settings.php
|
138 |
+
msgid "Post, Page or Custom post type"
|
139 |
+
msgstr "Artigo, Página ou Tipo de Artigo Personalizado"
|
140 |
+
|
141 |
+
#: qtranslate-slug-settings.php
|
142 |
+
msgid "Category, tag or custom taxonomy"
|
143 |
+
msgstr "Categoria, etiqueta ou taxonomia personalizada"
|
144 |
+
|
145 |
+
#: qtranslate-slug.php
|
146 |
+
msgid ""
|
147 |
+
"This plugin requires at least <strong>Wordpress 3.3</strong> and "
|
148 |
+
"<strong>Qtranslate(2.5.8 or newer)</strong>"
|
149 |
+
msgstr ""
|
150 |
+
"Este plugin requer no mínimo o <strong>Wordpress 3.3</strong> e "
|
151 |
+
"<strong>Qtranslate (2.5.8 ou superior)</strong>"
|
152 |
+
|
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 ""
|
184 |
+
"For example, the taxonomy <kbd>category</kbd>, in Spanish would be displayed "
|
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)."
|
trunk/languages/qts.pot
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2012 qTranslate slug
|
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 |
+
"MIME-Version: 1.0\n"
|
9 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
+
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"PO-Revision-Date: 2012-MO-DA HO:MI+ZONE\n"
|
12 |
+
"Last-Translator: Carlos Sanz Garcia <carlos.sanz@gmail.com>\n"
|
13 |
+
"Language-Team: Carlos Sanz Garcia <carlos.sanz@gmail.com>\n"
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
#: qtranslate-slug.php
|
20 |
+
msgid "Language selector"
|
21 |
+
msgstr ""
|
22 |
+
|
23 |
+
#: qtranslate-slug.php
|
24 |
+
msgid "Title:"
|
25 |
+
msgstr ""
|
26 |
+
|
27 |
+
#: qtranslate-slug.php
|
28 |
+
msgid "<p style=\"color:red\">This plugin requires qTranslate to be installed and activated.</p>"
|
29 |
+
msgstr ""
|
30 |
+
|
31 |
+
#: qtranslate-slug.php
|
32 |
+
msgid "Slug"
|
33 |
+
msgstr ""
|
34 |
+
|
35 |
+
#: qtranslate-slug.php
|
36 |
+
msgid "Show short name (en):"
|
37 |
+
msgstr ""
|
38 |
+
|
39 |
+
#: qtranslate-slug-settings-options.php
|
40 |
+
msgid "Post types"
|
41 |
+
msgstr ""
|
42 |
+
|
43 |
+
#: qtranslate-slug-settings-options.php
|
44 |
+
msgid "Taxonomies"
|
45 |
+
msgstr ""
|
46 |
+
|
47 |
+
#: qtranslate-slug-settings-options.php
|
48 |
+
msgid "Slug (%s)"
|
49 |
+
msgstr ""
|
50 |
+
|
51 |
+
#: qtranslate-slug-settings-options.php
|
52 |
+
msgid "<code>http://example.org/<u>%s</u>/some-%s/</code>"
|
53 |
+
msgstr ""
|
54 |
+
|
55 |
+
#: qtranslate-slug-settings-options.php
|
56 |
+
msgid "<code>http://example.org/<u>category</u>/some-category/</code>"
|
57 |
+
msgstr ""
|
58 |
+
|
59 |
+
#: qtranslate-slug-settings-options.php
|
60 |
+
msgid "<code>http://example.org/<u>tag</u>/some-tag/</code>"
|
61 |
+
msgstr ""
|
62 |
+
|
63 |
+
#: qtranslate-slug-settings.php
|
64 |
+
msgid "Qtranslate Slug options"
|
65 |
+
msgstr ""
|
66 |
+
|
67 |
+
#: qtranslate-slug-settings.php
|
68 |
+
msgid "Slug options"
|
69 |
+
msgstr ""
|
70 |
+
|
71 |
+
#: qtranslate-slug-settings.php
|
72 |
+
msgid "Save Changes"
|
73 |
+
msgstr ""
|
74 |
+
|
75 |
+
#: qtranslate-slug-settings.php
|
76 |
+
msgid "Expecting a Numeric value! Please fix."
|
77 |
+
msgstr ""
|
78 |
+
|
79 |
+
#: qtranslate-slug-settings.php
|
80 |
+
msgid "Expecting comma separated numeric values! Please fix."
|
81 |
+
msgstr ""
|
82 |
+
|
83 |
+
#: qtranslate-slug-settings.php
|
84 |
+
msgid "Invalid email"
|
85 |
+
msgstr ""
|
86 |
+
|
87 |
+
#: qtranslate-slug-settings.php
|
88 |
+
msgid "This setting field cannot be empty! Please enter a valid email address."
|
89 |
+
msgstr ""
|
90 |
+
|
91 |
+
#: qtranslate-slug-settings.php
|
92 |
+
msgid "Please enter a valid email address."
|
93 |
+
msgstr ""
|
94 |
+
|
95 |
+
#: qtranslate-slug-settings.php
|
96 |
+
msgid "upgrade now"
|
97 |
+
msgstr ""
|
98 |
+
|
99 |
+
#: qtranslate-slug.php
|
100 |
+
msgid "Please update your old data to the new system."
|
101 |
+
msgstr ""
|
102 |
+
|
103 |
+
#: qtranslate-slug-settings.php
|
104 |
+
msgid "Upgrade your data"
|
105 |
+
msgstr ""
|
106 |
+
|
107 |
+
#: qtranslate-slug-settings.php
|
108 |
+
msgid "There are slugs stored with old data system. Please upgrade your data pressing upgrade button:"
|
109 |
+
msgstr ""
|
110 |
+
|
111 |
+
#: qtranslate-slug-settings.php
|
112 |
+
msgid "Sorry, some error happened. Refresh this page and try again please."
|
113 |
+
msgstr ""
|
114 |
+
|
115 |
+
#: qtranslate-slug-settings.php
|
116 |
+
msgid "Congratulations, your data has been upgraded, you are up to date."
|
117 |
+
msgstr ""
|
118 |
+
|
119 |
+
#: qtranslate-slug-settings.php
|
120 |
+
msgid "One step more, select what type of slug is this: <strong>%s</strong>"
|
121 |
+
msgstr ""
|
122 |
+
|
123 |
+
#: qtranslate-slug-settings.php
|
124 |
+
msgid "Post, Page or Custom post type"
|
125 |
+
msgstr ""
|
126 |
+
|
127 |
+
#: qtranslate-slug-settings.php
|
128 |
+
msgid "Category, tag or custom taxonomy"
|
129 |
+
msgstr ""
|
130 |
+
|
131 |
+
#: qtranslate-slug.php
|
132 |
+
msgid "This plugin requires at least <strong>Wordpress 3.3</strong> and <strong>Qtranslate(2.5.8 or newer)</strong>"
|
133 |
+
msgstr ""
|
134 |
+
|
135 |
+
#: qtranslate-slug-settings.php
|
136 |
+
msgid "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."
|
137 |
+
msgstr ""
|
138 |
+
|
139 |
+
#: qtranslate-slug-settings.php
|
140 |
+
msgid "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."
|
141 |
+
msgstr ""
|
142 |
+
|
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 ""
|
trunk/phpunit.xml
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>
|
trunk/qtranslate-slug-settings-options.php
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
}
|
trunk/qtranslate-slug-settings.php
ADDED
@@ -0,0 +1,972 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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');
|
trunk/qtranslate-slug.php
ADDED
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
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.8
|
7 |
+
Author: Carlos Sanz Garcia
|
8 |
+
Author URI: http://github.com/not-only-code
|
9 |
+
*/
|
10 |
+
|
11 |
+
|
12 |
+
////////////////////////////////////////////////////////////////////////////////////////
|
13 |
+
|
14 |
+
if ( !function_exists('_debug') ):
|
15 |
+
function _debug( $message ) {
|
16 |
+
|
17 |
+
if ( WP_DEBUG === true ):
|
18 |
+
|
19 |
+
if ( is_array( $message ) || is_object( $message ) ) {
|
20 |
+
|
21 |
+
error_log( print_r( $message, true ) );
|
22 |
+
|
23 |
+
} else {
|
24 |
+
|
25 |
+
error_log( $message );
|
26 |
+
}
|
27 |
+
|
28 |
+
endif;
|
29 |
+
}
|
30 |
+
endif;
|
31 |
+
|
32 |
+
////////////////////////////////////////////////////////////////////////////////////////
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Includes
|
38 |
+
*
|
39 |
+
* @since 1.1.8
|
40 |
+
*/
|
41 |
+
include_once(dirname(__FILE__).'/includes/class-qtranslate-slug-widget.php');
|
42 |
+
include_once(dirname(__FILE__).'/includes/class-qtranslate-slug.php');
|
43 |
+
|
44 |
+
////////////////////////////////////////////////////////////////////////////////////////
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Define Constants
|
50 |
+
*
|
51 |
+
* @since 1.0
|
52 |
+
*/
|
53 |
+
if (!defined("QTS_VERSION")) define("QTS_VERSION", '1.1.8');
|
54 |
+
if (!defined("QTS_PREFIX")) define("QTS_PREFIX", '_qts_');
|
55 |
+
if (!defined("QTS_PAGE_BASENAME")) define('QTS_PAGE_BASENAME', 'qtranslate-slug-settings');
|
56 |
+
if (!defined("QTS_OPTIONS_NAME")) define("QTS_OPTIONS_NAME", 'qts_options');
|
57 |
+
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
|
58 |
+
|
59 |
+
////////////////////////////////////////////////////////////////////////////////////////
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Includes
|
65 |
+
*
|
66 |
+
* @since 1.0
|
67 |
+
*/
|
68 |
+
if ( is_admin() && !QtranslateSlug::block_activate() ) { // setting options page
|
69 |
+
include_once(dirname(__FILE__).'/includes/qtranslate-slug-settings.php');
|
70 |
+
}
|
71 |
+
|
72 |
+
include_once(dirname(__FILE__).'/includes/termmeta-core.php'); // termmeta install and core functions
|
73 |
+
|
74 |
+
////////////////////////////////////////////////////////////////////////////////////////
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Init the plugin
|
80 |
+
*
|
81 |
+
* @since 1.0
|
82 |
+
*/
|
83 |
+
global $qtranslate_slug;
|
84 |
+
|
85 |
+
$qtranslate_slug = new QtranslateSlug();
|
86 |
+
|
87 |
+
// plugin activation
|
88 |
+
register_activation_hook( __FILE__, array($qtranslate_slug, 'install') );
|
89 |
+
|
90 |
+
// plugin deactivation
|
91 |
+
register_deactivation_hook( __FILE__, array($qtranslate_slug, 'deactivate') );
|
92 |
+
|
93 |
+
// plugin uninstall
|
94 |
+
register_uninstall_hook( __FILE__, 'qts_uninstall' );
|
95 |
+
|
96 |
+
// plugin init
|
97 |
+
add_action('plugins_loaded', array($qtranslate_slug, 'init') );
|
98 |
+
|
99 |
+
////////////////////////////////////////////////////////////////////////////////////////
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Language Selector Code for templating
|
105 |
+
*
|
106 |
+
* @package Qtranslate Slug
|
107 |
+
* @subpackage Core
|
108 |
+
* @since 1.0
|
109 |
+
*/
|
110 |
+
function qts_language_menu ($type = "text", $args = array()) {
|
111 |
+
global $qtranslate_slug;
|
112 |
+
|
113 |
+
$qtranslate_slug->language_menu($type, $args);
|
114 |
+
}
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Adds support for old plugin function
|
120 |
+
*
|
121 |
+
* @package Qtranslate Slug
|
122 |
+
* @subpackage Core
|
123 |
+
* @since 1.1.5
|
124 |
+
*/
|
125 |
+
function qTranslateSlug_getSelfUrl ($lang = false) { // bad naming, I'll keep just in case
|
126 |
+
return qts_get_url($lang);
|
127 |
+
}
|
128 |
+
|
129 |
+
function qts_get_url($lang = false) {
|
130 |
+
global $qtranslate_slug;
|
131 |
+
|
132 |
+
return $qtranslate_slug->get_current_url($lang);
|
133 |
+
}
|
134 |
+
|
135 |
+
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Add a "Settings" link to the plugins.php page for Qtranslate Slug
|
139 |
+
*
|
140 |
+
* @package Qtranslate Slug
|
141 |
+
* @subpackage Settings
|
142 |
+
* @version 1.0
|
143 |
+
*
|
144 |
+
* @return calls qts_show_msg()
|
145 |
+
*/
|
146 |
+
function qts_add_settings_link( $links, $file ) {
|
147 |
+
|
148 |
+
if (QtranslateSlug::block_activate()) return $links;
|
149 |
+
|
150 |
+
$this_plugin = plugin_basename( __FILE__ );
|
151 |
+
if( $file == $this_plugin ) {
|
152 |
+
$settings_link = "<a href=\"options-general.php?page=" . QTS_PAGE_BASENAME . "\">" . __( 'Settings' ) . '</a>';
|
153 |
+
array_unshift($links, $settings_link);
|
154 |
+
}
|
155 |
+
return $links;
|
156 |
+
}
|
157 |
+
add_filter( 'plugin_action_links', 'qts_add_settings_link', 10, 2 );
|
158 |
+
|
159 |
+
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Delete plugin stored data ( options, termmeta table and postmeta data ) ################################################ TODO: test this function
|
163 |
+
*
|
164 |
+
* @package Qtranslate Slug
|
165 |
+
* @subpackage Settings
|
166 |
+
* @version 1.0
|
167 |
+
*
|
168 |
+
*/
|
169 |
+
function qts_uninstall() {
|
170 |
+
global $q_config, $wpdb;
|
171 |
+
|
172 |
+
// options
|
173 |
+
delete_option(QTS_OPTIONS_NAME);
|
174 |
+
delete_option('qts_version');
|
175 |
+
|
176 |
+
// delete termmeta table
|
177 |
+
$wpdb->query("DROP TABLE IF EXISTS $wpdb->termmeta");
|
178 |
+
|
179 |
+
// delete postmeta data
|
180 |
+
$meta_keys = array();
|
181 |
+
foreach ($q_config['enabled_languages'] as $lang) $meta_keys[] = sprintf("_qts_slug_%s", $lang);
|
182 |
+
$meta_keys = "'". implode( "','", $meta_keys ) . "'";
|
183 |
+
$wpdb->query("DELETE from $wpdb->postmeta WHERE meta_key IN ($meta_keys)");
|
184 |
+
}
|
trunk/readme.md
ADDED
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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**.
|
trunk/readme.txt
ADDED
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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**.
|
trunk/screenshot-1.png
ADDED
Binary file
|
trunk/screenshot-2.png
ADDED
Binary file
|
trunk/screenshot-3.png
ADDED
Binary file
|
trunk/screenshot-4.png
ADDED
Binary file
|
trunk/termmeta-core.php
ADDED
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
trunk/version.txt
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
= 1.1.8 =
|
2 |
+
|
3 |
+
Many thanks to everyone that contributed to this update, both for their commits and bug reports )
|
4 |
+
|
5 |
+
* Portuguese translation and fixed some translation bugs ( thanks pedro-mendonca )
|
6 |
+
* removed mqtranslate switcher widget hook
|
7 |
+
* Updated the plugin structure and coding style
|
8 |
+
* solve some conflicts with search and pagination queries
|
9 |
+
* Settings php errors, syntax indent and fixed settings assets url
|
10 |
+
* Change titles when there is a click on pagination on show all pages tab ( thanks juanfran-granados )
|
11 |
+
* Formatted dependency notice message ( thanks arildm )
|
12 |
+
* Updated the deprecated jquery 'live' function and solve php strict standards error ( thanks rafitaFCB )
|
13 |
+
* Fixed error showing if PHP was newer than 5.3 ( thanks rafitaFCB )
|
14 |
+
* Strict standard advise prevented ( thanks rafitaFCB )
|
15 |
+
* php notices are prevented in post edit, when using adding new translated tags ( thanks rafitaFCB )
|
16 |
+
* fixed the hreflang issue! 'bout time!
|
17 |
+
* As discussed in issue #25, the flags are now img tags, intead of background-url.
|
18 |
+
* Added another option to include the css style in a minified file. ( and also showing in the option screen the styles we would use.)
|
19 |
+
|
20 |
+
= 1.1.7 =
|
21 |
+
* removed styles from html elements and added options to use .css file or print inline styles
|
22 |
+
* fixed tag creation on post edit.
|
23 |
+
* fixed earlier bad post slug introduced in 1.1.6
|
24 |
+
|
25 |
+
= 1.1.6 =
|
26 |
+
* compatible with mqtranslate
|
27 |
+
* php5.4+ compatible
|
28 |
+
|
29 |
+
= 1.1.5 =
|
30 |
+
* bugfixes
|
31 |
+
|
32 |
+
= 1.1 =
|
33 |
+
* added multisite support
|
34 |
+
* fixed some parse url bugs
|
35 |
+
* fixed slug bases validation
|
36 |
+
|
37 |
+
= 1.0 =
|
38 |
+
* new branch, the plugin has been rewrited: now the code is commented and wrapped inside a class, also all code has change and the performance has been increased.
|
39 |
+
* structural changes:
|
40 |
+
* no ID for slug type, then don't install qtrasnlate_slug table.
|
41 |
+
* slugs now are stored on meta tables, 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/).
|
42 |
+
* some automation:
|
43 |
+
* the plugin generates translated slug automatically from title in empty cases (like wordpress).
|
44 |
+
* the plugin checks if the slug already exists (per each language and type / taxonomy), and adds a progressive number in this case (like wordpress).
|
45 |
+
* works on ajax requests like creatig new taxonomies on edit post page.
|
46 |
+
* possibility to translate the base of permastructs for 'post_types' and 'taxonomies' (uses $wp_rewrite).
|
47 |
+
* added some filters:
|
48 |
+
* 'qts_validate_post_slug' : args( $post (object), $slug (string), $lang (string) ) / filter to process the post slug before is saved on the database.
|
49 |
+
* 'qts_validate_term_slug' : args( $term (object), $slug (string), $lang (string) ) / filter to process the term slug before is saved on the database.
|
50 |
+
* 'qts_current_url' : args ( $url (string), $lang (string) ) / filter to process the entire url after it has been generated.
|
51 |
+
* 'qts_permastruct' : args ( $permastruct (string), $name (string) ) / filter to process the permastruct, used for change the base.
|
52 |
+
* added plugin language textdomain (.pot file)
|
53 |
+
* new admin options page for save the base permastructs.
|
54 |
+
* import process when the plugin updates older versions.
|
55 |
+
* some bug fixes.
|
56 |
+
* some Qtranslate patches.
|
57 |
+
|
58 |
+
= 0.9 =
|
59 |
+
* some wordpress qTranslate bug fixes
|
60 |
+
* adds a javascript solution for qTranslate Nav Menus
|
61 |
+
|
62 |
+
= 0.8 =
|
63 |
+
* added support por Categories
|
64 |
+
* added support por Tags
|
65 |
+
* added support por Taxonomies
|
66 |
+
* added support por Custom Post Types
|
67 |
+
|
68 |
+
= 0.7 ( enhanced by Zapo (http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=4&t=1049&start=50#p7499) ) =
|
69 |
+
* added suport for qTranslate TLD domain mode (en: domain.com | fr: domain.fr) visit
|
70 |
+
|
71 |
+
= 0.5 and 0.6 enhanched by Marco Del Percio =
|
version.txt
CHANGED
@@ -1,3 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
= 1.1.7 =
|
2 |
* removed styles from html elements and added options to use .css file or print inline styles
|
3 |
* fixed tag creation on post edit.
|
1 |
+
= 1.1.8 =
|
2 |
+
|
3 |
+
Many thanks to everyone that contributed to this update, both for their commits and bug reports )
|
4 |
+
|
5 |
+
* Portuguese translation and fixed some translation bugs ( thanks pedro-mendonca )
|
6 |
+
* removed mqtranslate switcher widget hook
|
7 |
+
* Updated the plugin structure and coding style
|
8 |
+
* solve some conflicts with search and pagination queries
|
9 |
+
* Settings php errors, syntax indent and fixed settings assets url
|
10 |
+
* Change titles when there is a click on pagination on show all pages tab ( thanks juanfran-granados )
|
11 |
+
* Formatted dependency notice message ( thanks arildm )
|
12 |
+
* Updated the deprecated jquery 'live' function and solve php strict standards error ( thanks rafitaFCB )
|
13 |
+
* Fixed error showing if PHP was newer than 5.3 ( thanks rafitaFCB )
|
14 |
+
* Strict standard advise prevented ( thanks rafitaFCB )
|
15 |
+
* php notices are prevented in post edit, when using adding new translated tags ( thanks rafitaFCB )
|
16 |
+
* fixed the hreflang issue! 'bout time!
|
17 |
+
* As discussed in issue #25, the flags are now img tags, intead of background-url.
|
18 |
+
* Added another option to include the css style in a minified file. ( and also showing in the option screen the styles we would use.)
|
19 |
+
|
20 |
= 1.1.7 =
|
21 |
* removed styles from html elements and added options to use .css file or print inline styles
|
22 |
* fixed tag creation on post edit.
|