forked from SteGriff/magic-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
67 lines (53 loc) · 1.28 KB
/
index.php
File metadata and controls
67 lines (53 loc) · 1.28 KB
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
<?php
require "string_extensions.php";
require "card_extractors.php";
require "timing.php";
require "db.php";
require "DAL.php";
startTiming();
$cardObject = null;
$name_search = null;
$cardObject["error"] = null;
//Get database instance
$db = db();
$metrics = false;
if ($_GET){
if ( isset($_GET["name"]) ){
$name_search = strip_quotes($_GET["name"]);
if ( isset($_GET["metrics"]) ){
$metrics = true;
}
}
else{
$cardObject["error"] = "No paramaters in name search.";
}
}
else{
$cardObject["error"] = "No search parameters. Use ?name=";
}
if ($name_search){
$cardObject = DB_card_exists($name_search, $db);
if ( $cardObject ){
if ($metrics) { $cardObject["from_cache"] = "true"; }
}
else{
$cardObject = download_card($name_search);
//If we got a real card, cache it and mark it.
if ( !isset($cardObject["error"]) ){
//Save
$committed = DB_create_card($cardObject, $db);
if ($metrics){
$cardObject["from_cache"] = "false";
$cardObject["into_cache"] = $committed ? "success" : "failure";
}
}
}
}
elseif (!$cardObject["error"]){
$cardObject["error"] = "No results";
}
$cardObject["request_time"] = stopTiming() . " seconds";
header('content-Type: application/json');
header("Access-Control-Allow-Origin: *");
echo json_encode($cardObject);
?>