diff -u -r yui_editor.orig/plugins/bidi.css yui_editor/plugins/bidi.css
--- yui_editor.orig/plugins/bidi.css	2008-11-25 22:21:57.000000000 +0100
+++ yui_editor/plugins/bidi.css	2009-09-01 11:23:23.000000000 +0200
@@ -1,11 +1,11 @@
 .yui-skin-sam .yui-toolbar-container .yui-toolbar-editcode span.yui-toolbar-icon {
-  background-image: url( ../assets/html_editor.gif );
+  background-image: url(../assets/html_editor.gif);
   background-position: 0 1px;
   left: 5px;
 }
 
 .yui-skin-sam .yui-toolbar-container .yui-button-editcode-selected span.yui-toolbar-icon {
-  background-image: url( ../assets/html_editor.gif );
+  background-image: url(../assets/html_editor.gif);
   background-position: 0 1px;
   left: 5px;
 }
diff -u -r yui_editor.orig/plugins/coder.css yui_editor/plugins/coder.css
--- yui_editor.orig/plugins/coder.css	2008-11-21 23:54:27.000000000 +0100
+++ yui_editor/plugins/coder.css	2009-09-01 11:21:46.000000000 +0200
@@ -1,13 +1,13 @@
 /* $Id: coder.css,v 1.1.2.2.2.1 2008/11/21 22:54:27 jeffcd Exp $ */
 
 .yui-skin-sam .yui-toolbar-container .yui-toolbar-editcode span.yui-toolbar-icon {
-  background-image: url( ../assets/html_editor.gif );
+  background-image: url(../assets/html_editor.gif);
   background-position: 0 1px;
   left: 5px;
 }
 
 .yui-skin-sam .yui-toolbar-container .yui-button-editcode-selected span.yui-toolbar-icon {
-  background-image: url( ../assets/html_editor.gif );
+  background-image: url(../assets/html_editor.gif);
   background-position: 0 1px;
   left: 5px;
 }
