1
0
Fork 0

images and localizing

Dieser Commit ist enthalten in:
oldperl 2011-08-23 14:08:57 +00:00
Ursprung a23cd6e222
Commit 29b005c9f4
8 geänderte Dateien mit 997 neuen und 893 gelöschten Zeilen

Binäre Datei nicht angezeigt.

BIN
trunk/_psd/statz_small.psd Normale Datei

Binäre Datei nicht angezeigt.

BIN
trunk/img/statzR.png Normale Datei

Binäre Datei nicht angezeigt.

Nachher

Breite:  |  Höhe:  |  Größe: 6,6 KiB

Datei anzeigen

@ -0,0 +1,473 @@
<?php
############################################## SEMMELSTATZ-interne Funktionen
### Encodierung der IP-Adresse durch simple arithmetische Operation
function sem_encodeIP($ip) {
$ip_parts = split("[.]", $ip);
$new_ip = ($ip_parts[0]+700) . "." . ($ip_parts[1]*2) . "." . ($ip_parts[2]+600) . "." . ($ip_parts[3]*3);
return $new_ip;
}
### Decodierung der IP-Adresse durch simple arithmetische Operation
function sem_decodeIP($ip) {
$ip_parts = split("[.]", $ip);
$new_ip = ($ip_parts[0]-700) . "." . ($ip_parts[1] / 2) . "." . ($ip_parts[2]-600) . "." . ($ip_parts[3]/3);
return $new_ip;
}
### Ist IP-Adresse codiert?
function sem_checkIfIPisEncoded($ip) {
$ip_parts = split("[.]", $ip);
if($ip_parts[0]>700) {
return true;
}
else {
return false;
}
}
### Auslesen der höchsten Post-ID
function sem_getMaxPostID() {
global $wpdb;
$maxpostid = $wpdb->get_var("SELECT MAX(ID) FROM ".$wpdb->posts." LIMIT 0,1");
return $maxpostid; //Ganzzahl
}
### Auslesen des User- bzw. Kommentarautornamen
function sem_getUsername() {
global $user_ID, $user_login, $isAdmin;
get_currentuserinfo();
if($user_ID > 0) {
$useronline = $user_login;
if(current_user_can('manage_options')) {
$isAdmin = 1;
}
else {
$isAdmin = 0;
}
}
elseif(isset($_COOKIE["comment_author_".COOKIEHASH])) {
$useronline = trim($_COOKIE["comment_author_".COOKIEHASH]);
$isAdmin = -1;
}
else {
$useronline = "Gast";
$isAdmin = -1;
}
return $useronline;
}
### Prüfen, ob Besucher ein Bot ist
function sem_AreYouBot($user_agent) {
global $isBot;
$bots = array(
'aipbot',
'amfibibot',
'appie',
'ask jeeves/teoma',
'aspseek',
'axadine',
'baiduspider',
'becomebot',
'blogcorpuscrawler',
'blogpulse',
'blogsnowbot',
'boitho.com',
'bruinbot',
'cerberian',
'cfnetwork',
'check_http',
'cipinetbot',
'claymont',
'cometsearch@cometsystems.com',
'converacrawler',
'cydralspider',
'digger',
'es.net_crawler',
'eventax',
'everyfeed-spider',
'exabot@exava.com',
'faxobot',
'findlinks',
'fireball',
'francis',
'gaisbot',
'gamekitbot',
'gazz@nttr.co.jp',
'geonabot',
'getrax crawler',
'gigabot',
'girafa.com',
'goforitbot',
'googlebot',
'grub-client',
'holmes',
'houxoucrawler',
'http://www.almaden.ibm.com/cs/crawler',
'http://www.istarthere.com',
'http://www.relevantnoise.com',
'httrack ?',
'ia_archiver',
'ichiro',
'iltrovatore-setaccio',
'inelabot',
'infoseek',
'inktomi.com',
'irlbot',
'jetbot',
'jobspider_ba',
'kazoombot',
'larbin',
'libwww',
'linkwalker',
'lmspider',
'mackster',
'mediapartners-google',
'microsoft url control',
'mj12bot',
'moreoverbot',
'mozdex',
'msnbot',
'msrbot',
'naverbot',
'netresearchserver',
'ng/2.0',
'np(bot)',
'nutch',
'objectssearch',
'ocelli',
'omniexplorer_bot',
'openbot',
'overture',
'patwebbot',
'php',
'phpdig',
'pilgrim html-crawler',
'pipeliner',
'pompos',
'psbot',
'python-urllib',
'quepasacreep',
'robozilla',
'rpt-httpclient',
'savvybot',
'scooter',
'search.ch',
'seekbot',
'semager',
'seznambot',
'sherlock',
'shelob',
'sitesearch',
'snapbot',
'snappreviewbot',
'speedy spider',
'sphere scout',
'stackrambler',
'steeler',
'surveybot',
'szukacz',
'technoratibot',
'telnet',
'themiragorobot',
'thesubot',
'thumbshots-de-bot',
'topicblogs',
'turnitinbot',
'tutorgigbot',
'tutorial crawler',
'twiceler',
'vagabondo',
'versus',
'voilabot',
'w3c_css_validator',
'w3c_validator',
'w3c-checklink',
'web downloader',
'webcopier',
'webcrawler',
'webfilter robot',
'west wind internet protocols',
'wget',
'wwweasel robot',
'wwwster',
'xaldon webspider',
'xenu',
'yahoo! slurp',
'yahoofeedseeker',
'yahoo-mmcrawler',
'zao',
'zipppbot',
'zyborg',
);
foreach($bots as $bot) {
if(stristr($user_agent, $bot) !== false) {
return true;
}
}
return false;
}
### Referer nach Suchmaschinen-Queries und interner Suche prüfen und Suchstring extrahieren
function sem_getKeyword($referer) {
$keyword = @parse_url($referer);
if (preg_match("/google\./i", $keyword["host"])) {
if (preg_match("/imgurl/i", $keyword["query"])) {
parse_str($keyword["query"],$q);
$keyword = substr($q["prev"],10);
}
else if (preg_match("/translate\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
}
else {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
}
if($keyword == "") return; return "Google: ".$keyword;
}
elseif (preg_match("/search\.live\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "LiveSearch: ".$keyword;
}
elseif (preg_match("/bing\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "Bing: ".$keyword;
}
elseif (preg_match("/yahoo\./i", $keyword["host"])) {
if (preg_match("/images/i", $keyword["query"])) {
parse_str($keyword["query"],$q);
$keyword = $q["p"];
}
else {
parse_str($keyword["query"],$q);
$keyword = $q["p"];
}
if($keyword == "") return; return "Yahoo: ".$keyword;
}
elseif (preg_match("/aol\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "AOL: ".$keyword;
}
elseif (preg_match("/aolsvc\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "AOL: ".$keyword;
}
elseif (preg_match("/search\.msn\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "MSN: ".$keyword;
}
elseif (preg_match("/gmx\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["su"];
if($keyword == "") return; return "GMX: ".$keyword;
}
elseif (preg_match("/\.bild\.t\-/i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["query"];
if($keyword == "") return; return "BILD: ".$keyword;
}
elseif (preg_match("/t\-online\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "T-Online: ".$keyword;
}
elseif (preg_match("/suche\.web\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["su"];
if($keyword == "") return; return "WEB.de: ".$keyword;
}
elseif (preg_match("/suche\.lycos\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["query"];
if($keyword == "") return; return "Lycos: ".$keyword;
}
elseif (preg_match("/altavista\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "Altavista: ".$keyword;
}
elseif (preg_match("/alltheweb\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "alltheweb: ".$keyword;
}
elseif (preg_match("/technorati\.com\/search\//", $referer)) {
$q = preg_split("/technorati\.com\/search\//", $referer,-1,PREG_SPLIT_NO_EMPTY);
$keyword = $q[1];
if($keyword == "") return; return "Technorati: ".$keyword;
}
elseif (preg_match("/".$homehost."/i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["s"];
if($keyword == "") return; return "Interne Suche: ".$keyword;
}
else {
return;
}
}
### Anzahl der Datensätze in der statz-Tabelle
function sem_showNumStatzEntries() {
global $wpdb;
$numstatzentries = $wpdb->get_var("SELECT COUNT(id) FROM ".$wpdb->statz);
return $numstatzentries; // Zahl
}
### Aufgezeichnete Tage in der statz-Tabelle
function sem_countDaysInStatzTable() {
global $wpdb;
$firstdate = $wpdb->get_var("SELECT MIN(time) FROM ".$wpdb->statz." LIMIT 0,1");
if(!$firstdate) {
return 1;
}
else {
$firstdate = strtotime($firstdate); $now = time();
$days = (int) (($now - $firstdate) / (60*60*24)+1);
return $days; // KOMPLETTE! Tage
}
}
### Wenn Tage in statz-Tabelle kleiner als Tage in Daily-Statz, dann nimm Tage in Daily-Statz
function sem_compareLimitDays2DailyStatz () {
global $wpdb;
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
if (sem_countDaysInStatzTable() << $sem_options["statz_days_limit"]) {
$sem_options["statz_days_limit"] = sem_countDaysInStatzTable();
update_option("semmelstatzR_options", $sem_options);
}
}
### Zeigt Copyright-Notiz an
function sem_showCopyright() {
print "<p class='copyright'>semmelstatzR ". SEMMELSTATZR_VERSION . " happily coded by <a target='_blank' href='http://php-backoffice.de'>PHP-Backoffice<br />
<a target='_blank' style='border:none;' href='http://sourceforge.net/projects/semmelstatz/'>
<img src='".get_option('siteurl')."/wp-content/plugins/semmelstatzR/img/statzR.png' /></a></p>";
}
### statz-Tabelle leeren (NICHT LÖSCHEN!!!)
function sem_truncateStatzTable() {
global $wpdb, $userip;
$wpdb->query('TRUNCATE TABLE '.$wpdb->statz);
sem_optStatzTable();
$wpdb->query("INSERT INTO `$wpdb->statz`(ip, time, referer, page, username) VALUES('127.0.0.1', NOW(),NULL,0,'statz-Tabelle geleert')");
}
### Obsolet, bleibt aber aus Kompatibilitätsgründen zu SEMMELSTATZ_DELETE
function sem_delOldRecords($days) {
return true;
}
### simpleEncoding für die GoogleChartAPI
function sem_encodeChartData($values) {
$maxValue = max($values);
$simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$chartData = "s:";
for ($i = 0; $i < count($values); $i++) {
$currentValue = $values[$i];
if ($currentValue > -1 && $maxValue <> 0) {
$chartData.=substr($simpleEncoding,61*($currentValue/$maxValue),1);
}
else {
$chartData.='_';
}
}
return $chartData;
}
### Datensätze älter als statz_recdays_limit-Tage löschen
function sem_delOutOfLimit() {
global $wpdb;
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
$today = time(); $days = $sem_options["statz_recdays_limit"];
$enddatum = $today - ($days * 86400);
$enddatum = date("Y-m-d", $enddatum) . " 23:59:59";
$wpdb->query("DELETE FROM ".$wpdb->statz." WHERE time <= '".$enddatum."'");
sem_optStatzTable();
}
### Wenn AUTOMATISCHES LIMIT aktiviert, dann LIMITIERE und erhöhe NEXT_CRON
function sem_doCronStatzLimit() {
sem_delOutOfLimit();
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
$statz_next_cron = $sem_options["statz_next_cron"] + 86400;
$sem_options["statz_next_cron"] = $statz_next_cron;
update_option("semmelstatzR_options", $sem_options);
}
### Konvertiert Strings von utf-8 in ISO-8859
function sem_encodeToIso($string) {
return mb_convert_encoding($string, "ISO-8859-1", mb_detect_encoding($string, "UTF-8, ISO-8859-1, ISO-8859-15", true));
}
### statz-Tabelle optimieren
function sem_optStatzTable() {
global $wpdb;
$wpdb->query("OPTIMIZE TABLE ".$wpdb->statz);
}
### Unter bestimmten Voraussetzungen den Vortag in die statzhist-Tabelle schreiben
function sem_writeYesterdayToHist() {
global $wpdb;
if(!$wpdb->get_var("SELECT date FROM ".$wpdb->statzhist." WHERE substring(date,1,10) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")) {
if($wpdb->get_var("SELECT COUNT(ip) FROM ".$wpdb->statz." WHERE substring(time,1,10) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")) {
$yesterdays = $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 substring(time,1,10) = DATE_SUB(CURDATE(),
INTERVAL 1 DAY) GROUP BY date");
foreach ($yesterdays as $yesterday) {
$date = $yesterday->date;
$visitors = $yesterday->visitors;
$hits = $yesterday->hits;
$referers = $yesterday->referers;
}
$sql = $wpdb->query("INSERT INTO ".$wpdb->statzhist." (date, referers, visitors, hits)
VALUES('$date', $referers, $visitors, $hits)");
}
else {
$date = $wpdb->get_var("SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)");
$sql = $wpdb->query("INSERT INTO ".$wpdb->statzhist." (date, referers, visitors, hits) VALUES('$date', 0, 0, 0)");
}
}
}
### Summen der vergangenen Tage in die statzhist schreiben */
function sem_writeOldDaysToHist() {
global $wpdb;
if(!$wpdb->get_var("SELECT date FROM ".$wpdb->statzhist." WHERE substring(date,1,10) <= DATE_SUB(CURDATE(), INTERVAL 1 DAY)")) {
$theolddays = $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
substring(time,1,10) <= DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY date ORDER BY time ASC");
foreach ($theolddays as $theoldday) {
$date = $theoldday->date;
$visitors = $theoldday->visitors; if(!$visitors) $visitors = 0;
$hits = $theoldday->hits; if(!$hits) $hits = 0;
$referers = $theoldday->referers; if(!$referers) $referers = 0;
$sql = $wpdb->query("INSERT INTO ".$wpdb->statzhist." (date, referers, visitors, hits)
VALUES('$date', $referers, $visitors, $hits)");
}
}
}
function semr_e($sValue, $sDomain = "semmelstatzR") {
return __($sValue, $sDomain);
}
############################################## Ende SEMMELSTATZ-interne Funktionen
?>

Datei anzeigen

@ -0,0 +1,267 @@
<?php
############################################## Beginn TEMPLATE-Funktionen
### Zeigt die letzten $num_posts-Posts an: Titel und absolutes Datum - CSS-id: #lastposts
function sem_showLastPosts($num_posts = 10) {
global $wpdb;
$lastposts = $wpdb->get_results("SELECT ID, post_title FROM ".$wpdb->posts." WHERE post_status = 'publish'
AND post_type = 'post' ORDER BY post_date DESC LIMIT 0, ".$num_posts);
print "<div id='lastposts'>";
if (empty($lastposts)) {
print "... noch keine Beitr&auml;ge";
}
else {
print "<b>Die letzten ".$num_posts." Beitr&auml;ge</b><br />";
foreach ($lastposts as $lastpost) {
$posttitle = $lastpost->post_title;
$permalink = get_permalink($lastpost->ID);
$postdate = $lastpost->post_date;
print "<a href='".$permalink."'>".$posttitle."</a><br />\n";
}
}
print "</div>";
}
### Zeigt die letzten $num_comments-Kommentare an: Autor und Post mit relativem Datum - CSS-id: #lastcomments
function sem_showLastComments($num_comments = 10) {
global $wpdb;
$comments = $wpdb->get_results("SELECT comment_author, comment_ID, comment_post_ID, comment_date
FROM ".$wpdb->comments." WHERE comment_approved = '1' ORDER BY comment_date DESC LIMIT 0, $num_comments");
print "<div id='lastcomments'>";
if (empty($comments)) {
print "Keine Kommentare";
}
else {
print "<b>Die letzten ".$num_comments." Kommentare</b><br />";
foreach ($comments as $comment) {
$commentday = strtotime(substr($comment->comment_date,1,10));
$today = time();
$difference = ceil(($today - $commentday) / (60*60*24))-1;
if($difference == 0) {
$commentdate = "Heute&nbsp;um&nbsp;" . mysql2date("G:i", $comment->comment_date);
}
elseif($difference == 1) {
$commentdate = "Gestern&nbsp;um&nbsp;" . mysql2date("G:i", $comment->comment_date);
}
elseif($difference == 2) {
$commentdate = "Vorgestern&nbsp;um&nbsp;" . mysql2date("G:i", $comment->comment_date);
}
else {
$commentdate = mysql2date("j. F G:i", $comment->comment_date);
}
print "<a href='" . get_permalink($comment->comment_post_ID) . "#comment-$comment->comment_ID'>$comment->comment_author@". get_the_title($comment->comment_post_ID) .", $commentdate</a><br />\n";
}
}
print "</div>";
}
### Zeigt die $num_reads meist gelesenen Posts an - CSS-id: #mostreads
function sem_showMostReads($num_reads = 10) {
global $wpdb;
$mostreads = $wpdb->get_results("SELECT post_title AS posttitle, guid AS postid, hits AS hits FROM ".$wpdb->posts." WHERE hits != '0' GROUP BY postid ORDER BY hits DESC LIMIT 0, $num_reads");
print "<div id='mostreads'>";
if (empty($mostreads)) {
print "... noch keine Eintr&auml;ge";
}
else {
print "<b>Die ".$num_reads." meist gelesenen Beitr&auml;ge</b><br />";
foreach ($mostreads as $mostread) {
$posttitle = $mostread->posttitle;
$postid = $mostread->postid;
//$permalink = get_permalink($mostread->postid);
$hits = $mostread->hits;
print "<a target='_blank' href='".$postid."'>".$posttitle." (".$hits.")</a><br />\n";
}
}
print "</div>";
}
### Zeigt die $num_reads meist gelesenen Posts an - CSS-id: #mostreads - ACHTUNG: Das Ergebnis der Funktion basiert auf der statz-Tabelle
function sem_showMostReadsOld($num_reads = 10) {
global $wpdb;
$mostreads = $wpdb->get_results("SELECT post_title AS posttitle, ".$wpdb->posts.".guid AS postid,
COUNT(".$wpdb->statz.".page) AS count FROM ".$wpdb->posts.", ".$wpdb->statz." WHERE
".$wpdb->statz.".page = ".$wpdb->posts.".ID GROUP BY postid ORDER BY count DESC LIMIT 0, $num_reads");
print "<div id='mostreads'>";
if (empty($mostreads)) {
print "... noch keine Eintr&auml;ge";
}
else {
print "<b>Die ".$num_reads." meist gelesenen Beitr&auml;ge</b><br />";
foreach ($mostreads as $mostread) {
$posttitle = $mostread->posttitle;
$postid = $mostread->postid;
//$permalink = get_permalink($mostread->postid);
$count = $mostread->count;
print "<a target='_blank' href='".$postid."'>".$posttitle." (".$count.")</a><br />\n";
}
}
print "</div>";
}
### Zeigt die $num_commented meist kommentierten Posts an - CSS-id: #mostcommented
function sem_showMostCommented($num_commented = 10) {
global $wpdb;
$mostcommented = $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 id, post_title ORDER BY count DESC LIMIT 0, $num_commented");
print "<div id='mostcommented'>";
if (empty($mostcommented)) {
print "... noch keine Eintr&auml;ge";
}
else {
print "<b>Die ".$num_commented." meist kommentierten Beitr&auml;ge</b><br />";
foreach ($mostcommented as $key => $mostcommented) {
$posttitle = $mostcommented->post_title;
$count = $mostcommented->count;
$postid = $mostcommented->guid;
print "<a target='_blank' href='".$postid."'>".$posttitle." (".$count.")</a><br />\n";
}
}
print "</div>";
}
### Zeigt einen Zähler der Hits im jeweiligen Post. ACHTUNG: FUNKTIONIERT NUR IM LOOP (index.php, single.php)
function sem_showPostHitsInLoop($postid) {
global $wpdb;
$hits = $wpdb->get_var("SELECT hits FROM $wpdb->posts WHERE ID = $postid LIMIT 0,1");
return $hits;
}
### Anzahl aller Posts/Pages
function sem_showTotalPosts() {
global $wpdb;
$totalposts = $wpdb->get_var("SELECT COUNT(ID) AS num FROM ".$wpdb->posts." WHERE post_status = 'publish' LIMIT 0,1");
return $totalposts; // Ganzzahl
}
### Anzahl aller Kommentare
function sem_showTotalComments() {
global $wpdb;
$totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) AS num FROM ".$wpdb->comments." WHERE comment_approved = '1' LIMIT 0,1");
return $totalcomments; // Ganzzahl
}
### Anzahl aller User seit Beginn der Statzaufzeichnung
function sem_showTotalUsers() {
global $wpdb;
$totalusers = $wpdb->get_var("SELECT SUM(visitors) FROM ".$wpdb->statzhist." LIMIT 0,1");
if(!$totalusers) $totalusers = 0;
return $totalusers; // Ganzzahl
}
### Anzahl User pro Tag im Durchschnitt
function sem_showAverageUserPerDay() {
$averageuser = ceil(sem_showTotalUsers() / sem_showStatzDays());
return $averageuser;
}
### Datum des 1. Posts = Blogstart
function sem_showFirstPostDate() {
global $wpdb;
$firstpostdate = $wpdb->get_var("SELECT MIN(post_date) FROM ".$wpdb->posts." WHERE post_status = 'publish' AND post_date != '0000-00-00 00:00:00' LIMIT 0,1");
$firstpostdate = mysql2date("j.n.Y", $firstpostdate);
return $firstpostdate; // String T.M.JJJJ
}
### Datum des 1. Kommentars
function sem_showFirstCommentDate() {
global $wpdb;
$firstcommentdate = $wpdb->get_var("SELECT MIN(comment_date) FROM ".$wpdb->comments." WHERE comment_approved = '1'
AND comment_date != '0000-00-00 00:00:00' LIMIT 0,1");
$firstcommentdate = mysql2date("j.n.Y", $firstcommentdate);
return $firstcommentdate; // String T.M.JJJJ
}
### Anzahl der Kommentierer nach Nicknamen
function sem_showNumCommenters() {
global $wpdb;
$totalcommenters = $wpdb->get_var("SELECT COUNT(DISTINCT comment_author) FROM ".$wpdb->comments." WHERE comment_approved = '1' LIMIT 0,1");
if(!$totalcommenters) $totalcommenters = 0;
return $totalcommenters; // Ganzzahl
}
### Blog besteht seit x Tagen
function sem_showPostDays() {
global $wpdb;
$firstdate = $wpdb->get_var("SELECT MIN(post_date) AS date FROM ".$wpdb->posts." WHERE post_status = 'publish' AND post_date != '0000-00-00 00:00' LIMIT 0,1");
$firstdate = strtotime($firstdate); $now = time();
$blogdays = (int) (($now - $firstdate) / (60*60*24));
$blogdays = $blogdays + 1;
return $blogdays; // Ganzzahl
}
### Tage seit 1. Kommentar
function sem_showCommentDays() {
global $wpdb;
$firstdate = $wpdb->get_var("SELECT MIN(comment_date) AS date FROM ".$wpdb->comments." LIMIT 0,1");
$firstdate = strtotime($firstdate); $now = time();
$commentdays = (int) (($now - $firstdate) / (60*60*24));
$commentdays = $commentdays + 1;
return $commentdays; // Ganzzahl
}
### durchschn. Posts pro Tag
function sem_showPostsPerDay() {
global $wpdb;
$postsperday = (int) sem_showTotalPosts() / (int) sem_showPostDays();
return $postsperday; // Ganzzahl
}
### durchschn. Kommentare pro Tag
function sem_showCommentsPerDay() {
global $wpdb;
$commentsperday = (int) sem_showTotalComments() / (int) sem_showCommentDays();
return $commentsperday; // Ganzzahl
}
### Startdatum der Gesamtstatistik (Basis: statzhist)
function sem_showStatzStartDate() {
global $wpdb;
$statzhiststartdate = $wpdb->get_var("SELECT MIN(date) FROM ".$wpdb->statzhist." WHERE date != '0000-00-00 00:00' LIMIT 0,1");
$statzhiststartdate = mysql2date("j.n.Y", $statzhiststartdate);
// if(!$statzhiststartdate) $statzhiststartdate= "xx.xx.xxxx";
return $statzhiststartdate; // String T.M.JJJJ
}
### Dauer der Statistikaufzeichnung in Tagen (Basis: statzhist)
function sem_showStatzDays() {
global $wpdb;
$firstdate = $wpdb->get_var("SELECT MIN(date) FROM ".$wpdb->statzhist." LIMIT 0,1");
if(!$firstdate) {
return 1;
}
else {
$firstdate = strtotime($firstdate); $now = time();
$statzdays = (int) (($now - $firstdate) / (60*60*24));
return $statzdays; // Ganzzahl
}
}
### Anzahl der Online-Besucher - Verweildauer in den Einstellungen
function sem_showNumUsersOnline() {
global $wpdb;
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
$onlinetime = $sem_options["statz_online_time"];
$numonline = $wpdb->get_var("SELECT COUNT(DISTINCT ip) FROM ".$wpdb->statz." WHERE time > Now() - INTERVAL ".$onlinetime." SECOND");
return $numonline; // Ganzzahl
}
### Anzahl der heutigen Besucher
function sem_showUsersToday() {
global $wpdb; $today = date("Y-m-d");
$todayusers = $wpdb->get_var("SELECT COUNT(DISTINCT ip) FROM ".$wpdb->statz." WHERE time >= '$today' LIMIT 0, 1");
return $todayusers;
}
### Anzahl der gestrigen Besucher
function sem_showUsersYesterday() {
global $wpdb;
$yesterdaysusers = $wpdb->get_var("SELECT visitors FROM ".$wpdb->statzhist." WHERE date = substr(DATE_SUB(NOW(), INTERVAL 1 DAY),1,10) LIMIT 0, 1");
return $yesterdaysusers;
}
##################################################### Ende TEMPLATE-Funktionen
?>

Datei anzeigen

@ -42,14 +42,15 @@ if(!current_user_can('manage_statz')) {
$sem_options['statz_show_todayusers'] = $_POST['statz_show_todayusers'];
$sem_options['statz_on_dashboard'] = $_POST['statz_on_dashboard'];
$sem_options['statz_datarecs_limit'] = $_POST['statz_datarecs_limit'];
$sem_options['statz_use_img'] = $_POST['statz_use_img'];
update_option("semmelstatzR_options", $sem_options);
echo '<div class="updated fade"><p>Einstellungen gespeichert</strong></p></div>';
echo '<div class="updated fade"><p>'.semr_e('Options saved').'</strong></p></div>';
}
if(isset($_POST['trunc_save'])) {
if ($result == sem_truncateStatzTable()) {
echo "<div class='updated'><p>Die <i>statz</i>-Tabelle wurde erfolgreich geleert.</p></div>";
echo "<div class='updated'><p>".semr_e('<i>statz</i>-table emptied succesfully.')."</p></div>";
}
}
@ -92,12 +93,20 @@ if(!current_user_can('manage_statz')) {
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=<?php echo plugin_basename(__FILE__); ?>">
<div id='icon-semmelstatzR' class='icon32'><br /></div>
<h2>SemmelstatzR &rsaquo; Einstellungen</h2>
<h2>SemmelstatzR &rsaquo; <?php echo semr_e('Options'); ?></h2>
<p><input type="submit" class="button-secondary" name="options_save" value="&Auml;nderungen &uuml;bernehmen" /></p>
<p><input type="submit" class="button-secondary" name="options_save" value="<?php echo semr_e('Save Changes'); ?>" /></p>
<table class="form-table">
<tr style="background:#eee;" valign="middle">
<th><?php echo semr_e('Use tracking image'); ?></th>
<td><input name="statz_use_img" type="checkbox" id="statz_write_admins" value="statz_use_img"
<?php if($sem_options["statz_use_img"] == TRUE) {?> checked="checked" <?php } ?> />
</td>
<td><?php echo semr_e('Use a pixelimage in the footer to track visitors. Only needed with some cache-plugins. - (Default: Off)'); ?></td>
</tr>
<tr style="background:#eee;" valign="middle">
<th>Blog-Administratoren aufzeichnen</th>
<td><input name="statz_write_admins" type="checkbox" id="statz_write_admins" value="statz_write_admins"

Datei anzeigen

@ -1,8 +1,8 @@
<?php
/*
Plugin Name: SemmelstatzR
Plugin URI: http://sourceforge.net/projects/semmelstatzR/
Description: Visitorstatistic for Wordpress, based upon the original wp-plugin semmelstatzR by Andreas 'Redunzl' Mueller (http://www.kopfhoch-studio.de)
Plugin URI: http://sourceforge.net/projects/semmelstatz/
Description: Visitorstatistic for Wordpress, based upon the original wp-plugin semmelstatz by Andreas 'Redunzl' Mueller (http://www.kopfhoch-studio.de)
Version: 1.0.0 beta
Author: Ortwin Pinke
Author URI: http://www.ortwinpinke.de
@ -40,8 +40,10 @@ Author URI: http://www.ortwinpinke.de
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
### konstante für version
### constants
define('SEMMELSTATZR_VERSION', '1.0.0 Beta');
define('SEMMELSTATZR_SRVPATH', dirname(__FILE__));
define('SEMMELSTATZR_HTML_RELPATH', WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)));
### Deklaration der Tabellennamen
global $wpdb;
@ -62,25 +64,53 @@ if(!load_plugin_textdomain('semmelstatzR','/wp-content/languages/')) {
load_plugin_textdomain('semmelstatzR',null,$plugin_dir.'/locale/');
}
include_once SEMMELSTATZR_SRVPATH.'/includes/functions.semr.php';
include_once SEMMELSTATZR_SRVPATH.'/includes/functions.semr_template.php';
### Erstellen des Top-Level-Menus im Adminbereich
add_action('admin_menu', 'semmelstatzR_menu');
if(is_admin() == true) {
/**
* add CSS
*
* @return void
*/
function semmelstatzR_css() {
print "<link rel='stylesheet' href='".get_option('siteurl')."/wp-content/plugins/semmelstatzR/semmelstatzR.css' type='text/css' media='screen' />\n";
}
add_action('admin_head', 'semmelstatzR_css');
### End add CSS
/**
* add toplevel menu into admin
*
* @todo localization
*
* @return void
*/
function semmelstatzR_menu() {
if (function_exists('add_menu_page')) {
add_menu_page('SemmelstatzR','SemmelstatzR', 'manage_statz', 'semmelstatzR/semmelstatzR-statz.php', '', plugins_url('semmelstatzR/img/statz_small.png'));
}
if (function_exists('add_submenu_page')) {
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', 'Aktuell', 'Aktuell', 'manage_statz', 'semmelstatzR/semmelstatzR-statz.php');
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', 'Historie', 'Historie', 'manage_statz', 'semmelstatzR/semmelstatzR-history.php');
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', 'Log', 'Log', 'manage_statz', 'semmelstatzR/semmelstatzR-log.php');
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', 'Datenbank', 'Datenbank', 'manage_statz', 'semmelstatzR/semmelstatzR-database.php');
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', 'Templates', 'Templates', 'manage_statz', 'semmelstatzR/semmelstatzR-templates.php');
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', 'Einstellungen', 'Einstellungen', 'manage_statz', 'semmelstatzR/semmelstatzR-options.php');
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', semr_e('Current Statz'), semr_e('Current Statz'), 'manage_statz', 'semmelstatzR/semmelstatzR-statz.php');
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', semr_e('History'), semr_e('History'), 'manage_statz', 'semmelstatzR/semmelstatzR-history.php');
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', semr_e('Log'), semr_e('Log'), 'manage_statz', 'semmelstatzR/semmelstatzR-log.php');
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', semr_e('Database'), semr_e('Database'), 'manage_statz', 'semmelstatzR/semmelstatzR-database.php');
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', semr_e('Templates'), semr_e('Templates'), 'manage_statz', 'semmelstatzR/semmelstatzR-templates.php');
add_submenu_page('semmelstatzR/semmelstatzR-statz.php', semr_e('Options'), semr_e('Options'), 'manage_statz', 'semmelstatzR/semmelstatzR-options.php');
}
}
add_action('admin_menu', 'semmelstatzR_menu');
### end add toplevel adminmenu
### Default-Werte der statz-Optionen in das Array 'semmelstatzR_options' schreiben
add_action('init', 'sem_init_options');
/**
* write defaults to options-array
*
* @return void
*/
function sem_init_options() {
global $wpdb;
@ -112,15 +142,23 @@ add_action('init', 'sem_init_options');
"statz_show_useronline" => true,
"statz_topreads_limit" => 10,
"statz_write_admins" => false,
"statz_write_users" => false
"statz_write_users" => false,
"statz_use_img" => true
);
add_option( 'semmelstatzR_options', $sem_options );
}
}
add_action('init', 'sem_init_options');
### End write defaults to options-array
} else {
}
### Anlegen der Tabellen, Optionen schreiben
add_action('activate_semmelstatzR/semmelstatzR.php', 'sem_statzsetup');
function sem_statzsetup() {
add_action('activate_semmelstatzR/semmelstatzR.php', 'sem_statzsetup');
function sem_statzsetup() {
global $wpdb;
if(@is_file(ABSPATH.'/wp-admin/upgrade-functions.php')) {
include_once(ABSPATH.'/wp-admin/upgrade-functions.php');
@ -167,14 +205,21 @@ add_action('init', 'sem_init_options');
if(!$role->has_cap('manage_statz')) {
$role->add_cap('manage_statz');
}
}
}
### Zugriff analysieren und in statz-Tabelle schreiben
add_action('wp_head', 'sem_writeStatz');
function sem_writeStatz() {
add_action('wp_footer', 'sem_writeStatz');
function sem_writeStatz() {
global $wpdb, $wp_query, $isBot, $isAdmin, $page;
$plugin_dir = basename(dirname(__FILE__));
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
// true === $sem_options['statz_use_img'] &&
if(true == $sem_options['statz_use_img'] && !defined('SEMMELSTATZR_STATZIMG')) {
print '<img src="'.SEMMELSTATZR_HTML_RELPATH.'semr_image.php" alt="" />';
return; ### nothing todo if stat image is used
}
sem_writeYesterdayToHist();
$useragent = $wpdb->escape($_SERVER['HTTP_USER_AGENT']);
$isBot = sem_AreYouBot($useragent);
@ -189,16 +234,16 @@ add_action('init', 'sem_init_options');
$userip = $wpdb->escape($_SERVER['REMOTE_ADDR']);
if($sem_options['statz_encode_ip'] == true) $userip = sem_encodeIP($userip);
$referer = $wpdb->escape(urldecode($_SERVER['HTTP_REFERER']));
$referer = $wpdb->escape(urldecode($_SERVER['HTTP_REFERER']));
$blogtime = gmdate('Y-m-d H:i:s', current_time('timestamp'));
if (!empty($referer)) {
if(get_option('blog_charset') == 'iso-8859-1') $referer = utf8_decode($referer);
$referer = "'".$referer."'";
}
else {
$referer = 'NULL';
$referer = "'".$referer."'";
}
else {
$referer = 'NULL';
}
$readingnow = wp_title('', false);
if(empty($readingnow)) {
@ -207,13 +252,13 @@ add_action('init', 'sem_init_options');
$page = $wp_query->post->ID;
}
$wpdb->query("INSERT INTO $wpdb->statz (ip, time, referer, page, username)
$wpdb->query("INSERT INTO $wpdb->statz (ip, time, referer, page, username)
VALUES('$userip', '$blogtime', $referer, $page, '$username')");
if($wpdb->query("SELECT COUNT(hits) FROM $wpdb->posts")) {
$wpdb->query("UPDATE $wpdb->posts SET hits = hits + 1 WHERE ID = $page"); // neu ab 3.2
}
}
}
### Zeitgesteuertes Limitieren der statz-Tabelle
// Wenn semmelKron JA UND statz_next_cron älter JETZT, dann...
@ -222,14 +267,10 @@ add_action('init', 'sem_init_options');
add_action('shutdown', 'sem_doCronStatzLimit'); // ...limitiere statz-Tabelle auf vorgegebenen Wert
}
### CSS für den SEMMELSTATZ-Admin-Bereich
add_action('admin_head', 'semmelstatzR_css');
function semmelstatzR_css() {
print "<link rel='stylesheet' href='".get_option('siteurl')."/wp-content/plugins/semmelstatzR/semmelstatzR.css' type='text/css' media='screen' />\n";
}
### Rendert eine Mini-STATZ. Idee: René Tauchnitz
function sem_dashboardStatz() {
function sem_dashboardStatz_show() {
$widgets = get_option( 'dashboard_widget_options' );
echo '<p>';
printf(_n("%d Visitor online", "%d Visitors online", sem_showNumUsersOnline(), "semmelstatzR"), sem_showNumUsersOnline());
echo ' - ';
@ -238,13 +279,35 @@ function sem_dashboardStatz() {
echo '</p>';
}
function sem_dashboardStatz_control() {
if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
$widget_options = array();
if ( !isset($widget_options['dashboard_sem_dashboardStatz']) )
$widget_options['dashboard_sem_dashboardStatz'] = array();
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['dashboard-sem-dashboardStatz']) ) {
$number = absint( $_POST['dashboard-sem-dashboardStatz']['items'] );
$widget_options['dashboard_sem_dashboardStatz']['items'] = $number;
update_option( 'dashboard_widget_options', $widget_options );
}
$number = isset( $widget_options['dashboard_sem_dashboardStatz']['items'] ) ? (int) $widget_options['dashboard_sem_dashboardStatz']['items'] : '';
echo '<p><label for="sem-number">' . __('Number of Whatever:') . '</label>';
echo '<input id="sem-number" name="dashboard-sem-dashboardStatz[items]" type="text" value="' . $number . '" size="3" /></p>';
print_r($widget_options['dashboard_sem_dashboardStatz']);
}
### Widget für die Mini-STATZ
add_action('wp_dashboard_setup', 'sem_dashboardStatz_setup');
function sem_dashboardStatz_setup() {
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
if(!current_user_can('manage_statz')) return;
if($sem_options['statz_on_dashboard'] != true) return;
wp_add_dashboard_widget( 'sem_dashboardStatz', 'SemmelstatzR', 'sem_dashboardStatz' );
wp_add_dashboard_widget( 'sem_dashboardStatz', 'SemmelstatzR', 'sem_dashboardStatz_show', 'sem_dashboardStatz_control' );
}
### Mini-Statz für Dashboard-Widget & AKTUELL-Anzeige
@ -252,7 +315,7 @@ function sem_dashboardStatz_setup() {
global $wpdb;
$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() GROUP BY date");
$thedays = array(array('hits' => 33));
//$thedays = array(array('hits' => 33));
if (empty($thedays)) {
return "<small>".__("... no entries", "semmelstatzR")."</small>";
}
@ -266,737 +329,4 @@ function sem_dashboardStatz_setup() {
.sprintf(_n("%d Hit","%d Hits",$hits, "semmelstatzR"),$hits)." - "
.sprintf(_n("%d Referrer","%d Referrers",$referer, "semmelstatzR"),$referers);
}
### Encodierung der IP-Adresse durch simple arithmetische Operation
function sem_encodeIP($ip) {
$ip_parts = split("[.]", $ip);
$new_ip = ($ip_parts[0]+700) . "." . ($ip_parts[1]*2) . "." . ($ip_parts[2]+600) . "." . ($ip_parts[3]*3);
return $new_ip;
}
### Decodierung der IP-Adresse durch simple arithmetische Operation
function sem_decodeIP($ip) {
$ip_parts = split("[.]", $ip);
$new_ip = ($ip_parts[0]-700) . "." . ($ip_parts[1] / 2) . "." . ($ip_parts[2]-600) . "." . ($ip_parts[3]/3);
return $new_ip;
}
### Ist IP-Adresse codiert?
function sem_checkIfIPisEncoded($ip) {
$ip_parts = split("[.]", $ip);
if($ip_parts[0]>700) {
return true;
}
else {
return false;
}
}
### Auslesen der höchsten Post-ID
function sem_getMaxPostID() {
global $wpdb;
$maxpostid = $wpdb->get_var("SELECT MAX(ID) FROM ".$wpdb->posts." LIMIT 0,1");
return $maxpostid; //Ganzzahl
}
### Auslesen des User- bzw. Kommentarautornamen
function sem_getUsername() {
global $user_ID, $user_login, $isAdmin;
get_currentuserinfo();
if($user_ID > 0) {
$useronline = $user_login;
if(current_user_can('manage_options')) {
$isAdmin = 1;
}
else {
$isAdmin = 0;
}
}
elseif(isset($_COOKIE["comment_author_".COOKIEHASH])) {
$useronline = trim($_COOKIE["comment_author_".COOKIEHASH]);
$isAdmin = -1;
}
else {
$useronline = "Gast";
$isAdmin = -1;
}
return $useronline;
}
### Prüfen, ob Besucher ein Bot ist
function sem_AreYouBot($user_agent) {
global $isBot;
$bots = array(
'aipbot',
'amfibibot',
'appie',
'ask jeeves/teoma',
'aspseek',
'axadine',
'baiduspider',
'becomebot',
'blogcorpuscrawler',
'blogpulse',
'blogsnowbot',
'boitho.com',
'bruinbot',
'cerberian',
'cfnetwork',
'check_http',
'cipinetbot',
'claymont',
'cometsearch@cometsystems.com',
'converacrawler',
'cydralspider',
'digger',
'es.net_crawler',
'eventax',
'everyfeed-spider',
'exabot@exava.com',
'faxobot',
'findlinks',
'fireball',
'francis',
'gaisbot',
'gamekitbot',
'gazz@nttr.co.jp',
'geonabot',
'getrax crawler',
'gigabot',
'girafa.com',
'goforitbot',
'googlebot',
'grub-client',
'holmes',
'houxoucrawler',
'http://www.almaden.ibm.com/cs/crawler',
'http://www.istarthere.com',
'http://www.relevantnoise.com',
'httrack ?',
'ia_archiver',
'ichiro',
'iltrovatore-setaccio',
'inelabot',
'infoseek',
'inktomi.com',
'irlbot',
'jetbot',
'jobspider_ba',
'kazoombot',
'larbin',
'libwww',
'linkwalker',
'lmspider',
'mackster',
'mediapartners-google',
'microsoft url control',
'mj12bot',
'moreoverbot',
'mozdex',
'msnbot',
'msrbot',
'naverbot',
'netresearchserver',
'ng/2.0',
'np(bot)',
'nutch',
'objectssearch',
'ocelli',
'omniexplorer_bot',
'openbot',
'overture',
'patwebbot',
'php',
'phpdig',
'pilgrim html-crawler',
'pipeliner',
'pompos',
'psbot',
'python-urllib',
'quepasacreep',
'robozilla',
'rpt-httpclient',
'savvybot',
'scooter',
'search.ch',
'seekbot',
'semager',
'seznambot',
'sherlock',
'shelob',
'sitesearch',
'snapbot',
'snappreviewbot',
'speedy spider',
'sphere scout',
'stackrambler',
'steeler',
'surveybot',
'szukacz',
'technoratibot',
'telnet',
'themiragorobot',
'thesubot',
'thumbshots-de-bot',
'topicblogs',
'turnitinbot',
'tutorgigbot',
'tutorial crawler',
'twiceler',
'vagabondo',
'versus',
'voilabot',
'w3c_css_validator',
'w3c_validator',
'w3c-checklink',
'web downloader',
'webcopier',
'webcrawler',
'webfilter robot',
'west wind internet protocols',
'wget',
'wwweasel robot',
'wwwster',
'xaldon webspider',
'xenu',
'yahoo! slurp',
'yahoofeedseeker',
'yahoo-mmcrawler',
'zao',
'zipppbot',
'zyborg',
);
foreach($bots as $bot) {
if(stristr($user_agent, $bot) !== false) {
return true;
}
}
return false;
}
### Referer nach Suchmaschinen-Queries und interner Suche prüfen und Suchstring extrahieren
function sem_getKeyword($referer) {
$keyword = @parse_url($referer);
if (preg_match("/google\./i", $keyword["host"])) {
if (preg_match("/imgurl/i", $keyword["query"])) {
parse_str($keyword["query"],$q);
$keyword = substr($q["prev"],10);
}
else if (preg_match("/translate\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
}
else {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
}
if($keyword == "") return; return "Google: ".$keyword;
}
elseif (preg_match("/search\.live\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "LiveSearch: ".$keyword;
}
elseif (preg_match("/bing\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "Bing: ".$keyword;
}
elseif (preg_match("/yahoo\./i", $keyword["host"])) {
if (preg_match("/images/i", $keyword["query"])) {
parse_str($keyword["query"],$q);
$keyword = $q["p"];
}
else {
parse_str($keyword["query"],$q);
$keyword = $q["p"];
}
if($keyword == "") return; return "Yahoo: ".$keyword;
}
elseif (preg_match("/aol\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "AOL: ".$keyword;
}
elseif (preg_match("/aolsvc\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "AOL: ".$keyword;
}
elseif (preg_match("/search\.msn\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "MSN: ".$keyword;
}
elseif (preg_match("/gmx\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["su"];
if($keyword == "") return; return "GMX: ".$keyword;
}
elseif (preg_match("/\.bild\.t\-/i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["query"];
if($keyword == "") return; return "BILD: ".$keyword;
}
elseif (preg_match("/t\-online\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "T-Online: ".$keyword;
}
elseif (preg_match("/suche\.web\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["su"];
if($keyword == "") return; return "WEB.de: ".$keyword;
}
elseif (preg_match("/suche\.lycos\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["query"];
if($keyword == "") return; return "Lycos: ".$keyword;
}
elseif (preg_match("/altavista\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "Altavista: ".$keyword;
}
elseif (preg_match("/alltheweb\./i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["q"];
if($keyword == "") return; return "alltheweb: ".$keyword;
}
elseif (preg_match("/technorati\.com\/search\//", $referer)) {
$q = preg_split("/technorati\.com\/search\//", $referer,-1,PREG_SPLIT_NO_EMPTY);
$keyword = $q[1];
if($keyword == "") return; return "Technorati: ".$keyword;
}
elseif (preg_match("/".$homehost."/i", $keyword["host"])) {
parse_str($keyword["query"],$q);
$keyword = $q["s"];
if($keyword == "") return; return "Interne Suche: ".$keyword;
}
else {
return;
}
}
### Anzahl der Datensätze in der statz-Tabelle
function sem_showNumStatzEntries() {
global $wpdb;
$numstatzentries = $wpdb->get_var("SELECT COUNT(id) FROM ".$wpdb->statz);
return $numstatzentries; // Zahl
}
### Aufgezeichnete Tage in der statz-Tabelle
function sem_countDaysInStatzTable() {
global $wpdb;
$firstdate = $wpdb->get_var("SELECT MIN(time) FROM ".$wpdb->statz." LIMIT 0,1");
if(!$firstdate) {
return 1;
}
else {
$firstdate = strtotime($firstdate); $now = time();
$days = (int) (($now - $firstdate) / (60*60*24)+1);
return $days; // KOMPLETTE! Tage
}
}
### Wenn Tage in statz-Tabelle kleiner als Tage in Daily-Statz, dann nimm Tage in Daily-Statz
function sem_compareLimitDays2DailyStatz () {
global $wpdb;
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
if (sem_countDaysInStatzTable() << $sem_options["statz_days_limit"]) {
$sem_options["statz_days_limit"] = sem_countDaysInStatzTable();
update_option("semmelstatzR_options", $sem_options);
}
}
### Zeigt Copyright-Notiz an
function sem_showCopyright() {
print "<p class='copyright'>semmelstatzR ". SEMMELSTATZ_VERSION . " ist (c) kopfhoch-studio 2005-2009<br />
<a target='_blank' style='border:none;' href='http://www.kopfhoch-studio.de/blog/2765'>
<img src='".get_option('siteurl')."/wp-content/plugins/semmelstatzR/img/statz.png' /></a></p>";
}
### statz-Tabelle leeren (NICHT LÖSCHEN!!!)
function sem_truncateStatzTable() {
global $wpdb, $userip;
$wpdb->query('TRUNCATE TABLE '.$wpdb->statz);
sem_optStatzTable();
$wpdb->query("INSERT INTO `$wpdb->statz`(ip, time, referer, page, username) VALUES('127.0.0.1', NOW(),NULL,0,'statz-Tabelle geleert')");
}
### Obsolet, bleibt aber aus Kompatibilitätsgründen zu SEMMELSTATZ_DELETE
function sem_delOldRecords($days) {
return true;
}
### simpleEncoding für die GoogleChartAPI
function sem_encodeChartData($values) {
$maxValue = max($values);
$simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$chartData = "s:";
for ($i = 0; $i < count($values); $i++) {
$currentValue = $values[$i];
if ($currentValue > -1) {
$chartData.=substr($simpleEncoding,61*($currentValue/$maxValue),1);
}
else {
$chartData.='_';
}
}
return $chartData;
}
### Datensätze älter als statz_recdays_limit-Tage löschen
function sem_delOutOfLimit() {
global $wpdb;
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
$today = time(); $days = $sem_options["statz_recdays_limit"];
$enddatum = $today - ($days * 86400);
$enddatum = date("Y-m-d", $enddatum) . " 23:59:59";
$wpdb->query("DELETE FROM ".$wpdb->statz." WHERE time <= '".$enddatum."'");
sem_optStatzTable();
}
### Wenn AUTOMATISCHES LIMIT aktiviert, dann LIMITIERE und erhöhe NEXT_CRON
function sem_doCronStatzLimit() {
sem_delOutOfLimit();
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
$statz_next_cron = $sem_options["statz_next_cron"] + 86400;
$sem_options["statz_next_cron"] = $statz_next_cron;
update_option("semmelstatzR_options", $sem_options);
}
### Konvertiert Strings von utf-8 in ISO-8859
function sem_encodeToIso($string) {
return mb_convert_encoding($string, "ISO-8859-1", mb_detect_encoding($string, "UTF-8, ISO-8859-1, ISO-8859-15", true));
}
### statz-Tabelle optimieren
function sem_optStatzTable() {
global $wpdb;
$wpdb->query("OPTIMIZE TABLE ".$wpdb->statz);
}
### Unter bestimmten Voraussetzungen den Vortag in die statzhist-Tabelle schreiben
function sem_writeYesterdayToHist() {
global $wpdb;
if(!$wpdb->get_var("SELECT date FROM ".$wpdb->statzhist." WHERE substring(date,1,10) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")) {
if($wpdb->get_var("SELECT COUNT(ip) FROM ".$wpdb->statz." WHERE substring(time,1,10) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")) {
$yesterdays = $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 substring(time,1,10) = DATE_SUB(CURDATE(),
INTERVAL 1 DAY) GROUP BY date");
foreach ($yesterdays as $yesterday) {
$date = $yesterday->date;
$visitors = $yesterday->visitors;
$hits = $yesterday->hits;
$referers = $yesterday->referers;
}
$sql = $wpdb->query("INSERT INTO ".$wpdb->statzhist." (date, referers, visitors, hits)
VALUES('$date', $referers, $visitors, $hits)");
}
else {
$date = $wpdb->get_var("SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)");
$sql = $wpdb->query("INSERT INTO ".$wpdb->statzhist." (date, referers, visitors, hits) VALUES('$date', 0, 0, 0)");
}
}
}
### Summen der vergangenen Tage in die statzhist schreiben */
function sem_writeOldDaysToHist() {
global $wpdb;
if(!$wpdb->get_var("SELECT date FROM ".$wpdb->statzhist." WHERE substring(date,1,10) <= DATE_SUB(CURDATE(), INTERVAL 1 DAY)")) {
$theolddays = $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
substring(time,1,10) <= DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY date ORDER BY time ASC");
foreach ($theolddays as $theoldday) {
$date = $theoldday->date;
$visitors = $theoldday->visitors; if(!$visitors) $visitors = 0;
$hits = $theoldday->hits; if(!$hits) $hits = 0;
$referers = $theoldday->referers; if(!$referers) $referers = 0;
$sql = $wpdb->query("INSERT INTO ".$wpdb->statzhist." (date, referers, visitors, hits)
VALUES('$date', $referers, $visitors, $hits)");
}
}
}
############################################## Ende SEMMELSTATZ-interne Funktionen
############################################## Beginn TEMPLATE-Funktionen
### Zeigt die letzten $num_posts-Posts an: Titel und absolutes Datum - CSS-id: #lastposts
function sem_showLastPosts($num_posts = 10) {
global $wpdb;
$lastposts = $wpdb->get_results("SELECT ID, post_title FROM ".$wpdb->posts." WHERE post_status = 'publish'
AND post_type = 'post' ORDER BY post_date DESC LIMIT 0, ".$num_posts);
print "<div id='lastposts'>";
if (empty($lastposts)) {
print "... noch keine Beitr&auml;ge";
}
else {
print "<b>Die letzten ".$num_posts." Beitr&auml;ge</b><br />";
foreach ($lastposts as $lastpost) {
$posttitle = $lastpost->post_title;
$permalink = get_permalink($lastpost->ID);
$postdate = $lastpost->post_date;
print "<a href='".$permalink."'>".$posttitle."</a><br />\n";
}
}
print "</div>";
}
### Zeigt die letzten $num_comments-Kommentare an: Autor und Post mit relativem Datum - CSS-id: #lastcomments
function sem_showLastComments($num_comments = 10) {
global $wpdb;
$comments = $wpdb->get_results("SELECT comment_author, comment_ID, comment_post_ID, comment_date
FROM ".$wpdb->comments." WHERE comment_approved = '1' ORDER BY comment_date DESC LIMIT 0, $num_comments");
print "<div id='lastcomments'>";
if (empty($comments)) {
print "Keine Kommentare";
}
else {
print "<b>Die letzten ".$num_comments." Kommentare</b><br />";
foreach ($comments as $comment) {
$commentday = strtotime(substr($comment->comment_date,1,10));
$today = time();
$difference = ceil(($today - $commentday) / (60*60*24))-1;
if($difference == 0) {
$commentdate = "Heute&nbsp;um&nbsp;" . mysql2date("G:i", $comment->comment_date);
}
elseif($difference == 1) {
$commentdate = "Gestern&nbsp;um&nbsp;" . mysql2date("G:i", $comment->comment_date);
}
elseif($difference == 2) {
$commentdate = "Vorgestern&nbsp;um&nbsp;" . mysql2date("G:i", $comment->comment_date);
}
else {
$commentdate = mysql2date("j. F G:i", $comment->comment_date);
}
print "<a href='" . get_permalink($comment->comment_post_ID) . "#comment-$comment->comment_ID'>$comment->comment_author@". get_the_title($comment->comment_post_ID) .", $commentdate</a><br />\n";
}
}
print "</div>";
}
### Zeigt die $num_reads meist gelesenen Posts an - CSS-id: #mostreads
function sem_showMostReads($num_reads = 10) {
global $wpdb;
$mostreads = $wpdb->get_results("SELECT post_title AS posttitle, guid AS postid, hits AS hits FROM ".$wpdb->posts." WHERE hits != '0' GROUP BY postid ORDER BY hits DESC LIMIT 0, $num_reads");
print "<div id='mostreads'>";
if (empty($mostreads)) {
print "... noch keine Eintr&auml;ge";
}
else {
print "<b>Die ".$num_reads." meist gelesenen Beitr&auml;ge</b><br />";
foreach ($mostreads as $mostread) {
$posttitle = $mostread->posttitle;
$postid = $mostread->postid;
//$permalink = get_permalink($mostread->postid);
$hits = $mostread->hits;
print "<a target='_blank' href='".$postid."'>".$posttitle." (".$hits.")</a><br />\n";
}
}
print "</div>";
}
### Zeigt die $num_reads meist gelesenen Posts an - CSS-id: #mostreads - ACHTUNG: Das Ergebnis der Funktion basiert auf der statz-Tabelle
function sem_showMostReadsOld($num_reads = 10) {
global $wpdb;
$mostreads = $wpdb->get_results("SELECT post_title AS posttitle, ".$wpdb->posts.".guid AS postid,
COUNT(".$wpdb->statz.".page) AS count FROM ".$wpdb->posts.", ".$wpdb->statz." WHERE
".$wpdb->statz.".page = ".$wpdb->posts.".ID GROUP BY postid ORDER BY count DESC LIMIT 0, $num_reads");
print "<div id='mostreads'>";
if (empty($mostreads)) {
print "... noch keine Eintr&auml;ge";
}
else {
print "<b>Die ".$num_reads." meist gelesenen Beitr&auml;ge</b><br />";
foreach ($mostreads as $mostread) {
$posttitle = $mostread->posttitle;
$postid = $mostread->postid;
//$permalink = get_permalink($mostread->postid);
$count = $mostread->count;
print "<a target='_blank' href='".$postid."'>".$posttitle." (".$count.")</a><br />\n";
}
}
print "</div>";
}
### Zeigt die $num_commented meist kommentierten Posts an - CSS-id: #mostcommented
function sem_showMostCommented($num_commented = 10) {
global $wpdb;
$mostcommented = $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 id, post_title ORDER BY count DESC LIMIT 0, $num_commented");
print "<div id='mostcommented'>";
if (empty($mostcommented)) {
print "... noch keine Eintr&auml;ge";
}
else {
print "<b>Die ".$num_commented." meist kommentierten Beitr&auml;ge</b><br />";
foreach ($mostcommented as $key => $mostcommented) {
$posttitle = $mostcommented->post_title;
$count = $mostcommented->count;
$postid = $mostcommented->guid;
print "<a target='_blank' href='".$postid."'>".$posttitle." (".$count.")</a><br />\n";
}
}
print "</div>";
}
### Zeigt einen Zähler der Hits im jeweiligen Post. ACHTUNG: FUNKTIONIERT NUR IM LOOP (index.php, single.php)
function sem_showPostHitsInLoop($postid) {
global $wpdb;
$hits = $wpdb->get_var("SELECT hits FROM $wpdb->posts WHERE ID = $postid LIMIT 0,1");
return $hits;
}
### Anzahl aller Posts/Pages
function sem_showTotalPosts() {
global $wpdb;
$totalposts = $wpdb->get_var("SELECT COUNT(ID) AS num FROM ".$wpdb->posts." WHERE post_status = 'publish' LIMIT 0,1");
return $totalposts; // Ganzzahl
}
### Anzahl aller Kommentare
function sem_showTotalComments() {
global $wpdb;
$totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) AS num FROM ".$wpdb->comments." WHERE comment_approved = '1' LIMIT 0,1");
return $totalcomments; // Ganzzahl
}
### Anzahl aller User seit Beginn der Statzaufzeichnung
function sem_showTotalUsers() {
global $wpdb;
$totalusers = $wpdb->get_var("SELECT SUM(visitors) FROM ".$wpdb->statzhist." LIMIT 0,1");
if(!$totalusers) $totalusers = 0;
return $totalusers; // Ganzzahl
}
### Anzahl User pro Tag im Durchschnitt
function sem_showAverageUserPerDay() {
$averageuser = ceil(sem_showTotalUsers() / sem_showStatzDays());
return $averageuser;
}
### Datum des 1. Posts = Blogstart
function sem_showFirstPostDate() {
global $wpdb;
$firstpostdate = $wpdb->get_var("SELECT MIN(post_date) FROM ".$wpdb->posts." WHERE post_status = 'publish' AND post_date != '0000-00-00 00:00:00' LIMIT 0,1");
$firstpostdate = mysql2date("j.n.Y", $firstpostdate);
return $firstpostdate; // String T.M.JJJJ
}
### Datum des 1. Kommentars
function sem_showFirstCommentDate() {
global $wpdb;
$firstcommentdate = $wpdb->get_var("SELECT MIN(comment_date) FROM ".$wpdb->comments." WHERE comment_approved = '1'
AND comment_date != '0000-00-00 00:00:00' LIMIT 0,1");
$firstcommentdate = mysql2date("j.n.Y", $firstcommentdate);
return $firstcommentdate; // String T.M.JJJJ
}
### Anzahl der Kommentierer nach Nicknamen
function sem_showNumCommenters() {
global $wpdb;
$totalcommenters = $wpdb->get_var("SELECT COUNT(DISTINCT comment_author) FROM ".$wpdb->comments." WHERE comment_approved = '1' LIMIT 0,1");
if(!$totalcommenters) $totalcommenters = 0;
return $totalcommenters; // Ganzzahl
}
### Blog besteht seit x Tagen
function sem_showPostDays() {
global $wpdb;
$firstdate = $wpdb->get_var("SELECT MIN(post_date) AS date FROM ".$wpdb->posts." WHERE post_status = 'publish' AND post_date != '0000-00-00 00:00' LIMIT 0,1");
$firstdate = strtotime($firstdate); $now = time();
$blogdays = (int) (($now - $firstdate) / (60*60*24));
$blogdays = $blogdays + 1;
return $blogdays; // Ganzzahl
}
### Tage seit 1. Kommentar
function sem_showCommentDays() {
global $wpdb;
$firstdate = $wpdb->get_var("SELECT MIN(comment_date) AS date FROM ".$wpdb->comments." LIMIT 0,1");
$firstdate = strtotime($firstdate); $now = time();
$commentdays = (int) (($now - $firstdate) / (60*60*24));
$commentdays = $commentdays + 1;
return $commentdays; // Ganzzahl
}
### durchschn. Posts pro Tag
function sem_showPostsPerDay() {
global $wpdb;
$postsperday = (int) sem_showTotalPosts() / (int) sem_showPostDays();
return $postsperday; // Ganzzahl
}
### durchschn. Kommentare pro Tag
function sem_showCommentsPerDay() {
global $wpdb;
$commentsperday = (int) sem_showTotalComments() / (int) sem_showCommentDays();
return $commentsperday; // Ganzzahl
}
### Startdatum der Gesamtstatistik (Basis: statzhist)
function sem_showStatzStartDate() {
global $wpdb;
$statzhiststartdate = $wpdb->get_var("SELECT MIN(date) FROM ".$wpdb->statzhist." WHERE date != '0000-00-00 00:00' LIMIT 0,1");
$statzhiststartdate = mysql2date("j.n.Y", $statzhiststartdate);
// if(!$statzhiststartdate) $statzhiststartdate= "xx.xx.xxxx";
return $statzhiststartdate; // String T.M.JJJJ
}
### Dauer der Statistikaufzeichnung in Tagen (Basis: statzhist)
function sem_showStatzDays() {
global $wpdb;
$firstdate = $wpdb->get_var("SELECT MIN(date) FROM ".$wpdb->statzhist." LIMIT 0,1");
if(!$firstdate) {
return 1;
}
else {
$firstdate = strtotime($firstdate); $now = time();
$statzdays = (int) (($now - $firstdate) / (60*60*24));
return $statzdays; // Ganzzahl
}
}
### Anzahl der Online-Besucher - Verweildauer in den Einstellungen
function sem_showNumUsersOnline() {
global $wpdb;
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
$onlinetime = $sem_options["statz_online_time"];
$numonline = $wpdb->get_var("SELECT COUNT(DISTINCT ip) FROM ".$wpdb->statz." WHERE time > Now() - INTERVAL ".$onlinetime." SECOND");
return $numonline; // Ganzzahl
}
### Anzahl der heutigen Besucher
function sem_showUsersToday() {
global $wpdb; $today = date("Y-m-d");
$todayusers = $wpdb->get_var("SELECT COUNT(DISTINCT ip) FROM ".$wpdb->statz." WHERE time >= '$today' LIMIT 0, 1");
return $todayusers;
}
### Anzahl der gestrigen Besucher
function sem_showUsersYesterday() {
global $wpdb;
$yesterdaysusers = $wpdb->get_var("SELECT visitors FROM ".$wpdb->statzhist." WHERE date = substr(DATE_SUB(NOW(), INTERVAL 1 DAY),1,10) LIMIT 0, 1");
return $yesterdaysusers;
}
##################################################### Ende TEMPLATE-Funktionen
?>

25
trunk/semr_image.php Normale Datei
Datei anzeigen

@ -0,0 +1,25 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
define('SEMMELSTATZR_STATZIMG', true);
/*
echo "<pre>";
print_r($_SERVER);
echo "</pre>";
*/
header('Cache-Control: no-cache');
header("X-Robots-Tag: noindex, nofollow", true);
require '../../../wp-load.php';
sem_writeStatz();
// Output transparent gif
header('Content-type: image/gif');
header('Content-length: 43');
echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
?>