Content Duplication Bug

Having Problems? Need Help? Post here!

Re: Content Duplication Bug

Postby NickLW » Tue Mar 13, 2012 5:40 pm

Aneon wrote:Please try this fix, it worked for me:
http://wordpress.stackexchange.com/ques ... 5371#45371


Hi Aneon

Just tried your fix, thanks.

It works better for me than Kokarn's fix but still doesn't completely solve the problem.

Good news is that with your fix, I don't have to avoid <p> or <h> tags in the first line of html text. As long as I stick to only saving in HTML, then your fix seems to work - I've run one test 10 times in a row with no problems.

But I've also found how to consistently break qTranslate pages despite your fix.

Here are my details:

My site is set up for 6 languages but I'm currently only using two: English and Norwegian (with English as the main language). The other four languages are completely blank for the moment - even the titles. Both my English and Norwegian content are structurally the same: The first line has <h> tags in it. The rest has paragraph text.

The test I did was this:

I opened the page and saved it in HTML. Then I clicked on the Visual tab and saved it again. Then I clicked on the HTML tab. I discovered that the Norwegian text had dropped down a space and that the four formerly blank languages now had
Code: Select all
&nbsp;
in their content. I then saved in HTML with the Norwegian tab on display. The result was that the Norwegian content was replaced with English content.

I have been able to replicate this fault at least 10 times in a row.

The lesson seems to be: Never save in Visual mode. If you need to check pages in Visual mode, only do it after saving in HTML first.
However I'd still like to hear if anyone out there can either confirm or disprove my findings?
NickLW
 
Posts: 29
Joined: Wed Feb 24, 2010 6:18 pm

Re: Content Duplication Bug

Postby Aneon » Wed Mar 14, 2012 12:25 am

Hi, glad the fix works.

That's an interesting bug you found. I'm not sure it's related to the other bug, although it's certainly a problem with qTranslate. I spent some time trying to trace it down, but it's trickier than the first so I've not found a fix.

For me (using two languages), the bug triggers when you load the edit page in Visual mode for the main language, switch to HTML mode, then switch to another language. It inserts a line break at the top just like you say. If you save the post when you see this line break, the content gets replaced with the main language's content.

However, I believe this is only a problem when you save in HTML mode, so I would actually recommend to never save in HTML mode. For me at least, if I always switch to Visual mode before saving then this is not a problem. Could you confirm this on your site as well?
Aneon
 
Posts: 5
Joined: Tue Mar 13, 2012 2:34 am

Re: Content Duplication Bug

Postby Aneon » Wed Mar 14, 2012 2:59 am

Ok, I got something.

Try this fix:

In /wp-content/plugins/qtranslate/qtranslate_javascript.php, find this code:

Code: Select all
$q_config['js']['qtrans_hook_on_tinyMCE'] = "
      qtrans_hook_on_tinyMCE = function(id) {
         tinyMCEPreInit.mceInit[id].setup = function(ed) {
            ed.onSaveContent.add(function(ed, o) {
                  qtrans_save(switchEditors.pre_wpautop(o.content));
            });
         };
         ed = new tinymce.Editor(id, tinyMCEPreInit.mceInit[id]);
         ed.render();
      }
      ";

And change it into:

Code: Select all
$q_config['js']['qtrans_hook_on_tinyMCE'] = "
      qtrans_hook_on_tinyMCE = function(id) {
         tinyMCEPreInit.mceInit[id].setup = function(ed) {
            ed.onSaveContent.add(function(ed, o) {
               if (!ed.isHidden())  {
                  qtrans_save(switchEditors.pre_wpautop(o.content));
               }
            });
         };
         ed = new tinymce.Editor(id, tinyMCEPreInit.mceInit[id]);
         ed.render();
      }
      ";

This should fix the content duplication bug (changing language tab when in html mode replaces content on post save).



For the new line bug (new line is sometimes added on top of content), please try the following fix:

In /wp-content/plugins/qtranslate/qtranslate_javascript.php, find this code:

Code: Select all
$q_config['js']['qtrans_disable_old_editor'] = "
      var waitForTinyMCE = window.setInterval(function() {
            if(typeof(tinyMCE) !== 'undefined' && typeof(tinyMCE.get2) == 'function' && tinyMCE.get2('content')!=undefined) {
               tinyMCE.get2('content').remove();
               window.clearInterval(waitForTinyMCE);
            }
            
         }, 250);
      ";

Replace with:

Code: Select all
$q_config['js']['qtrans_disable_old_editor'] = "
      var waitForTinyMCE = window.setInterval(function() {
            if(typeof(tinyMCE) !== 'undefined' && typeof(tinyMCE.get2) == 'function' && tinyMCE.get2('content')!=undefined) {
               content=jQuery('#content').val();
               tinyMCE.get2('content').remove();
               jQuery('#content').val(content);
               window.clearInterval(waitForTinyMCE);
            }
            
         }, 250);
      ";
Aneon
 
Posts: 5
Joined: Tue Mar 13, 2012 2:34 am

