Qtranslate Slug - Version 1.1.6

Version Description

Download this release

Release Info

Developer carlos_a_sanz
Plugin Icon wp plugin Qtranslate Slug
Version 1.1.6
Comparing to
See all releases

Code changes from version 1.1.5 to 1.1.6

Files changed (3) hide show
  1. README.txt +0 -158
  2. qtranslate-slug.php +173 -96
  3. version.txt +12 -0
README.txt DELETED
@@ -1,158 +0,0 @@
1
- === Qtranslate Slug ===
2
- Contributors: Carlos Sanz García
3
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SYC46KSLRC4Q8
4
- Tags: qtranslate, slug, multilanguage
5
- Requires at least: 3.3
6
- Tested up to: 3.5.1
7
- Version: 1.1.5
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
- * Qtranslate 2.5.8
23
-
24
- = New in version 1.1.5 =
25
-
26
- * bugfixes
27
-
28
- **Advice: If you're using a multisite installation, you will must activate qtranslate plugins by sepparetly on each site.**
29
-
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
- == Installation ==
35
-
36
- **This plugins requires [Qtranslate](http://wordpress.org/extend/plugins/qtranslate/) installed previously, if not, it will not activate.**
37
-
38
- 1. Upload `qtranslate-slug` to the `/wp-content/plugins/` directory.
39
- 1. Activate the plugin through the 'Plugins' menu in WordPress.
40
- 1. That's all!
41
-
42
- = Changing base permastructs =
43
-
44
- 1. In admin: navigate to *Settings/Slug options*.
45
- 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).
46
- 1. Save settings and that's all!
47
-
48
- == Frequently Asked Questions ==
49
-
50
- = It works with posts and pages, but with other content type? =
51
-
52
- This plugin allows to translate slugs of: posts, pages, custom post types, categories, tags and custom taxonomies.
53
-
54
- = Do I have to configure anything? =
55
-
56
- If you want to translate also the base permastructs (ex. *category*, *tag*, etc). Visit the plugin settings page in the admin *Settings/Slug options*
57
-
58
- = How can i insert a language selector in my theme ? =
59
-
60
- You can choose to:
61
- * use **Qtranslate Slug Widget** in your sidebar.
62
- * place in your template `<?php if (function_exists('qts_language_menu') ) qts_language_menu('text'); ?>`. Options are: `dropdown`, `text`, `image`, and `both`.
63
-
64
- = Appears an error 404, what can i do? =
65
-
66
- In the admin go to *Settings/Permalinks* or *Settings/Slug options* and save.
67
-
68
- = I can't manage translations in Nav Menus. =
69
-
70
- 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.
71
-
72
- == Screenshots ==
73
-
74
- 1. Edit page for: post / page / post_type, you can see the meta box for translated slugs on top and right.
75
- 2. Add new taxonomy page
76
- 3. Edit taxonomy page
77
- 4. Qtranslate Slug options page for translate base permastructs of post_types and taxonomies.
78
-
79
- == Changelog ==
80
-
81
- = 1.1.5 =
82
- * bugfixes
83
-
84
- = 1.1 =
85
- * added multisite support
86
- * fixed some parse url bugs
87
- * fixed slug bases validation
88
-
89
- = 1.0 =
90
- * **works** with any permalink combination and qtranslate mode.
91
- * 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).
92
- * 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.
93
- * the plugin generates translated slug automatically from title in empty cases.
94
- * 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.
95
- * 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.
96
- * added some filters, see in [other notes](http://wordpress.org/extend/plugins/qtranslate-slug/other_notes/).
97
- * added plugin language textdomain (.pot file).
98
- * updated **Language selector Widget**, and some new conventions like accessible functions for templating.
99
- * some bug fixes.
100
- * some Qtranslate patches.
101
-
102
- = 0.9 =
103
- * some wordpress qTranslate bug fixes
104
- * adds a javascript solution for qTranslate Nav Menus
105
-
106
- = 0.8 =
107
- * added support por Categories
108
- * added support por Tags
109
- * added support por Taxonomies
110
- * added support por Custom Post Types
111
-
112
- = 0.7 = [Zapo](http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=4&t=1049&start=50#p7499)
113
- * added suport for qTranslate TLD domain mode (en: domain.com | fr: domain.fr) visit
114
-
115
- = 0.5 and 0.6 enhanched by Marco Del Percio =
116
-
117
- == Upgrade Notice ==
118
-
119
- = 1.0 =
120
- Major version, the plugin has been rewritten. Better performance, and some enhancements.
121
-
122
- = 0.9 =
123
- This version fix some bugs and allow multilanguage in nav-menus.
124
-
125
- = 0.8 =
126
- A lot of slugs content allowed
127
-
128
- = 0.7 =
129
- This version allows TLD domain option for a different Qtranslate fork maded by Zappo
130
-
131
-
132
- == Other notes ==
133
-
134
- Plugin filters reference:
135
-
136
- = qts_validate_post_slug =
137
- filter to process the post slug before is saved on the database.
138
- `args: $post (object), $slug (string), $lang (string)`
139
-
140
- = qts_validate_term_slug =
141
- filter to process the term slug before is saved on the database.
142
- `args: $term (object), $slug (string), $lang (string)`
143
-
144
- = qts_url_args =
145
- filter to process the entire url after it has been generated.
146
- `args: $url (string), $lang (string)`
147
-
148
- = qts_permastruct =
149
- filter to process the permastruct, used for change the base.
150
- `args: $permastruct (string), $name (string)`
151
-
152
-
153
- = Todo =
154
-
155
- * detect Slug for each language and redirect accordingly in parse_query.
156
- * expand qtranslate for translate attachment names and descriptions ( useful for galleries )
157
- * translate other slugs like attachments.
158
- * qtranslate integration with other plugins like Jigoshop, e-commerce, etc. Addapt **$wp_rewrite**.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.5
7
  Author: Carlos Sanz Garcia
8
  Author URI: http://github.com/not-only-code
9
  */
@@ -258,7 +258,9 @@ class QtranslateSlug {
258
 
259
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
260
 
261
- return ( version_compare($wp_version, "3.3", "<" ) || !is_plugin_active('qtranslate/qtranslate.php') );
 
 
262
  }
263
 
264
 
@@ -316,7 +318,7 @@ class QtranslateSlug {
316
  }
317
 
318
  // regenerate rewrite rules in db
319
- add_action( 'generate_rewrite_rules', array($this, 'modify_rewrite_rules') );
320
  flush_rewrite_rules();
321
  }
322
 
@@ -331,7 +333,7 @@ class QtranslateSlug {
331
  global $wp_rewrite;
332
 
333
  // regenerate rewrite rules in db
334
- remove_action( 'generate_rewrite_rules', array($this, 'modify_rewrite_rules') );
335
  $wp_rewrite->flush_rules();
336
  }
337
 
@@ -367,8 +369,8 @@ class QtranslateSlug {
367
 
368
  echo "<div class=\"error\">" . PHP_EOL;
369
  echo "<p><strong>Qtranslate Slug:</strong></p>" . PHP_EOL;
370
- echo "<p>" . __('This plugin requires at least <strong>Wordpress 3.3</strong> and <strong>Qtranslate(2.5.8 or newer)</strong>', 'qts') . "</p>" . PHP_EOL;
371
- echo "</div>" . PHP_EOL;
372
  }
373
 
374
 
@@ -406,7 +408,7 @@ class QtranslateSlug {
406
  private function check_old_versions() {
407
 
408
  if ( $this->check_old_data() )
409
- add_action('admin_notices', array($this, 'notice_update'));
410
  }
411
 
412
 
@@ -423,7 +425,7 @@ class QtranslateSlug {
423
  // checking plugin activate
424
  if ( self::block_activate() ) {
425
  if (is_admin())
426
- add_action('admin_notices', array($this, 'notice_dependences'));
427
  return;
428
  }
429
 
@@ -435,33 +437,34 @@ class QtranslateSlug {
435
  $this->check_old_versions();
436
 
437
  // add filters
438
- add_filter( 'term_name', array($this, 'term_name'), 0, 2 );
439
- add_filter( 'qts_validate_post_slug', array($this, 'validate_post_slug'), 0, 3 );
440
- add_filter( 'qts_validate_post_slug', array($this, 'unique_post_slug'), 1, 3 );
441
- add_filter( 'qts_validate_term_slug', array($this, 'validate_term_slug'), 0, 3 );
442
- add_filter( 'qts_validate_term_slug', array($this, 'unique_term_slug'), 1, 3 );
 
443
 
444
  // admin actions
445
- add_action( 'admin_menu', array($this, 'add_slug_meta_box') );
446
- add_action( 'save_post', array($this, 'save_postdata'), 605, 2 );
447
- add_action( 'delete_term', array($this, 'delete_term'), 0, 3);
448
- add_action( 'created_term', array($this, 'save_term'), 605, 3);
449
- add_action( 'edited_term', array($this, 'save_term'), 605, 3 );
450
- add_action( 'admin_head', array($this, 'hide_slug_box'), 900 );
451
 
452
- add_action( 'init', array($this, 'taxonomies_hooks'), 805 );
453
 
454
- add_action( 'wp_dashboard_setup', array($this, 'remove_dashboard_widgets') );
455
- add_action( 'admin_head', array($this, 'hide_quick_edit'), 600 );
456
- add_action( 'admin_init', array($this, 'fix_nav_menu') );
457
 
458
  } else {
459
 
460
- add_filter( 'request', array($this, 'filter_request') );
461
  }
462
 
463
- add_filter( 'query_vars', array($this, 'query_vars'));
464
- add_action( 'generate_rewrite_rules', array($this, 'modify_rewrite_rules') );
465
 
466
  // remove some Qtranslate filters
467
  remove_filter( 'page_link', 'qtrans_convertURL' );
@@ -469,21 +472,32 @@ class QtranslateSlug {
469
  remove_filter( 'category_link', 'qtrans_convertURL' );
470
  remove_filter( 'tag_link', 'qtrans_convertURL' );
471
 
472
- add_filter( 'qts_permastruct' , array($this, 'get_extra_permastruct'), 0, 2);
473
- add_filter( 'qts_url_args', array($this, 'parse_url_args'), 0, 1);
474
- add_filter( 'home_url', array($this, 'home_url'), 10, 4);
475
- add_filter( 'post_type_link', array($this, 'post_type_link'), 600, 4 );
476
- add_filter( 'post_link', array($this, 'post_link'), 0, 3 );
477
- add_filter( '_get_page_link', array($this, '_get_page_link'), 0, 2 );
478
- add_filter( 'term_link', array($this, 'term_link'), 600, 3 );
479
 
480
  add_filter( 'single_term_title', 'qtrans_useTermLib', 805 );
481
- add_filter( 'get_blogs_of_user', array($this, 'blog_names'), 1 );
482
- add_action( 'widgets_init', array($this, 'widget_init'), 100 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
483
  }
484
-
485
-
486
-
487
  /**
488
  * Adds news rules to translate the URL bases, this function must be called on flush_rewrite or 'flush_rewrite_rules'
489
  *
@@ -620,8 +634,8 @@ class QtranslateSlug {
620
  // rebulid query with all args
621
  $url = add_query_arg($base_args, $url);
622
 
623
- $url = str_replace('/?', '?', $url); // hack: improve this code
624
- $url = str_replace('?', '/?', $url); // hack: improve this code
625
 
626
  return $url;
627
  }
@@ -676,6 +690,8 @@ class QtranslateSlug {
676
  $req_uri = trim($req_uri, '/');
677
  $req_uri = preg_replace("|^$home_path|", '', $req_uri);
678
  $req_uri = trim($req_uri, '/');
 
 
679
  $pathinfo = trim($pathinfo, '/');
680
  $pathinfo = preg_replace("|^$home_path|", '', $pathinfo);
681
  $pathinfo = trim($pathinfo, '/');
@@ -789,7 +805,7 @@ class QtranslateSlug {
789
 
790
  $page = wp_cache_get('qts_page_request');
791
  if (!$page)
792
- $page = isset($query['page_id']) ? get_page($query['page_id']) : $this->get_page_by_path($query['pagename']);
793
 
794
  if (!$page) return $query;
795
  $id = $page->ID;
@@ -872,6 +888,14 @@ class QtranslateSlug {
872
 
873
  endif;
874
 
 
 
 
 
 
 
 
 
875
  if ( isset($function) ):
876
 
877
  // parse all languages links
@@ -1010,7 +1034,7 @@ class QtranslateSlug {
1010
 
1011
  $foundid = $this->get_page_id_by_path($page_path, $output, $post_type);
1012
  if ( $foundid )
1013
- return get_page( $foundid, $output );
1014
 
1015
  return null;
1016
  }
@@ -1302,7 +1326,11 @@ class QtranslateSlug {
1302
  if ( !$id )
1303
  $id = (int) $post->ID;
1304
  else
 
 
 
1305
  $current_post = &get_post($id);
 
1306
 
1307
  $draft_or_pending = in_array( $current_post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
1308
 
@@ -1341,7 +1369,7 @@ class QtranslateSlug {
1341
  private function get_page_uri($page) {
1342
 
1343
  if ( ! is_object($page) )
1344
- $page = get_page($page);
1345
 
1346
  $uri = get_post_meta( $page->ID, $this->get_meta_key(), true );
1347
  if (!$uri) $uri = $page->post_name;
@@ -1351,7 +1379,7 @@ class QtranslateSlug {
1351
  return $uri;
1352
 
1353
  while ($page->post_parent != 0) {
1354
- $page = get_page($page->post_parent);
1355
 
1356
  $page_name = get_post_meta( $page->ID, $this->get_meta_key(), true );
1357
  if (!$page_name) $page_name = $page->post_name;
@@ -1439,12 +1467,12 @@ class QtranslateSlug {
1439
  /**
1440
  * Get all Term data from database by Term field and data.
1441
  *
1442
- * @param string $field Either 'slug', 'name', or 'id'
1443
- * @param string|int $value Search for this term value
1444
- * @param string $taxonomy Taxonomy Name
1445
- * @param string $output Constant OBJECT, ARRAY_A, or ARRAY_N
1446
- * @param string $filter Optional, default is raw or no WordPress defined filter will applied.
1447
- * @return mixed Term Row from database. Will return false if $taxonomy does not exist or $term was not found.
1448
  *
1449
  * @since 1.0
1450
  */
@@ -1498,9 +1526,92 @@ class QtranslateSlug {
1498
  return $term;
1499
  }
1500
  }
1501
-
1502
-
1503
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1504
  /**
1505
  * hide quickedit button ( functionality not supported by qTranslate )
1506
  *
@@ -1556,11 +1667,11 @@ class QtranslateSlug {
1556
 
1557
  if ( function_exists( 'add_meta_box' ) ) {
1558
 
1559
- add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array($this, 'draw_meta_box'), 'post', 'side', 'high');
1560
- add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array($this, 'draw_meta_box'), 'page', 'side', 'high' );
1561
 
1562
  foreach ( get_post_types( array('_builtin' => false ) ) as $ptype )
1563
- add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array($this, 'draw_meta_box'), $ptype, 'side', 'high' );
1564
  }
1565
  }
1566
 
@@ -1942,10 +2053,10 @@ class QtranslateSlug {
1942
  foreach ($taxonomies as $taxonomy ) {
1943
  add_action( $taxonomy->name.'_add_form', 'qtrans_modifyTermFormFor');
1944
  add_action( $taxonomy->name.'_edit_form', 'qtrans_modifyTermFormFor');
1945
- add_action( $taxonomy->name.'_add_form', array($this, 'show_term_fields'));
1946
- add_action( $taxonomy->name.'_edit_form_fields', array($this, 'show_term_fields') );
1947
- add_filter('manage_edit-'.$taxonomy->name.'_columns', array($this, 'taxonomy_columns'));
1948
- add_filter('manage_'.$taxonomy->name.'_custom_column', array($this, 'taxonomy_custom_column'), 0, 3);
1949
  }
1950
  }
1951
  }
@@ -1986,40 +2097,6 @@ class QtranslateSlug {
1986
 
1987
 
1988
 
1989
- /**
1990
- * Bug fix for taxonomy names in wp_terms_list_table
1991
- *
1992
- * @param string $name parsed term name
1993
- * @param object $tag term object
1994
- * @return string translated term name
1995
- *
1996
- * @since 1.0
1997
- */
1998
- function term_name($name, $tag) {
1999
-
2000
- $backtrace = debug_backtrace();
2001
-
2002
- foreach ( $backtrace as $tracepoint ) {
2003
-
2004
- // post page column
2005
- if ( isset($tracepoint['function']) && $tracepoint['function'] == 'sanitize_term_field' ) {
2006
- return apply_filters('single_term_title', $name);
2007
- }
2008
-
2009
- // term page column
2010
- if ( isset($tracepoint['class']) && $tracepoint['class'] == 'WP_Terms_List_Table' ) {
2011
- $name_array = explode('&#8212; ', $name);
2012
- array_pop($name_array);
2013
- array_push($name_array, apply_filters('single_term_title', $tag->name));
2014
- return implode('&#8212; ', $name_array);
2015
- }
2016
-
2017
- }
2018
-
2019
- return $name;
2020
- }
2021
-
2022
-
2023
 
2024
  /**
2025
  * Bug fix for multisite blog names
@@ -2074,7 +2151,7 @@ class QtranslateSlug {
2074
  if( $pagenow != 'nav-menus.php' ) return;
2075
 
2076
  wp_enqueue_script( 'nav-menu-query', plugins_url( 'assets/js/qts-nav-menu-min.js' , __FILE__ ) , 'nav-menu', '1.0' );
2077
- add_meta_box( 'qt-languages', __('Languages'), array($this, 'nav_menu_meta_box'), 'nav-menus', 'side', 'default' );
2078
  }
2079
 
2080
 
@@ -2321,4 +2398,4 @@ function qts_uninstall() {
2321
  foreach ($q_config['enabled_languages'] as $lang) $meta_keys[] = sprintf("_qts_slug_%s", $lang);
2322
  $meta_keys = "'". implode( "','", $meta_keys ) . "'";
2323
  $wpdb->query("DELETE from $wpdb->postmeta WHERE meta_key IN ($meta_keys)");
2324
- }
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.6
7
  Author: Carlos Sanz Garcia
8
  Author URI: http://github.com/not-only-code
9
  */
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
 
318
  }
319
 
320
  // regenerate rewrite rules in db
321
+ add_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
322
  flush_rewrite_rules();
323
  }
324
 
333
  global $wp_rewrite;
334
 
335
  // regenerate rewrite rules in db
336
+ remove_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
337
  $wp_rewrite->flush_rules();
338
  }
