123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
- class AtompubshowmembershipAction extends AtompubAction
- {
- private $_private = null;
- private $_group = null;
- private $_membership = null;
- protected function atompubPrepare()
- {
- $this->_profile = Profile::getKV('id', $this->trimmed('profile'));
- if (!$this->_profile instanceof Profile) {
-
- throw new ClientException(_('No such profile.'), 404);
- }
- $this->_group = User_group::getKV('id', $this->trimmed('group'));
- if (!$this->_group instanceof User_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) {
-
- throw new ClientException(_('Not a member.'), 404);
- }
- return true;
- }
- protected function handleGet() {
- return $this->showMembership();
- }
- protected function handleDelete() {
- return $this->deleteMembership();
- }
-
- function showMembership()
- {
- $activity = $this->_membership->asActivity();
- header('Content-Type: application/atom+xml; charset=utf-8');
- $this->startXML();
- $this->raw($activity->asString(true, true, true));
- $this->endXML();
- return;
- }
-
- function deleteMembership()
- {
- if (empty($this->auth_user) ||
- $this->auth_user->id != $this->_profile->id) {
-
- throw new ClientException(_("Cannot delete someone else's".
- " membership."), 403);
- }
- $this->auth_user->leaveGroup($this->_group);
- return;
- }
-
- function lastModified()
- {
- return max(strtotime($this->_profile->modified),
- strtotime($this->_group->modified),
- strtotime($this->_membership->modified));
- }
-
- function etag()
- {
- $ctime = strtotime($this->_membership->created);
- $adminflag = ($this->_membership->is_admin) ? 't' : 'f';
- return 'W/"' . implode(':', array('AtomPubShowMembership',
- $this->_profile->id,
- $this->_group->id,
- $adminflag,
- $ctime)) . '"';
- }
- }
|