Some code for ya'all to learn from

Questions about programming languages and debugging
Post Reply
User avatar
Gogeta70
^_^
^_^
Posts: 3275
Joined: 25 Jun 2005, 16:00
18

Some code for ya'all to learn from

Post by Gogeta70 »

I created a new irc logging system for G7 today, figured i would share the majority of the code.

I of course, removed all the paths to certain files, etc. for obvious reasons.

Code: Select all

function irclog($usr, $buffer, $chan, $said, $nicks, $switch)
{ global $open, $filename, $hour;

$said = htmlentities($said);

if($switch == TRUE)
{
fclose($open);
} else {

$parts = explode(" ", $buffer);

if($hour != date("g")) // Every hour, create a new log file.
{
fclose($open);
unset($open);
$filename2 = explode(".html", $filename);
$filename2 = $filename2[0];
$filename2 .= " -TO- [" . date("g.i.a") . "] " . date("n-j-y") . ".html";
rename("PATH/$filename", "E:/irc/logs/$filename2"); // Rename the log file to indicate when logging was stopped in that file.
unset($filename2);
}

if(!isset($open)) // If no log file has been started, do the following.
{
$filename = "[" . date("g.i.a") . "] " . date("n-j-y") . ".html"; // Write a file name with a time and date.
$hour = date("g"); // Get the hour. We will use this to dictate when to change files.
$open = fopen("PATH/$filename", "w"); // Create a file stream
fwrite($open, "<ht ml><he ad><tit le>IRC Logs - " . date("g:i A - n/j/y") . "</ti tle></he ad><bo dy>"); // Write the header to the file.
}

if($parts[1] == "PRIVMSG") // If a regular message is sent to the channel, then...
{
$write = "[" . date("g:i a") ."]" . " <b><$usr></b> [$chan] " . $said . "<br/>\n";
fwrite($open, $write);
}

if($parts[1] == "JOIN") // If somebody joins, then...
{
$write = "[" . date("g:i a") ."]" . " <b><$usr></b> <font color=green>Has Joined.</font><br/>\n";
fwrite($open, $write);
}

if($parts[3] == ":". chr(1) . "ACTION") // If somebody /me's, then...
{
$said = str_replace(CHR(1), "", $said);
$said = str_replace("ACTION", $usr, $said);
$write = "[" . date("g:i a") ."]" . " <b><$usr></b> [$chan] <font color=purple>$said</font> <br/>\n";
fwrite($open, $write);
}

}

    return; // Return.

}
I know i still need to add a little, for when people quit, part, etc. But it works, right? Well, if you have any questions, feel free to ask.



Read. Learn. Code.
¯\_(ツ)_/¯ It works on my machine...

Post Reply