]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/backupaccount.php
Merge branch 'master' into 0.9.x
[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
52 class BackupaccountAction extends Action
53 {
54     /**
55      * Returns the title of the page
56      * 
57      * @return string page title
58      */
59
60     function title()
61     {
62         return _("Backup account");
63     }
64
65     /**
66      * For initializing members of the class.
67      *
68      * @param array $argarray misc. arguments
69      *
70      * @return boolean true
71      */
72
73     function prepare($argarray)
74     {
75         parent::prepare($argarray);
76
77         $cur = common_current_user();
78
79         if (empty($cur)) {
80             throw new ClientException(_('Only logged-in users can backup their account.'), 403);
81         }
82
83         if (!$cur->hasRight(Right::BACKUPACCOUNT)) {
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
98     function handle($argarray=null)
99     {
100         parent::handle($argarray);
101
102         if ($this->isPost()) {
103             $this->sendFeed();
104         } else {
105             $this->showPage();
106         }
107         return;
108     }
109
110     /**
111      * Send a feed of the user's activities to the browser
112      * 
113      * Uses the UserActivityStream class; may take a long time!
114      *
115      * @return void
116      */
117
118     function sendFeed()
119     {
120         $cur = common_current_user();
121         
122         $stream = new UserActivityStream($cur);
123
124         header('Content-Disposition: attachment; filename='.$cur->nickname.'.atom');
125         header('Content-Type: application/atom+xml; charset=utf-8');
126
127         $this->raw($stream->getString());
128     }
129
130     /**
131      * Show a little form so that the person can request a backup.
132      *
133      * @return void
134      */
135     
136     function showContent()
137     {
138         $form = new BackupAccountForm($this);
139         $form->show();
140     }
141  
142     /**
143      * Return true if read only.
144      *
145      * MAY override
146      *
147      * @param array $args other arguments
148      *
149      * @return boolean is read only action?
150      */
151
152     function isReadOnly($args)
153     {
154         return false;
155     }
156
157     /**
158      * Return last modified, if applicable.
159      *
160      * MAY override
161      *
162      * @return string last modified http header
163      */
164
165     function lastModified()
166     {
167         // For comparison with If-Last-Modified
168         // If not applicable, return null
169         return null;
170     }
171
172     /**
173      * Return etag, if applicable.
174      *
175      * MAY override
176      *
177      * @return string etag http header
178      */
179
180     function etag()
181     {
182         return null;
183     }
184 }
185
186 /**
187  * A form for backing up the account.
188  *
189  * @category  Account
190  * @package   StatusNet
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/
195  */
196
197 class BackupAccountForm extends Form
198 {
199     /**
200      * Class of the form.
201      *
202      * @return string the form's class
203      */
204
205     function formClass()
206     {
207         return 'form_profile_backup';
208     }
209
210     /**
211      * URL the form posts to
212      *
213      * @return string the form's action URL
214      */
215
216     function action()
217     {
218         return common_local_url('backupaccount');
219     }
220
221     /**
222      * Output form data
223      * 
224      * Really, just instructions for doing a backup.
225      *
226      * @return void
227      */
228
229     function formData()
230     {
231         $msg =
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 '.
238               'backed up.');
239         $this->out->elementStart('p');
240         $this->out->raw($msg);
241         $this->out->elementEnd('p');
242     }
243
244     /**
245      * Buttons for the form
246      * 
247      * In this case, a single submit button
248      *
249      * @return void
250      */
251
252     function formActions()
253     {
254         $this->out->submit('submit',
255                            _m('BUTTON', 'Backup'),
256                            'submit',
257                            null,
258                            _('Backup your account'));
259     }
260 }