2010-12-23 12:26:25 +01:00
|
|
|
<?
|
|
|
|
session_start();
|
|
|
|
include 'class/ShortURL.php';
|
|
|
|
|
|
|
|
$url = new ShortURL();
|
2011-01-04 11:19:25 +01:00
|
|
|
$log = new Log('shorting.log');
|
2010-12-23 12:26:25 +01:00
|
|
|
|
|
|
|
$newname = $_POST['shortName'];
|
|
|
|
$newURL = $_POST['url'];
|
2011-01-04 11:19:25 +01:00
|
|
|
|
|
|
|
$log->message('entering '.$newname.' as '.$newURL);
|
|
|
|
|
2011-01-04 12:29:04 +01:00
|
|
|
$URI = $_SERVER['REQUEST_URI'];
|
|
|
|
$folders = explode('/', $URI);
|
|
|
|
if(count($folders) > 2){
|
|
|
|
$folder = '/'.$folders[1].'/';
|
|
|
|
}else
|
|
|
|
$folder = '/';
|
|
|
|
$log->message('folder : '.$folder);
|
|
|
|
|
2010-12-23 12:26:25 +01:00
|
|
|
$_SESSION['msg'] = '';
|
|
|
|
if($newname =='' || $newURL==''){
|
|
|
|
$_SESSION['msg'] .= ShortURL::STATE_FIELD_MISSING;
|
2011-01-04 12:29:04 +01:00
|
|
|
$log->error(ShortURL::STATE_FIELD_MISSING);
|
|
|
|
}else{
|
2010-12-23 12:26:25 +01:00
|
|
|
|
2011-01-04 12:29:04 +01:00
|
|
|
$ret = $url->shortThisUrl($newURL, $newname);
|
2010-12-23 12:26:25 +01:00
|
|
|
|
2011-01-04 12:29:04 +01:00
|
|
|
if(is_bool($ret) && !$ret){
|
|
|
|
$log->error(ShortURL::STATE_FIELD_MISSING);
|
|
|
|
$_SESSION['msg'] .= ShortURL::STATE_FIELD_MISSING;
|
|
|
|
}
|
|
|
|
elseif($ret === ShortURL::STATE_ALREADY_EXIST){
|
|
|
|
$log->error(ShortURL::STATE_ALREADY_EXIST);
|
|
|
|
$_SESSION['msg'] .= $ret;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$_SESSION['msg'] .= ShortURL::STATE_CREATED.': <a href="http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($newname).'">http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($newname).'</a>';
|
2011-01-04 11:19:25 +01:00
|
|
|
|
2011-01-04 12:29:04 +01:00
|
|
|
$log->message('that makes the link : http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($newname).'"');
|
|
|
|
}
|
2010-12-23 12:26:25 +01:00
|
|
|
}
|
2011-01-04 12:29:04 +01:00
|
|
|
$log->message('Redirecting to '.$folder);
|
2010-12-23 12:26:25 +01:00
|
|
|
header('Location: '.$folder);
|