function initFeed() { parent::initFeed(); $attrs = array(); if (!empty($this->cur)) { $attrs['member'] = $this->cur->isMember($this->group) ? 'true' : 'false'; $attrs['blocked'] = Group_block::isBlocked($this->group, $this->cur->getProfile()) ? 'true' : 'false'; } $attrs['member_count'] = $this->group->getMemberCount(); $this->element('statusnet:group_info', $attrs, null); }
static function unblockProfile($group, $profile) { $block = Group_block::pkeyGet(array('group_id' => $group->id, 'blocked' => $profile->id)); if (empty($block)) { return null; } $result = $block->delete(); if (!$result) { common_log_db_error($block, 'DELETE', __FILE__); return null; } return true; }
/** * A remote user joined our group. * @fixme move permission checks and event call into common code, * currently we're doing the main logic in joingroup action * and so have to repeat it here. */ function handleJoin() { $oprofile = $this->ensureProfile(); if (!$oprofile) { // TRANS: Client error. $this->clientError(_m("Can't read profile to set up group membership.")); } if ($oprofile->isGroup()) { // TRANS: Client error. $this->clientError(_m("Groups can't join groups.")); } common_log(LOG_INFO, "Remote profile {$oprofile->uri} joining local group {$this->group->nickname}"); $profile = $oprofile->localProfile(); if ($profile->isMember($this->group)) { // Already a member; we'll take it silently to aid in resolving // inconsistencies on the other side. return true; } if (Group_block::isBlocked($this->group, $profile)) { $this->clientError(_m('You have been blocked from that group by the admin.'), 403); return false; } try { // @fixme that event currently passes a user from main UI // Event should probably move into Group_member::join // and take a Profile object. // //if (Event::handle('StartJoinGroup', array($this->group, $profile))) { Group_member::join($this->group->id, $profile->id); //Event::handle('EndJoinGroup', array($this->group, $profile)); //} } catch (Exception $e) { // TRANS: Server error. %1$s is a profile URI, %2$s is a group nickname. $this->serverError(sprintf(_m('Could not join remote user %1$s to group %2$s.'), $oprofile->uri, $this->group->nickname)); } }
function showActions() { $cur = common_current_user(); $this->out->elementStart('div', 'entity_actions'); // TRANS: Group actions header (h2). Text hidden by default. $this->out->element('h2', null, _('Group actions')); $this->out->elementStart('ul'); if (Event::handle('StartGroupActionsList', array($this, $this->group))) { $this->out->elementStart('li', 'entity_subscribe'); if (Event::handle('StartGroupSubscribe', array($this, $this->group))) { if ($cur) { $profile = $cur->getProfile(); if ($profile->isMember($this->group)) { $lf = new LeaveForm($this->out, $this->group); $lf->show(); } else { if ($profile->isPendingMember($this->group)) { $cf = new CancelGroupForm($this->out, $this->group); $cf->show(); } else { if (!Group_block::isBlocked($this->group, $profile)) { $jf = new JoinForm($this->out, $this->group); $jf->show(); } } } } Event::handle('EndGroupSubscribe', array($this, $this->group)); } $this->out->elementEnd('li'); if ($cur && $cur->hasRight(Right::DELETEGROUP)) { $this->out->elementStart('li', 'entity_delete'); $df = new DeleteGroupForm($this->out, $this->group); $df->show(); $this->out->elementEnd('li'); } Event::handle('EndGroupActionsList', array($this, $this->group)); } $this->out->elementEnd('ul'); $this->out->elementEnd('div'); }
/** * Handle the request * * Join the authenticated user to the group * * @return void */ protected function handle() { parent::handle(); if (empty($this->scoped)) { // TRANS: Client error displayed when trying to have a non-existing user join a group. $this->clientError(_('No such user.'), 404); } if (empty($this->group)) { // TRANS: Client error displayed when trying to join a group that does not exist. $this->clientError(_('Group not found.'), 404); } if ($this->scoped->isMember($this->group)) { // TRANS: Server error displayed when trying to join a group the user is already a member of. $this->clientError(_('You are already a member of that group.'), 403); } if (Group_block::isBlocked($this->group, $this->scoped)) { // TRANS: Server error displayed when trying to join a group the user is blocked from joining. $this->clientError(_('You have been blocked from that group by the admin.'), 403); } try { $this->scoped->joinGroup($this->group); } catch (Exception $e) { // TRANS: Server error displayed when joining a group failed in the database. // TRANS: %1$s is the joining user's nickname, $2$s is the group nickname for which the join failed. $this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'), $this->scoped->nickname, $this->group->nickname)); } switch ($this->format) { case 'xml': $this->showSingleXmlGroup($this->group); break; case 'json': $this->showSingleJsonGroup($this->group); break; default: // TRANS: Client error displayed when coming across a non-supported API method. $this->clientError(_('API method not found.'), 404); } }
function getBlockedCount() { // XXX: WORM cache this $block = new Group_block(); $block->group_id = $this->id; return $block->count(); }
function twitterGroupArray($group) { $twitter_group = array(); $twitter_group['id'] = intval($group->id); $twitter_group['url'] = $group->permalink(); $twitter_group['nickname'] = $group->nickname; $twitter_group['fullname'] = $group->fullname; if (isset($this->auth_user)) { $twitter_group['member'] = $this->auth_user->isMember($group); $twitter_group['blocked'] = Group_block::isBlocked($group, $this->auth_user->getProfile()); } $twitter_group['member_count'] = $group->getMemberCount(); $twitter_group['original_logo'] = $group->original_logo; $twitter_group['homepage_logo'] = $group->homepage_logo; $twitter_group['stream_logo'] = $group->stream_logo; $twitter_group['mini_logo'] = $group->mini_logo; $twitter_group['homepage'] = $group->homepage; $twitter_group['description'] = $group->description; $twitter_group['location'] = $group->location; $twitter_group['created'] = $this->dateTwitter($group->created); $twitter_group['modified'] = $this->dateTwitter($group->modified); return $twitter_group; }
/** * Prepare to run */ function prepare($args) { parent::prepare($args); if (!common_logged_in()) { // TRANS: Client error displayed when trying to join a group while not logged in. $this->clientError(_('You must be logged in to join a group.')); return false; } $nickname_arg = $this->trimmed('nickname'); $id = intval($this->arg('id')); if ($id) { $this->group = User_group::staticGet('id', $id); } else { if ($nickname_arg) { $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname if ($nickname_arg != $nickname) { $args = array('nickname' => $nickname); common_redirect(common_local_url('leavegroup', $args), 301); return false; } $local = Local_group::staticGet('nickname', $nickname); if (!$local) { // TRANS: Client error displayed when trying to join a non-local group. $this->clientError(_('No such group.'), 404); return false; } $this->group = User_group::staticGet('id', $local->group_id); } else { // TRANS: Client error displayed when trying to join a group without providing a group name or group ID. $this->clientError(_('No nickname or ID.'), 404); return false; } } if (!$this->group) { // TRANS: Client error displayed when trying to join a non-existing group. $this->clientError(_('No such group.'), 404); return false; } $cur = common_current_user(); if ($cur->isMember($this->group)) { // TRANS: Client error displayed when trying to join a group while already a member. $this->clientError(_('You are already a member of that group.'), 403); return false; } if (Group_block::isBlocked($this->group, $cur->getProfile())) { // TRANS: Client error displayed when trying to join a group while being blocked form joining it. $this->clientError(_('You have been blocked from that group by the admin.'), 403); return false; } return true; }
/** * Actually block a user. * * @return void */ function blockProfile() { $block = Group_block::blockProfile($this->group, $this->profile, common_current_user()); if (empty($block)) { $this->serverError(_("Database error blocking user from group.")); return false; } // Now, gotta figure where we go back to foreach ($this->args as $k => $v) { if ($k == 'returnto-action') { $action = $v; } elseif (substr($k, 0, 9) == 'returnto-') { $args[substr($k, 9)] = $v; } } if ($action) { common_redirect(common_local_url($action, $args), 303); } else { common_redirect(common_local_url('groupmembers', array('nickname' => $this->group->nickname)), 303); } }
function ensurePost($user, $group) { $gps = self::forGroup($group); if ($gps->allow_privacy == Group_privacy_settings::NEVER) { // TRANS: Exception thrown when trying to set group privacy setting if group %s does not allow private messages. throw new Exception(sprintf(_m('Group %s does not allow private messages.'), $group->nickname)); } switch ($gps->allow_sender) { case Group_privacy_settings::EVERYONE: $profile = $user->getProfile(); if (Group_block::isBlocked($group, $profile)) { // TRANS: Exception thrown when trying to send group private message while blocked from that group. // TRANS: %1$s is a user nickname, %2$s is a group nickname. throw new Exception(sprintf(_m('User %1$s is blocked from group %2$s.'), $user->nickname, $group->nickname)); } break; case Group_privacy_settings::MEMBER: if (!$user->isMember($group)) { // TRANS: Exception thrown when trying to send group private message while not a member. // TRANS: %1$s is a user nickname, %2$s is a group nickname. throw new Exception(sprintf(_m('User %1$s is not a member of group %2$s.'), $user->nickname, $group->nickname)); } break; case Group_privacy_settings::ADMIN: if (!$user->isAdmin($group)) { // TRANS: Exception thrown when trying to send group private message while not a group administrator. // TRANS: %1$s is a user nickname, %2$s is a group nickname. throw new Exception(sprintf(_m('User %1$s is not an administrator of group %2$s.'), $user->nickname, $group->nickname)); } break; default: // TRANS: Exception thrown when encountering undefined group privacy settings. // TRANS: %s is a group nickname. throw new Exception(sprintf(_m('Unknown privacy settings for group %s.'), $group->nickname)); } return true; }
/** * Unblock a user. * * @return void */ function unblockProfile() { $result = Group_block::unblockProfile($this->group, $this->profile); if (!$result) { // TRANS: Server error displayed when unblocking a user from a group fails because of an unknown error. $this->serverError(_('Error removing the block.')); return; } foreach ($this->args as $k => $v) { if ($k == 'returnto-action') { $action = $v; } else { if (substr($k, 0, 9) == 'returnto-') { $args[substr($k, 9)] = $v; } } } if ($action) { common_redirect(common_local_url($action, $args), 303); } else { common_redirect(common_local_url('blockedfromgroup', array('nickname' => $this->group->nickname)), 303); } }
/** * Show the group profile * * Information about the group * * @return void */ function showGroupProfile() { $this->elementStart('div', array('id' => 'i', 'class' => 'entity_profile vcard author')); $this->element('h2', null, _('Group profile')); $this->elementStart('dl', 'entity_depiction'); $this->element('dt', null, _('Avatar')); $this->elementStart('dd'); $logo = $this->group->homepage_logo ? $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE); $this->element('img', array('src' => $logo, 'class' => 'photo avatar', 'width' => AVATAR_PROFILE_SIZE, 'height' => AVATAR_PROFILE_SIZE, 'alt' => $this->group->nickname)); $this->elementEnd('dd'); $this->elementEnd('dl'); $this->elementStart('dl', 'entity_nickname'); $this->element('dt', null, _('Nickname')); $this->elementStart('dd'); $hasFN = $this->group->fullname ? 'nickname url uid' : 'fn org nickname url uid'; $this->element('a', array('href' => $this->group->homeUrl(), 'rel' => 'me', 'class' => $hasFN), $this->group->nickname); $this->elementEnd('dd'); $this->elementEnd('dl'); if ($this->group->fullname) { $this->elementStart('dl', 'entity_fn'); $this->element('dt', null, _('Full name')); $this->elementStart('dd'); $this->element('span', 'fn org', $this->group->fullname); $this->elementEnd('dd'); $this->elementEnd('dl'); } if ($this->group->location) { $this->elementStart('dl', 'entity_location'); $this->element('dt', null, _('Location')); $this->element('dd', 'label', $this->group->location); $this->elementEnd('dl'); } if ($this->group->homepage) { $this->elementStart('dl', 'entity_url'); $this->element('dt', null, _('URL')); $this->elementStart('dd'); $this->element('a', array('href' => $this->group->homepage, 'rel' => 'me', 'class' => 'url'), $this->group->homepage); $this->elementEnd('dd'); $this->elementEnd('dl'); } if ($this->group->description) { $this->elementStart('dl', 'entity_note'); $this->element('dt', null, _('Note')); $this->element('dd', 'note', $this->group->description); $this->elementEnd('dl'); } if (common_config('group', 'maxaliases') > 0) { $aliases = $this->group->getAliases(); if (!empty($aliases)) { $this->elementStart('dl', 'entity_aliases'); $this->element('dt', null, _('Aliases')); $this->element('dd', 'aliases', implode(' ', $aliases)); $this->elementEnd('dl'); } } $this->elementEnd('div'); $cur = common_current_user(); $this->elementStart('div', 'entity_actions'); $this->element('h2', null, _('Group actions')); $this->elementStart('ul'); $this->elementStart('li', 'entity_subscribe'); if (Event::handle('StartGroupSubscribe', array($this, $this->group))) { if ($cur) { if ($cur->isMember($this->group)) { $lf = new LeaveForm($this, $this->group); $lf->show(); } else { if (!Group_block::isBlocked($this->group, $cur->getProfile())) { $jf = new JoinForm($this, $this->group); $jf->show(); } } } Event::handle('EndGroupSubscribe', array($this, $this->group)); } $this->elementEnd('li'); if ($cur && $cur->hasRight(Right::DELETEGROUP)) { $this->elementStart('li', 'entity_delete'); $df = new DeleteGroupForm($this, $this->group); $df->show(); $this->elementEnd('li'); } $this->elementEnd('ul'); $this->elementEnd('div'); }
/** * A remote user joined our group. * @fixme move permission checks and event call into common code, * currently we're doing the main logic in joingroup action * and so have to repeat it here. */ function handleJoin() { $oprofile = $this->ensureProfile(); if (!$oprofile) { // TRANS: Client error. $this->clientError(_m('Cannot read profile to set up group membership.')); } if ($oprofile->isGroup()) { // TRANS: Client error. $this->clientError(_m('Groups cannot join groups.')); } common_log(LOG_INFO, "Remote profile {$oprofile->uri} joining local group {$this->group->nickname}"); $profile = $oprofile->localProfile(); if ($profile->isMember($this->group)) { // Already a member; we'll take it silently to aid in resolving // inconsistencies on the other side. return true; } if (Group_block::isBlocked($this->group, $profile)) { // TRANS: Client error displayed when trying to join a group the user is blocked from by a group admin. $this->clientError(_m('You have been blocked from that group by the admin.'), 403); return false; } try { $profile->joinGroup($this->group); } catch (Exception $e) { // TRANS: Server error. %1$s is a profile URI, %2$s is a group nickname. $this->serverError(sprintf(_m('Could not join remote user %1$s to group %2$s.'), $oprofile->uri, $this->group->nickname)); } }
function showJoinButton() { $user = $this->owner; if ($user) { $this->out->elementStart('li', 'entity_subscribe'); // XXX: special-case for user looking at own // subscriptions page if ($user->isMember($this->profile->getGroup())) { $lf = new LeaveForm($this->out, $this->profile->getGroup()); $lf->show(); } else { if (!Group_block::isBlocked($this->profile->getGroup(), $user->getProfile())) { $jf = new JoinForm($this->out, $this->profile->getGroup()); $jf->show(); } } $this->out->elementEnd('li'); } }
function handle($channel) { $group = $this->getGroup($this->other); $cur = $this->user; if ($cur->isMember($group)) { // TRANS: Error text shown a user tries to join a group they already are a member of. $channel->error($cur, _('You are already a member of that group.')); return; } if (Group_block::isBlocked($group, $cur->getProfile())) { // TRANS: Error text shown when a user tries to join a group they are blocked from joining. $channel->error($cur, _('You have been blocked from that group by the admin.')); return; } try { if (Event::handle('StartJoinGroup', array($group, $cur))) { Group_member::join($group->id, $cur->id); Event::handle('EndJoinGroup', array($group, $cur)); } } catch (Exception $e) { // TRANS: Message given having failed to add a user to a group. // TRANS: %1$s is the nickname of the user, %2$s is the nickname of the group. $channel->error($cur, sprintf(_('Could not join user %1$s to group %2$s.'), $cur->nickname, $group->nickname)); return; } // TRANS: Message given having added a user to a group. // TRANS: %1$s is the nickname of the user, %2$s is the nickname of the group. $channel->output($cur, sprintf(_('%1$s joined group %2$s.'), $cur->nickname, $group->nickname)); }
function ensurePost($user, $group) { $gps = self::forGroup($group); if ($gps->allow_privacy == Group_privacy_settings::NEVER) { throw new Exception(sprintf(_('Group %s does not allow private messages.'), $group->nickname)); } switch ($gps->allow_sender) { case Group_privacy_settings::EVERYONE: $profile = $user->getProfile(); if (Group_block::isBlocked($group, $profile)) { throw new Exception(sprintf(_('User %s is blocked from group %s.'), $user->nickname, $group->nickname)); } break; case Group_privacy_settings::MEMBER: if (!$user->isMember($group)) { throw new Exception(sprintf(_('User %s is not a member of group %s.'), $user->nickname, $group->nickname)); } break; case Group_privacy_settings::ADMIN: if (!$user->isAdmin($group)) { throw new Exception(sprintf(_('User %s is not an administrator of group %s.'), $user->nickname, $group->nickname)); } break; default: throw new Exception(sprintf(_('Unknown privacy settings for group %s.'), $group->nickname)); } return true; }
/** * Actually block a user. * * @return void */ function blockProfile() { $block = Group_block::blockProfile($this->group, $this->profile, common_current_user()); if (empty($block)) { // TRANS: Server error displayed when trying to block a user from a group fails because of an application error. $this->serverError(_("Database error blocking user from group.")); } $this->returnToPrevious(); }
/** * A remote user joined our group. * @fixme move permission checks and event call into common code, * currently we're doing the main logic in joingroup action * and so have to repeat it here. */ function handleJoin() { if ($this->oprofile->isGroup()) { // TRANS: Client error. $this->clientError(_m('Groups cannot join groups.')); } common_log(LOG_INFO, sprintf('Remote profile %s joining local group %s', $this->oprofile->getUri(), $this->group->getNickname())); if ($this->actor->isMember($this->group)) { // Already a member; we'll take it silently to aid in resolving // inconsistencies on the other side. return true; } if (Group_block::isBlocked($this->group, $this->actor)) { // TRANS: Client error displayed when trying to join a group the user is blocked from by a group admin. $this->clientError(_m('You have been blocked from that group by the admin.'), 403); } try { $this->actor->joinGroup($this->group); } catch (Exception $e) { // TRANS: Server error. %1$s is a profile URI, %2$s is a group nickname. $this->serverError(sprintf(_m('Could not join remote user %1$s to group %2$s.'), $this->oprofile->getUri(), $this->group->getNickname())); } }
function handle($channel) { $group = $this->getGroup($this->other); $cur = $this->user; if ($cur->isMember($group)) { $channel->error($cur, _('You are already a member of that group')); return; } if (Group_block::isBlocked($group, $cur->getProfile())) { $channel->error($cur, _('You have been blocked from that group by the admin.')); return; } try { if (Event::handle('StartJoinGroup', array($group, $cur))) { Group_member::join($group->id, $cur->id); Event::handle('EndJoinGroup', array($group, $cur)); } } catch (Exception $e) { $channel->error($cur, sprintf(_('Could not join user %s to group %s'), $cur->nickname, $group->nickname)); return; } $channel->output($cur, sprintf(_('%s joined group %s'), $cur->nickname, $group->nickname)); }
function showActions() { $cur = common_current_user(); $this->out->elementStart('div', 'entity_actions'); // TRANS: Group actions header (h2). Text hidden by default. $this->out->element('h2', null, _('Group actions')); $this->out->elementStart('ul'); if (Event::handle('StartGroupActionsList', array($this, $this->group))) { $this->out->elementStart('li', 'entity_subscribe'); if (Event::handle('StartGroupSubscribe', array($this, $this->group))) { if ($cur) { $profile = $cur->getProfile(); if ($profile->isMember($this->group)) { $lf = new LeaveForm($this->out, $this->group); $lf->show(); } else { if ($profile->isPendingMember($this->group)) { $cf = new CancelGroupForm($this->out, $this->group); $cf->show(); } else { if (!Group_block::isBlocked($this->group, $profile)) { $jf = new JoinForm($this->out, $this->group); $jf->show(); } } } } Event::handle('EndGroupSubscribe', array($this, $this->group)); } $this->out->elementEnd('li'); if ($cur && $cur->isAdmin($this->group)) { $this->out->elementStart('li', 'entity_edit'); $this->out->element('a', array('href' => common_local_url('editgroup', array('nickname' => $this->group->nickname)), 'title' => sprintf(_m('TOOLTIP', 'Edit %s group properties'), $this->group->nickname)), _m('BUTTON', 'Edit')); $this->out->elementEnd('li'); $this->out->elementStart('li', 'entity_edit'); $this->out->element('a', array('href' => common_local_url('grouplogo', array('nickname' => $this->group->nickname)), 'title' => sprintf(_m('TOOLTIP', 'Add or edit %s logo'), $this->group->nickname)), _m('MENU', 'Logo')); $this->out->elementEnd('li'); } if ($cur && $cur->hasRight(Right::DELETEGROUP)) { $this->out->elementStart('li', 'entity_delete'); $df = new DeleteGroupForm($this->out, $this->group); $df->show(); $this->out->elementEnd('li'); } Event::handle('EndGroupActionsList', array($this, $this->group)); } $this->out->elementEnd('ul'); $this->out->elementEnd('div'); }
/** * Actually block a user. * * @return void */ function blockProfile() { $block = Group_block::blockProfile($this->group, $this->profile, common_current_user()); if (empty($block)) { $this->serverError(_("Database error blocking user from group.")); return false; } $this->returnToArgs(); }
/** * 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->user)) { // TRANS: Client error displayed when trying to have a non-existing user join a group. $this->clientError(_('No such user.'), 404, $this->format); return; } if (empty($this->group)) { // TRANS: Client error displayed when trying to join a group that does not exist. $this->clientError(_('Group not found.'), 404, $this->format); return false; } if ($this->user->isMember($this->group)) { $this->clientError(_('You are already a member of that group.'), 403, $this->format); return; } if (Group_block::isBlocked($this->group, $this->user->getProfile())) { $this->clientError(_('You have been blocked from that group by the admin.'), 403, $this->format); return; } $member = new Group_member(); $member->group_id = $this->group->id; $member->profile_id = $this->user->id; $member->created = common_sql_now(); $result = $member->insert(); if (!$result) { common_log_db_error($member, 'INSERT', __FILE__); $this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'), $this->user->nickname, $this->group->nickname)); return; } switch ($this->format) { case 'xml': $this->showSingleXmlGroup($this->group); break; case 'json': $this->showSingleJsonGroup($this->group); break; default: $this->clientError(_('API method not found.'), 404, $this->format); break; } }
function showGroup() { $this->out->elementStart('li', array('class' => 'profile h-card', 'id' => 'group-' . $this->group->id)); $user = common_current_user(); $this->out->elementStart('div', 'entity_profile'); $logo = $this->group->stream_logo ?: User_group::defaultLogo(AVATAR_STREAM_SIZE); $this->out->elementStart('a', array('href' => $this->group->homeUrl(), 'class' => 'u-url p-nickname', 'rel' => 'contact group')); $this->out->element('img', array('src' => $logo, 'class' => 'avatar u-photo', 'width' => AVATAR_STREAM_SIZE, 'height' => AVATAR_STREAM_SIZE, 'alt' => $this->group->getBestName())); $this->out->text($this->group->getNickname()); $this->out->elementEnd('a'); if ($this->group->fullname) { $this->out->text(' '); $this->out->elementStart('span', 'p-name'); $this->out->raw($this->highlight($this->group->fullname)); $this->out->elementEnd('span'); } if ($this->group->location) { $this->out->text(' '); $this->out->elementStart('span', 'label'); $this->out->raw($this->highlight($this->group->location)); $this->out->elementEnd('span'); } if ($this->group->homepage) { $this->out->text(' '); $this->out->elementStart('a', array('href' => $this->group->homepage, 'class' => 'u-url')); $this->out->raw($this->highlight($this->group->homepage)); $this->out->elementEnd('a'); } if ($this->group->description) { $this->out->elementStart('p', 'note'); $this->out->raw($this->highlight($this->group->description)); $this->out->elementEnd('p'); } // If we're on a list with an owner (subscriptions or subscribers)... if (!empty($user) && !empty($this->owner) && $user->id == $this->owner->id) { $this->showOwnerControls(); } $this->out->elementEnd('div'); if ($user) { $this->out->elementStart('div', 'entity_actions'); $this->out->elementStart('ul'); $this->out->elementStart('li', 'entity_subscribe'); // XXX: special-case for user looking at own // subscriptions page if ($user->isMember($this->group)) { $lf = new LeaveForm($this->out, $this->group); $lf->show(); } else { if (!Group_block::isBlocked($this->group, $user->getProfile())) { $jf = new JoinForm($this->out, $this->group); $jf->show(); } } $this->out->elementEnd('li'); $this->out->elementEnd('ul'); $this->out->elementEnd('div'); } $this->out->elementEnd('li'); }
function _deleteBlocks() { $block = new Profile_block(); $block->blocked = $this->id; $block->delete(); $block = new Group_block(); $block->blocked = $this->id; $block->delete(); }
/** * add a new favorite * * @return void */ function addMembership() { // XXX: Refactor this; all the same for atompub if (empty($this->auth_user) || $this->auth_user->id != $this->_profile->id) { // TRANS: Client exception thrown when trying subscribe someone else to a group. throw new ClientException(_("Cannot add someone else's" . " membership."), 403); } $xml = file_get_contents('php://input'); $dom = DOMDocument::loadXML($xml); if ($dom->documentElement->namespaceURI != Activity::ATOM || $dom->documentElement->localName != 'entry') { // TRANS: Client error displayed when not using an Atom entry. throw new ClientException(_('Atom post must be an Atom entry.')); return; } $activity = new Activity($dom->documentElement); $membership = null; if (Event::handle('StartAtomPubNewActivity', array(&$activity))) { if ($activity->verb != ActivityVerb::JOIN) { // TRANS: Client error displayed when not using the join verb. throw new ClientException(_('Can only handle join activities.')); } $groupObj = $activity->objects[0]; if ($groupObj->type != ActivityObject::GROUP) { // TRANS: Client exception thrown when trying to join something which is not a group throw new ClientException(_('Can only join groups.')); } $group = User_group::getKV('uri', $groupObj->id); if (empty($group)) { // XXX: import from listed URL or something // TRANS: Client exception thrown when trying to subscribe to a non-existing group. throw new ClientException(_('Unknown group.')); } $old = Group_member::pkeyGet(array('profile_id' => $this->auth_user->id, 'group_id' => $group->id)); if (!empty($old)) { // TRANS: Client exception thrown when trying to subscribe to an already subscribed group. throw new ClientException(_('Already a member.')); } $profile = $this->auth_user->getProfile(); if (Group_block::isBlocked($group, $profile)) { // XXX: import from listed URL or something // TRANS: Client exception thrown when trying to subscribe to group while blocked from that group. throw new ClientException(_('Blocked by admin.')); } $this->auth_user->joinGroup($group); Event::handle('EndAtomPubNewActivity', array($activity, $membership)); } if (!empty($membership)) { $act = $membership->asActivity(); header('Content-Type: application/atom+xml; charset=utf-8'); header('Content-Location: ' . $act->selfLink); $this->startXML(); $this->raw($act->asString(true, true, true)); $this->endXML(); } }
/** * 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->user)) { // TRANS: Client error displayed when trying to have a non-existing user join a group. $this->clientError(_('No such user.'), 404, $this->format); return; } if (empty($this->group)) { // TRANS: Client error displayed when trying to join a group that does not exist. $this->clientError(_('Group not found.'), 404, $this->format); return false; } if ($this->user->isMember($this->group)) { $this->clientError(_('You are already a member of that group.'), 403, $this->format); return; } if (Group_block::isBlocked($this->group, $this->user->getProfile())) { $this->clientError(_('You have been blocked from that group by the admin.'), 403, $this->format); return; } try { $this->user->joinGroup($this->group); } catch (Exception $e) { // TRANS: Server error displayed when joining a group failed in the database. // TRANS: %1$s is the joining user's nickname, $2$s is the group nickname for which the join failed. $this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'), $cur->nickname, $this->group->nickname)); return; } switch ($this->format) { case 'xml': $this->showSingleXmlGroup($this->group); break; case 'json': $this->showSingleJsonGroup($this->group); break; default: $this->clientError(_('API method not found.'), 404, $this->format); break; } }