Пример #1
0
function module_top_visitors($arguments)
{
    global $gDb, $gData;
    global $lvc_nb_top_visitors;
    global $lvc_hide_IP;
    global $lvc_display_cache_delay;
    global $lvc_table_visitors;
    global $lvm_top_visitors, $lvm_host, $lvm_number;
    $is_archived = $arguments['archive'];
    if ($is_archived) {
        $values = explode("+", $gData['topVis']);
        $limit = sizeof($values) / 2;
        for ($cnt = 0; $cnt < $limit; $cnt++) {
            $row[$cnt]['host'] = $values[2 * $cnt];
            $row[$cnt]['nb'] = $values[2 * $cnt + 1];
        }
    } else {
        // to avoid 'table full' errors
        if (!$gDb->DbQuery('SET SQL_BIG_TABLES = 1')) {
            return '';
        }
        $month = $arguments['month'];
        $year = $arguments['year'];
        $query = "SELECT HOST, COUNT(*) AS C ";
        $query .= "FROM " . $lvc_table_visitors . " ";
        $query .= "WHERE DATE LIKE '" . $year . "/" . sprintf("%02d", $month) . "/%' ";
        $query .= "GROUP BY HOST ";
        $query .= "ORDER BY C DESC, HOST ";
        if ($gDb->DbQuery($query, 0, $lvc_nb_top_visitors) && $gDb->DbNumRows() != 0) {
            $cnt = 0;
            while ($gDb->DbNextRow()) {
                $visitor = $gDb->Row;
                $row[$cnt]['host'] = $visitor['HOST'];
                $row[$cnt]['nb'] = $visitor['C'];
                $cnt++;
            }
        } else {
            return '';
        }
    }
    $buffer = "<BR><CENTER><TABLE CELLSPACING=1 BORDER=0>\n";
    $buffer .= "<TR><TD COLSPAN=3><A CLASS='array'>";
    $buffer .= str_replace("{NB_TOP_VISITORS}", $lvc_nb_top_visitors, $lvm_top_visitors) . "</A></TD></TR>\n";
    $buffer .= "<TR>";
    $buffer .= "<TH CLASS='vis'>" . $lvm_host . "</TH>";
    $buffer .= "<TH CLASS='vis'>&nbsp;" . $lvm_number . "&nbsp;</TH></TR>\n";
    for ($cnt = 0; $cnt < $lvc_nb_top_visitors; $cnt++) {
        $buffer .= "<TR>";
        $buffer .= "<TD CLASS='vis'>&nbsp;<A CLASS='host'>" . ($lvc_hide_IP ? hide_machine($row[$cnt]['host']) : $row[$cnt]['host']) . "</A>&nbsp;</TD>";
        $buffer .= "<TD CLASS='vis' ALIGN='right'>&nbsp;" . ($row[$cnt]['nb'] != 0 ? number_format($row[$cnt]['nb'], 0, '', ' ') : '') . "&nbsp;</TD>";
        $buffer .= "</TR>\n";
    }
    // cache delay
    if ($lvc_display_cache_delay) {
        $buffer .= "<TR><TD ALIGN='center' COLSPAN='3'>";
        $buffer .= "<A CLASS='delay'>" . cache_delay($arguments['cache']) . "</A>";
    }
    $buffer .= "</TD></TR></TABLE></CENTER><BR>\n";
    return $buffer;
}
Пример #2
0
function module_top_agent_os($arguments)
{
    global $gDb, $gData;
    global $lvc_nb_top_agent_os;
    global $lvc_display_cache_delay;
    global $lvc_table_visitors;
    global $lvm_top_agent_os, $lvm_agent, $lvm_number;
    $is_archived = $arguments['archive'];
    if ($is_archived) {
        $values = explode("+", $gData['topNavOS']);
        $limit = sizeof($values) / 2;
        for ($cnt = 0; $cnt < $limit; $cnt++) {
            $row[$cnt]['agent'] = $values[2 * $cnt];
            $row[$cnt]['nb'] = $values[2 * $cnt + 1];
        }
    } else {
        $month = $arguments['month'];
        $year = $arguments['year'];
        $query = "SELECT AGENT, COUNT(*) AS C ";
        $query .= "FROM " . $lvc_table_visitors . " ";
        $query .= "WHERE AGENT <> '' AND DATE LIKE '" . $year . "/" . sprintf("%02d", $month) . "/%' ";
        $query .= "GROUP BY AGENT ";
        $query .= "ORDER BY C DESC, AGENT ";
        if ($gDb->DbQuery($query, 0, $lvc_nb_top_agent_os) && $gDb->DbNumRows() != 0) {
            $cnt = 0;
            while ($gDb->DbNextRow()) {
                $record = $gDb->Row;
                $row[$cnt]['agent'] = $record['AGENT'];
                $row[$cnt]['nb'] = $record['C'];
                $cnt++;
            }
        } else {
            return '';
        }
    }
    $buffer = "<BR><CENTER><TABLE CELLSPACING=1 BORDER=0>\n";
    $buffer .= "<TR><TD COLSPAN=2><A CLASS='array'>";
    $buffer .= str_replace("{NB_TOP_AGENT_OS}", $lvc_nb_top_agent_os, $lvm_top_agent_os) . "</A></TD></TR>\n";
    $buffer .= "<TR>";
    $buffer .= "<TH CLASS='vis'>" . $lvm_agent . "</TH>";
    $buffer .= "<TH CLASS='vis' nowrap>&nbsp;" . $lvm_number . "&nbsp;</TH></TR>\n";
    for ($cnt = 0; $cnt < $lvc_nb_top_agent_os; $cnt++) {
        $buffer .= "<TR>";
        $buffer .= "<TD CLASS='vis'>&nbsp;<A CLASS='item'>" . extract_agent($row[$cnt]['agent']) . "</A>&nbsp;</TD>";
        $buffer .= "<TD CLASS='vis' ALIGN='right' NOWRAP>&nbsp;" . ($row[$cnt]['nb'] != 0 ? number_format($row[$cnt]['nb'], 0, '', ' ') : '') . "&nbsp;</TD>";
        $buffer .= "</TR>\n";
    }
    // cache delay
    if ($lvc_display_cache_delay) {
        $buffer .= "<TR><TD ALIGN='center' COLSPAN='2'>";
        $buffer .= "<A CLASS='delay'>" . cache_delay($arguments['cache']) . "</A>";
    }
    $buffer .= "</TABLE></CENTER><BR>\n";
    return $buffer;
}
Пример #3
0
function module_top_referer($arguments)
{
    global $gDb, $gData;
    global $lvc_nb_top_referer;
    global $lvc_display_cache_delay;
    global $lvc_table_visitors;
    global $lvm_top_referer, $lvm_referer, $lvm_number;
    $is_archived = $arguments['archive'];
    if ($is_archived) {
        $values = explode("+", $gData['topRef']);
        $limit = sizeof($values) / 2;
        for ($cnt = 0; $cnt < $limit; $cnt++) {
            $row[$cnt]['referer'] = strip_tags($values[2 * $cnt]);
            $row[$cnt]['nb'] = $values[2 * $cnt + 1];
        }
    } else {
        $month = $arguments['month'];
        $year = $arguments['year'];
        $query = "SELECT REF_HOST, COUNT(*) AS C ";
        $query .= "FROM " . $lvc_table_visitors . " ";
        $query .= "WHERE REF_HOST <> '' AND REF_HOST <> '[unknown origin]' AND REF_HOST <> 'bookmarks' ";
        $query .= "AND DATE LIKE '" . $year . "/" . sprintf("%02d", $month) . "/%' ";
        $query .= "GROUP BY REF_HOST ";
        $query .= "ORDER BY C DESC, REF_HOST ";
        if ($gDb->DbQuery($query, 0, $lvc_nb_top_referer) && $gDb->DbNumRows() != 0) {
            $cnt = 0;
            while ($gDb->DbNextRow()) {
                $record = $gDb->Row;
                $row[$cnt]['referer'] = strip_tags($record['REF_HOST']);
                $row[$cnt]['nb'] = $record['C'];
                $cnt++;
            }
        }
    }
    $buffer = "<BR><CENTER><TABLE CELLSPACING=1 BORDER=0>\n";
    $buffer .= "<TR><TD COLSPAN=2><A CLASS='array'>";
    $buffer .= str_replace("{NB_TOP_REFERER}", $lvc_nb_top_referer, $lvm_top_referer) . "</A></TD></TR>\n";
    $buffer .= "<TR>";
    $buffer .= "<TH CLASS='vis'>" . $lvm_referer . "</TH>";
    $buffer .= "<TH CLASS='vis'>&nbsp;" . $lvm_number . "&nbsp;</TH></TR>\n";
    for ($cnt = 0; $cnt < $lvc_nb_top_referer; $cnt++) {
        $buffer .= "<TR>";
        $buffer .= "<TD CLASS='vis'>&nbsp;<A CLASS='host'>" . html_link($row[$cnt]['referer'], $row[$cnt]['referer'], '_blank') . "</A>&nbsp;</TD>";
        $buffer .= "<TD CLASS='vis' ALIGN='right'>&nbsp;" . ($row[$cnt]['nb'] != 0 ? number_format($row[$cnt]['nb'], 0, '', ' ') : '') . "&nbsp;</TD>";
        $buffer .= "</TR>\n";
    }
    // cache delay
    if ($lvc_display_cache_delay) {
        $buffer .= "<TR><TD ALIGN='center' COLSPAN='2'>";
        $buffer .= "<A CLASS='delay'>" . cache_delay($arguments['cache']) . "</A>";
    }
    $buffer .= "</TABLE></CENTER><BR>\n";
    return $buffer;
}
Пример #4
0
function module_daily_stats($arguments)
{
    global $gDb;
    global $lvc_display_cache_delay;
    global $lvc_table_visitors;
    global $lvm_daily_stats, $lvm_day_visitors, $lvm_day_direct, $lvm_day_referers;
    $date = !isset($arguments['date']) ? date('Y/m/d') : str_replace('-', '/', $arguments['date']);
    $buffer = "<BR><CENTER><TABLE CELLSPACING=1 BORDER=0>\n";
    $buffer .= "<TR><TD COLSPAN=3><A CLASS='array'>" . $lvm_daily_stats . "</A></TD></TR>\n";
    // count visitors
    $query = "SELECT COUNT(*) AS C ";
    $query .= "FROM " . $lvc_table_visitors . " ";
    $query .= "WHERE DATE LIKE '" . $date . "%'";
    if ($gDb->DbQuery($query) && $gDb->DbNumRows() != 0) {
        $gDb->Row = $gDb->DbNextRow();
        $data['visitors'] = $gDb->Row['C'];
        $buffer .= "<TR><TH CLASS='vis' ALIGN='left'>&nbsp;" . $lvm_day_visitors . "&nbsp;</TH>";
        $buffer .= "<TD CLASS='vis' ALIGN='right' COLSPAN=2>&nbsp;<B>" . number_format($data['visitors'], 0, ',', ' ') . "</B>&nbsp;</TD></TR>\n";
    } else {
        return '';
    }
    // count referers
    $query = "SELECT COUNT(*) AS C ";
    $query .= "FROM " . $lvc_table_visitors . " ";
    $query .= "WHERE DATE LIKE '" . $date . "%' ";
    $query .= "AND REF_HOST <> '' AND REF_HOST <> '[unknown origin]' AND REF_HOST <> 'bookmarks' ";
    if ($gDb->DbQuery($query) && $gDb->DbNumRows() != 0) {
        $gDb->Row = $gDb->DbNextRow();
        $data['referers'] = $gDb->Row['C'];
        $buffer .= "<TR><TH CLASS='vis' ALIGN='left'>&nbsp;" . $lvm_day_direct . "&nbsp;</TH>";
        $percent = $data['visitors'] == 0 ? 0 : round(($data['visitors'] - $data['referers']) / $data['visitors'] * 1000) / 10;
        $buffer .= "<TD CLASS='vis' ALIGN='right'>&nbsp;" . sprintf('%.1f', $percent) . " %&nbsp;</TD>\n";
        // %
        $buffer .= "<TD CLASS='vis' ALIGN='right'>&nbsp;<B>" . number_format($data['visitors'] - $data['referers'], 0, ',', ' ') . "</B>&nbsp;</TD></TR>\n";
        $buffer .= "<TR><TH CLASS='vis' ALIGN='left'>&nbsp;" . $lvm_day_referers . "&nbsp;</TH>";
        $percent = $data['visitors'] == 0 ? 0 : 100 - $percent;
        $buffer .= "<TD CLASS='vis' ALIGN='right'>&nbsp;" . sprintf('%.1f', $percent) . " %&nbsp;</TD>\n";
        // %
        $buffer .= "<TD CLASS='vis' ALIGN='right'>&nbsp;<B>" . number_format($data['referers'], 0, ',', ' ') . "</B>&nbsp;</TD></TR>\n";
    } else {
        return '';
    }
    // cache delay
    if ($lvc_display_cache_delay) {
        $buffer .= "<TR><TD ALIGN='center' COLSPAN='3'>";
        $buffer .= "<A CLASS='delay'>" . cache_delay($arguments['cache']) . "</A>";
    }
    $buffer .= "</TABLE></CENTER><BR>\n";
    return $buffer;
}
Пример #5
0
function module_top_day_referer($arguments)
{
    global $gDb, $gData;
    global $lvc_nb_top_referer;
    global $lvc_display_cache_delay;
    global $lvc_table_visitors;
    global $lvm_top_referer, $lvm_referer, $lvm_number, $lvm_today;
    $date = !isset($arguments['date']) ? date('Y/m/d') : str_replace('-', '/', $arguments['date']);
    $query = "SELECT REF_HOST, COUNT(*) AS C ";
    $query .= "FROM " . $lvc_table_visitors . " ";
    $query .= "WHERE REF_HOST <> '' AND REF_HOST <> '[unknown origin]' AND REF_HOST <> 'bookmarks' ";
    $query .= "AND DATE LIKE '" . $date . "%' ";
    $query .= "GROUP BY REF_HOST ";
    $query .= "ORDER BY C DESC, REF_HOST ";
    if ($gDb->DbQuery($query, 0, $lvc_nb_top_referer) && $gDb->DbNumRows() != 0) {
        $cnt = 0;
        while ($gDb->DbNextRow()) {
            $record = $gDb->Row;
            $row[$cnt]['referer'] = strip_tags($record['REF_HOST']);
            $row[$cnt]['nb'] = $record['C'];
            $cnt++;
        }
    }
    $buffer = "<BR><CENTER><TABLE CELLSPACING=1 BORDER=0>\n";
    $buffer .= "<TR><TD COLSPAN=2><A CLASS='array'>";
    $buffer .= str_replace("{NB_TOP_REFERER}", $lvc_nb_top_referer, $lvm_top_referer) . " - " . $lvm_today . "</A></TD></TR>\n";
    $buffer .= "<TR>";
    $buffer .= "<TH CLASS='vis'>" . $lvm_referer . "</TH>";
    $buffer .= "<TH CLASS='vis'>&nbsp;" . $lvm_number . "&nbsp;</TH></TR>\n";
    for ($cnt = 0; $cnt < $lvc_nb_top_referer; $cnt++) {
        $buffer .= "<TR>";
        $buffer .= "<TD CLASS='vis'>&nbsp;<A CLASS='host'>" . html_link($row[$cnt]['referer'], $row[$cnt]['referer'], '_blank') . "</A>&nbsp;</TD>";
        $buffer .= "<TD CLASS='vis' ALIGN='right'>&nbsp;" . ($row[$cnt]['nb'] != 0 ? number_format($row[$cnt]['nb'], 0, '', ' ') : '') . "&nbsp;</TD>";
        $buffer .= "</TR>\n";
    }
    // cache delay
    if ($lvc_display_cache_delay) {
        $buffer .= "<TR><TD ALIGN='center' COLSPAN='2'>";
        $buffer .= "<A CLASS='delay'>" . cache_delay($arguments['cache']) . "</A>";
    }
    $buffer .= "</TABLE></CENTER><BR>\n";
    return $buffer;
}
Пример #6
0
function module_img_year_per_day($arguments)
{
    global $lvc_cache_dir;
    global $lvc_images_format;
    global $lvc_pattern_per_day;
    global $lvc_base_img_year_per_day;
    global $lvc_img_site_name;
    global $lvc_site_opening_year;
    global $lvc_site_opening_month;
    global $lvc_table_visitors;
    global $lvc_display_cache_delay;
    global $lvc_color_bg_out;
    global $lvc_color_bg_in;
    global $lvc_color_value;
    global $lvc_color_bar_h;
    global $lvc_color_title;
    global $lvc_color_month_0;
    global $lvc_color_month_1;
    global $lvc_color_cache;
    global $lvm_img_arr_months_graph, $lvm_year_per_day;
    global $gDb;
    // --------------------------------------------------------------------------
    $width = 804;
    $height = 288;
    $file_name = $lvc_cache_dir . '/' . $arguments['module'] . '.' . $lvc_images_format;
    // --------------------------------------------------------------------------
    if (!$arguments['generate']) {
        return "WIDTH='" . $width . "' HEIGHT='" . $height . "'";
    }
    // cache delay
    $cache_delay = $arguments['cache'];
    if (is_image_expired($file_name, $cache_delay)) {
        // image creation
        $image = imagecreate($width, $height);
        $fct_imagecreatefrom = 'imagecreatefrom' . $lvc_images_format;
        $pattern = $fct_imagecreatefrom('images/' . $lvc_pattern_per_day . '.' . $lvc_images_format);
        // colors
        $color_white = imagecolorallocate($image, 0xff, 0xff, 0xff);
        $color_black = imagecolorallocate($image, 0x0, 0x0, 0x0);
        $color_value = create_new_color($image, $lvc_color_value);
        $color_bar_h = create_new_color($image, $lvc_color_bar_h);
        $color_bg_in = create_new_color($image, $lvc_color_bg_in);
        $color_bg_out = create_new_color($image, $lvc_color_bg_out);
        $color_title = create_new_color($image, $lvc_color_title);
        $color_cache = create_new_color($image, $lvc_color_cache);
        $color_month[0] = create_new_color($image, $lvc_color_month_0);
        $color_month[1] = create_new_color($image, $lvc_color_month_1);
        imagefill($image, 0, 0, $color_bg_out);
        imagerectangle($image, 0, 0, 803, 287, $color_white);
        imagerectangle($image, 30, 20, 773, 267, $color_black);
        imagefilledrectangle($image, 31, 21, 772, 266, $color_white);
        imagefilledrectangle($image, 34, 24, 769, 263, $color_bg_in);
        // title
        $title = $lvc_img_site_name . ' - ' . $lvm_year_per_day;
        $start = (int) (($width - imagefontwidth(3) * strlen($title)) / 2);
        if ($start < 0) {
            $start = 2;
        }
        imagestring($image, 3, $start, 5, $title, $color_title);
        // first month ?
        $current_year = date('Y');
        $current_month = date('n');
        $first_year = $current_year;
        $first_month = $current_month;
        for ($cnt_month = 1; $cnt_month < 12; $cnt_month++) {
            $first_month = $first_month == 1 ? 12 : $first_month - 1;
            $first_year = $first_month == 12 ? $first_year - 1 : $first_year;
        }
        $month = $first_month;
        $year = $first_year;
        $cnt_day = 0;
        $finished = false;
        $today = date('d/m/Y');
        for ($cnt = 0; $cnt < 12; $cnt++) {
            $arr_month[$cnt] = $month;
            $site_open = $year > $lvc_site_opening_year || $year == $lvc_site_opening_year && $month >= $lvc_site_opening_month;
            // retrieving archive if exists
            $data = archive_month($month, $year, 'vpj');
            if ($is_archived = $data[0] != NO_ARCHIVE) {
                $values = explode('+', $data[0]);
            }
            for ($day = 1; $day <= 31; $day++) {
                $val = 0;
                if (!$finished && $site_open) {
                    $the_day = sprintf('%02d/%02d/%4d', $day, $month, $year);
                    if (checkdate($month, $day, $year)) {
                        if ($is_archived) {
                            $val = $values[$day * 2 - 1];
                        } else {
                            $query = "SELECT COUNT(*) ";
                            $query .= "FROM " . $lvc_table_visitors . " ";
                            $query .= "WHERE DATE LIKE '" . $year . "/" . sprintf("%02d", $month) . "/" . sprintf("%02d", $day) . "%'";
                            $gDb->DbQuery($query);
                            $record = $gDb->DbNextRow();
                            $val = $record[0];
                        }
                    }
                    $finished = $the_day == $today;
                }
                $arr_values[$cnt_day] = $val;
                if ($cnt_day == 0) {
                    $max = $arr_values[0];
                    $min = $arr_values[0];
                }
                if ($val > $max) {
                    $max = $val;
                }
                if ($val != 0 && $val < $min) {
                    $min = $val;
                }
                $cnt_day++;
            }
            $month = $month == 12 ? 1 : $month + 1;
            $year = $month == 1 ? $year + 1 : $year;
        }
        // horizontal bars
        $level = $lvc_base_img_year_per_day;
        while ($max > 3.75 * $level) {
            $level += $lvc_base_img_year_per_day;
        }
        for ($cnt = 0; $cnt <= 4; $cnt++) {
            $start = (int) ((30 - imagefontwidth(1) * strlen($cnt * $level)) / 2);
            imagestring($image, 1, 2 + $start, $height - 28 - $cnt * 60, $cnt * $level, $color_white);
            $y = $cnt == 0 ? $height - 25 - $cnt * 60 : $height - 24 - $cnt * 60;
            imageline($image, 35, $y, $width - 35, $y, $color_bar_h);
        }
        // histograms
        $cnt_days = 0;
        $finished = false;
        $cnt_day = 0;
        $month = $first_month;
        $year = $first_year;
        for ($cnt = 0; $cnt < 12; $cnt++) {
            // month
            $start = (int) ((60 - imagefontwidth(1) * strlen($lvm_img_arr_months_graph[$arr_month[$cnt]])) / 2);
            imagestring($image, 1, 36 + $cnt_days * 2 + $start, $height - 18, $lvm_img_arr_months_graph[$arr_month[$cnt]], $color_white);
            for ($day = 1; $day <= 31; $day++) {
                if (checkdate($month, $day, $year)) {
                    $cnt_days++;
                }
                if (!$finished) {
                    $the_day = sprintf("%02d/%02d/%d", $day, $month, $year);
                    $finished = $the_day == $today;
                }
                if (($val = $arr_values[$cnt_day]) != 0) {
                    $y = $height - 24 - $val * 60 / $level;
                    imageline($image, 35 + $cnt_days * 2, $y, 35 + $cnt_days * 2, $height - 25, $color_month[$cnt % 2]);
                }
                $cnt_day++;
            }
            $month = $month == 12 ? 1 : $month + 1;
            $year = $month == 1 ? $year + 1 : $year;
        }
        // cache delay
        if ($lvc_display_cache_delay) {
            imagestringup($image, 2, $width - 29, $height - 22, cache_delay($cache_delay), $color_cache);
        }
        imageinterlace($image, false);
        // saving image
        $fct_image = 'image' . $lvc_images_format;
        $fct_image($image, $file_name);
        // sending image
        header('Content-type: image/' . $lvc_images_format);
        $fct_image($image);
    } else {
        // sending image
        header('Content-type: image/' . $lvc_images_format);
        echo fread(fopen($file_name, 'r'), filesize($file_name));
    }
}
Пример #7
0
function module_last_visitors($arguments)
{
    global $gDb;
    global $lvc_nb_last_visitors;
    global $lvc_hide_IP;
    global $lvc_table_visitors;
    global $lvc_display_cache_delay;
    global $lvm_last_visitors, $lvm_agent, $lvm_host, $lvm_time;
    $buffer .= "<BR><CENTER><TABLE CELLSPACING=1 BORDER=0>\n";
    $buffer .= "<TR><TD COLSPAN=2 ALIGN='left'>";
    $buffer .= "<A CLASS='array'>";
    $buffer .= str_replace("{NB_LAST_VISITORS}", $lvc_nb_last_visitors, $lvm_last_visitors) . "</A>&nbsp;";
    $buffer .= "</TD><TD COLSPAN=2 ALIGN='right'>&nbsp;";
    if ($lvc_display_cache_delay) {
        $buffer .= "<A CLASS='delay'>" . cache_delay($arguments['cache']) . "</A>";
    }
    $buffer .= "</TD></TR>\n";
    $buffer .= "<TR>";
    $buffer .= "<TH CLASS='vis'>" . $lvm_agent . "</TH>";
    $buffer .= "<TH CLASS='vis'>@ IP</TH>";
    $buffer .= "<TH CLASS='vis'>" . $lvm_host . "</TH>";
    $buffer .= "<TH CLASS='vis'>&nbsp;" . $lvm_time . "&nbsp;</TH>";
    $buffer .= "</TR>\n";
    $query = "SELECT AGENT, ADDR, HOST, DATE, REFERER, REF_HOST ";
    $query .= "FROM " . $lvc_table_visitors . " ";
    $query .= "ORDER BY DATE DESC, CODE DESC ";
    if ($gDb->DbQuery($query, 0, $lvc_nb_last_visitors) && $gDb->DbNumRows() != 0) {
        $cnt = 0;
        while ($gDb->DbNextRow()) {
            $record = $gDb->Row;
            $row[$cnt]['agent'] = $record['AGENT'];
            $row[$cnt]['addr'] = $record['ADDR'];
            $row[$cnt]['host'] = $record['HOST'];
            $row[$cnt]['date'] = $record['DATE'];
            $row[$cnt]['referer'] = $record['REFERER'];
            $row[$cnt]['ref_host'] = $record['REF_HOST'];
            $cnt++;
        }
    }
    // loading engines
    $arr_engines = load_engines();
    $prev_date = '';
    for ($cnt = 0; $cnt < $lvc_nb_last_visitors; $cnt++) {
        // separation between 2 days
        $date = substr($row[$cnt]['date'], 8, 2) . "/";
        $date .= substr($row[$cnt]['date'], 5, 2);
        if ($date != $prev_date && $prev_date != '') {
            $buffer .= "<TR><TH BGCOLOR='#FFFFAA' COLSPAN='4' HEIGHT='1' CLASS='vis'>";
            $buffer .= html_image("images/nothing.gif");
            $buffer .= "</TH></TR>\n";
        }
        $prev_date = $date;
        $buffer .= "<TR>";
        // agent
        $buffer .= "<TD CLASS='vis'>&nbsp;" . extract_agent($row[$cnt]['agent']) . "&nbsp;</TD>\n";
        // ip + host
        if ($row[$cnt]['host'] == $row[$cnt]['addr'] || $row[$cnt]['host'] == "") {
            // no hostname, only ip
            $buffer .= "<TD CLASS='vis'>&nbsp;";
            $buffer .= "<A CLASS='host'>" . ($lvc_hide_IP ? hide_machine($row[$cnt]['addr']) : $row[$cnt]['addr']) . "</A>";
            $buffer .= "&nbsp;</TD>";
            $buffer .= "<TD CLASS='vis'>&nbsp;</TD>";
        } else {
            // ip
            $buffer .= "<TD CLASS='vis'>&nbsp;<A CLASS='host'>" . ($lvc_hide_IP ? hide_machine($row[$cnt]['addr']) : $row[$cnt]['addr']) . "</A>&nbsp;</TD>";
            // server
            $buffer .= "<TD CLASS='vis'>&nbsp;[<A HREF='http://" . extract_server($row[$cnt]['host']) . "/' CLASS='server' TARGET='_blank'>Srv</A>]&nbsp;";
            // host
            $buffer .= "<A CLASS='host'>" . ($lvc_hide_IP ? hide_machine($row[$cnt]['host']) : $row[$cnt]['host']) . "</A>&nbsp;</TD>";
        }
        // datetime
        $buffer .= "<TD CLASS='vis'><CENTER>&nbsp;" . ($row[$cnt]['date'] != '' ? show_datetime($row[$cnt]['date']) : '') . "&nbsp;</CENTER></TD>";
        $buffer .= "</TR>\n";
        // referer
        if ($row[$cnt]['ref_host'] != '') {
            $buffer .= "<TR><TD COLSPAN='4' CLASS='visref'>";
            $buffer .= show_keywords($row[$cnt]['referer'], $row[$cnt]['ref_host'], $arr_engines);
            $buffer .= "</TD></TR>\n";
        }
    }
    $buffer .= "</TABLE></CENTER>\n";
    $buffer .= "<BR>";
    return $buffer;
}
Пример #8
0
function module_img_visitors_per_day($arguments)
{
    global $lvc_cache_dir;
    global $lvc_images_format;
    global $lvc_pattern_per_day;
    global $lvc_base_img_per_day;
    global $lvc_img_site_name;
    global $lvc_table_visitors;
    global $lvc_display_cache_delay;
    global $lvc_color_bg_out;
    global $lvc_color_bg_in;
    global $lvc_color_maxvalue;
    global $lvc_color_minvalue;
    global $lvc_color_value;
    global $lvc_color_bar_h;
    global $lvc_color_title;
    global $lvc_color_cache;
    global $lvm_img_arr_months_graph, $lvm_img_per_day;
    global $gDb, $gData;
    // --------------------------------------------------------------------------
    $width = 399;
    $height = 288;
    $month = $arguments['month'];
    $year = $arguments['year'];
    $file_name = $lvc_cache_dir . '/' . $arguments['module'] . '_year=' . $year . '_month=' . $month . '.' . $lvc_images_format;
    // --------------------------------------------------------------------------
    if (!$arguments['generate']) {
        return "WIDTH='" . $width . "' HEIGHT='" . $height . "'";
    }
    // cache delay
    $cache_delay = $arguments['cache'];
    if (is_image_expired($file_name, $cache_delay)) {
        // image creation
        $image = imagecreate($width, $height);
        $fct_imagecreatefrom = 'imagecreatefrom' . $lvc_images_format;
        $pattern = $fct_imagecreatefrom('images/' . $lvc_pattern_per_day . '.' . $lvc_images_format);
        // colors
        $color_white = imagecolorallocate($image, 0xff, 0xff, 0xff);
        $color_black = imagecolorallocate($image, 0x0, 0x0, 0x0);
        $color_maxvalue = create_new_color($image, $lvc_color_maxvalue);
        $color_minvalue = create_new_color($image, $lvc_color_minvalue);
        $color_value = create_new_color($image, $lvc_color_value);
        $color_bar_h = create_new_color($image, $lvc_color_bar_h);
        $color_bg_in = create_new_color($image, $lvc_color_bg_in);
        $color_bg_out = create_new_color($image, $lvc_color_bg_out);
        $color_title = create_new_color($image, $lvc_color_title);
        $color_cache = create_new_color($image, $lvc_color_cache);
        imagefill($image, 0, 0, $color_bg_out);
        imagerectangle($image, 0, 0, $width - 1, $height - 1, $color_white);
        imagefilledrectangle($image, 28, 21, 374, 267, $color_white);
        imagerectangle($image, 27, 20, 374, 267, $color_black);
        imagefilledrectangle($image, 31, 24, 370, 263, $color_bg_in);
        // title
        $title = $lvc_img_site_name . ' - ' . $lvm_img_per_day . ' - ' . $lvm_img_arr_months_graph[(int) $month] . ' ' . $year;
        $start = (int) (($width - imagefontwidth(3) * strlen($title)) / 2);
        if ($start < 0) {
            $start = 2;
        }
        imagestring($image, 3, $start, 5, $title, $color_title);
        // retrieving archive
        if ($is_archived = $arguments['archive']) {
            $values = explode('+', $gData['vpj']);
        }
        for ($cnt = 1; $cnt <= 31; $cnt++) {
            $hour = sprintf('%02d', $cnt);
            // 01 ... 31
            if (checkdate($month, $cnt, $year)) {
                $day = sprintf("%02d", $cnt);
                $the_day = date("D", mktime(12, 0, 0, $month, $cnt, $year));
                $color = $the_day == "Sat" || $the_day == "Sun" ? $color_title : $color_white;
                imagestring($image, 1, 20 + $cnt * 11, $height - 18, $day, $color);
                if ($is_archived) {
                    $val = $values[$cnt * 2 - 1];
                } else {
                    $query = "SELECT COUNT(*) ";
                    $query .= "FROM " . $lvc_table_visitors . " ";
                    $query .= "WHERE DATE LIKE '" . $year . "/" . $month . "/" . $day . " %'";
                    $gDb->DbQuery($query);
                    $record = $gDb->DbNextRow();
                    $val = $record[0];
                }
                $arr_values[$cnt] = $val;
                if ($cnt == 1) {
                    $max = $arr_values[1];
                    $min = $arr_values[1];
                }
                if ($val > $max) {
                    $max = $val;
                }
                if ($val != 0 && $val < $min) {
                    $min = $val;
                }
            }
        }
        // horizontal bars
        $level = $lvc_base_img_per_day;
        while ($max > 3.5 * $level) {
            $level += $lvc_base_img_per_day;
        }
        for ($cnt = 0; $cnt <= 4; $cnt++) {
            $start = (int) ((30 - imagefontwidth(1) * strlen($cnt * $level)) / 2);
            imagestring($image, 1, $start, $height - 28 - $cnt * 60, $cnt * $level, $color_white);
            $y = $cnt == 0 ? $height - 25 - $cnt * 60 : $height - 24 - $cnt * 60;
            imageline($image, 32, $y, $width - 30, $y, $color_bar_h);
        }
        // histograms
        for ($cnt = 1; $cnt <= 31; $cnt++) {
            if (($val = $arr_values[$cnt]) != 0) {
                // histograms
                $y = $height - 24 - $val * 60 / $level;
                imagecopyresized($image, $pattern, 21 + $cnt * 11, $y + 1, 0, 0, 8, $val * 60 / $level - 1, 8, 1);
                imagerectangle($image, 20 + $cnt * 11, $y, 29 + $cnt * 11, $height - 25, $color_black);
                // value
                $color = $val == $min ? $color_minvalue : $color_value;
                if ($val == $max) {
                    $color = $color_maxvalue;
                }
                imagestringup($image, 1, 21 + $cnt * 11, $y - 5, $val, $color);
            }
        }
        // cache delay
        if ($lvc_display_cache_delay) {
            imagestringup($image, 2, $width - 24, $height - 22, cache_delay($cache_delay), $color_cache);
        }
        imageinterlace($image, false);
        // saving image
        $fct_image = 'image' . $lvc_images_format;
        $fct_image($image, $file_name);
        // sending image
        header('Content-type: image/' . $lvc_images_format);
        $fct_image($image);
    } else {
        // sending image
        header('Content-type: image/' . $lvc_images_format);
        echo fread(fopen($file_name, 'r'), filesize($file_name));
    }
}
Пример #9
0
function module_calendar($arguments)
{
    global $gDb;
    global $lvc_nb_months_calendar;
    global $lvc_site_opening_year;
    global $lvc_site_opening_month;
    global $lvc_table_visitors;
    global $lvc_display_cache_delay;
    global $lvm_arr_months, $lvm_visitors_per_day, $lvm_month;
    global $lvm_average, $lvm_total;
    $buffer = '';
    $current_year = date('Y');
    $current_month = date('n');
    $today = date('Y/m/d');
    $first_year = $current_year;
    $first_month = $current_month;
    // looking for first month and first year in calendar
    for ($cnt_month = 1; $cnt_month < $lvc_nb_months_calendar && !($first_year == $lvc_site_opening_year && $first_month == $lvc_site_opening_month); $cnt_month++) {
        $first_month = $first_month == 1 ? 12 : $first_month - 1;
        $first_year = $first_month == 12 ? $first_year - 1 : $first_year;
    }
    $buffer .= "<BR><CENTER><TABLE CELLSPACING=1 BORDER=0>\n";
    $buffer .= "<TR><TD COLSPAN=17 ALIGN='left'><A CLASS='array'>";
    $buffer .= str_replace("{NB_LAST_MONTHS}", $cnt_month, $lvm_visitors_per_day) . "</A>&nbsp;";
    $buffer .= "</TD><TD COLSPAN=17 ALIGN='right'>&nbsp;";
    if ($lvc_display_cache_delay) {
        $buffer .= "<A CLASS='delay'>" . cache_delay($arguments['cache']) . "</A>";
    }
    $buffer .= "</TD></TR>\n";
    $buffer .= "<TR><TH CLASS='vis'>" . $lvm_month . "</TH>";
    for ($count = 1; $count <= 31; $count++) {
        $buffer .= "<TH CLASS='vis'>" . ($count < 10 ? "0" . $count : $count) . "</TH>";
    }
    $buffer .= "<TH CLASS='vis'>" . $lvm_average . "</TH>\n";
    $buffer .= "<TH CLASS='vis'>" . $lvm_total . "</TH></TR>\n";
    $Month = $first_month;
    $Year = $first_year;
    $finished = false;
    $prev_year = $Year;
    $big_cnt_values = 0;
    $big_total = 0;
    for ($count = 1; $count <= $cnt_month; $count++) {
        // separation between 2 years
        if ($Year != $prev_year) {
            $buffer .= "<TR><TH BGCOLOR='#FFFFAA' COLSPAN='34' HEIGHT='1'>";
            $buffer .= html_image("images/nothing.gif");
            $buffer .= "</TH></TR>\n";
        }
        // load month archive if exists
        $data = archive_month($Month, $Year, 'vpj');
        // vpj: visitor per day
        if ($archive = $data[0] != NO_ARCHIVE) {
            $values = explode('+', $data[0]);
        }
        $buffer .= "<TR>\n";
        $buffer .= "<TD CLASS='month'>&nbsp;<A CLASS='month' HREF='?view=" . VIEW_MONTH . "&year=" . $Year . "&month=" . sprintf('%02d', $Month) . "'>" . $lvm_arr_months[$Month] . "</A>&nbsp;</TD>";
        $the_month = sprintf('%02d', $Month);
        $total = 0;
        $cnt_values = 0;
        for ($count2 = 1; $count2 <= 31; $count2++) {
            if (checkdate($Month, $count2, $Year)) {
                $day = date('D', mktime(12, 0, 0, $Month, $count2, $Year));
                $color = $day == 'Sat' || $day == 'Sun' ? 'vis3' : 'vis1';
                $buffer .= "<TD CLASS='" . $color . "' ALIGN='center'>";
                $the_day = $Year . '/' . $the_month . '/' . ($count2 < 10 ? '0' . $count2 : $count2);
                if (!$finished) {
                    if ($archive) {
                        $val = $values[$count2 * 2 - 1];
                    } else {
                        $query = "SELECT COUNT(*) AS D FROM " . $lvc_table_visitors . " WHERE DATE LIKE '" . $the_day . "%'";
                        $gDb->DbQuery($query);
                        $gDb->DbNextRow();
                        $record = $gDb->Row;
                        $val = $record['D'];
                    }
                    if ($val > 0) {
                        $cnt_values++;
                    }
                    $buffer .= $val == 0 ? '&nbsp;' : $val;
                    $total += $val;
                } else {
                    $buffer .= '&nbsp;';
                }
                $finished = $finished || $the_day == $today;
                $buffer .= "</TD>";
            } else {
                $buffer .= "<TD CLASS='vis2' ALIGN='right'>&nbsp;</TD>";
            }
        }
        if ($cnt_values > 0) {
            $big_cnt_values += $cnt_values;
            $big_total += $total;
        }
        $buffer .= "<TD CLASS='avg' ALIGN='right' NOWRAP>&nbsp;" . ($cnt_values == 0 ? '' : number_format(round($total / $cnt_values), 0, '', ' ')) . "&nbsp;</TD>\n";
        $buffer .= "<TD CLASS='month' ALIGN='right' NOWRAP>&nbsp;" . ($total == 0 ? '' : number_format($total, 0, '', ' ')) . "&nbsp;</TD></TR>\n";
        $prev_year = $Year;
        $Month = $Month == 12 ? 1 : $Month + 1;
        $Year = $Month == 1 ? $Year + 1 : $Year;
    }
    $buffer .= "<TR><TH COLSPAN='32'>";
    $buffer .= html_image("images/nothing.gif");
    $buffer .= "</TH><TH BGCOLOR='#B8C8FE' COLSPAN='2' HEIGHT='1'>";
    $buffer .= html_image("images/nothing.gif");
    $buffer .= "</TH></TR>\n";
    $buffer .= "<TD COLSPAN='32'>&nbsp;</TD>";
    $buffer .= "<TD CLASS='avg' ALIGN='right' NOWRAP>&nbsp;" . ($big_cnt_values == 0 ? '' : number_format(round($big_total / $big_cnt_values), 0, '', ' ')) . "&nbsp;</TD>\n";
    $buffer .= "<TD CLASS='month' ALIGN='right' NOWRAP>&nbsp;" . ($big_total == 0 ? '' : number_format($big_total, 0, '', ' ')) . "&nbsp;</TD></TR>\n";
    $buffer .= "</TABLE></CENTER><BR>\n";
    return $buffer;
}
Пример #10
0
function module_img_last_months($arguments)
{
    global $lvc_cache_dir;
    global $lvc_images_format;
    global $lvc_img_site_name;
    global $lvc_site_opening_month;
    global $lvc_site_opening_year;
    global $lvc_base_img_last_months;
    global $lvc_pattern_last_months;
    global $lvc_table_visitors;
    global $lvc_display_cache_delay;
    global $lvc_color_bg_out;
    global $lvc_color_bg_in;
    global $lvc_color_maxvalue;
    global $lvc_color_minvalue;
    global $lvc_color_value;
    global $lvc_color_bar_h;
    global $lvc_color_title;
    global $lvc_color_cache;
    global $lvm_arr_months_abbr, $lvm_img_12_months;
    global $gDb;
    // --------------------------------------------------------------------------
    $width = 429;
    $height = 288;
    $file_name = $lvc_cache_dir . '/' . $arguments['module'] . '.' . $lvc_images_format;
    // --------------------------------------------------------------------------
    if ($arguments['generate'] == 0) {
        return 'WIDTH="' . $width . '" HEIGHT="' . $height . '"';
    }
    // cache delay
    $cache_delay = $arguments['cache'];
    if (is_image_expired($file_name, $cache_delay)) {
        // image creation
        $image = imagecreate($width, $height);
        // image for histograms
        $fct_imagecreatefrom = 'imagecreatefrom' . $lvc_images_format;
        $pattern = $fct_imagecreatefrom('images/' . $lvc_pattern_last_months . '.' . $lvc_images_format);
        // colors
        $color_white = imagecolorallocate($image, 0xff, 0xff, 0xff);
        $color_black = imagecolorallocate($image, 0x0, 0x0, 0x0);
        $color_maxvalue = create_new_color($image, $lvc_color_maxvalue);
        $color_minvalue = create_new_color($image, $lvc_color_minvalue);
        $color_value = create_new_color($image, $lvc_color_value);
        $color_bar_h = create_new_color($image, $lvc_color_bar_h);
        $color_bg_in = create_new_color($image, $lvc_color_bg_in);
        $color_bg_out = create_new_color($image, $lvc_color_bg_out);
        $color_title = create_new_color($image, $lvc_color_title);
        $color_cache = create_new_color($image, $lvc_color_cache);
        imagefill($image, 0, 0, $color_bg_out);
        imagerectangle($image, 0, 0, 428, 287, $color_white);
        imagerectangle($image, 30, 20, 398, 267, $color_black);
        imagefilledrectangle($image, 31, 21, 397, 266, $color_white);
        imagefilledrectangle($image, 34, 24, 394, 263, $color_bg_in);
        // title
        $title = $lvc_img_site_name . ' - ' . $lvm_img_12_months;
        $start = (int) (($width - imagefontwidth(3) * strlen($title)) / 2);
        if ($start < 0) {
            $start = 2;
        }
        imagestring($image, 3, $start, 5, $title, $color_title);
        // looking for 1st month
        $current_year = date('Y');
        $current_month = date('n');
        $first_year = $current_year;
        $first_month = $current_month;
        for ($cnt_month = 1; $cnt_month < 12; $cnt_month++) {
            $first_month = $first_month == 1 ? 12 : $first_month - 1;
            $first_year = $first_month == 12 ? $first_year - 1 : $first_year;
        }
        // looking for values
        $month = $first_month;
        $year = $first_year;
        for ($cnt_month = 0; $cnt_month < 12; $cnt_month++) {
            $arr_months[$cnt_month] = $month;
            $finished = $year < $lvc_site_opening_year || $year == $lvc_site_opening_year && $month < $lvc_site_opening_month;
            if ($finished) {
                $value = 0;
            } else {
                $data = archive_month($month, $year, 'vpm');
                if ($data[0] != NO_ARCHIVE) {
                    $value = $data[0];
                } else {
                    $query = "SELECT COUNT(*) ";
                    $query .= "FROM " . $lvc_table_visitors . " ";
                    $query .= "WHERE DATE LIKE '" . $year . "/" . sprintf("%02d", $month) . "/%'";
                    $gDb->DbQuery($query);
                    $record = $gDb->DbNextRow();
                    $value = $record[0];
                }
            }
            $arr_values[$cnt_month] = $value;
            if ($cnt_month == 0) {
                $max = $arr_values[0];
                $min = $arr_values[0];
            }
            if ($value > $max) {
                $max = $value;
            }
            if ($min == 0 || $value != 0 && $value < $min) {
                $min = $value;
            }
            $month = $month == 12 ? 1 : $month + 1;
            $year = $month == 1 ? $year + 1 : $year;
        }
        // horizontal bars
        $level = $lvc_base_img_last_months;
        while ($max > 3.75 * $level) {
            $level += $lvc_base_img_last_months;
        }
        for ($cnt = 0; $cnt <= 4; $cnt++) {
            $start = (int) ((30 - imagefontwidth(1) * strlen($cnt * $level)) / 2);
            imagestring($image, 1, 1 + $start, $height - 28 - $cnt * 60, $level * $cnt, $color_white);
            $y = $cnt == 0 ? $height - 25 - $cnt * 60 : $height - 24 - $cnt * 60;
            imageline($image, 35, $y, $width - 35, $y, $color_bar_h);
        }
        // histograms
        for ($cnt_month = 0; $cnt_month < 12; $cnt_month++) {
            // months names
            imagestring($image, 2, 42 + $cnt_month * 30, $height - 18, $lvm_arr_months_abbr[$arr_months[$cnt_month]], $color_white);
            $month = sprintf('%02d', $cnt_month + 1);
            if (($value = $arr_values[$cnt_month]) != 0) {
                // histograms
                $y = $height - 24 - $value * 60 / $level;
                imagecopyresized($image, $pattern, 38 + $cnt_month * 30, $y + 1, 0, 0, 24, $value * 60 / $level - 1, 24, 1);
                imagerectangle($image, 37 + $cnt_month * 30, $y, 62 + $cnt_month * 30, $height - 25, $color_black);
                // value
                $color = $value == $min ? $color_minvalue : $color_value;
                if ($value == $max) {
                    $color = $color_maxvalue;
                }
                $start = (int) ((26 - imagefontwidth(1) * strlen($value)) / 2);
                imagestring($image, 1, $start + 38 + $cnt_month * 30, $y - 10, $value, $color);
            }
        }
        // cache delay
        if ($lvc_display_cache_delay) {
            imagestringup($image, 2, $width - 30, $height - 22, cache_delay($cache_delay), $color_cache);
        }
        imageinterlace($image, false);
        // saving image
        $fct_image = 'image' . $lvc_images_format;
        $fct_image($image, $file_name);
        // sending image
        header('Content-type: image/' . $lvc_images_format);
        $fct_image($image);
    } else {
        // sending image
        header('Content-type: image/' . $lvc_images_format);
        echo fread(fopen($file_name, 'r'), filesize($file_name));
    }
}
Пример #11
0
function module_top_domain($arguments)
{
    global $gDb, $gData;
    global $lvc_display_cache_delay;
    global $lvc_nb_top_domain;
    global $lvc_table_visitors, $lvc_table_domains;
    global $lvm_top_domain, $lvm_number, $lvm_domain, $lvm_description;
    // loading domains descriptions
    $query = "SELECT domaine, description FROM " . $lvc_table_domains;
    if ($gDb->DbQuery($query) && $gDb->DbNumRows() != 0) {
        while ($gDb->DbNextRow()) {
            $record = $gDb->Row;
            $arr_domains[$record[0]] = array(0, $record[1]);
            // domain -> count, desc
        }
    }
    $is_archived = $arguments['archive'];
    if ($is_archived) {
        $values = explode("+", $gData['topDom']);
        $limit = sizeof($values) / 2;
        for ($cnt = 0; $cnt < $limit; $cnt++) {
            $arr_domains[$values[2 * $cnt]][0] += $values[2 * $cnt + 1];
        }
    } else {
        $month = $arguments['month'];
        $year = $arguments['year'];
        $query = "SELECT LCASE(SUBSTRING_INDEX(HOST, '.', -1)) AS D, COUNT(*) AS C ";
        $query .= "FROM " . $lvc_table_visitors . " ";
        $query .= "WHERE (HOST <> ADDR) AND DATE LIKE '" . $year . "/" . sprintf("%02d", $month) . "/%' ";
        $query .= "GROUP BY D ";
        $query .= "ORDER BY C DESC, D ";
        if ($gDb->DbQuery($query, 0, $lvc_nb_top_domain) && $gDb->DbNumRows() != 0) {
            while ($gDb->DbNextRow()) {
                $record = $gDb->Row;
                $arr_domains[$record['D']][0] = $record['C'];
            }
        }
    }
    $buffer = "<BR><CENTER><TABLE CELLSPACING=1 BORDER=0>\n";
    $buffer .= "<TR><TD COLSPAN=2><A CLASS='array'>" . str_replace('{NB_TOP_DOMAIN}', $lvc_nb_top_domain, $lvm_top_domain) . "</A></TD></TR>\n";
    $buffer .= "<TR>";
    $buffer .= "<TH CLASS='vis'>" . $lvm_domain . "</TH>";
    $buffer .= "<TH CLASS='vis'>" . $lvm_description . "</TH>";
    $buffer .= "<TH CLASS='vis'>&nbsp;" . $lvm_number . "&nbsp;</TH></TR>\n";
    if (sizeof($arr_domains) != 0) {
        for (reset($arr_domains); list($key, $value) = each($arr_domains);) {
            $list_domains[] = array($key, $value[0], $value[1]);
        }
        usort($list_domains, 'sort_domain');
        for ($cnt = 0; $cnt < $lvc_nb_top_domain; $cnt++) {
            $count = $list_domains[$cnt][1];
            $buffer .= "<TR>";
            $buffer .= "<TD CLASS='vis' ALIGN='left'>&nbsp;<A CLASS='item'>" . ($count ? $list_domains[$cnt][0] : '') . "</A>&nbsp;</TD>";
            $buffer .= "<TD CLASS='vis' ALIGN='left'>&nbsp;<A CLASS='item'>" . ($count ? $list_domains[$cnt][2] : '') . "</A>&nbsp;</TD>";
            $buffer .= "<TD CLASS='vis' ALIGN='right'>&nbsp;" . ($count != 0 ? number_format($count, 0, '', ' ') : '') . "&nbsp;</TD>";
            $buffer .= "</TR>\n";
        }
    }
    // cache delay
    if ($lvc_display_cache_delay) {
        $buffer .= "<TR><TD ALIGN='center' COLSPAN='3'>";
        $buffer .= "<A CLASS='delay'>" . cache_delay($arguments['cache']) . "</A>";
    }
    $buffer .= "</TABLE></CENTER><BR>\n";
    return $buffer;
}
Пример #12
0
function module_top_os($arguments)
{
    global $gDb, $gData;
    global $lvc_display_cache_delay;
    global $lvc_OS;
    global $lvc_table_visitors;
    global $lvm_top_os, $lvm_number, $lvm_os, $lvm_others_os;
    $is_archived = $arguments['archive'];
    if ($is_archived) {
        $big_total = 100;
        $values = explode("+", $gData['topOS']);
        $limit = sizeof($values) / 2;
        for ($cnt = 0; $cnt < $limit; $cnt++) {
            $cnt_OS[$values[2 * $cnt]] = $values[2 * $cnt + 1];
        }
    } else {
        $month = $arguments['month'];
        $year = $arguments['year'];
        // total
        $big_total = 0;
        $query = "SELECT COUNT(*) AS C ";
        $query .= "FROM " . $lvc_table_visitors . " ";
        $query .= "WHERE DATE LIKE '" . $year . "/" . sprintf("%02d", $month) . "/%' ";
        if ($gDb->DbQuery($query) && $gDb->DbNumRows() != 0) {
            $gDb->DbNextRow();
            $record = $gDb->Row;
            $big_total = $record['C'];
        } else {
            return '';
        }
        $total = 0;
        for (reset($lvc_OS); list($key, $value) = each($lvc_OS);) {
            $query = "SELECT COUNT(*) AS C ";
            $query .= "FROM " . $lvc_table_visitors . " ";
            $query .= "WHERE DATE LIKE '" . $year . "/" . sprintf("%02d", $month) . "/%' ";
            $query .= "AND AGENT LIKE'%" . $key . "%'";
            if ($gDb->DbQuery($query) && $gDb->DbNumRows() != 0) {
                $gDb->DbNextRow();
                $record = $gDb->Row;
                $cnt_OS[$value] = $record['C'];
                $total += $record['C'];
            }
        }
        // other OS
        $cnt_OS[$lvm_others_os] = $big_total - $total;
    }
    $buffer = "<BR><CENTER><TABLE CELLSPACING=1 BORDER=0>\n";
    $buffer .= "<TR><TD COLSPAN=2><A CLASS='array'>" . $lvm_top_os . "</A></TD></TR>\n";
    $buffer .= "<TR>";
    $buffer .= "<TH CLASS='vis'>" . $lvm_os . "</TH>";
    $buffer .= "<TH CLASS='vis'>&nbsp;" . $lvm_number . "&nbsp;</TH></TR>\n";
    if (sizeof($cnt_OS) != 0) {
        for (reset($cnt_OS); list($key, $value) = each($cnt_OS);) {
            $percent = $big_total == 0 ? 0 : round($value / $big_total * 1000) / 10;
            $list_OS[] = array($key, $percent);
        }
        usort($list_OS, 'sort_os');
        for ($cnt = 0; $cnt < sizeof($list_OS); $cnt++) {
            $buffer .= "<TR>";
            $buffer .= "<TD CLASS='vis'>&nbsp;<A CLASS='item'>" . $list_OS[$cnt][0] . "</A>&nbsp;</TD>";
            $buffer .= "<TD CLASS='vis' ALIGN='right'>&nbsp;" . sprintf('%.1f', $list_OS[$cnt][1]) . " %&nbsp;</TD>";
            $buffer .= "</TR>\n";
        }
    }
    // cache delay
    if ($lvc_display_cache_delay) {
        $buffer .= "<TR><TD ALIGN='center' COLSPAN='2'>";
        $buffer .= "<A CLASS='delay'>" . cache_delay($arguments['cache']) . "</A>";
    }
    $buffer .= "</TABLE></CENTER><BR>\n";
    return $buffer;
}
Пример #13
0
function insert_cached_module($module_desc)
{
    global $gloaded_modules;
    global $lvc_default_cache_delay;
    global $lvc_modules_dir;
    global $lvc_cache_dir;
    if (eregi('<[Mm][Oo][Dd]-([A-Za-z0-9_]*) ([^>]*)', $module_desc, $arr_elements)) {
        // module name
        $module_name = $arr_elements[1];
        // loading the module and its function
        if (!$gloaded_modules[$module_name]) {
            include $lvc_modules_dir . '/' . $module_name . '.module.php';
            $gloaded_modules[$module_name] = true;
        }
        // function to run
        $function_name = 'module_' . $module_name;
        // modules parameters
        $arr_parameters = explode(' ', strtolower($arr_elements[2]));
        // cache file name
        $cache_file_name = $lvc_cache_dir . '/' . $module_name;
        // looking for parameters and making cache file name
        for ($i = 0; $i < count($arr_parameters); $i++) {
            // parameter name
            if ($parameter_name = strtok($arr_parameters[$i], '=')) {
                $arr_arguments[$parameter_name] = strtok('=');
                // exclude 'cache' and 'archive' parameters in file_name
                if ($parameter_name != 'cache' && $parameter_name != 'archive') {
                    $cache_file_name .= '_' . $parameter_name . '=' . $arr_arguments[$parameter_name];
                }
            }
        }
        $cache_file_name .= '.cache.html';
        // cache delay
        $cache_delay = !isset($arr_arguments['cache']) ? $lvc_default_cache_delay : $arr_arguments['cache'];
        // read or write module ?
        if (file_exists($cache_file_name) && filesize($cache_file_name)) {
            $cache_exists = true;
            if ($cache_delay > 0 && filemtime($cache_file_name) + $cache_delay <= date('U')) {
                $write_cache = true;
                // cache is expired
                $read_cache = false;
            } else {
                $read_cache = true;
                // cache ok, read it
                $write_cache = false;
            }
        } else {
            $cache_exists = false;
            // no cache, create it
            $read_cache = false;
            $write_cache = true;
        }
        // module creation
        if ($write_cache && ($buffer = $function_name($arr_arguments)) != '') {
            $buffer = "\n\n<!-- [module: " . $module_name . "]---" . cache_delay($cache_delay) . " //-->\n\n" . $buffer;
            $buffer .= "\n\n<!-- [module: " . $module_name . "]---[end] //-->\n\n";
        } else {
            $buffer = '';
        }
        // read module
        if ($cache_exists && ($read_cache || $write_cache && $buffer == '')) {
            if ($f = fopen($cache_file_name, 'r')) {
                while ($data = fgets($f, 4096)) {
                    $buffer .= $data;
                }
                fclose($f);
            }
        }
        // file creation if needed
        if ($write_cache && $buffer != '') {
            if ($f = fopen($cache_file_name, 'w')) {
                fputs($f, $buffer);
                fclose($f);
            }
        }
        return $buffer;
    } else {
        return '';
    }
}
Пример #14
0
function module_month_calendar($arguments)
{
    global $gDb, $gData;
    global $lvc_table_visitors;
    global $lvc_display_cache_delay;
    global $lvm_arr_months, $lvm_visitors_day, $lvm_month;
    global $lvm_average, $lvm_total;
    $is_archived = $arguments['archive'];
    if ($is_archived) {
        $values = explode("+", $gData['vpj']);
    }
    $month = $arguments['month'];
    $year = $arguments['year'];
    $buffer = "<BR><CENTER><TABLE CELLSPACING=1 BORDER=0>\n";
    $buffer .= "<TR><TD COLSPAN=17 ALIGN='left'><A CLASS='array'>";
    $buffer .= str_replace("{NB_LAST_MONTHS}", 1, $lvm_visitors_day) . "</A>&nbsp;";
    $buffer .= "</TD><TD COLSPAN=17 ALIGN='right'>";
    if ($lvc_display_cache_delay) {
        $buffer .= "<A CLASS='delay'>" . cache_delay($arguments['cache']) . "</A>";
    }
    $buffer .= "</TD></TR>\n";
    $buffer .= "<TR><TH CLASS='vis'>" . $lvm_month . "</TH>";
    for ($count = 1; $count <= 31; $count++) {
        $buffer .= "<TH CLASS='vis'>" . ($count < 10 ? "0" . $count : $count) . "</TH>";
    }
    $buffer .= "<TH CLASS='vis'>" . $lvm_average . "</TH>\n";
    $buffer .= "<TH CLASS='vis'>" . $lvm_total . "</TH></TR>\n";
    $finished = false;
    $buffer .= "<TR>\n";
    $buffer .= "<TD CLASS='month'>&nbsp;" . $lvm_arr_months[(int) $month] . "&nbsp;</TD>";
    $the_month = sprintf('%02d', $month);
    $total = 0;
    $cnt_values = 0;
    for ($count = 1; $count <= 31; $count++) {
        if (checkdate($month, $count, $year)) {
            $day = date('D', mktime(12, 0, 0, $month, $count, $year));
            $color = $day == 'Sat' || $day == 'Sun' ? 'vis3' : 'vis1';
            $buffer .= "<TD CLASS='" . $color . "' ALIGN='center'>";
            $the_day = $year . '/' . $the_month . '/' . ($count < 10 ? '0' . $count : $count);
            if (!$finished) {
                if ($is_archived) {
                    $val = $values[$count * 2 - 1];
                } else {
                    $query = "SELECT COUNT(*) AS D FROM " . $lvc_table_visitors . " WHERE DATE LIKE '" . $the_day . "%'";
                    $gDb->DbQuery($query);
                    $gDb->DbNextRow();
                    $record = $gDb->Row;
                    $val = $record['D'];
                }
                if ($val != 0) {
                    $cnt_values++;
                }
                $buffer .= $val == 0 ? '&nbsp;' : $val;
                $total += $val;
            } else {
                $buffer .= '&nbsp;';
            }
            $finished = $finished || $the_day == $today;
            $buffer .= "</TD>";
        } else {
            $buffer .= "<TD CLASS='vis2' ALIGN='right'>&nbsp;</TD>";
        }
    }
    $buffer .= "<TD CLASS='avg' ALIGN='right' NOWRAP>&nbsp;" . ($cnt_values == 0 ? '' : number_format(round($total / $cnt_values), 0, '', ' ')) . "&nbsp;</TD>\n";
    $buffer .= "<TD CLASS='month' ALIGN='right' NOWRAP>&nbsp;" . ($total == 0 ? '' : number_format($total, 0, '', ' ')) . "&nbsp;</TD></TR>\n";
    $buffer .= "</TABLE></CENTER><BR>\n";
    return $buffer;
}
Пример #15
0
function module_img_day_per_hour($arguments)
{
    global $lvc_cache_dir;
    global $lvc_images_format;
    global $lvc_pattern_day_per_hour;
    global $lvc_base_img_day_per_hour;
    global $lvc_img_site_name;
    global $lvc_table_visitors;
    global $lvc_display_cache_delay;
    global $lvc_color_bg_out;
    global $lvc_color_bg_in;
    global $lvc_color_maxvalue;
    global $lvc_color_minvalue;
    global $lvc_color_value;
    global $lvc_color_bar_h;
    global $lvc_color_title;
    global $lvc_color_cache;
    global $lvm_img_today, $lvm_img_per_hour;
    global $gDb, $gData;
    // --------------------------------------------------------------------------
    $width = 538;
    $height = 288;
    $file_name = $lvc_cache_dir . '/' . $arguments['module'] . '.' . $lvc_images_format;
    // --------------------------------------------------------------------------
    if (!$arguments['generate']) {
        return "WIDTH='" . $width . "' HEIGHT='" . $height . "'";
    }
    // cache delay
    $cache_delay = $arguments['cache'];
    if (is_image_expired($file_name, $cache_delay)) {
        // image creation
        $image = imagecreate($width, $height);
        $fct_imagecreatefrom = 'imagecreatefrom' . $lvc_images_format;
        $pattern = $fct_imagecreatefrom('images/' . $lvc_pattern_day_per_hour . '.' . $lvc_images_format);
        // colors
        $color_white = imagecolorallocate($image, 0xff, 0xff, 0xff);
        $color_black = imagecolorallocate($image, 0x0, 0x0, 0x0);
        $color_maxvalue = create_new_color($image, $lvc_color_maxvalue);
        $color_minvalue = create_new_color($image, $lvc_color_minvalue);
        $color_value = create_new_color($image, $lvc_color_value);
        $color_bar_h = create_new_color($image, $lvc_color_bar_h);
        $color_bg_in = create_new_color($image, $lvc_color_bg_in);
        $color_bg_out = create_new_color($image, $lvc_color_bg_out);
        $color_title = create_new_color($image, $lvc_color_title);
        $color_cache = create_new_color($image, $lvc_color_cache);
        imagefill($image, 0, 0, $color_bg_out);
        imagerectangle($image, 0, 0, 537, 287, $color_white);
        imagerectangle($image, 25, 20, 511, 267, $color_black);
        imagefilledrectangle($image, 26, 21, 510, 266, $color_white);
        imagefilledrectangle($image, 29, 24, 507, 263, $color_bg_in);
        // title
        $title = $lvc_img_site_name . ' - ' . $lvm_img_per_hour . ' - ' . $lvm_img_today . ' ' . $year;
        $start = (int) (($width - imagefontwidth(3) * strlen($title)) / 2);
        if ($start < 0) {
            $start = 2;
        }
        imagestring($image, 3, $start, 5, $title, $color_title);
        // retrieving archive
        if ($is_archived = $arguments['archive']) {
            $values = explode('+', $gData['vph']);
        }
        for ($cnt = 0; $cnt <= 23; $cnt++) {
            $hour = sprintf('%02d', $cnt);
            // 00 ... 23
            imagestring($image, 1, 33 + $cnt * 20, $height - 18, $hour, $color_white);
            if ($is_archived) {
                $val = $values[$cnt * 2 + 1];
            } else {
                $query = "SELECT COUNT(*) ";
                $query .= "FROM " . $lvc_table_visitors . " ";
                $query .= "WHERE DATE LIKE '" . date('Y/m/d') . " " . $hour . ":__'";
                $gDb->DbQuery($query);
                $record = $gDb->DbNextRow();
                $val = $record[0];
            }
            $arr_values[$cnt] = $val;
            if ($cnt == 0) {
                $max = $arr_values[0];
                $min = $arr_values[0];
            }
            if ($val > $max) {
                $max = $val;
            }
            if ($val != 0 && $val < $min) {
                $min = $val;
            }
        }
        // horizontal bars
        $level = $lvc_base_img_day_per_hour;
        while ($max > 3.75 * $level) {
            $level += $lvc_base_img_day_per_hour;
        }
        for ($cnt = 0; $cnt <= 4; $cnt++) {
            $start = (int) ((28 - imagefontwidth(1) * strlen($cnt * $level)) / 2);
            imagestring($image, 1, $start, $height - 28 - $cnt * 60, $cnt * $level, $color_white);
            $y = $cnt == 0 ? $height - 25 - $cnt * 60 : $height - 24 - $cnt * 60;
            imageline($image, 29, $y, $width - 32, $y, $color_bar_h);
        }
        // histograms
        for ($cnt = 0; $cnt <= 23; $cnt++) {
            $hour = sprintf('%02d', $cnt);
            if (($val = $arr_values[$cnt]) != 0) {
                // histograms
                $y = $height - 24 - $val * 60 / $level;
                imagecopyresized($image, $pattern, 30 + $cnt * 20, $y + 1, 0, 0, 16, $val * 60 / $level - 1, 16, 1);
                imagerectangle($image, 29 + $cnt * 20, $y, 46 + $cnt * 20, $height - 25, $color_black);
                // value
                $color = $val == $min ? $color_minvalue : $color_value;
                if ($val == $max) {
                    $color = $color_maxvalue;
                }
                $start = (int) ((17 - imagefontwidth(1) * strlen($val)) / 2);
                imagestring($image, 1, $start + 29 + $cnt * 20, $y - 10, $val, $color);
            }
        }
        // cache delay
        if ($lvc_display_cache_delay) {
            imagestringup($image, 2, $width - 26, $height - 22, cache_delay($cache_delay), $color_cache);
        }
        imageinterlace($image, false);
        // saving image
        $fct_image = 'image' . $lvc_images_format;
        $fct_image($image, $file_name);
        // sending image
        header('Content-type: image/' . $lvc_images_format);
        $fct_image($image);
    } else {
        // sending image
        header('Content-type: image/' . $lvc_images_format);
        echo fread(fopen($file_name, 'r'), filesize($file_name));
    }
}