if (!$content) {
$this->show_form(_('No content!'));
return;
-// } else if (mb_strlen($content) > 140) {
} else {
- $content = common_shorten_links($content);
+ $content_shortened = common_shorten_links($content);
- if (mb_strlen($content) > 140) {
- common_debug("Content = '$content'", __FILE__);
- common_debug("mb_strlen(\$content) = " . mb_strlen($content), __FILE__);
+ if (mb_strlen($content_shortened) > 140) {
+ common_debug("Content = '$content_shortened'", __FILE__);
+ common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__);
$this->show_form(_('That\'s too long. Max message size is 140 chars.'));
return;
}
$this->show_form(_('No content!'));
return;
} else {
- $content = common_shorten_links($content);
+ $content_shortened = common_shorten_links($content);
- if (mb_strlen($content) > 140) {
- common_debug("Content = '$content'", __FILE__);
- common_debug("mb_strlen(\$content) = " . mb_strlen($content), __FILE__);
+ if (mb_strlen($content_shortened) > 140) {
+ common_debug("Content = '$content_shortened'", __FILE__);
+ common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__);
$this->show_form(_('That\'s too long. Max notice size is 140 chars.'));
return;
}
$inter = new CommandInterpreter();
- $cmd = $inter->handle_command($user, $content);
+ $cmd = $inter->handle_command($user, $content_shortened);
if ($cmd) {
$cmd->execute(new WebChannel());
return false;
}
$content = $req->get_parameter('omb_notice_content');
-// if (!$content || strlen($content) > 140) {
- $content = common_shorten_links($content);
- if (mb_strlen($content) > 140) {
- common_user_error(_('Invalid notice content'), 400);
- return false;
- }
-// }
+ $content_shortened = common_shorten_links($content);
+ if (mb_strlen($content_shortened) > 140) {
+ common_user_error(_('Invalid notice content'), 400);
+ return false;
+ }
$notice_uri = $req->get_parameter('omb_notice');
if (!Validate::uri($notice_uri) &&
!common_valid_tag($notice_uri)) {
$this->client_error(_('No message text!'), $code = 406, $apidata['content-type']);
// } else if (mb_strlen($status) > 140) {
} else {
- $status = common_shorten_links($status);
- if (mb_strlen($status) > 140) {
+ $content_shortened = common_shorten_links($content);
+ if (mb_strlen($content_shortened) > 140) {
$this->client_error(_('That\'s too long. Max message size is 140 chars.'),
$code = 406, $apidata['content-type']);
return;
// } else if (mb_strlen($status) > 140) {
} else {
- $status = common_shorten_links($status);
+ $status_shortened = common_shorten_links($status);
- if (mb_strlen($status) > 140) {
+ if (mb_strlen($status_shortened) > 140) {
// XXX: Twitter truncates anything over 140, flags the status
// as "truncated." Sending this error may screw up some clients
// Check for commands
$inter = new CommandInterpreter();
- $cmd = $inter->handle_command($user, $status);
+ $cmd = $inter->handle_command($user, $status_shortened);
if ($cmd) {
$msg->from_profile = $from;
$msg->to_profile = $to;
- $msg->content = $content;
+ $msg->content = common_shorten_links($content);
$msg->rendered = common_render_text($content);
$msg->created = common_sql_now();
$msg->source = $source;
$notice->reply_to = $reply_to;
$notice->created = common_sql_now();
- $notice->content = $content;
+ $notice->content = common_shorten_links($content);
$notice->rendered = common_render_content($notice->content, $notice);
$notice->source = $source;
$notice->uri = $uri;
function common_shorten_links($text) {
if (mb_strlen($text) <= 140) return $text;
+ static $cache = array();
+ if (isset($cache[$text])) return $cache[$text];
// \s = not a horizontal whitespace character (since PHP 5.2.4)
- // RYM this should prevent * preceded URLs from being processed but it its a char
-// $r = preg_replace('@[^*](https?://[^)\]>\s]+)@e', "common_shorten_link('\\1')", $r);
- return preg_replace('@https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $text);
+ return $cache[$text] = preg_replace('@https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $text);
}
function common_shorten_link($long_url) {
}
function add_notice($user, $msg) {
+ // should test
+ // $msg_shortened = common_shorten_links($msg);
+ // if (mb_strlen($msg_shortened) > 140) ERROR and STOP
$notice = Notice::saveNew($user->id, $msg, 'mail');
if (is_string($notice)) {
$this->log(LOG_ERR, $notice);
}
$md = new MailerDaemon();
-$md->handle_message('php://stdin');
\ No newline at end of file
+$md->handle_message('php://stdin');
}
function add_notice(&$user, &$pl) {
- $notice = Notice::saveNew($user->id, trim(mb_substr($pl['body'], 0, 140)), 'xmpp');
+ $content_shortened = common_shorten_link($pl['body']);
+ if (mb_strlen($content_shortened) > 140) {
+ $content = trim(mb_substr($pl['body'], 0, 140));
+ $content_shortened = common_shorten_link($content);
+ }
+ else {
+ $content = $pl['body'];
+ }
+ $notice = Notice::saveNew($user->id, $content, 'xmpp');
if (is_string($notice)) {
$this->log(LOG_ERR, $notice);
return;