Index: webfm.module
===================================================================
--- webfm.module	(revision 78)
+++ webfm.module	(working copy)
@@ -45,6 +45,33 @@
 }
 
 /**
+ * Implementation of hook_link().
+ */
+function webfm_link($type, $node = NULL, $teaser = FALSE) {
+  $links = array();
+
+  // Display a link with the number of attachments
+  if ($teaser && $type == 'node' && isset($node->webfm_files) && user_access('see webfm_attachments')) {
+//tbd for list usage
+//    $num_files = 0;
+//    foreach ($node->webfm_files as $file) {
+//      if ($file->list) {
+//        $num_files++;
+//      }
+//    }
+//    if($num_files) {
+      if($num_files = count($node->webfm_files)) {
+      $links['upload_attachments'] = array(
+        'title' => format_plural($num_files, '1 attachment', '@count attachments'),
+        'href' => "node/$node->nid",
+        'attributes' => array('title' => t('Read full article to view attachments.')),
+        'fragment' => 'attachments');
+    }
+  }
+  return $links;
+}
+
+/**
  * Implementation of hook_settings().
  */
 function webfm_admin_settings() {
@@ -447,7 +474,7 @@
     //make sure ftp root is outside of webfm root
     if (wfm_check_path($ftp_path, $root_path)) {
       drupal_set_message(t('illegal name for ftp root directory'), error);
-      print drupal_to_js(array('status' => FALSE, 'data' => 'illegal name for ftp root directory'));
+      print drupal_json(array('status' => FALSE, 'data' => 'illegal name for ftp root directory'));
       exit();
     }
 
@@ -461,12 +488,12 @@
             $db_check = FALSE;
           // prevent any ../ shenanigans
           if($source && !ereg('\.\.', $source)) {
-            print drupal_to_js(array('status' => webfm_delete($source, $db_check)));
+            print drupal_json(array('status' => webfm_delete($source, $db_check)));
           } else {
-            print drupal_to_js(array('status' => FALSE, 'data' => 'illegal dir'));
+            print drupal_json(array('status' => FALSE, 'data' => 'illegal dir'));
           }
         } else {
-          print drupal_to_js(array('status' => FALSE, 'data' => 'insufficient params'));
+          print drupal_json(array('status' => FALSE, 'data' => 'insufficient params'));
         }
         exit();
         break;
@@ -477,10 +504,10 @@
           if(($source = wfm_check_path(trim(rawurldecode($_POST["param0"])), $root_path)) ||
              ($source = wfm_check_path(trim(rawurldecode($_POST["param0"])), $ftp_path))) {
             $dest = t("New_Folder");
-            print drupal_to_js(array('status' => webfm_mkdir($source, $dest)));
+            print drupal_json(array('status' => webfm_mkdir($source, $dest)));
           }
         } else {
-          print drupal_to_js(array('status' => FALSE, 'data' => 'insufficient params'));
+          print drupal_json(array('status' => FALSE, 'data' => 'insufficient params'));
         }
         exit();
         break;
@@ -496,12 +523,12 @@
 
           // Destination path must be under webfm_root
           if($source && ($dest = wfm_check_path(trim(rawurldecode($_POST["param1"])), $root_path)) && ($source != $dest)) {
-            print drupal_to_js(array('status' => webfm_move($source, $dest, $db_check)));
+            print drupal_json(array('status' => webfm_move($source, $dest, $db_check)));
           } else {
-            print drupal_to_js(array('status' => FALSE, 'data' => 'move operation not permitted'));
+            print drupal_json(array('status' => FALSE, 'data' => 'move operation not permitted'));
           }
         } else {
-          print drupal_to_js(array('status' => FALSE, 'data' => 'insufficient params'));
+          print drupal_json(array('status' => FALSE, 'data' => 'insufficient params'));
         }
         exit();
         break;
@@ -517,15 +544,15 @@
             $dest = trim(rawurldecode($_POST["param1"]));
             // prevent any ../ shenanigans
             if(!ereg('\.\.', $dest)) {
-              print drupal_to_js(array('status' => webfm_rename($source, $dest, $db_check)));
+              print drupal_json(array('status' => webfm_rename($source, $dest, $db_check)));
             } else {
-              print drupal_to_js(array('status' => FALSE, 'data' => 'illegal name'));
+              print drupal_json(array('status' => FALSE, 'data' => 'illegal name'));
             }
           } else {
-            print drupal_to_js(array('status' => FALSE, 'data' => 'illegal dir'));
+            print drupal_json(array('status' => FALSE, 'data' => 'illegal dir'));
           }
         } else {
-          print drupal_to_js(array('status' => FALSE, 'data' => 'insufficient params'));
+          print drupal_json(array('status' => FALSE, 'data' => 'insufficient params'));
         }
         exit();
         break;
@@ -534,7 +561,7 @@
       case "readtree":
         //Build directory tree
         $tree = new build_dir_tree($root_path, false);
-        print drupal_to_js(array('status' => TRUE, 'tree' => $tree->get_dirtree(), 'current' => $root_path));
+        print drupal_json(array('status' => TRUE, 'tree' => $tree->get_dirtree(), 'current' => $root_path));
         exit();
         break;
 
@@ -542,7 +569,7 @@
       case "readftptree":
         //Build directory tree
         $tree = new build_dir_tree($ftp_path, false);
