3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * Download a backup of your own account to the browser
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.
38 * Download a backup of your own account to the browser
40 * We go through some hoops to make this only respond to POST, since
41 * it's kind of expensive and there's probably some downside to having
42 * your account in all kinds of search engines.
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 BackupaccountAction extends Action
55 * Returns the title of the page
57 * @return string page title
62 return _("Backup account");
66 * For initializing members of the class.
68 * @param array $argarray misc. arguments
70 * @return boolean true
73 function prepare($argarray)
75 parent::prepare($argarray);
77 $cur = common_current_user();
80 throw new ClientException(_('Only logged-in users can backup their account.'), 403);
83 if (!$cur->hasRight(Right::BACKUPACCOUNT)) {
84 throw new ClientException(_('You may not backup your account.'), 403);
93 * @param array $argarray is ignored since it's now passed in in prepare()
98 function handle($argarray=null)
100 parent::handle($argarray);
102 if ($this->isPost()) {
111 * Send a feed of the user's activities to the browser
113 * Uses the UserActivityStream class; may take a long time!
120 $cur = common_current_user();
122 $stream = new UserActivityStream($cur);
124 header('Content-Disposition: attachment; filename='.$cur->nickname.'.atom');
125 header('Content-Type: application/atom+xml; charset=utf-8');
127 $this->raw($stream->getString());
131 * Show a little form so that the person can request a backup.
136 function showContent()
138 $form = new BackupAccountForm($this);
143 * Return true if read only.
147 * @param array $args other arguments
149 * @return boolean is read only action?
152 function isReadOnly($args)
158 * Return last modified, if applicable.
162 * @return string last modified http header
165 function lastModified()
167 // For comparison with If-Last-Modified
168 // If not applicable, return null
173 * Return etag, if applicable.
177 * @return string etag http header
187 * A form for backing up the account.
191 * @author Evan Prodromou <evan@status.net>
192 * @copyright 2010 StatusNet, Inc.
193 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
194 * @link http://status.net/
197 class BackupAccountForm extends Form
202 * @return string the form's class
207 return 'form_profile_backup';
211 * URL the form posts to
213 * @return string the form's action URL
218 return common_local_url('backupaccount');
224 * Really, just instructions for doing a backup.
232 _('You can backup your account data in '.
233 '<a href="http://activitystrea.ms/">Activity Streams</a> '.
234 'format. This is an experimental feature and provides an '.
235 'incomplete backup; private account '.
236 'information like email and IM addresses is not backed up. '.
237 'Additionally, uploaded files and direct messages are not '.
239 $this->out->elementStart('p');
240 $this->out->raw($msg);
241 $this->out->elementEnd('p');
245 * Buttons for the form
247 * In this case, a single submit button
252 function formActions()
254 $this->out->submit('submit',
255 _m('BUTTON', 'Backup'),
258 _('Backup your account'));