339
 
369
 
370
  echo "<div class=\"error\">" . PHP_EOL;
371
  echo "<p><strong>Qtranslate Slug:</strong></p>" . PHP_EOL;
372
+ 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;
373
+ echo "</div>" . PHP_EOL;
374
  }
375
 
376
 
408
  private function check_old_versions() {
409
 
410
  if ( $this->check_old_data() )
411
+ add_action('admin_notices', array(&$this, 'notice_update'));
412
  }
413
 
414
 
425
  // checking plugin activate
426
  if ( self::block_activate() ) {
427
  if (is_admin())
428
+ add_action('admin_notices', array(&$this, 'notice_dependences'));
429
  return;
430
  }
431
 
437
  $this->check_old_versions();
438
 
439
  // add filters
440
+ add_filter( 'qts_validate_post_slug', array(&$this, 'validate_post_slug'), 0, 3 );
441
+ add_filter( 'qts_validate_post_slug', array(&$this, 'unique_post_slug'), 1, 3 );
442
+ add_filter( 'qts_validate_term_slug', array(&$this, 'validate_term_slug'), 0, 3 );
443
+ add_filter( 'qts_validate_term_slug', array(&$this, 'unique_term_slug'), 1, 3 );
444
+ add_filter( 'wp_get_object_terms', array(&$this, 'get_object_terms'), 0, 4 );
445
+ add_filter( 'get_terms', array(&$this, 'get_terms'), 0, 3 );
446
 
