diff --git a/trunk/ACHTUNG_Updater.txt b/trunk/ACHTUNG_Updater.txt new file mode 100644 index 0000000..86eb2c5 --- /dev/null +++ b/trunk/ACHTUNG_Updater.txt @@ -0,0 +1,10 @@ + +UPDATE auf Version 3.3: + +Es ist zwingend erforderlich, SEMMELSTATZ zu deaktivieren und den alten Ordner +SEMMELSTATZ aus dem Plugin-Verzeichnis zu löschen. Ein simples Überschreiben der +Plugin-Dateien funktioniert nicht, da sich die Namen der Dateien geändert haben. +Außerdem werden diverse Änderungen an den STATZ-Tabellen vorgenommen, die aber nur +bei Aktivierung des Plugins abgearbeitet werden. + +Ich bitte um Beachtung... \ No newline at end of file diff --git a/trunk/img/arin.png b/trunk/img/arin.png new file mode 100644 index 0000000..cdf3081 Binary files /dev/null and b/trunk/img/arin.png differ diff --git a/trunk/img/icon_observe.png b/trunk/img/icon_observe.png new file mode 100644 index 0000000..14fbffc Binary files /dev/null and b/trunk/img/icon_observe.png differ diff --git a/trunk/img/icon_template.png b/trunk/img/icon_template.png new file mode 100644 index 0000000..ad4fc9a Binary files /dev/null and b/trunk/img/icon_template.png differ diff --git a/trunk/img/ripe.png b/trunk/img/ripe.png new file mode 100644 index 0000000..8da70ba Binary files /dev/null and b/trunk/img/ripe.png differ diff --git a/trunk/img/statz.png b/trunk/img/statz.png new file mode 100644 index 0000000..af8bfdd Binary files /dev/null and b/trunk/img/statz.png differ diff --git a/trunk/img/statz_small.png b/trunk/img/statz_small.png new file mode 100644 index 0000000..eee9f5c Binary files /dev/null and b/trunk/img/statz_small.png differ diff --git a/trunk/img/utrace.png b/trunk/img/utrace.png new file mode 100644 index 0000000..f59a10d Binary files /dev/null and b/trunk/img/utrace.png differ diff --git a/trunk/lies_mich.txt b/trunk/lies_mich.txt new file mode 100644 index 0000000..d528d1b --- /dev/null +++ b/trunk/lies_mich.txt @@ -0,0 +1,18 @@ + ****************************************************** + * * + * SEMMELSTATZ * + * Statistik-Plugin für Wordress >= 2.7.x * + * * + ****************************************************** + +Plugin-URL: http://www.kopfhoch-studio.de/blog/2765 +Autor: Andreas Müller aka Redunzl Semmelmann +Copyright (c) 2005-2009 Andreas Müller & kopfhoch-studio Waiblingen, Deutschland + +Die komplette Dokumentation befindet sich im Blog: + +******************************************* +* * +* http://www.kopfhoch-studio.de/blog/2765 * +* * +******************************************* \ No newline at end of file diff --git a/trunk/semmelstatz-database.php b/trunk/semmelstatz-database.php new file mode 100644 index 0000000..609a284 --- /dev/null +++ b/trunk/semmelstatz-database.php @@ -0,0 +1,82 @@ +prefix; $lenpre = strlen($pre); + $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS"); + + print "
"; + print "
"; + print "

"; + print "

Semmelstatz › Datenbank

"; + + print "
Datenbank
"; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + foreach($tablesstatus as $key=>$tablestatus) { + + if(substr($tablestatus->Name,0,$lenpre) != $pre) continue; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + if($tablestatus->Data_free > 0) { + print ""; + } + else { + print ""; + } + + $row_usage += $tablestatus->Rows; + $data_usage += $tablestatus->Data_length; + $index_usage += $tablestatus->Index_length; + $total_usage += $tablestatus->Data_length + $tablestatus->Index_length; + $overhead_usage += $tablestatus->Data_free; + echo ''; + } + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + + print "
Nr.TabellenDatensätzeDatenIndexDaten & IndexÜberhang".($key+1)."".$tablestatus->Name."".number_format($tablestatus->Rows,0,',','.')."".number_format($tablestatus->Data_length/1024,0,',','.')." kb".number_format($tablestatus->Index_length/1024,0,',','.')." kb".number_format(($tablestatus->Data_length + $tablestatus->Index_length)/1024,0,',','.')." kb"; + print " ".number_format($tablestatus->Data_free/1024,2,',','.')." kb"; + print "--
Gesamt ".number_format($row_usage,0,',','.')."".number_format($data_usage/1024,0,',','.')." kb".number_format($index_usage/1024,0,',','.')." kb".number_format($total_usage/1024,0,',','.')." kb".number_format($overhead_usage/1024,2,',','.')." kb

Es werden ausschließlich die WORDPRESS-Tabellen angezeigt, die zum Blog '".get_option('blogname')."' gehören.

