aboutsummaryrefslogtreecommitdiff
path: root/alpine/irc/log/ircdaily.php
blob: 3389e5f0c51069a1cd21891b5e1fc8c0a81bab3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
define('DS', DIRECTORY_SEPARATOR);
//date_default_timezone_set('Asia/Kolkata'); # Asia/Kolkata
date_default_timezone_set('UTC'); # set to server logs are fetched from

$ConfigAll['site']['domain'] = $domain = $_SERVER['HTTP_HOST'];
$ConfigAll['base']['install']['path'] = realpath($_SERVER['DOCUMENT_ROOT']);
$ConfigAll['base']['install']['url']['http'] = 'http://' . $domain;
$ConfigAll['base']['install']['url']['https'] = 'https://' . $domain;
$ConfigAll['base']['install']['url']['current'] = $ConfigAll['base']['install']['url']['http'];

$dirurl = dirname($_SERVER['SCRIPT_NAME']);
$ConfigAll['application']['install']['path'] = $ConfigAll['base']['install']['path'].$dirurl;
$ConfigAll['application']['script'] = $ConfigAll['base']['install']['url']['current'].$_SERVER['SCRIPT_NAME'];

$scriptname = basename($_SERVER['SCRIPT_NAME']);
$thisfile = $ConfigAll['application']['install']['path'].'/'.$scriptname;
if (! file_exists($thisfile)) { echo "$thisfile not found."; exit; }

$arr_logname = explode('.', $scriptname);
$logname = $arr_logname[0];

$YYMM = date('Y-m');
$date = 1;
if (! empty($_GET['dt'])) { $date = (int) $_GET['dt']; }
if ($date <= 1 || $date >= 32) $date = 1;
if ($date <= 9) $date = '0'.$date;
//print_r($logname); exit;

$file = 'alpine-'.$logname.'-'.$YYMM.'.log.html';
if(! file_exists($file)) { echo "$file not found."; exit; }
$fp = @fopen($file, "r");

$a = 0; $str_dts = '';
$sn = $ConfigAll['application']['script'];
while ($a <= 30) {
    $a++; if ($a <= 9) $a = '0'.$a;
    $href = "$sn?dt=$a";
    $cls = ($a === $date) ? 'active' : '';
    $str_dts = $str_dts. "<span class='date ".$cls."'><a href='".$href."'>$a</a></span>";
}

if ($fp) { # first 3 line, html header
    if (($buffer = fgets($fp, 4096)) !== false) { echo $buffer; }
    if (($buffer = fgets($fp, 4096)) !== false) { echo $buffer; }
    if (($buffer = fgets($fp, 4096)) !== false) { echo $buffer; }
}
?>
</head><body>
<style>
.dtwrap { width: 100%; padding: 4px; }
.date {line-height: 110%; float: left; padding: 1px 2px; border: 2px solid #333; color: blue;}
.date a { text-decoration: none; display: block; padding: 4px 8px; }
.date a:hover { background-color: #eee; }
span.active a { background-color: #999; }
.br { height:1px; clear:both; font-size:1px; }
</style>
<?php
  echo "<div class='dtwrap'>$str_dts</div>";
  echo '<hr class="br">';
?>
<div id="ircchat"><ul class="list">
<?php
$Pat1 = "^<li><span class=\"ts\">".$YYMM."-".$date;
if ($fp) {
    while (($buffer = fgets($fp, 4096)) !== false) {
        if (preg_match("/$Pat1/", $buffer)) {
            echo $buffer;
        }
    }
    if (!feof($fp)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($fp);
}
?>
</ul>
</div></body></html>