]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/backupaccount.php
Handle selfLink in ActivityObject
[quix0rs-gnu-social.git] / actions / backupaccount.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * Download a backup of your own account to the browser
7  *
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Account
24  * @package   StatusNet
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/
29  */
30
31 if (!defined('GNUSOCIAL')) { exit(1); }
32
33 /**
34  * Download a backup of your own account to the browser
35  *
36  * We go through some hoops to make this only respond to POST, since
37  * it's kind of expensive and there's probably some downside to having
38  * your account in all kinds of search engines.
39  *
40  * @category  Account
41  * @package   StatusNet
42  * @author    Evan Prodromou <evan@status.net>
43  * @copyright 2010 StatusNet, Inc.
44  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45  * @link      http://status.net/
46  */
47 class BackupaccountAction extends FormAction
48 {
49     protected $form = 'BackupAccount';
50
51     function title()
52     {
53         // TRANS: Title for backup account page.
54         return _('Backup account');
55     }
56
57     protected function doPreparation()
58     {
59         if (!$this->scoped->hasRight(Right::BACKUPACCOUNT)) {
60             // TRANS: Client exception thrown when trying to backup an account without having backup rights.
61             throw new ClientException(_('You may not backup your account.'), 403);
62         }
63
64         return true;
65     }
66
67     protected function doPost()
68     {
69         $stream = new UserActivityStream($this->scoped->getUser(), true, UserActivityStream::OUTPUT_RAW);
70
71         header('Content-Disposition: attachment; filename='.urlencode($this->scoped->getNickname()).'.atom');
72         header('Content-Type: application/atom+xml; charset=utf-8');
73
74         // @fixme atom feed logic is in getString...
75         // but we just want it to output to the outputter.
76         $this->raw($stream->getString());
77     }
78
79     public function isReadOnly($args) {
80         return true;
81     }
82
83     function lastModified()
84     {
85         // For comparison with If-Last-Modified
86         // If not applicable, return null
87         return null;
88     }
89
90     function etag()
91     {
92         return null;
93     }
94 }