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/
51 class BackupaccountAction extends Action
54 * Returns the title of the page
56 * @return string page title
60 // TRANS: Title for backup account page.
61 return _("Backup account");
65 * For initializing members of the class.
67 * @param array $argarray misc. arguments
69 * @return boolean true
71 function prepare($argarray)
73 parent::prepare($argarray);
75 $cur = common_current_user();
78 // TRANS: Client exception thrown when trying to backup an account while not logged in.
79 throw new ClientException(_('Only logged-in users can backup their account.'), 403);
82 if (!$cur->hasRight(Right::BACKUPACCOUNT)) {
83 // TRANS: Client exception thrown when trying to backup an account without having backup rights.
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()
97 function handle($argarray=null)
99 parent::handle($argarray);
101 if ($this->isPost()) {
110 * Send a feed of the user's activities to the browser
112 * Uses the UserActivityStream class; may take a long time!
119 $cur = common_current_user();
121 $stream = new UserActivityStream($cur);
123 header('Content-Disposition: attachment; filename='.$cur->nickname.'.atom');
124 header('Content-Type: application/atom+xml; charset=utf-8');
126 $this->raw($stream->getString());
130 * Show a little form so that the person can request a backup.
135 function showContent()
137 $form = new BackupAccountForm($this);
142 * Return true if read only.
146 * @param array $args other arguments
148 * @return boolean is read only action?
150 function isReadOnly($args)
156 * Return last modified, if applicable.
160 * @return string last modified http header
162 function lastModified()
164 // For comparison with If-Last-Modified
165 // If not applicable, return null
170 * Return etag, if applicable.
174 * @return string etag http header
183 * A form for backing up the account.
187 * @author Evan Prodromou <evan@status.net>
188 * @copyright 2010 StatusNet, Inc.
189 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
190 * @link http://status.net/
192 class BackupAccountForm extends Form
197 * @return string the form's class
201 return 'form_profile_backup';
205 * URL the form posts to
207 * @return string the form's action URL
211 return common_local_url('backupaccount');
217 * Really, just instructions for doing a backup.
224 // TRANS: Information displayed on the backup account page.
225 _('You can backup your account data in '.
226 '<a href="http://activitystrea.ms/">Activity Streams</a> '.
227 'format. This is an experimental feature and provides an '.
228 'incomplete backup; private account '.
229 'information like email and IM addresses is not backed up. '.
230 'Additionally, uploaded files and direct messages are not '.
232 $this->out->elementStart('p');
233 $this->out->raw($msg);
234 $this->out->elementEnd('p');
238 * Buttons for the form
240 * In this case, a single submit button
244 function formActions()
246 $this->out->submit('submit',
247 // TRANS: Submit button to backup an account on the backup account page.
248 _m('BUTTON', 'Backup'),
251 // TRANS: Title for submit button to backup an account on the backup account page.
252 _('Backup your account'));