2014-07-04 21:31:52 +00:00
< ? php
session_start ();
$catches = explode ( " : " , $_SESSION [ 'catch' ]);
$catchid = $catches [ 0 ];
$catchVal = $catches [ 1 ];
$seperator = " ᐖ " ; // Chosen because it looks like a smiling face
// 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
5 - Successful lob . li link resolve
6 - Successful lookup of non - lob . li link
7 - Unsuccessful lookup of non - lob . li link
2014-07-25 21:41:51 +00:00
8 - Lookup of link Stats ( returns 8 $sep JSONarray )
2014-07-04 21:31:52 +00:00
*/
require ( 'Include/PHP/functions.php' );
2014-08-15 22:34:46 +00:00
if ( isset ( $_GET [ 'resolve' ]) && ! empty ( $_POST [ 'link' ])){
2014-08-29 18:14:49 +00:00
if ( empty ( $_POST [ $catchid ]) || $_POST [ $catchid ] != $catchVal ){
2014-08-15 22:34:46 +00:00
die ( " <div id= \" danger \" class= \" alert alert-danger \" >Oh Noes! Something happened and I can't continue.<br />Please try again by using the form located at <a href= \" http://lob.li \" >lob.li</a>.</div> " );
}
2014-08-29 18:14:49 +00:00
if ( ! $redis -> exists ( " tokens: " . $_SESSION [ 'token' ]) || $redis -> get ( " tokens: " . $_SESSION [ 'token' ]) == 1 ){
include ( " Include/PHP/token.php " );
2014-08-29 19:23:09 +00:00
echo " <script>window.location = \" index.php \" ;</script> " ;
2014-08-29 18:14:49 +00:00
}
2014-08-15 22:34:46 +00:00
$link = $_POST [ 'link' ];
$trTtl = $redis -> ttl ( " links: $link " );
if ( $trTtl == - 2 ){ // Didn't find links:linkid, checking if long link
$trTtl = $redis -> ttl ( " llinks: $link " );
if ( $trTtl == - 2 ){ // Didn't find that either, give error
echo "
< div class = \ " alert alert-warning \" id= \" warning \" >
Your link : < a href = \ " $link\ " >
< span class = \ " longlink \" > $link </span></a> is not a lob.li link and has not been shortened.
</ div >
" ;
exit ;
}
}
2014-08-29 19:23:09 +00:00
$short = $redis -> lRange ( " links: $link " , 0 , 0 );
if ( $short ){
$link = $short [ 0 ];
echo "
< div class = \ " alert alert-success \" id= \" success \" >
Your Resolved link : < a href = \ " $link\ " >
< span class = \ " longlink \" > $link </span></a>
< a href = \ " # \" id= \" copylink \" title= \" Copy Link \" onclick= \" copyToClipboard(' $link '); \" >
< span class = \ " glyphicon glyphicon-link \" style= \" float:right;padding-right:1%; \" ></span>
</ a >
</ div >
" ;
exit ;
} else {
$short = $redis -> get ( " llinks: $link " );
if ( $short ){
echo "
< div class = \ " alert alert-warning \" id= \" warning \" >
Your link : < a href = \ " $link\ " >
< span class = \ " longlink2 \" > $link </span></a> is not a lob.li link.<br> However we found that it has been shortened. <a href= \" http://lob.li/ $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 >
" ;
exit ;
}
}
2014-08-15 22:34:46 +00:00
2014-08-29 19:23:09 +00:00
} elseif ( ! empty ( $_POST [ 'link' ]) || ! empty ( $_POST [ 'linkage' ])){
2014-08-29 18:14:49 +00:00
if ( empty ( $_POST [ $catchid ]) || $_POST [ $catchid ] != $catchVal ){
2014-07-25 21:41:51 +00:00
die ( " <div id= \" danger \" class= \" alert alert-danger \" >Oh Noes! Something happened and I can't continue.<br />Please try again by using the form located at <a href= \" http://lob.li \" >lob.li</a>.</div> " );
}
2014-08-29 18:14:49 +00:00
if ( ! $redis -> exists ( " tokens: " . $_SESSION [ 'token' ]) || $redis -> get ( " tokens: " . $_SESSION [ 'token' ]) == 1 ){
include ( " Include/PHP/token.php " );
2014-08-29 18:24:02 +00:00
echo " <script>window.location = \" index.php \" ;</script> " ;
2014-08-29 18:14:49 +00:00
}
$redis -> set ( " tokens: " . $_SESSION [ 'token' ], 1 );
2014-07-25 21:41:51 +00:00
//$short = sanitize($_POST['link'], $seperator);
$short = $_POST [ 'link' ];
$linkage = $_POST [ 'linkage' ];
//echo $short;
2014-07-04 21:31:52 +00:00
if ( strpos ( $short , " http:// " ) === false && strpos ( $short , " https:// " ) === false ){
$short = " http:// $short " ;
}
2014-07-25 21:41:51 +00:00
$reShort = shorten ( $redis , $short , $linkage , $seperator );
$reShort = explode ( $seperator , $reShort );
$retCode = $reShort [ 0 ];
switch ( $retCode ){
case " 0 " : // Successful link Shorten
$short = $reShort [ 1 ];
echo "
< div class = \ " alert alert-success \" id= \" success \" >
2014-08-15 23:35:35 +00:00
Your link : < a href = \ " http://lob.li/ $short\ " target = \ " lobli. $short\ " > lob . li / $short </ a >
2014-07-25 21:41:51 +00:00
< a href = \ " # \" id= \" copylink \" title= \" Copy Link \" onclick= \" copyToClipboard('http://lob.li/ $short '); \" >
<!--< a href = \ " # \" id= \" newlink \" title= \" New Link \" > This would require changing how I generate links, and I don't feel like doing it right now - 6/22/12 1:21am EST
< span class = \ " glyphicon glyphicon-refresh \" style= \" float:right; \" ></span>
</ a >-->
< span class = \ " glyphicon glyphicon-link \" style= \" float:right;padding-right:1%; \" ></span>
</ a >
</ div >
" ;
break ;
case " 1 " : // Existing Short Link Found
$short = $reShort [ 1 ];
echo "
< div class = \ " alert alert-warning \" id= \" warning \" >
2014-08-15 23:35:35 +00:00
Existing link : < a href = \ " http://lob.li/ $short\ " target = \ " lobli. $short\ " > lob . li / $short </ a >
2014-07-25 21:41:51 +00:00
< 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 >
" ;
break ;
case " 2 " : // Dead Link
$link = $reShort [ 1 ];
echo "
< div class = \ " alert alert-danger \" id= \" danger \" >
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 >
" ;
break ;
case " 3 " : // DB Error
$error = $reShort [ 1 ];
echo "
< div class = \ " alert alert-danger \" id= \" danger \" >
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 >
" ;
break ;
case " 4 " : // Sanitize Failure Error
echo "
< div class = \ " alert alert-danger \" id= \" danger \" >
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 >
" ;
break ;
default :
echo " <div id= \" danger \" class= \" alert alert-danger \" >Oh Noes! Something happened and I can't continue.<br />Please try again by using the form located at <a href= \" http://lob.li \" >lob.li</a>.</div> " ;
break ;
}
exit ;
2014-07-04 21:31:52 +00:00
//foreach($messages as $message){
// echo $message;
//}
} else { die ( " <div id= \" danger \" class= \" alert alert-danger \" >I can't do my job if I'm not given a link to work on...</div> " ); }
2014-06-22 05:24:17 +00:00
?>