-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
72 lines (67 loc) · 2.13 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* Avatar API
*
* @author Fact Maven
* @link https://api.factmaven.com/avatar
* @version 1.2.1
*/
# Headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");
ini_set("user_agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
# Special properties
$link = (isset($_SERVER['HTTPS'])?"https":"http")."://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if (count($_GET)) {
# Convert email into MD5 hash
if (isset($_GET['email'])) {
$email = $_GET['email'];
$hash = md5(strtolower($email));
}
$gravatar = @file_get_contents("https://gravatar.com/".$hash.".json");
if ($gravatar === FALSE) {
$gravatar = FALSE;
} else {
$gravatar = json_decode($gravatar);
}
# Structure API
$api = [
"@link" => $link,
"email" => $email,
"hash" => $hash,
"@sources" => [
"gravatar" => [
"avatar" => "https://gravatar.com/avatar/".$hash,
"api" => $gravatar,
],
"robohash" => [
"avatar" => "https://robohash.org/".$hash.".png",
"links" => [
"https://robohash.org/".$hash.".png?gravatar=hashed",
"https://robohash.org/".$hash.".png?set=set2",
"https://robohash.org/".$hash.".png?set=set3",
"https://robohash.org/".$hash.".png?set=set4",
"https://robohash.org/".$hash.".png?set=set5",
],
],
],
];
} else {
$api = [
"errors" => [
"id" => "404",
"title" => "Missing Parameter",
"detail" => "Please start with adding '[email protected]' at the end.",
],
"meta" => [
"version" => "1.2.1",
"copyright" => "Copyright 2011-".date("Y")." Fact Maven",
"link" => "https://factmaven.com/",
"authors" => [
"Ethan O'Sullivan",
]
],
];
}
# Output JSON
print_r(json_encode(array_filter($api)));