Index: img_assist.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/Attic/img_assist.css,v
retrieving revision 1.3.2.13
diff -u -p -r1.3.2.13 img_assist.css
--- img_assist.css	24 Feb 2008 21:46:08 -0000	1.3.2.13
+++ img_assist.css	3 Apr 2008 22:03:46 -0000
@@ -1,115 +1,6 @@
 /* $Id: img_assist.css,v 1.3.2.13 2008/02/24 21:46:08 sun Exp $ */
 
 /**
- * IMG ASSIST WINDOW
- */ 
-body.img_assist {
-  margin: 0px;
-  padding: 5px;
-  width: auto;
-  min-width: 0;
-  color: #000000;
-  font-family: Arial, Helvetica, sans-serif;
-  font-size: .8em;
-  background-color: #efefef;
-}
-/* Thin line between the header frame and the main frame */
-body#img_assist_thumbs, body#img_assist_upload, body#img_assist_properties {
-  border-top: 1px solid #000;
-}
-/* Darker background color in the header frame */
-body#img_assist_header {
-  background-color:#ccc;
-  margin: 0;
-}
-/* Thin border around images */
-.img_assist img  {
-  border: 1px solid #000;
-}
-.img_assist-button {
-  font-weight: bold;
-  margin: 3px;
-}
-.img_assist img {
-  display: inline; /* pushbutton theme changes the display to block */
-}
-.img_assist .messages {
-  border: 1px solid #000;
-  background-color: #ccc;
-  padding: 2px;
-  margin: 3px 0px 6px 0px;
-}
-
-/* Upload Window */
-.img_assist .node-form {
-  width: 95%;
-}
-
-/* Properties Window */
-.img_assist #preview {
-  padding: 5px 10px 5px 5px;
-}
-.img_assist .form-item { /* the first form field on the properties frame should be at the top of the page  */
-  margin-top: 0px;
-  margin-bottom: 1em;
-}
-.img_assist #caption {
-  display: block;
-}
-.img_assist #header-browse div.form-item,
-.img_assist #link-group div.form-item,
-.img_assist #edit-size div.form-item,
-.img_assist #size-other div.form-item {
-  display: inline;
-}
-.img_assist #alignment {
-  text-align: left;
-}
-.img_assist #edit-title, .img_assist #edit-desc {
-  width: 99%;
-}
-.img_assist #edit-link {
-  width: 155px;
-}
-.img_assist #edit-url {
-  width: 150px;
-}
-.img_assist #edit-align {
-  width: 100px;
-}  
-#finalhtmlcode {
-  display: none;
-  visibility: hidden;
-}
-
-/* Header Frame */
-#header-uploading, #header-properties, #header-browse {
-  float: left; 
-  width: 80%;
-}
-#header-startover, #header-cancel {
-  float: right;
-  width: 19%;
-  text-align: right;
-}
-
-#header-uploading input, #header-properties input, #header-browse input, #header-startover input, #header-cancel input, #header-uploading select, #header-properties select, #header-browse select {
-  margin-top: 0;
-  margin-bottom: 0;
-  vertical-align: baseline;
-}
-
-
-/**
- * POPUP IMAGES WINDOW
- */
-body#img_assist_popup {
-  margin: 0;
-  padding: 0;
-}
-
-/**
- * FINAL PAGE (node)
  * You may want to copy these styles to your theme's CSS file and then set img_assist.css 
  * not to load on every page.  This can be set on the img_assist settings page.
  */ 
