We are a few people on our IRC channel(s), talking and helping eachother about RC related stuff.
The problem with IRC or should I say people, is their ability to turn on everything out of their knowledge. IRC can be tricky at first, but it gives you a nice playroom.
To recruite people I had to find a simple way to connect people to IRC and join our channel. A quick google search found web-irc linking to antoher site running CGIIRC. It’s a client which runs on a webserver through your browser and can connect you directly to desired channel. When people get used and addicted to IRC, they will install a decent client locally.
My next step was to get people interested. A way of doing this is by giving them some of our conversations and not just a few, but the latest conversations. By doing this, people will (or should) get interested in connecting.
So, how will I give them our conversations? through a image. Because it’s the only way I can update anything on remote sites such as forums and not letting any one just copy our conversations.
I will now explain how I did it. I will assume you are a fellow geek and know what I’m talking about, if not, just google the unknown words.
To get latest conversations on our network I ran a eggdrop on our channel on logging modus. The eggdrop is running on the same server as my web server, making it easy to get the required text.
$file = “../../../eggdrop/logs/#rchobby.log”; // this is where my conversations are
$r = $g = $b = 255;
$lines = 8;
$width = 600;
$size = 10;
$text = array();
/* read file and get number of wanted lines */
foreach (array_slice(file($file),-$lines) as $x)
{
$x = str_replace(“<motor> (EFnet) “,”",$x); // have to remove some crap since we have linked networks
$x = preg_replace(“/^\[(\d{2})\:(\d{2})\] <(.*)>/”,”[\\1:\\2] (\\3)”,$x); // custom display format
$x = utf8_encode($x); // to support norwegian characters such as ø æ å
/* split up long sentences to fit width*/
$x = wordwrap($x,$width*0.15); // text can go utside the image, therefore we split it
foreach (explode(“\n”,$x) as $y)
{
if (!empty($y))
{
$text[] = $y;
}
}
}
/* define image and background color */
$image = imagecreate($width,count($text)*11); // create image object
$bgColor = imagecolorallocate($image,$r,$g,$b); // set background color
/* print text with desired font */
$x = $size;
foreach ($text as $line)
{
imagettftext($image,$size,0,0,$x,imagecolorallocate($image,0,0,0),”./ProFontWindows.ttf”,$line); // custom font
$x += $size;
}
imagettftext($image,25,-10,30,30,imagecolorallocatealpha($image,255,0,0,60),”./ProFontWindows.ttf”,”CLICK TO CHAT RC!”); // making it more professional, like a stamp
/* tell browser not to cache, conversation updates */
header(“Cache-Control: no-store, no-cache, must-revalidate”);
header(“Pragma: no-cache”);
/* send png image to browser */
header(“Content-type: image/png”);
imagepng($image);
?>
Now we have a file that displays a image with a given number of lines, but what about customizing colours and number of lines? to match designs on different forums. The solution is simple.
If we add following after variable defining we should be set.
/* custom color */
if (isset($_GET['r']) && is_numeric($_GET['r']) && $_GET['r'] >= 0 && $_GET['r'] <= 255)
{
$r = $_GET['r'];
}
if (isset($_GET['g']) && is_numeric($_GET['g']) && $_GET['g'] >= 0 && $_GET['g'] <= 255)
{
$g = $_GET['g'];
}
if (isset($_GET['b']) && is_numeric($_GET['b']) && $_GET['b'] >= 0 && $_GET['b'] <= 255)
{
$b = $_GET['r'];
}
/* number of lines to display */
if (isset($_GET['lines']) && is_numeric($_GET['lines']) && $_GET['lines'] > 0 && $_GET['lines'] <= 100)
{
$lines = $_GET['lines'];
}
/* image width */
if (isset($_GET['width']) && is_numeric($_GET['width']) && $_GET['width'] > 0 && $_GET['width'] <= 1280)
{
$width = $_GET['width'];
}
/* font size */
if (isset($_GET['size']) && is_numeric($_GET['size']) && $_GET['size'] > 0)
{
$size = $_GET['size'];
}
We’d want to make the image click able, linking it to our web based IRC client. We can also put it in the same file to make it simple and easy to maintain.
My complete program ended looking like this.
<?php
/* we want to display image */
if (isset($_GET['img']))
{
/* define vars */
$file = “../../../eggdrop/logs/#rchobby.log”;
if (!file_exists($file))
{
$file .= “.yesterday”;
}
$r = $g = $b = 255;
$lines = 8;
$width = 600;
$size = 10;
/* custom color */
if (isset($_GET['r']) && is_numeric($_GET['r']) && $_GET['r'] >= 0 && $_GET['r'] <= 255)
{
$r = $_GET['r'];
}
if (isset($_GET['g']) && is_numeric($_GET['g']) && $_GET['g'] >= 0 && $_GET['g'] <= 255)
{
$g = $_GET['g'];
}
if (isset($_GET['b']) && is_numeric($_GET['b']) && $_GET['b'] >= 0 && $_GET['b'] <= 255)
{
$b = $_GET['r'];
}
/* number of lines to display */
if (isset($_GET['lines']) && is_numeric($_GET['lines']) && $_GET['lines'] > 0 && $_GET['lines'] <= 100)
{
$lines = $_GET['lines'];
}
/* image width */
if (isset($_GET['width']) && is_numeric($_GET['width']) && $_GET['width'] > 0 && $_GET['width'] <= 1280)
{
$width = $_GET['width'];
}
/* font size */
if (isset($_GET['size']) && is_numeric($_GET['size']) && $_GET['size'] > 0)
{
$size = $_GET['size'];
}
$text = array();
/* read file and get number of wanted lines */
foreach (array_slice(file($file),-$lines) as $x)
{
$x = str_replace(“<motor> (EFnet) “,”",$x);
$x = preg_replace(“/^\[(\d{2})\:(\d{2})\] <(.*)>/”,”[\\1:\\2] (\\3)”,$x);
$x = utf8_encode($x);
/* split up long sentences to fit width*/
$x = wordwrap($x,$width*0.15);
foreach (explode(“\n”,$x) as $y)
{
if (!empty($y))
{
$text[] = $y;
}
}
}
/* define image and background color */
$image = imagecreate($width,count($text)*11);
$bgColor = imagecolorallocate($image,$r,$g,$b);
/* print text with desired font */
$x = $size;
foreach ($text as $line)
{
imagettftext($image,$size,0,0,$x,imagecolorallocate($image,0,0,0),”./ProFontWindows.ttf”,$line);
$x += $size;
}
imagettftext($image,25,-10,30,30,imagecolorallocatealpha($image,255,0,0,60),”./ProFontWindows.ttf”,”CLICK TO CHAT RC!”);
/* don’t cache */
header(“Cache-Control: no-store, no-cache, must-revalidate”);
header(“Pragma: no-cache”);
/* send image to browser */
header(“Content-type: image/png”);
imagepng($image);
return;
}
?>
<html>
<head>
<title>#rchobby @ quakenet connecter</title>
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8″/>
<meta name=”description” content=”#rchobby on Quakenet.org”/>
</head>
<body>
<strong>Want to chat? click and connect!</strong><br />
<form method=”post” action=”http://portalzona.com/cgi-bin/cgiirc/irc.cgi”>
<input type=”hidden” name=”interface” value=”mozilla”>
Your nickname <input type=”text” id=”nickname” name=”Nickname” value=”rchobby<?php echo mt_rand(100,999); ?>” />
<input type=”hidden” name=”Server” value=”irc.quakenet.org” />
<input type=”hidden” name=”Port” value=”6667″ />
<input type=”hidden” name=”Channel” value=”#rchobby” />
<input type=”hidden” name=”Password” value=”" />
<input type=”submit” value=”CLICK TO CONNECT” />
</form>
<br /><br /><br />
<strong>If you want to customize the image output, you can use following settings and copy image location.</strong><br /><br />
<u>Color settings for background</u><br />
<form method=”get” action=”">
Red <input type=”text” name=”r” length=3 value=”<?php echo (isset($_GET['r'])?$_GET['r']:255); ?>” size=1 /><br />
Green <input type=”text” name=”g” length=3 value=”<?php echo (isset($_GET['g'])?$_GET['g']:255); ?>” size=1 /><br />
Blue <input type=”text” name=”b” length=3 value=”<?php echo (isset($_GET['b'])?$_GET['b']:255); ?>” size=1 /><br />
<br />
<u>Text settings</u><br />
Font size <input type=”text” name=”size” length=2 value=”<?php echo (isset($_GET['size'])?$_GET['size']:10); ?>” size=1 /> pixels<br />
Image width <input type=”text” name=”width” length=4 value=”<?php echo (isset($_GET['width'])?$_GET['width']:600); ?>” size=2 /> pixels<br />
Numer of lines <input type=”text” name=”lines” length=3 value=”<?php echo (isset($_GET['lines'])?$_GET['lines']:8); ?>” size=1 /><br />
<input type=”submit” value=”Display” />
</form>
<img src=”rchobby.php?img&<?php foreach ($_GET as $key=>$val) { echo “$key=$val&”; } ?>” alt=”" />
<script type=”text/javascript”>document.getElementById(‘nickname’).focus();</script>
</body>
This is the result
