forked from hyphacoop/link.hypha.coop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redir.php
122 lines (109 loc) · 2.96 KB
/
redir.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
$link = $_REQUEST['link'];
$tolink = "";
$csv = file_get_contents("https://raw.githubusercontent.com/tomeshnet/toronto-community-network/master/communications/shortlinks.csv");
$lines = explode("\n", $csv);
foreach ($lines as $line) {
$val = explode(",", $line);
if (strtolower($link) == strtolower($val[0])) {
$tolink = $val[1];
break;
}
}
if ($tolink != "")
header("location: $tolink");
else
$msg = "<span class='error'>There is no <b>$link</b> defined as a short link.</span>";
if ($link == "redit.php" || $link == "" ) $link = $msg = "";
?>
<html>
<head>
<title>Toronto Mesh Link Redirector</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.devbridge-autocomplete/1.2.27/jquery.autocomplete.min.js"></script>
</head>
<body>
<style>
html,
body {
width: 100%;
height: 100%;
background: #000000;
color: white;
font-family: 'WorkSans', helvetica, sans-serif;
padding:0;
margin:0;
display: table;
}
h1 {
font-size:42px;
margin:0px;
padding:0px;
}
.Selection {
text-align: center;
font-size: 24px;
display: table-cell;
vertical-align: middle;
height:100%;
}
.Selection input {
padding: 10px;
font-size: 24px;
}
.autocomplete-suggestions {
background: white;
border: 1px solid black;
color: black;
overflow: auto;
}
.autocomplete-suggestion {
padding: 2px;
color:#999999;
}
.autocomplete-suggestion:hover {
background: #e3c9f4;
}
.autocomplete-suggestion strong {
color: #9900fc;
}
.error {
background:white;
color:red;
display:inline-block;
padding:5px;
border-radius:3px;
}
</style>
<div class="Selection">
<h1>Toronto Mesh</h1>
<label for="files">Short Link Redirector</label>
<br/>
<br/>
<?=$msg?>
<br/>
Enter short link
<br/>
<input type="text" name="code" id="autocomplete" value="<?= $link ?>" />
</div>
<script>
var options = [
<?php
foreach ($lines as $line) {
$val = explode(",", $line);
echo " { value: '$val[0]', data: '$val[1]' },";
}
?> {
value: '',
data: ''
}
];
$('#autocomplete').autocomplete({
lookup: options,
onSelect: function(suggestion) {
window.location = suggestion.data;
}
});
</script>
</body>
</html>