gnu-social/plugins/Linkback/actions/webmention.php

74 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2015-10-22 18:18:20 +01:00
<?php
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET')) {
exit(1);
}
class WebmentionAction extends Action
{
protected function handle()
{
GNUsocial::setApi(true); // Minimize error messages to aid in debugging
parent::handle();
if ($this->isPost()) {
return $this->handlePost();
}
return false;
}
function handlePost()
{
$source = $this->arg('source');
$target = $this->arg('target');
header('Content-Type: text/plain; charset=utf-8');
if(!$source) {
echo _m('"source" is missing')."\n";
2016-06-10 22:01:23 +01:00
throw new ClientException(_m('"source" is missing'), 400);
2015-10-22 18:18:20 +01:00
}
if(!$target) {
echo _m('"target" is missing')."\n";
2016-06-10 22:01:23 +01:00
throw new ClientException(_m('"target" is missing'), 400);
2015-10-22 18:18:20 +01:00
}
$response = linkback_get_source($source, $target);
if(!$response) {
echo _m('Source does not link to target.')."\n";
2016-06-10 22:01:23 +01:00
throw new ClientException(_m('Source does not link to target.'), 400);
2015-10-22 18:18:20 +01:00
}
$notice = linkback_get_target($target);
if(!$notice) {
echo _m('Target not found')."\n";
2016-06-10 22:01:23 +01:00
throw new ClientException(_m('Target not found'), 404);
2015-10-22 18:18:20 +01:00
}
$url = linkback_save($source, $target, $response, $notice);
if(!$url) {
echo _m('An error occured while saving.')."\n";
2016-06-10 22:01:23 +01:00
throw new ClientException(_m('An error occured while saving.'), 500);
2015-10-22 18:18:20 +01:00
}
echo $url."\n";
return true;
}
}