<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam a risus. Quisque accumsan ligula ac neque. Curabitur a turpis. Fusce nisi. Quisque adipiscing. Sed quis diam sed felis lacinia accumsan. Aliquam adipiscing. Proin vehicula convallis ante. Nulla orci lacus, eleifend sed, ultricies non, porttitor at, leo. Nunc est nibh, varius at, eleifend et, consectetur non, leo. <a href="http://google.com">Nulla faucibus orci et nisl</a>. Proin bibendum felis.</p>
<p>\r\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam a risus.\r\nQuisque accumsan ligula ac neque. Curabitur a turpis. Fusce nisi.\r\nQuisque adipiscing. Sed quis diam sed felis lacinia accumsan. Aliquam\r\nadipiscing. Proin vehicula convallis ante. Nulla orci lacus, eleifend\r\nsed, ultricies non, porttitor at, leo. Nunc est nibh, varius at,\r\neleifend et, consectetur non, leo. <a href="%5C%22http://google.com%5C%22">Nulla faucibus orci et nisl</a>. Proin bibendum felis.\r\n</p>
FYI, %5C%22 is URL-encoded \" (backslash + double quote).
-> http://www.blooberry.com/indexdot/html/topics/urlencoding.htm
TinyMCE is adding the extraneous material. You can most likely change the TinyMCS configuration so that it doesn’t do that or you can just turn the RTE off and edit the raw HTML which will be saved as is.
Here’s some info on configuring TinyMCE:
http://wiki.modxcms.com/index.php/How_to_Get_TinyMCE_to_Format_HTML_Source_Correctly_in_TinyMCE_2.0.6.1
http://wiki.moxiecode.com/index.php/TinyMCE:Configuration
Well, \" is essentially what addslashes() does. Because of all the JS/Ajax stuff going on in the manager, maybe the URL-encoding is necessary.
Try stripslashes() + urldecode()?
If you want to continue using RTE, try setting tinyMCE entity encoding to "raw" in the plugin settings.
<?php global $content; //get raw posted content $myContent = $_POST['ta']; //your plugin processing here... $content = $modx->db->escape($myContent); //get out of here.... ?>
Quote from: BobRay at May 03, 2009, 12:10 PM
TinyMCE is adding the extraneous material. You can most likely change the TinyMCS configuration so that it doesn’t do that or you can just turn the RTE off and edit the raw HTML which will be saved as is.
Here’s some info on configuring TinyMCE:
http://wiki.modxcms.com/index.php/How_to_Get_TinyMCE_to_Format_HTML_Source_Correctly_in_TinyMCE_2.0.6.1
http://wiki.moxiecode.com/index.php/TinyMCE:Configuration
My bad. I would have bet it was TinyMCE.
I disabled the TinyMCE plugin and get the same results, it’s not the editor. Modx is doing some sort of encoding before the OnBeforeDocFormSaved is called. Is there anyway to "undo" this and then when I am done modifying it I can re-encode it?
First of all using ereg here is inappropriate, a simple str_replace would be much faster.Furthermore in an ereg the backslashes have special meaning so for ereg_replace ’\r\n’ is not the same a the string ’\r\n’.
The ’\r\n’ are a result of the content being escaped with mysql_real_escape_string (via $modx->db->escape).
You can try two things...
1. Use $content=str_replace(’\r\n’,"\r\n",$content);
This will at least let php recognize them as proper newline characters when you apply stripslashes().
2. Act on the raw posted data instead of $content.
<?php global $content; //get raw posted content $myContent = $_POST['ta']; //your plugin processing here... $content = $modx->db->escape($myContent); //get out of here.... ?>
The disadvantage (and it is a big one) is that if you have more than one plugin acting on the OnBeforeDocFormSave event the results may not be what you expect.