Re: Content Duplication Bug

Postby Coksnuss » Wed Mar 14, 2012 8:33 am

Aneon wrote:Ok, I got something.

Try this fix:
[...]


Phenomenal! This works pretty good! Thank you!
Coksnuss
 
Posts: 4
Joined: Wed Feb 22, 2012 10:16 am

Re: Content Duplication Bug

Postby roshaw » Wed Mar 14, 2012 9:59 am

Aneon wrote:Ok, I got something.

Try this fix:

In /wp-content/plugins/qtranslate/qtranslate_javascript.php, find this code:

Code: Select all
$q_config['js']['qtrans_hook_on_tinyMCE'] = "
      qtrans_hook_on_tinyMCE = function(id) {
         tinyMCEPreInit.mceInit[id].setup = function(ed) {
            ed.onSaveContent.add(function(ed, o) {
                  qtrans_save(switchEditors.pre_wpautop(o.content));
            });
         };
         ed = new tinymce.Editor(id, tinyMCEPreInit.mceInit[id]);
         ed.render();
      }
      ";

And change it into:

Code: Select all
$q_config['js']['qtrans_hook_on_tinyMCE'] = "
      qtrans_hook_on_tinyMCE = function(id) {
         tinyMCEPreInit.mceInit[id].setup = function(ed) {
            ed.onSaveContent.add(function(ed, o) {
               if (!ed.isHidden())  {
                  qtrans_save(switchEditors.pre_wpautop(o.content));
               }
            });
         };
         ed = new tinymce.Editor(id, tinyMCEPreInit.mceInit[id]);
         ed.render();
      }
      ";

This should fix the content duplication bug (changing language tab when in html mode replaces content on post save).


When I try this my Visual editor looks like HTML editor without all buttons on the top !!!
When I upload with FTP original file all is OK.
roshaw
 
Posts: 4
Joined: Tue Mar 08, 2011 3:01 pm

Re: Content Duplication Bug

Postby Bev » Wed Mar 14, 2012 12:43 pm

Awesome work Aneon! The plugin is looking pretty solid now.
Bev
 
Posts: 6
Joined: Mon Mar 21, 2011 7:59 pm

Re: Content Duplication Bug

Postby NickLW » Wed Mar 14, 2012 1:00 pm

Aneon wrote:Ok, I got something.

Try this fix:


Hi Aneon

Many thanks for your 2 new fixes. I'm hesitant to say this but I THINK IT WORKS!

I've run my previous test again (the one which previously consistently broke qTranslate Pages). I tried it 10 times in a row - without causing any problems. So - great news!

Just a few observations:

Saving alternately between Visual and HTML mode still produces some weird things in the HTML text - but fortunately, nothing that appears to affect the pages. Every time I saved in Visual then viewed the page in HTML - I would see <p> tags added for each paragraph. Then once I'd saved in HTML these would disappear. The four blank pages went through a bewildering sequence of added code. I can't remember the order but they would alternate between &nbsp; to <p> to <br /> and back again.

On the 8th saving, the second language dropped down a line in the HTML code. In the past, if it is then re-saved in HTML then the second language is replaced with the first. I was convinced your fix had failed. However when I re-saved it in HTML the text stayed the same - still dropped down a line but, of course, that did not affect the way the page appears to the public.

Just one more thing: It's a bit academic now but before you came up with your two new fixes, you asked me to test your theory that the best thing was to only save in Visual mode. I was surprised by this suggestion because time and time again you come across people in WordPress blogs insisting that you should only save in HTML and should abandon the Visual editor completely. Anyway, I tested your theory and agree you are right. I tested it 10 times and on the 6th, 8th and 10th occasion the HTML text dropped down a line in the second language. However, as soon as I'd re-saved in Visual mode, the text jumped back up again.

So, once again, thank you for all your help. Much appreciated!
NickLW
 
Posts: 29
Joined: Wed Feb 24, 2010 6:18 pm

Re: Content Duplication Bug

Postby itsmir » Wed Mar 14, 2012 1:10 pm

Aneon wrote:Ok, I got something.

Try this fix:


Thank you, thank you, thank you. This appears to solve the content duplication for me. I haven't yet tested it thoroughly, but am working in visual mode with no issues so far. Happy that I can finally hand over the site to the user :) :)
itsmir
 
Posts: 10
Joined: Mon Jan 09, 2012 7:38 am

Re: Content Duplication Bug

Postby warenhaus » Wed Mar 14, 2012 4:39 pm

Aneon wrote:Ok, I got something.

thank you!
warenhaus
 
Posts: 15
Joined: Wed Apr 06, 2011 4:32 pm

Re: Content Duplication Bug

Postby roshaw » Thu Mar 15, 2012 7:04 am

warenhaus wrote:
Aneon wrote:Ok, I got something.

thank you!


?!?!? Am I the only one with problem ?!?! Can somebody help me ?
roshaw
 
Posts: 4
Joined: Tue Mar 08, 2011 3:01 pm

PreviousNext

Return to qTranslate Support Forum

Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot] and 4 guests