diff options
-rw-r--r-- | EVENTS.txt | 4 | ||||
-rw-r--r-- | README | 26 | ||||
-rw-r--r-- | actions/editgroup.php | 4 | ||||
-rw-r--r-- | actions/newgroup.php | 4 | ||||
-rw-r--r-- | actions/newmessage.php | 7 | ||||
-rw-r--r-- | actions/newnotice.php | 12 | ||||
-rw-r--r-- | actions/postnotice.php | 5 | ||||
-rw-r--r-- | actions/profilesettings.php | 14 | ||||
-rw-r--r-- | actions/register.php | 15 | ||||
-rw-r--r-- | actions/twitapidirect_messages.php | 7 | ||||
-rw-r--r-- | actions/twitapistatuses.php | 7 | ||||
-rw-r--r-- | classes/Message.php | 51 | ||||
-rw-r--r-- | classes/Notice.php | 24 | ||||
-rw-r--r-- | classes/Profile.php | 21 | ||||
-rw-r--r-- | classes/User_group.php | 18 | ||||
-rwxr-xr-x | classes/laconica.ini | 8 | ||||
-rw-r--r-- | db/08to09.sql | 14 | ||||
-rw-r--r-- | db/laconica.sql | 8 | ||||
-rw-r--r-- | js/util.js | 28 | ||||
-rw-r--r-- | lib/command.php | 16 | ||||
-rw-r--r-- | lib/common.php | 14 | ||||
-rw-r--r-- | lib/facebookaction.php | 11 | ||||
-rw-r--r-- | lib/groupeditform.php | 24 | ||||
-rw-r--r-- | lib/messageform.php | 17 | ||||
-rw-r--r-- | lib/noticeform.php | 23 | ||||
-rw-r--r-- | lib/settingsaction.php | 10 | ||||
-rw-r--r-- | lib/util.php | 6 | ||||
-rwxr-xr-x | scripts/maildaemon.php | 22 | ||||
-rwxr-xr-x | scripts/xmppdaemon.php | 6 |
29 files changed, 298 insertions, 128 deletions
diff --git a/EVENTS.txt b/EVENTS.txt index ef4c2cffa..25d95fe06 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -223,3 +223,7 @@ EndRegistrationTry: after saving a new user (note: no profile or user object!) StartNewQueueManager: before trying to start a new queue manager; good for plugins implementing new queue manager classes - $qm: empty queue manager to set + +RedirectToLogin: event when we force a redirect to login (like when going to a settings page on a remembered login) +- $action: action object being shown +- $user: current user @@ -967,6 +967,9 @@ shorturllength: Length of URL at which URLs in a message exceeding 140 dupelimit: minimum time allowed for one person to say the same thing twice. Default 60s. Anything lower is considered a user or UI error. +textlimit: default max size for texts in the site. Defaults to 140. + 0 means no limit. Can be fine-tuned for notices, messages, + profile bios and group descriptions. db -- @@ -1269,6 +1272,8 @@ banned: an array of usernames and/or profile IDs of 'banned' profiles. The site will reject any notices by these users -- they will not be accepted at all. (Compare with blacklisted users above, whose posts just won't show up in the public stream.) +biolimit: max character length of bio; 0 means no limit; null means to use + the site text limit default. newuser ------- @@ -1365,6 +1370,9 @@ Options for group functionality. maxaliases: maximum number of aliases a group can have. Default 3. Set to 0 or less to prevent aliases in a group. +desclimit: maximum number of characters to allow in group descriptions. + null (default) means to use the site-wide text limits. 0 + means no limit. oohembed -------- @@ -1443,6 +1451,24 @@ linkcolor: Hex color of all links. backgroundimage: Image to use for the background. disposition: Flags for whether or not to tile the background image. +notice +------ + +Configuration options specific to notices. + +contentlimit: max length of the plain-text content of a notice. + Default is null, meaning to use the site-wide text limit. + 0 means no limit. + +message +------- + +Configuration options specific to messages. + +contentlimit: max length of the plain-text content of a message. + Default is null, meaning to use the site-wide text limit. + 0 means no limit. + Plugins ======= diff --git a/actions/editgroup.php b/actions/editgroup.php index 6aa6f8b11..aeeea2b63 100644 --- a/actions/editgroup.php +++ b/actions/editgroup.php @@ -196,8 +196,8 @@ class EditgroupAction extends GroupDesignAction } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { $this->showForm(_('Full name is too long (max 255 chars).')); return; - } else if (!is_null($description) && mb_strlen($description) > 140) { - $this->showForm(_('description is too long (max 140 chars).')); + } else if (User_group::descriptionTooLong($description)) { + $this->showForm(sprintf(_('description is too long (max %d chars).'), User_group::maxDescription())); return; } else if (!is_null($location) && mb_strlen($location) > 255) { $this->showForm(_('Location is too long (max 255 chars).')); diff --git a/actions/newgroup.php b/actions/newgroup.php index 0289e77c2..71647d834 100644 --- a/actions/newgroup.php +++ b/actions/newgroup.php @@ -146,8 +146,8 @@ class NewgroupAction extends Action } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { $this->showForm(_('Full name is too long (max 255 chars).')); return; - } else if (!is_null($description) && mb_strlen($description) > 140) { - $this->showForm(_('description is too long (max 140 chars).')); + } else if (User_group::descriptionTooLong($description)) { + $this->showForm(sprintf(_('description is too long (max %d chars).'), User_group::maxDescription())); return; } else if (!is_null($location) && mb_strlen($location) > 255) { $this->showForm(_('Location is too long (max 255 chars).')); diff --git a/actions/newmessage.php b/actions/newmessage.php index 52d4899ba..cd26e1640 100644 --- a/actions/newmessage.php +++ b/actions/newmessage.php @@ -144,9 +144,10 @@ class NewmessageAction extends Action } else { $content_shortened = common_shorten_links($this->content); - if (mb_strlen($content_shortened) > 140) { - $this->showForm(_('That\'s too long. ' . - 'Max message size is 140 chars.')); + if (Message::contentTooLong($content_shortened)) { + $this->showForm(sprintf(_('That\'s too long. ' . + 'Max message size is %d chars.'), + Message::maxContent())); return; } } diff --git a/actions/newnotice.php b/actions/newnotice.php index e254eac49..f773fc880 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -162,9 +162,10 @@ class NewnoticeAction extends Action $this->clientError(_('No content!')); } else { $content_shortened = common_shorten_links($content); - if (mb_strlen($content_shortened) > 140) { - $this->clientError(_('That\'s too long. '. - 'Max notice size is 140 chars.')); + if (Notice::contentTooLong($content_shortened)) { + $this->clientError(sprintf(_('That\'s too long. '. + 'Max notice size is %d chars.'), + Notice::maxContent())); } } @@ -241,9 +242,10 @@ class NewnoticeAction extends Action $short_fileurl = common_shorten_url($fileurl); $content_shortened .= ' ' . $short_fileurl; - if (mb_strlen($content_shortened) > 140) { + if (Notice::contentTooLong($content_shortened)) { $this->deleteFile($filename); - $this->clientError(_('Max notice size is 140 chars, including attachment URL.')); + $this->clientError(sprintf(_('Max notice size is %d chars, including attachment URL.'), + Notice::maxContent())); } // Also, not sure this is necessary -- Zach diff --git a/actions/postnotice.php b/actions/postnotice.php index 97e887c46..14152a83d 100644 --- a/actions/postnotice.php +++ b/actions/postnotice.php @@ -82,8 +82,9 @@ class PostnoticeAction extends Action function checkNotice() { $content = common_shorten_links($_POST['omb_notice_content']); - if (mb_strlen($content) > 140) { - throw new Exception(_('The notice content is too long.')); + if (Notice::contentTooLong($content)) { + $this->clientError(_('Invalid notice content'), 400); + return false; } $license = $_POST['omb_notice_license']; $site_license = common_config('license', 'url'); diff --git a/actions/profilesettings.php b/actions/profilesettings.php index fb847680b..961e15ae7 100644 --- a/actions/profilesettings.php +++ b/actions/profilesettings.php @@ -109,9 +109,16 @@ class ProfilesettingsAction extends AccountSettingsAction _('URL of your homepage, blog, or profile on another site')); $this->elementEnd('li'); $this->elementStart('li'); + $maxBio = Profile::maxBio(); + if ($maxBio > 0) { + $bioInstr = sprintf(_('Describe yourself and your interests in %d chars'), + $maxBio); + } else { + $bioInstr = _('Describe yourself and your interests'); + } $this->textarea('bio', _('Bio'), ($this->arg('bio')) ? $this->arg('bio') : $profile->bio, - _('Describe yourself and your interests in 140 chars')); + $bioInstr); $this->elementEnd('li'); $this->elementStart('li'); $this->input('location', _('Location'), @@ -202,8 +209,9 @@ class ProfilesettingsAction extends AccountSettingsAction } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { $this->showForm(_('Full name is too long (max 255 chars).')); return; - } else if (!is_null($bio) && mb_strlen($bio) > 140) { - $this->showForm(_('Bio is too long (max 140 chars).')); + } else if (Profile::bioTooLong($bio)) { + $this->showForm(sprintf(_('Bio is too long (max %d chars).'), + Profile::maxBio())); return; } else if (!is_null($location) && mb_strlen($location) > 255) { $this->showForm(_('Location is too long (max 255 chars).')); diff --git a/actions/register.php b/actions/register.php index dcbbbdb6a..ab04f18d5 100644 --- a/actions/register.php +++ b/actions/register.php @@ -207,8 +207,9 @@ class RegisterAction extends Action } else if (!is_null($fullname) && mb_strlen($fullname) > 255) { $this->showForm(_('Full name is too long (max 255 chars).')); return; - } else if (!is_null($bio) && mb_strlen($bio) > 140) { - $this->showForm(_('Bio is too long (max 140 chars).')); + } else if (Profile::bioTooLong($bio)) { + $this->showForm(sprintf(_('Bio is too long (max %d chars).'), + Profile::maxBio())); return; } else if (!is_null($location) && mb_strlen($location) > 255) { $this->showForm(_('Location is too long (max 255 chars).')); @@ -445,10 +446,16 @@ class RegisterAction extends Action 'or profile on another site')); $this->elementEnd('li'); $this->elementStart('li'); + $maxBio = Profile::maxBio(); + if ($maxBio > 0) { + $bioInstr = sprintf(_('Describe yourself and your interests in %d chars'), + $maxBio); + } else { + $bioInstr = _('Describe yourself and your interests'); + } $this->textarea('bio', _('Bio'), $this->trimmed('bio'), - _('Describe yourself and your '. - 'interests in 140 chars')); + $bioInstr); $this->elementEnd('li'); $this->elementStart('li'); $this->input('location', _('Location'), diff --git a/actions/twitapidirect_messages.php b/actions/twitapidirect_messages.php index bd27e9d20..aac7d63b1 100644 --- a/actions/twitapidirect_messages.php +++ b/actions/twitapidirect_messages.php @@ -141,9 +141,10 @@ class Twitapidirect_messagesAction extends TwitterapiAction $code = 406, $apidata['content-type']); } else { $content_shortened = common_shorten_links($content); - if (mb_strlen($content_shortened) > 140) { - $this->clientError(_('That\'s too long. Max message size is 140 chars.'), - $code = 406, $apidata['content-type']); + if (Message::contentTooLong($content_shortened)) { + $this->clientError(sprintf(_('That\'s too long. Max message size is %d chars.'), + Message::maxContent()), + $code = 406, $apidata['content-type']); return; } } diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index e3d366ecc..038282414 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -242,14 +242,15 @@ class TwitapistatusesAction extends TwitterapiAction $status_shortened = common_shorten_links($status); - if (mb_strlen($status_shortened) > 140) { + if (Notice::contentTooLong($status_shortened)) { // 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->clientError(_('That\'s too long. Max notice size is 140 chars.'), - $code = 406, $apidata['content-type']); + $this->clientError(sprintf(_('That\'s too long. Max notice size is %d chars.'), + Notice::maxContent()), + $code = 406, $apidata['content-type']); return; } } diff --git a/classes/Message.php b/classes/Message.php index 4806057b4..979e6e87c 100644 --- a/classes/Message.php +++ b/classes/Message.php @@ -4,7 +4,7 @@ */ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; -class Message extends Memcached_DataObject +class Message extends Memcached_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ @@ -14,58 +14,73 @@ class Message extends Memcached_DataObject public $uri; // varchar(255) unique_key public $from_profile; // int(4) not_null public $to_profile; // int(4) not_null - public $content; // varchar(140) - public $rendered; // text() - public $url; // varchar(255) + public $content; // text() + public $rendered; // text() + public $url; // varchar(255) public $created; // datetime() not_null public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP - public $source; // varchar(32) + public $source; // varchar(32) /* Static get */ - function staticGet($k,$v=null) - { return Memcached_DataObject::staticGet('Message',$k,$v); } + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Message',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - + function getFrom() { return Profile::staticGet('id', $this->from_profile); } - + function getTo() { return Profile::staticGet('id', $this->to_profile); } - + static function saveNew($from, $to, $content, $source) { - + $msg = new Message(); - + $msg->from_profile = $from; $msg->to_profile = $to; $msg->content = common_shorten_links($content); $msg->rendered = common_render_text($content); $msg->created = common_sql_now(); $msg->source = $source; - + $result = $msg->insert(); - + if (!$result) { common_log_db_error($msg, 'INSERT', __FILE__); return _('Could not insert message.'); } - + $orig = clone($msg); $msg->uri = common_local_url('showmessage', array('message' => $msg->id)); - + $result = $msg->update($orig); - + if (!$result) { common_log_db_error($msg, 'UPDATE', __FILE__); return _('Could not update message with new URI.'); } - + return $msg; } + + static function maxContent() + { + $desclimit = common_config('message', 'contentlimit'); + // null => use global limit (distinct from 0!) + if (is_null($desclimit)) { + $desclimit = common_config('site', 'textlimit'); + } + return $desclimit; + } + + static function contentTooLong($content) + { + $contentlimit = self::maxContent(); + return ($contentlimit > 0 && !empty($content) && (mb_strlen($content) > $contentlimit)); + } } diff --git a/classes/Notice.php b/classes/Notice.php index 9578d87b2..2133247b8 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -44,7 +44,7 @@ class Notice extends Memcached_DataObject public $id; // int(4) primary_key not_null public $profile_id; // int(4) not_null public $uri; // varchar(255) unique_key - public $content; // varchar(140) + public $content; // text() public $rendered; // text() public $url; // varchar(255) public $created; // datetime() not_null @@ -55,9 +55,7 @@ class Notice extends Memcached_DataObject public $conversation; // int(4) /* Static get */ - function staticGet($k,$v=NULL) { - return Memcached_DataObject::staticGet('Notice',$k,$v); - } + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Notice',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE @@ -154,7 +152,7 @@ class Notice extends Memcached_DataObject $final = common_shorten_links($content); - if (mb_strlen($final) > 140) { + if (Notice::contentTooLong($final)) { common_log(LOG_INFO, 'Rejecting notice that is too long.'); return _('Problem saving notice. Too long.'); } @@ -1354,4 +1352,20 @@ class Notice extends Memcached_DataObject return $last->id; } } + + static function maxContent() + { + $contentlimit = common_config('notice', 'contentlimit'); + // null => use global limit (distinct from 0!) + if (is_null($contentlimit)) { + $contentlimit = common_config('site', 'textlimit'); + } + return $contentlimit; + } + + static function contentTooLong($content) + { + $contentlimit = self::maxContent(); + return ($contentlimit > 0 && !empty($content) && (mb_strlen($content) > $contentlimit)); + } } diff --git a/classes/Profile.php b/classes/Profile.php index f926b2cef..8f92b386e 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -35,14 +35,13 @@ class Profile extends Memcached_DataObject public $fullname; // varchar(255) multiple_key public $profileurl; // varchar(255) public $homepage; // varchar(255) multiple_key - public $bio; // varchar(140) multiple_key + public $bio; // text() multiple_key public $location; // varchar(255) multiple_key public $created; // datetime() not_null public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=null) - { return Memcached_DataObject::staticGet('Profile',$k,$v); } + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Profile',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE @@ -461,4 +460,20 @@ class Profile extends Memcached_DataObject $c->delete(common_cache_key('profile:notice_count:'.$this->id)); } } + + static function maxBio() + { + $biolimit = common_config('profile', 'biolimit'); + // null => use global limit (distinct from 0!) + if (is_null($biolimit)) { + $biolimit = common_config('site', 'textlimit'); + } + return $biolimit; + } + + static function bioTooLong($bio) + { + $biolimit = self::maxBio(); + return ($biolimit > 0 && !empty($bio) && (mb_strlen($bio) > $biolimit)); + } } diff --git a/classes/User_group.php b/classes/User_group.php index b1ab1c2d3..e6e79ca6a 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -13,7 +13,7 @@ class User_group extends Memcached_DataObject public $nickname; // varchar(64) unique_key public $fullname; // varchar(255) public $homepage; // varchar(255) - public $description; // varchar(140) + public $description; // text() public $location; // varchar(255) public $original_logo; // varchar(255) public $homepage_logo; // varchar(255) @@ -297,4 +297,20 @@ class User_group extends Memcached_DataObject return $ids; } + + static function maxDescription() + { + $desclimit = common_config('group', 'desclimit'); + // null => use global limit (distinct from 0!) + if (is_null($desclimit)) { + $desclimit = common_config('site', 'textlimit'); + } + return $desclimit; + } + + static function descriptionTooLong($desc) + { + $desclimit = self::maxDescription(); + return ($desclimit > 0 && !empty($desc) && (mb_strlen($desc) > $desclimit)); + } } diff --git a/classes/laconica.ini b/classes/laconica.ini index f8d4eebd3..c02996b3f 100755 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -239,7 +239,7 @@ id = 129 uri = 2 from_profile = 129 to_profile = 129 -content = 2 +content = 34 rendered = 34 url = 2 created = 142 @@ -266,7 +266,7 @@ ts = K id = 129 profile_id = 129 uri = 2 -content = 2 +content = 34 rendered = 34 url = 2 created = 142 @@ -314,7 +314,7 @@ nickname = 130 fullname = 2 profileurl = 2 homepage = 2 -bio = 2 +bio = 34 location = 2 created = 142 modified = 384 @@ -486,7 +486,7 @@ id = 129 nickname = 2 fullname = 2 homepage = 2 -description = 2 +description = 34 location = 2 original_logo = 2 homepage_logo = 2 diff --git a/db/08to09.sql b/db/08to09.sql index 892df4a39..4d1830611 100644 --- a/db/08to09.sql +++ b/db/08to09.sql @@ -1,2 +1,12 @@ -// SQL commands to update an 0.8.x version of Laconica -// to 0.9.x. +alter table notice + modify column content text comment 'update content'; + +alter table message + modify column content text comment 'message content'; + +alter table profile + modify column bio text comment 'descriptive biography'; + +alter table user_group + modify column description text comment 'group description'; + diff --git a/db/laconica.sql b/db/laconica.sql index f01107176..56bd4b1e3 100644 --- a/db/laconica.sql +++ b/db/laconica.sql @@ -6,7 +6,7 @@ create table profile ( fullname varchar(255) comment 'display name', profileurl varchar(255) comment 'URL, cached so we dont regenerate', homepage varchar(255) comment 'identifying URL', - bio varchar(140) comment 'descriptive biography', + bio text comment 'descriptive biography', location varchar(255) comment 'physical location', created datetime not null comment 'date this record was created', modified timestamp comment 'date this record was modified', @@ -110,7 +110,7 @@ create table notice ( id integer auto_increment primary key comment 'unique identifier', profile_id integer not null comment 'who made the update' references profile (id), uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI', - content varchar(140) comment 'update content', + content text comment 'update content', rendered text comment 'HTML version of the content', url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)', created datetime not null comment 'date this record was created', @@ -331,7 +331,7 @@ create table message ( uri varchar(255) unique key comment 'universally unique identifier', from_profile integer not null comment 'who the message is from' references profile (id), to_profile integer not null comment 'who the message is to' references profile (id), - content varchar(140) comment 'message content', + content text comment 'message content', rendered text comment 'HTML version of the content', url varchar(255) comment 'URL of any attachment (image, video, bookmark, whatever)', created datetime not null comment 'date this record was created', @@ -380,7 +380,7 @@ create table user_group ( nickname varchar(64) unique key comment 'nickname for addressing', fullname varchar(255) comment 'display name', homepage varchar(255) comment 'URL, cached so we dont regenerate', - description varchar(140) comment 'descriptive biography', + description text comment 'group description', location varchar(255) comment 'related physical location, if any', original_logo varchar(255) comment 'original size logo', diff --git a/js/util.js b/js/util.js index f3ed918cf..3a0a8d9a7 100644 --- a/js/util.js +++ b/js/util.js @@ -19,7 +19,9 @@ $(document).ready(function(){ // count character on keyup function counter(event){ - var maxLength = 140; + if (maxLength <= 0) { + return; + } var currentLength = $("#notice_data-text").val().length; var remaining = maxLength - currentLength; var counter = $("#notice_text-count"); @@ -42,12 +44,20 @@ $(document).ready(function(){ return true; } + // define maxLength if it wasn't defined already + + if (typeof(maxLength) == "undefined") { + maxLength = 140; + } + if ($("#notice_data-text").length) { - $("#notice_data-text").bind("keyup", counter); - $("#notice_data-text").bind("keydown", submitonreturn); + if (maxLength > 0) { + $("#notice_data-text").bind("keyup", counter); + // run once in case there's something in there + counter(); + } - // run once in case there's something in there - counter(); + $("#notice_data-text").bind("keydown", submitonreturn); if($('body')[0].id != 'conversation') { $("#notice_data-text").focus(); @@ -185,7 +195,9 @@ $(document).ready(function(){ } else { $("#notice_data-text").val(""); - counter(); + if (maxLength > 0) { + counter(); + } } } } @@ -225,7 +237,9 @@ $(document).ready(function(){ $("#notice_data-attach").val(""); $("#notice_in-reply-to").val(""); $('#notice_data-attach_selected').remove(); - counter(); + if (maxLength > 0) { + counter(); + } } $("#form_notice").removeClass("processing"); $("#notice_action-submit").removeAttr("disabled"); diff --git a/lib/command.php b/lib/command.php index 4e2280bc8..371386dc5 100644 --- a/lib/command.php +++ b/lib/command.php @@ -211,16 +211,20 @@ class MessageCommand extends Command function execute($channel) { $other = User::staticGet('nickname', common_canonical_nickname($this->other)); + $len = mb_strlen($this->text); + if ($len == 0) { $channel->error($this->user, _('No content!')); return; - } else if ($len > 140) { - $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; - } + } + + $this->text = common_shorten_links($this->text); + + if (Message::contentTooLong($this->text)) { + $channel->error($this->user, sprintf(_('Message too long - maximum is %d characters, you sent %d'), + Message::maxContent(), mb_strlen($this->text))); + return; } if (!$other) { diff --git a/lib/common.php b/lib/common.php index 5cecf309a..a9eef13ff 100644 --- a/lib/common.php +++ b/lib/common.php @@ -113,7 +113,9 @@ $config = 'ssl' => 'never', 'sslserver' => null, 'shorturllength' => 30, - 'dupelimit' => 60), # default for same person saying the same thing + 'dupelimit' => 60, # default for same person saying the same thing + 'textlimit' => 140, + ), 'syslog' => array('appname' => 'laconica', # for syslog 'priority' => 'debug', # XXX: currently ignored @@ -137,7 +139,8 @@ $config = array('blacklist' => array(), 'featured' => array()), 'profile' => - array('banned' => array()), + array('banned' => array(), + 'biolimit' => null), 'avatar' => array('server' => null, 'dir' => INSTALLDIR . '/avatar/', @@ -246,7 +249,8 @@ $config = 'filecommand' => '/usr/bin/file', ), 'group' => - array('maxaliases' => 3), + array('maxaliases' => 3, + 'desclimit' => null), 'oohembed' => array('endpoint' => 'http://oohembed.com/oohembed/'), 'search' => array('type' => 'fulltext'), @@ -261,6 +265,10 @@ $config = 'linkcolor' => null, 'backgroundimage' => null, 'disposition' => null), + 'notice' => + array('contentlimit' => null), + 'message' => + array('contentlimit' => null), ); $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 5be2f2fe6..08141177a 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -35,7 +35,6 @@ if (!defined('LACONICA')) require_once INSTALLDIR.'/lib/facebookutil.php'; require_once INSTALLDIR.'/lib/noticeform.php'; - class FacebookAction extends Action { @@ -201,7 +200,6 @@ class FacebookAction extends Action } - // Make this into a widget later function showLocalNav() { @@ -261,7 +259,6 @@ class FacebookAction extends Action $this->endHTML(); } - function showInstructions() { @@ -287,7 +284,6 @@ class FacebookAction extends Action $this->elementEnd('div'); } - function showLoginForm($msg = null) { @@ -332,7 +328,6 @@ class FacebookAction extends Action } - function updateProfileBox($notice) { @@ -414,7 +409,6 @@ class FacebookAction extends Action $this->xw->openURI('php://output'); } - /** * Generate pagination links * @@ -473,8 +467,9 @@ class FacebookAction extends Action } else { $content_shortened = common_shorten_links($content); - if (mb_strlen($content_shortened) > 140) { - $this->showPage(_('That\'s too long. Max notice size is 140 chars.')); + if (Notice::contentTooLong($content_shortened)) { + $this->showPage(sprintf(_('That\'s too long. Max notice size is %d chars.'), + Notice::maxContent())); return; } } diff --git a/lib/groupeditform.php b/lib/groupeditform.php index fbb39129b..47e62d469 100644 --- a/lib/groupeditform.php +++ b/lib/groupeditform.php @@ -150,27 +150,33 @@ class GroupEditForm extends Form $this->out->elementStart('li'); $this->out->hidden('groupid', $id); $this->out->input('nickname', _('Nickname'), - ($this->out->arg('nickname')) ? $this->out->arg('nickname') : $nickname, - _('1-64 lowercase letters or numbers, no punctuation or spaces')); + ($this->out->arg('nickname')) ? $this->out->arg('nickname') : $nickname, + _('1-64 lowercase letters or numbers, no punctuation or spaces')); $this->out->elementEnd('li'); $this->out->elementStart('li'); $this->out->input('fullname', _('Full name'), - ($this->out->arg('fullname')) ? $this->out->arg('fullname') : $fullname); + ($this->out->arg('fullname')) ? $this->out->arg('fullname') : $fullname); $this->out->elementEnd('li'); $this->out->elementStart('li'); $this->out->input('homepage', _('Homepage'), - ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage, - _('URL of the homepage or blog of the group or topic')); + ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage, + _('URL of the homepage or blog of the group or topic')); $this->out->elementEnd('li'); $this->out->elementStart('li'); + $desclimit = User_group::maxDescription(); + if ($desclimit == 0) { + $descinstr = _('Describe the group or topic'); + } else { + $descinstr = sprintf(_('Describe the group or topic in %d characters'), $desclimit); + } $this->out->textarea('description', _('Description'), - ($this->out->arg('description')) ? $this->out->arg('description') : $description, - _('Describe the group or topic in 140 chars')); + ($this->out->arg('description')) ? $this->out->arg('description') : $description, + $descinstr); $this->out->elementEnd('li'); $this->out->elementStart('li'); $this->out->input('location', _('Location'), - ($this->out->arg('location')) ? $this->out->arg('location') : $location, - _('Location for the group, if any, like "City, State (or Region), Country"')); + ($this->out->arg('location')) ? $this->out->arg('location') : $location, + _('Location for the group, if any, like "City, State (or Region), Country"')); $this->out->elementEnd('li'); if (common_config('group', 'maxaliases') > 0) { $aliases = (empty($this->group)) ? array() : $this->group->getAliases(); diff --git a/lib/messageform.php b/lib/messageform.php index 8ea2b36c2..044fdc719 100644 --- a/lib/messageform.php +++ b/lib/messageform.php @@ -140,12 +140,19 @@ class MessageForm extends Form 'rows' => 4, 'name' => 'content'), ($this->content) ? $this->content : ''); - $this->out->elementStart('dl', 'form_note'); - $this->out->element('dt', null, _('Available characters')); - $this->out->element('dd', array('id' => 'notice_text-count'), - '140'); - $this->out->elementEnd('dl'); + $contentLimit = Message::maxContent(); + + $this->out->element('script', array('type' => 'text/javascript'), + 'maxLength = ' . $contentLimit . ';'); + + if ($contentLimit > 0) { + $this->out->elementStart('dl', 'form_note'); + $this->out->element('dt', null, _('Available characters')); + $this->out->element('dd', array('id' => 'notice_text-count'), + $contentLimit); + $this->out->elementEnd('dl'); + } } /** diff --git a/lib/noticeform.php b/lib/noticeform.php index 4e2a2edd6..35a21c6bd 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -83,7 +83,7 @@ class NoticeForm extends Form $this->action = $action; $this->content = $content; - + if ($user) { $this->user = $user; } else { @@ -117,7 +117,6 @@ class NoticeForm extends Form return common_local_url('newnotice'); } - /** * Legend of the Form * @@ -128,7 +127,6 @@ class NoticeForm extends Form $this->out->element('legend', null, _('Send a notice')); } - /** * Data elements * @@ -145,11 +143,20 @@ class NoticeForm extends Form 'rows' => 4, 'name' => 'status_textarea'), ($this->content) ? $this->content : ''); - $this->out->elementStart('dl', 'form_note'); - $this->out->element('dt', null, _('Available characters')); - $this->out->element('dd', array('id' => 'notice_text-count'), - '140'); - $this->out->elementEnd('dl'); + + $contentLimit = Notice::maxContent(); + + $this->out->element('script', array('type' => 'text/javascript'), + 'maxLength = ' . $contentLimit . ';'); + + if ($contentLimit > 0) { + $this->out->elementStart('dl', 'form_note'); + $this->out->element('dt', null, _('Available characters')); + $this->out->element('dd', array('id' => 'notice_text-count'), + $contentLimit); + $this->out->elementEnd('dl'); + } + if (common_config('attachments', 'uploads')) { $this->out->element('label', array('for' => 'notice_data-attach'),_('Attach')); $this->out->element('input', array('id' => 'notice_data-attach', diff --git a/lib/settingsaction.php b/lib/settingsaction.php index 17d3a2f64..4cf9b80c4 100644 --- a/lib/settingsaction.php +++ b/lib/settingsaction.php @@ -77,10 +77,12 @@ class SettingsAction extends CurrentUserDesignAction // _all_ our settings are important common_set_returnto($this->selfUrl()); $user = common_current_user(); - if ($user->hasOpenID()) { - common_redirect(common_local_url('openidlogin'), 303); - } else { - common_redirect(common_local_url('login'), 303); + if (Event::handle('RedirectToLogin', array($this, $user))) { + if ($user->hasOpenID()) { + common_redirect(common_local_url('openidlogin'), 303); + } else { + common_redirect(common_local_url('login'), 303); + } } } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->handlePost(); diff --git a/lib/util.php b/lib/util.php index cd9bd9ed8..0402e2401 100644 --- a/lib/util.php +++ b/lib/util.php @@ -570,7 +570,8 @@ function common_linkify($url) { function common_shorten_links($text) { - if (mb_strlen($text) <= 140) return $text; + $maxLength = Notice::maxContent(); + if ($maxLength == 0 || mb_strlen($text) <= $maxLength) return $text; return common_replace_urls_callback($text, array('File_redirection', 'makeShort')); } @@ -1152,7 +1153,8 @@ function common_negotiate_type($cprefs, $sprefs) function common_config($main, $sub) { global $config; - return isset($config[$main][$sub]) ? $config[$main][$sub] : false; + return (array_key_exists($main, $config) && + array_key_exists($sub, $config[$main])) ? $config[$main][$sub] : false; } function common_copy_args($from) diff --git a/scripts/maildaemon.php b/scripts/maildaemon.php index 3ef4d0638..179f0de09 100755 --- a/scripts/maildaemon.php +++ b/scripts/maildaemon.php @@ -66,9 +66,10 @@ class MailerDaemon } $msg = $this->cleanup_msg($msg); $msg = common_shorten_links($msg); - if (mb_strlen($msg) > 140) { - $this->error($from,_('That\'s too long. '. - 'Max notice size is 140 chars.')); + if (Notice::contentTooLong($msg)) { + $this->error($from, sprintf(_('That\'s too long. '. + 'Max notice size is %d chars.'), + Notice::maxContent())); } $fileRecords = array(); foreach($attachments as $attachment){ @@ -78,9 +79,9 @@ class MailerDaemon die('error() should trigger an exception before reaching here.'); } $filename = $this->saveFile($user, $attachment,$mimetype); - + fclose($attachment); - + if (empty($filename)) { $this->error($from,_('Couldn\'t save file.')); } @@ -96,9 +97,10 @@ class MailerDaemon $short_fileurl = common_shorten_url($fileurl); $msg .= ' ' . $short_fileurl; - if (mb_strlen($msg) > 140) { + if (Notice::contentTooLong($msg)) { $this->deleteFile($filename); - $this->error($from,_('Max notice size is 140 chars, including attachment URL.')); + $this->error($from, sprintf(_('Max notice size is %d chars, including attachment URL.'), + Notice::maxContent())); } // Also, not sure this is necessary -- Zach @@ -123,7 +125,7 @@ class MailerDaemon $stream = stream_get_meta_data($attachment); if (copy($stream['uri'], $filepath) && chmod($filepath,0664)) { return $filename; - } else { + } else { $this->error(null,_('File could not be moved to destination directory.' . $stream['uri'] . ' ' . $filepath)); } } @@ -152,7 +154,7 @@ class MailerDaemon } function maybeAddRedir($file_id, $url) - { + { $file_redir = File_redirection::staticGet('url', $url); if (empty($file_redir)) { @@ -273,7 +275,7 @@ class MailerDaemon } function attachFile($notice, $filerec) - { + { File_to_post::processNew($filerec->id, $notice->id); $this->maybeAddRedir($filerec->id, diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index 69512f243..f033025f8 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -316,9 +316,11 @@ class XMPPDaemon extends Daemon { $body = trim($pl['body']); $content_shortened = common_shorten_links($body); - if (mb_strlen($content_shortened) > 140) { + if (Notice::contentTooLong($content_shortened)) { $from = jabber_normalize_jid($pl['from']); - $this->from_site($from, "Message too long - maximum is 140 characters, you sent ".mb_strlen($content_shortened)); + $this->from_site($from, sprintf(_("Message too long - maximum is %d characters, you sent %d"), + Notice::maxContent(), + mb_strlen($content_shortened))); return; } $notice = Notice::saveNew($user->id, $content_shortened, 'xmpp'); |