]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Linkback/actions/pingback.php
Merge branch 'foolproof_file_redirection_branch' into 'nightly'
[quix0rs-gnu-social.git] / plugins / Linkback / actions / pingback.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 PingbackAction 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
37         $server = xmlrpc_server_create();
38         xmlrpc_server_register_method($server, 'pingback.ping', array($this, 'ping'));
39         echo xmlrpc_server_call_method($server, file_get_contents('php://input'), null, array('encoding' => 'utf-8'));
40         xmlrpc_server_destroy($server);
41         return true;
42     }
43
44     function ping($method, $parameters) {
45         list($source, $target) = $parameters;
46
47         if(!$source) {
48             return array(
49                 'faultCode' => 0x0010,
50                 'faultString' => '"source" is missing'
51             );
52         }
53
54         if(!$target) {
55             return array(
56                 'faultCode' => 0x0020,
57                 'faultString' => '"target" is missing'
58             );
59         }
60
61         $response = linkback_get_source($source, $target);
62         if(!$response) {
63             return array(
64                 'faultCode' => 0x0011,
65                 'faultString' => 'Source does not link to target'
66             );
67         }
68
69         $notice = linkback_get_target($target);
70         if(!$notice) {
71             return array(
72                 'faultCode' => 0x0021,
73                 'faultString' => 'Target not found'
74             );
75         }
76
77         $url = linkback_save($source, $target, $response, $notice);
78         if(!$url) {
79             return array(
80                 'faultCode' => 0,
81                 'faultString' => 'An error occured while saving.'
82             );
83         }
84
85         return array('Success');
86     }
87 }