-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
58 lines (48 loc) · 1.35 KB
/
api.php
File metadata and controls
58 lines (48 loc) · 1.35 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
<?php
require "peridot.php";
function outputResult($data) {
echo json_encode($data);
}
function outputError($error) {
//header();
outputResult(array('error' => $error));
}
$p = new Peridot();
if (isset($_GET['action'])) {
$action = $_GET['action'];
if ($action == "redirectInfo") {
if (isset($_GET['id'])) {
if (($data = $p->getUrlData($_GET['id']))) {
outputResult($data);
}
} else {
outputError("Malformed request");
}
} else {
outputError("Invalid action");
}
} elseif ((isset($_POST['action'])) && (isset($_POST['key']))) {
if (($user = $p->getUserByKey($_POST['key']))) {
$action = $_POST['action'];
if ($action == "createShort") {
if (isset($_POST['url'])) {
$ident = $p->createShort($_POST['url'],$user['id']);
if ($ident) {
outputResult(array('ident' => $ident));
} else {
outputError("Malformed URI");
}
} else {
outputError("Malformed request");
}
} else {
outputError("Invalid action");
}
} else {
//Invalid key
outputError("Invalid API key");
}
} else {
outputError("Malformed request");
}
?>