We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit ce088333 authored by millette's avatar millette

shorten urls for posts > 140 chars only, from anywhere. Only show long urls in...

shorten urls for posts > 140 chars only, from anywhere. Only show long urls in title attributes for links we shortened ourselves.

darcs-hash:20081128210114-099f7-4e4cde0a983c2ac6d41efb59b46cb7dbf45dc7a6.gz
parent 4fca9960
......@@ -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;
}
......
......@@ -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());
......
......@@ -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)) {
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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;
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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');
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment