From 39baade2e40b87a15bc2d19468d68a8de93448a6 Mon Sep 17 00:00:00 2001 From: alopexc0de Date: Sun, 10 Aug 2014 20:37:34 -0400 Subject: [PATCH] Fix check to see if link exists in db or not. This seemed like the most friendly way to do this since my other option is checking all links:id for the string of the url --- Website/Include/PHP/functions.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Website/Include/PHP/functions.php b/Website/Include/PHP/functions.php index 562de0e..3ca90df 100644 --- a/Website/Include/PHP/functions.php +++ b/Website/Include/PHP/functions.php @@ -17,19 +17,22 @@ */ function shorten($redis, $link, $linkage, $seperator){ - $short = $redis->get("links:id:$link"); + $short = $redis->get("llinks:$link"); if($short){ - $title = $redis->get("links:title:$link"); - return "1$seperator$link$seperator$title"; + $sId = $short; + $short = $redis->lrange("links:$short", 0, 1); + $title = $short[1]; + return "1$seperator$sId$seperator$title"; }else{ do { if(checkRemoteFile($link) !== true) return "2$seperator$link"; - $title = getRemoteTitle($url); + //if(($title = getRemoteTitle($url)) !== true) return "2$seperator$link"; + $title = "google"; $short = substr(number_format(time() * mt_rand(),0,'',''),0,5); $short = base_convert($short, 10, 36); - if(!$redis->exists("links:id:$short")) { + if(!$redis->exists("links:$short")) { break; } } while (1); @@ -42,10 +45,12 @@ if($linkage == '1') $xTime = 604800; if($linkage == '2') $xTime = 2628000; + $redis->set("llinks:$link", $short); $redis->rpush("links:$short", $link); $redis->rpush("links:$short", $title); $redis->rpush("links:$short", date("d/m/Y", strtotime($str))); $redis->expireAt("links:$short", $now+$xTime); + $redis->expireAt("llinks:$link", $now+$xTime); $redis->zAdd("tracking:clicks", 1, $link);