447
  // admin actions
448
+ add_action( 'admin_menu', array(&$this, 'add_slug_meta_box') );
449
+ add_action( 'save_post', array(&$this, 'save_postdata'), 605, 2 );
450
+ add_action( 'delete_term', array(&$this, 'delete_term'), 0, 3);
451
+ add_action( 'created_term', array(&$this, 'save_term'), 605, 3);
452
+ add_action( 'edited_term', array(&$this, 'save_term'), 605, 3 );
453
+ add_action( 'admin_head', array(&$this, 'hide_slug_box'), 900 );
454
 
455
+ add_action( 'init', array(&$this, 'taxonomies_hooks'), 805 );
456
 
457
+ add_action( 'wp_dashboard_setup', array(&$this, 'remove_dashboard_widgets') );
458
+ add_action( 'admin_head', array(&$this, 'hide_quick_edit'), 600 );
459
+ add_action( 'admin_init', array(&$this, 'fix_nav_menu') );
460
 
461
  } else {
462
 
463
+ add_filter( 'request', array(&$this, 'filter_request') );
464
  }
465
 
466
+ add_filter( 'query_vars', array(&$this, 'query_vars'));
467
+ add_action( 'generate_rewrite_rules', array(&$this, 'modify_rewrite_rules') );
468
 
