.
*
* $Id$
*
*/
/**
* based upon semmelstatz
* Copyright (c) 2005-2009 Andreas 'Redunzl' Mueller (redunzl@gmx.de)
*
* @license http://www.gnu.org/licenses/gpl-2.0.html
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (version 2) as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
if(!current_user_can('manage_statz')) {
die(semr_i18n("Restricted Area"));
}
include_once plugin_dir_path(__FILE__).'includes/pChart/class/pData.class.php';
include_once plugin_dir_path(__FILE__).'includes/pChart/class/pDraw.class.php';
include_once plugin_dir_path(__FILE__).'includes/pChart/class/pImage.class.php';
/**
* chart for last 30 days
*
* @uses pChart
* @since 1.0.0
* @todo use own semR chart class
*
* @global wpdb $wpdb
* @return void
*/
function sem_drawLast30DaysGoo() {
global $wpdb;
//$sql = $wpdb->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 ORDER BY date ASC");
print "
".semr_i18n("Visitors: Last 30 days")."
";
print "";
if (empty($results)) {
print "... ".semr_i18n("no entries")."
";
return;
}
foreach ($results as $result) {
$visitors[] = $result->visitors;
$days[] = $result->days;
}
$maxvalue = max($visitors);
$daylabels = implode('|', $days);
$MyData = new pData();
$MyData->addPoints($visitors,"Visitors");
$MyData->setAxisName(0,"Hits");
$MyData->addPoints($days,"Days");
$MyData->setAbscissa("Days");
$myPicture = new pImage(780,150,$MyData);
$myPicture->Antialias = FALSE;
$myPicture->drawRectangle(0,0,779,149,array("R"=>0,"G"=>0,"B"=>0));
$myPicture->setFontProperties(array("FontName"=>plugin_dir_path(__FILE__)."includes/pChart/fonts/Bedizen.ttf","FontSize"=>8));
$myPicture->setGraphArea(30,20,760,130);
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200);
$myPicture->drawScale($scaleSettings);
$myPicture->drawBarChart();
@$myPicture->Render(WP_CONTENT_DIR."/cache/Last30DaysGoo.png");
print "";
//print "
";
if(is_readable(WP_CONTENT_DIR."/cache/Last30DaysGoo.png")) {
print '
';
} else if(!is_dir(WP_CONTENT_DIR."/cache")) {
print semr_i18n('No Chart: Cannot find cache-folder!');
} else if(!is_writable(WP_CONTENT_DIR."/cache")) {
print semr_i18n('No Chart: Missing rights for cache-folder!');
}
print "
";
print "";
print "
";
}
/**
* chart of all month
*
* @global wpdb $wpdb
* @return void
*/
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 "";
printf(semr_i18np("Visitors: Last %s month", "Visitors: Last %s month", $nummonths), $nummonths);
print "
";
print "";
if (empty($results)) {
print "... ".semr_i18n("no entries")."
";
return;
}
foreach ($results as $result) {
$visitors[] = $result->visitors;
$months[] = $result->months;
}
$maxvalue = max($visitors);
$monthlabels = implode('|', $months);
$MyData = new pData();
$MyData->addPoints($visitors,"Visitors");
$MyData->setAxisName(0,"Hits");
$MyData->addPoints($months,"Month");
$MyData->setAbscissa("Month");
$myPicture = new pImage(780,150,$MyData);
$myPicture->Antialias = FALSE;
$myPicture->drawRectangle(0,0,779,149,array("R"=>0,"G"=>0,"B"=>0));
$myPicture->setFontProperties(array("FontName"=>plugin_dir_path(__FILE__)."includes/pChart/fonts/Bedizen.ttf","FontSize"=>8));
$myPicture->setGraphArea(30,20,760,130);
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200);
$myPicture->drawScale($scaleSettings);
$myPicture->drawBarChart();
@$myPicture->Render(WP_CONTENT_DIR."/cache/AllMonthGoo.png");
print "";
//print "
";
if(is_readable(WP_CONTENT_DIR."/cache/AllMonthGoo.png")) {
print '
';
} else if(!is_dir(WP_CONTENT_DIR."/cache")) {
print semr_i18n('No Chart: Cannot find cache-folder!');
} else if(!is_writable(WP_CONTENT_DIR."/cache")) {
print semr_i18n('No Chart: Missing rights for cache-folder!');
}
print "
";
print "";
print "
";
}
/**
*
* @global wpdb $wpdb
* @return void
*/
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");
print "";
printf(semr_i18np("Visitors: %s day back", "Visitors: %s days back", $numdays), $numdays);
print "
";
print "";
if (empty($results)) {
print "... ".semr_i18n("no entries")."
";
return;
}
foreach($results as $result) {
$visitors[] = $result->visitors;
$hits[] = $result->hits;
$referers[] = $result->referers;
}
$maxvalue = max($visitors);
$MyData = new pData();
$MyData->addPoints($visitors,"Visitors");
$MyData->setAxisName(0,"Hits");
$MyData->addPoints($hits,"Hits");
$MyData->setAbscissa("Hits");
$myPicture = new pImage(780,150,$MyData);
$myPicture->Antialias = FALSE;
$myPicture->drawRectangle(0,0,779,149,array("R"=>0,"G"=>0,"B"=>0));
$myPicture->setFontProperties(array("FontName"=>plugin_dir_path(__FILE__)."includes/pChart/fonts/Bedizen.ttf","FontSize"=>8));
$myPicture->setGraphArea(30,20,760,130);
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200);
$myPicture->drawScale($scaleSettings);
$myPicture->drawBarChart();
@$myPicture->Render(WP_CONTENT_DIR."/cache/AllDaysGoo.png");
print "";
//print "
";
if(is_readable(WP_CONTENT_DIR."/cache/AllDaysGoo.png")) {
print '
';
} else if(!is_dir(WP_CONTENT_DIR."/cache")) {
print semr_i18n('No Chart: Cannot find cache-folder!');
} else if(!is_writable(WP_CONTENT_DIR."/cache")) {
print semr_i18n('No Chart: Missing rights for cache-folder!');
}
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 "";
printf(semr_i18np("Last %s day", "Last %s days", $numdays), $numdays);
print "
";
if (empty($results)) {
print "... ".semr_i18n("no entries")."";
return;
}
print "";
print "";
print "";
print "".semr_i18n("Date")." | ";
print "".semr_i18n("Visitors")." | ";
print "".semr_i18n("Hits")." | ";
print "".semr_i18n("Referrer")." | ";
print " | ";
print "
";
print "";
print "";
$sum_visitors = 0;
$sum_hits = 0;
$sum_referers = 0;
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 "".$date." | ";
print "".$visitors." | ";
print "".$hits." | ";
print "".$referers." | ";
print " | ";
print "
";
}
print " |
";
print "";
print "".semr_i18n("Total")." | ";
print "".$sum_visitors." | ";
print "".$sum_hits." | ";
print "".$sum_referers." | ";
print "
";
print "";
print "".semr_i18n("Average")." | ";
print "".ceil($sum_visitors / $numdays)." | ";
print "".ceil($sum_hits / $numdays)." | ";
print "".ceil($sum_referers / $numdays)." | ";
print "
";
print "";
print "
";
print "
";
}
### ANZEIGE HISTORY
print "";
print "
";
print "
SemmelstatzR > ".semr_i18n("History")."
";
sem_drawLast30DaysGoo();
sem_drawAllMonthGoo();
sem_drawAllDaysGoo();
sem_showAllDaysInNumbers();
sem_showCopyright();
print "
";
?>