--- twitter.module	2010-07-16 21:28:33.000000000 -0700
+++ twitter_new.module	2010-07-16 21:51:38.000000000 -0700
@@ -96,7 +96,7 @@ function twitter_form_alter(&$form, $for
     );
     $form['twitter'] += $twitter_form;
     $form['twitter']['status']['#default_value'] = variable_get('twitter_default_format', 'New post: !title !tinyurl');
-    $form['twitter']['status']['#description'] = t('The given text will be posted to twitter.com. You can use !url, !url-alias, !tinyurl, !title and !user as replacement text.');
+    $form['twitter']['status']['#description'] = t('The given text will be posted to twitter.com. You can use !body, !url, !url-alias, !tinyurl, !title and !user as replacement text.');
   }
 }
 
@@ -115,7 +115,29 @@ function twitter_nodeapi(&$node, $op, $a
         $twitter_accounts = twitter_get_user_accounts($node->uid, TRUE);
         $pass = $twitter_accounts[$node->twitter['account']]['password'];
 
-        $replacements = array('!title' => $node->title,
+        /* 
+        beginning of added section
+        
+        get the length of the title
+        get the length of the body
+        how long is the URL going to be? -> assume 25 chars
+        */
+        
+        //step tags from body
+        $stripped_text = strip_tags($node->body);
+  
+        $len_title = strlen($node->title) + 2 ; //for the colon and space
+        $len_body  = strlen($stripped_text);
+        
+        $len_url   = 23; //estimate
+        $len_used = $len_title + $len_url;
+        $len_left = 140 - $len_used;
+        
+        //this truncates the body section
+        //$len_left - 8 -> is to make sure we don't overrun.
+        $stripped_text = _substr($stripped_text, ($len_left -8), 3);
+        
+        $replacements = array('!body' => $stripped_text, '!title' => $node->title . ': ',
                               '!url' => url('node/'. $node->nid, array('absolute' => TRUE, 'alias' => TRUE)),
                               '!url-alias' => url('node/'. $node->nid, array('absolute' => TRUE)),
                               '!user' => $node->name);
@@ -147,15 +169,29 @@ function twitter_shorten_url($url) {
     return shorten_url($url);
   }
   else {
-    $response = drupal_http_request("http://tinyurl.com/api-create.php?url=" . $url);
+    if (false) {
+      $response = drupal_http_request("http://tinyurl.com/api-create.php?url=" . $url);
+      if ($response->code == 200) {
+        return $response->data;
+      }
+      else {
+        return $url;
+      }
+    }
+    
+    //your info here:
+    //$login = YOUR_BITLY_LOGIN
+    //$api = YOUR_BITLY_API
+    $base = "http://api.bit.ly/v3/shorten?login=YOUR_BITLY_LOGIN&apiKey=YOUR_BITLY_API&format=txt&longUrl=";
+    $toSubmit = $base . $url;
+    $response = drupal_http_request($toSubmit);
     if ($response->code == 200) {
       return $response->data;
-    }
-    else {
+    } else {
       return $url;
     }
   }
-}
+}                                             
 
 /**
  * Implementation of hook_cron()
@@ -313,3 +349,26 @@ function twitter_twitter_accounts($drupa
 function twitter_views_api() {
   return array('api' => 2);
 }
+
+/**
+ * Word Break Substring Function
+ */
+function _substr($str, $length, $minword = 3)
+{
+    $sub = '';
+    $len = 0;
+    
+    foreach (explode(' ', $str) as $word)
+    {
+        $part = (($sub != '') ? ' ' : '') . $word;
+        $sub .= $part;
+        $len += strlen($part);
+        
+        if (strlen($word) > $minword && strlen($sub) >= $length)
+        {
+            break;
+        }
+    }
+    
+    return $sub . (($len < strlen($str)) ? '...' : '');
+}
