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