diff -u -r yui_editor.orig/plugins/coder.js yui_editor/plugins/coder.js
--- yui_editor.orig/plugins/coder.js	2008-11-21 23:54:27.000000000 +0100
+++ yui_editor/plugins/coder.js	2009-08-24 17:21:15.000000000 +0200
@@ -3,11 +3,15 @@
 function yui_editor_coder() {
   for (var e in YAHOO.Drupal.editors) {
     var myEditor = YAHOO.Drupal.editors[e].editor;
+    if (typeof myEditor === "undefined")
+      continue;
     var config = YAHOO.Drupal.editors[e].config;
+    var id = YAHOO.Drupal.editors[e].id;
+    myEditor.config = config;
+    config.coderState = 'off';
 
-    var coderState = 'off';
     if (config.coder == 1) {
-      myEditor.on('toolbarLoaded', function() {
+      myEditor.on('toolbarLoaded', function () {
         var Dom = YAHOO.util.Dom;
         var codeConfig = {
           type: 'push', label: 'Edit HTML Code', value: 'editcode'
@@ -18,8 +22,8 @@
           var ta = this.get('element'),
             iframe = this.get('iframe').get('element');
 
-          if (coderState == 'on') {
-            coderState = 'off';
+          if (this.config.coderState == 'on') {
+            this.config.coderState = 'off';
             this.toolbar.set('disabled', false);
             this.setEditorHTML(ta.value);
             if (!this.browser.ie) {
@@ -32,7 +36,6 @@
             this._focusWindow();
           }
           else {
-            coderState = 'on';
             this.cleanHTML();
             Dom.addClass(iframe, 'editor-hidden');
             Dom.removeClass(ta, 'editor-hidden');
@@ -42,13 +45,14 @@
             this.dompath.innerHTML = 'Editing HTML Code';
             Dom.setStyle(this.get('element'), 'border', '0px');
             this.hide();
+            this.config.coderState = 'on';
           }
 
           return false;
         }, this, true);
 
         this.on('cleanHTML', function(ev) {
-          this.get('element').value = ev.html;
+            this.get('element').value = ev.html;
         }, this, true);
 
         this.on('afterRender', function() {
@@ -63,23 +67,27 @@
 
           this.addClass('editor-hidden');
         }, this, true);
-      }, myEditor, true);
+      });
     }
+  }
 
-    var toggle = 'off';
-    $('#toggleEditor-'+id).bind('click', function () { toggle = 'on'; });
-    $('form').bind('submit', function (e) {
-      if (toggle == 'on') {
-        toggle = 'off';
-        return false;
-      }
-      else if (coderState == 'on') {
-        myEditor.setEditorHTML(myEditor.get('textarea').value);
-      }
-      else {
-        myEditor.saveHTML();
-      }
-    });
+  // If code is active, make sure contents is saved properly. We need
+  // to add our own submit handler before the Yahoo one. Not tested what
+  // happens if handleSubmit is false.
+  var Event = YAHOO.util.Event;
+  for (var e in YAHOO.Drupal.editors) {
+    var myEditor = YAHOO.Drupal.editors[e].editor;
+    if (typeof myEditor === "undefined")
+      continue;
+    var form = myEditor.get('element').form;
+    Event.removeListener(form, 'submit', myEditor._handleFormSubmit);
+    Event.addListener(form, 'submit', function (ev) {
+        if (this.config.coderState == "on")
+          this.setEditorHTML(this.get('element').value);
+      }, myEditor, true);
+    Event.addListener(form, 'submit', myEditor._handleFormSubmit, myEditor, true);
   }
+
 }
+
 YAHOO.Drupal.yui_editor_load.subscribe(yui_editor_coder);
diff -u -r yui_editor.orig/plugins/flickr.css yui_editor/plugins/flickr.css
--- yui_editor.orig/plugins/flickr.css	2008-11-21 23:54:27.000000000 +0100
+++ yui_editor/plugins/flickr.css	2009-09-01 11:23:13.000000000 +0200
@@ -1,12 +1,12 @@
 /* $Id: flickr.css,v 1.1.2.2.2.1 2008/11/21 22:54:27 jeffcd Exp $ */
 
 .yui-skin-sam .yui-toolbar-container .yui-toolbar-flickr span.yui-toolbar-icon {
-  background-image: url( ../assets/flickr.gif );
+  background-image: url(../assets/flickr.gif);
   background-position: 6px 0px;
   width: 24px;
 }
 .yui-skin-sam .yui-toolbar-container .yui-toolbar-flickr-selected span.yui-toolbar-icon {
-  background-image: url( ../assets/flickr.gif );
+  background-image: url(../assets/flickr.gif);
   background-position: 6px 0px;
   wdth: 24px;
 }
diff -u -r yui_editor.orig/plugins/img_upload.2.6.js yui_editor/plugins/img_upload.2.6.js
--- yui_editor.orig/plugins/img_upload.2.6.js	2008-11-22 00:12:43.000000000 +0100
+++ yui_editor/plugins/img_upload.2.6.js	2009-08-20 21:08:10.000000000 +0200
@@ -6,7 +6,7 @@
     var config = YAHOO.Drupal.editors[e].config;
 
     if (config.img_upload == 1) {
-      yui_img_uploader(myEditor, config.base_path + '?q=/yui_editor/image_upload', 'files[upload]', config.base_path, YAHOO.Drupal.editors[e].id);
+      yui_img_uploader(myEditor, config.base_path + '?q=/yui_editor/image_upload', 'files[yui_upload]', config.base_path, YAHOO.Drupal.editors[e].id);
     }
   }
 }