-        print drupal_to_js(array('status' => TRUE, 'tree' => $tree->get_dirtree(), 'current' => $root_path));
+        print drupal_json(array('status' => TRUE, 'tree' => $tree->get_dirtree(), 'current' => $root_path));
         exit();
         break;
 
@@ -565,22 +592,22 @@
 
         if($rootpath_var) {
           if(!is_dir($source)) {
-            print drupal_to_js(array('status' => FALSE, 'data' => 'directory does not exist'));
+            print drupal_json(array('status' => FALSE, 'data' => 'directory does not exist'));
             exit();
           }
           if(ereg('\.\.', $source)) {
-            print drupal_to_js(array('status' => FALSE, 'data' => 'illegal read dir'));
+            print drupal_json(array('status' => FALSE, 'data' => 'illegal read dir'));
             exit();
           }
           //Build current directory listings
           $dirlist = new build_dir_list($source, $rootpath_var);
           if($dirlist->get_breadcrumb())
-            print drupal_to_js(array('status' => TRUE, 'current' => $source, 'bcrumb' => $dirlist->get_breadcrumb(), 'dirs' => $dirlist->get_dir_listing(), 'files' => $dirlist->get_file_listing()));
+            print drupal_json(array('status' => TRUE, 'current' => $source, 'bcrumb' => $dirlist->get_breadcrumb(), 'dirs' => $dirlist->get_dir_listing(), 'files' => $dirlist->get_file_listing()));
           else
             //invalid directory
-            print drupal_to_js(array('status' => FALSE, 'data' => 'invalid dir'));
+            print drupal_json(array('status' => FALSE, 'data' => 'invalid dir'));
         } else {
-          print drupal_to_js(array('status' => FALSE, 'data' => 'invalid path'));
+          print drupal_json(array('status' => FALSE, 'data' => 'invalid path'));
         }
         exit();
         break;
@@ -595,10 +622,10 @@
             $maxlevel = 0;
             @clearstatcache();
             $search = new searchFiles($source, $searchpattern, $maxlevel, $regexpsearch);
-            print drupal_to_js(array('files' => $search->get_files()));
+            print drupal_json(array('files' => $search->get_files()));
           }
         } else {
-          print drupal_to_js(array('status' => FALSE, 'data' => 'insufficient params'));
+          print drupal_json(array('status' => FALSE, 'data' => 'insufficient params'));
         }
         exit();
         break;
@@ -608,12 +635,12 @@
         if(isset($_POST["param0"])) {
           $fid = rawurldecode($_POST["param0"]);
           if(($meta = webfm_get_file_record($fid)) !== FALSE) {
-            print drupal_to_js(array('status' => TRUE, 'meta' => $meta));
+            print drupal_json(array('status' => TRUE, 'meta' => $meta));
           } else {
-            print drupal_to_js(array('status' => FALSE, 'data' => 'file record not found'));
+            print drupal_json(array('status' => FALSE, 'data' => 'file record not found'));
           }
         } else {
-          print drupal_to_js(array('status' => FALSE, 'data' => 'insufficient params'));
+          print drupal_json(array('status' => FALSE, 'data' => 'insufficient params'));
         }
         exit();
         break;
@@ -621,9 +648,9 @@
       //Change file metadata
       case "putmeta":
         if(isset($_POST["param0"]) && isset($_POST["param1"])) {
-          print drupal_to_js(array('status' => webfm_putmeta(rawurldecode($_POST["param0"]), rawurldecode($_POST["param1"]))));
+          print drupal_json(array('status' => webfm_putmeta(rawurldecode($_POST["param0"]), rawurldecode($_POST["param1"]))));
         } else {
-          print drupal_to_js(array('status' => FALSE, 'data' => 'unknown action'));
+          print drupal_json(array('status' => FALSE, 'data' => 'unknown action'));
         }
         exit();
         break;
@@ -634,9 +661,9 @@
         // the 'node' var passed via AJAX is the action attribute of id=node-form
         if (($node_num = strstr($node_str, 'node/')) !== FALSE) {
           $node_arr = explode("/", $node_num);
-          print drupal_to_js(array('status' => TRUE, 'attach' => webfm_get_attachments($node_arr[1])));
+          print drupal_json(array('status' => TRUE, 'attach' => webfm_get_attachments($node_arr[1])));
         } else {
-          print drupal_to_js(array('status' => FALSE, 'data' => 'illegal path'));
+          print drupal_json(array('status' => FALSE, 'data' => 'illegal path'));
         }
         exit();
         break;
@@ -648,18 +675,18 @@
           $fid = rawurldecode($_POST["param0"]);
           if(($_file = webfm_get_file_record($fid)) !== FALSE) {
             $file = new fdesc($_file);
-            print drupal_to_js(array('status' => TRUE, 'attach' => $file));
+            print drupal_json(array('status' => TRUE, 'attach' => $file));
           } else {
-            print drupal_to_js(array('status' => FALSE, 'data' => 'file record not found'));
+            print drupal_json(array('status' => FALSE, 'data' => 'file record not found'));
           }
         } else {
-          print drupal_to_js(array('status' => FALSE, 'data' => 'insufficient params'));
+          print drupal_json(array('status' => FALSE, 'data' => 'insufficient params'));
         }
         exit();
         break;
 
       default:
-        print drupal_to_js(array('status' => FALSE, 'data' => 'unknown operation'));
+        print drupal_json(array('status' => FALSE, 'data' => 'unknown operation'));
         exit();
         break;
     }
