Issue #1090216: Add MIME type icon compatibility for kml/kmz files.
[project/filefield.git] / filefield.token.inc
index 8b0cff5..e850186 100644 (file)
@@ -1,5 +1,9 @@
 <?php
-// $Id$
+
+/**
+ * @file
+ * Token hook implementations. Included if token.module is installed.
+ */
 
 /**
  * Implementation of hook_token_list().
 function filefield_token_list($type = 'all') {
   if ($type == 'field' || $type == 'all') {
     $tokens = array();
-    $tokens['file']['filefield-fid']                = t("File ID");
-    $tokens['file']['filefield-description']        = t("File description");
-    $tokens['file']['filefield-filename']           = t("File name");
-    $tokens['file']['filefield-filepath']           = t("File path");
-    $tokens['file']['filefield-filemime']           = t("File MIME type");
-    $tokens['file']['filefield-filesize']           = t("File size (in bytes)");
-    $tokens['file']['filefield-filesize_formatted'] = t("File size (pretty printed)");
-    $tokens['file']['filefield-view']               = t("Fully formatted HTML file tag");
-    $tokens['file']['filefield-onlyname']           = t("File name without extension.");
-    $tokens['file']['filefield-extension']          = t("File extension");
+    $tokens['file']['filefield-fid']                = t('File ID');
+    $tokens['file']['filefield-description']        = t('File description');
+    $tokens['file']['filefield-filename']           = t('File name');
+    $tokens['file']['filefield-filepath']           = t('File path');
+    $tokens['file']['filefield-fileurl']            = t('File URL');
+    $tokens['file']['filefield-filemime']           = t('File MIME type');
+    $tokens['file']['filefield-filesize']           = t('File size (in bytes)');
+    $tokens['file']['filefield-filesize_formatted'] = t('File size (pretty printed)');
+    $tokens['file']['filefield-view']               = t('Fully formatted HTML file tag');
+    $tokens['file']['filefield-onlyname']           = t('File name without extension');
+    $tokens['file']['filefield-extension']          = t('File extension');
     return $tokens;
   }
 }
@@ -29,12 +34,14 @@ function filefield_token_list($type = 'all') {
  * Provide the token values for a given file item.
  */
 function filefield_token_values($type, $object = NULL) {
-  if ($type == 'field') {
+  $tokens = array();
+  if ($type == 'field' && isset($object[0]['fid'])) {
     $item = $object[0];
     $tokens['filefield-fid']                = $item['fid'];
-    $tokens['filefield-description']        = isset($item['data']['description']) ? $item['data']['description'] : '';
-    $tokens['filefield-filename']           = $item['filename'];
-    $tokens['filefield-filepath']           = $item['filepath'];
+    $tokens['filefield-description']        = isset($item['data']['description']) ? check_plain($item['data']['description']) : '';
+    $tokens['filefield-filename']           = check_plain($item['filename']);
+    $tokens['filefield-filepath']           = check_plain($item['filepath']);
+    $tokens['filefield-fileurl']            = file_create_url($item['filepath']);
     $tokens['filefield-filemime']           = $item['filemime'];
     $tokens['filefield-filesize']           = $item['filesize'];
     $tokens['filefield-filesize_formatted'] = format_size($item['filesize']);
@@ -52,9 +59,9 @@ function filefield_token_values($type, $object = NULL) {
     }
     if (!isset($tokens['filefield-extension'])) {
       $info = pathinfo($item['filename']);
-      $tokens['filefield-onlyname'] = $info['filename'];
+      $tokens['filefield-onlyname'] = basename($info['basename'], '.'. $info['extension']);
       $tokens['filefield-extension'] = $info['extension'];
     }
-    return $tokens;  
   }
+  return $tokens;  
 }