Selaa lähdekoodia

status json order; media url

master
Robin Thoni 10 vuotta sitten
vanhempi
commit
b35db813cb
2 muutettua tiedostoa jossa 13 lisäystä ja 7 poistoa
  1. 11
    6
      status.php
  2. 2
    1
      user.php

+ 11
- 6
status.php Näytä tiedosto

@@ -29,7 +29,7 @@ function status_create()
29 29
       && getimagesize($_FILES["media"]["tmp_name"]) !== false)
30 30
   {
31 31
     global $media_path;
32
-    $media = dechex(time());
32
+    $media = dechex(microtime());
33 33
     move_uploaded_file($_FILES["media"]["tmp_name"], $media_path . $media);
34 34
   }
35 35
 
@@ -48,11 +48,12 @@ function status_create()
48 48
   $date = new DateTime($s["date"]);
49 49
 
50 50
   echo json_encode(array("status" => $s["status"],
51
+    "user_id" => intval($u["id"]),
51 52
     "creation_date" => $date->format(DateTime::ISO8601),
52 53
     "latitude" => $s["latitude"] === null ? null : floatval($s["latitude"]),
53 54
     "longitude" => $s["longitude"] === null ? null : floatval($s["longitude"]),
54
-    "id" => intval($s["id"]),
55
-    "user_id" => intval($u["id"])
55
+    "media_url" => ($s["media"] !== null ) ? $media_url . $s["media"] : null,
56
+    "id" => intval($s["id"])
56 57
   ));
57 58
 }
58 59
 
@@ -69,12 +70,16 @@ function status_feed()
69 70
   global $media_url;
70 71
   while (($u = $s->fetch()) !== false)
71 72
   {
72
-    $date = new DateTime($u['date']);
73
-    $data[] = array("id" => intval($u["id"]), "status" => $u["status"],
73
+    $a = database_exec("SELECT `id`, `username` FROM users WHERE `id` = :id",
74
+      array(":id" => $u["user"]))->fetch();
75
+    $date = new DateTime($u["date"]);
76
+    $data[] = array("id" => intval($u["id"]),
77
+    "status" => $u["status"],
74 78
     "creation_date" => $date->format(DateTime::ISO8601),
75 79
     "latitude" => $u["latitude"] === null ? null : floatval($u["latitude"]),
76 80
     "longitude" => $u["longitude"] === null ? null : floatval($u["longitude"]),
77
-    "author_username" => "42",
81
+    "author_id" => intval($a["id"]),
82
+    "author_username" => $a["username"],
78 83
     "nb_confirm_up" => intval($u["up"]),
79 84
     "nb_confirm_down" => intval($u["down"]),
80 85
     "media_url" => ($u["media"] !== null ) ? $media_url . $u["media"] : null);

+ 2
- 1
user.php Näytä tiedosto

@@ -41,7 +41,8 @@ function user_login($username = false)
41 41
   $token = hash_password(uniqid(mt_rand(), true));
42 42
   database_exec("INSERT INTO tokens (`token`, `user`) VALUES (:token, :user)",
43 43
     array(":token" => $token, ":user" => $u['id']));
44
-  echo json_encode(array("username" => $username, "id" => intval($u["id"]),
44
+  echo json_encode(array("id" => intval($u["id"]),
45
+    "username" => $username,
45 46
     "token" => $token));
46 47
 }
47 48
 ?>

Loading…
Peruuta
Tallenna