public static function twitter_message_optimization($tweet, $url, $user, $hashtags, $method = '1')
 {
     global $essb_options;
     $max_message_length = 140;
     $twitter_message_optimize_dots = ESSBOptionValuesHelper::options_bool_value($essb_options, 'twitter_message_optimize_dots');
     $current_message_length = ESSBButtonHelper::twitter_message_length($tweet, $url, $user, $hashtags);
     $result = array();
     $result['tweet'] = $tweet;
     $result['hashtags'] = $hashtags;
     $result['user'] = $user;
     if ($current_message_length < $max_message_length) {
         return $result;
     } else {
         switch ($method) {
             case "1":
                 $result['hashtags'] = '';
                 $current_message_length = ESSBButtonHelper::twitter_message_length($result['tweet'], $url, $result['user'], $result['hashtags']);
                 if ($current_message_length > $max_message_length) {
                     $result['user'] = '';
                     $current_message_length = ESSBButtonHelper::twitter_message_length($result['tweet'], $url, $result['user'], $result['hashtags']);
                     if ($current_message_length > $max_message_length) {
                         $length = ESSBButtonHelper::twitter_maximum_message_length($result['tweet'], $url, $result['user'], $result['hashtags']);
                         if ($twitter_message_optimize_dots) {
                             $length -= 3;
                         }
                         $last_space = strrpos(substr($result['tweet'], 0, $length), '+');
                         $trimmed_text = substr($result['tweet'], 0, $last_space);
                         if ($twitter_message_optimize_dots) {
                             $trimmed_text .= '...';
                         }
                         $result['tweet'] = $trimmed_text;
                     }
                 }
                 break;
             case "2":
                 $result['user'] = '';
                 $current_message_length = ESSBButtonHelper::twitter_message_length($result['tweet'], $url, $result['user'], $result['hashtags']);
                 if ($current_message_length > $max_message_length) {
                     $result['hashtags'] = '';
                     $current_message_length = ESSBButtonHelper::twitter_message_length($result['tweet'], $url, $result['user'], $result['hashtags']);
                     if ($current_message_length > $max_message_length) {
                         $length = ESSBButtonHelper::twitter_maximum_message_length($result['tweet'], $url, $result['user'], $result['hashtags']);
                         if ($twitter_message_optimize_dots) {
                             $length -= 3;
                         }
                         $last_space = strrpos(substr($result['tweet'], 0, $length), '+');
                         $trimmed_text = substr($result['tweet'], 0, $last_space);
                         if ($twitter_message_optimize_dots) {
                             $trimmed_text .= '...';
                         }
                         $result['tweet'] = $trimmed_text;
                     }
                 }
                 break;
             case "3":
                 $result['user'] = '';
                 $current_message_length = ESSBButtonHelper::twitter_message_length($result['tweet'], $url, $result['user'], $result['hashtags']);
                 if ($current_message_length > $max_message_length) {
                     $length = ESSBButtonHelper::twitter_maximum_message_length($result['tweet'], $url, $result['user'], $result['hashtags']);
                     if ($twitter_message_optimize_dots) {
                         $length -= 3;
                     }
                     $last_space = strrpos(substr($result['tweet'], 0, $length), '+');
                     $trimmed_text = substr($result['tweet'], 0, $last_space);
                     if ($twitter_message_optimize_dots) {
                         $trimmed_text .= '...';
                     }
                     $result['tweet'] = $trimmed_text;
                 }
                 break;
             case "4":
                 $result['hashtags'] = '';
                 $current_message_length = ESSBButtonHelper::twitter_message_length($result['tweet'], $url, $result['user'], $result['hashtags']);
                 if ($current_message_length > $max_message_length) {
                     $length = ESSBButtonHelper::twitter_maximum_message_length($result['tweet'], $url, $result['user'], $result['hashtags']);
                     if ($twitter_message_optimize_dots) {
                         $length -= 3;
                     }
                     $last_space = strrpos(substr($result['tweet'], 0, $length), '+');
                     $trimmed_text = substr($result['tweet'], 0, $last_space);
                     if ($twitter_message_optimize_dots) {
                         $trimmed_text .= '...';
                     }
                     $result['tweet'] = $trimmed_text;
                 }
                 break;
             case "5":
                 $length = ESSBButtonHelper::twitter_maximum_message_length($result['tweet'], $url, $result['user'], $result['hashtags']);
                 if ($twitter_message_optimize_dots) {
                     $length -= 3;
                 }
                 $last_space = strrpos(substr($result['tweet'], 0, $length), '+');
                 $trimmed_text = substr($result['tweet'], 0, $last_space);
                 if ($twitter_message_optimize_dots) {
                     $trimmed_text .= '...';
                 }
                 $result['tweet'] = $trimmed_text;
                 break;
         }
         return $result;
     }
 }