Merge branch 'csl', added support of last-modified
This commit is contained in:
commit
fc0b7c51ed
15
get.php
15
get.php
@ -3,7 +3,7 @@
|
||||
* @Author: prpr
|
||||
* @Date: 2016-02-02 20:56:42
|
||||
* @Last Modified by: prpr
|
||||
* @Last Modified time: 2016-02-02 21:33:12
|
||||
* @Last Modified time: 2016-02-03 13:26:30
|
||||
*/
|
||||
|
||||
$dir = dirname(__FILE__);
|
||||
@ -12,13 +12,16 @@ require "$dir/config.php";
|
||||
|
||||
if (isset($_GET['type']) && isset($_GET['uname'])) {
|
||||
$user = new user($_GET['uname']);
|
||||
|
||||
if (!$user->is_registered) utils::raise(1, 'Non-existent user.');
|
||||
|
||||
if ($_GET['type'] == "skin") {
|
||||
echo $user->getBinaryTexture('skin');
|
||||
} else if ($_GET['type'] == "cape") {
|
||||
echo $user->getBinaryTexture('cape');
|
||||
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null;
|
||||
|
||||
if ($_GET['type'] == "skin" || $_GET['type'] == "cape") {
|
||||
if ($if_modified_since >= $user->getLastModified()) {
|
||||
header('HTTP/1.0 304 Not Modified');
|
||||
} else {
|
||||
echo $user->getBinaryTexture($_GET['type']);
|
||||
}
|
||||
} else if ($_GET['type'] == "json") {
|
||||
echo $user->getJsonProfile();
|
||||
} else {
|
||||
|
@ -3,7 +3,7 @@
|
||||
* @Author: printempw
|
||||
* @Date: 2016-02-02 21:59:06
|
||||
* @Last Modified by: prpr
|
||||
* @Last Modified time: 2016-02-03 00:10:17
|
||||
* @Last Modified time: 2016-02-03 12:12:16
|
||||
*/
|
||||
|
||||
class database
|
||||
@ -39,7 +39,7 @@ class database
|
||||
if (!$this->connection->error) {
|
||||
return $result;
|
||||
}
|
||||
utils::raise(-1, "Database query error: ", $this->connection->error);
|
||||
utils::raise(-1, "Database query error: ".$this->connection->error);
|
||||
}
|
||||
|
||||
public function fetchArray($sql) {
|
||||
@ -69,7 +69,7 @@ class database
|
||||
}
|
||||
|
||||
public function update($uname, $key, $value) {
|
||||
return $this->query("UPDATE users SET $key='$value' WHERE username='$uname'");
|
||||
return $this->query("UPDATE users SET `$key`='$value' WHERE username='$uname'");
|
||||
}
|
||||
|
||||
public function delete($uname) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
* @Author: printempw
|
||||
* @Date: 2016-01-16 23:01:33
|
||||
* @Last Modified by: prpr
|
||||
* @Last Modified time: 2016-02-02 23:41:37
|
||||
* @Last Modified time: 2016-02-03 13:25:55
|
||||
*/
|
||||
|
||||
class user
|
||||
@ -73,6 +73,7 @@ class user
|
||||
$filename = "./textures/".$this->getTexture($type);
|
||||
if (file_exists($filename)) {
|
||||
header('Content-Type: image/png');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->getLastModified()).' GMT');
|
||||
$data = fread(fopen($filename, 'r'), filesize($filename));
|
||||
return $data;
|
||||
} else {
|
||||
@ -87,10 +88,12 @@ class user
|
||||
// remove the original texture first
|
||||
if ($this->getTexture('skin') != "")
|
||||
utils::remove("./textures/".$this->getTexture('skin'));
|
||||
$this->updateLastModified();
|
||||
return $this->db->update($this->uname, 'skin_hash', $hash);
|
||||
} else if ($type == "cape") {
|
||||
if ($this->getTexture('cape') != "")
|
||||
utils::remove("./textures/".$this->getTexture('cape'));
|
||||
$this->updateLastModified();
|
||||
return $this->db->update($this->uname, 'cape_hash', $hash);
|
||||
}
|
||||
return false;
|
||||
@ -107,10 +110,9 @@ class user
|
||||
public function getJsonProfile() {
|
||||
header('Content-type: application/json');
|
||||
if ($this->is_registered) {
|
||||
$json['player_name'] = $this->uname;
|
||||
$preference = $this->getPreference();
|
||||
$json['model_preference'] = [$preference];
|
||||
$json['skins'][$preference] = $this->getTexture('skin');
|
||||
$json['model'] = $preference;
|
||||
$json['skin'] = $this->getTexture('skin');
|
||||
$json['cape'] = $this->getTexture('cape');
|
||||
} else {
|
||||
$json['errno'] = 1;
|
||||
@ -119,4 +121,17 @@ class user
|
||||
return json_encode($json);
|
||||
}
|
||||
|
||||
public function updateLastModified() {
|
||||
// http://stackoverflow.com/questions/2215354/php-date-format-when-inserting-into-datetime-in-mysql
|
||||
return $this->db->update($this->uname, 'last_modified', date("Y-m-d H:i:s"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last modified time
|
||||
* @return timestamp
|
||||
*/
|
||||
public function getLastModified() {
|
||||
return strtotime($this->db->select('username', $this->uname)['last_modified']);
|
||||
}
|
||||
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 114 KiB |
Loading…
Reference in New Issue
Block a user