You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

79 lines
1.7 KiB

<?php
require_once('config.php');
$target_url = $_POST['target'];
if (!isset($target_url)) {
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
exit;
}
$dsn = 'mysql:dbname=' . $config['db']['name'] . ';host=' . $config['db']['host'];
$user = $config['db']['username'];
$password = $config['db']['password'];
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
error_log('Connection failed: ' . $e->getMessage(), 4);
exit('Err');
}
$sth = $dbh->prepare('SELECT * FROM webmentions WHERE local_url = ? ORDER BY published');
if ($sth === false) {
error_log('Could not prepare SQL statement.');
error_log('Error code: ' . $dbh->errorCode());
error_log('Error info: ' . $dbh->errorInfo());
}
$res = $sth->execute(array($target_url));
if ($res === false) {
error_log('Could not execute SQL query.');
error_log('Error code: ' . $dbh->errorCode());
error_log('Error info: ' . $dbh->errorInfo());
}
$data = array(
'likes' => array(),
'mentions' => array(),
'replies'=> array(),
'reposts' => array(),
'rsvps' => array()
);
while ($row = $sth->fetch()) {
switch($row['type']) {
case "like":
$data['likes'][] = $row;
break;
case "reply":
$data['replies'][] = $row;
break;
case "repost":
$data['reposts'][] = $row;
break;
case "rsvp":
$data['rsvps'][] = $row;
break;
default:
$data['mentions'][] = $row;
break;
}
}
$json = json_encode($data);
if ($json === false) {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
exit;
} else {
header('Content-Type: application/json');
echo $json;
}