コード例 #1
0
ファイル: Group_member.php プロジェクト: himmelex/NTW
 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;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
 /**
  * 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;
 }
コード例 #5
0
 /**
  * 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();
     }
 }
コード例 #6
0
 function onEndJoinGroup($group, $profile)
 {
     // Only do this if config is enabled
     if (!$this->JoinGroup) {
         return true;
     }
     if (!$profile->isLocal()) {
         return true;
     }
     // TRANS: Text for "joined group" item in activity plugin.
     // TRANS: %1$s is a profile URL, %2$s is a profile name,
     // TRANS: %3$s is a group URL, %4$s is a group name.
     $rendered = sprintf(_m('<a href="%1$s">%2$s</a> joined the group <a href="%3$s">%4$s</a>.'), $profile->getUrl(), $profile->getBestName(), $group->homeUrl(), $group->getBestName());
     // TRANS: Text for "joined group" item in activity plugin.
     // TRANS: %1$s is a profile name, %2$s is a profile URL,
     // TRANS: %3$s is a group name, %4$s is a group URL.
     $content = sprintf(_m('%1$s (%2$s) joined the group %3$s (%4$s).'), $profile->getBestName(), $profile->getUrl(), $group->getBestName(), $group->homeUrl());
     $mem = Group_member::pkeyGet(array('group_id' => $group->id, 'profile_id' => $profile->id));
     $notice = Notice::saveNew($profile->id, $content, ActivityPlugin::SOURCE, array('rendered' => $rendered, 'urls' => array(), 'groups' => array($group->id), 'uri' => $mem->getURI(), 'verb' => ActivityVerb::JOIN, 'object_type' => ActivityObject::GROUP));
     return true;
 }
コード例 #7
0
ファイル: makeadmin.php プロジェクト: Br3nda/laconica
 /**
  * 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);
     }
 }
コード例 #8
0
ファイル: makeadmin.php プロジェクト: bashrc/gnusocial-debian
 /**
  * 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)) {
         // TRANS: Server error displayed when trying to make another user admin on the Make Admin page fails
         // TRANS: because the group membership record could not be gotten.
         // TRANS: %1$s is the to be admin user, %2$s is the group user should be admin for.
         $this->serverError(_('Can\'t get membership record for %1$s in group %2$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__);
         // TRANS: Server error displayed when trying to make another user admin on the Make Admin page fails
         // TRANS: because the group adminship record coud not be saved properly.
         // TRANS: %1$s is the to be admin user, %2$s is the group user is already admin for.
         $this->serverError(_('Can\'t make %1$s an admin for group %2$s.'), $this->profile->getBestName(), $this->group->getBestName());
     }
     $this->returnToPrevious();
 }
コード例 #9
0
ファイル: Profile.php プロジェクト: phpsource/gnu-social
 function isAdmin(User_group $group)
 {
     $gm = Group_member::pkeyGet(array('profile_id' => $this->id, 'group_id' => $group->id));
     return !empty($gm) && $gm->is_admin;
 }
コード例 #10
0
$nickname = get_option_value('n', 'nickname');
$groupname = get_option_value('g', 'group');
if (empty($nickname) || empty($groupname)) {
    print "Must provide a nickname and group.\n";
    exit(1);
}
try {
    $user = User::getKV('nickname', $nickname);
    if (empty($user)) {
        throw new Exception("No user named '{$nickname}'.");
    }
    $group = User_group::getKV('nickname', $groupname);
    if (empty($group)) {
        throw new Exception("No group named '{$groupname}'.");
    }
    $member = Group_member::pkeyGet(array('group_id' => $group->id, 'profile_id' => $user->id));
    if (empty($member)) {
        $member = new Group_member();
        $member->group_id = $group->id;
        $member->profile_id = $user->id;
        $member->created = common_sql_now();
        if (!$member->insert()) {
            throw new Exception("Can't add '{$nickname}' to '{$groupname}'.");
        }
    }
    if ($member->is_admin) {
        throw new Exception("'{$nickname}' is already an admin of '{$groupname}'.");
    }
    $orig = clone $member;
    $member->is_admin = 1;
    if (!$member->update($orig)) {
コード例 #11
0
ファイル: makeadmin.php プロジェクト: microcosmx/experiments
 /**
  * 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 %1$s in group %2$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 %1$s an admin for group %2$s.'), $this->profile->getBestName(), $this->group->getBestName());
     }
     $this->returnToPrevious();
 }