mirror of
https://github.com/gamaio/lobli.git
synced 2024-12-22 19:52:40 +00:00
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
This commit is contained in:
parent
4c98480648
commit
2164dd856f
@ -1,18 +1,21 @@
|
||||
<?php
|
||||
|
||||
$seperator = "ᐖ"; // Chosen because it looks like a smiling face
|
||||
require('Include/PHP/db.php');
|
||||
|
||||
// Returns will be in the structure: response code seperator extra data and will be formatted client side
|
||||
/*
|
||||
Response codes:
|
||||
0 - Successful shorten
|
||||
1 - Existing link found
|
||||
2 - Dead link
|
||||
3 - Database Error
|
||||
4 - Sanitize failed
|
||||
1 - Existing link found
|
||||
2 - Dead link
|
||||
3 - Database Error
|
||||
4 - Sanitize failed
|
||||
5 - Successful lob.li link resolve
|
||||
6 - Successful lookup of non-lob.li link
|
||||
7 - Unsuccessful lookup of non-lob.li link
|
||||
*/
|
||||
|
||||
function shorten($sdb, $link){
|
||||
function shorten($sdb, $link, $seperator){
|
||||
$sql = "SELECT * FROM `links` WHERE `link` = '$link' LIMIT 1;";
|
||||
if($result = $sdb->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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user