469
  // remove some Qtranslate filters
470
  remove_filter( 'page_link', 'qtrans_convertURL' );
472
  remove_filter( 'category_link', 'qtrans_convertURL' );
473
  remove_filter( 'tag_link', 'qtrans_convertURL' );
474
 
475
+ add_filter( 'qts_permastruct' , array(&$this, 'get_extra_permastruct'), 0, 2);
476
+ add_filter( 'qts_url_args', array(&$this, 'parse_url_args'), 0, 1);
477
+ add_filter( 'home_url', array(&$this, 'home_url'), 10, 4);
478
+ add_filter( 'post_type_link', array(&$this, 'post_type_link'), 600, 4 );
479
+ add_filter( 'post_link', array(&$this, 'post_link'), 0, 3 );
480
+ add_filter( '_get_page_link', array(&$this, '_get_page_link'), 0, 2 );
481
+ add_filter( 'term_link', array(&$this, 'term_link'), 600, 3 );
482
 
483
  add_filter( 'single_term_title', 'qtrans_useTermLib', 805 );
484
+ add_filter( 'get_blogs_of_user', array(&$this, 'blog_names'), 1 );
485
+ add_action( 'widgets_init', array(&$this, 'widget_init'), 100 );
486
+ // Add specific CSS class to body class based on current lang
487
+ add_filter('body_class', array($this, 'qts_body_class'), 600, 1 );
488
+ }
489
+
490
+
491
+ /**
492
+ * Add a class based on the current language
493
+ * @param array $classes list of classes
494
+ */
495
+ public function qts_body_class( $classes ) {
496
+ // add 'class-name' to the $classes array
497
+ $classes[] = qtrans_getLanguage();
498
+ // return the $classes array
499
+ return $classes;
500
  }
 
 
 
