remove not needed functions

This commit is contained in:
mischa 2022-08-28 08:55:14 +00:00
parent 04d41647bc
commit d2d3c30b4a
1 changed files with 5 additions and 17 deletions

View File

@ -8,7 +8,7 @@ define("CHARSET", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678
$url = ""; $url = "";
$link = ""; $link = "";
$callback = "NO"; $callback = "NO";
$dbh = new PDO('mysql:host='. DB_HOST . ';dbname='. DB_NAME , DB_USER, DB_PASS);
if (DEBUG == 'true') { if (DEBUG == 'true') {
ini_set('display_errors', 1); ini_set('display_errors', 1);
@ -19,16 +19,6 @@ if (DEBUG == 'true') {
ini_set('display_startup_errors', 0); ini_set('display_startup_errors', 0);
} }
function db_connect() {
$dbh = new PDO('mysql:host='. DB_HOST . ';dbname='. DB_NAME , DB_USER, DB_PASS);
return $dbh;
}
function count_urls($dbh) {
$sth = $dbh->query("SELECT COUNT(*) FROM ". DB_TABLE);
return $sth->fetchColumn();
}
function generate_short($url, $dbh) { function generate_short($url, $dbh) {
if(!preg_match("/^((https?|ftp)[:\/\/].*\/{2,})/i",$url)) { if(!preg_match("/^((https?|ftp)[:\/\/].*\/{2,})/i",$url)) {
return false; return false;
@ -92,8 +82,7 @@ function find_short($hash, $dbh) {
if (isset($_POST['url'])) { if (isset($_POST['url'])) {
if ($_POST['url'] != '' && strlen($_POST['url']) > 0) { if ($_POST['url'] != '' && strlen($_POST['url']) > 0) {
$db = db_connect(); $link = generate_short($_POST['url'], $dbh);
$link = generate_short($_POST['url'], $db);
} else { } else {
$link = false; $link = false;
} }
@ -103,8 +92,7 @@ if (isset($_GET['hash']) && $_GET['hash'] != '' && strlen($_GET['hash']) > 0) {
$path = explode('/', $_SERVER['REQUEST_URI']); $path = explode('/', $_SERVER['REQUEST_URI']);
$uri = $path[count($path)-1]; $uri = $path[count($path)-1];
if ($uri != '') { if ($uri != '') {
$db = db_connect(); $link = find_short($uri, $dbh);
$link = find_short($uri, $db);
if ($link != '') { if ($link != '') {
header("Cache-Control: no-cache, must-revalidate"); header("Cache-Control: no-cache, must-revalidate");
header("Expires: Wed, 29 Feb 1984 00:00:00 GMT"); header("Expires: Wed, 29 Feb 1984 00:00:00 GMT");
@ -114,8 +102,8 @@ if (isset($_GET['hash']) && $_GET['hash'] != '' && strlen($_GET['hash']) > 0) {
} }
if ($callback == 'NO') { if ($callback == 'NO') {
$db = db_connect(); $sth = $dbh->query("SELECT COUNT(*) FROM ". DB_TABLE);
$count = count_urls($db); $count = $sth->fetchColumn();
?> ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html> <html>