Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->user = common_current_user();
     if (empty($this->user)) {
         throw new ClientException(_('Must be logged in.'), 403);
     }
     if (!$this->user->hasRight(Right::NEWMESSAGE)) {
         throw new Exception(sprintf(_('User %s 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);
         return false;
     }
     $localGroup = Local_group::staticGet('nickname', $nickname);
     if (empty($localGroup)) {
         throw new ClientException(_('No such group'), 404);
     }
     $this->group = User_group::staticGet('id', $localGroup->group_id);
     if (empty($this->group)) {
         throw new ClientException(_('No such group'), 404);
     }
     // This throws an exception on error
     Group_privacy_settings::ensurePost($this->user, $this->group);
     // If we're posted to, check session token and get text
     if ($this->isPost()) {
         $this->checkSessionToken();
         $this->text = $this->trimmed('content');
     }
     return true;
 }
 function forGroup($group)
 {
     $gps = Group_privacy_settings::getKV('group_id', $group->id);
     if (empty($gps)) {
         // make a fake one with defaults
         $gps = new Group_privacy_settings();
         $gps->allow_privacy = Group_privacy_settings::SOMETIMES;
         $gps->allow_sender = Group_privacy_settings::MEMBER;
     }
     return $gps;
 }
 function onStartShowExportData($action)
 {
     if ($action instanceof ShowgroupAction) {
         $gps = Group_privacy_settings::forGroup($action->group);
         if ($gps->allow_privacy == Group_privacy_settings::ALWAYS) {
             return false;
         }
     }
     return true;
 }