123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
- class AtompubshowsubscriptionAction extends AtompubAction
- {
- private $_subscriber = null;
- private $_subscribed = null;
- private $_subscription = null;
- protected function atompubPrepare()
- {
- $subscriberId = $this->trimmed('subscriber');
- $this->_subscriber = Profile::getKV('id', $subscriberId);
- if (!$this->_subscriber instanceof Profile) {
-
-
- throw new ClientException(sprintf(_('No such profile id: %d.'),
- $subscriberId), 404);
- }
- $subscribedId = $this->trimmed('subscribed');
- $this->_subscribed = Profile::getKV('id', $subscribedId);
- if (!$this->_subscribed instanceof Profile) {
-
-
- throw new ClientException(sprintf(_('No such profile id: %d.'),
- $subscribedId), 404);
- }
- $this->_subscription = Subscription::pkeyGet(array('subscriber' => $subscriberId,
- 'subscribed' => $subscribedId));
- if (!$this->_subscription instanceof Subscription) {
-
-
- $msg = sprintf(_('Profile %1$d not subscribed to profile %2$d.'),
- $subscriberId, $subscribedId);
- throw new ClientException($msg, 404);
- }
- return true;
- }
- protected function handleGet()
- {
- $this->showSubscription();
- }
- protected function handleDelete()
- {
- $this->deleteSubscription();
- }
-
- function showSubscription()
- {
- $activity = $this->_subscription->asActivity();
- header('Content-Type: application/atom+xml; charset=utf-8');
- $this->startXML();
- $this->raw($activity->asString(true, true, true));
- $this->endXML();
- }
-
- function deleteSubscription()
- {
- if (!$this->scoped instanceof Profile ||
- $this->scoped->id != $this->_subscriber->id) {
-
- throw new ClientException(_("Cannot delete someone else's subscription."), 403);
- }
- Subscription::cancel($this->_subscriber, $this->_subscribed);
- }
-
- function isReadOnly($args)
- {
- if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
- return false;
- }
- return true;
- }
-
- function lastModified()
- {
- return max(strtotime($this->_subscriber->modified),
- strtotime($this->_subscribed->modified),
- strtotime($this->_subscription->modified));
- }
-
- function etag()
- {
- $mtime = strtotime($this->_subscription->modified);
- return 'W/"' . implode(':', array('AtomPubShowSubscription',
- $this->_subscriber->id,
- $this->_subscribed->id,
- $mtime)) . '"';
- }
-
- function requiresAuth()
- {
- if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
- return true;
- } else {
- return false;
- }
- }
- }
|