]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/atompubaction.php
Introduced common_location_shared() to check if location sharing is always,
[quix0rs-gnu-social.git] / lib / atompubaction.php
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
21 if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
22
23 abstract class AtompubAction extends ApiAuthAction
24 {
25     protected function prepare(array $args=array())
26     {
27         parent::prepare($args);
28
29         return $this->atompubPrepare();
30     }
31
32     protected function atompubPrepare() {
33         return true;
34     }
35
36     protected function handle()
37     {
38         parent::handle();
39
40         switch ($_SERVER['REQUEST_METHOD']) {
41         case 'HEAD':
42             $this->handleHead();
43             break;
44         case 'GET':
45             $this->handleGet();
46             break;
47         case 'POST':
48             $this->handlePost();
49             break;
50         case 'DELETE':
51             $this->handleDelete();
52             break;
53         default:
54             // TRANS: Client exception thrown when using an unsupported HTTP method.
55             throw new ClientException(_('HTTP method not supported.'), 405);
56         }
57
58         return true;
59     }
60
61     protected function handleHead()
62     {
63         $this->handleGet();
64     }
65
66     protected function handleGet()
67     {
68         throw new ClientException(_('HTTP method not supported.'), 405);
69     }
70
71     protected function handlePost()
72     {
73         throw new ClientException(_('HTTP method not supported.'), 405);
74     }
75
76     protected function handleDelete()
77     {
78         throw new ClientException(_('HTTP method not supported.'), 405);
79     }
80
81     function isReadOnly($args)
82     {
83         // GET/HEAD is readonly, POST and DELETE (etc?) are readwrite.
84         return in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD'));
85     }
86
87     function requiresAuth()
88     {
89         // GET/HEAD don't require auth, POST and DELETE (etc?) require it.
90         return !in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD'));
91     }
92 }