"; + print "
"; + + sem_showCopyright(); + + print "
"; + +?> \ No newline at end of file diff --git a/trunk/semmelstatz-history.php b/trunk/semmelstatz-history.php new file mode 100644 index 0000000..b5d1fbf --- /dev/null +++ b/trunk/semmelstatz-history.php @@ -0,0 +1,189 @@ +get_results("ALTER TABLE ".$wpdb->statzhist." ORDER BY date ASC"); + $results = $wpdb->get_results("SELECT DAY(date) as days, visitors FROM ".$wpdb->statzhist." WHERE date >= NOW() - INTERVAL 31 DAY"); + + print "
Besucher: Die letzten 30 Tage
"; + print "
"; + + if (empty($results)) { + print "... noch keine Einträge
"; + return; + } + + foreach ($results as $result) { + $visitors[] = $result->visitors; + $days[] = $result->days; + } + + $maxvalue = max($visitors); + $daylabels = implode('|', $days); + + print "
"; + + print ""; + + print "
"; + + print ""; + print "
"; + } + +### HISTORY Monatsgrafik GOOGLE-API + + function sem_drawAllMonthGoo() { + global $wpdb; + + $nummonths = $wpdb->get_var("SELECT MONTH(date) FROM ".$wpdb->statzhist); + $results = $wpdb->get_results("SELECT MONTH(date) as months, SUM(visitors) as visitors FROM ".$wpdb->statzhist." GROUP BY months ORDER BY date ASC"); + + print "
Besucher: Die letzten ".$nummonths." Monate
"; + print "
"; + + if (empty($results)) { + print "... noch keine Einträge
"; + return; + } + + foreach ($results as $result) { + $visitors[] = $result->visitors; + $months[] = $result->months; + } + + $maxvalue = max($visitors); + + $monthlabels = implode('|', $months); + + print "
"; + + print ""; + + print "
"; + + print ""; + print "
"; + } + +### HISTORY ALLE historischen Tage + + function sem_drawAllDaysGoo() { + global $wpdb; + + $numdays = $wpdb->get_var("SELECT COUNT(date) FROM ".$wpdb->statzhist); + + $results = $wpdb->get_results("SELECT referers, visitors, hits, substring(date,1,10) AS date + FROM ".$wpdb->statzhist." GROUP BY date ORDER BY date ASC"); + $visitors=$totaldays->visitors; + + print "
Besucher: ".$numdays." Tage zurück
"; + print "
"; + + if (empty($results)) { + print "... noch keine Einträge
"; + return; + } + + foreach($results as $result) { + $visitors[] = $result->visitors; + $hits[] = $result->hits; + $referers[] = $result->referers; + } + + $maxvalue = max($visitors); + + print "
"; + + print ""; + + print "
"; + + print ""; + print "
"; + } + + function sem_showAllDaysInNumbers() { + global $wpdb; + + $numdays = $wpdb->get_var("SELECT COUNT(date) as num FROM $wpdb->statzhist"); + + $results = $wpdb->get_results("SELECT referers, visitors, hits, substring(date,1,10) AS date + FROM ".$wpdb->statzhist." GROUP BY date ORDER BY date DESC"); + + print "
Die letzten ".$numdays." Tage
"; + if (empty($results)) { + print "... noch keine Einträge"; + return; + } + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + foreach($results as $key=>$result) { + $date = mysql2date('d.m.Y',$result->date); + $visitors = $result->visitors; $sum_visitors += $visitors; + $hits = $result->hits; $sum_hits += $hits; + $referers = $result->referers; $sum_referers += $referers; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + } + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print "
DatumBesucherHitsReferer 
".$date."".$visitors."".$hits."".$referers." 
 
Gesamt".$sum_visitors."".$sum_hits."".$sum_referers."
Durchschnitt".ceil($sum_visitors / $numdays)."".ceil($sum_hits / $numdays)."".ceil($sum_referers / $numdays)."
"; + print "
"; + } + + +### ANZEIGE HISTORY + + print "
"; + print "

"; + print "

Semmelstatz › Historie

"; + + sem_drawLast30DaysGoo(); + sem_drawAllMonthGoo(); + sem_drawAllDaysGoo(); + sem_showAllDaysInNumbers(); + sem_showCopyright(); + + print "
"; + +?> \ No newline at end of file diff --git a/trunk/semmelstatz-log.php b/trunk/semmelstatz-log.php new file mode 100644 index 0000000..e9a93ba --- /dev/null +++ b/trunk/semmelstatz-log.php @@ -0,0 +1,113 @@ +get_results("SELECT id, ip, time, referer, page, username FROM ".$wpdb->statz." ORDER BY time DESC LIMIT 0, ".$limit); + + print "
"; + print "

"; + print "

Semmelstatz › Log

