Have you ever found yourself having started a Drupal site, entered content and then yourself or your customer decides they suddenly want to implement TinyMCE as a WYSIWYG editor? If so, you may have found out the hard way that when you open content that was already entered before enabling TinyMCE, in TinyMCE itself, all our paragraphs and breaks are missing.
Well fear not. This is actually behaviour that is intended between the automatic line break feature of Drupal and the consequences of this in TinyMCE. See in Drupal, prior to installing TinyMCE, your content body and teasers were probably stored something like this in the database:
Note the regular line feeds, i.e. no HTML <> or <> tags. TinyMCE is a WYSIWYG HTML editor and therefore treats text as text and uses the underlying HTML to render the content in the editor. So we need a quick hack, although I think this could easily become a useful function to be added to the TinyMCE module itself.
What I have below is a quick hack written as a standalone page. converttext.php. Save this to the root of your Drupal installation. Now browse to it from your web browser. Once it completes, delete it from your Drupal installation. (No sense leaving a security issue in place!).
What this does is simply loops over all your node content revisions and pipes the body and teaser content through the built-in Drupal _filter_autop function. This is the function in Drupal that creates the proper HTML output for content that has CRLF in the content but not the HTML <> and <>. So, using the same logic Drupal does to create the correct content, we pipe your current content through this function and get good HTML content that now has the <> and <> tags. Then we write this back to the body and teaser fields for the record.
Now, even the old content created before TinyMCE will open and display properly in TinyMCE for editing. Your body content would look something like this now in the DB.
Hope this helps.
---------------------------------------------------------------------
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$sq = 'select * from {node_revisions}';
$q = db_query($sq);
while($o = db_fetch_object($q))
{
$newbody = _filter_autop($o->body);
$newteaser = _filter_autop($o->teaser);
$sq2 = "update {node_revisions} set body = '%s', teaser = '%s' where vid = %d";
$q2 = db_query($sq2, $newbody, $newteaser, $o->vid);
}
--------------------------------------------------------
Well fear not. This is actually behaviour that is intended between the automatic line break feature of Drupal and the consequences of this in TinyMCE. See in Drupal, prior to installing TinyMCE, your content body and teasers were probably stored something like this in the database:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam aliquam
mi eu ipsum. In vestibulum, metus quis blandit pretium, lectus est
ornare nisl, at tincidunt nulla nulla a nunc. Quisque in metus mattis
eros elementum facilisis.
Sed mattis, diam et consequat commodo, orci eros cursus erat, atristique turpis metus at turpis. Cras mollis justo in dolor. Nunc
gravida. Praesent commodo dui aliquam sem. Aenean semper hendrerit
diam. Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas.
Ut volutpat neque. Duis aliquam facilisis nisl. Vivamus vel dui.
Pellentesque eu diam id est ultrices consectetuer. Nulla et ligula
bibendum risus mattis tincidunt. Aenean id magna et mauris consequat
rutrum. Aenean elementum.
Note the regular line feeds, i.e. no HTML <> or <> tags. TinyMCE is a WYSIWYG HTML editor and therefore treats text as text and uses the underlying HTML to render the content in the editor. So we need a quick hack, although I think this could easily become a useful function to be added to the TinyMCE module itself.
What I have below is a quick hack written as a standalone page. converttext.php. Save this to the root of your Drupal installation. Now browse to it from your web browser. Once it completes, delete it from your Drupal installation. (No sense leaving a security issue in place!).
What this does is simply loops over all your node content revisions and pipes the body and teaser content through the built-in Drupal _filter_autop function. This is the function in Drupal that creates the proper HTML output for content that has CRLF in the content but not the HTML <> and <>. So, using the same logic Drupal does to create the correct content, we pipe your current content through this function and get good HTML content that now has the <> and <> tags. Then we write this back to the body and teaser fields for the record.
Now, even the old content created before TinyMCE will open and display properly in TinyMCE for editing. Your body content would look something like this now in the DB.
<>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam aliquam
mi eu ipsum. In vestibulum, metus quis blandit pretium, lectus est
ornare nisl, at tincidunt nulla nulla a nunc. Quisque in metus mattis
eros elementum facilisis. < /p >
<>Sed mattis, diam et consequat commodo, orci eros cursus erat, a
tristique turpis metus at turpis. Cras mollis justo in dolor. Nunc
gravida. Praesent commodo dui aliquam sem. Aenean semper hendrerit
diam. Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. < /p >
<>Ut volutpat neque. Duis aliquam facilisis nisl. Vivamus vel dui.
Pellentesque eu diam id est ultrices consectetuer. Nulla et ligula
bibendum risus mattis tincidunt. Aenean id magna et mauris consequat
rutrum. Aenean elementum. < /p >
Hope this helps.
---------------------------------------------------------------------
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$sq = 'select * from {node_revisions}';
$q = db_query($sq);
while($o = db_fetch_object($q))
{
$newbody = _filter_autop($o->body);
$newteaser = _filter_autop($o->teaser);
$sq2 = "update {node_revisions} set body = '%s', teaser = '%s' where vid = %d";
$q2 = db_query($sq2, $newbody, $newteaser, $o->vid);
}
--------------------------------------------------------

