static function blockProfile($group, $profile, $blocker) { // Insert the block $block = new Group_block(); $block->query('BEGIN'); $block->group_id = $group->id; $block->blocked = $profile->id; $block->blocker = $blocker->id; $result = $block->insert(); if (!$result) { common_log_db_error($block, 'INSERT', __FILE__); return null; } // Delete membership if any $member = new Group_member(); $member->group_id = $group->id; $member->profile_id = $profile->id; if ($member->find(true)) { $result = $member->delete(); if (!$result) { common_log_db_error($member, 'DELETE', __FILE__); return null; } } // Commit, since both have been done $block->query('COMMIT'); return $block; }
static function leave($group_id, $profile_id) { $member = Group_member::pkeyGet(array('group_id' => $group_id, 'profile_id' => $profile_id)); if (empty($member)) { throw new Exception(_("Not part of group.")); } $result = $member->delete(); if (!$result) { common_log_db_error($member, 'INSERT', __FILE__); throw new Exception(_("Group leave failed.")); } return true; }
static function leave($group_id, $profile_id) { $member = Group_member::pkeyGet(array('group_id' => $group_id, 'profile_id' => $profile_id)); if (empty($member)) { // TRANS: Exception thrown when trying to leave a group the user is not a member of. throw new Exception(_("Not part of group.")); } $result = $member->delete(); if (!$result) { common_log_db_error($member, 'INSERT', __FILE__); // TRANS: Exception thrown when trying to leave a group fails. throw new Exception(_("Group leave failed.")); } return true; }
/** * Complete a pending group join... * * @return Group_member object on success */ function complete() { $join = null; $profile = $this->getMember(); $group = $this->getGroup(); if (Event::handle('StartJoinGroup', array($profile, $group))) { $join = Group_member::join($group->id, $profile->id); $this->delete(); Event::handle('EndJoinGroup', array($profile, $group)); } if (!$join) { throw new Exception('Internal error: group join failed.'); } $join->notify(); return $join; }
function showContent() { $notice = $this->nli->notice; $out = $this->nli->out; $mem = Group_member::getKV('uri', $notice->uri); if (!empty($mem)) { $out->elementStart('div', 'join-activity'); $profile = $mem->getMember(); $group = $mem->getGroup(); // TRANS: Text for "joined list" item in activity plugin. // TRANS: %1$s is a profile URL, %2$s is a profile name, // TRANS: %3$s is a group home URL, %4$s is a group name. $out->raw(sprintf(_m('<a href="%1$s">%2$s</a> joined the group <a href="%3$s">%4$s</a>.'), $profile->profileurl, $profile->getBestName(), $group->homeUrl(), $group->getBestName())); $out->elementEnd('div'); } else { parent::showContent(); } }
function onEndUserRegister($profile, $user) { $profile = $user->getProfile(); foreach ($this->join as $nickname) { $group = User_group::getForNickname($nickname); if ($group && !$profile->isMember($group)) { try { if (Event::handle('StartJoinGroup', array($group, $user))) { Group_member::join($group->id, $user->id); Event::handle('EndJoinGroup', array($group, $user)); } } catch (Exception $e) { // TRANS: Server exception. // TRANS: %1$s is a user nickname, %2$s is a group nickname. throw new ServerException(sprintf(_m('Could not join user %1$s to group %2$s.'), $user->nickname, $group->nickname)); } } } }
protected function atompubPrepare() { $this->_profile = Profile::getKV('id', $this->trimmed('profile')); if (!$this->_profile instanceof Profile) { // TRANS: Client exception. throw new ClientException(_('No such profile.'), 404); } $this->_group = User_group::getKV('id', $this->trimmed('group')); if (!$this->_group instanceof User_group) { // TRANS: Client exception thrown when referencing a non-existing group. throw new ClientException(_('No such group.'), 404); } $kv = array('group_id' => $groupId, 'profile_id' => $this->_profile->id); $this->_membership = Group_member::pkeyGet($kv); if (!$this->_membership instanceof Group_member) { // TRANS: Client exception thrown when trying to show membership of a non-subscribed group throw new ClientException(_('Not a member.'), 404); } return true; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); $profileId = $this->trimmed('profile'); $this->_profile = Profile::staticGet('id', $profileId); if (empty($this->_profile)) { // TRANS: Client exception. throw new ClientException(_('No such profile.'), 404); } $groupId = $this->trimmed('group'); $this->_group = User_group::staticGet('id', $groupId); if (empty($this->_group)) { // TRANS: Client exception thrown when referencing a non-existing group. throw new ClientException(_('No such group.'), 404); } $kv = array('group_id' => $groupId, 'profile_id' => $profileId); $this->_membership = Group_member::pkeyGet($kv); if (empty($this->_membership)) { // TRANS: Client exception thrown when trying to show membership of a non-subscribed group throw new ClientException(_('Not a member.'), 404); } return true; }
/** * Handle the request * * Save the new message * * @return void */ protected function handle() { parent::handle(); if (!$this->scoped instanceof Profile) { // TRANS: Client error displayed when trying to have a non-existing user leave a group. $this->clientError(_('No such user.'), 404); } if (!$this->group instanceof User_group) { // TRANS: Client error displayed when trying to leave a group that does not exist. $this->clientError(_('Group not found.'), 404); } $member = new Group_member(); $member->group_id = $this->group->id; $member->profile_id = $this->scoped->id; if (!$member->find(true)) { // TRANS: Server error displayed when trying to leave a group the user is not a member of. $this->serverError(_('You are not a member of this group.')); } try { $this->user->leaveGroup($this->group); } catch (Exception $e) { // TRANS: Server error displayed when leaving a group failed in the database. // TRANS: %1$s is the leaving user's nickname, $2$s is the group nickname for which the leave failed. $this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'), $this->scoped->getNickname(), $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 moveActivity($act, $sink, $user, $remote) { if (empty($user)) { throw new Exception(sprintf(_("No such user %s."), $act->actor->id)); } switch ($act->verb) { case ActivityVerb::FAVORITE: $this->log(LOG_INFO, "Moving favorite of {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}."); // push it, then delete local $sink->postActivity($act); $notice = Notice::staticGet('uri', $act->objects[0]->id); if (!empty($notice)) { $fave = Fave::pkeyGet(array('user_id' => $user->id, 'notice_id' => $notice->id)); $fave->delete(); } break; case ActivityVerb::POST: $this->log(LOG_INFO, "Moving notice {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}."); // XXX: send a reshare, not a post $sink->postActivity($act); $notice = Notice::staticGet('uri', $act->objects[0]->id); if (!empty($notice)) { $notice->delete(); } break; case ActivityVerb::JOIN: $this->log(LOG_INFO, "Moving group join of {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}."); $sink->postActivity($act); $group = User_group::staticGet('uri', $act->objects[0]->id); if (!empty($group)) { Group_member::leave($group->id, $user->id); } break; case ActivityVerb::FOLLOW: if ($act->actor->id == $user->uri) { $this->log(LOG_INFO, "Moving subscription to {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}."); $sink->postActivity($act); $other = Profile::fromURI($act->objects[0]->id); if (!empty($other)) { Subscription::cancel($user->getProfile(), $other); } } else { $otherUser = User::staticGet('uri', $act->actor->id); if (!empty($otherUser)) { $this->log(LOG_INFO, "Changing sub to {$act->objects[0]->id}" . "by {$act->actor->id} to {$remote->nickname}."); $otherProfile = $otherUser->getProfile(); Subscription::start($otherProfile, $remote); Subscription::cancel($otherProfile, $user->getProfile()); } else { $this->log(LOG_NOTICE, "Not changing sub to {$act->objects[0]->id}" . "by remote {$act->actor->id} " . "to {$remote->nickname}."); } } break; } }
/** * Handle the request * * On POST, add the current user to the group * * @param array $args unused * * @return void */ function handle($args) { parent::handle($args); $cur = common_current_user(); try { if (Event::handle('StartJoinGroup', array($this->group, $cur))) { Group_member::join($this->group->id, $cur->id); Event::handle('EndJoinGroup', array($this->group, $cur)); } } catch (Exception $e) { $this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'), $cur->nickname, $this->group->nickname)); } if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); $this->element('title', null, sprintf(_('%1$s joined group %2$s'), $cur->nickname, $this->group->nickname)); $this->elementEnd('head'); $this->elementStart('body'); $lf = new LeaveForm($this, $this->group); $lf->show(); $this->elementEnd('body'); $this->elementEnd('html'); } else { common_redirect(common_local_url('groupmembers', array('nickname' => $this->group->nickname)), 303); } }
/** * Delete the membership (leave the group) * * @return void */ function deleteMembership() { if (empty($this->auth_user) || $this->auth_user->id != $this->_profile->id) { // TRANS: Client exception thrown when deleting someone else's membership. throw new ClientException(_("Cannot delete someone else's" . " membership."), 403); } if (Event::handle('StartLeaveGroup', array($this->_group, $this->auth_user))) { Group_member::leave($this->_group->id, $this->auth_user->id); Event::handle('EndLeaveGroup', array($this->_group, $this->auth_user)); } return; }
/** * Get stream of memberships by member * * @param integer $memberId profile ID of the member to fetch for * @param integer $offset offset from start of stream to get * @param integer $limit number of memberships to get * * @return Group_member stream of memberships, use fetch() to iterate */ static function byMember($memberId, $offset = 0, $limit = GROUPS_PER_PAGE) { $membership = new Group_member(); $membership->profile_id = $memberId; $membership->orderBy('created DESC'); $membership->limit($offset, $limit); $membership->find(); return $membership; }
function getGroups() { $groups = array(); $gm = new Group_member(); $gm->profile_id = $this->user->id; if (!empty($this->after)) { $gm->whereAdd("created > '" . common_sql_date($this->after) . "'"); } if ($gm->find()) { while ($gm->fetch()) { $groups[] = clone $gm; } } return $groups; }
public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped = null) { switch ($stored->verb) { case ActivityVerb::UNFAVORITE: // FIXME: do something here break; case ActivityVerb::JOIN: $mem = Group_member::getKV('uri', $stored->getUri()); if ($mem instanceof Group_member) { $group = $mem->getGroup(); $act->title = $stored->getTitle(); $act->objects = array(ActivityObject::fromGroup($group)); } break; case ActivityVerb::LEAVE: // FIXME: ???? break; case ActivityVerb::FOLLOW: $sub = Subscription::getKV('uri', $stored->uri); if ($sub instanceof Subscription) { $profile = Profile::getKV('id', $sub->subscribed); if ($profile instanceof Profile) { $act->title = $stored->getTitle(); $act->objects = array($profile->asActivityObject()); } } break; case ActivityVerb::UNFOLLOW: // FIXME: ???? break; } return true; }
/** * Get the Nth most recent group membership for this user * * @param User $user The user to get memberships for * @param integer $n How far to count back * * @return Group_member a membership or null */ private function _getNthMem($user, $n) { $mem = new Group_member(); $mem->profile_id = $user->id; $mem->orderBy('created DESC'); $mem->limit($n - 1, 1); if ($mem->find(true)) { return $mem; } else { return null; } }
function handle($channel) { $group = $this->getGroup($this->other); $cur = $this->user; if (!$group) { // TRANS: Error text shown when trying to leave a group that does not exist. $channel->error($cur, _('No such group.')); return; } if (!$cur->isMember($group)) { // TRANS: Error text shown when trying to leave an existing group the user is not a member of. $channel->error($cur, _('You are not a member of that group.')); return; } try { if (Event::handle('StartLeaveGroup', array($group, $cur))) { Group_member::leave($group->id, $cur->id); Event::handle('EndLeaveGroup', array($group, $cur)); } } catch (Exception $e) { // TRANS: Message given having failed to remove a user from 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 remove user %1$s from group %2$s.'), $cur->nickname, $group->nickname)); return; } // TRANS: Message given having removed a user from 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 left group %2$s.'), $cur->nickname, $group->nickname)); }
function handle($channel) { $group = $this->getGroup($this->other); $cur = $this->user; if (!$group) { $channel->error($cur, _('No such group.')); return; } if (!$cur->isMember($group)) { $channel->error($cur, _('You are not a member of that group.')); return; } try { if (Event::handle('StartLeaveGroup', array($group, $cur))) { Group_member::leave($group->id, $cur->id); Event::handle('EndLeaveGroup', array($group, $cur)); } } catch (Exception $e) { $channel->error($cur, sprintf(_('Could not remove user %s to group %s'), $cur->nickname, $group->nickname)); return; } $channel->output($cur, sprintf(_('%s left group %s'), $cur->nickname, $group->nickname)); }
/** * 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 * * On POST, add the current user to the group * * @param array $args unused * * @return void */ function handle($args) { parent::handle($args); $cur = common_current_user(); try { if (Event::handle('StartJoinGroup', array($this->group, $cur))) { Group_member::join($this->group->id, $cur->id); Event::handle('EndJoinGroup', array($this->group, $cur)); } } 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; } if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); // TRANS: Title for join group page after joining. $this->element('title', null, sprintf(_m('TITLE', '%1$s joined group %2$s'), $cur->nickname, $this->group->nickname)); $this->elementEnd('head'); $this->elementStart('body'); $lf = new LeaveForm($this, $this->group); $lf->show(); $this->elementEnd('body'); $this->elementEnd('html'); } else { common_redirect(common_local_url('groupmembers', array('nickname' => $this->group->nickname)), 303); } }
function joinGroup($user, $activity) { // XXX: check that actor == subject $uri = $activity->objects[0]->id; $group = User_group::staticGet('uri', $uri); if (empty($group)) { $oprofile = Ostatus_profile::ensureActivityObjectProfile($activity->objects[0]); if (!$oprofile->isGroup()) { // TRANS: Client exception thrown when trying to join a remote group that is not a group. throw new ClientException(_("Remote profile is not a group!")); } $group = $oprofile->localGroup(); } assert(!empty($group)); if ($user->isMember($group)) { // TRANS: Client exception thrown when trying to join a group the importing user is already a member of. throw new ClientException(_("User is already a member of this group.")); } if (Event::handle('StartJoinGroup', array($group, $user))) { Group_member::join($group->id, $user->id); Event::handle('EndJoinGroup', array($group, $user)); } }
function isAdmin($group) { $mem = new Group_member(); $mem->group_id = $group->id; $mem->profile_id = $this->id; $mem->is_admin = 1; if ($mem->find()) { return true; } else { return false; } }
/** * 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; } }
/** * 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)) { $this->clientError(_('No such user.'), 404, $this->format); return; } if (empty($this->group)) { $this->clientError(_('Group not found.'), 404, $this->format); return false; } $member = new Group_member(); $member->group_id = $this->group->id; $member->profile_id = $this->auth_user->id; if (!$member->find(true)) { $this->serverError(_('You are not a member of this group.')); return; } $result = $member->delete(); if (!$result) { common_log_db_error($member, 'DELETE', __FILE__); $this->serverError(sprintf(_('Could not remove user %1$s from 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 dumpGroups($user, $dir) { common_log(LOG_INFO, 'dumping memberships of ' . $user->nickname . ' to directory ' . $dir); $page = 1; do { $mem = Group_member::byMember($user->id, ($page - 1) * GROUPS_PER_PAGE, GROUPS_PER_PAGE + 1); while ($mem->fetch()) { try { $fname = $dir . '/' . common_date_iso8601($mem->created) . '-membership-' . $mem->group_id . '.atom'; $act = $mem->asActivity(); $data = $act->asString(false, false, false); common_log(LOG_INFO, 'dumping membership in ' . $mem->group_id . ' to file ' . $fname); file_put_contents($fname, $data); $data = null; } catch (Exception $e) { common_log(LOG_ERR, "Error backing up membership in " . $mem->group_id . ": " . $e->getMessage()); continue; } } $page++; } while ($mem->N > GROUPS_PER_PAGE); }
/** * A remote user left our group. */ function handleLeave() { $oprofile = $this->ensureProfile(); if (!$oprofile) { $this->clientError(_m("Can't read profile to cancel group membership.")); } if ($oprofile->isGroup()) { $this->clientError(_m("Groups can't join groups.")); } common_log(LOG_INFO, "Remote profile {$oprofile->uri} leaving local group {$this->group->nickname}"); $profile = $oprofile->localProfile(); try { // @fixme event needs to be refactored as above //if (Event::handle('StartLeaveGroup', array($this->group, $profile))) { Group_member::leave($this->group->id, $profile->id); //Event::handle('EndLeaveGroup', 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 remove remote user %1$s from group %2$s.'), $oprofile->uri, $this->group->nickname)); return; } }
static function register($fields) { if (!empty($fields['userid'])) { $profile = Profile::staticGet('id', $fields['userid']); if ($profile && !$profile->hasRight(Right::CREATEGROUP)) { common_log(LOG_WARNING, "Attempted group creation from banned user: " . $profile->nickname); // TRANS: Client exception thrown when a user tries to create a group while banned. throw new ClientException(_('You are not allowed to create groups on this site.'), 403); } } // MAGICALLY put fields into current scope // @fixme kill extract(); it makes debugging absurdly hard $defaults = array('nickname' => null, 'fullname' => null, 'homepage' => null, 'description' => null, 'location' => null, 'uri' => null, 'mainpage' => null, 'aliases' => array(), 'userid' => null); $fields = array_merge($defaults, $fields); extract($fields); $group = new User_group(); $group->query('BEGIN'); if (empty($uri)) { // fill in later... $uri = null; } if (empty($mainpage)) { $mainpage = common_local_url('showgroup', array('nickname' => $nickname)); } $group->nickname = $nickname; $group->fullname = $fullname; $group->homepage = $homepage; $group->description = $description; $group->location = $location; $group->uri = $uri; $group->mainpage = $mainpage; $group->created = common_sql_now(); if (isset($fields['join_policy'])) { $group->join_policy = intval($fields['join_policy']); } else { $group->join_policy = 0; } if (isset($fields['force_scope'])) { $group->force_scope = intval($fields['force_scope']); } else { $group->force_scope = 0; } if (Event::handle('StartGroupSave', array(&$group))) { $result = $group->insert(); if (!$result) { common_log_db_error($group, 'INSERT', __FILE__); // TRANS: Server exception thrown when creating a group failed. throw new ServerException(_('Could not create group.')); } if (!isset($uri) || empty($uri)) { $orig = clone $group; $group->uri = common_local_url('groupbyid', array('id' => $group->id)); $result = $group->update($orig); if (!$result) { common_log_db_error($group, 'UPDATE', __FILE__); // TRANS: Server exception thrown when updating a group URI failed. throw new ServerException(_('Could not set group URI.')); } } $result = $group->setAliases($aliases); if (!$result) { // TRANS: Server exception thrown when creating group aliases failed. throw new ServerException(_('Could not create aliases.')); } $member = new Group_member(); $member->group_id = $group->id; $member->profile_id = $userid; $member->is_admin = 1; $member->created = $group->created; $result = $member->insert(); if (!$result) { common_log_db_error($member, 'INSERT', __FILE__); // TRANS: Server exception thrown when setting group membership failed. throw new ServerException(_('Could not set group membership.')); } self::blow('profile:groups:%d', $userid); if ($local) { $local_group = new Local_group(); $local_group->group_id = $group->id; $local_group->nickname = $nickname; $local_group->created = common_sql_now(); $result = $local_group->insert(); if (!$result) { common_log_db_error($local_group, 'INSERT', __FILE__); // TRANS: Server exception thrown when saving local group information failed. throw new ServerException(_('Could not save local group info.')); } } $group->query('COMMIT'); Event::handle('EndGroupSave', array($group)); } return $group; }
/** * Make user an admin * * @return void */ function makeAdmin() { $member = Group_member::pkeyGet(array('group_id' => $this->group->id, 'profile_id' => $this->profile->id)); if (empty($member)) { $this->serverError(_('Can\'t get membership record for %s in group %s'), $this->profile->getBestName(), $this->group->getBestName()); } $orig = clone $member; $member->is_admin = 1; $result = $member->update($orig); if (!$result) { common_log_db_error($member, 'UPDATE', __FILE__); $this->serverError(_('Can\'t make %s an admin for group %s'), $this->profile->getBestName(), $this->group->getBestName()); } 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('groupmembers', array('nickname' => $this->group->nickname)), 303); } }
static function register($fields) { // MAGICALLY put fields into current scope extract($fields); $group = new User_group(); $group->query('BEGIN'); if (empty($uri)) { // fill in later... $uri = null; } $group->nickname = $nickname; $group->fullname = $fullname; $group->homepage = $homepage; $group->description = $description; $group->location = $location; $group->uri = $uri; $group->mainpage = $mainpage; $group->created = common_sql_now(); $result = $group->insert(); if (!$result) { common_log_db_error($group, 'INSERT', __FILE__); // TRANS: Server exception thrown when creating a group failed. throw new ServerException(_('Could not create group.')); } if (!isset($uri) || empty($uri)) { $orig = clone $group; $group->uri = common_local_url('groupbyid', array('id' => $group->id)); $result = $group->update($orig); if (!$result) { common_log_db_error($group, 'UPDATE', __FILE__); // TRANS: Server exception thrown when updating a group URI failed. throw new ServerException(_('Could not set group URI.')); } } $result = $group->setAliases($aliases); if (!$result) { // TRANS: Server exception thrown when creating group aliases failed. throw new ServerException(_('Could not create aliases.')); } $member = new Group_member(); $member->group_id = $group->id; $member->profile_id = $userid; $member->is_admin = 1; $member->created = $group->created; $result = $member->insert(); if (!$result) { common_log_db_error($member, 'INSERT', __FILE__); // TRANS: Server exception thrown when setting group membership failed. throw new ServerException(_('Could not set group membership.')); } if ($local) { $local_group = new Local_group(); $local_group->group_id = $group->id; $local_group->nickname = $nickname; $local_group->created = common_sql_now(); $result = $local_group->insert(); if (!$result) { common_log_db_error($local_group, 'INSERT', __FILE__); // TRANS: Server exception thrown when saving local group information failed. throw new ServerException(_('Could not save local group info.')); } } $group->query('COMMIT'); return $group; }
/** * Attempt to finalize subscription. * validateFeed must have been run first. * * Calls showForm on failure or success on success. */ function saveFeed() { $user = common_current_user(); $group = $this->oprofile->localGroup(); if ($user->isMember($group)) { // TRANS: OStatus remote group subscription dialog error. $this->showForm(_m('Already a member!')); return; } if (Event::handle('StartJoinGroup', array($group, $user))) { $ok = Group_member::join($this->oprofile->group_id, $user->id); if ($ok) { Event::handle('EndJoinGroup', array($group, $user)); $this->success(); } else { // TRANS: OStatus remote group subscription dialog error. $this->showForm(_m('Remote group join failed!')); } } else { // TRANS: OStatus remote group subscription dialog error. $this->showForm(_m('Remote group join aborted!')); } }