"; + print "
Die neuesten ".$limit." Datensätze
"; + + if ($completerecords == NULL) { + print "... noch keine Einträge"; + return; + } + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + foreach ($completerecords as $key=>$completerecord) { + $id = $completerecord->id; + $ip = $completerecord->ip; + if(sem_checkIfIPisEncoded($ip) == true) $ip = sem_decodeIP($ip); + $date = mysql2date("d.m.Y G:i", $completerecord->time); + $referer = $completerecord->referer; + if($referer == "") { + $referer = "--"; + } + else { + if(strlen($referer) >= 50) { + $printreferer = substr($referer, 0, 50)."..."; + } + else { + $printreferer = $referer; + } + } + $keyword = sem_getKeyword($referer); + if(empty($keyword)) $keyword ='--'; + $page = $completerecord->page; + if ($page == 0) { + $link = get_option('siteurl'); + $title = "0"; //oder wie auch immer + } + else { + $link = get_permalink($page); + $postarray = get_post($page, ARRAY_A); + $title = $postarray['post_title']; + } + $username = $completerecord->username; + print ""; + print ""; + print ""; + print ""; + } + else { + if($mask != true) { + print "".$printreferer.""; + } + else { + $referer = htmlspecialchars($referer, ENT_QUOTES); + print "".$printreferer.""; + } + } + + print ""; + print ""; + print ""; + print ""; + } + + print ""; + print "
DatumTCP/IPRefererSuchbegriffPost/PageUsername
".$date." + +   + +   + + "; + if ($referer == "--") { + print "--".$keyword."".$title."".$username."
"; + print "
"; + + if (function_exists('sem_showCopyright')) sem_showCopyright(); + + print "
"; + +?> \ No newline at end of file diff --git a/trunk/semmelstatz-options.php b/trunk/semmelstatz-options.php new file mode 100644 index 0000000..044757b --- /dev/null +++ b/trunk/semmelstatz-options.php @@ -0,0 +1,344 @@ +

Einstellungen gespeichert

'; + } + + if(isset($_POST['trunc_save'])) { + if ($result == sem_truncateStatzTable()) { + echo "

Die statz-Tabelle wurde erfolgreich geleert.

"; + } + } + + if(isset($_POST['limit_save'])) { + $sem_options["statz_recdays_limit"] = $_POST["statz_recdays_limit"]; + + if($sem_options["statz_recdays_limit"] < 1 || (!is_numeric($sem_options["statz_recdays_limit"]))) $sem_options["statz_recdays_limit"] = 1; + update_option("semmelstatz_options", $sem_options); + + echo "

Der Wert für das Limit wurde erfolgreich gespeichert.

"; + } + + if(isset($_POST['limit_execute'])) { + $days = $sem_options["statz_recdays_limit"]; + if(($days >= sem_showStatzDays()) || (!is_numeric($days))) { + echo "

Der eingegebene Wert ist keine Zahl oder zu groß!

"; + } + else { + if ($result == sem_delOutOfLimit()) { + echo "

Die statz-Tabelle wurde erfolgreich auf ".$days." Tage gekürzt.

"; + } + } + } + + if(isset($_POST['cron_save'])) { + if($sem_options['statz_do_cron'] == true) { + $sem_options['statz_do_cron'] = false; + } + else { + $sem_options['statz_do_cron'] = true; + $sem_options['statz_next_cron'] = time() + 86400; + } + update_option("semmelstatz_options", $sem_options); + } + +?> + +
+ +
+ +

+

Semmelstatz › Einstellungen

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Blog-Administratoren aufzeichnen checked="checked" /> + Trackt alle Zugriffe des/der Blog-Admins im Frontend des Blogs - (default: AUS)
Blog-User aufzeichnen checked="checked" /> + Trackt alle Zugriffe der registrierten Blog-User im Frontend des Blogs - (default: AUS)
IP-Adressen codiert aufzeichnen checked="checked" /> + Der Gesetzgeber verbietet die Aufzeichnung der IP-Adresse eines Besuchers über dessen + zeitlichen Verbleib auf einer Webseite hinaus. Nach Aktivierung dieser Option rechnet SEMMELSTATZ + die IP-Adresse des Besuchers nach einem simplen arithmetischen Verfahren um. Somit schreibt + SEMMELSTATZ keine IP-Adressen im Klartext in die statz-Tabelle - (default: AUS)
Statz der letzten " style="text-align:center;" size="2" maxlength="2" /> + Tage anzeigen + checked="checked" /> + Tagesübersicht Besucher-Hits-Referer in absoluten Zahlen mit absteigendem Datum - (default: 7, AN)
" style="text-align:center;" size="2" maxlength="2" /> + Referer anzeigen + checked="checked" /> + Listet Links auf Webseiten, die auf dieses Blog + verweisen - (default: 10, AN)
Referer-Links via Google maskieren checked="checked" /> + Der Aufruf einer referenzierenden Webseite aus SEMMELSTATZ heraus würde die komplette URL + des Adminbereichs an den Webserver dieser Webseite übermitteln. Die Maskierung der Referer-Links + als GOOGLE-Weiterleitung verhindert dies. Funktioniert nicht mit allen Links - (default: AUS)
" style="text-align:center;" size="2" maxlength="2" /> + Suchbegriffe anzeigen + checked="checked" /> + Listet Links zu Suchbegriffen, mit denen Besucher + das Blog gefunden haben. Der Name der entsprechenden Searchengine (soweit bekannt) ist dem + Suchbegriff vorangestellt. Der WP-internen Suche steht ein INTERN voraus - (default: 10, AN)
Top" style="text-align:center;" size="2" maxlength="2" /> + Posts & Pages anzeigen + checked="checked" /> + Die meist gelesenen Posts & Pages, basierend + auf dem seit SEMMELSTATZ 3.2 neuen Zähler in der posts-Tabelle. Dieser Zähler ist, im Gegensatz + zur Ermittlung aus der statz-Tabelle, dauerhaft - (default: 10, AN)
Top10 Posts & Pages heute anzeigen checked="checked" /> + Die 10 meist gelesenen Posts & Pages des laufenden Tages mit Anzahl der Klicks - (default: AN)
Top" style="text-align:center;" size="2" maxlength="2" /> + Kommentierer anzeigen + checked="checked" /> + Die Top der Kommentierer auf Basis der + comments-Tabelle mit Anzahl ihrer Kommentare - (default: 10, AN)
Top10 kommentierter Posts anzeigen checked="checked" /> + Die Top10 der kommentierten Posts mit Anzahl der Kommentare - (default: AN)
Online-User anzeigen checked="checked" /> + Zeigt einen Besucher an, sobald er das Blog 'betreten' hat. Ist er ein Administrator oder regsitrierter + User des Blogs oder kommt mit einem Kommentar-COOKIE, wird er mit seinem Login- bzw. Kommentierer-Namen und + nicht als GAST angezeigt - (default: AN)
Sekunden, die ein User als anwesend gilt" style="text-align:center;" size="3" maxlength="4" /> + Dieser Wert legt fest, dass ein Besucher Sekunden als + anwesend gilt und so lange als ONLINE-Besucher angezeigt wird - (default: 180)
Heutige User anzeigen checked="checked" />(default: AN)
Mini-Statz im Dashboard anzeigen checked="checked" /> + Aktiviert das SEMMELSTATZ-Widget im Dashboard - (default: AUS)
Anzahl Datensätze im Log" style="text-align:center;" size="3" maxlength="4" /> + Anzahl der kompletten Datensätze DATUM-TCP/IP-REFERER-SUCHBEGRIFF-POST/PAGE-USERNAME + im SEMMELSTATZ-Log - (default: 100)
+ +

