mirror of
https://github.com/gamaio/lobli.git
synced 2025-01-03 15:52:42 +00:00
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
This commit is contained in:
parent
9e1035fde3
commit
39baade2e4
@ -17,19 +17,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function shorten($redis, $link, $linkage, $seperator){
|
function shorten($redis, $link, $linkage, $seperator){
|
||||||
$short = $redis->get("links:id:$link");
|
$short = $redis->get("llinks:$link");
|
||||||
if($short){
|
if($short){
|
||||||
$title = $redis->get("links:title:$link");
|
$sId = $short;
|
||||||
return "1$seperator$link$seperator$title";
|
$short = $redis->lrange("links:$short", 0, 1);
|
||||||
|
$title = $short[1];
|
||||||
|
return "1$seperator$sId$seperator$title";
|
||||||
}else{
|
}else{
|
||||||
do {
|
do {
|
||||||
if(checkRemoteFile($link) !== true) return "2$seperator$link";
|
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 = substr(number_format(time() * mt_rand(),0,'',''),0,5);
|
||||||
$short = base_convert($short, 10, 36);
|
$short = base_convert($short, 10, 36);
|
||||||
|
|
||||||
if(!$redis->exists("links:id:$short")) {
|
if(!$redis->exists("links:$short")) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (1);
|
} while (1);
|
||||||
@ -42,10 +45,12 @@
|
|||||||
if($linkage == '1') $xTime = 604800;
|
if($linkage == '1') $xTime = 604800;
|
||||||
if($linkage == '2') $xTime = 2628000;
|
if($linkage == '2') $xTime = 2628000;
|
||||||
|
|
||||||
|
$redis->set("llinks:$link", $short);
|
||||||
$redis->rpush("links:$short", $link);
|
$redis->rpush("links:$short", $link);
|
||||||
$redis->rpush("links:$short", $title);
|
$redis->rpush("links:$short", $title);
|
||||||
$redis->rpush("links:$short", date("d/m/Y", strtotime($str)));
|
$redis->rpush("links:$short", date("d/m/Y", strtotime($str)));
|
||||||
$redis->expireAt("links:$short", $now+$xTime);
|
$redis->expireAt("links:$short", $now+$xTime);
|
||||||
|
$redis->expireAt("llinks:$link", $now+$xTime);
|
||||||
|
|
||||||
$redis->zAdd("tracking:clicks", 1, $link);
|
$redis->zAdd("tracking:clicks", 1, $link);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user