summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/newmessage.php9
-rw-r--r--actions/newnotice.php10
-rw-r--r--actions/postnotice.php12
-rw-r--r--actions/twitapidirect_messages.php4
-rw-r--r--actions/twitapistatuses.php6
-rw-r--r--classes/Message.php2
-rw-r--r--classes/Notice.php2
-rw-r--r--lib/util.php6
-rwxr-xr-xscripts/maildaemon.php5
-rwxr-xr-xscripts/xmppdaemon.php10
10 files changed, 37 insertions, 29 deletions
diff --git a/actions/newmessage.php b/actions/newmessage.php
index d4e289465..67695210e 100644
--- a/actions/newmessage.php
+++ b/actions/newmessage.php
@@ -51,13 +51,12 @@ class NewmessageAction extends Action {
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;
}
diff --git a/actions/newnotice.php b/actions/newnotice.php
index a79d0a1a2..932099c60 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -51,11 +51,11 @@ class NewnoticeAction extends Action {
$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;
}
@@ -63,7 +63,7 @@ class NewnoticeAction extends Action {
$inter = new CommandInterpreter();
- $cmd = $inter->handle_command($user, $content);
+ $cmd = $inter->handle_command($user, $content_shortened);
if ($cmd) {
$cmd->execute(new WebChannel());
diff --git a/actions/postnotice.php b/actions/postnotice.php
index 243aa3163..243081f12 100644
--- a/actions/postnotice.php
+++ b/actions/postnotice.php
@@ -58,13 +58,11 @@ class PostnoticeAction extends Action {
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)) {
diff --git a/actions/twitapidirect_messages.php b/actions/twitapidirect_messages.php
index a04ae5fa7..a14a9e567 100644
--- a/actions/twitapidirect_messages.php
+++ b/actions/twitapidirect_messages.php
@@ -115,8 +115,8 @@ class Twitapidirect_messagesAction extends TwitterapiAction {
$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;
diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php
index 6d6d5266f..947d21032 100644
--- a/actions/twitapistatuses.php
+++ b/actions/twitapistatuses.php
@@ -255,9 +255,9 @@ class TwitapistatusesAction extends TwitterapiAction {
// } 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
@@ -271,7 +271,7 @@ class TwitapistatusesAction extends TwitterapiAction {
// Check for commands
$inter = new CommandInterpreter();
- $cmd = $inter->handle_command($user, $status);
+ $cmd = $inter->handle_command($user, $status_shortened);
if ($cmd) {
diff --git a/classes/Message.php b/classes/Message.php
index 8674f7f80..ef4bd0316 100644
--- a/classes/Message.php
+++ b/classes/Message.php
@@ -41,7 +41,7 @@ class Message extends Memcached_DataObject
$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;
diff --git a/classes/Notice.php b/classes/Notice.php
index ceec7a2fa..83862ae95 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -127,7 +127,7 @@ class Notice extends Memcached_DataObject
$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;
diff --git a/lib/util.php b/lib/util.php
index b14d121e6..c3d11b074 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -837,10 +837,10 @@ function common_longurl2($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) {
diff --git a/scripts/maildaemon.php b/scripts/maildaemon.php
index 64f913bf9..8b809f646 100755
--- a/scripts/maildaemon.php
+++ b/scripts/maildaemon.php
@@ -120,6 +120,9 @@ class MailerDaemon {
}
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);
@@ -209,4 +212,4 @@ class MailerDaemon {
}
$md = new MailerDaemon();
-$md->handle_message('php://stdin'); \ No newline at end of file
+$md->handle_message('php://stdin');
diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php
index 90506a0f4..e55b9e3e9 100755
--- a/scripts/xmppdaemon.php
+++ b/scripts/xmppdaemon.php
@@ -236,7 +236,15 @@ class XMPPDaemon extends Daemon {
}
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;