From 7a4793f2fa5316f8ba6aef4716f516536898e04f Mon Sep 17 00:00:00 2001 From: Oldperl <44996956+oldperl@users.noreply.github.com> Date: Thu, 1 Dec 2011 17:40:57 +0000 Subject: [PATCH] localistation, chart view and added some functions --- includes/functions.semr.php | 54 ++++++++++ semmelstatzR-statz.php | 196 ++++++++++++++++++++++-------------- 2 files changed, 177 insertions(+), 73 deletions(-) diff --git a/includes/functions.semr.php b/includes/functions.semr.php index 1e51417..992fc4c 100644 --- a/includes/functions.semr.php +++ b/includes/functions.semr.php @@ -415,5 +415,59 @@ function semr_i18np($sSingular, $sPlural, $iNumber, $sDomain = "semmelstatzR") { return _n($sSingular, $sPlural, $iNumber, $sDomain); } +/** + * + * @author anyexample.com + * @license http://www.anyexample.com/license/ + * @link http://www.anyexample.com/programming/php/php_convert_rgb_from_to_html_hex_color.xml + * + * @param string $color + * @return array + */ +function semr_hex2rgb($color) { + if ($color[0] == '#') + $color = substr($color, 1); + + if (strlen($color) == 6) + list($r, $g, $b) = array($color[0].$color[1], + $color[2].$color[3], + $color[4].$color[5]); + elseif (strlen($color) == 3) + list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]); + else + return false; + + $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); + + return array($r, $g, $b); +} + +/** + * + * @author anyexample.com + * @license http://www.anyexample.com/license/ + * @link http://www.anyexample.com/programming/php/php_convert_rgb_from_to_html_hex_color.xml + * + * @param int $r + * @param int $g + * @param int $b + * @return string + */ +function semr_rgb2hex($r, $g=-1, $b=-1) { + if (is_array($r) && sizeof($r) == 3) + list($r, $g, $b) = $r; + + $r = intval($r); $g = intval($g); + $b = intval($b); + + $r = dechex($r<0?0:($r>255?255:$r)); + $g = dechex($g<0?0:($g>255?255:$g)); + $b = dechex($b<0?0:($b>255?255:$b)); + + $color = (strlen($r) < 2?'0':'').$r; + $color .= (strlen($g) < 2?'0':'').$g; + $color .= (strlen($b) < 2?'0':'').$b; + return '#'.$color; +} ############################################## Ende SEMMELSTATZ-interne Funktionen ?> \ No newline at end of file diff --git a/semmelstatzR-statz.php b/semmelstatzR-statz.php index 9191b6f..d281f23 100644 --- a/semmelstatzR-statz.php +++ b/semmelstatzR-statz.php @@ -59,99 +59,147 @@ include_once plugin_dir_path(__FILE__).'includes/pChart/class/pImage.class.php'; $sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen $onlinetime = $sem_options["statz_online_time"]; + + /** @todo add show_vars to semr-config */ + $sem_options['show_utrace'] = $sem_options['show_whois'] = $sem_options['show_arin'] = true; $onlineusers = $wpdb->get_results("SELECT DISTINCT username, page, ip, time FROM ".$wpdb->statz." WHERE time > Now() - INTERVAL ".$onlinetime." SECOND GROUP BY ip ORDER BY page DESC"); - print "
".sem_showNumUsersOnline()." Besucher online - Heute: ".sem_showTodayStatz()."
"; + print "
"; + $iUsersOnline = (int) sem_showNumUsersOnline(); + printf("%s ".semr_i18np("Visitor online", "Visitors online", $iUsersOnline), $iUsersOnline); + print " - ".semr_i18n("Today").": ".sem_showTodayStatz()."
"; if (empty($onlineusers)) { - print "... keine Einträge"; - print "
"; + print "... ".semr_i18n("no entries").""; + print "
"; return; } - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; + print '
UsernamePost/PageTCP/IPZeit
'; + 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 { + $title = semr_i18n("startpage"); + } 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 + $title = get_post($page); + if(is_array($title)) { + $title = $title->post_title; + } else { + $link = null; + $title = semr_i18n("no page"); + } } $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 ''; + print ''; + print ''; + print ''; + print ''; } - print ""; - print "
'.semr_i18n("Username").''.semr_i18n("Post/Page").''.semr_i18n("TCP/IP").''.semr_i18n("Time").'
".$username."".$title." - -   - -   - - $time
'.$username.''; + print (is_null($link))?$title:''.$title.''; + print ''; + if($sem_options['show_arin']) { + print ''; + print ''; + print ' '; + } + if($sem_options['show_whois']) { + print ''; + print ''; + print ' '; + } + if($sem_options['show_utrace']) { + print ''; + print ''; + print ' '; + } + print ''.$time.'
"; - print "
"; + print ''; + print ''; + 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); +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 '
'; + print semr_i18n("Visitors: Last 24 hours").'
'; + print "
"; + + if(empty($results)) { + print '... '. semr_i18n("no entries at all").'
'; + print "
"; + return; + } + + $aHours = array(); + $aVisitors = array(); + $iInterval = 86400-7200; + + for($i=0;$i<24;$i++) { + $aHours[$i] = date("H", time() - $iInterval); + $iInterval = $iInterval - 3600; + $aVisitors[$i] = VOID; + } + + $iCount = 0; + $bFirst = true; + $atemp = array(); + + foreach($results as $aResult) { + $iDbHour = mysql2date('H', $aResult->hours); + $iKey = array_search($iDbHour, $aHours); + $aVisitors[$iKey] = $aResult->visitors; } $MyData = new pData(); - $MyData->addPoints($visitors,"Visitors"); + $MyData->addPoints($aVisitors,"Visitors"); $MyData->setAxisName(0,"Visitors"); - $MyData->addPoints($hours,"Hours"); + $MyData->addPoints($aHours,"Hours"); $MyData->setAbscissa("Hours"); - + $myPicture = new pImage(780,150,$MyData); - $myPicture->Antialias = FALSE; + $myPicture->Antialias = true; $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); + $scaleSettings = array( + //"DrawSubTicks"=>TRUE, + "GridR"=>200, + "GridG"=>200, + "GridB"=>200 + ); $myPicture->drawScale($scaleSettings); - $myPicture->drawBarChart(); - @$myPicture->Render(WP_CONTENT_DIR."/cache/24HourGoo.png"); - - print "
"; + $myPicture->drawBarChart(array("DisplayValues"=>true,"DisplayColor"=>DISPLAY_MANUAL,"DisplayPos"=>LABEL_POS_OUTSIDE)); + //$myPicture->drawSplineChart(); + $TextSettings = array("R"=>100,"G"=>100,"B"=>100,"FontSize"=>8,"Align"=>TEXT_ALIGN_TOPRIGHT); + $myPicture->drawText(770,5,"(c) 2011 semmelstatzR",$TextSettings); + + @$myPicture->Render(WP_CONTENT_DIR."/cache/24HourGoo.png"); + + print '
'; + if(is_readable(WP_CONTENT_DIR."/cache/24HourGoo.png")) { print ''; } else if(!is_dir(WP_CONTENT_DIR."/cache")) { @@ -177,8 +225,8 @@ include_once plugin_dir_path(__FILE__).'includes/pChart/class/pImage.class.php'; print "
".$limit."-Tage-Statistik
"; if (empty($thedays)) { - print "... noch keine Einträge"; - print "
"; + print '... '. semr_i18n("no entries at all").'
'; + print "
"; return; } print ""; @@ -238,8 +286,8 @@ include_once plugin_dir_path(__FILE__).'includes/pChart/class/pImage.class.php'; print "
Die letzten ".$limit." Referer
"; if (empty($lastreferers)) { - print "... noch keine Einträge"; - print "
"; + print '... '. semr_i18n("no entries at all").''; + print "
"; return; } print "
"; @@ -285,8 +333,8 @@ include_once plugin_dir_path(__FILE__).'includes/pChart/class/pImage.class.php'; print "
Die letzten $limit Suchbegriffe
"; if (empty($results)) { - print "... noch keine Einträge"; - print "
"; + print '... '. semr_i18n("no entries at all").''; + print "
"; return; } print "
"; @@ -336,8 +384,8 @@ include_once plugin_dir_path(__FILE__).'includes/pChart/class/pImage.class.php'; print "
Die Top10 aller Posts & Pages heute
"; if (empty($topreads)) { - print "... noch keine Einträge"; - print "
"; + print '... '. semr_i18n("no entries at all").''; + print "
"; return; } print "
"; @@ -376,8 +424,8 @@ include_once plugin_dir_path(__FILE__).'includes/pChart/class/pImage.class.php'; print "
Die Top".$limit." aller Posts & Pages
"; if (empty($topreads)) { - print "... noch keine Einträge"; - print "
"; + print '... '. semr_i18n("no entries at all").''; + print "
"; return; } print "
"; @@ -411,10 +459,12 @@ include_once plugin_dir_path(__FILE__).'includes/pChart/class/pImage.class.php'; $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
"; + print '
'; + print semr_i18n("Known visitors today"); + print '
'; if (empty($todaysonlineusers)) { - print "... noch keine Einträge"; - print "
"; + print '... '. semr_i18n("no entries at all").''; + print "
"; return; } print "
";