12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class PingbackAction extends Action
- {
- protected function handle()
- {
- GNUsocial::setApi(true);
- parent::handle();
- if ($this->isPost()) {
- return $this->handlePost();
- }
- return false;
- }
- function handlePost()
- {
- $server = xmlrpc_server_create();
- xmlrpc_server_register_method($server, 'pingback.ping', array($this, 'ping'));
- echo xmlrpc_server_call_method($server, file_get_contents('php://input'), null, array('encoding' => 'utf-8'));
- xmlrpc_server_destroy($server);
- return true;
- }
- function ping($method, $parameters) {
- list($source, $target) = $parameters;
- if(!$source) {
- return array(
- 'faultCode' => 0x0010,
- 'faultString' => '"source" is missing'
- );
- }
- if(!$target) {
- return array(
- 'faultCode' => 0x0020,
- 'faultString' => '"target" is missing'
- );
- }
- $response = linkback_get_source($source, $target);
- if(!$response) {
- return array(
- 'faultCode' => 0x0011,
- 'faultString' => 'Source does not link to target'
- );
- }
- $notice = linkback_get_target($target);
- if(!$notice) {
- return array(
- 'faultCode' => 0x0021,
- 'faultString' => 'Target not found'
- );
- }
- $url = linkback_save($source, $target, $response, $notice);
- if(!$url) {
- return array(
- 'faultCode' => 0,
- 'faultString' => 'An error occured while saving.'
- );
- }
- return array('Success');
- }
- }
|