Binary files attachment-4.7.x-1.x-dev/.DS_Store and attachment/.DS_Store differ
diff -Nurp --exclude=.svn --exclude=po attachment-4.7.x-1.x-dev/attachment.info attachment/attachment.info
--- attachment-4.7.x-1.x-dev/attachment.info	1969-12-31 16:00:00.000000000 -0800
+++ attachment/attachment.info	2007-06-26 13:29:47.000000000 -0700
@@ -0,0 +1,5 @@
+; $Id$
+name = Attachment
+description = Adds support for attaching files to nodes and downloading them.
+dependencies = filemanager
+
diff -Nurp --exclude=.svn --exclude=po attachment-4.7.x-1.x-dev/attachment.install attachment/attachment.install
--- attachment-4.7.x-1.x-dev/attachment.install	2007-07-04 15:17:26.000000000 -0700
+++ attachment/attachment.install	2007-06-25 14:33:17.000000000 -0700
@@ -13,41 +13,51 @@ function attachment_update_1() {
  * Install the initial schema.
  */
 function attachment_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query(
-  <<<MYSQL_UPDATE
-        CREATE TABLE {attachment} (
-          aid int(10) unsigned NOT NULL,
-          nid int(10) unsigned NOT NULL,
-          fid int(10) unsigned NOT NULL,
-          filename varchar(255) NOT NULL,
-          title varchar(255) NOT NULL,
-          description varchar(255) NOT NULL,
-          size int(12) NOT NULL,
-          hidden char(1) NOT NULL,
-          PRIMARY KEY (aid)
-        ) /*!40100 DEFAULT CHARACTER SET utf8 */;
+  if( ! db_table_exists('attachment') ) {
+    switch ($GLOBALS['db_type']) {
+      case 'mysql':
+      case 'mysqli':
+        db_query(
+<<<MYSQL_UPDATE
+          CREATE TABLE {attachment} (
+            aid int(10) unsigned NOT NULL,
+            nid int(10) unsigned NOT NULL,
+            fid int(10) unsigned NOT NULL,
+            filename varchar(255) NOT NULL,
+            title varchar(255) NOT NULL,
+            description varchar(255) NOT NULL,
+            size int(12) NOT NULL,
+            hidden char(1) NOT NULL,
+            PRIMARY KEY (aid)
+          ) /*!40100 DEFAULT CHARACTER SET utf8 */;
 MYSQL_UPDATE
-      );
-      break;
-
-    case 'pgsql':
-      db_query(
+        );
+        break;
+  
+      case 'pgsql':
+        db_query(
 <<<PGSQL_UPDATE
-      create table {attachment} (
-        aid serial primary key,
-        nid integer not null,
-        fid integer not null,
-        filename varchar(255) not null,
-        title varchar(255) not null,
-        description varchar(255) not null,
-        size integer not null,
-        hidden char(1) not null
-      );
+        create table {attachment} (
+          aid serial primary key,
+          nid integer not null,
+          fid integer not null,
+          filename varchar(255) not null,
+          title varchar(255) not null,
+          description varchar(255) not null,
+          size integer not null,
+          hidden char(1) not null
+        );
 PGSQL_UPDATE
-      );
-      break;
-  }
+        );
+        break;
+    } // End switch($GLOBALS['db_type'])
+  } // End if( ! db_table_exists('attachment') )
+}
+
+/**
+ * Uninstall table
+ */
+function attachment_uninstall() 
+{
+  db_query( 'DROP TABLE {attachment}' );
 }
