mirror of
https://github.com/gamaio/lobli.git
synced 2024-12-22 19:52:40 +00:00
Change click tracking to sorted set.
Using a sorted set makes it easier to sort from highest to lowest on the stats page. Minor change how tracking is done on the index and link checking has been updated.
This commit is contained in:
parent
485f1fa66f
commit
4ad0f8ce74
@ -47,8 +47,7 @@
|
|||||||
$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->set("tracking:clicks:$link", 1);
|
$redis->zAdd("tracking:clicks", 1, $link);
|
||||||
$redis->expireAt("tracking:clicks:$link", $now+$xTime);
|
|
||||||
|
|
||||||
return "0$seperator$short$seperator$title";
|
return "0$seperator$short$seperator$title";
|
||||||
}
|
}
|
||||||
|
@ -38,21 +38,19 @@
|
|||||||
if(!in_array($_SERVER['REMOTE_ADDR'], $ipTrack)){ // Check to see if visiter hit this link before (This would make it a lot easier to skew statistics if anyone would register multiples times)
|
if(!in_array($_SERVER['REMOTE_ADDR'], $ipTrack)){ // Check to see if visiter hit this link before (This would make it a lot easier to skew statistics if anyone would register multiples times)
|
||||||
$redis->rPush("tracking:ip:$link", $_SERVER['REMOTE_ADDR']);
|
$redis->rPush("tracking:ip:$link", $_SERVER['REMOTE_ADDR']);
|
||||||
|
|
||||||
// Tracking code
|
$trTtl = $redis->ttl("links:$link");
|
||||||
$tracking = $redis->get("tracking:clicks:$link");
|
|
||||||
$trTtl = $redis->ttl("links:id:$link");
|
|
||||||
|
|
||||||
if(!$tracking || $trTtl != -2){
|
if($trTtl != -2){
|
||||||
$tracking = $redis->set("tracking:clicks:$link", 1);
|
$tracking = $redis->zIncrBy("tracking:clicks", 1, $link);
|
||||||
}else{
|
}else{
|
||||||
if($trTtl == -2){ // The link has been deleted, no need to track it anymore
|
if($trTtl == -2){ // The link has been deleted, no need to track it anymore
|
||||||
|
$redis->zRem("tracking:clicks", $link);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$tracking = $redis->incr("tracking:clicks:$link");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$short = $redis->get("links:id:$link");
|
$short = $redis->get("links:$link");
|
||||||
if($short){
|
if($short){
|
||||||
echo $short;
|
echo $short;
|
||||||
exit(5);
|
exit(5);
|
||||||
|
@ -45,20 +45,23 @@
|
|||||||
|
|
||||||
require('Include/PHP/db.php');
|
require('Include/PHP/db.php');
|
||||||
|
|
||||||
$stats = $redis->keys("tracking:clicks:*");
|
$stats = $redis->zRangeByScore("tracking:clicks", "-inf", "+inf");
|
||||||
rsort($stats);
|
$stats = array_reverse($stats);
|
||||||
$stats = array_slice($stats, 0, 5, true);
|
$stats = array_slice($stats, 0, 5, true);
|
||||||
|
|
||||||
foreach($stats as $stat){ // There should only be 5, but the page doesn't limit how many
|
foreach($stats as $id){ // There should only be 5, but the page doesn't limit how many
|
||||||
$id = explode(":", $stat);
|
$trTtl = $redis->ttl("links:$id");
|
||||||
$id = $id[2]; // Grab just the short link ID
|
if($trTtl == -2){ // The link has been deleted, no need to track it anymore
|
||||||
|
$redis->zRem("tracking:clicks", $id;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$linkData = $redis->lRange("links:$id", 0, -1);
|
$linkData = $redis->lRange("links:$id", 0, -1);
|
||||||
|
|
||||||
$link = $linkData[0];
|
$link = $linkData[0];
|
||||||
$title = $linkData[1];
|
$title = $linkData[1];
|
||||||
$date = $linkData[2];
|
$date = $linkData[2];
|
||||||
$trackClicks = $redis->get("tracking:clicks:$id");
|
$trackClicks = $redis->zScore("tracking:clicks", $id);
|
||||||
|
|
||||||
echo "
|
echo "
|
||||||
<tr class=\"success\">
|
<tr class=\"success\">
|
||||||
|
Loading…
Reference in New Issue
Block a user