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.9KB

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