-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
73 lines (63 loc) · 2.15 KB
/
index.php
File metadata and controls
73 lines (63 loc) · 2.15 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
68
69
70
71
72
73
<?php
require "peridot.php";
$p = new Peridot();
if (isset($_GET['id'])) {
//redirect or preview
if (($data = $p->getUrlData($_GET['id']))) {
$data['url'] = htmlspecialchars($data['url'], ENT_QUOTES, 'UTF-8');
if (isset($_GET['preview'])) {
//Preview
//If there is a user provided, display username
if ($data['userID'] != NULL) {
$user = $p->getUserById($data['userID']);
$data['name'] = $user['name'];
} else {
//Else use a placeholder
$data['name'] = 'Anonymous Coward';
}
displayView('views/preview.php',$data);
} else {
//Redirect
header("HTTP/1.1 301 Moved Permanently");
header("Location: {$data['url']}");
displayView('views/redirect.php',$data, false);
$p->incrementRedirectHits($data['ident']);
}
} else {
//No such ident
displayError("Non-existent identifier. ({$_GET['id']})");
}
} elseif (isset($_POST['name'])) {
//Creating user
$p->createUser($_POST['name']);
} elseif (isset($_POST['url'])) {
//Creating redirect
$data = array();
if (isset($_POST['key'])) {
if (($user = $p->getUserByKey($_POST['key']))) {
$data['ident'] = $p->createShort($_POST['url'],$user['id']);
if ($data['ident']) {
displayView('views/create.php',$data);
} else {
displayError("Malformed URI");
}
} else {
//Invalid key
displayError("Invalid API key");
}
} elseif (ALLOW_PUBLIC) {
//Anonymous redirect
$data['ident'] = $p->createShort($_POST['url']);
if ($data['ident']) {
displayView('views/create.php',$data);
} else {
displayError("Malformed URI");
}
} else {
//No key given, and not public
displayError("No API key was provided, and anonymous redirect creation is disabled.");
}
} else {
displayView('views/create.php');
}
?>