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.

status.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. require_once "utils.php";
  3. function check_token()
  4. {
  5. $token = check_table_field("Authorization", "tokens", "token");
  6. if ($token === false)
  7. error(401, "Invalid token");
  8. return $token;
  9. }
  10. function status_confirm($id)
  11. {
  12. check_token();
  13. }
  14. function status_create()
  15. {
  16. $token = check_token();
  17. $status = get_post("status");
  18. if (strlen($status) < 10)
  19. error(422, "Status too short");
  20. $lat = check_float(get_post("latitude", false));
  21. $long = check_float(get_post("longitude", false));
  22. $media = null;
  23. $u = database_exec("SELECT `id`, `username` FROM users WHERE `id` = ".
  24. "(SELECT `user` FROM tokens WHERE `token` = :token)",
  25. array(":token" => $token))->fetch();
  26. database_exec("INSERT INTO status (`status`, `user`, `longitude`, ".
  27. "`latitude`, `media`) VALUES(:status, :user, :long, :lat, :media)",
  28. array(":status" => $status, ":user" => $u["id"], ":long" => $long,
  29. ":lat" => $lat, ":media" => $media));
  30. $s = database_exec("SELECT * FROM status WHERE id = :id",
  31. array(":id" => database_get()->lastInsertId()))->fetch();
  32. $date = new DateTime($s["date"]);
  33. echo json_encode(array("status" => $s["status"],
  34. "creation_date" => $date->format(DateTime::ISO8601),
  35. "latitude" => $s["latitude"] === null ? null : floatval($s["latitude"]),
  36. "longitude" => $s["longitude"] === null ? null : floatval($s["longitude"]),
  37. "id" => intval($s["id"]),
  38. "user_id" => intval($u["id"])
  39. ));
  40. }
  41. function status_feed()
  42. {
  43. check_token();
  44. $page = get_get("page", false);
  45. $limit = get_get("limit", false);
  46. $sdatabase_exec("SELECT * FROM status ORDER BY id DESC LIMIT :begin, :count",
  47. array(":begin" => intval(($page - 1) * $limit), ":count" => $limit));
  48. }
  49. ?>