]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/backupaccount.php
* improve L10n consistency for English. For example proper punctuation for all button...
[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('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Download a backup of your own account to the browser
39  *
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.
43  *
44  * @category  Account
45  * @package   StatusNet
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/
50  */
51 class BackupaccountAction extends Action
52 {
53     /**
54      * Returns the title of the page
55      *
56      * @return string page title
57      */
58     function title()
59     {
60         // TRANS: Title for backup account page.
61         return _('Backup account');
62     }
63
64     /**
65      * For initializing members of the class.
66      *
67      * @param array $argarray misc. arguments
68      *
69      * @return boolean true
70      */
71     function prepare($argarray)
72     {
73         parent::prepare($argarray);
74
75         $cur = common_current_user();
76
77         if (empty($cur)) {
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);
80         }
81
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);
85         }
86
87         return true;
88     }
89
90     /**
91      * Handler method
92      *
93      * @param array $argarray is ignored since it's now passed in in prepare()
94      *
95      * @return void
96      */
97     function handle($argarray=null)
98     {
99         parent::handle($argarray);
100
101         if ($this->isPost()) {
102             $this->sendFeed();
103         } else {
104             $this->showPage();
105         }
106         return;
107     }
108
109     /**
110      * Send a feed of the user's activities to the browser
111      *
112      * Uses the UserActivityStream class; may take a long time!
113      *
114      * @return void
115      */
116
117     function sendFeed()
118     {
119         $cur = common_current_user();
120
121         $stream = new UserActivityStream($cur);
122
123         header('Content-Disposition: attachment; filename='.$cur->nickname.'.atom');
124         header('Content-Type: application/atom+xml; charset=utf-8');
125
126         $this->raw($stream->getString());
127     }
128
129     /**
130      * Show a little form so that the person can request a backup.
131      *
132      * @return void
133      */
134
135     function showContent()
136     {
137         $form = new BackupAccountForm($this);
138         $form->show();
139     }
140
141     /**
142      * Return true if read only.
143      *
144      * MAY override
145      *
146      * @param array $args other arguments
147      *
148      * @return boolean is read only action?
149      */
150     function isReadOnly($args)
151     {
152         return true;
153     }
154
155     /**
156      * Return last modified, if applicable.
157      *
158      * MAY override
159      *
160      * @return string last modified http header
161      */
162     function lastModified()
163     {
164         // For comparison with If-Last-Modified
165         // If not applicable, return null
166         return null;
167     }
168
169     /**
170      * Return etag, if applicable.
171      *
172      * MAY override
173      *
174      * @return string etag http header
175      */
176     function etag()
177     {
178         return null;
179     }
180 }
181
182 /**
183  * A form for backing up the account.
184  *
185  * @category  Account
186  * @package   StatusNet
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/
191  */
192 class BackupAccountForm extends Form
193 {
194     /**
195      * Class of the form.
196      *
197      * @return string the form's class
198      */
199     function formClass()
200     {
201         return 'form_profile_backup';
202     }
203
204     /**
205      * URL the form posts to
206      *
207      * @return string the form's action URL
208      */
209     function action()
210     {
211         return common_local_url('backupaccount');
212     }
213
214     /**
215      * Output form data
216      *
217      * Really, just instructions for doing a backup.
218      *
219      * @return void
220      */
221     function formData()
222     {
223         $msg =
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 '.
231               'backed up.');
232         $this->out->elementStart('p');
233         $this->out->raw($msg);
234         $this->out->elementEnd('p');
235     }
236
237     /**
238      * Buttons for the form
239      *
240      * In this case, a single submit button
241      *
242      * @return void
243      */
244     function formActions()
245     {
246         $this->out->submit('submit',
247                            // TRANS: Submit button to backup an account on the backup account page.
248                            _m('BUTTON', 'Backup'),
249                            'submit',
250                            null,
251                            // TRANS: Title for submit button to backup an account on the backup account page.
252                            _('Backup your account.'));
253     }
254 }