Permalink
Browse files

Truncate default tweet values longer than 140.

  • Loading branch information...
1 parent a7aea12 commit 34923c773f8e306a4ca438b07cb6ad82b04a3c3e @ckieffer ckieffer committed Feb 17, 2011
Showing with 12 additions and 2 deletions.
  1. +12 −2 3.1/modules/twitter/helpers/twitter.php
@@ -60,6 +60,7 @@ static function get_configure_form() {
* Get tweet form
* @param object $item
* @return Forge
+ * @todo Truncate the $tweet at 140 - strlen($url)
*/
static function get_tweet_form($item) {
$long_url = url::abs_site($item->relative_url_cache);
@@ -81,7 +82,16 @@ static function get_tweet_form($item) {
} else {
$url = url::abs_site($item->relative_url_cache);
}
- $tweet = preg_replace("/%url/", $url, $tweet);
+
+ // Truncate the default tweet if it's too long
+ $url_length = strlen($url) + 1;
+ $tweet_length = strlen($tweet);
+
+ if (($tweet_length + $url_length) > self::$character_count) {
+ $trim_pos = 0 - (($tweet_length + $url_length) - 140);
+ $tweet = substr($tweet, 0, $trim_pos);
+ }
+ $tweet = $tweet . ' ' . $url;
$form = new Forge("twitter/tweet/$item->id", "", "post", array("id" => "g-twitter-tweet-form"));
$group = $form->group("twitter_message")->label(t("Compose Tweet"));
@@ -134,7 +144,7 @@ static function is_registered() {
}
static function reset_default_tweet() {
- return t("Check out this %type, '%title': %description %url");
+ return t("Check out this %type, '%title': %description");
}
}

0 comments on commit 34923c7

Please sign in to comment.