12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- require_once "utils.php";
- require_once "misc/config.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;
- if (isset($_FILES["media"])
- && getimagesize($_FILES["media"]["tmp_name"]) !== false)
- {
- global $media_path;
- $media = $media_path . dechex(time());
- move_uploaded_file($_FILES["media"]["tmp_name"], $media);
- }
-
- $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));
- }
- ?>
|