diff -u -r yui_editor.orig/plugins/img_upload.inc yui_editor/plugins/img_upload.inc
--- yui_editor.orig/plugins/img_upload.inc	2008-11-21 23:54:27.000000000 +0100
+++ yui_editor/plugins/img_upload.inc	2009-08-22 09:36:12.000000000 +0200
@@ -12,16 +12,20 @@
 function yui_editor_image_upload() {
   header('content-type: text/html'); // the return type must be text/html
   $response = NULL;
-  $path = file_directory_path();
 
-  // Append trailing slash to path if not there
-  if (!(substr($path, -1) == '/')) {
-    $path .= '/';
+  $path = file_create_path('images');
+  if (!file_check_directory($path, true)) {
+    $response->status = t('Error creating subdirectory images.');
+    print drupal_to_js($response);
+    exit;
   }
-  $path .= 'images';
-  $file = file_save_upload('upload', array(), $path, FILE_EXISTS_REPLACE);
+  $file = file_save_upload('yui_upload', array(), $path, FILE_EXISTS_REPLACE);
   if (!$file) {
-    $response->status = t('Error reading uploaded file.');
+    $messages = drupal_get_messages('error');
+    if ($messages)
+      $response->status = implode ('; ', $messages['error']);
+    else
+      $response->status = t('Error reading uploaded file.');
     print drupal_to_js($response);
     exit;
   }
@@ -42,6 +46,7 @@
     'access callback' => 'user_access',
     'access arguments' => array('upload files'),
     'type' => MENU_CALLBACK,
+    'file' => 'plugins/img_upload.inc',
   );
 
   return $items;
@@ -50,8 +55,8 @@
 function yui_editor_img_upload_render(&$profile) {
   $profile['img_upload'] = (user_access('upload files') ? $profile['img_upload'] : 0);
   if ($profile['img_upload'] == 1) {
-    $yui_source = variable_get('yui_source', 'http://yui.yahooapis.com/2.6.0');
-    if (preg_match('/2.6.[0-9]$/iU', $yui_source)) {
+    $is_26_plus = yui_editor_is_26_plus ();
+    if ($is_26_plus) {
       drupal_add_js(drupal_get_path('module', 'yui_editor') .'/plugins/img_upload.2.6.js', 'module', 'footer');
     }
     else {
diff -u -r yui_editor.orig/plugins/img_upload.js yui_editor/plugins/img_upload.js
--- yui_editor.orig/plugins/img_upload.js	2008-11-21 23:54:27.000000000 +0100
+++ yui_editor/plugins/img_upload.js	2009-08-20 21:15:12.000000000 +0200
@@ -6,7 +6,7 @@
     var config = YAHOO.Drupal.editors[e].config;
 
     if (config.img_upload == 1) {
-      yui_img_uploader(myEditor, '?q=/yui_editor/image_upload', 'files[upload]', config.base_path);
+      yui_img_uploader(myEditor, '?q=/yui_editor/image_upload', 'files[yui_upload]', config.base_path);
     }
   }
 }
diff -u -r yui_editor.orig/plugins/resize.js yui_editor/plugins/resize.js
--- yui_editor.orig/plugins/resize.js	2008-11-21 23:54:27.000000000 +0100
+++ yui_editor/plugins/resize.js	2009-08-24 15:30:36.000000000 +0200
@@ -7,7 +7,7 @@
 
     if (config.resize == 1) {
       myEditor.on('editorContentLoaded', function() {
-        resize = new YAHOO.util.Resize(myEditor.get('element_cont').get('element'), {
+        resize = new YAHOO.util.Resize(this.get('element_cont').get('element'), {
           handles: ['br'],
           autoRatio: true,
           status: true,
@@ -16,7 +16,7 @@
         resize.on('startResize', function() {
           this.hide();
           this.set('disabled', true);
-        }, myEditor, true);
+        }, this, true);
         resize.on('resize', function(args) {
           var h = args.height;
           var th = (this.toolbar.get('element').clientHeight + 2); //It has a 1px border..
@@ -26,7 +26,7 @@
           this.set('height', newH + 'px');
           this.set('disabled', false);
           this.show();
-        }, myEditor, true);
+        }, this, true);
       });
     }
   }
diff -u -r yui_editor.orig/plugins/table.css yui_editor/plugins/table.css
--- yui_editor.orig/plugins/table.css	2008-11-21 23:54:27.000000000 +0100
+++ yui_editor/plugins/table.css	2009-09-01 11:23:37.000000000 +0200
@@ -1,13 +1,13 @@
 /* $Id: table.css,v 1.1.2.2 2008/11/21 22:54:27 jeffcd Exp $ */
 
 .yui-skin-sam .yui-toolbar-container .yui-toolbar-table span.yui-toolbar-icon {
-  background-image: url( ../assets/icons.gif );
+  background-image: url(../assets/icons.gif);
   background-position: -580px -22px;
   left: 5px;
 }
 
 .yui-skin-sam .yui-toolbar-container .yui-button-table-selected span.yui-toolbar-icon {
-  background-image: url( ../assets/icons.gif );
+  background-image: url(../assets/icons.gif);
   background-position: -580px -22px;
   left: 5px;
 }
\ No newline at end of file
diff -u -r yui_editor.orig/plugins/table.js yui_editor/plugins/table.js
--- yui_editor.orig/plugins/table.js	2008-11-21 23:54:27.000000000 +0100
+++ yui_editor/plugins/table.js	2009-08-31 18:15:45.000000000 +0200
@@ -11,10 +11,10 @@
         var tableConfig = {
           type: 'push', label: 'Create Table', value: 'table'
         };
-        myEditor.toolbar.addButtonToGroup(tableConfig, 'plugins');
-        myEditor.win = null;
+        this.toolbar.addButtonToGroup(tableConfig, 'plugins');
+        this.win = null;
 
-        myEditor.createTableHTML =
+        this.createTableHTML =
           '<table><tbody>' +
           '<tr><td>Rows:</td><td><input type="text" size="1" id="tableRows' + id + '" value="3"></td><td>Columns:</td><td><input type="text" size="1" id="tableColumns' + id + '" value="3"></td></tr>' +
           '<tr><td>Width:</td><td><input type="text" size="1" id="tableWidth' + id + '" value=""></td><td>Height:</td><td><input type="text" size="1" id="tableHeight' + id + '" value=""></td></tr>' +
@@ -24,9 +24,9 @@
           '<tr><td colspan="4"><div align="right"><input type="button" id="tableCreate' + id + '" value="Create"></div></td></tr>' +
           '</tbody></table>';
 
-        myEditor.toolbar.on('tableClick', function(ev) {
+        this.toolbar.on('tableClick', function(ev) {
           if (this.win !== null) {
-            this.win.setBody(myEditor.createTableHTML);
+            this.win.setBody(this.createTableHTML);
             this.win.show();
           }
           else {
@@ -37,16 +37,17 @@
               width: '350px'
             });
             this.win.setHeader('Create Table');
-            this.win.setBody(myEditor.createTableHTML);
+            this.win.setBody(this.createTableHTML);
             this.win.render(document.body);
             this.win.hideEvent.subscribe(function() {
               //Just to make sure we didn't loose it
               this._setDesignMode('on');
               this._focusWindow();
-            }, myEditor, true);
+            }, this, true);
           }
 
           var tableCreateButton = new YAHOO.widget.Button('tableCreate' + id);
+          tableCreateButton.editor = this;
           tableCreateButton.on('click', function() {
             var rows =
               document.getElementById('tableRows' + id).value.match('[0-9]+') ? document.getElementById('tableRows' + id).value : 3;
@@ -76,12 +77,12 @@
               tableHTML += '</tr>\n';
             }
             tableHTML += '</tbody></table>';
-            myEditor.execCommand('inserthtml', tableHTML);
-            createTablePanel.hide();
+            tableCreateButton.editor.execCommand('inserthtml', tableHTML);
+            tableCreateButton.editor.win.hide();
           });
 
-	      return false;
-	    }, myEditor, true);
+        return false;
+      }, this, true);
       });
     }
   }
diff -u -r yui_editor.orig/yui_editor.admin.inc yui_editor/yui_editor.admin.inc
--- yui_editor.orig/yui_editor.admin.inc	2008-11-22 00:05:28.000000000 +0100
+++ yui_editor/yui_editor.admin.inc	2009-08-31 11:45:02.000000000 +0200
@@ -219,7 +219,7 @@
     '#type' => 'checkbox',
     '#default_value' => $profile['ptags'],
     '#title' => t('Use P tags'),
-    '#description' => t('Use P tags instead of BR tags for paragraphs. (Shift+enter to get BR tag when this is turned on) Note: This option appears to only work in IE.'),
+    '#description' => t('Use P tags instead of BR tags for paragraphs. (Shift+enter to get BR tag when this is turned on). This feature does not appear to work well without patching editor.js'),
   );
   $form['plugins'] = array(
     '#type' => 'fieldset',
@@ -246,7 +246,7 @@
     '#type' => 'select',
     '#title' => t('Button profile'),
     '#default_value' => $profile['button_profile'],
-    '#options' => array('yui_editor_toolbar_default.js' => 'Default', 'yui_editor_toolbar_no_style.js' => 'No Style Tags', '1'  => 'Custom'),
+    '#options' => array('yui_editor_toolbar_default.js' => 'Default', 'yui_editor_toolbar_no_style.js' => 'No Style Tags', 'yui_editor_toolbar_rmhc.js' => 'RMHC', '1'  => 'Custom'),
     '#description' => t('Select the appropriate button profile. If you choose "Custom", then you will be able to build your own toolbar below.'),
   );
   $form['buttns']['_custom_html'] = array(
diff -u -r yui_editor.orig/yui_editor.module yui_editor/yui_editor.module
--- yui_editor.orig/yui_editor.module	2008-11-22 00:05:28.000000000 +0100
+++ yui_editor/yui_editor.module	2009-08-31 12:04:28.000000000 +0200
@@ -1,6 +1,8 @@
 <?php
 // $Id: yui_editor.module,v 1.5.2.17.2.9 2008/11/21 23:05:28 jeffcd Exp $
 
+define('YUI_URL', 'http://yui.yahooapis.com/2.7.0');
+
 /**
  * @file
  * Replace textareas with the YUI rich text editor.
@@ -167,7 +169,9 @@
 
 function yui_editor_load_libs() {
   // TODO: only load CSS/JS based on the settings...
-  $yui_source = variable_get('yui_source', 'http://yui.yahooapis.com/2.6.0');
+  $yui_source = variable_get('yui_source', YUI_URL);
+  $is_26_plus = yui_editor_is_26_plus ();
+
   yui_add_css('editor', $yui_source, '/build/menu/assets/skins/sam/menu.css');
   yui_add_css('editor', $yui_source, '/build/button/assets/skins/sam/button.css');
   yui_add_css('editor', $yui_source, '/build/fonts/fonts-min.css');
@@ -179,7 +183,7 @@
   yui_add_js('editor', $yui_source, '/build/utilities/utilities.js');
   yui_add_js('editor', $yui_source, '/build/dragdrop/dragdrop-min.js');
   yui_add_js('editor', $yui_source, '/build/animation/animation-min.js');
-  if (preg_match('/2.6.[0-9]$/iU', $yui_source)) {
+  if ($is_26_plus) {
     yui_add_js('editor', $yui_source, '/build/element/element-min.js');
   }
   else {
@@ -188,11 +192,12 @@
   yui_add_js('editor', $yui_source, '/build/container/container-min.js');
   yui_add_js('editor', $yui_source, '/build/menu/menu-min.js');
   yui_add_js('editor', $yui_source, '/build/button/button-min.js');
-  if (preg_match('/2.6.[0-9]$/iU', $yui_source)) {
+  if ($is_26_plus) {
     yui_add_js('editor', $yui_source, '/build/resize/resize-min.js');
     yui_add_js('editor', $yui_source, '/build/datasource/datasource-min.js');
     yui_add_js('editor', $yui_source, '/build/autocomplete/autocomplete-min.js');
-    yui_add_js('editor', $yui_source, '/build/editor/editor-min.js');
+    //yui_add_js('editor', $yui_source, '/build/editor/editor-min.js');
+    drupal_add_js(drupal_get_path('module', 'yui_editor') .'/editor.js');
   }
   else {
     yui_add_js('editor', $yui_source, '/build/resize/resize-beta-min.js');
@@ -221,3 +226,32 @@
     }
   }
 }
+
+/**
+ * Test if we have a newer version of YUI
+ */
+function yui_editor_is_26_plus () {
+  $yui_source = variable_get('yui_source', YUI_URL);
+  $is_26_plus = (bool) preg_match('/2\.[6-7]\.[0-9]$/iU', $yui_source);
+  return $is_26_plus;
+}
+
+
+/**
+ * Filter to allow php code in the form of <php> tags
+ */
+
+function yui_editor_filter($op, $delta = 0, $format = -1, $text = '') {
+  switch ($op) {
+    case 'list':
+      return array(1 => t('Convert &lt;php&gt; tags to PHP code'));
+    case 'description':
+      return t('Allow &lt;php&gt; tags to insert PHP code. Start PHP with &lt;php&gt;&lt;!-- and them with --&gt;&lt;/span&gt;. You will also need to enable the PHP evaluator. Make sure to rearrange that one to come after this fitler.');
+    case 'process':
+      $text = preg_replace ('/<php><!--/', '<?php ', $text);
+      $text = preg_replace ('/--><\/php>/', '?>', $text);
+      return $text;
+    default:
+      return $text;
+  }
+}
