backupaccount.php 2.9 KB

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