mirror of
https://github.com/gamaio/unps.us-Shortener.git
synced 2024-12-21 17:52:41 +00:00
Include more mobile friendly version
Basically exactly the same, but it scales better with almost everything stripped out
This commit is contained in:
parent
a9b73c1161
commit
b34e2db558
101
mobile/index.php
Normal file
101
mobile/index.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
$appname = " Shortener";
|
||||
|
||||
// Generate a token on the fly. This should prevent POST spam attacks directly into process.php
|
||||
$token = substr(number_format(time() * mt_rand(),0,'',''),0,10);
|
||||
$token = base_convert($token, 10, 36);
|
||||
$_SESSION['token'] = $token;
|
||||
|
||||
$catchid = substr(number_format(time() * mt_rand(),0,'',''),0,10);
|
||||
$catchVal = hash('sha256', $catchid.mt_rand().time().substr(number_format(time() * mt_rand(),0,'',''),0,10));
|
||||
$catchVal = base_convert($catchVal.$catchid, 10, 36);
|
||||
$_SESSION['catch'] = $catchid.":".$catchVal;
|
||||
|
||||
if(!empty($_GET['l'])){
|
||||
include('api/dbsettings.php');
|
||||
$link = $shortdb->real_escape_string(strtolower(stripslashes(strip_tags($_GET['l']))));
|
||||
$sql = "SELECT * FROM `links` WHERE `shortlink` = '$link' LIMIT 1;";
|
||||
if($result = $shortdb->query($sql)){
|
||||
if($row = $result->fetch_assoc()){
|
||||
$link = $row['link'];
|
||||
header("location:$link");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_GET['newbg'])){
|
||||
echo "<style>body{background-image: url('../assets/images/newbody.jpg') !important;}</style>";
|
||||
}
|
||||
|
||||
function userpic($email){
|
||||
$default = "http://fox.gy/fCDIjceUvkk.png";
|
||||
$size = 20;
|
||||
$grav_url = "http://www.gravatar.com/avatar/".md5(strtolower(trim($email)))."?d=".urlencode($default)."&s=".$size;
|
||||
return $grav_url;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns# fb: http://www.facebook.com/2008/fbml">
|
||||
<head>
|
||||
<title>UnPS Link Shortener</title>
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
||||
<meta name="description" content="UnPS Link Shortener"/>
|
||||
<meta name="keywords" content="UnPS, GAMA, Shorten, Link"/>
|
||||
<meta name="author" content="David Todd"/>
|
||||
<meta property="og:image" content="http://fox.gy/fCDIjceUvkk.png"/>
|
||||
|
||||
<link href="../assets/bootstrap/css/bootstrap.css" rel="stylesheet" media="screen" />
|
||||
<link href="../assets/css/elements.css?<?php echo time(); ?>" rel="stylesheet" />
|
||||
|
||||
<link rel="shortcut icon" type="image/ico" href="../favicon.ico"/>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="../favicon.ico"/>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrap">
|
||||
<?php include('navbar.php'); ?>
|
||||
|
||||
<div class="container">
|
||||
<form class="form-shorten" id="form-shorten">
|
||||
<h2 class="form-shorten-heading">Please give me a link to shorten...</h2>
|
||||
<input type="text" id="link" class="form-control" name="link" placeholder="http://" autofocus>
|
||||
|
||||
<input type="hidden" name="<?php echo $catchid; ?>" value="<?php echo $catchVal; ?>"/>
|
||||
<input type="hidden" name="linkmod" id="shorten" value="shorten" />
|
||||
<button class="btn btn-block btn-primary" id="short-button" type="submit">Shorten</button>
|
||||
</form>
|
||||
<div id="message"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Load the JS after the DOM so speed up load times -->
|
||||
<script type="text/javascript" language="JavaScript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
|
||||
<script type="text/javascript" language="JavaScript" src="../assets/bootstrap/js/bootstrap.js"></script>
|
||||
<script type="text/javascript" language="JavaScript" src="unps.core.js"></script>
|
||||
|
||||
<script type="text/javascript" language="JavaScript">
|
||||
// This is our AJAX - Thank you Wizzy <3
|
||||
$("#form-shorten").submit(function(event){
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
$.post("process.php?token=<?php echo $token; ?>", $(this).serialize(), function(data){
|
||||
$("#message").hide().html(data).fadeIn("fast");
|
||||
if($('#error').length){
|
||||
$('#short-button').removeClass('btn-primary');
|
||||
$('#short-button').removeClass('btn-success');
|
||||
$('#short-button').addClass('btn-danger');
|
||||
}else if($('#success').length){
|
||||
$('#short-button').removeClass('btn-primary');
|
||||
$('#short-button').removeClass('btn-danger');
|
||||
$('#short-button').addClass('btn-success');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
54
mobile/navbar.php
Normal file
54
mobile/navbar.php
Normal file
@ -0,0 +1,54 @@
|
||||
<div class="navbar-wrapper">
|
||||
<div class="container">
|
||||
<div class="navbar navbar-inverse navbar-static-top">
|
||||
<div class="container">
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<div class="nav-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="./"><img src="../favicon.ico" style="max-height:18px;"><?php echo $appname; ?></a></li>
|
||||
<li><a href="http://unps-gama.info">UnPS Home</a></li>
|
||||
<li><a href="http://unps-gama.info/about">About</a></li>
|
||||
<li><a href="http://unps-gama.info/contact">Contact</a></li>
|
||||
|
||||
|
||||
<!-- User area -->
|
||||
<?php if(isset($_SESSION['uname'])){ ?>
|
||||
<ul class="nav navbar-nav" style="float:right;">
|
||||
<?php if($appname === " Image Host"){ ?>
|
||||
<li><a href="#">Upload Picture</a></li>
|
||||
<?php } ?>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" id="uname-dropdown" data-toggle="dropdown">
|
||||
<img id="profile-pic" class="img-rounded" src="<?php echo userpic($_SESSION['email']); ?>" alt="User gravatar image" /> <?php echo $_SESSION['uname'] ?> <b class="caret"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li class="divider"></li>
|
||||
|
||||
<li><a href="http://unps-gama.info/account.php">Account</a></li>
|
||||
<li><a href="http://unps-gama.info/friends.php">Friends</a></li>
|
||||
<li><a href="http://unps-gama.info/stats.php?all">Stats</a></li>
|
||||
<li><a href="http://unps-gama.info/stats.php?links">Short Links</a></li>
|
||||
<li><a href="http://unps-gama.info/stats.php?pics">Uploaded Pictures</a></li>
|
||||
<li><a id="logout-link" href="http://unps-gama.info/signout.php">Sign Out</a></li>
|
||||
|
||||
<li class="divider"></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<?php }else{ ?>
|
||||
<ul class="nav navbar-nav" style="float:right;">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="login">
|
||||
<img style="max-height:18px;max-width:18px;" src="../assets/images/user.png" /> Login <b class="caret"></b>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
59
mobile/process.php
Normal file
59
mobile/process.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
$catches = explode(":", $_SESSION['catch']);
|
||||
$catchid = $catches[0];
|
||||
$catchVal = $catches[1];
|
||||
|
||||
if(empty($_GET['token']) || $_GET['token'] != $_SESSION['token'] || empty($_POST[$catchid]) || $_POST[$catchid] != $catchVal){
|
||||
die("<div id=\"error\">Oh Noes! Something happened and I can't continue.<br />Please try again by using the form located at <a href=\"http://unps.us\">http://unps.us</a>.</div>");
|
||||
}
|
||||
|
||||
require('api/api.backend.php');
|
||||
require('api/dbsettings.php');
|
||||
|
||||
$key = '9a211e90b0a0570ed33e47428231e702af47b6f54fb347960f661184e063a1d0'; // KEEP THIS PRIVATE! This is the only thing that authenticates the application
|
||||
|
||||
function sanitize($input){
|
||||
if ($input == null) die("<div id=\"error\">Sanatize() - No Input Provided, Aborting</div>");
|
||||
include('api/dbsettings.php');
|
||||
$output = strip_tags($input);
|
||||
$output = stripslashes($output);
|
||||
$output = $apidb->real_escape_string($output);
|
||||
return $output;
|
||||
}
|
||||
|
||||
$unpsAPI = new api();
|
||||
|
||||
if(!empty($_POST['link']) && !empty($_POST['linkmod'])){
|
||||
switch ($_POST['linkmod']){
|
||||
case "shorten":
|
||||
$short = sanitize($_POST['link']);
|
||||
if(strpos($short, "http://") === false && strpos($short, "https://") === false){
|
||||
$short = "http://$short";
|
||||
}
|
||||
echo $unpsAPI->shorten($apidb, $key, $shortdb, $short);
|
||||
break;
|
||||
case "dellink":
|
||||
if(empty($_POST['password'])) die("<div id=\"error\">Something went wrong somewhere, but there's no password here</div>");
|
||||
$link = sanitize($_POST['link']);
|
||||
$password = sanitize($_POST['password']);
|
||||
$link = explode("=", $link);
|
||||
if(count($link) != 2){
|
||||
die("<div id=\"error\">I'm sorry, but something went wrong... did you paste the whole link?</div>");
|
||||
}
|
||||
$link = $link[1];
|
||||
echo $unpsAPI->delShort($apidb, $key, $shortdb, $link, $password);
|
||||
break;
|
||||
case "replink":
|
||||
if(empty($_POST['report-details'])) die("<div id=\"error\">Something went wrong somewhere, but I can't find the reason for reporting this link</div>");
|
||||
$link = sanitize($_POST['link']);
|
||||
$details = sanitize($_POST['report-details']);
|
||||
echo $unpsAPI->reportLink($apidb, $key, $shortdb, $link, $details);
|
||||
break;
|
||||
default:
|
||||
die("<div id=\"error\">I don't know what you want to do... [-Check linkmod-]</div>");
|
||||
}
|
||||
}else{ die("<div id=\"error\">I can't do my job if I'm not given a link to work on...</div>"); }
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user