3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2010 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
37 require_once INSTALLDIR . '/lib/apiauth.php';
40 * Show a single subscription
44 * @author Evan Prodromou <evan@status.net>
45 * @copyright 2010 StatusNet, Inc.
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
47 * @link http://status.net/
50 class AtompubshowsubscriptionAction extends ApiAuthAction
52 private $_subscriber = null;
53 private $_subscribed = null;
54 private $_subscription = null;
57 * For initializing members of the class.
59 * @param array $argarray misc. arguments
61 * @return boolean true
64 function prepare($argarray)
66 parent::prepare($argarray);
67 $subscriberId = $this->trimmed('subscriber');
69 $this->_subscriber = Profile::staticGet('id', $subscriberId);
71 if (empty($this->_subscriber)) {
72 throw new ClientException(sprintf(_('No such profile id: %d'),
76 $subscribedId = $this->trimmed('subscribed');
78 $this->_subscribed = Profile::staticGet('id', $subscribedId);
80 if (empty($this->_subscribed)) {
81 throw new ClientException(sprintf(_('No such profile id: %d'),
85 $this->_subscription =
86 Subscription::pkeyGet(array('subscriber' => $subscriberId,
87 'subscribed' => $subscribedId));
89 if (empty($this->_subscription)) {
90 $msg = sprintf(_('Profile %d not subscribed to profile %d'),
91 $subscriberId, $subscribedId);
92 throw new ClientException($msg, 404);
101 * @param array $argarray is ignored since it's now passed in in prepare()
106 function handle($argarray=null)
108 parent::handle($argarray);
109 switch ($_SERVER['REQUEST_METHOD']) {
112 $this->showSubscription();
115 $this->deleteSubscription();
118 $this->clientError(_('HTTP method not supported.'), 405);
126 * Show the subscription in ActivityStreams Atom format.
131 function showSubscription()
133 $activity = $this->_subscription->asActivity();
135 header('Content-Type: application/atom+xml; charset=utf-8');
138 $this->raw($activity->asString(true, true, true));
145 * Delete the subscription
150 function deleteSubscription()
152 if (empty($this->auth_user) ||
153 $this->auth_user->id != $this->_subscriber->id) {
154 throw new ClientException(_("Can't delete someone else's".
155 " subscription"), 403);
158 Subscription::cancel($this->_subscriber,
165 * Is this action read only?
167 * @param array $args other arguments
169 * @return boolean true
172 function isReadOnly($args)
174 if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
182 * Return last modified, if applicable.
184 * @return string last modified http header
187 function lastModified()
189 return max(strtotime($this->_subscriber->modified),
190 strtotime($this->_subscribed->modified),
191 strtotime($this->_subscription->modified));
195 * Etag for this object
197 * @return string etag http header
202 $mtime = strtotime($this->_subscription->modified);
204 return 'W/"' . implode(':', array('AtomPubShowSubscription',
205 $this->_subscriber->id,
206 $this->_subscribed->id,
211 * Does this require authentication?
213 * @return boolean true if delete, else false
216 function requiresAuth()
218 if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {