1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- require_once "utils.php";
-
- function check_token()
- {
- $token = check_table_field("Authorization", "tokens", "token");
- if ($token === false)
- error(401, "Invalid token");
- return $token;
- }
-
- function status_confirm($id)
- {
- check_token();
- }
-
- function status_create()
- {
- $token = check_token();
- $status = get_post("status");
- if (strlen($status) < 10)
- error(422, "Status too short");
-
- $lat = check_float(get_post("latitude", false));
- $long = check_float(get_post("longitude", false));
- $media = null;
-
- $u = database_exec("SELECT `id`, `username` FROM users WHERE `id` = ".
- "(SELECT `user` FROM tokens WHERE `token` = :token)",
- array(":token" => $token))->fetch();
-
- database_exec("INSERT INTO status (`status`, `user`, `longitude`, ".
- "`latitude`, `media`) VALUES(:status, :user, :long, :lat, :media)",
- array(":status" => $status, ":user" => $u["id"], ":long" => $long,
- ":lat" => $lat, ":media" => $media));
-
- $s = database_exec("SELECT * FROM status WHERE id = :id",
- array(":id" => database_get()->lastInsertId()))->fetch();
-
- $date = new DateTime($s["date"]);
-
- echo json_encode(array("status" => $s["status"],
- "creation_date" => $date->format(DateTime::ISO8601),
- "latitude" => $s["latitude"] === null ? null : floatval($s["latitude"]),
- "longitude" => $s["longitude"] === null ? null : floatval($s["longitude"]),
- "id" => intval($s["id"]),
- "user_id" => intval($u["id"])
- ));
- }
-
- function status_feed()
- {
- check_token();
- $page = get_get("page", false);
- $limit = get_get("limit", false);
- $sdatabase_exec("SELECT * FROM status ORDER BY id DESC LIMIT :begin, :count",
- array(":begin" => intval(($page - 1) * $limit), ":count" => $limit));
- }
- ?>
|