@@ -130,7 +21,8 @@ span.inline-center {
 span.inline .caption {
   display: block;
 }
-.image-clear { /* Clear floated images. Copied from Garland's style.css. */
+/* Clear floated images. Copied from Garland's style.css. */
+.image-clear {
   display: block;
   clear: both;
   height: 1px;
Index: img_assist.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/Attic/img_assist.info,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 img_assist.info
--- img_assist.info	21 Sep 2007 18:45:26 -0000	1.1.2.4
+++ img_assist.info	28 Mar 2008 14:36:16 -0000
@@ -1,5 +1,6 @@
 ; $Id: img_assist.info,v 1.1.2.4 2007/09/21 18:45:26 sun Exp $
 name = Image assist
 description = This module allows users to upload and insert inline images into posts. It automatically generates an Add image link under the textarea fields of your choice.
-dependencies = image
+dependencies[] = image
 package = Image
+core = 6.x
Index: img_assist.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/Attic/img_assist.install,v
retrieving revision 1.3.2.7
diff -u -p -r1.3.2.7 img_assist.install
--- img_assist.install	26 Sep 2007 22:05:05 -0000	1.3.2.7
+++ img_assist.install	28 Mar 2008 14:35:31 -0000
@@ -1,37 +1,46 @@
 <?php
 // $Id: img_assist.install,v 1.3.2.7 2007/09/26 22:05:05 sun Exp $
 
+/**
+ * Implementation of hook_schema().
+ */
+function img_assist_schema() {
+  $schema['img_assist_map'] = array(
+    'description' => t('Stores references of image files to content.'),
+    'fields' => array(
+      'nid' => array(
+        'description' => t('The {node}.nid of the content referencing the image file.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+      'iid' => array(
+        'description' => t('The {image}.nid of the image file referenced by the content.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array('nid', 'iid'),
+  );
+  return $schema;
+}
 
 /**
- * Implementation of hook_install()
+ * Implementation of hook_install().
  */
 function img_assist_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query('CREATE TABLE {img_assist_map} (
-        nid INT(10) UNSIGNED NOT NULL ,
-        iid INT(10) UNSIGNED NOT NULL ,
-        PRIMARY KEY (nid, iid)
-      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;');
-      break;
-    
-    case 'pgsql':
-      db_query('create table {img_assist_map} (
-        nid integer not null,
-        iid integer not null,
-        primary key (nid, iid)
-      );');
-      break;
-  }
-  drupal_set_message(t('Image assist has been setup.'));
+  drupal_install_schema('img_assist');
 }
 
 /**
  * Implementation of hook_uninstall().
  */
 function img_assist_uninstall() {
-  db_query('DROP TABLE {img_assist_map}');
+  drupal_uninstall_schema('img_assist');
+
   variable_del('img_assist_page_styling');
   variable_del('img_assist_link');
   variable_del('img_assist_all');
@@ -53,13 +62,6 @@ function img_assist_uninstall() {
 }
 
 /**
- * Convert img_assist_map table to utf8.
- */
-function img_assist_update_1() {
-  return _system_update_utf8(array('img_assist_map'));
-}
-
-/**
  * Fix variable value of img_assist_textareas_type.
  * 
  * Configuration options 0 and 1 have been switched.
@@ -75,4 +77,3 @@ function img_assist_update_2() {
   return $ret;
 }
 
-
Index: img_assist.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/Attic/img_assist.js,v
retrieving revision 1.4.2.5
diff -u -p -r1.4.2.5 img_assist.js
--- img_assist.js	19 Nov 2007 02:27:49 -0000	1.4.2.5
+++ img_assist.js	3 Apr 2008 22:43:42 -0000
@@ -1,162 +1,21 @@
 /* $Id: img_assist.js,v 1.4.2.5 2007/11/19 02:27:49 sun Exp $ */
 
-var currentMode;
-
-function onChangeBrowseBy(el) {
-	frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/thumbs/' + el.value;
-}
-
-function onClickUpload() {
-  frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/upload';
-}
-
-function onClickStartOver() {
-  frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/thumbs/myimages';
-}
-
-function updateCaption() {
-  var caption = frames['img_assist_main'].document.getElementById('caption');
-  var title = frames['img_assist_main'].document.img_assist['edit-title'].value;
-  var desc = frames['img_assist_main'].document.img_assist['edit-desc'].value;
-  if (desc != '') {
-    title = title + ': ';
-  }
-  caption.innerHTML = '<strong>' + title + '</strong>' + desc;
-}
-
-function onChangeHeight() {
-  var formObj = frames['img_assist_main'].document.forms[0];
-  var aspect = formObj['edit-aspect'].value;
-  var height = formObj['edit-height'].value;
-  formObj['edit-width'].value = Math.round(height * aspect);
-}
-
-function onChangeWidth() {
-  var formObj = frames['img_assist_main'].document.forms[0];
-  var aspect = formObj['edit-aspect'].value;
-  var width = formObj['edit-width'].value;
-  formObj['edit-height'].value = Math.round(width / aspect);
-}
-
-function onChangeLink() {
-  var formObj = frames['img_assist_main'].document.forms[0];
-	if (formObj['edit-link-options-visible'].value == 1) {
-		if (formObj['edit-link'].value == 'url') {
-			showElement('edit-url', 'inline');
-		}
-		else {
-			hideElement('edit-url');
+if (Drupal.jsEnabled) {
+	$(document).ready(function() {
+		if (Drupal.settings.img_assist.elements) {
+			$.each(Drupal.settings.img_assist.elements, function(i, id) {
+				var el = $('#'+ id);
+				var link, html = '<div class="img_assist-button">';
+				if (Drupal.settings.img_assist.link == 'icon') {
+					link = '<img src="'+ Drupal.settings.basePath + Drupal.settings.img_assist.icon +'" alt="Add image" title="Add image" />';
+				}
+				else {
+					link = 'Add image';
+				}
+				html += '<a href="'+ Drupal.settings.basePath +'index.php?q=img_assist/load/textarea&textarea='+ el.attr('name') +'" class="img_assist-link" id="img_assist-link-'+ id +'" title="Click here to add images" onclick="window.open(this.href, \'img_assist_link\', \'width=600,height=350,scrollbars=yes,status=yes,resizable=yes,toolbar=no,menubar=no\'); return false;">'+ link +'</a>';
+				html += '</div>';
+				el.parent().append(html);
+			});
 		}
-	}
-}
-
-function onChangeSizeLabel() {
-  var formObj = frames['img_assist_main'].document.forms[0];
-  if (formObj['edit-size-label'].value == 'other') {
-    showElement('size-other', 'inline');
-  }
-  else {
-    hideElement('size-other');
-    // get the new width and height
-    var size = formObj['edit-size-label'].value.split('x');
-    // this array is probably a bounding box size, not an actual image
-    // size, so now we use the known aspect ratio to find the actual size
-    var aspect = formObj['edit-aspect'].value;
-    var width = size[0];
-    var height = size[1];
-    if (Math.round(width / aspect) <= height) {
-    	// width is controlling factor
-      height = Math.round(width / aspect);
-    }
-    else {
-    	// height is controlling factor
-      width = Math.round(height * aspect);
-    }
-    // fill the hidden width and height textboxes with these values
-    formObj['edit-width'].value = width;
-    formObj['edit-height'].value = height;
-  }
-}
-
-function setHeader(mode) {
-	if (currentMode != mode) {
-		frames['img_assist_header'].window.location.href = BASE_URL + 'index.php?q=img_assist/header/' + mode;
-	}
-	currentMode = mode;
-}
-
-function showElement(id, format) {
-  var docObj = frames['img_assist_main'].document;
-  format = (format) ? format : 'block';
-  if (docObj.layers) {
-    docObj.layers[id].display = format;
-  }
-  else if (docObj.all) {
-    docObj.all[id].style.display = format;
-  }
-  else if (docObj.getElementById) {
-    docObj.getElementById(id).style.display = format;
-  }
-}
-
-function hideElement(id) {
-  var docObj = frames['img_assist_main'].document;
-  if (docObj.layers) {
-    docObj.layers[id].display = 'none';
-  }
-  else if (docObj.all) {
-    docObj.all[id].style.display = 'none';
-  }
-  else if (docObj.getElementById) {
-    docObj.getElementById(id).style.display = 'none';
-  }
-}
-
-function launch_popup(nid, mw, mh) {
-	var ox = mw;
-	var oy = mh;
-	if((ox>=screen.width) || (oy>=screen.height)) {
-		var ox = screen.width-150;
-		var oy = screen.height-150;
-		var winx = (screen.width / 2)-(ox / 2);
-		var winy = (screen.height / 2)-(oy / 2);
-		var use_scrollbars = 1;
-	}
-	else {
-		var winx = (screen.width / 2)-(ox / 2);
-		var winy = (screen.height / 2)-(oy / 2);
-		var use_scrollbars = 0;
-	}
-	var win = window.open(BASE_URL + 'index.php?q=img_assist/popup/' + nid, 'imagev', 'height='+oy+'-10,width='+ox+',top='+winy+',left='+winx+',scrollbars='+use_scrollbars+',resizable');
-}
-
-function insertImage() {
-  if (window.opener) {
-    // Get variables from the fields on the properties frame
-    var formObj = frames['img_assist_main'].document.forms[0];
-		// Get mode	(see img_assist.module for detailed comments)
-		if (formObj['edit-insertmode'].value == 'html') {
-			// return so the page can submit normally and generate the HTML code
-			return true;
-		}
-		else if (formObj['edit-insertmode'].value == 'html2') {
-			// HTML step 2 (processed code, ready to be inserted)
-			var content = getHTML(formObj);
-		}
-		else {
-			var content = getFilterTag(formObj);
-		}
-		insertToEditor(content);
-		return false;
-		
-  }
-  else {
-		alert('The image cannot be inserted because the parent window cannot be found.');
-		return false;
-	}
-}
-
-function getHTML(formObj) {
-	var html = frames['img_assist_main'].document.getElementById('finalhtmlcode').value;
-	return html;
+	});
 }
Index: img_assist.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/img_assist/Attic/img_assist.module,v
retrieving revision 1.68.2.48
diff -u -p -r1.68.2.48 img_assist.module
--- img_assist.module	24 Feb 2008 21:46:08 -0000	1.68.2.48
+++ img_assist.module	3 Apr 2008 22:53:15 -0000
@@ -24,91 +24,109 @@ function img_assist_help($section) {
 }
 
 /**
+ * Implementation of hook_theme().
+ */
+function img_assist_theme() {
+  return array(
+    'img_assist_textarea_link' => array(
+      'arguments' => array('element' => NULL, 'link' => NULL),
+    ),
+    'img_assist_inline' => array(
+      'arguments' => array('node' => NULL, 'size' => NULL, 'attributes' => NULL),
+    ),
+    'img_assist_filter' => array(
+      'arguments' => array('text' => NULL),
+    ),
+    'img_assist_popup' => array(
+      'arguments' => array('content' => NULL, 'attributes' => NULL),
+    ),
+    'img_assist_page' => array(
+      'arguments' => array('content' => NULL, 'attributes' => NULL),
+    ),
+    'img_assist_legacy' => array(),
+  );
+}
+
+/**
  * Implementation of hook_menu().
  */
-function img_assist_menu($may_cache) {
+function img_assist_menu() {
   $items = array();
-  
-  $access = user_access('access content');
-  
-  if ($may_cache) {
-    $items[] = array('path' => 'img_assist/cache/clear',
-      'title' => t('Empty cache'),
-      'callback' => 'img_assist_cache_clear',
-      'access' => $access,
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'img_assist/load',
-      'title' => t('Image Assist'),
-      'callback' => 'img_assist_loader',
-      'access' => $access,
-      'type' => MENU_CALLBACK,
-    );
-    // Page callbacks called internally by img_assist/load.
-    $items[] = array(
-      'path' => 'img_assist/header',
-      'title' => t('Image Assist Header'),
-      'callback' => 'img_assist_header',
-      'access' => $access,
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'img_assist/thumbs',
-      'title' => t('Image Assist Thumbnails'),
-      'callback' => 'img_assist_thumbs',
-      'access' => $access,
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'img_assist/upload',
-      'title' => t('Image Assist Upload'),
-      'callback' => 'img_assist_upload',
-      'access' => $access,
-      'type' => MENU_CALLBACK,
-    );
-    $items[] = array(
-      'path' => 'img_assist/properties',
-      'title' => t('Image Assist Properties'),
-      'callback' => 'img_assist_properties',
-      'access' => $access,
-      'type' => MENU_CALLBACK,
-    );
-    // Popup images page.
-    $items[] = array(
-      'path' => 'img_assist/popup',
-      'title' => t('Popup Image'),
-      'callback' => 'img_assist_popup',
-      'access' => $access,
-      'type' => MENU_CALLBACK,
-    );
-    // Insert callback (only for inserting HTML, not filter tag).
-    $items[] = array(
-      'path' => 'img_assist/insert_html',
-      'title' => t('Insert Callback'),
-      'access' => $access,
-      'type' => MENU_CALLBACK,
-      'callback' => 'img_assist_insert_html',
-    );
-    $items[] = array(
-      'path' => 'admin/settings/img_assist',
-      'title' => t('Image assist'),
-      'description' => t('Change settings for the Image assist module.'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => 'img_assist_admin_settings',
-      'access' => user_access('administer site configuration'),
-    );
+
+  $items['img_assist/cache/clear'] = array(
+    'title' => 'Empty cache',
+    'page callback' => 'img_assist_cache_clear',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['img_assist/load'] = array(
+    'title' => 'Image assist',
+    'page callback' => 'img_assist_loader',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  // Page callbacks called internally by img_assist/load.
+  $items['img_assist/header'] = array(
+    'title' => 'Image assist header',
+    'page callback' => 'img_assist_header',
+    'page arguments' => array(2),
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['img_assist/thumbs'] = array(
+    'title' => 'Image assist thumbnails',
+    'page callback' => 'img_assist_thumbs',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['img_assist/upload'] = array(
+    'title' => 'Image assist upload',
+    'page callback' => 'img_assist_upload',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['img_assist/properties'] = array(
+    'title' => 'Image assist properties',
+    'page callback' => 'img_assist_properties',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  // Popup images page.
+  $items['img_assist/popup'] = array(
+    'title' => 'Popup image',
+    'page callback' => 'img_assist_popup',
+    'access callback' => 'user_access',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  // Insert callback (only for inserting HTML, not filter tag).
+  $items['img_assist/insert_html'] = array(
+    'title' => 'Insert callback',
+    'page callback' => 'img_assist_insert_html',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  $items['admin/settings/img_assist'] = array(
+    'title' => 'Image assist',
+    'description' => 'Change settings for the Image assist module.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('img_assist_admin_settings'),
+    'access arguments' => array('administer site configuration'),
+  );
+  return $items;
+}
+
+/**
+ * Implementation of hook_init().
+ */
+function img_assist_init() {
+  $path = drupal_get_path('module', 'img_assist');
+  if (arg(0) == 'img_assist') {
+    drupal_add_css($path .'/img_assist_popup.css');
   }
-  else {
-    $path = drupal_get_path('module', 'img_assist');
-    if (variable_get('img_assist_page_styling', 'yes') == 'yes') {
-      drupal_add_css($path .'/img_assist.css');
-    }
-    // Assign base_path to insert in image source by javascript.
-    drupal_add_js('var BASE_URL = "'. base_path() .'";', 'inline');
-    drupal_add_js($path .'/img_assist.js');
+  else if (variable_get('img_assist_page_styling', 'yes') == 'yes') {
+    drupal_add_css($path .'/img_assist.css');
   }
-  return $items;
 }
 
 /**
@@ -123,21 +141,35 @@ function img_assist_perm() {
  */
 function img_assist_elements() {
   $type['textarea'] = array(
-    '#process' => array('img_assist_textarea' => array()),
+    '#process' => 'img_assist_textarea'
   );
   return $type;
 }
 
-/*
- * Add image link underneath textareas.
+/**
+ * Add JavaScript settings for generating the image link underneath textareas.
  */
 function img_assist_textarea($element) {
+  static $initialized = FALSE;
+
   $link = variable_get('img_assist_link', 'icon');
   if (($link == 'icon') || ($link == 'text')) {
     if (_img_assist_textarea_match($element['#id']) && _img_assist_page_match() && !strstr($_GET['q'], 'img_assist')) {
       if (user_access('access img_assist')) {
-        $output = theme('img_assist_textarea_link', $element, $link);
-        $element['#suffix'] .= $output;
+        if (!$initialized) {
+          drupal_add_js(drupal_get_path('module', 'img_assist') .'/img_assist.js');
+
+          $settings['link'] = $link;
+          if ($link == 'icon') {
+            $settings['icon'] = drupal_get_path('module', 'img_assist') .'/add-image.jpg';
+          }
+          $initialized = TRUE;
+        }
+        if (!is_array($settings['elements'])) {
+          $settings['elements'] = array();
+        }
+        $settings['elements'][] = $element['#id'];
+        drupal_add_js(array('img_assist' => $settings), 'setting');
       }
     }
   }
@@ -372,9 +404,9 @@ function img_assist_admin_settings() {
 /**
  * Validate Image Assist settings.
  */
-function img_assist_admin_settings_validate($form_id, $form_values) {
+function img_assist_admin_settings_validate($form, &$form_state) {
   // img_assist_max_size must contain a value for width and height.
-  if (!preg_match('/\d+x\d+/', $form_values['img_assist_max_size'])) {
+  if (!preg_match('/\d+x\d+/', $form_state['values']['img_assist_max_size'])) {
     form_set_error('img_assist_max_size', t('Allowed maximum inline image size has to indicate width and height, for example %example.', array('%example' => '200x300')));
   }
 }
@@ -417,8 +449,6 @@ function img_assist_filter_tips($delta, 
  * - Clear input filter cache.
  * - Keep track of where images are used.
  * - Catch nids of recently uploaded images.
- * 
- * @todo Remove usage of global variable.
  */
 function img_assist_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
   switch ($op) {
@@ -432,11 +462,6 @@ function img_assist_nodeapi(&$node, $op,
     case 'insert':
       // Update the image map.
       img_assist_map_save($node);
-      // Store nid globally if this node is an image uploaded with img_assist.
-      if ($node->type == 'image' && arg(0) == 'img_assist') {
-        global $_img_assist_saved_image;
-        $_img_assist_saved_image = $node->nid;
-      }
       break;
     
     case 'delete':
@@ -484,7 +509,7 @@ function img_assist_loader() {
   $output .= "--></script>\n";
   
   $path = drupal_get_path('module', 'img_assist');
-  $output .= '<script type="text/javascript" src="'. base_path() . $path .'/img_assist.js"></script>'."\n";
+  $output .= '<script type="text/javascript" src="'. base_path() . $path .'/img_assist_popup.js"></script>'."\n";
   if ($editor == 'tinymce') {
     $tinymce_path = drupal_get_path('module', 'tinymce');
     $tinymce_js = base_path() . $tinymce_path .'/tinymce/jscripts/tiny_mce/tiny_mce_popup.js';
@@ -504,14 +529,13 @@ function img_assist_loader() {
   echo $output;
 }
 
-function img_assist_header() {
+function img_assist_header($mode) {
   // Mode may be 'uploading', 'properties' or 'browse'.
-  $mode = arg(2);
   $output = drupal_get_form('img_assist_header_form', $mode);
   echo theme('img_assist_page', $output, array('id' => 'img_assist_header', 'onload' => 'parent.initHeader();', 'class' => 'img_assist'));
 }
 
-function img_assist_header_form($mode) {
+function img_assist_header_form(&$form_state, $mode) {
   global $user;
   
   // Upload image.
@@ -560,7 +584,7 @@ function img_assist_header_form($mode) {
     if (module_exists('taxonomy')) {
       $vocabs = (array)variable_get('img_assist_vocabs', array());
       foreach ($vocabs as $vid) {
-        $vocab = taxonomy_get_vocabulary($vid);
+        $vocab = taxonomy_vocabulary_load($vid);
         $terms = taxonomy_get_tree($vid);
         if ($terms) {
           foreach ($terms as $key => $value) {
@@ -617,7 +641,8 @@ function img_assist_header_form($mode) {
  */
 function img_assist_upload() {
   global $user;
-  
+  module_load_include('inc', 'node', 'node.pages');
+
   if (module_exists('image') && user_access('create images')) {
     // On other img_assist_pages I've added the javascript using the body onload
     // attribute, but for this page will also need the collapse functions and
@@ -650,29 +675,28 @@ function img_assist_upload() {
 /**
  * Implementation of hook_form_alter().
  * 
- * Add a submit callback to image_node_form which alters the redirect.
+ * Reroute submit button callback to our own handler to be able to redirect
+ * the user after saving the node.
+ *
+ * @see img_assist_node_form_submit()
  */
-function img_assist_form_alter($form_id, &$form) {
-  switch ($form_id) {
-    case 'image_node_form':
-      if (arg(0) != 'img_assist') {
-        break;
-      }
-      if (!is_array($form['#submit'])) $form['#submit'] = array();
-      $form['#submit'] += array('img_assist_node_form_submit' => array($form));
-      break;
+function img_assist_form_alter(&$form, &$form_state, $form_id) {
+  if ($form_id == 'image_node_form' && arg(0) == 'img_assist') {
+    $form['buttons']['submit']['#submit'] = array('img_assist_node_form_submit');
   }
 }
 
 /**
  * Submit callback for image_node_form.
- * 
- * Change the redirect from node/$nid to img_assist/properties/$nid.
  */
-function img_assist_node_form_submit($form_id, $form_values) {
-  // Get the nid of the newly created image (caught by img_assist_nodeapi).
-  global $_img_assist_saved_image;
-  drupal_goto('img_assist/properties/'. $_img_assist_saved_image);
+function img_assist_node_form_submit($form, &$form_state) {
+  // Execute regular node submit handler.
+  node_form_submit($form, $form_state);
+
+  if ($form_state['nid']) {
+    // Send to different url.
+    $form_state['redirect'] = 'img_assist/properties/'. $form_state['nid'];
+  }
 }
 
 /**
@@ -726,14 +750,16 @@ function img_assist_thumbs() {
       }
     }
     
+    $num_rows = FALSE;
     $show_amount = variable_get('img_assist_preview_count', 10);
     $result = pager_query($query, $show_amount, $element = 0, $count_query = NULL, $params);
     while ($row = db_fetch_object($result)) {
       $node    = node_load(array('nid' => $row->nid));
       $image   = img_assist_display($node, IMAGE_THUMBNAIL);
-      $output .= l($image, 'img_assist/properties/'. $node->nid, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = TRUE) ."\n";
+      $output .= l($image, 'img_assist/properties/'. $node->nid, array('html' => TRUE)) ."\n";
+      $num_rows = TRUE;
     }
-    if (!db_num_rows($result)) {
+    if (!$num_rows) {
       $output .= t('No images were found. Please upload a new image or browse images by a different category.');
     }
     
@@ -755,7 +781,7 @@ function img_assist_properties() {
   $update = (arg(3)) ? 1 : 0;
   
   if (is_numeric($nid)) {
-    $node = node_load(array('nid' => $nid));
+    $node = node_load($nid);
     
     // Setup a default caption & description.
     $node->title = str_replace("\r", ' ', strip_tags($node->title));
@@ -775,7 +801,7 @@ function img_assist_properties() {
 /**
  * Construct the image properties form.
  */
-function img_assist_properties_form($node, $update) {
+function img_assist_properties_form($form_state, $node, $update) {
   $image_info = image_get_info(file_create_path($node->images[IMAGE_ORIGINAL]));
   
   // Select (or generate) a preview image.
@@ -1021,8 +1047,8 @@ function img_assist_properties_form($nod
   return $form;
 }
 
-function img_assist_properties_form_validate($form_id, $form_values) {
-  $html = img_assist_render_image($form_values);
+function img_assist_properties_form_validate($form, &$form_state) {
+  $html = img_assist_render_image($form_state['values']);
   img_assist_set_htmlcode($html);
   drupal_goto('img_assist/insert_html');
 }
@@ -1166,16 +1192,7 @@ function img_assist_display(&$node, $siz
     _img_assist_build_derivatives($node, $size);
   }
   
-  if (empty($node->images[$label])) {
-    return;
-  }
-  
-  // Get actual size ($size is just a bounding box).
-  $info = image_get_info(file_create_path($node->images[$label]));
-  $attributes['class']  = 'image image-'. $label . (isset($attributes['class']) ? ' '. $attributes['class'] : '');
-  $attributes['width']  = $info['width'];
-  $attributes['height'] = $info['height'];
-  return theme('image_display', $node, $label, file_create_url($node->images[$label]), $attributes);
+  return image_display($node, $label);
 }
 
 /**
@@ -1236,14 +1253,15 @@ function _img_assist_build_derivatives(&
 }
 
 function _img_assist_remove($node, $size) {
-  $result = db_query("SELECT * FROM {files} WHERE nid = %d AND filename = '%s'", $node->nid, $size['key']);
+  $result = db_query("SELECT * FROM {files} f INNER JOIN {image} i WHERE f.fid = i.fid AND i.nid = %d AND f.filename = '%s'", $node->nid, $size['key']);
   while ($file = db_fetch_object($result)) {
     // Never delete original image.
     if ($file->filepath != $node->images[IMAGE_ORIGINAL]) {
       // Delete image file.
       file_delete(file_create_path($file->filepath));
       // Delete file reference in database.
-      db_query("DELETE FROM {files} WHERE nid = %d AND filename = '%s'", $node->nid, $size['key']);
+      db_query("DELETE FROM {files} WHERE fid = %d AND filename = '%s'", $file->fid, $size['key']);
+      db_query("DELETE FROM {image} WHERE nid = %d AND fid = '%d'", $node->nid, $file->fid);
     }
   }
 }
@@ -1471,7 +1489,7 @@ function img_assist_map_delete($node) {
  */
 function img_assist_map_load($nid) {
   $imagemap = array();
-  $result = db_query('SELECT * FROM {files} f INNER JOIN {img_assist_map} i ON f.nid = i.iid WHERE f.nid = %d', $nid);
+  $result = db_query('SELECT * FROM {image} f INNER JOIN {img_assist_map} i ON f.nid = i.iid WHERE f.nid = %d', $nid);
   while ($data = db_fetch_object($result)) {
     $imagemap[] = $data->nid;
   }
@@ -1605,12 +1623,13 @@ function theme_img_assist_textarea_link(
   else {
     $link = t('Add image');
   }
-  $output .= l($link, 'img_assist/load/textarea', array(
-    'class' => 'img_assist-link',
-    'id' => 'img_assist-link-'. $element['#id'],
-    'title' => t('Click here to add images'),
+  $attribs = array(
+    'class'   => 'img_assist-link',
+    'id'      => 'img_assist-link-'. $element['#id'],
+    'title'   => t('Click here to add images'),
     'onclick' => 'window.open(this.href, \'img_assist_link\', \'width=600,height=350,scrollbars=yes,status=yes,resizable=yes,toolbar=no,menubar=no\'); return false;',
-  ), 'textarea='. $element['#name'], NULL, FALSE, TRUE);
+  );
+  $output .= l($link, 'img_assist/load/textarea', array('attributes' => $attribs, 'query' => 'textarea='. $element['#name'], 'html' => TRUE));
   $output .= '</div>';
   return $output;
 }
@@ -1644,7 +1663,7 @@ function theme_img_assist_inline($node, 
   }
   
   if ($link == 'node') {
-    $output .= l($img_tag, 'node/'. $node->nid, array(), NULL, NULL, FALSE, TRUE);
+    $output .= l($img_tag, 'node/'. $node->nid, array('html' => TRUE));
   }
   elseif ($link == 'popup') {
     $popup_size = variable_get('img_assist_popup_label', IMAGE_PREVIEW);
@@ -1652,10 +1671,10 @@ function theme_img_assist_inline($node, 
     $width      = $info['width'];
     $height     = $info['height'];
     $popup_url  = file_create_url($node->images[variable_get('img_assist_popup_label', IMAGE_PREVIEW)]);
-    $output .= l($img_tag, $popup_url, array('onclick' => "launch_popup({$node->nid}, {$width}, {$height}); return false;", 'target' => '_blank'), NULL, NULL, FALSE, TRUE);
+    $output .= l($img_tag, $popup_url, array('attributes' => array('onclick' => "launch_popup({$node->nid}, {$width}, {$height}); return false;", 'target' => '_blank'), 'html' =>TRUE));
   }
   elseif ($link == 'url') {
-    $output .= l($img_tag, $url, array(), NULL, NULL, FALSE, TRUE);
+    $output .= l($img_tag, $url, array('html' => TRUE));
   }
   else {
     $output .= $img_tag;
@@ -1694,7 +1713,7 @@ function theme_img_assist_popup($content
   $output .= "</head>\n";
   $output .= '<body'. drupal_attributes($attributes) .">\n";
   $output .= "<!-- begin content -->\n";
-  $output .= l($content, '', array('onclick' => 'javascript:window.close();'), NULL, NULL, FALSE, TRUE);
+  $output .= l($content, '', array('attributes' => array('onclick' => 'javascript:window.close();'), 'html' => TRUE));
   $output .= "<!-- end content -->\n";
   $output .= '</body>';
   $output .= '</html>';
@@ -1702,6 +1721,7 @@ function theme_img_assist_popup($content
 }
 
 function theme_img_assist_page($content, $attributes = NULL) {
+  $title = drupal_get_title();
   $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
   $output .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'."\n";
   $output .= "<head>\n";
@@ -1793,7 +1813,7 @@ function img_assist_load_images($tid = N
   }
   
   if (!$image) {
-    $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, f.* FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {files} f ON n.nid = f.nid AND n.type = 'image' ". $where ." ORDER BY n.changed DESC"));
+    $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, f.* FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {image} f ON n.nid = f.nid AND n.type = 'image' ". $where ." ORDER BY n.changed DESC"));
     while ($node = db_fetch_object($result)) {
       $node->filepath = file_create_path($node->filepath);
       $dim = getimagesize($node->filepath, $info);
@@ -1816,7 +1836,7 @@ function img_assist_load_images($tid = N
     // Note: If we didn't use "LIKE 'image/%%'" here we could load other files.
     // Might be interesting to expand on this someday.
     if ($image) {
-      $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, f.* FROM {files} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid WHERE f.nid = n.nid AND f.filemime LIKE 'image/%%' AND n.nid NOT IN (". implode(array_keys($image), ', ') .") ". $where ." ORDER BY n.changed DESC"));
+      $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, f.* FROM {image} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid WHERE f.nid = n.nid AND f.filemime LIKE 'image/%%' AND n.nid NOT IN (". implode(array_keys($image), ', ') .") ". $where ." ORDER BY n.changed DESC"));
       while ($node = db_fetch_object($result)) {
         $node->filepath = file_create_path($node->filepath);
         $dim = getimagesize($node->filepath, $info);
@@ -1847,7 +1867,7 @@ function img_assist_load_images($tid = N
  * Load an image from the database.
  */
 function img_assist_load_image($id, $derivatives = TRUE) {
-  $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, f.* FROM {files} f, {node} n WHERE f.nid = n.nid AND f.fid = %d'), $id));
+  $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, f.* FROM {image} f, {node} n WHERE f.nid = n.nid AND f.fid = %d'), $id));
   $node->filepath = file_create_path($node->filepath);
   
   if (!$derivatives) {
@@ -1862,7 +1882,7 @@ function img_assist_load_image($id, $der
       foreach (image_get_sizes() as $size) {
         if ($size['label'] == $node->filename) {
           $image_module_image = TRUE;
-          $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, r.teaser, f.* FROM {files} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid WHERE f.nid = n.nid AND n.nid = %d'), $node->nid);
+          $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, r.teaser, f.* FROM {image} f, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid WHERE f.nid = n.nid AND n.nid = %d'), $node->nid);
           while ($node = db_fetch_object($result)) {
             $node->filepath = file_create_path($node->filepath);
             $dim = getimagesize($node->filepath, $info);
@@ -1895,7 +1915,7 @@ function img_assist_load_image($id, $der
 function _img_assist_get_thumbnail(&$image) {
   static $thumbs = array();
   if ($thumbs[$image->nid] === NULL) {
-    $thumbpath = file_create_path(db_result(db_query("SELECT filepath FROM {files} WHERE nid = %d AND filename = '%s'", $image->nid, IMAGE_THUMBNAIL)));
+    $thumbpath = file_create_path(db_result(db_query("SELECT filepath FROM {image} WHERE nid = %d AND filename = '%s'", $image->nid, IMAGE_THUMBNAIL)));
     // In old versions of image.module thumbs were named 'thumb_filename.ext'.
     if (!file_exists($thumbpath)) {
       $pos = strrpos($image->filepath, '/') + 1;
Index: img_assist_popup.css
===================================================================
RCS file: img_assist_popup.css
diff -N img_assist_popup.css
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ img_assist_popup.css	3 Apr 2008 22:05:24 -0000
@@ -0,0 +1,102 @@
+/* $Id$ */
+
+body#img_assist_popup {
+  margin: 0;
+  padding: 0;
+}
+
+body.img_assist {
+  margin: 0px;
+  padding: 5px;
+  width: auto;
+  min-width: 0;
+  color: #000000;
+  font-family: Arial, Helvetica, sans-serif;
+  font-size: .8em;
+  background-color: #efefef;
+}
+/* Thin line between the header frame and the main frame */
+body#img_assist_thumbs, body#img_assist_upload, body#img_assist_properties {
+  border-top: 1px solid #000;
+}
+/* Darker background color in the header frame */
+body#img_assist_header {
+  background-color:#ccc;
+  margin: 0;
+}
+/* Thin border around images */
+.img_assist img  {
+  border: 1px solid #000;
+}
+.img_assist-button {
+  font-weight: bold;
+  margin: 3px;
+}
+.img_assist img {
+  display: inline; /* pushbutton theme changes the display to block */
+}
+.img_assist .messages {
+  border: 1px solid #000;
+  background-color: #ccc;
+  padding: 2px;
+  margin: 3px 0px 6px 0px;
+}
+
+/* Upload Window */
+.img_assist .node-form {
+  width: 95%;
+}
+
+/* Properties Window */
+.img_assist #preview {
+  padding: 5px 10px 5px 5px;
+}
+.img_assist .form-item { /* the first form field on the properties frame should be at the top of the page  */
+  margin-top: 0px;
+  margin-bottom: 1em;
+}
+.img_assist #caption {
+  display: block;
+}
+.img_assist #header-browse div.form-item,
+.img_assist #link-group div.form-item,
+.img_assist #edit-size div.form-item,
+.img_assist #size-other div.form-item {
+  display: inline;
+}
+.img_assist #alignment {
+  text-align: left;
+}
+.img_assist #edit-title, .img_assist #edit-desc {
+  width: 99%;
+}
+.img_assist #edit-link {
+  width: 155px;
+}
+.img_assist #edit-url {
+  width: 150px;
+}
+.img_assist #edit-align {
+  width: 100px;
+}  
+#finalhtmlcode {
+  display: none;
+  visibility: hidden;
+}
+
+/* Header Frame */
+#header-uploading, #header-properties, #header-browse {
+  float: left; 
+  width: 80%;
+}
+#header-startover, #header-cancel {
+  float: right;
+  width: 19%;
+  text-align: right;
+}
+
+#header-uploading input, #header-properties input, #header-browse input, #header-startover input, #header-cancel input, #header-uploading select, #header-properties select, #header-browse select {
+  margin-top: 0;
+  margin-bottom: 0;
+  vertical-align: baseline;
+}
Index: img_assist_popup.js
===================================================================
RCS file: img_assist_popup.js
diff -N img_assist_popup.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ img_assist_popup.js	3 Apr 2008 22:45:18 -0000
@@ -0,0 +1,162 @@
+/* $Id: img_assist.js,v 1.4.2.5 2007/11/19 02:27:49 sun Exp $ */
+
+var currentMode;
+
+function onChangeBrowseBy(el) {
+	frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/thumbs/' + el.value;
+}
+
+function onClickUpload() {
+  frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/upload';
+}
+
+function onClickStartOver() {
+  frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/thumbs/myimages';
+}
+
+function updateCaption() {
+  var caption = frames['img_assist_main'].document.getElementById('caption');
+  var title = frames['img_assist_main'].document.img_assist['edit-title'].value;
+  var desc = frames['img_assist_main'].document.img_assist['edit-desc'].value;
+  if (desc != '') {
+    title = title + ': ';
+  }
+  caption.innerHTML = '<strong>' + title + '</strong>' + desc;
+}
+
+function onChangeHeight() {
+  var formObj = frames['img_assist_main'].document.forms[0];
+  var aspect = formObj['edit-aspect'].value;
+  var height = formObj['edit-height'].value;
+  formObj['edit-width'].value = Math.round(height * aspect);
+}
+
+function onChangeWidth() {
+  var formObj = frames['img_assist_main'].document.forms[0];
+  var aspect = formObj['edit-aspect'].value;
+  var width = formObj['edit-width'].value;
+  formObj['edit-height'].value = Math.round(width / aspect);
+}
+
+function onChangeLink() {
+  var formObj = frames['img_assist_main'].document.forms[0];
+	if (formObj['edit-link-options-visible'].value == 1) {
+		if (formObj['edit-link'].value == 'url') {
+			showElement('edit-url', 'inline');
+		}
+		else {
+			hideElement('edit-url');
+		}
+	}
+}
+
+function onChangeSizeLabel() {
+  var formObj = frames['img_assist_main'].document.forms[0];
+  if (formObj['edit-size-label'].value == 'other') {
+    showElement('size-other', 'inline');
+  }
+  else {
+    hideElement('size-other');
+    // get the new width and height
+    var size = formObj['edit-size-label'].value.split('x');
+    // this array is probably a bounding box size, not an actual image
+    // size, so now we use the known aspect ratio to find the actual size
+    var aspect = formObj['edit-aspect'].value;
+    var width = size[0];
+    var height = size[1];
+    if (Math.round(width / aspect) <= height) {
+    	// width is controlling factor
+      height = Math.round(width / aspect);
+    }
+    else {
+    	// height is controlling factor
+      width = Math.round(height * aspect);
+    }
+    // fill the hidden width and height textboxes with these values
+    formObj['edit-width'].value = width;
+    formObj['edit-height'].value = height;
+  }
+}
+
+function setHeader(mode) {
+	if (currentMode != mode) {
+		frames['img_assist_header'].window.location.href = BASE_URL + 'index.php?q=img_assist/header/' + mode;
+	}
+	currentMode = mode;
+}
+
+function showElement(id, format) {
+  var docObj = frames['img_assist_main'].document;
+  format = (format) ? format : 'block';
+  if (docObj.layers) {
+    docObj.layers[id].display = format;
+  }
+  else if (docObj.all) {
+    docObj.all[id].style.display = format;
+  }
+  else if (docObj.getElementById) {
+    docObj.getElementById(id).style.display = format;
+  }
+}
+
+function hideElement(id) {
+  var docObj = frames['img_assist_main'].document;
+  if (docObj.layers) {
+    docObj.layers[id].display = 'none';
+  }
+  else if (docObj.all) {
+    docObj.all[id].style.display = 'none';
+  }
+  else if (docObj.getElementById) {
+    docObj.getElementById(id).style.display = 'none';
+  }
+}
+
+function launch_popup(nid, mw, mh) {
+	var ox = mw;
+	var oy = mh;
+	if((ox>=screen.width) || (oy>=screen.height)) {
+		var ox = screen.width-150;
+		var oy = screen.height-150;
+		var winx = (screen.width / 2)-(ox / 2);
+		var winy = (screen.height / 2)-(oy / 2);
+		var use_scrollbars = 1;
+	}
+	else {
+		var winx = (screen.width / 2)-(ox / 2);
+		var winy = (screen.height / 2)-(oy / 2);
+		var use_scrollbars = 0;
+	}
+	var win = window.open(BASE_URL + 'index.php?q=img_assist/popup/' + nid, 'imagev', 'height='+oy+'-10,width='+ox+',top='+winy+',left='+winx+',scrollbars='+use_scrollbars+',resizable');
+}
+
+function insertImage() {
+  if (window.opener) {
+    // Get variables from the fields on the properties frame
+    var formObj = frames['img_assist_main'].document.forms[0];
+		// Get mode	(see img_assist.module for detailed comments)
+		if (formObj['edit-insertmode'].value == 'html') {
+			// return so the page can submit normally and generate the HTML code
+			return true;
+		}
+		else if (formObj['edit-insertmode'].value == 'html2') {
+			// HTML step 2 (processed code, ready to be inserted)
+			var content = getHTML(formObj);
+		}
+		else {
+			var content = getFilterTag(formObj);
+		}
+		insertToEditor(content);
+		return false;
+		
+  }
+  else {
+		alert('The image cannot be inserted because the parent window cannot be found.');
+		return false;
+	}
+}
+
+function getHTML(formObj) {
+	var html = frames['img_assist_main'].document.getElementById('finalhtmlcode').value;
+	return html;
+}