501
  /**
502
  * Adds news rules to translate the URL bases, this function must be called on flush_rewrite or 'flush_rewrite_rules'
503
  *
634
  // rebulid query with all args
635
  $url = add_query_arg($base_args, $url);
636
 
637
+ $url = str_replace('/?', '?', $url); // TODO: hack: improve this code
638
+ $url = str_replace('?', '/?', $url); // TODO: hack: improve this code
639
 
640
  return $url;
641
  }
690
  $req_uri = trim($req_uri, '/');
691
  $req_uri = preg_replace("|^$home_path|", '', $req_uri);
692
  $req_uri = trim($req_uri, '/');
693
+ if ($GLOBALS['q_config']['url_mode'] == QT_URL_PATH)
694
+ $req_uri = preg_replace("/^{$GLOBALS['q_config']['language']}(\/|$)/", '', $req_uri);
695
  $pathinfo = trim($pathinfo, '/');
696
  $pathinfo = preg_replace("|^$home_path|", '', $pathinfo);
697
  $pathinfo = trim($pathinfo, '/');
805
 
806
  $page = wp_cache_get('qts_page_request');
807
  if (!$page)
808
+ $page = isset($query['page_id']) ? get_post($query['page_id']) : $this->get_page_by_path($query['pagename']);
809
 
810
  if (!$page) return $query;
811
  $id = $page->ID;
888
 
889
  endif;
890
 
891
+ // -> search
892
+ if(isset($query['s'])):
893
+
894
+ $id=$query['s'];
895
+ $function="get_search_link";
896
+
897
+ endif;
898
+
899
  if ( isset($function) ):
900
 
901
  // parse all languages links
1034
 
1035
  $foundid = $this->get_page_id_by_path($page_path, $output, $post_type);
1036
  if ( $foundid )
1037
+ return get_post( $foundid, $output );
1038
 
1039
  return null;
1040
  }
1326
  if ( !$id )
1327
  $id = (int) $post->ID;
1328
  else
1329
+ if(phpversion() >= 5.4) {
1330
+ $current_post = get_post($id);
1331
+ } else {
1332
  $current_post = &get_post($id);
1333
+ }
1334
 
1335
  $draft_or_pending = in_array( $current_post->post_status, array( 'draft', 'pending', 'auto-draft' ) );
1336
 
1369
  private function get_page_uri($page) {
1370
 
1371
  if ( ! is_object($page) )
1372
+ $page = get_post($page);
1373
 
1374
  $uri = get_post_meta( $page->ID, $this->get_meta_key(), true );
1375
  if (!$uri) $uri = $page->post_name;
1379
  return $uri;
1380
 
1381
  while ($page->post_parent != 0) {
1382
+ $page = get_post($page->post_parent);
1383
 
1384
  $page_name = get_post_meta( $page->ID, $this->get_meta_key(), true );
1385
  if (!$page_name) $page_name = $page->post_name;
1467
  /**
1468
  * Get all Term data from database by Term field and data.
1469
  *
1470
+ * @param (string) $field Either 'slug', 'name', or 'id'
1471
+ * @param (string|int) $value Search for this term value
1472
+ * @param (string) $taxonomy Taxonomy Name
1473
+ * @param (string) $output Constant OBJECT, ARRAY_A, or ARRAY_N
1474
+ * @param (string) $filter Optional, default is raw or no WordPress defined filter will applied.
1475
+ * @return (mixed) Term Row from database. Will return false if $taxonomy does not exist or $term was not found.
1476
  *
1477
  * @since 1.0
1478
  */
