1
0
mirror of https://github.com/gamaio/lobli.git synced 2024-12-23 04:02:40 +00:00

Add return code messages to array and remove API stuf

I don't think in its current state, it will be able to shorten links...
	working on that
Will PHP complain at me if I store variable names without actually defining
	the variables yet?
The plan is to recieve the response, explode it, store the variables and
	echo $messages[response code];
This commit is contained in:
alopexc0de 2014-06-22 02:04:07 -04:00
parent 0598e96979
commit 187900675d

View File

@ -5,37 +5,62 @@
$catchid = $catches[0]; $catchid = $catches[0];
$catchVal = $catches[1]; $catchVal = $catches[1];
// Returns will be in the structure: Message code / seperator / extra data and will be formatted client side
/*
Message codes:
0 - Successful shorten
1 - Existing link found
2 - Dead link
3 - Database Error
4 - Sanitize failed
*/
$messages = array(
"
<div class=\"alert alert-success\" id=\"message\">
Your link: <a href=\"http://lob.li/$short\" title=\"HTML Title of website being shortened\" target=\"lobli.$short\">lob.li/$short</a>
<a href=\"#\" id=\"copylink\" title=\"Copy Link\" onclick=\"copyToClipboard('http://lob.li/$short');\">
<span class=\"glyphicon glyphicon-link\" style=\"float:right;padding-right:1%;\"></span>
</a>
</div>
",
"
<div class=\"alert alert-warning\" id=\"message\">
Existing link: <a href=\"http://lob.li/$short\" title=\"HTML Title of website being shortened\" target=\"lobli.$short\">lob.li/$short</a>
<a href=\"#\" id=\"copylink\" title=\"Copy Link\" onclick=\"copyToClipboard('http://lob.li/$short');\">
<span class=\"glyphicon glyphicon-link\" style=\"float:right;padding-right:1%;\"></span>
</a>
</div>
",
"
<div class=\"alert alert-danger\" id=\"message\">
ERROR! - Your link: <a href=\"$link\" target=\"$link\">$link</a> didn't resolve to a website. <br />Please check your link and try again.
</div>
",
"
<div class=\"alert alert-danger\" id=\"message\">
ERROR! - Well this is embarrassing... This never happens, but I appear to have suffered a database error. <br />Here's what I know: $error
</div>
",
"
<div class=\"alert alert-danger\" id=\"message\">
ERROR! - The sanitize function seems to have failed. This shouldn't happen, maybe <a href=\"mailto:c0de@unps.us\">c0de</a> forgot a semi-colon somewhere or something.
</div>
"
);
if(empty($_GET['token']) || $_GET['token'] != $_SESSION['token'] || empty($_POST[$catchid]) || $_POST[$catchid] != $catchVal){ 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>"); 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('Include/PHP/functions.php');
require('api/dbsettings.php');
$key = '9a211e90b0a0570ed33e47428231e702af47b6f54fb347960f661184e063a1d0'; // KEEP THIS PRIVATE! This is the only thing that authenticates the application if(!empty($_POST['link'])){
$short = sanitize($_POST['link']);
function sanitize($input){ if(strpos($short, "http://") === false && strpos($short, "https://") === false){
if ($input == null) die("<div id=\"error\">Sanatize() - No Input Provided, Aborting</div>"); $short = "http://$short";
include('api/dbsettings.php'); }
$output = strip_tags($input); //echo shorten($shortdb, $short);
$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;
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>"); } }else{ die("<div id=\"error\">I can't do my job if I'm not given a link to work on...</div>"); }