示例#1
0
function iriStatPressMain()
{
    global $wpdb;
    $table_name = $wpdb->prefix . "statpress";
    // OVERVIEW table
    $unique_color = "#114477";
    $web_color = "#3377B6";
    $rss_color = "#f38f36";
    $spider_color = "#83b4d8";
    $lastmonth = iri_StatPress_lastmonth();
    $thismonth = gmdate('Ym', current_time('timestamp'));
    $yesterday = gmdate('Ymd', current_time('timestamp') - 86400);
    $today = gmdate('Ymd', current_time('timestamp'));
    $tlm[0] = my_substr($lastmonth, 0, 4);
    $tlm[1] = my_substr($lastmonth, 4, 2);
    print "<div class='wrap'><h2>" . __('Overview', 'statpress') . "</h2>";
    print "<table class='widefat'><thead><tr>\r\n  <th scope='col'></th>\r\n  <th scope='col'>" . __('Total', 'statpress') . "</th>\r\n  <th scope='col'>" . __('Last month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', gmmktime(0, 0, 0, $tlm[1], 1, $tlm[0])) . "</font></th>\r\n  <th scope='col'>" . __('This month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) . "</font></th>\r\n  <th scope='col'>" . __('Target', 'statpress') . " " . __('This month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) . "</font></th>\r\n  <th scope='col'>" . __('Yesterday', 'statpress') . "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp') - 86400) . "</font></th>\r\n  <th scope='col'>" . __('Today', 'statpress') . "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp')) . "</font></th>\r\n  </tr></thead>\r\n  <tbody id='the-list'>";
    //###############################################################################################
    // VISITORS ROW
    print "<tr><td><div style='background:{$unique_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Visitors', 'statpress') . "</td>";
    //TOTAL
    $qry_total = $wpdb->get_row("\r\n    SELECT count(DISTINCT ip) AS visitors\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider=''\r\n  ");
    print "<td>" . $qry_total->visitors . "</td>\n";
    //LAST MONTH
    $qry_lmonth = $wpdb->get_row("\r\n    SELECT count(DISTINCT ip) AS visitors\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider=''\r\n    AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'\r\n  ");
    print "<td>" . $qry_lmonth->visitors . "</td>\n";
    //THIS MONTH
    $qry_tmonth = $wpdb->get_row("\r\n    SELECT count(DISTINCT ip) AS visitors\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider=''\r\n    AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'\r\n  ");
    if ($qry_lmonth->visitors != 0) {
        $pc = round(100 * ($qry_tmonth->visitors / $qry_lmonth->visitors) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->visitors . $qry_tmonth->change . "</td>\n";
    //TARGET
    $qry_tmonth->target = round($qry_tmonth->visitors / (time() - mktime(0, 0, 0, date('m'), date('1'), date('Y'))) * (86400 * date('t')));
    if ($qry_lmonth->visitors != 0) {
        $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->visitors) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
    //YESTERDAY
    $qry_y = $wpdb->get_row("\r\n    SELECT count(DISTINCT ip) AS visitors\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider=''\r\n    AND date = '" . mysql_real_escape_string($yesterday) . "'\r\n  ");
    print "<td>" . $qry_y->visitors . "</td>\n";
    //TODAY
    $qry_t = $wpdb->get_row("\r\n    SELECT count(DISTINCT ip) AS visitors\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider=''\r\n    AND date = '" . mysql_real_escape_string($today) . "'\r\n  ");
    print "<td>" . $qry_t->visitors . "</td>\n";
    print "</tr>";
    //###############################################################################################
    // PAGEVIEWS ROW
    print "<tr><td><div style='background:{$web_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Pageviews', 'statpress') . "</td>";
    //TOTAL
    $qry_total = $wpdb->get_row("\r\n    SELECT count(date) as pageview\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider=''\r\n  ");
    print "<td>" . $qry_total->pageview . "</td>\n";
    //LAST MONTH
    $prec = 0;
    $qry_lmonth = $wpdb->get_row("\r\n    SELECT count(date) as pageview\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider=''\r\n    AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'\r\n  ");
    print "<td>" . $qry_lmonth->pageview . "</td>\n";
    //THIS MONTH
    $qry_tmonth = $wpdb->get_row("\r\n    SELECT count(date) as pageview\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider=''\r\n    AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'\r\n  ");
    if ($qry_lmonth->pageview != 0) {
        $pc = round(100 * ($qry_tmonth->pageview / $qry_lmonth->pageview) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->pageview . $qry_tmonth->change . "</td>\n";
    //TARGET
    $qry_tmonth->target = round($qry_tmonth->pageview / (time() - mktime(0, 0, 0, date('m'), date('1'), date('Y'))) * (86400 * date('t')));
    if ($qry_lmonth->pageview != 0) {
        $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->pageview) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
    //YESTERDAY
    $qry_y = $wpdb->get_row("\r\n    SELECT count(date) as pageview\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider=''\r\n    AND date = '" . mysql_real_escape_string($yesterday) . "'\r\n  ");
    print "<td>" . $qry_y->pageview . "</td>\n";
    //TODAY
    $qry_t = $wpdb->get_row("\r\n    SELECT count(date) as pageview\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider=''\r\n    AND date = '" . mysql_real_escape_string($today) . "'\r\n  ");
    print "<td>" . $qry_t->pageview . "</td>\n";
    print "</tr>";
    //###############################################################################################
    // SPIDERS ROW
    print "<tr><td><div style='background:{$spider_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Spiders', 'statpress') . "</td>";
    //TOTAL
    $qry_total = $wpdb->get_row("\r\n    SELECT count(date) as spiders\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider<>''\r\n  ");
    print "<td>" . $qry_total->spiders . "</td>\n";
    //LAST MONTH
    $prec = 0;
    $qry_lmonth = $wpdb->get_row("\r\n    SELECT count(date) as spiders\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider<>''\r\n    AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'\r\n  ");
    print "<td>" . $qry_lmonth->spiders . "</td>\n";
    //THIS MONTH
    $prec = $qry_lmonth->spiders;
    $qry_tmonth = $wpdb->get_row("\r\n    SELECT count(date) as spiders\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider<>''\r\n    AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'\r\n  ");
    if ($qry_lmonth->spiders != 0) {
        $pc = round(100 * ($qry_tmonth->spiders / $qry_lmonth->spiders) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->spiders . $qry_tmonth->change . "</td>\n";
    //TARGET
    $qry_tmonth->target = round($qry_tmonth->spiders / (time() - mktime(0, 0, 0, date('m'), date('1'), date('Y'))) * (86400 * date('t')));
    if ($qry_lmonth->spiders != 0) {
        $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->spiders) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
    //YESTERDAY
    $qry_y = $wpdb->get_row("\r\n    SELECT count(date) as spiders\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider<>''\r\n    AND date = '" . mysql_real_escape_string($yesterday) . "'\r\n  ");
    print "<td>" . $qry_y->spiders . "</td>\n";
    //TODAY
    $qry_t = $wpdb->get_row("\r\n    SELECT count(date) as spiders\r\n    FROM {$table_name}\r\n    WHERE feed=''\r\n    AND spider<>''\r\n    AND date = '" . mysql_real_escape_string($today) . "'\r\n  ");
    print "<td>" . $qry_t->spiders . "</td>\n";
    print "</tr>";
    //###############################################################################################
    // FEEDS ROW
    print "<tr><td><div style='background:{$rss_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Feeds', 'statpress') . "</td>";
    //TOTAL
    $qry_total = $wpdb->get_row("\r\n    SELECT count(date) as feeds\r\n    FROM {$table_name}\r\n    WHERE feed<>''\r\n    AND spider=''\r\n  ");
    print "<td>" . $qry_total->feeds . "</td>\n";
    //LAST MONTH
    $qry_lmonth = $wpdb->get_row("\r\n    SELECT count(date) as feeds\r\n    FROM {$table_name}\r\n    WHERE feed<>''\r\n    AND spider=''\r\n    AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'\r\n  ");
    print "<td>" . $qry_lmonth->feeds . "</td>\n";
    //THIS MONTH
    $qry_tmonth = $wpdb->get_row("\r\n    SELECT count(date) as feeds\r\n    FROM {$table_name}\r\n    WHERE feed<>''\r\n    AND spider=''\r\n    AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'\r\n  ");
    if ($qry_lmonth->feeds != 0) {
        $pc = round(100 * ($qry_tmonth->feeds / $qry_lmonth->feeds) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->feeds . $qry_tmonth->change . "</td>\n";
    //TARGET
    $qry_tmonth->target = round($qry_tmonth->feeds / (time() - mktime(0, 0, 0, date('m'), date('1'), date('Y'))) * (86400 * date('t')));
    if ($qry_lmonth->feeds != 0) {
        $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->feeds) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
    $qry_y = $wpdb->get_row("\r\n    SELECT count(date) as feeds\r\n    FROM {$table_name}\r\n    WHERE feed<>''\r\n    AND spider=''\r\n    AND date = '" . mysql_real_escape_string($yesterday) . "'\r\n  ");
    print "<td>" . $qry_y->feeds . "</td>\n";
    $qry_t = $wpdb->get_row("\r\n    SELECT count(date) as feeds\r\n    FROM {$table_name}\r\n    WHERE feed<>''\r\n    AND spider=''\r\n    AND date = '" . mysql_real_escape_string($today) . "'\r\n  ");
    print "<td>" . $qry_t->feeds . "</td>\n";
    print "</tr></table><br />\n\n";
    //###############################################################################################
    //###############################################################################################
    // THE GRAPHS
    // last "N" days graph  NEW
    $gdays = get_option('statpress_daysinoverviewgraph');
    if ($gdays == 0) {
        $gdays = 20;
    }
    //  $start_of_week = get_settings('start_of_week');
    $start_of_week = get_option('start_of_week');
    print '<table width="100%" border="0"><tr>';
    $qry = $wpdb->get_row("\r\n    SELECT count(date) as pageview, date\r\n    FROM {$table_name}\r\n    GROUP BY date HAVING date >= '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gdays) . "'\r\n    ORDER BY pageview DESC\r\n    LIMIT 1\r\n  ");
    $maxxday = $qry->pageview;
    if ($maxxday == 0) {
        $maxxday = 1;
    }
    // Y
    $gd = 90 / $gdays . '%';
    for ($gg = $gdays - 1; $gg >= 0; $gg--) {
        //TOTAL VISITORS
        $qry_visitors = $wpdb->get_row("\r\n      SELECT count(DISTINCT ip) AS total\r\n      FROM {$table_name}\r\n      WHERE feed=''\r\n      AND spider=''\r\n      AND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'\r\n    ");
        $px_visitors = round($qry_visitors->total * 100 / $maxxday);
        //TOTAL PAGEVIEWS (we do not delete the uniques, this is falsing the info.. uniques are not different visitors!)
        $qry_pageviews = $wpdb->get_row("\r\n      SELECT count(date) as total\r\n      FROM {$table_name}\r\n      WHERE feed=''\r\n      AND spider=''\r\n      AND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'\r\n    ");
        $px_pageviews = round($qry_pageviews->total * 100 / $maxxday);
        //TOTAL SPIDERS
        $qry_spiders = $wpdb->get_row("\r\n      SELECT count(ip) AS total\r\n      FROM {$table_name}\r\n      WHERE feed=''\r\n      AND spider<>''\r\n      AND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'\r\n    ");
        $px_spiders = round($qry_spiders->total * 100 / $maxxday);
        //TOTAL FEEDS
        $qry_feeds = $wpdb->get_row("\r\n      SELECT count(ip) AS total\r\n      FROM {$table_name}\r\n      WHERE feed<>''\r\n      AND spider=''\r\n      AND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'\r\n    ");
        $px_feeds = round($qry_feeds->total * 100 / $maxxday);
        $px_white = 100 - $px_feeds - $px_spiders - $px_pageviews - $px_visitors;
        print '<td width="' . $gd . '" valign="bottom"';
        if ($start_of_week == gmdate('w', current_time('timestamp') - 86400 * $gg)) {
            print ' style="border-left:2px dotted gray;"';
        }
        // week-cut
        print "><div style='float:left;height: 100%;width:100%;font-family:Helvetica;font-size:7pt;text-align:center;border-right:1px solid white;color:black;'>\r\n    <div style='background:#ffffff;width:100%;height:" . $px_white . "px;'></div>\r\n    <div style='background:{$unique_color};width:100%;height:" . $px_visitors . "px;' title='" . $qry_visitors->total . " " . __('visitors', 'statpress') . "'></div>\r\n    <div style='background:{$web_color};width:100%;height:" . $px_pageviews . "px;' title='" . $qry_pageviews->total . " " . __('pageviews', 'statpress') . "'></div>\r\n    <div style='background:{$spider_color};width:100%;height:" . $px_spiders . "px;' title='" . $qry_spiders->total . " " . __('spiders', 'statpress') . "'></div>\r\n    <div style='background:{$rss_color};width:100%;height:" . $px_feeds . "px;' title='" . $qry_feeds->total . " " . __('feeds', 'statpress') . "'></div>\r\n    <div style='background:gray;width:100%;height:1px;'></div>\r\n    <br />" . gmdate('d', current_time('timestamp') - 86400 * $gg) . ' ' . gmdate('M', current_time('timestamp') - 86400 * $gg) . "</div></td>\n";
    }
    print '</tr></table>';
    print '</div>';
    // END OF OVERVIEW
    //###################################################################################################
    $querylimit = "LIMIT 20";
    // Tabella Last hits
    print "<div class='wrap'><h2>" . __('Last hits', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('IP', 'statpress') . "</th><th scope='col'>" . __('Threat', 'statpress') . "</th><th scope='col'>" . __('Domain', 'statpress') . "</th><th scope='col'>" . __('Page', 'statpress') . "</th><th scope='col'>" . __('OS', 'statpress') . "</th><th scope='col'>" . __('Browser', 'statpress') . "</th><th scope='col'>" . __('Feed', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $fivesdrafts = $wpdb->get_results("SELECT * FROM {$table_name} WHERE (os<>'' OR feed<>'') order by id DESC {$querylimit}");
    foreach ($fivesdrafts as $fivesdraft) {
        print "<tr>";
        print "<td>" . irihdate($fivesdraft->date) . "</td>";
        print "<td>" . $fivesdraft->time . "</td>";
        print "<td>" . $fivesdraft->ip . "</td>";
        print "<td>" . $fivesdraft->threat_score;
        if ($fivesdraft->threat_score > 0) {
            print "/";
            if ($fivesdraft->threat_type == 0) {
                print "Sp";
            } else {
                if (($fivesdraft->threat_type & 1) == 1) {
                    print "S";
                }
                // Suspicious
                if (($fivesdraft->threat_type & 2) == 2) {
                    print "H";
                }
                // Harvester
                if (($fivesdraft->threat_type & 4) == 4) {
                    print "C";
                }
                // Comment spammer
            }
        }
        print "<td>" . $fivesdraft->nation . "</td>";
        print "<td>" . iri_StatPress_Abbrevia(iri_StatPress_Decode($fivesdraft->urlrequested), 30) . "</td>";
        print "<td>" . $fivesdraft->os . "</td>";
        print "<td>" . $fivesdraft->browser . "</td>";
        print "<td>" . $fivesdraft->feed . "</td>";
        print "</tr>";
    }
    print "</table></div>";
    // Last Search terms
    print "<div class='wrap'><h2>" . __('Last search terms', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('Terms', 'statpress') . "</th><th scope='col'>" . __('Engine', 'statpress') . "</th><th scope='col'>" . __('Result', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,referrer,urlrequested,search,searchengine FROM {$table_name} WHERE search<>'' ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td><a href='" . $rk->referrer . "'>" . $rk->search . "</a></td><td>" . $rk->searchengine . "</td><td><a href='" . irigetblogurl() . (strpos($rk->urlrequested, 'index.php') === FALSE ? $rk->urlrequested : '') . "'>" . __('page viewed', 'statpress') . "</a></td></tr>\n";
    }
    print "</table></div>";
    // Referrer
    print "<div class='wrap'><h2>" . __('Last referrers', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('URL', 'statpress') . "</th><th scope='col'>" . __('Result', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,referrer,urlrequested FROM {$table_name} WHERE ((referrer NOT LIKE '" . get_option('home') . "%') AND (referrer <>'') AND (searchengine='')) ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td><a href='" . $rk->referrer . "'>" . iri_StatPress_Abbrevia($rk->referrer, 80) . "</a></td><td><a href='" . irigetblogurl() . (strpos($rk->urlrequested, 'index.php') === FALSE ? $rk->urlrequested : '') . "'>" . __('page viewed', 'statpress') . "</a></td></tr>\n";
    }
    print "</table></div>";
    // Last Agents
    print "<div class='wrap'><h2>" . __('Last agents', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('Agent', 'statpress') . "</th><th scope='col'>" . __('What', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,agent,os,browser,spider FROM {$table_name} WHERE (agent <>'') ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td>" . $rk->agent . "</td><td> " . $rk->os . " " . $rk->browser . " " . $rk->spider . "</td></tr>\n";
    }
    print "</table></div>";
    // Last pages
    print "<div class='wrap'><h2>" . __('Last pages', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('Page', 'statpress') . "</th><th scope='col'>" . __('What', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,urlrequested,os,browser,spider FROM {$table_name} WHERE (spider='' AND feed='') ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td>" . iri_StatPress_Abbrevia(iri_StatPress_Decode($rk->urlrequested), 60) . "</td><td> " . $rk->os . " " . $rk->browser . " " . $rk->spider . "</td></tr>\n";
    }
    print "</table></div>";
    // Last Spiders
    print "<div class='wrap'><h2>" . __('Last spiders', 'statpress') . "</h2>";
    print "<table class='widefat'><thead><tr>";
    print "<th scope='col'>" . __('Date', 'statpress') . "</th>";
    print "<th scope='col'>" . __('Time', 'statpress') . "</th>";
    print "<th scope='col'>" . __('Spider', 'statpress') . "</th>";
    print "<th scope='col'>" . __('Page', 'statpress') . "</th>";
    print "<th scope='col'>" . __('Agent', 'statpress') . "</th>";
    print "</tr></thead><tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,agent,spider,urlrequested,agent FROM {$table_name} WHERE (spider<>'') ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td>";
        print "<td>" . $rk->time . "</td>";
        print "<td>" . $rk->spider . "</td>";
        print "<td>" . iri_StatPress_Abbrevia(iri_StatPress_Decode($rk->urlrequested), 30) . "</td>";
        print "<td> " . $rk->agent . "</td></tr>\n";
    }
    print "</table></div>";
    print "<br />";
    print "&nbsp;<i>" . __('StatPress table size', 'statpress') . ": <b>" . iritablesize($wpdb->prefix . "statpress") . "</b></i><br />";
    print "&nbsp;<i>" . __('StatPress current time', 'statpress') . ": <b>" . current_time('mysql') . "</b></i><br />";
    print "&nbsp;<i>" . __('RSS2 url', 'statpress') . ": <b>" . get_bloginfo('rss2_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('rss2_url')) . ")</b></i><br />";
    print "&nbsp;<i>" . __('ATOM url', 'statpress') . ": <b>" . get_bloginfo('atom_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('atom_url')) . ")</b></i><br />";
    print "&nbsp;<i>" . __('RSS url', 'statpress') . ": <b>" . get_bloginfo('rss_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('rss_url')) . ")</b></i><br />";
    print "&nbsp;<i>" . __('COMMENT RSS2 url', 'statpress') . ": <b>" . get_bloginfo('comments_rss2_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('comments_rss2_url')) . ")</b></i><br />";
    print "&nbsp;<i>" . __('COMMENT ATOM url', 'statpress') . ": <b>" . get_bloginfo('comments_atom_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('comments_atom_url')) . ")</b></i><br />";
}
示例#2
0
function iriValueTable($fld, $fldtitle, $limit = 0, $param = "", $queryfld = "", $exclude = "")
{
    /* Maddler 04112007: 添加了参数 */
    global $wpdb;
    $table_name = $wpdb->prefix . "statpress";
    $to_time = current_time('timestamp');
    if (strlen(get_option("statpress_details_period")) > 0) {
        $period = get_option("statpress_details_period");
    } else {
        $period = "1 month";
        update_option("statpress_details_period", $period);
    }
    $from_time = strtotime('-' . $period, $to_time);
    $exclude .= " and (statuscode != '404' or statuscode is null)";
    #$fc_statpress = $wpdb->query("select * from $table_name where feed!='' and timestamp between $from_time and $to_time;");
    //$qry = $wpdb->get_results("select count(DISTINCT(IP)) as feedcounts from $table_name where feed!='' and timestamp between $from_time and $to_time;");
    if ($queryfld == '') {
        $queryfld = $fld;
    }
    print "<div class='wrap'><table align=center><tr><td align=center>";
    print "<h3>{$fldtitle}</h3>(" . __("recently", "statpresscn") . " " . $period . ")<table style='width:100%;padding:0px;margin:0px;' cellpadding=0 cellspacing=0><thead><tr><th style='width:220px;background-color:white;'></th><th style='width:60px;background-color:white;'><u>" . __('Visits', 'statpresscn') . "</u></th><th style='background-color:white;'></th></tr></thead>";
    print "<tbody id='the-list'>";
    $rks = $wpdb->get_var("SELECT count({$param} {$queryfld}) as rks FROM {$table_name} where timestamp between {$from_time} and {$to_time} {$exclude};");
    if ($rks > 0) {
        $sql = "SELECT count({$param} {$queryfld}) as pageview, {$fld} FROM {$table_name} where timestamp between {$from_time} and {$to_time} {$exclude}  GROUP BY {$fld} ORDER BY pageview DESC";
        if ($limit > 0) {
            $sql = $sql . " LIMIT {$limit}";
        }
        $qry = $wpdb->get_results($sql);
        $tdwidth = 250;
        $red = 131;
        $green = 180;
        $blue = 216;
        $deltacolor = round(250 / count($qry), 0);
        //	    $chl="";
        //	    $chd="t:";
        foreach ($qry as $rk) {
            $pc = round($rk->pageview * 100 / $rks, 1);
            if ($fld == 'date') {
                $rk->{$fld} = irihdate($rk->{$fld});
            }
            if ($fld == 'urlrequested') {
                $rk->{$fld} = iri_StatPress_Decode($rk->{$fld});
            }
            //			$chl.=urlencode(substr($rk->$fld,0,50))."|";
            //			$chd.=($tdwidth*$pc/100)."|";
            print "<tr><td style='width:250px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;'>";
            if ($fld == "referrer") {
                echo "<a href='" . $rk->{$fld} . "' target='_heart5'>";
            }
            echo iri_StatPress_Abbrevia(urldecode($rk->{$fld}), 26);
            if ($fld == "referrer") {
                echo "</a>";
            }
            print "</td><td style='text-align:center;'>" . $rk->pageview . "</td>";
            // <td style='text-align:right'>$pc%</td>";
            print "<td><div style='text-align:right;padding:2px;font-family:helvetica;font-size:7pt;font-weight:bold;height:16px;width:" . $tdwidth * $pc / 100 . "px;background:" . irirgbhex($red, $green, $blue) . ";border-top:1px solid " . irirgbhex($red + 20, $green + 20, $blue) . ";border-right:1px solid " . irirgbhex($red + 30, $green + 30, $blue) . ";border-bottom:1px solid " . irirgbhex($red - 20, $green - 20, $blue) . ";'>{$pc}%</div>";
            print "</td></tr>\n";
            $red = $red + $deltacolor;
            $blue = $blue - $deltacolor / 2;
        }
    }
    print "</table>\n</td><td bgcolor=gray><font color=white>*vs*</font></td>";
    print "<td align=center><h3>{$fldtitle}</h3>(" . __("all stats days", "statpresscn") . ")<table style='width:100%;padding:0px;margin:0px;' cellpadding=0 cellspacing=0><thead><tr><th style='width:220px;background-color:white;'></th><th style='width:60px;background-color:white;'><u>" . __('Visits', 'statpresscn') . "</u></th><th style='background-color:white;'></th></tr></thead>";
    print "<tbody id='the-list'>";
    $rks = $wpdb->get_var("SELECT count({$param} {$queryfld}) as rks FROM {$table_name} WHERE 1=1 {$exclude};");
    if ($rks > 0) {
        $sql = "SELECT count({$param} {$queryfld}) as pageview, {$fld} FROM {$table_name} WHERE 1=1 {$exclude}  GROUP BY {$fld} ORDER BY pageview DESC";
        if ($limit > 0) {
            $sql = $sql . " LIMIT {$limit}";
        }
        $qry = $wpdb->get_results($sql);
        $tdwidth = 250;
        $red = 131;
        $green = 180;
        $blue = 216;
        $deltacolor = round(250 / count($qry), 0);
        //	    $chl="";
        //	    $chd="t:";
        foreach ($qry as $rk) {
            $pc = round($rk->pageview * 100 / $rks, 1);
            if ($fld == 'date') {
                $rk->{$fld} = irihdate($rk->{$fld});
            }
            if ($fld == 'urlrequested') {
                $rk->{$fld} = iri_StatPress_Decode($rk->{$fld});
            }
            print "<tr><td style='width:250px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;'>";
            if ($fld == "referrer") {
                echo "<a href='" . $rk->{$fld} . "' target='_heart5'>";
            }
            echo iri_StatPress_Abbrevia(urldecode($rk->{$fld}), 26);
            if ($fld == "referrer") {
                echo "</a>";
            }
            print "</td><td style='text-align:center;'>" . $rk->pageview . "</td>";
            // <td style='text-align:right'>$pc%</td>";
            print "<td><div style='text-align:right;padding:2px;font-family:helvetica;font-size:7pt;font-weight:bold;height:16px;width:" . $tdwidth * $pc / 100 . "px;background:" . irirgbhex($red, $green, $blue) . ";border-top:1px solid " . irirgbhex($red + 20, $green + 20, $blue) . ";border-right:1px solid " . irirgbhex($red + 30, $green + 30, $blue) . ";border-bottom:1px solid " . irirgbhex($red - 20, $green - 20, $blue) . ";'>{$pc}%</div>";
            print "</td></tr>\n";
            $red = $red + $deltacolor;
            $blue = $blue - $deltacolor / 2;
        }
    }
    print "</table>\n";
    print "</td></table>";
    //	print "<img src=http://chart.apis.google.com/chart?cht=p3&chd=".($chd)."&chs=400x200&chl=".($chl)."&chco=1B75DF,92BF23>\n";
    print "</div>\n";
}
示例#3
0
function iriStatPressMain()
{
    global $wpdb;
    $table_name = $wpdb->prefix . "statpress";
    // OVERVIEW table
    $unique_color = "#114477";
    $web_color = "#3377B6";
    $rss_color = "#f38f36";
    $spider_color = "#83b4d8";
    $lastmonth = iri_StatPress_lastmonth();
    $thismonth = gmdate('Ym', current_time('timestamp'));
    $yesterday = gmdate('Ymd', current_time('timestamp') - 86400);
    $today = gmdate('Ymd', current_time('timestamp'));
    $tlm[0] = my_substr($lastmonth, 0, 4);
    $tlm[1] = my_substr($lastmonth, 4, 2);
    print "<div class='wrap'><h2>" . __('Overview', 'statpress') . "</h2>";
    print "<table class='widefat'><thead><tr>\n\t<th scope='col'></th>\n\t<th scope='col'>" . __('Total', 'statpress') . "</th>\n\t<th scope='col'>" . __('Last month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', gmmktime(0, 0, 0, $tlm[1], 1, $tlm[0])) . "</font></th>\n\t<th scope='col'>" . __('This month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) . "</font></th>\n\t<th scope='col'>" . __('Target This month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) . "</font></th>\n\t<th scope='col'>" . __('Yesterday', 'statpress') . "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp') - 86400) . "</font></th>\n\t<th scope='col'>" . __('Today', 'statpress') . "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp')) . "</font></th>\n\t</tr></thead>\n\t<tbody id='the-list'>";
    //###############################################################################################
    // VISITORS ROW
    print "<tr><td><div style='background:{$unique_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Visitors', 'statpress') . "</td>";
    //TOTAL
    $qry_total = $wpdb->get_row("SELECT count(DISTINCT ip) AS visitors\n                                       FROM {$table_name}\n                                       WHERE feed='' AND spider='' AND ip IS NOT NULL ");
    print "<td>" . $qry_total->visitors . "</td>\n";
    //LAST MONTH
    $qry_lmonth = $wpdb->get_row("SELECT count(DISTINCT ip) AS visitors\n                                        FROM {$table_name}\n                                        WHERE feed='' AND spider=''  AND ip IS NOT NULL AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'");
    print "<td>" . $qry_lmonth->visitors . "</td>\n";
    //THIS MONTH
    $qry_tmonth = $wpdb->get_row("SELECT count(DISTINCT ip) AS visitors\n                                        FROM {$table_name}\n                                        WHERE feed='' AND spider=''  AND ip IS NOT NULL AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'");
    if ($qry_lmonth->visitors != 0) {
        $pc = round(100 * ($qry_tmonth->visitors / $qry_lmonth->visitors) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->visitors . $qry_tmonth->change . "</td>\n";
    //TARGET
    $tmonthtarget = round($qry_tmonth->visitors / (time() - mktime(0, 0, 0, date('m'), date('1'), date('Y'))) * (86400 * date('t')));
    if ($qry_lmonth->visitors != 0) {
        $pt = round(100 * ($tmonthtarget / $qry_lmonth->visitors) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $tmonthadded = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $tmonthtarget . $tmonthadded . "</td>\n";
    //YESTERDAY
    $qry_y = $wpdb->get_row("SELECT count(DISTINCT ip) AS visitors\n                                   FROM {$table_name}\n                                   WHERE feed='' AND spider=''  AND ip IS NOT NULL AND date = '" . mysql_real_escape_string($yesterday) . "'");
    print "<td>" . $qry_y->visitors . "</td>\n";
    //TODAY
    $qry_t = $wpdb->get_row("SELECT count(DISTINCT ip) AS visitors\n                                   FROM {$table_name}\n                                   WHERE feed='' AND spider=''  AND ip IS NOT NULL AND date = '" . mysql_real_escape_string($today) . "'");
    print "<td>" . $qry_t->visitors . "</td>\n";
    print "</tr>";
    //###############################################################################################
    // PAGEVIEWS ROW
    print "<tr><td><div style='background:{$web_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Pageviews', 'statpress') . "</td>";
    //TOTAL
    $qry_total = $wpdb->get_row("SELECT count(ip) as pageview\n                                       FROM {$table_name}\n                                       WHERE feed='' AND spider='' AND ip IS NOT NULL ");
    print "<td>" . $qry_total->pageview . "</td>\n";
    //LAST MONTH
    $prec = 0;
    $qry_lmonth = $wpdb->get_row("SELECT count(ip) as pageview\n                                        FROM {$table_name}\n                                        WHERE feed='' AND spider='' AND ip IS NOT NULL AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'");
    print "<td>" . $qry_lmonth->pageview . "</td>\n";
    //THIS MONTH
    $qry_tmonth = $wpdb->get_row("SELECT count(ip) as pageview\n                                        FROM {$table_name}\n                                        WHERE feed='' AND spider='' AND ip IS NOT NULL AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'");
    if ($qry_lmonth->pageview != 0) {
        $pc = round(100 * ($qry_tmonth->pageview / $qry_lmonth->pageview) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->pageview . $qry_tmonth->change . "</td>\n";
    //TARGET
    $qry_tmonth->target = round($qry_tmonth->pageview / (time() - mktime(0, 0, 0, date('m'), date('1'), date('Y'))) * (86400 * date('t')));
    if ($qry_lmonth->pageview != 0) {
        $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->pageview) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
    //YESTERDAY
    $qry_y = $wpdb->get_row("SELECT count(ip) as pageview\n                                   FROM {$table_name}\n                                   WHERE feed='' AND spider='' AND ip IS NOT NULL AND date = '" . mysql_real_escape_string($yesterday) . "'");
    print "<td>" . $qry_y->pageview . "</td>\n";
    //TODAY
    $qry_t = $wpdb->get_row("SELECT count(ip) as pageview\n                                   FROM {$table_name}\n                                   WHERE feed='' AND spider='' AND ip IS NOT NULL AND date = '" . mysql_real_escape_string($today) . "'");
    print "<td>" . $qry_t->pageview . "</td>\n";
    print "</tr>";
    //###############################################################################################
    // SPIDERS ROW
    print "<tr><td><div style='background:{$spider_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Spiders', 'statpress') . "</td>";
    //TOTAL
    $qry_total = $wpdb->get_row("SELECT count(ip) as spiders\n                                       FROM {$table_name}\n                                       WHERE feed='' AND spider<>'' AND ip IS NOT NULL ");
    print "<td>" . $qry_total->spiders . "</td>\n";
    //LAST MONTH
    $prec = 0;
    $qry_lmonth = $wpdb->get_row("SELECT count(ip) as spiders\n                                        FROM {$table_name}\n                                        WHERE feed='' AND spider<>'' AND ip IS NOT NULL AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'");
    print "<td>" . $qry_lmonth->spiders . "</td>\n";
    //THIS MONTH
    $prec = $qry_lmonth->spiders;
    $qry_tmonth = $wpdb->get_row("SELECT count(ip) as spiders\n                                        FROM {$table_name}\n                                        WHERE feed='' AND spider<>'' AND ip IS NOT NULL AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'");
    if ($qry_lmonth->spiders != 0) {
        $pc = round(100 * ($qry_tmonth->spiders / $qry_lmonth->spiders) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->spiders . $qry_tmonth->change . "</td>\n";
    //TARGET
    $qry_tmonth->target = round($qry_tmonth->spiders / (time() - mktime(0, 0, 0, date('m'), date('1'), date('Y'))) * (86400 * date('t')));
    if ($qry_lmonth->spiders != 0) {
        $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->spiders) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
    //YESTERDAY
    $qry_y = $wpdb->get_row("SELECT count(ip) as spiders\n                                   FROM {$table_name}\n                                   WHERE feed='' AND spider<>''  AND ip IS NOT NULL AND date = '" . mysql_real_escape_string($yesterday) . "'");
    print "<td>" . $qry_y->spiders . "</td>\n";
    //TODAY
    $qry_t = $wpdb->get_row("SELECT count(ip) as spiders\n                                   FROM {$table_name}\n                                   WHERE feed='' AND spider<>''  AND ip IS NOT NULL AND date = '" . mysql_real_escape_string($today) . "'");
    print "<td>" . $qry_t->spiders . "</td>\n";
    print "</tr>";
    //###############################################################################################
    // FEEDS ROW
    print "<tr><td><div style='background:{$rss_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Feeds', 'statpress') . "</td>";
    //TOTAL
    $qry_total = $wpdb->get_row("SELECT count(ip) as feeds\n                                       FROM {$table_name}\n                                       WHERE feed<>'' AND spider='' AND ip IS NOT NULL ");
    print "<td>" . $qry_total->feeds . "</td>\n";
    //LAST MONTH
    $qry_lmonth = $wpdb->get_row("SELECT count(ip) as feeds\n                                        FROM {$table_name}\n                                        WHERE feed<>'' AND spider=''  AND ip IS NOT NULL AND date LIKE '" . mysql_real_escape_string($lastmonth) . "%'");
    print "<td>" . $qry_lmonth->feeds . "</td>\n";
    //THIS MONTH
    $qry_tmonth = $wpdb->get_row("SELECT count(ip) as feeds\n                                        FROM {$table_name}\n                                        WHERE feed<>'' AND spider=''  AND ip IS NOT NULL AND date LIKE '" . mysql_real_escape_string($thismonth) . "%'");
    if ($qry_lmonth->feeds != 0) {
        $pc = round(100 * ($qry_tmonth->feeds / $qry_lmonth->feeds) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->feeds . $qry_tmonth->change . "</td>\n";
    //TARGET
    $qry_tmonth->target = round($qry_tmonth->feeds / (time() - mktime(0, 0, 0, date('m'), date('1'), date('Y'))) * (86400 * date('t')));
    if ($qry_lmonth->feeds != 0) {
        $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->feeds) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
    $qry_y = $wpdb->get_row("SELECT count(ip) as feeds\n                                   FROM {$table_name}\n                                   WHERE feed<>'' AND spider=''  AND ip IS NOT NULL AND date = '" . mysql_real_escape_string($yesterday) . "'");
    print "<td>" . $qry_y->feeds . "</td>\n";
    $qry_t = $wpdb->get_row("SELECT count(ip) as feeds\n                                   FROM {$table_name}\n                                   WHERE feed<>'' AND spider=''  AND ip IS NOT NULL AND date = '" . mysql_real_escape_string($today) . "'");
    print "<td>" . $qry_t->feeds . "</td>\n";
    print "</tr></table><br />\n\n";
    //###############################################################################################
    //###############################################################################################
    // THE GRAPHS
    // last "N" days graph  NEW
    $graphdays = get_option('statpress_daysinoverviewgraph');
    if ($graphdays == 0) {
        $graphdays = 7;
    }
    if (isset($_GET['pp'])) {
        // Get Current page from URL
        $pagePeriode = $_GET['pp'];
        if ($pagePeriode <= 0) {
            // Page is less than 0 then set it to 1
            $pagePeriode = 1;
        }
    } else {
        // URL does not show the page set it to 1
        $pagePeriode = 1;
    }
    // selection of the older day with real visit
    $strqry = "SELECT date FROM {$table_name} WHERE (IP IS NOT NULL) GROUP BY date ORDER BY date ASC LIMIT 1";
    $query = $wpdb->get_row($strqry);
    $old_date = $query->date;
    if (isset($old_date)) {
        $nbjours = ceil((current_time('timestamp') - strtotime($old_date)) / 86400);
    } else {
        $nbjours = 0;
    }
    $NumberOfPagesPeriode = $nbjours / $graphdays;
    $LimitValue = $pagePeriode * $graphdays - $graphdays;
    $limitdate = gmdate('Ymd', current_time('timestamp') - 86400 * $graphdays * $pagePeriode + 86400);
    $currentdate = gmdate('Ymd', current_time('timestamp') - 86400 * $graphdays * ($pagePeriode - 1));
    $start_of_week = get_option('start_of_week');
    luc_Verify_continuity($graphdays, $pagePeriode, $limitdate, $currentdate);
    // Verify continuity of days in the database
    print "Period of days : ";
    luc_printperiodelink($NumberOfPagesPeriode, $pagePeriode, "overview");
    $qry = $wpdb->get_row("SELECT count(ip) AS pageview\n            FROM {$table_name}\n\t\t\tWHERE ip IS NOT NULL AND date BETWEEN {$limitdate} AND {$currentdate}\n            GROUP BY date \n            ORDER BY pageview DESC LIMIT 1 ");
    $maxxday = $qry->pageview;
    if ($maxxday == 0) {
        $maxxday = 1;
    }
    $day0visit = "SELECT 0 AS total, date\n\t                     FROM {$table_name} \n\t                     WHERE date BETWEEN {$limitdate} AND {$currentdate}";
    // set of all days with 0 visit
    //TOTAL VISITORS
    $qry_visitors = $wpdb->get_results(" SELECT total AS totalvisitors, date\n\t        FROM ((SELECT count(DISTINCT ip) AS total, date \n\t               FROM {$table_name} \n\t               WHERE feed='' AND spider='' AND date BETWEEN {$limitdate} AND {$currentdate}\n                   GROUP BY date )\n\t        UNION (" . $day0visit . ")\n\t\t\t\t  ) visitor \n\t        GROUP BY date ");
    // return 0 if 0 visit else real totalvisitors
    $i = 0;
    foreach ($qry_visitors as $qry) {
        $visitors[$i] = $qry->totalvisitors;
        $totalvisitors += $visitors[$i];
        $px_visitors[$i] = round($visitors[$i] * 100 / $maxxday);
        $px_white[$i] = 130 - $px_visitors[$i];
        $i++;
    }
    //TOTAL PAGEVIEWS (we do not delete the uniques, this is falsing the info.. uniques are not different visitors!)
    $qry_pageviews = $wpdb->get_results(" SELECT total AS totalpageviews, date\n\t        FROM ((SELECT count(ip) AS total, date \n\t               FROM {$table_name} \n\t               WHERE feed='' AND spider='' AND date BETWEEN {$limitdate} AND {$currentdate}\n                   GROUP BY date )\n\t        UNION (" . $day0visit . ")\n\t\t\t      ) pageviews\n\t        GROUP BY date ");
    $i = 0;
    foreach ($qry_pageviews as $qry) {
        $pageviews[$i] = $qry->totalpageviews;
        $totalpageviews += $pageviews[$i];
        $px_pageviews[$i] = round($pageviews[$i] * 100 / $maxxday);
        $px_white[$i] -= $px_pageviews[$i];
        $i++;
    }
    //TOTAL SPIDERS
    $qry_spiders = $wpdb->get_results(" SELECT total AS totalspiders, date\n\t        FROM ((SELECT count(ip) AS total, date \n\t               FROM {$table_name} \n\t               WHERE spider<>'' AND feed='' AND date BETWEEN {$limitdate} AND {$currentdate}\n                   GROUP BY date )\n\t        UNION (" . $day0visit . ")\n\t             ) spiders\n\t        GROUP BY date ");
    $i = 0;
    foreach ($qry_spiders as $qry) {
        $spiders[$i] = $qry->totalspiders;
        $totalspiders += $spiders[$i];
        $px_spiders[$i] = round($spiders[$i] * 100 / $maxxday);
        $px_white[$i] -= $px_spiders[$i];
        $i++;
    }
    //TOTAL FEEDS
    $qry_feeds = $wpdb->get_results(" SELECT total AS totalfeeds, date\n\t        FROM ((SELECT count(ip) AS total, date \n\t               FROM {$table_name} \n\t               WHERE feed<>'' AND spider='' AND date BETWEEN {$limitdate} AND {$currentdate}\n                   GROUP BY date )\n\t        UNION (" . $day0visit . ")\n\t              ) feeds\n\t        GROUP BY date ");
    $i = 0;
    foreach ($qry_feeds as $qry) {
        $feeds[$i] = $qry->totalfeeds;
        $totalfeeds += $feeds[$i];
        $px_feeds[$i] = round($feeds[$i] * 100 / $maxxday);
        $px_white[$i] -= $px_feeds[$i];
        $i++;
    }
    print '<table width="100%" border="0"><tr></tr></table>';
    print "Average : " . round($totalvisitors / $graphdays, 1) . " Visitors,";
    print "   " . round($totalpageviews / $graphdays, 1) . " Pageviews,";
    print "   " . round($totalspiders / $graphdays, 1) . " Spiders,";
    print "   " . round($totalfeeds / $graphdays, 1) . " Feeds  by day";
    print '<table width="100%" border="0"><tr>';
    // Y
    $gd = 90 / $graphdays . '%';
    for ($i = 0; $i < $graphdays; $i++) {
        print '<td width="' . $gd . '" valign="bottom"';
        if ($start_of_week == gmdate('w', current_time('timestamp') - 86400 * ($graphdays * $pagePeriode - $i - 1))) {
            // week-cut
            print ' style="border-left:2px dotted gray;"';
        }
        print "><div style='float:left;height: 100%;width:100%;font-family:Helvetica;font-size:7pt;text-align:center;border-right:1px solid white;color:black;'>\n                  <div style='background:#ffffff;width:100%;height:" . $px_white[$i] . "px;'></div>\n                  <div style='background:{$unique_color};width:100%;height:" . $px_visitors[$i] . "px;' title='" . $visitors[$i] . " " . __('visitors', 'statpress') . "'></div>\n                  <div style='background:{$web_color};width:100%;height:" . $px_pageviews[$i] . "px;' title='" . $pageviews[$i] . " " . __('pageviews', 'statpress') . "'></div>\n                  <div style='background:{$spider_color};width:100%;height:" . $px_spiders[$i] . "px;' title='" . $spiders[$i] . " " . __('spiders', 'statpress') . "'></div>\n                  <div style='background:{$rss_color};width:100%;height:" . $px_feeds[$i] . "px;' title='" . $feeds[$i] . " " . __('feeds', 'statpress') . "'></div>\n                  <div style='background:gray;width:100%;height:1px;'></div>\n                  <br />" . gmdate('d', current_time('timestamp') - 86400 * ($graphdays * $pagePeriode - $i - 1)) . ' ' . gmdate('M', current_time('timestamp') - 86400 * ($graphdays * $pagePeriode - $i - 1)) . "</div></td>\n";
    }
    print '</tr></table>';
    print '</div>';
    // END OF OVERVIEW
    //###################################################################################################
    $querylimit = "LIMIT 20";
    // Tabella Last hits
    print "<div class='wrap'><h2>" . __('Last hits', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('IP', 'statpress') . "</th><th scope='col'>" . __('Threat', 'statpress') . "</th><th scope='col'>" . __('Domain', 'statpress') . "</th><th scope='col'>" . __('Page', 'statpress') . "</th><th scope='col'>" . __('OS', 'statpress') . "</th><th scope='col'>" . __('Browser', 'statpress') . "</th><th scope='col'>" . __('Feed', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $fivesdrafts = $wpdb->get_results("SELECT * FROM {$table_name} WHERE (os<>'' OR feed<>'')  AND ip IS NOT NULL order by id DESC {$querylimit}");
    foreach ($fivesdrafts as $fivesdraft) {
        print "<tr>";
        print "<td>" . irihdate($fivesdraft->date) . "</td>";
        print "<td>" . $fivesdraft->time . "</td>";
        print "<td>" . $fivesdraft->ip . "</td>";
        print "<td>" . $fivesdraft->threat_score;
        if ($fivesdraft->threat_score > 0) {
            print "/";
            if ($fivesdraft->threat_type == 0) {
                print "Sp";
            } else {
                if (($fivesdraft->threat_type & 1) == 1) {
                    print "S";
                }
                // Suspicious
                if (($fivesdraft->threat_type & 2) == 2) {
                    print "H";
                }
                // Harvester
                if (($fivesdraft->threat_type & 4) == 4) {
                    print "C";
                }
                // Comment spammer
            }
        }
        print "<td>" . $fivesdraft->nation . "</td>";
        print "<td>" . iri_StatPress_Abbrevia(iri_StatPress_Decode($fivesdraft->urlrequested), 30) . "</td>";
        print "<td>" . $fivesdraft->os . "</td>";
        print "<td>" . $fivesdraft->browser . "</td>";
        print "<td>" . $fivesdraft->feed . "</td>";
        print "</tr>";
    }
    print "</table></div>";
    // Last Search terms
    print "<div class='wrap'><h2>" . __('Last search terms', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('Terms', 'statpress') . "</th><th scope='col'>" . __('Engine', 'statpress') . "</th><th scope='col'>" . __('Result', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,referrer,urlrequested,search,searchengine FROM {$table_name} WHERE search<>''  AND ip IS NOT NULL ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td><a href='" . $rk->referrer . "'>" . urldecode($rk->search) . "</a></td><td>" . $rk->searchengine . "</td><td><a href='" . irigetblogurl() . (strpos($rk->urlrequested, 'index.php') === FALSE ? $rk->urlrequested : '') . "'>" . __('page viewed', 'statpress') . "</a></td></tr>\n";
    }
    print "</table></div>";
    // Referrer
    print "<div class='wrap'><h2>" . __('Last referrers', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('URL', 'statpress') . "</th><th scope='col'>" . __('Result', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,referrer,urlrequested FROM {$table_name} WHERE ((referrer NOT LIKE '" . get_option('home') . "%') AND (referrer <>'') AND (searchengine='') AND ip IS NOT NULL ) ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td><a href='" . $rk->referrer . "'>" . iri_StatPress_Abbrevia($rk->referrer, 80) . "</a></td><td><a href='" . irigetblogurl() . (strpos($rk->urlrequested, 'index.php') === FALSE ? $rk->urlrequested : '') . "'>" . __('page viewed', 'statpress') . "</a></td></tr>\n";
    }
    print "</table></div>";
    // Last pages
    print "<div class='wrap'><h2>" . __('Last pages', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('Page', 'statpress') . "</th><th scope='col'>" . __('What', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,urlrequested,os,browser,spider FROM {$table_name} WHERE spider='' AND feed='' AND ip IS NOT NULL ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td>" . iri_StatPress_Abbrevia(iri_StatPress_Decode($rk->urlrequested), 60) . "</td><td> " . $rk->os . " " . $rk->browser . " " . $rk->spider . "</td></tr>\n";
    }
    print "</table></div>";
    // Last Spiders
    print "<div class='wrap'><h2>" . __('Last spiders', 'statpress') . "</h2>";
    print "<table class='widefat'><thead><tr>";
    print "<th scope='col'>" . __('Date', 'statpress') . "</th>";
    print "<th scope='col'>" . __('Time', 'statpress') . "</th>";
    print "<th scope='col'>" . __('Spider', 'statpress') . "</th>";
    print "<th scope='col'>" . __('Page', 'statpress') . "</th>";
    print "<th scope='col'>" . __('Agent', 'statpress') . "</th>";
    print "</tr></thead><tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,agent,spider,urlrequested,agent FROM {$table_name} WHERE spider<>'' AND ip IS NOT NULL  ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td>";
        print "<td>" . $rk->time . "</td>";
        print "<td>" . $rk->spider . "</td>";
        print "<td>" . iri_StatPress_Abbrevia(iri_StatPress_Decode($rk->urlrequested), 30) . "</td>";
        print "<td> " . $rk->agent . "</td></tr>\n";
    }
    print "</table></div>";
    print "<br />";
    print "&nbsp;<i>" . __('StatPress table size', 'statpress') . ": <b>" . iritablesize($wpdb->prefix . "statpress") . "</b></i><br />";
    print "&nbsp;<i>" . __('StatPress current time', 'statpress') . ": <b>" . current_time('mysql') . "</b></i><br />";
    print "&nbsp;<i>" . __('RSS2 url', 'statpress') . ": <b>" . get_bloginfo('rss2_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('rss2_url')) . ")</b></i><br />";
    print "&nbsp;<i>" . __('ATOM url', 'statpress') . ": <b>" . get_bloginfo('atom_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('atom_url')) . ")</b></i><br />";
    print "&nbsp;<i>" . __('RSS url', 'statpress') . ": <b>" . get_bloginfo('rss_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('rss_url')) . ")</b></i><br />";
    print "&nbsp;<i>" . __('COMMENT RSS2 url', 'statpress') . ": <b>" . get_bloginfo('comments_rss2_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('comments_rss2_url')) . ")</b></i><br />";
    print "&nbsp;<i>" . __('COMMENT ATOM url', 'statpress') . ": <b>" . get_bloginfo('comments_atom_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('comments_atom_url')) . ")</b></i><br />";
}
function iriStatPressMain()
{
    global $wpdb;
    $table_name = $wpdb->prefix . "statpress";
    # Tabella OVERVIEW
    $unique_color = "#114477";
    $web_color = "#3377B6";
    $rss_color = "#f38f36";
    $spider_color = "#83b4d8";
    $lastmonth = iri_StatPress_lastmonth();
    $thismonth = gmdate('Ym', current_time('timestamp'));
    $yesterday = gmdate('Ymd', current_time('timestamp') - 86400);
    $today = gmdate('Ymd', current_time('timestamp'));
    $tlm[0] = substr($lastmonth, 0, 4);
    $tlm[1] = substr($lastmonth, 4, 2);
    print "<div class='wrap'><h2>" . __('Overview', 'statpress') . "</h2>";
    print "<table class='widefat'><thead><tr>\n\t<th scope='col'></th>\n\t<th scope='col'>" . __('Total', 'statpress') . "</th>\n\t<th scope='col'>" . __('Last month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', gmmktime(0, 0, 0, $tlm[1], 1, $tlm[0])) . "</font></th>\n\t<th scope='col'>" . __('This month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) . "</font></th>\n\t<th scope='col'>Target " . __('This month', 'statpress') . "<br /><font size=1>" . gmdate('M, Y', current_time('timestamp')) . "</font></th>\n\t<th scope='col'>" . __('Yesterday', 'statpress') . "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp') - 86400) . "</font></th>\n\t<th scope='col'>" . __('Today', 'statpress') . "<br /><font size=1>" . gmdate('d M, Y', current_time('timestamp')) . "</font></th>\n\t</tr></thead>\n\t<tbody id='the-list'>";
    ################################################################################################
    # VISITORS ROW
    print "<tr><td><div style='background:{$unique_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Visitors', 'statpress') . "</td>";
    #TOTAL
    $qry_total = $wpdb->get_row("\n\t\tSELECT count(DISTINCT ip) AS visitors\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider=''\n\t");
    print "<td>" . $qry_total->visitors . "</td>\n";
    #LAST MONTH
    $qry_lmonth = $wpdb->get_row("\n\t\tSELECT count(DISTINCT ip) AS visitors\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider=''\n\t\tAND date LIKE '" . $lastmonth . "%'\n\t");
    print "<td>" . $qry_lmonth->visitors . "</td>\n";
    #THIS MONTH
    $qry_tmonth = $wpdb->get_row("\n\t\tSELECT count(DISTINCT ip) AS visitors\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider=''\n\t\tAND date LIKE '" . $thismonth . "%'\n\t");
    if ($qry_lmonth->visitors != 0) {
        $pc = round(100 * ($qry_tmonth->visitors / $qry_lmonth->visitors) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->visitors . $qry_tmonth->change . "</td>\n";
    #TARGET
    $qry_tmonth->target = round($qry_tmonth->visitors / date("d", current_time('timestamp')) * 30);
    if ($qry_lmonth->visitors != 0) {
        $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->visitors) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
    #YESTERDAY
    $qry_y = $wpdb->get_row("\n\t\tSELECT count(DISTINCT ip) AS visitors\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider=''\n\t\tAND date = '{$yesterday}'\n\t");
    print "<td>" . $qry_y->visitors . "</td>\n";
    #TODAY
    $qry_t = $wpdb->get_row("\n\t\tSELECT count(DISTINCT ip) AS visitors\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider=''\n\t\tAND date = '{$today}'\n\t");
    print "<td>" . $qry_t->visitors . "</td>\n";
    print "</tr>";
    ################################################################################################
    # PAGEVIEWS ROW
    print "<tr><td><div style='background:{$web_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>" . __('Pageviews', 'statpress') . "</td>";
    #TOTAL
    $qry_total = $wpdb->get_row("\n\t\tSELECT count(date) as pageview\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider=''\n\t");
    print "<td>" . $qry_total->pageview . "</td>\n";
    #LAST MONTH
    $prec = 0;
    $qry_lmonth = $wpdb->get_row("\n\t\tSELECT count(date) as pageview\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider=''\n\t\tAND date LIKE '" . $lastmonth . "%'\n\t");
    print "<td>" . $qry_lmonth->pageview . "</td>\n";
    #THIS MONTH
    $qry_tmonth = $wpdb->get_row("\n\t\tSELECT count(date) as pageview\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider=''\n\t\tAND date LIKE '" . $thismonth . "%'\n\t");
    if ($qry_lmonth->pageview != 0) {
        $pc = round(100 * ($qry_tmonth->pageview / $qry_lmonth->pageview) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->pageview . $qry_tmonth->change . "</td>\n";
    #TARGET
    $qry_tmonth->target = round($qry_tmonth->pageview / date("d", current_time('timestamp')) * 30);
    if ($qry_lmonth->pageview != 0) {
        $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->pageview) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
    #YESTERDAY
    $qry_y = $wpdb->get_row("\n\t\tSELECT count(date) as pageview\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider=''\n\t\tAND date = '{$yesterday}'\n\t");
    print "<td>" . $qry_y->pageview . "</td>\n";
    #TODAY
    $qry_t = $wpdb->get_row("\n\t\tSELECT count(date) as pageview\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider=''\n\t\tAND date = '{$today}'\n\t");
    print "<td>" . $qry_t->pageview . "</td>\n";
    print "</tr>";
    ################################################################################################
    # SPIDERS ROW
    print "<tr><td><div style='background:{$spider_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>Spiders</td>";
    #TOTAL
    $qry_total = $wpdb->get_row("\n\t\tSELECT count(date) as spiders\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider<>''\n\t");
    print "<td>" . $qry_total->spiders . "</td>\n";
    #LAST MONTH
    $prec = 0;
    $qry_lmonth = $wpdb->get_row("\n\t\tSELECT count(date) as spiders\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider<>''\n\t\tAND date LIKE '" . $lastmonth . "%'\n\t");
    print "<td>" . $qry_lmonth->spiders . "</td>\n";
    #THIS MONTH
    $prec = $qry_lmonth->spiders;
    $qry_tmonth = $wpdb->get_row("\n\t\tSELECT count(date) as spiders\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider<>''\n\t\tAND date LIKE '" . $thismonth . "%'\n\t");
    if ($qry_lmonth->spiders != 0) {
        $pc = round(100 * ($qry_tmonth->spiders / $qry_lmonth->spiders) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->spiders . $qry_tmonth->change . "</td>\n";
    #TARGET
    $qry_tmonth->target = round($qry_tmonth->spiders / date("d", current_time('timestamp')) * 30);
    if ($qry_lmonth->spiders != 0) {
        $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->spiders) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
    #YESTERDAY
    $qry_y = $wpdb->get_row("\n\t\tSELECT count(date) as spiders\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider<>''\n\t\tAND date = '{$yesterday}'\n\t");
    print "<td>" . $qry_y->spiders . "</td>\n";
    #TODAY
    $qry_t = $wpdb->get_row("\n\t\tSELECT count(date) as spiders\n\t\tFROM {$table_name}\n\t\tWHERE feed=''\n\t\tAND spider<>''\n\t\tAND date = '{$today}'\n\t");
    print "<td>" . $qry_t->spiders . "</td>\n";
    print "</tr>";
    ################################################################################################
    # FEEDS ROW
    print "<tr><td><div style='background:{$rss_color};width:10px;height:10px;float:left;margin-top:4px;margin-right:5px;'></div>Feeds</td>";
    #TOTAL
    $qry_total = $wpdb->get_row("\n\t\tSELECT count(date) as feeds\n\t\tFROM {$table_name}\n\t\tWHERE feed<>''\n\t\tAND spider=''\n\t");
    print "<td>" . $qry_total->feeds . "</td>\n";
    #LAST MONTH
    $qry_lmonth = $wpdb->get_row("\n\t\tSELECT count(date) as feeds\n\t\tFROM {$table_name}\n\t\tWHERE feed<>''\n\t\tAND spider=''\n\t\tAND date LIKE '" . $lastmonth . "%'\n\t");
    print "<td>" . $qry_lmonth->feeds . "</td>\n";
    #THIS MONTH
    $qry_tmonth = $wpdb->get_row("\n\t\tSELECT count(date) as feeds\n\t\tFROM {$table_name}\n\t\tWHERE feed<>''\n\t\tAND spider=''\n\t\tAND date LIKE '" . $thismonth . "%'\n\t");
    if ($qry_lmonth->feeds != 0) {
        $pc = round(100 * ($qry_tmonth->feeds / $qry_lmonth->feeds) - 100, 1);
        if ($pc >= 0) {
            $pc = "+" . $pc;
        }
        $qry_tmonth->change = "<code> (" . $pc . "%)</code>";
    }
    print "<td>" . $qry_tmonth->feeds . $qry_tmonth->change . "</td>\n";
    #TARGET
    $qry_tmonth->target = round($qry_tmonth->feeds / date("d", current_time('timestamp')) * 30);
    if ($qry_lmonth->feeds != 0) {
        $pt = round(100 * ($qry_tmonth->target / $qry_lmonth->feeds) - 100, 1);
        if ($pt >= 0) {
            $pt = "+" . $pt;
        }
        $qry_tmonth->added = "<code> (" . $pt . "%)</code>";
    }
    print "<td>" . $qry_tmonth->target . $qry_tmonth->added . "</td>\n";
    $qry_y = $wpdb->get_row("\n\t\tSELECT count(date) as feeds\n\t\tFROM {$table_name}\n\t\tWHERE feed<>''\n\t\tAND spider=''\n\t\tAND date = '" . $yesterday . "'\n\t");
    print "<td>" . $qry_y->feeds . "</td>\n";
    $qry_t = $wpdb->get_row("\n\t\tSELECT count(date) as feeds\n\t\tFROM {$table_name}\n\t\tWHERE feed<>''\n\t\tAND spider=''\n\t\tAND date = '{$today}'\n\t");
    print "<td>" . $qry_t->feeds . "</td>\n";
    print "</tr></table><br />\n\n";
    ################################################################################################
    ################################################################################################
    # THE GRAPHS
    # last "N" days graph  NEW
    $gdays = get_option('statpress_daysinoverviewgraph');
    if ($gdays == 0) {
        $gdays = 20;
    }
    //	$start_of_week = get_settings('start_of_week');
    $start_of_week = get_option('start_of_week');
    print '<table width="100%" border="0"><tr>';
    $qry = $wpdb->get_row("\n\t\tSELECT count(date) as pageview, date\n\t\tFROM {$table_name}\n\t\tGROUP BY date HAVING date >= '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gdays) . "'\n\t\tORDER BY pageview DESC\n\t\tLIMIT 1\n\t");
    $maxxday = $qry->pageview;
    if ($maxxday == 0) {
        $maxxday = 1;
    }
    # Y
    $gd = 90 / $gdays . '%';
    for ($gg = $gdays - 1; $gg >= 0; $gg--) {
        #TOTAL VISITORS
        $qry_visitors = $wpdb->get_row("\n\t\t\tSELECT count(DISTINCT ip) AS total\n\t\t\tFROM {$table_name}\n\t\t\tWHERE feed=''\n\t\t\tAND spider=''\n\t\t\tAND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'\n\t\t");
        $px_visitors = round($qry_visitors->total * 100 / $maxxday);
        #TOTAL PAGEVIEWS (we do not delete the uniques, this is falsing the info.. uniques are not different visitors!)
        $qry_pageviews = $wpdb->get_row("\n\t\t\tSELECT count(date) as total\n\t\t\tFROM {$table_name}\n\t\t\tWHERE feed=''\n\t\t\tAND spider=''\n\t\t\tAND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'\n\t\t");
        $px_pageviews = round($qry_pageviews->total * 100 / $maxxday);
        #TOTAL SPIDERS
        $qry_spiders = $wpdb->get_row("\n\t\t\tSELECT count(ip) AS total\n\t\t\tFROM {$table_name}\n\t\t\tWHERE feed=''\n\t\t\tAND spider<>''\n\t\t\tAND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'\n\t\t");
        $px_spiders = round($qry_spiders->total * 100 / $maxxday);
        #TOTAL FEEDS
        $qry_feeds = $wpdb->get_row("\n\t\t\tSELECT count(ip) AS total\n\t\t\tFROM {$table_name}\n\t\t\tWHERE feed<>''\n\t\t\tAND spider=''\n\t\t\tAND date = '" . gmdate('Ymd', current_time('timestamp') - 86400 * $gg) . "'\n\t\t");
        $px_feeds = round($qry_feeds->total * 100 / $maxxday);
        $px_white = 100 - $px_feeds - $px_spiders - $px_pageviews - $px_visitors;
        print '<td width="' . $gd . '" valign="bottom"';
        if ($start_of_week == gmdate('w', current_time('timestamp') - 86400 * $gg)) {
            print ' style="border-left:2px dotted gray;"';
        }
        # week-cut
        print "><div style='float:left;height: 100%;width:100%;font-family:Helvetica;font-size:7pt;text-align:center;border-right:1px solid white;color:black;'>\n\t\t<div style='background:#ffffff;width:100%;height:" . $px_white . "px;'></div>\n\t\t<div style='background:{$unique_color};width:100%;height:" . $px_visitors . "px;' title='" . $qry_visitors->total . " visitors'></div>\n\t\t<div style='background:{$web_color};width:100%;height:" . $px_pageviews . "px;' title='" . $qry_pageviews->total . " pageviews'></div>\n\t\t<div style='background:{$spider_color};width:100%;height:" . $px_spiders . "px;' title='" . $qry_spiders->total . " spiders'></div>\n\t\t<div style='background:{$rss_color};width:100%;height:" . $px_feeds . "px;' title='" . $qry_feeds->total . " feeds'></div>\n\t\t<div style='background:gray;width:100%;height:1px;'></div>\n\t\t<br />" . gmdate('d', current_time('timestamp') - 86400 * $gg) . ' ' . gmdate('M', current_time('timestamp') - 86400 * $gg) . "</div></td>\n";
    }
    print '</tr></table>';
    print '</div>';
    # END OF OVERVIEW
    ####################################################################################################
    $querylimit = "LIMIT 10";
    # Tabella Last hits
    print "<div class='wrap'><h2>" . __('Last hits', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>IP</th><th scope='col'>" . __('Domain', 'statpress') . "</th><th scope='col'>" . __('Page', 'statpress') . "</th><th scope='col'>OS</th><th scope='col'>Browser</th><th scope='col'>Feed</th></tr></thead>";
    print "<tbody id='the-list'>";
    $fivesdrafts = $wpdb->get_results("SELECT * FROM {$table_name} WHERE (os<>'' OR feed<>'') order by id DESC {$querylimit}");
    foreach ($fivesdrafts as $fivesdraft) {
        print "<tr>";
        print "<td>" . irihdate($fivesdraft->date) . "</td>";
        print "<td>" . $fivesdraft->time . "</td>";
        print "<td>" . $fivesdraft->ip . "</td>";
        print "<td>" . $fivesdraft->nation . "</td>";
        print "<td>" . iri_StatPress_Abbrevia(iri_StatPress_Decode($fivesdraft->urlrequested), 30) . "</td>";
        print "<td>" . $fivesdraft->os . "</td>";
        print "<td>" . $fivesdraft->browser . "</td>";
        print "<td>" . $fivesdraft->feed . "</td>";
        print "</tr>";
    }
    print "</table></div>";
    # Last Search terms
    print "<div class='wrap'><h2>" . __('Last search terms', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('Terms', 'statpress') . "</th><th scope='col'>" . __('Engine', 'statpress') . "</th><th scope='col'>" . __('Result', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,referrer,urlrequested,search,searchengine FROM {$table_name} WHERE search<>'' ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td><a href='" . $rk->referrer . "'>" . $rk->search . "</a></td><td>" . $rk->searchengine . "</td><td><a href='" . get_bloginfo('url') . "/?" . $rk->urlrequested . "'>" . __('page viewed', 'statpress') . "</a></td></tr>\n";
    }
    print "</table></div>";
    # Referrer
    print "<div class='wrap'><h2>" . __('Last referrers', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('URL', 'statpress') . "</th><th scope='col'>" . __('Result', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,referrer,urlrequested FROM {$table_name} WHERE ((referrer NOT LIKE '" . get_option('home') . "%') AND (referrer <>'') AND (searchengine='')) ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td><a href='" . $rk->referrer . "'>" . iri_StatPress_Abbrevia($rk->referrer, 80) . "</a></td><td><a href='" . get_bloginfo('url') . "/?" . $rk->urlrequested . "'>" . __('page viewed', 'statpress') . "</a></td></tr>\n";
    }
    print "</table></div>";
    # Last Agents
    print "<div class='wrap'><h2>" . __('Last agents', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('Agent', 'statpress') . "</th><th scope='col'>" . __('What', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,agent,os,browser,spider FROM {$table_name} WHERE (agent <>'') ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td>" . $rk->agent . "</td><td> " . $rk->os . " " . $rk->browser . " " . $rk->spider . "</td></tr>\n";
    }
    print "</table></div>";
    # Last pages
    print "<div class='wrap'><h2>" . __('Last pages', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('Page', 'statpress') . "</th><th scope='col'>" . __('What', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,urlrequested,os,browser,spider FROM {$table_name} WHERE (spider='' AND feed='') ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td>" . iri_StatPress_Abbrevia(iri_StatPress_Decode($rk->urlrequested), 60) . "</td><td> " . $rk->os . " " . $rk->browser . " " . $rk->spider . "</td></tr>\n";
    }
    print "</table></div>";
    # Last Spiders
    print "<div class='wrap'><h2>" . __('Last spiders', 'statpress') . "</h2><table class='widefat'><thead><tr><th scope='col'>" . __('Date', 'statpress') . "</th><th scope='col'>" . __('Time', 'statpress') . "</th><th scope='col'>" . __('Spider', 'statpress') . "</th><th scope='col'>" . __('Agent', 'statpress') . "</th></tr></thead>";
    print "<tbody id='the-list'>";
    $qry = $wpdb->get_results("SELECT date,time,agent,os,browser,spider FROM {$table_name} WHERE (spider<>'') ORDER BY id DESC {$querylimit}");
    foreach ($qry as $rk) {
        print "<tr><td>" . irihdate($rk->date) . "</td><td>" . $rk->time . "</td><td>" . $rk->spider . "</td><td> " . $rk->agent . "</td></tr>\n";
    }
    print "</table></div>";
    print "<br />";
    print "&nbsp;<i>StatPress table size: <b>" . iritablesize($wpdb->prefix . "statpress") . "</b></i><br />";
    print "&nbsp;<i>StatPress current time: <b>" . current_time('mysql') . "</b></i><br />";
    print "&nbsp;<i>RSS2 url: <b>" . get_bloginfo('rss2_url') . ' (' . iri_StatPress_extractfeedreq(get_bloginfo('rss2_url')) . ")</b></i><br />";
}