Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

status.php 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. $date = new DateTime($token["date"]);
  8. $date->add(new DateInterval("P1D"));
  9. if ($token === false || $date < new DateTime())
  10. error(401, "Invalid token");
  11. return $token['token'];
  12. }
  13. function status_confirm($id)
  14. {
  15. check_token();
  16. }
  17. function status_create()
  18. {
  19. $token = check_token();
  20. $status = get_post("status");
  21. if (strlen($status) < 10)
  22. error(422, "Status too short");
  23. $lat = check_float(get_post("latitude", false));
  24. $long = check_float(get_post("longitude", false));
  25. $media = null;
  26. if (isset($_FILES["media"])
  27. && getimagesize($_FILES["media"]["tmp_name"]) !== false)
  28. {
  29. global $media_path;
  30. $media = dechex(microtime(true)) . dechex(rand());
  31. move_uploaded_file($_FILES["media"]["tmp_name"], $media_path . $media);
  32. }
  33. $u = database_exec("SELECT `id`, `username` FROM users WHERE `id` = ".
  34. "(SELECT `user` FROM tokens WHERE `token` = :token)",
  35. array(":token" => $token))->fetch();
  36. database_exec("INSERT INTO status (`status`, `user`, `longitude`, ".
  37. "`latitude`, `media`) VALUES(:status, :user, :long, :lat, :media)",
  38. array(":status" => $status, ":user" => $u["id"], ":long" => $long,
  39. ":lat" => $lat, ":media" => $media));
  40. $s = database_exec("SELECT * FROM status WHERE id = :id",
  41. array(":id" => database_get()->lastInsertId()))->fetch();
  42. $date = new DateTime($s["date"]);
  43. global $media_url;
  44. echo json_encode(array("status" => $s["status"],
  45. "user_id" => intval($u["id"]),
  46. "creation_date" => $date->format(DateTime::ISO8601),
  47. "latitude" => $s["latitude"] === null ? null : floatval($s["latitude"]),
  48. "longitude" => $s["longitude"] === null ? null : floatval($s["longitude"]),
  49. "media_url" => ($s["media"] !== null ) ? $media_url . $s["media"] : null,
  50. "id" => intval($s["id"])
  51. ));
  52. }
  53. function status_feed()
  54. {
  55. check_token();
  56. $limit = check_int(get_get("limit", false), 15);
  57. if ($limit < 1)
  58. $limit = 15;
  59. $page = max((check_int(get_get("page", false), 1) - 1), 0) * $limit;
  60. $s = database_query("SELECT * FROM status ORDER BY `id` DESC ".
  61. "LIMIT $page, $limit");
  62. $data = array();
  63. global $media_url;
  64. while (($u = $s->fetch()) !== false)
  65. {
  66. $a = database_exec("SELECT `id`, `username` FROM users WHERE `id` = :id",
  67. array(":id" => $u["user"]))->fetch();
  68. $date = new DateTime($u["date"]);
  69. $data[] = array("id" => intval($u["id"]),
  70. "status" => $u["status"],
  71. "creation_date" => $date->format(DateTime::ISO8601),
  72. "latitude" => $u["latitude"] === null ? null : floatval($u["latitude"]),
  73. "longitude" => $u["longitude"] === null ? null : floatval($u["longitude"]),
  74. "author_id" => intval($a["id"]),
  75. "author_username" => $a["username"],
  76. "nb_confirm_up" => intval($u["up"]),
  77. "nb_confirm_down" => intval($u["down"]),
  78. "media_url" => ($u["media"] !== null ) ? $media_url . $u["media"] : null);
  79. }
  80. echo json_encode($data);
  81. }
  82. ?>