atompubaction.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /*
  3. * GNU social - a federating social network
  4. * Copyright (C) 2015, Free Software Foundation, Inc.
  5. * Copyright (C) before that, StatusNet, Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
  21. abstract class AtompubAction extends ApiAuthAction
  22. {
  23. protected function prepare(array $args=array())
  24. {
  25. parent::prepare($args);
  26. return $this->atompubPrepare();
  27. }
  28. protected function atompubPrepare() {
  29. return true;
  30. }
  31. protected function handle()
  32. {
  33. parent::handle();
  34. switch ($_SERVER['REQUEST_METHOD']) {
  35. case 'HEAD':
  36. $this->handleHead();
  37. break;
  38. case 'GET':
  39. $this->handleGet();
  40. break;
  41. case 'POST':
  42. $this->handlePost();
  43. break;
  44. case 'DELETE':
  45. $this->handleDelete();
  46. break;
  47. default:
  48. // TRANS: Client exception thrown when using an unsupported HTTP method.
  49. throw new ClientException(_('HTTP method not supported.'), 405);
  50. }
  51. return true;
  52. }
  53. protected function handleHead()
  54. {
  55. $this->handleGet();
  56. }
  57. protected function handleGet()
  58. {
  59. throw new ClientException(_('HTTP method not supported.'), 405);
  60. }
  61. protected function handlePost()
  62. {
  63. throw new ClientException(_('HTTP method not supported.'), 405);
  64. }
  65. protected function handleDelete()
  66. {
  67. throw new ClientException(_('HTTP method not supported.'), 405);
  68. }
  69. function isReadOnly($args)
  70. {
  71. // GET/HEAD is readonly, POST and DELETE (etc?) are readwrite.
  72. return in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD'));
  73. }
  74. function requiresAuth()
  75. {
  76. // GET/HEAD don't require auth, POST and DELETE (etc?) require it.
  77. return !in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD'));
  78. }
  79. }