Index: link.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/link/link.module,v
retrieving revision 1.24.2.29
diff -u -r1.24.2.29 link.module
--- link.module	22 Sep 2008 04:20:33 -0000	1.24.2.29
+++ link.module	10 Mar 2009 15:25:22 -0000
@@ -8,6 +8,7 @@
 
 define('LINK_EXTERNAL', 'external');
 define('LINK_INTERNAL', 'internal');
+define('LINK_UNC', 'unc');
 define('LINK_FRONT', 'front');
 define('LINK_EMAIL', 'email');
 define('LINK_DOMAINS', 'aero|arpa|biz|com|cat|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|mobi|local');
@@ -323,7 +324,7 @@
   }
   // Save the new URL without the anchor or query.
   $item['url'] = $url;
-
+  
   // Create a shortened URL for display.
   $display_url = $type == LINK_EMAIL ? str_replace('mailto:', '', $url) : url($url, array('query' => isset($item['query']) ? $item['query'] : NULL, 'fragment' => isset($item['fragment']) ? $item['fragment'] : NULL, 'absolute' => TRUE));
   if ($field['display']['url_cutoff'] && strlen($display_url) > $field['display']['url_cutoff']) {
@@ -366,7 +367,7 @@
     }
   }
   // Remove the rel=nofollow for internal links.
-  if ($type != LINK_EXTERNAL && isset($attributes['rel']) && strpos($attributes['rel'], 'nofollow') !== FALSE) {
+  if ($type != LINK_EXTERNAL && $type != LINK_UNC && isset($attributes['rel']) && strpos($attributes['rel'], 'nofollow') !== FALSE) {
     $attributes['rel'] = str_replace('nofollow', '', $attributes['rel']);
     if (empty($attributes['rel'])) {
       unset($attributes['rel']);
@@ -404,6 +405,9 @@
     'link_formatter_separate' => array(
       'arguments' => array('element' => NULL),
     ),
+    'link_formatter_UNC' => array(
+      'arguments' => array('element' => NULL),
+    ),
     'link' => array(
       'arguments' => array('element' => NULL),
     ),
@@ -526,6 +530,11 @@
       'field types' => array('link'),
       'multiple values' => CONTENT_HANDLE_CORE,
     ),
+    'UNC' => array(
+      'label' => t('Title as UNC/URL link'),
+      'field types' => array('link'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+    ),
   );
 }
 
@@ -586,6 +595,31 @@
   return $output;
 }
 
+/**
+ * Theme function for 'UNC' text field formatter.
+ * 
+ * For these links to work in Firefox, see these resources:
+ * http://kb.mozillazine.org/Links_to_local_pages_don%27t_work
+ * https://addons.mozilla.org/en-US/firefox/addon/1419
+ */
+function theme_link_formatter_UNC($element) {
+  $unc_pattern = "/^\\\\{2}/";
+  if (isset($element['#item']['url']) && preg_match($unc_pattern, $element['#item']['url'])) {
+    if (!empty($element['#item']['display_title']) && !empty($element['#item']['url'])) {
+      return '<a href="file:///'. $element['#item']['url'] .'">'. $element['#item']['display_title'] .'</a>';
+    }
+  }
+  else {
+    if (!empty($element['#item']['display_title']) && !empty($element['#item']['url'])) {
+      return l($element['#item']['display_title'], $element['#item']['url'], $element['#item']);
+    }
+    // If only a title, display the title.
+    elseif (!empty($element['#item']['display_title'])) {
+      return check_plain($element['#item']['display_title']);
+    }
+  }
+}
+
 function link_token_list($type = 'all') {
   if ($type == 'field' || $type == 'all') {
     $tokens = array();
@@ -630,19 +664,18 @@
 function link_cleanup_url($url, $protocol = "http") {
   $url = trim($url);
   $type = link_validate_url($url);
-
   if ($type == LINK_EXTERNAL) {
     // Check if there is no protocol specified.
     $protocol_match = preg_match("/^([a-z0-9][a-z0-9\.\-_]*:\/\/)/i",$url);
     if (empty($protocol_match)) {
       // But should there be? Add an automatic http:// if it starts with a domain name.
       $domain_match = preg_match('/^(([a-z0-9]([a-z0-9\-_]*\.)+)('. LINK_DOMAINS .'|[a-z]{2}))/i',$url);
+      
       if (!empty($domain_match)) {
         $url = $protocol."://".$url;
       }
     }
   }
-
   return $url;
 }
 
@@ -657,7 +690,7 @@
  */
 function link_validate_url($text) {
 
-  $allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal'));
+  $allowed_protocols = variable_get('filter_allowed_protocols', array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', 'mailto', 'irc', 'ssh', 'sftp', 'webcal', 'file'));
 
   $protocol = '((' . implode("|", $allowed_protocols) . '):\/\/)';
   $authentication = '([a-z0-9]+(:[a-z0-9]+)?@)';
@@ -671,7 +704,10 @@
 
   // Pattern specific to internal links.
   $internal_pattern = "/^([a-z0-9_\-+\[\]]+)";
-
+  
+  // Pattern specific to network UNC links.
+  $unc_pattern = "/^\\\\{2}[\w-_]+(\\\\{1}[\w-_][\w-_.\s]*[\w-_]+)*$/";
+  
   $directories = "(\/[a-z0-9_\-\.~+%=&,$'():;*@\[\]]*)*";
    // Yes, four backslashes == a single backslash.
   $query = "(\/?\?([?a-z0-9+_|\-\.\/\\\\%=&,$'():;*@\[\]]*))";
@@ -689,6 +725,9 @@
   if (in_array('mailto', $allowed_protocols) && preg_match($email_pattern, $text)) {
     return LINK_EMAIL;
   }
+  if (preg_match($unc_pattern, $text)) {
+    return LINK_UNC;
+  }
   if (preg_match($internal_pattern . $end, $text)) {
     return LINK_INTERNAL;
   }

