Compare commits
3 Commits
ae036686b8
...
b7a8602e34
Author | SHA1 | Date | |
---|---|---|---|
b7a8602e34 | |||
42eff5e0fa | |||
3d36c2704a |
62
index.js
62
index.js
@@ -1,16 +1,55 @@
|
||||
// const submit = document.getElementById("button");
|
||||
// submit.addEventListener('click', validate);
|
||||
|
||||
mycheckbox = document.getElementById("restricted");
|
||||
mycheckbox.addEventListener('change',checkboxCallback);
|
||||
window.onload = function() {
|
||||
if (mycheckbox.checked) {
|
||||
document.getElementById("radiusLabel").hidden = false;
|
||||
document.getElementById("mandatory-radius").hidden = false;
|
||||
var radiusSelect = document.getElementById("radiusSelect");
|
||||
radiusSelect.hidden = false;
|
||||
radiusSelect.required = true;
|
||||
}
|
||||
}
|
||||
|
||||
var lat = document.getElementById("latitude");
|
||||
lat.setValue = function(newValue) {
|
||||
this.value = newValue;
|
||||
valueReceived();
|
||||
}
|
||||
|
||||
function valueReceived() {
|
||||
let load = document.getElementById("loadingText");
|
||||
load.innerHTML = "Location retrieved";
|
||||
load.style.color = "green";
|
||||
|
||||
}
|
||||
function valueRequested() {
|
||||
let load = document.getElementById("loadingText");
|
||||
load.innerHTML = "Location requested. Please wait...";
|
||||
load.style.color = "red";
|
||||
|
||||
}
|
||||
function checkboxCallback(event) {
|
||||
const radiusLabel = document.getElementById("radiusLabel");
|
||||
const radiusSelect = document.getElementById("radiusSelect");
|
||||
const mandatoryRadius = document.getElementById("mandatory-radius");
|
||||
if (event.currentTarget.checked) {
|
||||
radiusLabel.hidden = false;
|
||||
mandatoryRadius.hidden = false;
|
||||
radiusSelect.hidden = false;
|
||||
radiusSelect.required = true;
|
||||
valueRequested();
|
||||
getLocation();
|
||||
} else {
|
||||
radiusLabel.hidden = true;
|
||||
mandatoryRadius.hidden = true;
|
||||
radiusSelect.hidden = true;
|
||||
radiusSelect.required = false;
|
||||
}
|
||||
}
|
||||
|
||||
function getLocation() {
|
||||
console.log("GeoLocation");
|
||||
if (navigator.geolocation) {
|
||||
navigator.geolocation.getCurrentPosition(showPosition);
|
||||
} else {
|
||||
@@ -19,16 +58,27 @@ function getLocation() {
|
||||
}
|
||||
|
||||
function showPosition(position) {
|
||||
console.log("Gotten positions");
|
||||
console.log(position.coords.latitude);
|
||||
console.log(position.coords.longitude);
|
||||
|
||||
document.getElementById("latitude").value = position.coords.latitude;
|
||||
document.getElementById("latitude").setValue(position.coords.latitude);
|
||||
document.getElementById("longitude").value = position.coords.longitude;
|
||||
console.log("done");
|
||||
}
|
||||
|
||||
|
||||
function validate() {
|
||||
// submit.addEventListener('click', validate);
|
||||
function validate() {
|
||||
//e.preventDefault();
|
||||
const checked = document.getElementById("restricted");
|
||||
if (checked.checked) {
|
||||
const lat = document.getElementById("latitude");
|
||||
const long = document.getElementById("longitude");
|
||||
if (lat.value === "" || long.value === "") {
|
||||
/* wait */
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const url = document.getElementById("URL");
|
||||
let glink = document.getElementById("GLink");
|
||||
@@ -71,8 +121,6 @@ function validate() {
|
||||
var result = window.confirm("You have left the glink field blank. A random one will be generated for you.");
|
||||
if (result === false) {
|
||||
return false;
|
||||
} else {
|
||||
glinkStr = getRandomGLink();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
$keyspace = 'glink';
|
||||
$session = $cluster->connect($keyspace);
|
||||
|
||||
$statement = $session->prepare('SELECT url FROM data WHERE shortlink=? ALLOW FILTERING;');
|
||||
$statement = $session->prepare('SELECT url,is_geo FROM data WHERE shortlink=? ALLOW FILTERING;');
|
||||
$result = $session->execute($statement,array('arguments' => array($uri)));
|
||||
|
||||
if ($result->count() == 0) {
|
||||
@@ -27,8 +27,14 @@
|
||||
if (is_null($row)) {
|
||||
printf('The given GLink was invalid, and doesn\'t point to a specific web page.');
|
||||
exit;
|
||||
} else {
|
||||
if ($row['is_geo'] == true) {
|
||||
header("Location: https://glink.zip/reqloc.html");
|
||||
exit;
|
||||
} else {
|
||||
header("Location: " . $row['url']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
29
result.php
29
result.php
@@ -28,13 +28,29 @@ function gen_rand_shortlink($len) {
|
||||
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
use Casssandra;
|
||||
|
||||
$cluster = Cassandra::cluster()->withPersistentSessions(true)->build();
|
||||
$keyspace = 'glink';
|
||||
$session = $cluster->connect($keyspace);
|
||||
|
||||
$url = $_GET["url"];
|
||||
|
||||
if (isset($_GET["restricted"])) {
|
||||
$is_geo = 1;
|
||||
} else {
|
||||
$is_geo = 0;
|
||||
}
|
||||
|
||||
if ($is_geo == 1) {
|
||||
$radius = $_GET["radius"];
|
||||
|
||||
$latitude = $_GET["latitude"];
|
||||
$latitude = doubleval($latitude);
|
||||
|
||||
$longitude = $_GET["longitude"];
|
||||
$longitude = doubleval($longitude);
|
||||
}
|
||||
|
||||
$matches = preg_match('/^http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+$/',$url);
|
||||
if (($matches == 0) || ($matches == false)) {
|
||||
printf("The URL entered was invalid. Please try again.");
|
||||
@@ -78,8 +94,15 @@ if ($result->count() != 0) {
|
||||
|
||||
$rand_num = rand(0,99999999);
|
||||
|
||||
$statement = $session->prepare('INSERT INTO data (id, url, shortlink, when_created) VALUES (?,?,?,toTimestamp(now())) USING TTL 20');
|
||||
$result = $session->execute($statement,array('arguments' => array($rand_num,$url,$shortlink)));
|
||||
$statement = $session->prepare('INSERT INTO data (id, url, shortlink, is_geo, radius, latitude, longitude, when_created) VALUES (?,?,?,?,?,?,?,toTimestamp(now())) USING TTL 20');
|
||||
|
||||
if ($is_geo == 1) {
|
||||
$options = array($rand_num,$url,$shortlink,boolval($is_geo),intval($radius), $latitude, $longitude);
|
||||
} else {
|
||||
$options = array($rand_num,$url,$shortlink,boolval($is_geo),null,null,null);
|
||||
}
|
||||
|
||||
$result = $session->execute($statement,array('arguments' => $options));
|
||||
|
||||
//$stringRepresentation= json_encode($result[0]);
|
||||
|
||||
|
Reference in New Issue
Block a user