+ +
+ +

+

Semmelstatz › Statz-Tabellen

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ statz-Tabelle: ,xx Tage (Der aktuelle Tag ist natürlich nie komplett!!!)
+ statzhist-Tabelle: Tage +
" style="text-align:center;" + size="2" maxlength="3" />-Tage-Limit für die statz-Tabelle festlegen. + + + + Um die statz-Tabelle nicht ins Unendliche anwachsen zu lassen, macht es Sinn sie zu limitieren, + egal, ob nun manuell oder automatisch. Links die Anzahl der Statistiktage (nicht der zu löschenden Tage) + eintragen und speichern. Der Wert muss eine Ganzzahl >= 1 (default: 20) sein, sonst werden falsche + Werte in die statzhist-Tabelle übertragen. Der Wert gilt dann sowohl für das manuelle, wie + auch das automatische Limit.
Dieser Schritt löscht noch keine Daten, sondern speichert nur den Wert + fü das Limit! +
statz-Tabelle manuell limitieren + + Es erfolgt keine Rückfrage! Die statz-Tabelle wird einmalig auf + Tage gekürzt. Alle Datensätze über diesen + Zeitraum hinaus werden unwiderruflich gelöscht. Dies gilt nicht für die historischen Daten. +
statz-Tabelle automatisch limitieren + + + + + + Das automatische Limitieren der statz-Tabelle ist +  deaktiviert  + +  aktiviert  + + +
Nächster Lauf am + gegen Uhr. + +
Es erfolgt keine automatische Limitierung + +
statz-Tabelle leeren + + Die Datensätze der statz-Tabelle werden unwiderruflich geleert, und der Speicherplatz in der Datenbank mittels + OPTIMIZE TABLE freigegeben. ACHTUNG: Es erfolgt keine Rückfrage! Die Aufzeichnung + läuft ohne Unterbrechung weiter. Die Daten der statzhist-Tabelle bleiben unberührt. +
+
+ + + +
\ No newline at end of file diff --git a/trunk/semmelstatz-statz.php b/trunk/semmelstatz-statz.php new file mode 100644 index 0000000..2d17d7b --- /dev/null +++ b/trunk/semmelstatz-statz.php @@ -0,0 +1,501 @@ +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 "
".sem_showNumUsersOnline()." Besucher online - Heute: ".sem_showTodayStatz()."
"; + + if (empty($onlineusers)) { + print "... keine Einträge"; + print "
"; + return; + } + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + 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 ""; + print ""; + print ""; + print ""; + print ""; + print ""; + } + print ""; + print "
UsernamePost/PageTCP/IPZeit
".$username."".$title." + +   + +   + + $time
"; + print "
"; + } + + 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 "
Besucher: Die letzten 24 Stunden
"; + print "
"; + + if (empty($results)) { + print "... noch keine Einträge
"; + print "
"; + 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 "
"; + + print "Chart nicht verfügbar"; + + print "
"; + print ""; + print "
"; + } + + 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 "
".$limit."-Tage-Statistik
"; + if (empty($thedays)) { + print "... noch keine Einträge"; + print "
"; + return; + } + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + 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 ""; + print ""; + print ""; + print ""; + print ""; + print ""; + } + print ""; + print ""; + print ""; + print ""; + print "
DatumBesucherHitsReferer
$date$visitors$hits$referers
mehr...
"; + print "
"; + } + + 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 "
Die letzten ".$limit." Referer
"; + if (empty($lastreferers)) { + print "... noch keine Einträge"; + print "
"; + return; + } + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + 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 ""; + print ""; + if($mask != true) { + print ""; + } + else { + $referer = htmlspecialchars($referer, ENT_QUOTES); + print ""; + } + print ""; + } + print ""; + print "
ZeitReferer
".$time."".$printreferer."".$printreferer."
"; + print "
"; + } + + 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 "
Die letzten $limit Suchbegriffe
"; + if (empty($results)) { + print "... noch keine Einträge"; + print "
"; + return; + } + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + $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 ""; + print ""; + print ""; + print ""; + + print ""; + $i++; + } + if($i == $limit) break; + } + print ""; + print "
ZeitSuchbegriffTCP/IP
".$time."".$keyword." + +   + +   + +
"; + print "
"; + } + + 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 "
Die Top10 aller Posts & Pages heute
"; + if (empty($topreads)) { + print "... noch keine Einträge"; + print "
"; + return; + } + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + foreach ($topreads as $key=>$topread) { + $posttitle = $topread->posttitle; + $postname = $topread->postname; + $postid = $topread->postid; + $count = $topread->count; + print ""; + print ""; + print ""; + print ""; + print ""; + } + print ""; + print "
Post/PagePostnameHits
".$posttitle."".$postname."".$count."
"; + print "
"; + } + + 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 "
Die Top".$limit." aller Posts & Pages
"; + if (empty($topreads)) { + print "... noch keine Einträge"; + print "
"; + return; + } + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + foreach ($topreads as $key=>$topread) { + $posttitle = $topread->posttitle; + $postname = $topread->postname; + $postid = $topread->postid; + $count = $topread->count; + print ""; + print ""; + print ""; + print ""; + print ""; + } + print ""; + print "
Post/PagePostnameHits
".$posttitle."".$postname."".$count."
"; + print "
"; + } + + 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 "
Bekannte Besucher heute
"; + if (empty($todaysonlineusers)) { + print "... noch keine Einträge"; + print "
"; + return; + } + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + foreach ($todaysonlineusers as $key=>$todayonlineuser) { + $username = $todayonlineuser->username; + $num = $todayonlineuser->num; + print ""; + print ""; + print ""; + } + print ""; + print "
Besucher (Hits)
".$username." (".$num.")
"; + print "
"; + } + + 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 "
Die Top10 aller kommentierter Posts
"; + if (empty($topcommentedposts)) { + print "... noch keine Einträge"; + print "
"; + return; + } + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + foreach ($topcommentedposts as $key => $topcommentedpost) { + $posttitle = $topcommentedpost->post_title; + $count = $topcommentedpost->count; + $postid = $topcommentedpost->guid; + print ""; + print ""; + print ""; + print ""; + } + + print ""; + print "
Post/PageKommentare
 ".$posttitle."".$count."