diff -Nurp --exclude=.svn --exclude=po attachment-4.7.x-1.x-dev/attachment.module attachment/attachment.module
--- attachment-4.7.x-1.x-dev/attachment.module	2007-07-04 15:17:26.000000000 -0700
+++ attachment/attachment.module	2007-07-04 14:59:35.000000000 -0700
@@ -5,6 +5,7 @@ define(ATTACHMENT_EXTENSION_WHITELIST, v
 
 function attachment_form_alter($form_id, &$form) {
   $type = $form['type']['#value'];
+  $oldtype = $form['old_type']['#value'];
 
   switch ($form_id) {
     // node edit form
@@ -16,8 +17,16 @@ function attachment_form_alter($form_id,
           $node->attachments = $ret['attachments'];
         }
         $form['#attributes'] = array('enctype' => 'multipart/form-data');
+        
+        // We default to a collapsed region, but it's annoying if it's closed when we actually have
+        // something attached.  Test for it and set accordingly.
+        $collapsed = true;  // Default to collapsed.
+        if( isset($node->attachments) )
+        {
+          $collapsed = false;
+        }
 
-        $form['attachments'] = array('#type'=>'fieldset', '#title'=>t('Attachments'), '#tree'=>true, '#collapsible'=>true, '#weight'=>1);
+        $form['attachments'] = array('#type'=>'fieldset', '#title'=>t('Attachments'), '#tree'=>true, '#collapsible'=>true, '#collapsed'=>$collapsed, '#weight'=>1);
         $form['attachments']['#theme'] = 'attachment_form';
 
         foreach ((array)$node->attachments as $key=>$attachment) {
@@ -39,11 +48,11 @@ function attachment_form_alter($form_id,
       break;
 
     // node settings form
-    case $type .'_node_settings':
-      $form['workflow']['attachment_node_'. $type] = array(
+    case 'node_type_form':
+      $form['workflow']['attachment_settings'] = array(
         '#type'=>'radios',
         '#title'=>t('Attachments'),
-        '#default_value'=>variable_get('attachment_node_'. $type, 0),
+        '#default_value'=>variable_get('attachment_node_'. $oldtype, 0),
         '#options'=>array(0=>t('Disabled'), 1=>t('Enabled')),
       );
       break;
@@ -54,10 +63,14 @@ function attachment_form_alter($form_id,
  * Implementation of hook_nodeapi.
  */
 function attachment_nodeapi(&$node, $op, $arg = 0, $arg2 = 0) {
+  
   switch ($op) {
     case 'load':
       return attachment_load($node);
-    case 'view':
+      
+    case 'alter':
+      // This used to be in $op==view.  Not sure about it, but looks like alter is a good place for 
+      // it since it looks like it has to do str_replace.
       foreach ((array)$node->attachments as $attachment) {
         if ($attachment['working']) {
           $file = module_invoke('filemanager', 'get_file_info', $attachment['fid']);
@@ -67,14 +80,23 @@ function attachment_nodeapi(&$node, $op,
           $node->teaser = str_replace($activeurl, $workingurl, $node->teaser);
         }
       }
+      return;
+
+    case 'view':
 
       // If this is not a teaser add our attachment list to the end of the body
       if (_attachment_countvisible($node)>0) {
         if (!$arg) {
-          $node->body .= '<br /><a name="attachments"></a>' . theme('attachments', $node);
+          $node->content['attachment'] = array(
+            '#value' => '<br /><a name="attachments"></a>' . theme('attachments', $node),
+            '#weight' => 10
+            );
         }
         if (variable_get('attachment_display_teaser', 0)) {
-          $node->teaser .= '<br /><a name="attachments"></a>' . theme('attachments', $node);
+          $node->content['attachment'] = array(
+            '#value' => '<br /><a name="attachments"></a>' . theme('attachments', $node),
+            '#weight' => 10
+            );
         }
       }
       return;
@@ -111,13 +133,15 @@ function attachment_nodeapi(&$node, $op,
       return;
 
     case 'prepare':
-      if (isset($_POST['edit']['attachments'])) {
-        $node->attachments = $_POST['edit']['attachments'];
+      if( ($_POST['op'] == t('Preview')) || ($_POST['op'] == t('Submit')) )
+      {
+        $node->attachments = $_POST['attachments'];
       }
-
+      
       if ($_POST['fileop'] == t('Add')) {
         attachment_add($node);
       }
+      
 
       return;
   }
@@ -133,7 +157,7 @@ function attachment_perm() {
 /**
  * Implementation of hook_settings()
  */
-function attachment_settings() {
+function attachment_admin_settings() {
   $form['display'] = array(
     '#type' => 'fieldset',
     '#title' => t('Display settings')
@@ -163,7 +187,27 @@ function attachment_settings() {
     '#description' => t('List of extensions that are allowed to be uploaded without modification. All other extensions can still be uploaded, but they will be renamed to have a .txt file extension to protect your server from attackers.')
   );
 
-  return $form;
+  return system_settings_form($form);
+}
+
+/**
+ * Implementation of hook_menu()
+ */
+function attachment_menu($may_cache) {
+  $items = array();
+
+  if ($may_cache) {
+    $items[] = array( 
+      'path' => 'admin/settings/attachment', 
+      'title' => t('Attachment'),
+      'description' => t('Settings for Attachment module'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('attachment_admin_settings'),
+      'access' => user_access('administer site configuration'),
+      'type' => MENU_NORMAL_ITEM );
+  }
+
+  return $items;
 }
 
 /**
@@ -178,11 +222,9 @@ function attachment_filemanager_areas() 
  */
 function attachment_help($section) {
   switch ($section) {
-    case 'admin/modules#description':
-      return t('Adds support for attaching files to nodes and downloading them.');
     case 'admin/help#attachment':
       return t('<p>Attachments are files uploaded while creating nodes. These files can be used to add images to stories, blogs, etc as well as just adding documents for download.</p>
-                <p>There are two factors used to determine whether a user can add attachments to the node they are creating.  First the user is checked to make sure they have <em>add attachments</em> permission.  These permissions can be set on the <a href="%permissionurl%">permissions</a> page.  Second attachments must be enabled for that particular node type.  You can enable nodes on the <a href="%nodeconfigurl%">default workfow</a> page.</p>', array('%permissionurl' => url('admin/user/configure/permission'), '%nodeconfigurl' => url('admin/node/configure/defaults')));
+                <p>There are two factors used to determine whether a user can add attachments to the node they are creating.  First the user is checked to make sure they have <em>add attachments</em> permission.  These permissions can be set on the <a href="@permissionurl">permissions</a> page.  Second, attachments must be enabled for that particular node type.  You can enable attachments to nodes in the workflow section of each <a href="@nodeconfigurl">node type</a>.</p>', array('@permissionurl' => url('admin/user/access', NULL, 'module-attachment'), '@nodeconfigurl' => url('admin/content/types')));
    }
 }
 
@@ -197,7 +239,11 @@ function attachment_link($type, $node = 
       if ($main == 1 && !variable_get('attachment_display_teaser', 0)) {
         $count = _attachment_countvisible($node);
         if ($count > 0) {
-          $links[] = l(format_plural($count, 'attachment', '%count attachments'), "node/$node->nid", array('title' => t('View attachment list')), NULL, "attachments");
+          $links['attachment_tease_links'] = array(
+            'title' => format_plural($count, '1 attachment', '@count attachments'),
+            'href' => "node/$node->nid",
+            'attributes' => array('title' => t('View attachment list')),
+            'fragment' => "attachments" );
         }
       }
       break;
@@ -233,14 +279,14 @@ function theme_attachment_form($form) {
   foreach (element_children($form) as $key) {
     if ($key{0} != 'c') {
       $row = array();
-      $row[0]['data'] = form_render($form[$key]['display']);
+      $row[0]['data'] = drupal_render($form[$key]['display']);
       $row[0]['colspan'] = '4';
       $rows[] = $row;
       $row = array(
-        form_render($form[$key]['deleted']),
-        form_render($form[$key]['hidden']),
-        form_render($form[$key]['title']),
-        form_render($form[$key]['description']),
+        drupal_render($form[$key]['deleted']),
+        drupal_render($form[$key]['hidden']),
+        drupal_render($form[$key]['title']),
+        drupal_render($form[$key]['description']),
       );
       $rows[] = $row;
     }
@@ -250,7 +296,7 @@ function theme_attachment_form($form) {
     $output .= theme('table', $header, $rows);
   }
 
-  $output .= form_render($form);
+  $output .= drupal_render($form);
 
   return $output;
 }
@@ -377,7 +423,7 @@ function theme_attachments($node) {
 
   foreach ((array)$node->attachments as $attachment) {
     if (!$attachment['hidden'] && !$attachment['deleted']) {
-      $text = empty($attachment['title']) ? $attachment['filename'] : ($attachment['title'] . ' (' . $attachment['filename'] . ')');
+      $text = (empty($attachment['title'])) || (strcmp($attachment['title'], $attachment['filename']) == 0) ? $attachment['filename'] : ($attachment['title'] . ' (' . $attachment['filename'] . ')');
       $attrib = empty($attachment['description']) ? array() : array('title' => $attachment['description']);
       $row[0]['data'] = l($text, module_invoke('filemanager', 'url', $attachment['fid']), $attrib);
       $row[0]['data'] = module_invoke('filemanager', 'l', $text, $attachment['fid'], FALSE, $attrib, TRUE);
