]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Linkback/actions/webmention.php
Merge branch 'foolproof_file_redirection_branch' into 'nightly'
[quix0rs-gnu-social.git] / plugins / Linkback / actions / webmention.php
1 <?php
2 /*
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU Affero General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU Affero General Public License for more details.
12  *
13  * You should have received a copy of the GNU Affero General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16
17 if (!defined('STATUSNET')) {
18     exit(1);
19 }
20
21 class WebmentionAction extends Action
22 {
23     protected function handle()
24     {
25         GNUsocial::setApi(true); // Minimize error messages to aid in debugging
26         parent::handle();
27         if ($this->isPost()) {
28             return $this->handlePost();
29         }
30
31         return false;
32     }
33
34     function handlePost()
35     {
36         $source = $this->arg('source');
37         $target = $this->arg('target');
38
39         header('Content-Type: text/plain; charset=utf-8');
40
41         if(!$source) {
42             echo _m('"source" is missing')."\n";
43             throw new ServerException(_m('"source" is missing'), 400);
44         }
45
46         if(!$target) {
47             echo _m('"target" is missing')."\n";
48             throw new ServerException(_m('"target" is missing'), 400);
49         }
50
51         $response = linkback_get_source($source, $target);
52         if(!$response) {
53             echo _m('Source does not link to target.')."\n";
54             throw new ServerException(_m('Source does not link to target.'), 400);
55         }
56
57         $notice = linkback_get_target($target);
58         if(!$notice) {
59             echo _m('Target not found')."\n";
60             throw new ServerException(_m('Target not found'), 404);
61         }
62
63         $url = linkback_save($source, $target, $response, $notice);
64         if(!$url) {
65             echo _m('An error occured while saving.')."\n";
66             throw new ServerException(_m('An error occured while saving.'), 500);
67         }
68
69         echo $url."\n";
70
71         return true;
72     }
73 }