"; + print "
"; + } + + 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 "
Die Top".$limit." aller Kommentierer
"; + if (empty($topcommenters)) { + print "... noch keine Einträge"; + print "
"; + return; + } + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + 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 ""; + print ""; + print ""; + print ""; + print ""; + print ""; + } + + print ""; + print "
UserEmailHomepageKommentare
".$commenter."".$email."".$homepage."".$count."
"; + print "
"; + } + +### AKTUELL Anzeige + + print "
"; + print "
"; + print "

"; + print "

Semmelstatz › Aktuell

"; + $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 "
"; + +?> \ No newline at end of file diff --git a/trunk/semmelstatz-templates.php b/trunk/semmelstatz-templates.php new file mode 100644 index 0000000..9966562 --- /dev/null +++ b/trunk/semmelstatz-templates.php @@ -0,0 +1,217 @@ +"; + print "
"; + print "

"; + print "

Semmelstatz › Template-Funktionen

"; + print "
"; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + + print ""; + print "
FunktionSyntaxRückgabewertHierBemerkung
sem_showTotalPostsGanzzahl$totalpostsAnzahl aller Beiträge
sem_showTotalCommentsGanzzahl$totalcommentsAnzahl aller Kommentare
sem_showTotalUsersGanzzahl$totalusersGesamtzahl aller Besucher seit Statistikaufzeichnung
sem_showAverageUserPerDayDezimal$averageuserperdayDurchschnittliche Anzahl der täglichen Besucher
sem_showFirstPostDateDatum (d.m.y)$firstpostdateDatum des 1. Posts
sem_showPostDaysGanzzahl$postdaysZeitraum in Tagen seit 1. Beitrag
em_showFirstCommentDateDatum (d.m.y)$firstcommentdateDatum des 1. Kommentars
sem_showCommentDaysGanzzahl$commentdaysZeitraum in Tagen seit 1. Kommentar
sem_showPostsPerDayDezimal$postsperdayDurchschnittliche Anzahl der Beiträge pro Tag
sem_showCommentsPerDayDezimal$commentsperdayDurchschnittliche Anzahl der Kommentare pro Tag
sem_showNumCommentersGanzzahl$numcommentersGesamtzahl aller Kommentierer
sem_showStatzStartDateDatum (d.m.y)$statzstartdateBeginn der Statistik
sem_showStatzDaysGanzzahl$statzdaysZeitraum der Statistik in Tagen
sem_showNumUsersOnlineGanzzahl$numusersonlineUser Online
sem_showLastCommentsFormatierte Listen/aDie neusten 'n' Kommentare mit Autor, Post, abwärts sortiert nach Datum
CSS-ID: #lastcomments
sem_showLastPostsFormatierte Listen/aDie neusten 'n' Posts mit Titel, abwärts sortiert nach Datum
CSS-ID: #lastposts
sem_showMostReadsFormatierte Listen/aDie 'n' meist gelesenen Post/Pages mit Hits in Klammern
CSS-ID: #mostreads
sem_showPostHitsInLoopGanzzahlNur im LoopZeigt die Anzahl der Hits eines Posts an. Funktioniert nur im LOOP.
"; + print "Sämtliche Funktionen (bis auf die letzte) sind außerhalb des LOOPS zu verwenden. Wird + SEMMELSTATZ deaktiviert, und die Verfügbarkeit der Templatefunktion ist nicht mittels + if (function_exists... sichergestellt, wird die Indexseite des Blogs fehlerhaft bzw. + überhaupt nicht dargestellt."; + print "
"; + print "
"; + print "
"; + + if (function_exists('sem_showCopyright')) sem_showCopyright(); + + print "
"; + + print ""; + +?> \ No newline at end of file diff --git a/trunk/semmelstatz.css b/trunk/semmelstatz.css new file mode 100644 index 0000000..c0a8c89 --- /dev/null +++ b/trunk/semmelstatz.css @@ -0,0 +1,126 @@ + + /********************************************** + * * + * semmelstatz.css v3.3 * + * Copyright: © 2005-2009 kopfhoch-studio * + * Kontakt: http://www.kopfhoch-studio.de/ * + * * + ***********************************************/ + + +p.statz, div.statz { + /* font-family: tahoma,verdana,arial,helvetica; */ + font-size: 17px; + font-weight: normal; + color: #344964; + text-align: left; + padding: 10px 0 5px 5px; + margin-top: 10px; +} + +hr { + color: #ddd; + background-color: #ddd; + height: 2px; + border: none; +} + +.statz a { + border: none; +} + +.statz a img { + border: none; + padding-top: 0px; +} + +table.statzelement { + width: 100%; +} + +.statzelement th, .statzelement td { + /* font-family: tahoma,verdana,arial,helvetica; */ + font-size: 11px; + color: #344964; + padding: 3px 0 3px 5px; +} + +.statzelement th { + font-weight: bold; + background: #eee; +} + +.statzelement td { + font-weight: normal; +} + +.statzelement td a { + text-decoration: none; +} + +.statzelement p { + /* font-family: tahoma,verdana,arial,helvetica; */ + font-size: 11px; +} + +.optionstable { + border:none; +} + +.optioncell { + border:1px solid #ccc; + padding:5px; + font-size:11px; + vertical-align:top; + width:20%; +} + +div.chart { + margin: 10px 0px 20px 30px; +} + +table.chartelement { + border: none; + border-collapse: collapse; +} + +.chartelement td { + vertical-align: bottom; + text-align: center; +} + +.chartelement td div { + border-top: 2px solid #dedede; + border-left: 2px solid #dedede; + border-right: 2px solid #999; + border-bottom: 2px solid #999; +} + +.chartelement th { + vertical-align: middle; + text-align: right; +} + +.copyright { + /* font-family: tahoma,verdana,arial,helvetica; */ + font-size: 11px; + text-align:center; + margin-top: 20px +} + +.alternate { + background: #eee; +} + +#icon-semmelstatz { + background: transparent url(img/icon_observe.png); +} + +#icon-template { + background: transparent url(img/icon_template.png); +} + +input.regular-text { + font-size: 11px; + width: 28em; +} \ No newline at end of file diff --git a/trunk/semmelstatz.php b/trunk/semmelstatz.php new file mode 100644 index 0000000..79dd57b --- /dev/null +++ b/trunk/semmelstatz.php @@ -0,0 +1,975 @@ +statz = $wpdb->prefix . 'statz'; + $wpdb->statzhist = $wpdb->prefix . 'statzhist'; + +### Auslesen des Domainnamens + global $homehost; + if(substr($_SERVER['SERVER_NAME'],0,4) == 'www.') { + $homehost = '%' . substr($_SERVER['SERVER_NAME'],4) . '%'; + } + else { + $homehost = '%' . $_SERVER['SERVER_NAME'] . '%'; + } + +### Erstellen des Top-Level-Menus im Adminbereich + add_action('admin_menu', 'semmelstatz_menu'); + function semmelstatz_menu() { + if (function_exists('add_menu_page')) { + add_menu_page('Semmelstatz','Semmelstatz', 'manage_statz', 'semmelstatz/semmelstatz-statz.php', '', plugins_url('semmelstatz/img/statz_small.png')); + } + if (function_exists('add_submenu_page')) { + add_submenu_page('semmelstatz/semmelstatz-statz.php', 'Aktuell', 'Aktuell', 'manage_statz', 'semmelstatz/semmelstatz-statz.php'); + add_submenu_page('semmelstatz/semmelstatz-statz.php', 'Historie', 'Historie', 'manage_statz', 'semmelstatz/semmelstatz-history.php'); + add_submenu_page('semmelstatz/semmelstatz-statz.php', 'Log', 'Log', 'manage_statz', 'semmelstatz/semmelstatz-log.php'); + add_submenu_page('semmelstatz/semmelstatz-statz.php', 'Datenbank', 'Datenbank', 'manage_statz', 'semmelstatz/semmelstatz-database.php'); + add_submenu_page('semmelstatz/semmelstatz-statz.php', 'Templates', 'Templates', 'manage_statz', 'semmelstatz/semmelstatz-templates.php'); + add_submenu_page('semmelstatz/semmelstatz-statz.php', 'Einstellungen', 'Einstellungen', 'manage_statz', 'semmelstatz/semmelstatz-options.php'); + } + } + +### Default-Werte der statz-Optionen in das Array 'semmelstatz_options' schreiben +add_action('init', 'sem_init_options'); + function sem_init_options() { + global $wpdb; + + if(get_option('statz_options')) { + $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'statz%';"); // Löschen der alten Optionen + } + + if(!get_option('semmelstatz_options')) { + $sem_options = array( + "statz_comment_limit" => 10, + "statz_datarecs_limit" => 100, + "statz_days_limit" => 7, + "statz_do_cron" => false, + "statz_encode_ip" => false, + "statz_keyword_limit" =>10, + "statz_referer_limit" => 10, + "statz_mask_referer" => false, + "statz_on_dashboard" => false, + "statz_online_time" => 180, + "statz_recdays_limit" => 20, + "statz_show_commenters" => true, + "statz_show_dailystatz" => true, + "statz_show_keywords" => true, + "statz_show_reads" => true, + "statz_show_referers" => true, + "statz_show_todayreads" => true, + "statz_show_todayusers" => true, + "statz_show_topcommposts" => true, + "statz_show_useronline" => true, + "statz_topreads_limit" => 10, + "statz_write_admins" => false, + "statz_write_users" => false + ); + add_option( 'semmelstatz_options', $sem_options ); + } + } + +### Anlegen der Tabellen, Optionen schreiben + add_action('activate_semmelstatz/semmelstatz.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'); + } elseif(@is_file(ABSPATH.'/wp-admin/includes/upgrade.php')) { + include_once(ABSPATH.'/wp-admin/includes/upgrade.php'); + } else { + die('Kann wp-admin/upgrade-functions.php und wp-admin/includes/upgrade.php nicht finden!'); + } + + $create_table = array(); + $create_table['statz'] = "CREATE TABLE $wpdb->statz ( + id int(11) unsigned NOT NULL auto_increment, + ip varchar(39) default NULL, + time datetime NOT NULL default '0000-00-00 00:00:00', + referer varchar(255) default NULL, + page int(11) unsigned NOT NULL default '0', + username varchar(255) default NULL, + PRIMARY KEY (`id`))"; + $create_table['statzhist'] = "CREATE TABLE $wpdb->statzhist ( + id int(10) unsigned NOT NULL auto_increment, + date datetime NOT NULL default '0000-00-00 00:00:00', + visitors int(10) unsigned NOT NULL default '0', + hits int(10) unsigned NOT NULL default '0', + referers int(10) unsigned NOT NULL default '0', + PRIMARY KEY (`id`))"; + + maybe_create_table($wpdb->statz, $create_table['statz']); + maybe_create_table($wpdb->statzhist, $create_table['statzhist']); + + $sql = $wpdb->query("SELECT host FROM $wpdb->statz"); + if($sql) { $wpdb->query("ALTER TABLE $wpdb->statz DROP host"); } + + $sql = $wpdb->query("SELECT keyword FROM $wpdb->statz"); + if($sql) { $wpdb->query("ALTER TABLE $wpdb->statz DROP keyword"); } + + maybe_add_column($wpdb->posts, 'hits', "ALTER TABLE $wpdb->posts ADD hits bigint(20) NOT NULL DEFAULT '0';"); // ab 3.2 + + $wpdb->query("ALTER TABLE $wpdb->statz CHANGE ip ip VARCHAR(39) NULL DEFAULT NULL;"); + + sem_init_options(); + sem_writeOldDaysToHist(); + + $role = get_role('administrator'); + 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() { + global $wpdb, $wp_query, $isBot, $isAdmin, $page; + $sem_options = get_option('semmelstatz_options'); ### optionsarray auslesen + + sem_writeYesterdayToHist(); + $useragent = $wpdb->escape($_SERVER['HTTP_USER_AGENT']); + $isBot = sem_AreYouBot($useragent); + $username = sem_getUsername(); + + if(($isBot == true) + || ($isAdmin == 0 && $sem_options['statz_write_users'] == false) + || ($isAdmin == 1 && $sem_options['statz_write_admins'] == false) + || is_404() + ) return; + + $userip = $wpdb->escape($_SERVER['REMOTE_ADDR']); + if($sem_options['statz_encode_ip'] == true) $userip = sem_encodeIP($userip); + + $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'; + } + + $readingnow = wp_title('', false); + if(empty($readingnow)) { + $page = 0; + } + else { + $page = $wp_query->post->ID; + } + + $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... + $sem_options = get_option('semmelstatz_options'); ### optionsarray auslesen + if($sem_options['statz_do_cron'] == true && $sem_options['statz_next_cron'] < time()) { + add_action('shutdown', 'sem_doCronStatzLimit'); // ...limitiere statz-Tabelle auf vorgegebenen Wert + } + +### CSS für den SEMMELSTATZ-Admin-Bereich + add_action('admin_head', 'semmelstatz_css'); + function semmelstatz_css() { + print "\n"; + } + +### Rendert eine Mini-STATZ. Idee: René Tauchnitz + function sem_dashboardStatz() { + print "

