From 2164dd856fac833581fd4a49e4fa84dd6e3a4080 Mon Sep 17 00:00:00 2001 From: alopexc0de Date: Thu, 3 Jul 2014 15:16:57 -0400 Subject: [PATCH] Update response code list, Add site descriptions, basic link tracking The link tracking is very basic, but it doesn't need to be any more complicated than it already is --- Website/Include/PHP/functions.php | 50 +++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/Website/Include/PHP/functions.php b/Website/Include/PHP/functions.php index 88c6376..8200965 100644 --- a/Website/Include/PHP/functions.php +++ b/Website/Include/PHP/functions.php @@ -1,18 +1,21 @@ query($sql)){ if($row = $result->fetch_assoc()){ @@ -21,20 +24,49 @@ } } if(checkRemoteFile($link) !== true) return "2$seperator$link"; + $title = getRemoteTitle($link); + $short = substr(number_format(time() * mt_rand(),0,'',''),0,5); $short = base_convert($short, 10, 36); $dpass = substr(number_format(time() * mt_rand(),0,'',''),0,10); $dpass = base_convert($short.$dpass, 10, 36); - $sql = "INSERT INTO `links` (link, shortlink, dpass) VALUES ('$link', '$short', '$dpass')"; + $sql = "INSERT INTO `links` (link, shortlink, title, dpass, ddate) VALUES ('$link', '$short', '$title', '$dpass', NOW())"; - - if($result = $sdb->query($sql)): return "0$seperator$short"; + if($result = $sdb->query($sql)): return "0$seperator$short$seperator$title"; else: return '3'.$seperator.$sdb->error; endif; } + function stats($sdb, $seperator){ + + } + + function tracking($sdb, $lId){ // Very basic - counts number of total visits to a certain short link + $sql = "SELECT * FROM `tracking` WHERE `id` = '$lId' LIMIT 1;"; // Testing to see if the link has been visited before + if($result = $sdb->query($sql)){ + if($row = $result->fetch_assoc()){ + $sql = "UPDATE `tracking` SET `clicks` = `clicks` + 1 WHERE `id` = '$lId'"; // Yes it has, increment clicks by 1 + if($result = $sdb->query($sql)){}else{ + return $sdb->error; + } + } + }else{ + $sql = "INSERT INTO `tracking` (id, clicks) VALUES ('$lId', 1)"; // No it hasn't, add 1 click to the table + if($result = $sdb->query($sql)){}else{ + return $sdb->error; + } + } + } + + function getRemoteTitle($url){ + $url = parse_url($url); + $tags = get_meta_tags($url['scheme'].'://'.$url['host']); + $ret = sanitize($tags['description']); + return $ret; + } + function checkRemoteFile($ip=null){ if($ip==null) return false;