Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

get.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. require_once('config.php');
  3. $target_url = $_POST['target'];
  4. if (!isset($target_url)) {
  5. header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
  6. exit;
  7. }
  8. $dsn = 'mysql:dbname=' . $config['db']['name'] . ';host=' . $config['db']['host'];
  9. $user = $config['db']['username'];
  10. $password = $config['db']['password'];
  11. try {
  12. $dbh = new PDO($dsn, $user, $password);
  13. } catch (PDOException $e) {
  14. error_log('Connection failed: ' . $e->getMessage(), 4);
  15. exit('Err');
  16. }
  17. $sth = $dbh->prepare('SELECT * FROM webmentions WHERE local_url = ? ORDER BY published');
  18. if ($sth === false) {
  19. error_log('Could not prepare SQL statement.');
  20. error_log('Error code: ' . $dbh->errorCode());
  21. error_log('Error info: ' . $dbh->errorInfo());
  22. }
  23. $res = $sth->execute(array($target_url));
  24. if ($res === false) {
  25. error_log('Could not execute SQL query.');
  26. error_log('Error code: ' . $dbh->errorCode());
  27. error_log('Error info: ' . $dbh->errorInfo());
  28. }
  29. $data = array(
  30. 'likes' => array(),
  31. 'mentions' => array(),
  32. 'replies'=> array(),
  33. 'reposts' => array(),
  34. 'rsvps' => array()
  35. );
  36. while ($row = $sth->fetch()) {
  37. switch($row['type']) {
  38. case "like":
  39. $data['likes'][] = $row;
  40. break;
  41. case "reply":
  42. $data['replies'][] = $row;
  43. break;
  44. case "repost":
  45. $data['reposts'][] = $row;
  46. break;
  47. case "rsvp":
  48. $data['rsvps'][] = $row;
  49. break;
  50. default:
  51. $data['mentions'][] = $row;
  52. break;
  53. }
  54. }
  55. $json = json_encode($data);
  56. if ($json === false) {
  57. header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
  58. exit;
  59. } else {
  60. header('Content-Type: application/json');
  61. echo $json;
  62. }