1
0
Fork 0
SemmelstatzR/semmelstatz-statz.php

501 Zeilen
Kein EOL
21 KiB
PHP

<?php
/***********************************************
* *
* semmelstatz_statz.php v3.3 *
* Copyright: © 2005-2009 kopfhoch-studio *
* *
***********************************************/
if(!current_user_can('manage_statz')) {
die('Zugriff verweigert');
}
### AKTUELL - Funktionen
function sem_showWhoIsOnline() {
global $wpdb;
$sem_options = get_option('semmelstatz_options'); ### optionsarray auslesen
$onlinetime = $sem_options["statz_online_time"];
$onlineusers = $wpdb->get_results("SELECT DISTINCT username, page, ip, time
FROM ".$wpdb->statz." WHERE time > Now() - INTERVAL ".$onlinetime." SECOND GROUP BY ip ORDER BY page DESC");
print "<div class='statz'>".sem_showNumUsersOnline()." Besucher online - Heute: ".sem_showTodayStatz()."</div>";
if (empty($onlineusers)) {
print "<small>... keine Eintr&auml;ge</small>";
print "<hr />";
return;
}
print "<table class='statzelement'>";
print "<thead>";
print "<tr>";
print "<th style='text-align:left;'>Username</th>";
print "<th style='text-align:left;'>Post/Page</th>";
print "<th style='text-align:left;'>TCP/IP</th>";
print "<th style='text-align:center;'>Zeit</th>";
print "</tr>";
print "</thead>";
print "<tbody>";
foreach ($onlineusers as $key=>$onlineuser) {
$username = $onlineuser->username;
$page = $onlineuser->page;
if ($page == 0) {
$link = get_option('siteurl');
$title = 'startseite'; //oder wie auch immer
}
else {
$link = get_permalink($page);
$title = get_post($page); // muss so sein, da get_post = ARRAY
$title = $title->post_title; // sonst könnte man gleich diese Zeile nehmen
}
$ip = $onlineuser->ip;
if(sem_checkIfIPisEncoded($ip) == true) $ip = sem_decodeIP($ip);
$time = mysql2date("H:i",$onlineuser->time);
print "<tr"; if(1&$key) print " class='alternate'"; print ">";
print "<td style='text-align:left;'>".$username."</td>";
print "<td style='text-align:left;'><a target='_blank' href=".$link.">".$title."</td>";
print "<td style='white-space:nowrap;text-align:left;'>
<a target='_blank' style='border:none;' href='http://ws.arin.net/whois/?queryinput=".$ip."'>
<img src='".get_option('siteurl')."/wp-content/plugins/semmelstatz/img/arin.png' /></a>&nbsp;
<a target='_blank' style='border:none;' href='http://www.ripe.net/whois?searchtext=".$ip."'>
<img src='".get_option('siteurl')."/wp-content/plugins/semmelstatz/img/ripe.png' /></a>&nbsp;
<a target='_blank' style='border:none;' href='http://www.utrace.de/?query=".$ip."'>
<img src='".get_option('siteurl')."/wp-content/plugins/semmelstatz/img/utrace.png' /></a></td>";
print "<td style='text-align:center;'>$time</td>";
print "</tr>";
}
print "</tbody>";
print "</table>";
print "<hr />";
}
function sem_draw24HoursGoo() {
global $wpdb;
$results = $wpdb->get_results("SELECT time as hours, COUNT(DISTINCT ip) as visitors
FROM ".$wpdb->statz." WHERE time >= NOW() - INTERVAL 23 HOUR GROUP BY HOUR(time) ORDER BY time ASC");
print "<div class='statz'>Besucher: Die letzten 24 Stunden</div>";
print "<div align='left'>";
if (empty($results)) {
print "<small>... noch keine Eintr&auml;ge</small></div>";
print "<hr />";
return;
}
foreach ($results as $result) {
$visitors[] = $result->visitors;
$hours[] = mysql2date('H', $result->hours);
}
$maxvalue = max($visitors);
$visitors = implode(',', $visitors);
$hours = "|".implode('|', $hours)."|";
$charturl = "http://chart.apis.google.com/chart?";
$chartsize = "chs=600x150&";
$charttype = "cht=bvs&";
$chartgrid = "chg=25,25&";
$chartdata = "chd=t:".$visitors."&";
$chartminmax = "chds=0,".$maxvalue."&";
$barsize = "chbh=a&";
$axis = "chxt=x,y&";
$axisdataX = "chxl=0:".$hours;
$axisdataY = "1:|0|".$maxvalue."&";
$datalabels = "chm=N,000000,0,-1,10";
$chart = $charturl.$chartsize.$charttype.$chartgrid.$chartdata.$chartminmax.$barsize.$axis.$axisdataX.$axisdataY.$datalabels;
print "<div class='chart'>";
print "<img src=".$chart." alt='Chart nicht verf&uuml;gbar'/>";
print "</div>";
print "</div>";
print "<hr />";
}
function sem_showDailyStatz() {
global $wpdb;
$sem_options = get_option('semmelstatz_options'); ### optionsarray auslesen
$limit = $sem_options["statz_days_limit"];
$daylimit = $limit - 1;
$thedays = $wpdb->get_results("SELECT COUNT(ip) AS hits, COUNT(DISTINCT ip) AS visitors, COUNT(DISTINCT referer)
AS referers, substring(time,1,10) AS date FROM ".$wpdb->statz." WHERE time >= CURDATE() - INTERVAL ".$daylimit." DAY
GROUP BY date ORDER BY time DESC");
print "<div class='statz'>".$limit."-Tage-Statistik</div>";
if (empty($thedays)) {
print "<small>... noch keine Eintr&auml;ge</small>";
print "<hr />";
return;
}
print "<table class='statzelement'>";
print "<thead>";
print "<tr>";
print "<th style='text-align:left;'>Datum</th>";
print "<th style='width: 15%;text-align:center;'>Besucher</th>";
print "<th style='width: 15%;text-align:center;'>Hits</th>";
print "<th style='width: 15%;text-align:center;'>Referer</th>";
print "</tr>";
print "</thead>";
print "<tbody>";
foreach ($thedays as $key=>$theday) {
$date = $theday->date;
$date = strtotime(substr($theday->date,1,10));
$today = time();
$difference = ceil(($today - $date) / (60*60*24))-1;
if($difference == 0) {
$date = "Heute";
}
elseif($difference == 1) {
$date = "Gestern";
}
elseif($difference == 2) {
$date = "Vorgestern";
}
else {
$date = mysql2date("d.m.Y",$theday->date);
}
$hits = $theday->hits;
$visitors = $theday->visitors;
$referers = $theday->referers;
print "<tr"; if(1&$key) print " class='alternate'"; print ">";
print "<td style='text-align:left;'>$date</td>";
print "<td style='text-align:center;'>$visitors</td>";
print "<td style='text-align:center;'>$hits</td>";
print "<td style='text-align:center;'>$referers</td>";
print "</tr>";
}
print "<tr>";
print "<td style='text-align:left;'><a href='".get_option('siteurl')."/wp-admin/admin.php?page=semmelstatz/semmelstatz-history.php'>mehr...</a></td>";
print "</tr>";
print "</tbody>";
print "</table>";
print "<hr />";
}
function sem_showReferers() {
global $wpdb, $homehost;
$sem_options = get_option('semmelstatz_options'); ### optionsarray auslesen
$limit = $sem_options["statz_referer_limit"];
$mask = $sem_options["statz_mask_referer"];
$lastreferers = $wpdb->get_results("SELECT DISTINCT referer, time FROM ".$wpdb->statz." WHERE referer
NOT LIKE '".$homehost."' ORDER BY time DESC LIMIT 0, ".$limit);
print "<div class='statz'>Die letzten ".$limit." Referer</div>";
if (empty($lastreferers)) {
print "<small>... noch keine Eintr&auml;ge</small>";
print "<hr />";
return;
}
print "<table class='statzelement'>";
print "<thead>";
print "<tr>";
print "<th style='text-align:center;width:12%;'>Zeit</th>";
print "<th style='text-align:left;'>Referer</th>";
print "</tr>";
print "</thead>";
print "<tbody>";
foreach ($lastreferers as $key=>$lastreferer) {
$referer = $lastreferer->referer;
if(strlen($referer) >= 120) {
$printreferer = substr($referer, 0, 120)." ...";
}
else {
$printreferer = $referer;
}
$time = mysql2date("d.m.Y - H:i",$lastreferer->time);
print "<tr"; if(1&$key) print " class='alternate'"; print ">";
print "<td style='text-align:center;'>".$time."</td>";
if($mask != true) {
print "<td style='text-align:left;'><a target='_blank' href='".$referer."'>".$printreferer."</a></td>";
}
else {
$referer = htmlspecialchars($referer, ENT_QUOTES);
print "<td style='text-align:left;'><a target='_blank' href='http://www.google.com/url?sa=D&q=".$referer."'>".$printreferer."</a></td>";
}
print "</tr>";
}
print "</tbody>";
print "</table>";
print "<hr />";
}
function sem_showKeyword() {
global $wpdb;
$sem_options = get_option('semmelstatz_options'); ### optionsarray auslesen
$limit = $sem_options["statz_keyword_limit"];
$results = $wpdb->get_results("SELECT referer, time, ip FROM $wpdb->statz WHERE referer != 'NULL' ORDER BY time DESC");
print "<div class='statz'>Die letzten $limit Suchbegriffe</div>";
if (empty($results)) {
print "<small>... noch keine Eintr&auml;ge</small>";
print "<hr />";
return;
}
print "<table class='statzelement'>";
print "<thead>";
print "<tr>";
print "<th style='text-align: center;width:12%;'>Zeit</th>";
print "<th style='text-align:left;width:70%;'>Suchbegriff</th>";
print "<th style='text-align:left;'>TCP/IP</th>";
print "</tr>";
print "</thead>";
print "<tbody>";
$i=0;
foreach($results as $result) {
$referer = $result->referer;
$keyword = sem_getKeyword($referer);
$ip = $result->ip;
if(sem_checkIfIPisEncoded($ip) == true) $ip = sem_decodeIP($ip);
$time = mysql2date('d.m.Y - H:i',$result->time);
if($keyword) {
print "<tr"; if(1&$i) print " class='alternate'"; print ">";
print "<td style='text-align: center;'>".$time."</td>";
print "<td style='text-align: left;'><a target='_blank' href='".str_replace(' ','+',htmlspecialchars($referer, ENT_QUOTES))."'>".$keyword."</a></td>";
print "<td style='text-align: left;vertical-align:bottom;'>
<a target='_blank' href='http://ws.arin.net/whois/?queryinput=".$ip."'>
<img src='".get_option('siteurl')."/wp-content/plugins/semmelstatz/img/arin.png' /></a>&nbsp;
<a target='_blank' href='http://www.ripe.net/whois?searchtext=".$ip."'>
<img src='".get_option('siteurl')."/wp-content/plugins/semmelstatz/img/ripe.png' /></a>&nbsp;
<a target='_blank' href='http://www.utrace.de/?query=".$ip."'>
<img src='".get_option('siteurl')."/wp-content/plugins/semmelstatz/img/utrace.png' /></a></td>";
print "</tr>";
$i++;
}
if($i == $limit) break;
}
print "</tbody>";
print "</table>";
print "<hr />";
}
function sem_showTodayTopReads() {
global $wpdb;
$today = date("Y-m-d");
$topreads = $wpdb->get_results("SELECT post_title AS posttitle, post_name as postname, guid AS postid,
COUNT(".$wpdb->statz.".page) AS count FROM ".$wpdb->posts.", ".$wpdb->statz." WHERE
".$wpdb->statz.".page = ".$wpdb->posts.".ID AND time >= '$today' GROUP BY postid ORDER BY count DESC LIMIT 10");
print "<div class='statz'>Die Top10 aller Posts & Pages heute</div>";
if (empty($topreads)) {
print "<small>... noch keine Eintr&auml;ge</small>";
print "<hr />";
return;
}
print "<table class='statzelement'>";
print "<thead>";
print "<tr>";
print "<th style='text-align: left; width: 45%;'>Post/Page</th>";
print "<th style='text-align: left; width: 45%;'>Postname</th>";
print "<th style='text-align: center; width: 10%;'>Hits</th>";
print "</tr>";
print "</thead>";
print "<tbody>";
foreach ($topreads as $key=>$topread) {
$posttitle = $topread->posttitle;
$postname = $topread->postname;
$postid = $topread->postid;
$count = $topread->count;
print "<tr"; if(1&$key) print " class='alternate'"; print ">";
print "<td style='text-align: left;'><a target='_blank' href='$postid'>".$posttitle."</a></td>";
print "<td style='text-align: left;'>".$postname."</td>";
print "<td style='text-align: center;'>".$count."</td>";
print "</tr>";
}
print "</tbody>";
print "</table>";
print "<hr />";
}
function sem_showTopReads() {
global $wpdb;
$sem_options = get_option('semmelstatz_options'); ### optionsarray auslesen
$limit = $sem_options["statz_topreads_limit"];
$topreads = $wpdb->get_results("SELECT post_title AS posttitle, post_name as postname, guid AS postid,
hits AS count FROM ".$wpdb->posts." WHERE hits != '0' GROUP BY postid ORDER BY hits DESC LIMIT 0, ".$limit);
print "<div class='statz'>Die Top".$limit." aller Posts & Pages</div>";
if (empty($topreads)) {
print "<small>... noch keine Eintr&auml;ge</small>";
print "<hr />";
return;
}
print "<table class='statzelement'>";
print "<thead>";
print "<tr>";
print "<th style='text-align: left; width: 45%;'>Post/Page</th>";
print "<th style='text-align: left; width: 45%;'>Postname</th>";
print "<th style='text-align: center; width: 10%;'>Hits</th>";
print "</tr>";
print "</thead>";
print "<tbody>";
foreach ($topreads as $key=>$topread) {
$posttitle = $topread->posttitle;
$postname = $topread->postname;
$postid = $topread->postid;
$count = $topread->count;
print "<tr"; if(1&$key) print " class='alternate'"; print ">";
print "<td style='text-align: left;'><a target='_blank' href='".$postid."'>".$posttitle."</a></td>";
print "<td style='text-align: left;'>".$postname."</td>";
print "<td style='text-align: center;'>".$count."</td>";
print "</tr>";
}
print "</tbody>";
print "</table>";
print "<hr />";
}
function sem_showWhoWasOnlineToday() {
global $wpdb;
$today = date("Y-m-d");
$todaysonlineusers = $wpdb->get_results("SELECT DISTINCT username, COUNT(username) as num FROM ".$wpdb->statz." WHERE
time >= '$today' AND username != 'Gast' GROUP BY username ORDER BY num DESC");
print "<div class='statz'>Bekannte Besucher heute</div>";
if (empty($todaysonlineusers)) {
print "<small>... noch keine Eintr&auml;ge</small>";
print "<hr />";
return;
}
print "<table class='statzelement'>";
print "<thead>";
print "<tr>";
print "<th style='text-align: left; width: 80%;'>Besucher (Hits)</th>";
print "</tr>";
print "</thead>";
print "<tbody>";
foreach ($todaysonlineusers as $key=>$todayonlineuser) {
$username = $todayonlineuser->username;
$num = $todayonlineuser->num;
print "<tr"; if(1&$key) print " class='alternate'"; print ">";
print "<td style='text-align: left;'>".$username." (".$num.")</td>";
print "</tr>";
}
print "</tbody>";
print "</table>";
print "<hr />";
}
function sem_showTopCommented() {
global $wpdb;
$topcommentedposts = $wpdb->get_results("SELECT guid, id, post_title, COUNT(*) AS count FROM
".$wpdb->comments.",". $wpdb->posts." WHERE comment_approved = '1' AND comment_post_id = id
GROUP BY guid ORDER BY count DESC LIMIT 0, 10");
print "<div class='statz'>Die Top10 aller kommentierter Posts</div>";
if (empty($topcommentedposts)) {
print "<small>... noch keine Eintr&auml;ge</small>";
print "<hr />";
return;
}
print "<table class='statzelement'>";
print "<thead>";
print "<tr>";
print "<th style='text-align: left; width: 80%;'>Post/Page</th>";
print "<th style='text-align: center; width: 20%;'>Kommentare</th>";
print "</tr>";
print "</thead>";
print "<tbody>";
foreach ($topcommentedposts as $key => $topcommentedpost) {
$posttitle = $topcommentedpost->post_title;
$count = $topcommentedpost->count;
$postid = $topcommentedpost->guid;
print "<tr"; if(1&$key) print " class='alternate'"; print ">";
print "<td style='text-align: left;'><a target='_blank' href='".$postid."'>&nbsp;".$posttitle."</a></td>";
print "<td style='text-align: center;'>".$count."</td>";
print "</tr>";
}
print "</tbody>";
print "</table>";
print "<hr />";
}
function sem_showCommenters() {
global $wpdb;
$sem_options = get_option('semmelstatz_options'); ### optionsarray auslesen
$limit = $sem_options["statz_comment_limit"];
$topcommenters = $wpdb->get_results("SELECT comment_author AS commenter, COUNT(comment_ID) AS count,
comment_author_email AS email, comment_author_url AS homepage FROM " .$wpdb->comments . " WHERE
comment_approved = '1' GROUP BY comment_author ORDER BY count DESC LIMIT 0, ".$limit);
print "<div class='statz'>Die Top".$limit." aller Kommentierer</div>";
if (empty($topcommenters)) {
print "<small>... noch keine Eintr&auml;ge</small>";
print "<hr />";
return;
}
print "<table class='statzelement'>";
print "<thead>";
print "<tr>";
print "<th style='text-align: left; width: 20%;'>User</th>";
print "<th style='text-align: left; width: 30%;'>Email</th>";
print "<th style='text-align: left; width: 40%;'>Homepage</th>";
print "<th style='text-align: center; width: 10%;'>Kommentare</th>";
print "</tr>";
print "</thead>";
print "<tbody>";
foreach ($topcommenters as $key=>$topcommenter) {
$commenter = $topcommenter->commenter;
$email = $topcommenter->email;
$homepage = $topcommenter->homepage;
if($homepage=="http://") $homepage="";
$url=parse_url($homepage);
$homepage = $url['host'];
$count = $topcommenter->count;
print "<tr"; if(1&$key) print " class='alternate'"; print ">";
print "<td style='text-align: left;'>".$commenter."</td>";
print "<td style='text-align: left;'><a href='mailto:".$email."'>".$email."</a></td>";
print "<td style='text-align: left;'><a target='_blank' href='http://".$homepage."'>".$homepage."</a></td>";
print "<td style='text-align: center;'>".$count."</td>";
print "</tr>";
}
print "</tbody>";
print "</table>";
print "<hr />";
}
### AKTUELL Anzeige
print "<div class='wrap'>";
print "<div><a name='top'></a></div>";
print "<div id='icon-semmelstatz' class='icon32'><br /></div>";
print "<h2>Semmelstatz &rsaquo; Aktuell</h2>";
$sem_options = get_option('semmelstatz_options'); ### optionsarray auslesen
if ($sem_options["statz_show_useronline"]) sem_showWhoIsOnline();
sem_draw24HoursGoo();
if ($sem_options["statz_show_todayusers"]) sem_showWhoWasOnlineToday();
if ($sem_options["statz_show_dailystatz"]) sem_showDailyStatz();
if ($sem_options["statz_show_referers"]) sem_showReferers();
if ($sem_options["statz_show_keywords"]) sem_showKeyword();
if ($sem_options["statz_show_todayreads"]) sem_showTodayTopReads();
if ($sem_options["statz_show_reads"]) sem_showTopReads();
if ($sem_options["statz_show_topcommposts"]) sem_showTopCommented();
if ($sem_options["statz_show_commenters"]) sem_showCommenters();
sem_showCopyright();
print "</div>";
?>