当前位置: 首页>>代码示例>>PHP>>正文


PHP Message::saveNew方法代码示例

本文整理汇总了PHP中Message::saveNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::saveNew方法的具体用法?PHP Message::saveNew怎么用?PHP Message::saveNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Message的用法示例。


在下文中一共展示了Message::saveNew方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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());
     }
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:56,代码来源:messagecommand.php

示例2: execute

 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;
             }
         }
     }
     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) {
         $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
     } else {
         $channel->error($this->user, _('Error sending direct message.'));
     }
 }
开发者ID:Br3nda,项目名称:laconica,代码行数:37,代码来源:command.php

示例3: 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);
     }
 }
开发者ID:phpsource,项目名称:gnu-social,代码行数:44,代码来源:apidirectmessagenew.php

示例4: 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.'));
     }
 }
开发者ID:sukhjindersingh,项目名称:PHInest-Solutions,代码行数:44,代码来源:command.php

示例5: 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 (mb_strlen($content_shortened) > 140) {
             $this->showForm(_('That\'s too long. ' . 'Max message size is 140 chars.'));
             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;
     }
     $this->notify($user, $this->other, $message);
     $url = common_local_url('outbox', array('nickname' => $user->nickname));
     common_redirect($url, 303);
 }
开发者ID:Br3nda,项目名称:laconica,代码行数:44,代码来源:newmessage.php

示例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);
     }
 }
开发者ID:Br3nda,项目名称:StatusNet,代码行数:53,代码来源:apidirectmessagenew.php

示例7: 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);
     }
 }
开发者ID:stevertiqo,项目名称:StatusNet,代码行数:57,代码来源:newmessage.php

示例8: create

 function create($args, $apidata)
 {
     parent::handle($args);
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']);
         return;
     }
     $user = $apidata['user'];
     $source = $this->trimmed('source');
     // Not supported by Twitter.
     $reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api');
     if (!$source || in_array($source, $reserved_sources)) {
         $source = 'api';
     }
     $content = $this->trimmed('text');
     if (!$content) {
         $this->clientError(_('No message text!'), $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']);
             return;
         }
     }
     $other = $this->get_user($this->trimmed('user'));
     if (!$other) {
         $this->clientError(_('Recipient user not found.'), $code = 403, $apidata['content-type']);
         return;
     } else {
         if (!$user->mutuallySubscribed($other)) {
             $this->clientError(_('Can\'t send direct messages to users who aren\'t your friend.'), $code = 403, $apidata['content-type']);
             return;
         } else {
             if ($user->id == $other->id) {
                 // Sending msgs to yourself is allowed by Twitter
                 $this->clientError(_('Don\'t send a message to yourself; just say it to yourself quietly instead.'), $code = 403, $apidata['content-type']);
                 return;
             }
         }
     }
     $message = Message::saveNew($user->id, $other->id, html_entity_decode($content, ENT_NOQUOTES, 'UTF-8'), $source);
     if (is_string($message)) {
         $this->serverError($message);
         return;
     }
     $this->notify($user, $other, $message);
     if ($apidata['content-type'] == 'xml') {
         $this->show_single_xml_dmsg($message);
     } elseif ($apidata['content-type'] == 'json') {
         $this->show_single_json_dmsg($message);
     }
 }
开发者ID:Br3nda,项目名称:laconica,代码行数:52,代码来源:twitapidirect_messages.php

示例9: 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);
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:39,代码来源:newmessage.php


注:本文中的Message::saveNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。