3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * Show a single favorite in Atom Activity Streams format
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 favorite in Atom Activity Streams format.
42 * Can also be used to delete a favorite.
46 * @author Evan Prodromou <evan@status.net>
47 * @copyright 2010 StatusNet, Inc.
48 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
49 * @link http://status.net/
52 class AtompubshowfavoriteAction extends ApiAuthAction
54 private $_profile = null;
55 private $_notice = null;
56 private $_fave = null;
59 * For initializing members of the class.
61 * @param array $argarray misc. arguments
63 * @return boolean true
66 function prepare($argarray)
68 parent::prepare($argarray);
70 $profileId = $this->trimmed('profile');
71 $noticeId = $this->trimmed('notice');
73 $this->_profile = Profile::staticGet('id', $profileId);
75 if (empty($this->_profile)) {
76 throw new ClientException(_('No such profile.'), 404);
79 $this->_notice = Notice::staticGet('id', $noticeId);
81 if (empty($this->_notice)) {
82 throw new ClientException(_('No such notice.'), 404);
85 $this->_fave = Fave::pkeyGet(array('user_id' => $profileId,
86 'notice_id' => $noticeId));
88 if (empty($this->_fave)) {
89 throw new ClientException(_('No such favorite.'), 404);
98 * @param array $argarray is ignored since it's now passed in in prepare()
103 function handle($argarray=null)
105 parent::handle($argarray);
107 switch ($_SERVER['REQUEST_METHOD']) {
116 throw new ClientException(_('HTTP method not supported.'),
123 * Show a single favorite, in ActivityStreams format
130 $activity = $this->_fave->asActivity();
132 header('Content-Type: application/atom+xml; charset=utf-8');
135 $this->raw($activity->asString(true, true, true));
142 * Delete the favorite
147 function deleteFave()
149 if (empty($this->auth_user) ||
150 $this->auth_user->id != $this->_profile->id) {
151 throw new ClientException(_("Can't delete someone else's".
155 $this->_fave->delete();
161 * Return true if read only.
165 * @param array $args other arguments
167 * @return boolean is read only action?
170 function isReadOnly($args)
172 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
173 $_SERVER['REQUEST_METHOD'] == 'HEAD') {
181 * Return last modified, if applicable.
185 * @return string last modified http header
188 function lastModified()
190 return max(strtotime($this->_profile->modified),
191 strtotime($this->_notice->modified),
192 strtotime($this->_fave->modified));
196 * Return etag, if applicable.
200 * @return string etag http header
205 $mtime = strtotime($this->_fave->modified);
207 return 'W/"' . implode(':', array('AtomPubShowFavorite',
214 * Does this require authentication?
216 * @return boolean true if delete, else false
219 function requiresAuth()
221 if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
222 $_SERVER['REQUEST_METHOD'] == 'HEAD') {