--- insert.module	2010-08-07 14:46:55.000000000 -0400
+++ /www/ebremer-7.0/sites/all/modules/insert/insert.module	2011-01-16 00:23:49.000000000 -0500
@@ -21,26 +21,34 @@ require dirname(__FILE__) . '/includes/i
  * mimics the behavior of ImageCache in Drupal 6, making it so we can use the
  * final URLs directly.
  */
+
 function insert_menu() {
   $items = array();
 
-  // Public file directory callback.
-  $public_path = file_directory_path('public') .'/styles/%image_style';
-  $items[$public_path] = array(
-    'page callback' => 'image_style_generate',
-    'page arguments' => array(count(explode('/', $public_path)) - 1, 'public'),
+  // Generate image derivatives of publicly available files.
+  // If clean URLs are disabled, image derivatives will always be served
+  // through the menu system.
+  // If clean URLs are enabled and the image derivative already exists,
+  // PHP will be bypassed.
+  $directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath();
+  $items[$directory_path . '/styles/%image_style'] = array(
+    'title' => 'Generate image style',
+    'page callback' => 'image_style_deliver',
+    'page arguments' => array(count(explode('/', $directory_path)) + 1),
     'access callback' => TRUE,
-    'type' => MENU_CALLBACK
+    'type' => MENU_CALLBACK,
   );
-  // Private downloads callback.
+  // Generate and deliver image derivatives of private files.
+  // These image derivatives are always delivered through the menu system.
   $items['system/files/styles/%image_style'] = array(
-    'page callback' => 'image_style_generate',
-    'page arguments' => array(3, 'private'),
+    'title' => 'Generate image style',
+    'page callback' => 'image_style_deliver',
+    'page arguments' => array(3),
     'access callback' => TRUE,
-    'type' => MENU_CALLBACK
+    'type' => MENU_CALLBACK,
   );
 
-  return $items;
+   return $items;
 }
 
 /**
@@ -187,7 +195,7 @@ function insert_element_process($element
   // Bail out early if the needed properties aren't available. This happens
   // most frequently when editing a field configuration.
   if (!isset($element['#entity_type'])) {
-    return;
+    return $element;
   }
 
   $item = $element['#value'];
@@ -206,7 +214,7 @@ function insert_element_process($element
   // Add base settings only once.
   if (!isset($js_added)) {
     $js_added = array();
-    $settings = array('fileDirectoryPath' => file_directory_path());
+    $settings = array('fileDirectoryPath' => file_default_scheme());
     drupal_add_js(array('insert' => $settings), 'setting');
     drupal_add_js(drupal_get_path('module', 'insert') . '/insert.js');
   }
