/
log.php
85 lines (73 loc) · 3.82 KB
/
log.php
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
80
81
82
83
84
85
<?php
#####################################################################################################
require_once("lib.php");
$trailing=$argv[1];
$dest=strtolower(trim($argv[2]));
$nick=strtolower(trim($argv[3]));
$timestamp=$argv[4];
define("IRC_LOG_PATH","/var/www/irciv.us.to/irc_logs/");
define("IRC_LOG_INDEX_FILE","/var/www/irciv.us.to/irc_logs/index.php");
define("IRC_LOG_INDEX_FILE_HTML","/var/www/irciv.us.to/irc_logs/index.html");
define("HTML_NO_CACHE","<meta http-equiv=\"cache-control\" content=\"max-age=0\">\n<meta http-equiv=\"cache-control\" content=\"no-cache\">\n<meta http-equiv=\"expires\" content=\"0\">\n<meta http-equiv=\"expires\" content=\"Tue, 01 Jan 1980 1:00:00 GMT\">\n<meta http-equiv=\"pragma\" content=\"no-cache\">\n");
define("IRC_INDEX_SOURCE","<?php include(\"".IRC_LOG_INDEX_FILE_HTML."\"); ?>");
define("IRC_INDEX_HTML_HEAD","<!DOCTYPE HTML>\n<html>\n<head>\n<title>SoylentNews IRC Log Index</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n".HTML_NO_CACHE."<style type=\"text/css\"></style>\n<script type=\"text/javascript\"></script>\n</head>\n<body>\n<p>\n");
define("IRC_CHAN_INDEX_HEAD","<!DOCTYPE HTML>\n<html>\n<head>\n<title>%%title%%</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n".HTML_NO_CACHE."<style type=\"text/css\"></style>\n<script type=\"text/javascript\"></script>\n</head>\n<body>\n<p><a href=\"index.html\">return to channel index</a></p>\n<p>\n");
define("IRC_LOG_HEAD","<!DOCTYPE HTML>\n<html>\n<head>\n<title>%%title%%</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n".HTML_NO_CACHE."<style type=\"text/css\"></style>\n<script type=\"text/javascript\"></script>\n</head>\n<body>\n<p><a href=\"%%index_href%%\">return to date index</a></p>\n<p>\n");
$trailing=$argv[1];
$dest=$argv[2];
$nick=$argv[3];
$timestamp=$argv[4];
#term_echo("*** $timestamp: $trailing ***");
if (($dest=="") or (substr($dest,0,1)<>"#") or (strpos($dest," ")!==False))
{
#term_echo("*** dest=$dest ***");
return;
}
if (file_exists(IRC_LOG_INDEX_FILE)==False)
{
file_put_contents(IRC_LOG_INDEX_FILE,IRC_INDEX_SOURCE);
}
if (file_exists(IRC_LOG_INDEX_FILE_HTML)==False)
{
file_put_contents(IRC_LOG_INDEX_FILE_HTML,IRC_INDEX_HTML_HEAD);
}
$contents=file_get_contents(IRC_LOG_INDEX_FILE_HTML);
$chan_enc=urlencode($dest);
if (strpos($contents,$dest)===False)
{
$line="<a href=\"index_$chan_enc.html\">$dest</a><br>\n";
file_put_contents(IRC_LOG_INDEX_FILE_HTML,$line,FILE_APPEND);
}
$t=microtime(True);
$ts=time();
$timestamp=date("H:i:s",$t);
$timestamp_name=date("His",microtime(True));
$filename=IRC_LOG_PATH.$dest."_".date("Ymd",$ts).".html";
$filename_href=urlencode($dest)."_".date("Ymd",$ts).".html";
$href_caption=date("Y-m-d",$ts);
$data="<$nick> ".htmlspecialchars($trailing);
#term_echo("*** data=$data ***");
$line="<a href=\"#$timestamp_name\" name=\"$timestamp_name\" class=\"time\">[$timestamp]</a> $data<br>\n";
if (file_exists($filename)==False)
{
$chan_index_filename=IRC_LOG_PATH."index_".$dest.".html";
if (file_exists($chan_index_filename)==False)
{
$head=IRC_CHAN_INDEX_HEAD;
$head=str_replace("%%title%%","$dest | SoylentNews IRC Log",$head);
file_put_contents($chan_index_filename,$head);
}
$contents=file_get_contents($chan_index_filename);
if (strpos($contents,$filename_href)===False)
{
$line_chan_index="<a href=\"$filename_href\">$href_caption</a><br>\n";
file_put_contents($chan_index_filename,$line_chan_index,FILE_APPEND);
}
$head=IRC_LOG_HEAD;
$head=str_replace("%%title%%","$dest | $href_caption",$head);
$head=str_replace("%%index_href%%","index_$chan_enc.html",$head);
file_put_contents($filename,$head);
}
file_put_contents($filename,$line,FILE_APPEND);
#####################################################################################################
?>