introduced statistics, landing page and more eyecandy

This commit is contained in:
Sven Zemanek
2013-08-24 19:06:36 +02:00
parent 63c8ff8a4a
commit f6db00b69e
11 changed files with 349 additions and 102 deletions

99
includes/file.php Normal file
View File

@@ -0,0 +1,99 @@
<?php
function add_visit($id, $file){
$visits = get_visits($id, $file);
if($visits != null){
$date = date('Ymd');
if(!isset($visits[$date][$id])){
$visits[$date][$id] = 1;
} else {
$visits[$date][$id] = $visits[$date][$id] + 1;
}
set_visits($visits, $file);
} else {
echo '<!-- ERROR konnte Besuche nicht zählen -->';
}
}
function get_visits($id, $file){
if(!file_exists($file)){
$visits[date('Ymd')][$id] = 0;
return $visits;
}
if(is_readable($file)){
$handle = fopen($file, 'r');
$contents = fread($handle, filesize($file));
fclose($handle);
$visits = unserialize($contents);
return $visits;
} else {
echo "<!-- ERROR $file kann nicht gelesen werden! -->";
return null;
}
}
function set_visits($visits, $file){
if(is_writable($file) or (is_writable(dirname($file)) and !file_exists($file))){
$handle = fopen($file, 'w');
if (!fwrite($handle, serialize($visits))) {
echo "<!-- ERROR Kann in die Datei $file nicht schreiben -->";
}
fclose($handle);
} else {
echo "<!-- ERROR $file nicht beschreibbar! -->";
}
}
function get_salt($hashfile){
// a) file does not exist yet
if(!file_exists($hashfile)){
if(is_writable(dirname($hashfile))){
$hash[0] = date('Ymd');
$hash[1] = mt_rand();
$handle = fopen($hashfile, 'w');
if (!fwrite($handle, serialize($hash))) {
echo "<!-- ERROR Kann in die Datei $hashfile nicht schreiben -->";
}
fclose($handle);
} else {
echo "<!-- ERROR Kann Datei $hashfile nicht erstellen! -->";
}
}
if(is_readable($hashfile)){
$handle = fopen($hashfile, 'r');
$contents = fread($handle, filesize($hashfile));
fclose($handle);
$hash = unserialize($contents);
// b) hash is not of today
if($hash[0] != date('Ymd')){
$hash[0] = date('Ymd');
$hash[1] = mt_rand();
$handle = fopen($hashfile, 'w');
if (!fwrite($handle, serialize($hash))) {
echo "<!-- ERROR Kann in die Datei $hashfile nicht schreiben -->";
}
fclose($handle);
}
return $hash[1];
} else {
echo "<!-- ERROR $file kann nicht gelesen werden! -->";
return 1;
}
}
?>

View File

@@ -210,7 +210,7 @@ function code_to_answer($code){
if($i == $curr){
return '<li class="active"><a href="#">'.$i."</a></li>\n";
} else {
return '<li class=""><a href="index.php?id='.$i.'">'.$i."</a></li>\n";
return '<li class=""><a href="mahlowat.php?id='.$i.'">'.$i."</a></li>\n";
}
}