".sem_showNumUsersOnline() . " Besucher online - Heute: ".sem_showTodayStatz()."  + »»

"; + } + +### Widget für die Mini-STATZ + add_action('wp_dashboard_setup', 'sem_dashboardStatz_setup'); + function sem_dashboardStatz_setup() { + $sem_options = get_option('semmelstatz_options'); ### optionsarray auslesen + if(!current_user_can('manage_statz')) return; + if($sem_options['statz_on_dashboard'] != TRUE) return; + wp_add_dashboard_widget( 'sem_dashboardStatz', 'Semmelstatz', 'sem_dashboardStatz' ); + } + +### Mini-Statz für Dashboard-Widget & AKTUELL-Anzeige + function sem_showTodayStatz() { + 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"); + if (empty($thedays)) { + return "... noch keine Einträge"; + } + foreach($thedays as $key=>$theday) { + $date = mysql2date("l",$theday->date); + $hits = $theday->hits; + $visitors = $theday->visitors; + $referers = $theday->referers; + } + return $visitors." Besucher - ".$hits." Hits - ".$referers." Referer"; + } + +### 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('semmelstatz_options'); ### optionsarray auslesen + if (sem_countDaysInStatzTable() << $sem_options["statz_days_limit"]) { + $sem_options["statz_days_limit"] = sem_countDaysInStatzTable(); + update_option("semmelstatz_options", $sem_options); + } + } + +### Zeigt Copyright-Notiz an + function sem_showCopyright() { + print ""; + } + +### 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('semmelstatz_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('semmelstatz_options'); ### optionsarray auslesen + $statz_next_cron = $sem_options["statz_next_cron"] + 86400; + $sem_options["statz_next_cron"] = $statz_next_cron; + update_option("semmelstatz_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 "
"; + if (empty($lastposts)) { + print "... noch keine Beiträge"; + } + else { + print "Die letzten ".$num_posts." Beiträge
"; + foreach ($lastposts as $lastpost) { + $posttitle = $lastpost->post_title; + $permalink = get_permalink($lastpost->ID); + $postdate = $lastpost->post_date; + print "".$posttitle."
\n"; + } + } + print "
"; + } + +### 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 "
"; + if (empty($comments)) { + print "Keine Kommentare"; + } + else { + print "Die letzten ".$num_comments." Kommentare
"; + 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 um " . mysql2date("G:i", $comment->comment_date); + } + elseif($difference == 1) { + $commentdate = "Gestern um " . mysql2date("G:i", $comment->comment_date); + } + elseif($difference == 2) { + $commentdate = "Vorgestern um " . mysql2date("G:i", $comment->comment_date); + } + else { + $commentdate = mysql2date("j. F G:i", $comment->comment_date); + } + + print "$comment->comment_author@". get_the_title($comment->comment_post_ID) .", $commentdate
\n"; + } + } + print "
"; + } + +### 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 "
"; + if (empty($mostreads)) { + print "... noch keine Einträge"; + } + else { + print "Die ".$num_reads." meist gelesenen Beiträge
"; + foreach ($mostreads as $mostread) { + $posttitle = $mostread->posttitle; + $postid = $mostread->postid; + //$permalink = get_permalink($mostread->postid); + $hits = $mostread->hits; + print "".$posttitle." (".$hits.")
\n"; + } + } + print "
"; + } + +### 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 "
"; + if (empty($mostreads)) { + print "... noch keine Einträge"; + } + else { + print "Die ".$num_reads." meist gelesenen Beiträge
"; + foreach ($mostreads as $mostread) { + $posttitle = $mostread->posttitle; + $postid = $mostread->postid; + //$permalink = get_permalink($mostread->postid); + $count = $mostread->count; + print "".$posttitle." (".$count.")
\n"; + } + } + print "
"; + } + +### 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 "
"; + if (empty($mostcommented)) { + print "... noch keine Einträge"; + } + else { + print "Die ".$num_commented." meist kommentierten Beiträge
"; + + foreach ($mostcommented as $key => $mostcommented) { + $posttitle = $mostcommented->post_title; + $count = $mostcommented->count; + $postid = $mostcommented->guid; + print "".$posttitle." (".$count.")
\n"; + } + } + print "
"; + } + +### 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('semmelstatz_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 + +?> \ No newline at end of file