-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathredirect.php
93 lines (75 loc) · 2.19 KB
/
redirect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
require_once('autoload.php');
require_once('includes/config.php');
use includes\system;
/**
* Class API
*/
class redirect
{
/**
* @var system|null
*/
private $oSys = null;
/**
* API constructor.
*/
public function __construct()
{
$this->oSys = system::getInstance();
$this->execute();
}
/**
*
*/
private function execute()
{
$sRequestURI = $_SERVER["REQUEST_URI"];
//Kurz URL finden
$ex = explode('/', $sRequestURI);
if (count($ex) == 3)
{
$sShort = $ex[1];
}
else
{
$sShort = preg_replace('%/%', '', $sRequestURI);
}
$oResult = $this->oSys->oDB->query('SELECT * FROM urls WHERE short = \''.str_replace('+', '', $sShort).'\'');
$aResult = $oResult->fetch();
if ($aResult == false) {
header('Location: '.SITEURL);
return;
}
if ($aResult['abuse'] == '1') {
header('Location: '.SITEURL.'/abuse.html');
return;
}
if ($sShort[strlen($sShort)-1] == '+') {
$this->showStat($aResult);
return;
}
$this->oSys->oDB->exec('INSERT INTO stat(`url`, `time`) VALUES ('.$aResult['id'].', '.time().')');
header('Location: '.$aResult['long']);
return;
}
private function showStat($aData) {
$this->oSys->oTpl->addTemplate('design.tpl');
$this->oSys->oTpl->appendTemplate('stat.tpl', array('url_short' => SITEURL.'/'.$aData['short'], 'url_long' => $aData['long']), 'CONTENT');
$oResult = $this->oSys->oDB->query('SELECT * FROM stat WHERE url = '.$aData['id']);
$aStat = array();
while ($aRow = $oResult->fetch()) {
if (!isset($aStat[date('d.m.Y', $aRow['time'])])) {
$aStat[date('d.m.Y', $aRow['time'])] = 1;
} else {
$aStat[date('d.m.Y', $aRow['time'])]++;
}
}
foreach($aStat as $sDatum => $iCnt) {
$this->oSys->oTpl->setBlock('ZEILE', array('datum' => $sDatum, 'cnt' => $iCnt));
}
$this->oSys->oTpl->showOutput();
}
}
new redirect();
?>