[wp-trac] [WordPress Trac] #10851: TinyMCE occasionally leaves junk behind when copy and pasting

WordPress Trac wp-trac at lists.automattic.com
Fri Sep 25 12:03:16 UTC 2009


#10851: TinyMCE occasionally leaves junk behind when copy and pasting
-------------------------------+--------------------------------------------
 Reporter:  Denis-de-Bernardy  |       Owner:  azaozz
     Type:  defect (bug)       |      Status:  new   
 Priority:  normal             |   Milestone:  2.9   
Component:  TinyMCE            |     Version:  2.8.4 
 Severity:  normal             |    Keywords:        
-------------------------------+--------------------------------------------

Comment(by Denis-de-Bernardy):

 some code to fix it, in case there is any interest:

 {{{
         /**
          * fix_tinymce_paste()
          *
          * @param string $content
          * @return string $content
          **/

         function fix_tinymce_paste($content) {
                 if ( strpos($content, '_mcePaste') === false )
                         return $content;

                 $content = stripslashes($content);

                 do {
                         $old_content = $content;
                         $content = preg_replace_callback("~(<div
 id=\"_mcePaste\".*?>)(.*?)(</div>)~is", 'fix_tinymce_paste_callback',
 $old_content);
                 } while ( $content && $content != $old_content );

                 global $wpdb;
                 $content = $wpdb->escape($content);

                 return $content;
         } # fix_tinymce_paste()


         /**
          * fix_tinymce_paste_callback()
          *
          * @param array $match
          * @return string $output
          **/

         function fix_tinymce_paste_callback($match) {
                 $content = $match[2];

                 if ( !$content || strpos(strtolower($content), '<div') ===
 false )
                         return '';

                 $content .= $match[3];
                 do {
                         $old_content = $content;
                         $content = preg_replace("~<div.*?>.*?</div>~is",
 '', $old_content);
                 } while ( $content && $content != $old_content );

                 return $match[1] . $content;
         } # fix_tinymce_paste_callback()

 add_filter('content_save_pre', 'fix_tinymce_paste', 0);
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/10851#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list