Browse Source

status json order; media url

master
Robin Thoni 10 years ago
parent
commit
b35db813cb
2 changed files with 13 additions and 7 deletions
  1. 11
    6
      status.php
  2. 2
    1
      user.php

+ 11
- 6
status.php View File

29
       && getimagesize($_FILES["media"]["tmp_name"]) !== false)
29
       && getimagesize($_FILES["media"]["tmp_name"]) !== false)
30
   {
30
   {
31
     global $media_path;
31
     global $media_path;
32
-    $media = dechex(time());
32
+    $media = dechex(microtime());
33
     move_uploaded_file($_FILES["media"]["tmp_name"], $media_path . $media);
33
     move_uploaded_file($_FILES["media"]["tmp_name"], $media_path . $media);
34
   }
34
   }
35
 
35
 
48
   $date = new DateTime($s["date"]);
48
   $date = new DateTime($s["date"]);
49
 
49
 
50
   echo json_encode(array("status" => $s["status"],
50
   echo json_encode(array("status" => $s["status"],
51
+    "user_id" => intval($u["id"]),
51
     "creation_date" => $date->format(DateTime::ISO8601),
52
     "creation_date" => $date->format(DateTime::ISO8601),
52
     "latitude" => $s["latitude"] === null ? null : floatval($s["latitude"]),
53
     "latitude" => $s["latitude"] === null ? null : floatval($s["latitude"]),
53
     "longitude" => $s["longitude"] === null ? null : floatval($s["longitude"]),
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
   global $media_url;
70
   global $media_url;
70
   while (($u = $s->fetch()) !== false)
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
     "creation_date" => $date->format(DateTime::ISO8601),
78
     "creation_date" => $date->format(DateTime::ISO8601),
75
     "latitude" => $u["latitude"] === null ? null : floatval($u["latitude"]),
79
     "latitude" => $u["latitude"] === null ? null : floatval($u["latitude"]),
76
     "longitude" => $u["longitude"] === null ? null : floatval($u["longitude"]),
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
     "nb_confirm_up" => intval($u["up"]),
83
     "nb_confirm_up" => intval($u["up"]),
79
     "nb_confirm_down" => intval($u["down"]),
84
     "nb_confirm_down" => intval($u["down"]),
80
     "media_url" => ($u["media"] !== null ) ? $media_url . $u["media"] : null);
85
     "media_url" => ($u["media"] !== null ) ? $media_url . $u["media"] : null);

+ 2
- 1
user.php View File

41
   $token = hash_password(uniqid(mt_rand(), true));
41
   $token = hash_password(uniqid(mt_rand(), true));
42
   database_exec("INSERT INTO tokens (`token`, `user`) VALUES (:token, :user)",
42
   database_exec("INSERT INTO tokens (`token`, `user`) VALUES (:token, :user)",
43
     array(":token" => $token, ":user" => $u['id']));
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
     "token" => $token));
46
     "token" => $token));
46
 }
47
 }
47
 ?>
48
 ?>

Loading…
Cancel
Save