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, true, UserActivityStream::OUTPUT_RAW);
123 header('Content-Disposition: attachment; filename='.$cur->nickname.'.atom');
124 header('Content-Type: application/atom+xml; charset=utf-8');
126 // @fixme atom feed logic is in getString...
127 // but we just want it to output to the outputter.
128 $this->raw($stream->getString());
132 * Show a little form so that the person can request a backup.
137 function showContent()
139 $form = new BackupAccountForm($this);
144 * Return true if read only.
148 * @param array $args other arguments
150 * @return boolean is read only action?
152 function isReadOnly(array $args=array())
158 * Return last modified, if applicable.
162 * @return string last modified http header
164 function lastModified()
166 // For comparison with If-Last-Modified
167 // If not applicable, return null
172 * Return etag, if applicable.
176 * @return string etag http header
185 * A form for backing up the account.
189 * @author Evan Prodromou <evan@status.net>
190 * @copyright 2010 StatusNet, Inc.
191 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
192 * @link http://status.net/
194 class BackupAccountForm extends Form
199 * @return string the form's class
203 return 'form_profile_backup';
207 * URL the form posts to
209 * @return string the form's action URL
213 return common_local_url('backupaccount');
219 * Really, just instructions for doing a backup.
226 // TRANS: Information displayed on the backup account page.
227 _('You can backup your account data in '.
228 '<a href="http://activitystrea.ms/">Activity Streams</a> '.
229 'format. This is an experimental feature and provides an '.
230 'incomplete backup; private account '.
231 'information like email and IM addresses is not backed up. '.
232 'Additionally, uploaded files and direct messages are not '.
234 $this->out->elementStart('p');
235 $this->out->raw($msg);
236 $this->out->elementEnd('p');
240 * Buttons for the form
242 * In this case, a single submit button
246 function formActions()
248 $this->out->submit('submit',
249 // TRANS: Submit button to backup an account on the backup account page.
250 _m('BUTTON', 'Backup'),
253 // TRANS: Title for submit button to backup an account on the backup account page.
254 _('Backup your account.'));