$this->show_form(_('No content!'));
return;
} else if (mb_strlen($content) > 140) {
- common_debug("Content = '$content'", __FILE__);
- common_debug("mb_strlen(\$content) = " . mb_strlen($content), __FILE__);
- $this->show_form(_('That\'s too long. Max message size is 140 chars.'));
- return;
+
+ $content = common_shorten_links($content);
+
+ if (mb_strlen($content) > 140) {
+ common_debug("Content = '$content'", __FILE__);
+ common_debug("mb_strlen(\$content) = " . mb_strlen($content), __FILE__);
+ $this->show_form(_('That\'s too long. Max message size is 140 chars.'));
+ return;
+ }
}
$other = User::staticGet('id', $to);
$this->show_form(_('No content!'));
return;
} else if (mb_strlen($content) > 140) {
- common_debug("Content = '$content'", __FILE__);
- common_debug("mb_strlen(\$content) = " . mb_strlen($content), __FILE__);
- $this->show_form(_('That\'s too long. Max notice size is 140 chars.'));
- return;
+
+ $content = common_shorten_links($content);
+
+ if (mb_strlen($content) > 140) {
+ common_debug("Content = '$content'", __FILE__);
+ common_debug("mb_strlen(\$content) = " . mb_strlen($content), __FILE__);
+ $this->show_form(_('That\'s too long. Max notice size is 140 chars.'));
+ return;
+ }
}
$inter = new CommandInterpreter();
}
$content = $req->get_parameter('omb_notice_content');
if (!$content || strlen($content) > 140) {
- common_user_error(_('Invalid notice content'), 400);
- return false;
+ $content = common_shorten_links($content);
+ if (mb_strlen($content) > 140) {
+ common_user_error(_('Invalid notice content'), 400);
+ return false;
+ }
}
$notice_uri = $req->get_parameter('omb_notice');
if (!Validate::uri($notice_uri) &&
} else if ($this->nickname_exists($nickname)) {
$this->show_form(_('Nickname already in use. Try another one.'));
return;
- } else if (!is_null($language) && strlen($language) > 50) {
- $this->show_form(_('Language is too long (max 50 chars).'));
+ } else if (!is_null($language) && strlen($language) > 50) {
+ $this->show_form(_('Language is too long (max 50 chars).'));
}
$user = common_current_user();
if (!$content) {
$this->client_error(_('No message text!'), $code = 406, $apidata['content-type']);
} else if (mb_strlen($status) > 140) {
- $this->client_error(_('That\'s too long. Max message size is 140 chars.'),
- $code = 406, $apidata['content-type']);
- return;
+ $status = common_shorten_links($status);
+ if (mb_strlen($status) > 140) {
+ $this->client_error(_('That\'s too long. Max message size is 140 chars.'),
+ $code = 406, $apidata['content-type']);
+ return;
+ }
}
$other = $this->get_user($this->trimmed('user'));
return;
} else if (mb_strlen($status) > 140) {
+
+ $status = common_shorten_links($status);
- // XXX: Twitter truncates anything over 140, flags the status
- // as "truncated." Sending this error may screw up some clients
- // that assume Twitter will truncate for them. Should we just
- // truncate too? -- Zach
- $this->client_error(_('That\'s too long. Max notice size is 140 chars.'), $code = 406, $apidata['content-type']);
- return;
+ if (mb_strlen($status) > 140) {
+
+ // XXX: Twitter truncates anything over 140, flags the status
+ // as "truncated." Sending this error may screw up some clients
+ // that assume Twitter will truncate for them. Should we just
+ // truncate too? -- Zach
+ $this->client_error(_('That\'s too long. Max notice size is 140 chars.'), $code = 406, $apidata['content-type']);
+ return;
+
+ }
}
// Check for commands
$channel->error($this->user, _('No content!'));
return;
} else if ($len > 140) {
- $channel->error($this->user, sprintf(_('Message too long - maximum is 140 characters, you sent %d'), $len));
- return;
- } else if (!$other) {
+ $content = common_shorten_links($content);
+ if (mb_strlen($content) > 140) {
+ $channel->error($this->user, sprintf(_('Message too long - maximum is 140 characters, you sent %d'), $len));
+ return;
+ }
+ }
+
+ if (!$other) {
$channel->error($this->user, _('No such user.'));
return;
} else if (!$this->user->mutuallySubscribed($other)) {
public $smsemail; // varchar(255)
public $uri; // varchar(255) unique_key
public $autosubscribe; // tinyint(1)
+ public $urlshorteningservice; // varchar(50)
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
smsemail = 2
uri = 2
autosubscribe = 17
+urlshorteningservice = 2
created = 142
modified = 384
smsemail varchar(255) comment 'built from sms and carrier',
uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
autosubscribe tinyint default 0 comment 'automatically subscribe to users who subscribe to us',
+ urlshorteningservice varchar(50) default 'metamark.net' comment 'service to use for auto-shortening URLs',
created datetime not null comment 'date this record was created',
modified timestamp comment 'date this record was modified',
_('Updates by instant messenger (IM)')),
'twittersettings' =>
array(_('Twitter'),
- _('Twitter integration options')));
+ _('Twitter integration options')),
+ 'othersettings' =>
+ array(_('Other'),
+ _('Other options')));
$action = $this->trimmed('action');
common_element_start('ul', array('id' => 'nav_views'));
return '<a href="' . $uri . '" class="extlink">' . $uri . '</a>' . $trailer;
}
+function common_shorten_links($text) {
+ $r = htmlspecialchars($text);
+ $r = preg_replace('@https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $r);
+ return $r;
+}
+
+function common_shorten_link($long_url) {
+
+ $user = common_current_user();
+
+ $curlh = curl_init();
+ curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait
+ curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica');
+ curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true);
+
+ switch($user->urlshorteningservice) {
+ case 'is.gd':
+ curl_setopt($curlh, CURLOPT_URL, 'http://is.gd/api.php?longurl='.urlencode($long_url));
+ $short_url = curl_exec($curlh);
+ break;
+ case 'snipr.com':
+ curl_setopt($curlh, CURLOPT_URL, 'http://snipr.com/site/snip?r=simple&link='.urlencode($long_url));
+ $short_url = curl_exec($curlh);
+ break;
+ case 'metamark.net':
+ curl_setopt($curlh, CURLOPT_URL, 'http://metamark.net/api/rest/simple?long_url='.urlencode($long_url));
+ $short_url = curl_exec($curlh);
+ break;
+ case 'tinyurl.com':
+ curl_setopt($curlh, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($long_url));
+ $short_url = curl_exec($curlh);
+ break;
+ default:
+ $short_url = false;
+ }
+
+ curl_close($curlh);
+
+ if ($short_url) {
+ return $short_url;
+ }
+ return $long_url;
+}
+
function common_xml_safe_str($str) {
$xmlStr = htmlentities(iconv('UTF-8', 'UTF-8//IGNORE', $str), ENT_NOQUOTES, 'UTF-8');