pingback.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. if (!defined('STATUSNET')) {
  17. exit(1);
  18. }
  19. class PingbackAction extends Action
  20. {
  21. protected function handle()
  22. {
  23. GNUsocial::setApi(true); // Minimize error messages to aid in debugging
  24. parent::handle();
  25. if ($this->isPost()) {
  26. return $this->handlePost();
  27. }
  28. return false;
  29. }
  30. function handlePost()
  31. {
  32. $server = xmlrpc_server_create();
  33. xmlrpc_server_register_method($server, 'pingback.ping', array($this, 'ping'));
  34. echo xmlrpc_server_call_method($server, file_get_contents('php://input'), null, array('encoding' => 'utf-8'));
  35. xmlrpc_server_destroy($server);
  36. return true;
  37. }
  38. function ping($method, $parameters) {
  39. list($source, $target) = $parameters;
  40. if(!$source) {
  41. return array(
  42. 'faultCode' => 0x0010,
  43. 'faultString' => '"source" is missing'
  44. );
  45. }
  46. if(!$target) {
  47. return array(
  48. 'faultCode' => 0x0020,
  49. 'faultString' => '"target" is missing'
  50. );
  51. }
  52. $response = linkback_get_source($source, $target);
  53. if(!$response) {
  54. return array(
  55. 'faultCode' => 0x0011,
  56. 'faultString' => 'Source does not link to target'
  57. );
  58. }
  59. $notice = linkback_get_target($target);
  60. if(!$notice) {
  61. return array(
  62. 'faultCode' => 0x0021,
  63. 'faultString' => 'Target not found'
  64. );
  65. }
  66. $url = linkback_save($source, $target, $response, $notice);
  67. if(!$url) {
  68. return array(
  69. 'faultCode' => 0,
  70. 'faultString' => 'An error occured while saving.'
  71. );
  72. }
  73. return array('Success');
  74. }
  75. }