From 98bf0ca8bf3a96917b838f1e5fbc46541b8f4978 Mon Sep 17 00:00:00 2001 From: Chouchen Date: Tue, 4 Jan 2011 11:29:04 +0000 Subject: [PATCH] Folder bug correction + logging improved + messages from class --- trunk/short.php | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/trunk/short.php b/trunk/short.php index f337be7..93975b1 100644 --- a/trunk/short.php +++ b/trunk/short.php @@ -10,32 +10,35 @@ $newURL = $_POST['url']; $log->message('entering '.$newname.' as '.$newURL); +$URI = $_SERVER['REQUEST_URI']; +$folders = explode('/', $URI); +if(count($folders) > 2){ + $folder = '/'.$folders[1].'/'; +}else + $folder = '/'; +$log->message('folder : '.$folder); + $_SESSION['msg'] = ''; if($newname =='' || $newURL==''){ $_SESSION['msg'] .= ShortURL::STATE_FIELD_MISSING; -} + $log->error(ShortURL::STATE_FIELD_MISSING); +}else{ -$ret = $url->shortThisUrl($newURL, $newname); + $ret = $url->shortThisUrl($newURL, $newname); -if(is_bool($ret) && !$ret){ - $_SESSION['msg'] .= ShortURL::STATE_ERROR; -} -elseif($ret === ShortURL::STATE_ALREADY_EXIST){ - $_SESSION['msg'] .= $ret; -} -else{ - $URI = $_SERVER['REQUEST_URI']; - $folders = explode('/', $URI); - if(count($folders) > 2){ - $folder = '/'.$folders[1].'/'; - }else - $folder = '/'; + 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.': http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($newname).''; - $log->message('folder : '.$folder); - - $_SESSION['msg'] .= 'Raccourci créé : http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($newname).''; - - $log->message('that makes the link : http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($newname).'"'); + $log->message('that makes the link : http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($newname).'"'); + } } - +$log->message('Redirecting to '.$folder); header('Location: '.$folder);