本文整理汇总了PHP中Message::maxContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::maxContent方法的具体用法?PHP Message::maxContent怎么用?PHP Message::maxContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message::maxContent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
static function send($user, $group, $text)
{
if (!$user->hasRight(Right::NEWMESSAGE)) {
// XXX: maybe break this out into a separate right
// TRANS: Exception thrown when trying to send group private message without having the right to do that.
// TRANS: %s is a user nickname.
throw new Exception(sprintf(_m('User %s is not allowed to send private messages.'), $user->nickname));
}
Group_privacy_settings::ensurePost($user, $group);
$text = $user->shortenLinks($text);
// We use the same limits as for 'regular' private messages.
if (Message::contentTooLong($text)) {
// TRANS: Exception thrown when trying to send group private message that is too long.
// TRANS: %d is the maximum meggage length.
throw new Exception(sprintf(_m('That\'s too long. Maximum message size is %d character.', 'That\'s too long. Maximum message size is %d characters.', Message::maxContent()), Message::maxContent()));
}
// Valid! Let's do this thing!
$gm = new Group_message();
$gm->id = UUID::gen();
$gm->uri = common_local_url('showgroupmessage', array('id' => $gm->id));
$gm->from_profile = $user->id;
$gm->to_group = $group->id;
$gm->content = $text;
// XXX: is this cool?!
$gm->rendered = common_render_text($text);
$gm->url = $gm->uri;
$gm->created = common_sql_now();
// This throws a conniption if there's a problem
$gm->insert();
$gm->distribute();
return $gm;
}
示例2: handle
function handle($channel)
{
try {
$other = $this->getUser($this->other)->getProfile();
} catch (CommandException $e) {
try {
$profile = $this->getProfile($this->other);
} catch (CommandException $f) {
throw $e;
}
// TRANS: Command exception text shown when trying to send a direct message to a remote user (a user not registered at the current server).
// TRANS: %s is a remote profile.
throw new CommandException(sprintf(_('%s is a remote profile; you can only send direct messages to users on the same server.'), $this->other));
}
$len = mb_strlen($this->text);
if ($len == 0) {
// TRANS: Command exception text shown when trying to send a direct message to another user without content.
$channel->error($this->user, _('No content!'));
return;
}
$this->text = $this->user->shortenLinks($this->text);
if (Message::contentTooLong($this->text)) {
// XXX: i18n. Needs plural support.
// TRANS: Message given if content is too long. %1$sd is used for plural.
// TRANS: %1$d is the maximum number of characters, %2$d is the number of submitted characters.
$channel->error($this->user, sprintf(_m('Message too long - maximum is %1$d character, you sent %2$d.', 'Message too long - maximum is %1$d characters, you sent %2$d.', Message::maxContent()), Message::maxContent(), mb_strlen($this->text)));
return;
}
if (!$other instanceof Profile) {
// TRANS: Error text shown when trying to send a direct message to a user that does not exist.
$channel->error($this->user, _('No such user.'));
return;
} else {
if (!$this->user->mutuallySubscribed($other)) {
// TRANS: Error text shown when trying to send a direct message to a user without a mutual subscription (each user must be subscribed to the other).
$channel->error($this->user, _('You can\'t send a message to this user.'));
return;
} else {
if ($this->user->id == $other->id) {
// TRANS: Error text shown when trying to send a direct message to self.
$channel->error($this->user, _('Do not send a message to yourself; just say it to yourself quietly instead.'));
return;
}
}
}
try {
$message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
$message->notify();
// TRANS: Message given have sent a direct message to another user.
// TRANS: %s is the name of the other user.
$channel->output($this->user, sprintf(_('Direct message to %s sent.'), $this->other));
} catch (Exception $e) {
// TRANS: Error text shown sending a direct message fails with an unknown reason.
$channel->error($this->user, $e->getMessage());
}
}
示例3: formData
/**
* Data elements
*
* @return void
*/
function formData()
{
$user = common_current_user();
$mutual_users = $user->mutuallySubscribedUsers();
$mutual = array();
// TRANS: Label entry in drop-down selection box in direct-message inbox/outbox.
// TRANS: This is the default entry in the drop-down box, doubling as instructions
// TRANS: and a brake against accidental submissions with the first user in the list.
$mutual[0] = _('Select recipient:');
while ($mutual_users->fetch()) {
if ($mutual_users->id != $user->id) {
$mutual[$mutual_users->id] = $mutual_users->nickname;
}
}
$mutual_users->free();
unset($mutual_users);
if (count($mutual) == 1) {
// TRANS: Entry in drop-down selection box in direct-message inbox/outbox when no one is available to message.
$mutual[0] = _('No mutual subscribers.');
}
// TRANS: Dropdown label in direct notice form.
$this->out->dropdown('to', _('To'), $mutual, null, false, $this->to ? $this->to->id : null);
$this->out->element('textarea', array('class' => 'notice_data-text', 'cols' => 35, 'rows' => 4, 'name' => 'content'), $this->content ? $this->content : '');
$contentLimit = Message::maxContent();
if ($contentLimit > 0) {
$this->out->element('span', array('class' => 'count'), $contentLimit);
}
}
示例4: handle
/**
* Handle the request
*
* Save the new message
*
* @return void
*/
protected function handle()
{
parent::handle();
if (empty($this->content)) {
// TRANS: Client error displayed when no message text was submitted (406).
$this->clientError(_('No message text!'), 406);
} else {
$content_shortened = $this->auth_user->shortenLinks($this->content);
if (Message::contentTooLong($content_shortened)) {
// TRANS: Client error displayed when message content is too long.
// TRANS: %d is the maximum number of characters for a message.
$this->clientError(sprintf(_m('That\'s too long. Maximum message size is %d character.', 'That\'s too long. Maximum message size is %d characters.', Message::maxContent()), Message::maxContent()), 406);
}
}
if (!$this->other instanceof Profile) {
// TRANS: Client error displayed if a recipient user could not be found (403).
$this->clientError(_('Recipient user not found.'), 403);
} else {
if (!$this->user->mutuallySubscribed($this->other)) {
// TRANS: Client error displayed trying to direct message another user who's not a friend (403).
$this->clientError(_('Cannot send direct messages to users who aren\'t your friend.'), 403);
} else {
if ($this->user->id == $this->other->id) {
// Note: sending msgs to yourself is allowed by Twitter
// TRANS: Client error displayed trying to direct message self (403).
$this->clientError(_('Do not send a message to yourself; just say it to yourself quietly instead.'), 403);
}
}
}
$message = Message::saveNew($this->user->id, $this->other->id, html_entity_decode($this->content, ENT_NOQUOTES, 'UTF-8'), $this->source);
$message->notify();
if ($this->format == 'xml') {
$this->showSingleXmlDirectMessage($message);
} elseif ($this->format == 'json') {
$this->showSingleJsondirectMessage($message);
}
}
示例5: handle
function handle($channel)
{
try {
$other = $this->getUser($this->other);
} catch (CommandException $e) {
try {
$profile = $this->getProfile($this->other);
} catch (CommandException $f) {
throw $e;
}
throw new CommandException(sprintf(_('%s is a remote profile; you can only send direct messages to users on the same server.'), $this->other));
}
$len = mb_strlen($this->text);
if ($len == 0) {
$channel->error($this->user, _('No content!'));
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) {
$channel->error($this->user, _('No such user.'));
return;
} else {
if (!$this->user->mutuallySubscribed($other)) {
$channel->error($this->user, _('You can\'t send a message to this user.'));
return;
} else {
if ($this->user->id == $other->id) {
$channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
return;
}
}
}
$message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
if ($message) {
$message->notify();
$channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
} else {
$channel->error($this->user, _('Error sending direct message.'));
}
}
示例6: handle
/**
* Handle the request
*
* Save the new message
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
function handle($args)
{
parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(_('This method requires a POST.'), 400, $this->format);
return;
}
if (empty($this->content)) {
$this->clientError(_('No message text!'), 406, $this->format);
} else {
$content_shortened = common_shorten_links($this->content);
if (Message::contentTooLong($content_shortened)) {
$this->clientError(sprintf(_('That\'s too long. Max message size is %d chars.'), Message::maxContent()), 406, $this->format);
return;
}
}
if (empty($this->other)) {
$this->clientError(_('Recipient user not found.'), 403, $this->format);
return;
} else {
if (!$this->user->mutuallySubscribed($this->other)) {
$this->clientError(_('Can\'t send direct messages to users who aren\'t your friend.'), 403, $this->format);
return;
} else {
if ($this->user->id == $this->other->id) {
// Note: sending msgs to yourself is allowed by Twitter
$errmsg = 'Don\'t send a message to yourself; ' . 'just say it to yourself quietly instead.';
$this->clientError(_($errmsg), 403, $this->format);
return;
}
}
}
$message = Message::saveNew($this->user->id, $this->other->id, html_entity_decode($this->content, ENT_NOQUOTES, 'UTF-8'), $this->source);
if (is_string($message)) {
$this->serverError($message);
return;
}
$message->notify();
if ($this->format == 'xml') {
$this->showSingleXmlDirectMessage($message);
} elseif ($this->format == 'json') {
$this->showSingleJsondirectMessage($message);
}
}
示例7: formData
/**
* Data elements
*
* @return void
*/
function formData()
{
$user = common_current_user();
$mutual_users = $user->mutuallySubscribedUsers();
$mutual = array();
while ($mutual_users->fetch()) {
if ($mutual_users->id != $user->id) {
$mutual[$mutual_users->id] = $mutual_users->nickname;
}
}
$mutual_users->free();
unset($mutual_users);
$this->out->dropdown('to', _('To'), $mutual, null, false, $this->to ? $this->to->id : null);
$this->out->element('textarea', array('id' => 'notice_data-text', 'cols' => 35, 'rows' => 4, 'name' => 'content'), $this->content ? $this->content : '');
$contentLimit = Message::maxContent();
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');
}
}
示例8: saveNewMessage
function saveNewMessage()
{
// CSRF protection
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->showForm(_('There was a problem with your session token. ' . 'Try again, please.'));
return;
}
$user = common_current_user();
assert($user);
// XXX: maybe an error instead...
if (!$this->content) {
$this->showForm(_('No content!'));
return;
} else {
$content_shortened = common_shorten_links($this->content);
if (Message::contentTooLong($content_shortened)) {
// TRANS: Form validation error displayed when message content is too long.
// TRANS: %d is the maximum number of characters for a message.
$this->showForm(sprintf(_m('That\'s too long. Maximum message size is %d character.', 'That\'s too long. Maximum message size is %d characters.', Message::maxContent()), Message::maxContent()));
return;
}
}
if (!$this->other) {
$this->showForm(_('No recipient specified.'));
return;
} else {
if (!$user->mutuallySubscribed($this->other)) {
$this->clientError(_('You can\'t send a message to this user.'), 404);
return;
} else {
if ($user->id == $this->other->id) {
$this->clientError(_('Don\'t send a message to yourself; ' . 'just say it to yourself quietly instead.'), 403);
return;
}
}
}
$message = Message::saveNew($user->id, $this->other->id, $this->content, 'web');
if (is_string($message)) {
$this->showForm($message);
return;
}
$message->notify();
if ($this->boolean('ajax')) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
$this->element('title', null, _('Message sent'));
$this->elementEnd('head');
$this->elementStart('body');
$this->element('p', array('id' => 'command_result'), sprintf(_('Direct message to %s sent.'), $this->other->nickname));
$this->elementEnd('body');
$this->elementEnd('html');
} else {
$url = common_local_url('outbox', array('nickname' => $user->nickname));
common_redirect($url, 303);
}
}
示例9: formData
/**
* Entry data
*
* @param
*
* @return
*/
function formData()
{
$this->out->element('label', array('for' => 'notice_data-text', 'id' => 'notice_data-text-label'), sprintf(_m('Direct message to %s'), $this->group->nickname));
$this->out->element('textarea', array('id' => 'notice_data-text', 'cols' => 35, 'rows' => 4, 'name' => 'content'), $this->content ? $this->content : '');
$contentLimit = Message::maxContent();
if ($contentLimit > 0) {
$this->out->elementStart('dl', 'form_note');
// TRANS: Indicator for number of chatacters still available for notice.
$this->out->element('dt', null, _m('Available characters'));
$this->out->element('dd', array('class' => 'count'), $contentLimit);
$this->out->elementEnd('dl');
}
}
示例10: doPost
protected function doPost()
{
assert($this->scoped instanceof Profile);
// XXX: maybe an error instead...
if (empty($this->content)) {
// TRANS: Form validator error displayed trying to send a direct message without content.
$this->clientError(_('No content!'));
}
$content_shortened = $this->scoped->shortenLinks($this->content);
if (Message::contentTooLong($content_shortened)) {
// TRANS: Form validation error displayed when message content is too long.
// TRANS: %d is the maximum number of characters for a message.
$this->clientError(sprintf(_m('That\'s too long. Maximum message size is %d character.', 'That\'s too long. Maximum message size is %d characters.', Message::maxContent()), Message::maxContent()));
}
if (!$this->other instanceof Profile) {
// TRANS: Form validation error displayed trying to send a direct message without specifying a recipient.
$this->clientError(_('No recipient specified.'));
} else {
if (!$this->scoped->mutuallySubscribed($this->other)) {
// TRANS: Client error displayed trying to send a direct message to a user while sender and
// TRANS: receiver are not subscribed to each other.
$this->clientError(_('You cannot send a message to this user.'), 404);
} else {
if ($this->scoped->id == $this->other->id) {
// TRANS: Client error displayed trying to send a direct message to self.
$this->clientError(_('Do not send a message to yourself; ' . 'just say it to yourself quietly instead.'), 403);
}
}
}
$message = Message::saveNew($this->scoped->id, $this->other->id, $this->content, 'web');
$message->notify();
if (GNUsocial::isAjax()) {
// TRANS: Confirmation text after sending a direct message.
// TRANS: %s is the direct message recipient.
return sprintf(_('Direct message to %s sent.'), $this->other->getNickname());
}
$url = common_local_url('outbox', array('nickname' => $this->scoped->getNickname()));
common_redirect($url, 303);
}