123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- if (!defined('STATUSNET')) {
-
-
- exit(1);
- }
- class NewgroupmessageAction extends Action
- {
- var $group;
- var $user;
- var $text;
-
- function prepare(array $args = [])
- {
- parent::prepare($args);
- $this->user = common_current_user();
- if (empty($this->user)) {
-
- throw new ClientException(_m('Must be logged in.'), 403);
- }
- if (!$this->user->hasRight(Right::NEWMESSAGE)) {
-
- throw new Exception(sprintf(_m('User %s is not allowed to send private messages.'),
- $this->user->nickname));
- }
- $nicknameArg = $this->trimmed('nickname');
- $nickname = common_canonical_nickname($nicknameArg);
- if ($nickname != $nicknameArg) {
- $url = common_local_url('newgroupmessage', array('nickname' => $nickname));
- common_redirect($url, 301);
- }
- $localGroup = Local_group::getKV('nickname', $nickname);
- if (empty($localGroup)) {
-
- throw new ClientException(_m('No such group.'), 404);
- }
- $this->group = User_group::getKV('id', $localGroup->group_id);
- if (empty($this->group)) {
-
- throw new ClientException(_m('No such group.'), 404);
- }
-
- Group_privacy_settings::ensurePost($this->user, $this->group);
-
- if ($this->isPost()) {
- $this->checkSessionToken();
- $this->text = $this->trimmed('content');
- }
- return true;
- }
-
- function handle()
- {
- if ($this->isPost()) {
- $this->sendNewMessage();
- } else {
- $this->showPage();
- }
- }
- function sendNewMessage()
- {
- $gm = Group_message::send($this->user, $this->group, $this->text);
- if ($this->boolean('ajax')) {
- $this->startHTML('text/xml;charset=utf-8');
- $this->elementStart('head');
-
- $this->element('title', null, _m('Message sent'));
- $this->elementEnd('head');
- $this->elementStart('body');
- $this->element('p',
- array('id' => 'command_result'),
-
- sprintf(_m('Direct message to %s sent.'),
- $this->group->nickname));
- $this->elementEnd('body');
- $this->endHTML();
- } else {
- common_redirect($gm->url, 303);
- }
- }
- function showNoticeForm()
- {
- $form = new GroupMessageForm($this, $this->group);
- $form->show();
- }
- function title()
- {
-
- return sprintf(_m('New message to group %s'), $this->group->nickname);
- }
- }
|