1526
  return $term;
1527
  }
1528
  }
1529
+
1530
+
1531
+
1532
+ /**
1533
+ * Fix for:
1534
+ * - Taxonomy names in Taxonomy Manage page
1535
+ * - 'Popular Tags' in Taxonomy (Tags) Manage page
1536
+ * - Category filter dropdown menu in Post Manage page
1537
+ * - Category list in Post Edit page
1538
+ * - 'Most Used' tags list in Post Edit page (but have issues when saving)
1539
+ *
1540
+ * @param (array) $terms
1541
+ * @param (string|array) $taxonomy
1542
+ * @since 1.2
1543
+ */
1544
+ function get_terms($terms, $taxonomy) {
1545
+
1546
+ global $pagenow;
1547
+
1548
+ // Although in post edit page the tags in 'most
1549
+ // used' list are translated, but when saving the
1550
+ // post Wordpess considers the translated tags as
1551
+ // new tags. Due to this issue I skip this 'hack'
1552
+ // for tags in post edit page.
1553
+ if ( $pagenow != 'admin-ajax.php' ) {
1554
+
1555
+ $meta = get_option('qtranslate_term_name');
1556
+ $lang = qtrans_getLanguage();
1557
+
1558
+ if ( !empty( $terms ) ) {
1559
+ foreach ($terms as $term) {
1560
+ if ($meta[$term->name][$lang]) {
1561
+ $term->name = $meta[$term->name][$lang];
1562
+ }
1563
+ };
1564
+ };
1565
+ }
1566
+
1567
+ return $terms;
1568
+ }
1569
+
1570
+
1571
+
1572
+ /**
1573
+ * Fix for:
1574
+ * - Taxonomy & custom taxonomy names in Post Manage page
1575
+ * - List of tags already added to the post in Post
1576
+ * - Edit page (but have issues when saving)
1577
+ *
1578
+ * @param (array) $terms
1579
+ * @param (int|array) $obj_id
1580
+ * @param (string|array) $taxonomy
1581
+ * @param (array) $taxonomy
1582
+ * @since 1.2
1583
+ */
1584
+ function get_object_terms($terms, $obj_id, $taxonomy, $args) {
1585
+
1586
+ global $pagenow;
1587
+
1588
+ // Although in post edit page the tags are translated,
1589
+ // but when saving/updating the post Wordpess considers
1590
+ // the translated tags as new tags. Due to this
1591
+ // issue I limit this 'hack' to the post manage
1592
+ // page only.
1593
+ if ( $pagenow == 'edit.php' ) {
1594
+
1595
+ // $taxonomy output seems to be wrapped
1596
+ // in single quotes, thus remove them to
1597
+ // make the output valid
1598
+ $tax = str_replace("'", "", $taxonomy);
1599
+
1600
+ $meta = get_option('qtranslate_term_name');
1601
+ $lang = qtrans_getLanguage();
1602
+
1603
+ if ( !empty( $terms ) ) {
1604
+ foreach ($terms as $term) {
1605
+ $term->name = $meta[$term->name][$lang];
1606
+ };
1607
+ };
1608
+
1609
+ }
1610
+ return $terms;
1611
+ }
1612
+
1613
+
1614
+
1615
  /**
1616
  * hide quickedit button ( functionality not supported by qTranslate )
1617
  *
1667
 
1668
  if ( function_exists( 'add_meta_box' ) ) {
1669
 
1670
+ add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), 'post', 'side', 'high');
1671
+ add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), 'page', 'side', 'high' );
1672
 
1673
  foreach ( get_post_types( array('_builtin' => false ) ) as $ptype )
1674
+ add_meta_box( 'qts_sectionid', __('Slug', 'qts'), array(&$this, 'draw_meta_box'), $ptype, 'side', 'high' );
1675
  }
1676
  }
1677
 
2053
  foreach ($taxonomies as $taxonomy ) {
2054
  add_action( $taxonomy->name.'_add_form', 'qtrans_modifyTermFormFor');
2055
  add_action( $taxonomy->name.'_edit_form', 'qtrans_modifyTermFormFor');
2056
+ add_action( $taxonomy->name.'_add_form', array(&$this, 'show_term_fields'));
2057
+ add_action( $taxonomy->name.'_edit_form_fields', array(&$this, 'show_term_fields') );
2058
+ add_filter('manage_edit-'.$taxonomy->name.'_columns', array(&$this, 'taxonomy_columns'));
2059
+ add_filter('manage_'.$taxonomy->name.'_custom_column', array(&$this, 'taxonomy_custom_column'), 0, 3);
2060
  }
2061
  }
2062
  }
2097
 
2098
 
2099
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2100
 
2101
  /**
2102
  * Bug fix for multisite blog names
2151
  if( $pagenow != 'nav-menus.php' ) return;
2152
 
2153
  wp_enqueue_script( 'nav-menu-query', plugins_url( 'assets/js/qts-nav-menu-min.js' , __FILE__ ) , 'nav-menu', '1.0' );
2154
+ add_meta_box( 'qt-languages', __('Languages'), array(&$this, 'nav_menu_meta_box'), 'nav-menus', 'side', 'default' );
2155
  }
2156
 
2157
 
2398
  foreach ($q_config['enabled_languages'] as $lang) $meta_keys[] = sprintf("_qts_slug_%s", $lang);
2399
  $meta_keys = "'". implode( "','", $meta_keys ) . "'";
2400
  $wpdb->query("DELETE from $wpdb->postmeta WHERE meta_key IN ($meta_keys)");
2401
+ }
version.txt CHANGED
@@ -1,3 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
  = 1.0 =
2
  * 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.
3
  * structural changes:
1
+ = 1.1.6 =
2
+ * compatible with mqtranslate
3
+ * php5.4+ compatible
4
+
5
+ = 1.1.5 =
6
+ * bugfixes
7
+
8
+ = 1.1 =
9
+ * added multisite support
10
+ * fixed some parse url bugs
11
+ * fixed slug bases validation
12
+
13
  = 1.0 =
14
  * 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.
15
  * structural changes: