PDA

View Full Version : Statistics



HK
February 14th, 2011, 12:01:27
Hello, can I ask how you made those cool icons that show whether the user is online (on irc) or not?

Jobe
February 20th, 2011, 00:18:41
Sorry it's taken so long to reply, hadn't noticed your message.

The images go into a little more detail then online/offline, they also cover authenticated to services, IRCops, services, bots, away and SSL too.

Oh those are quite simple, its just a simple PHP script (mod_rewrite to give the .png extension) that reads from Denora's (IRC Statistics service) MySQL database.

As for the images they're just loaded by PHP's GD library. And in the case of the key (SSL) and clock (away) overlays, they're just images with a transparent background loaded and merged using PHP's GD library.

The images I use can be found in famfamfam.com's silk icon set (or in the attached zip.file)

The code I use (bear in mind this code is tuned for using Denora's MySQL DB with Denora connected to a network running Nefarious which has slightly different user modes to some IRCds):

<?php
$sqldetails['server'] = "<mysqlserver>";
$sqldetails['user'] = "<mysqluser>";
$sqldetails['password'] = "<mysqlpasswd>";
$sqldetails['database'] = "<mysqldenoradb>";

$nickin = "";
if ( isset($_GET['user']) ) {
$nickin = $_GET['user'];
}
if ( isset($_POST['user']) ) {
$nickin = $_POST['user'];
}

$nickin = str_replace("/", "\\", $nickin);

$status = 0;

$conn = mysql_connect($sqldetails['server'], $sqldetails['user'], $sqldetails['password']);
mysql_select_db($sqldetails['database'], $conn);

$sqlu = "SELECT * FROM user WHERE nick = '".mysql_real_escape_string($nickin)."'";
$resultu = mysql_query($sqlu, $conn) or die(mysql_error());

if ( mysql_num_rows($resultu) > 0 ) {
$userrow = mysql_fetch_array($resultu);
if ( $userrow['online'] == "Y" ) {
$status = 2;
if ( ( $userrow['account'] != "" ) or ( $userrow['mode_lr'] == "Y" ) ) {
$status = 1;
}
if ( $userrow['mode_lo'] == "Y" ) {
$status = 3;
}
if ( $userrow['mode_ub'] == "Y" ) {
$status = 5;
}
if ( $userrow['mode_lk'] == "Y" ) {
$status = 4;
}
if ( $userrow['mode_lz'] == "Y" ) {
$ssl = 1;
}
if ( $userrow['away'] == "Y" ) {
$away = 1;
}
} else {
$status = 0;
}
} else {
$status = 0;
}

if ( $status == 1 ) {
$img = ImageCreateFromPng("images/status-onlinereg.png");
} else if ( $status == 2 ) {
$img = ImageCreateFromPng("images/status-online.png");
} else if ( $status == 3 ) {
$img = ImageCreateFromPng("images/status-oper.png");
} else if ( $status == 4 ) {
$img = ImageCreateFromPng("images/status-service.png");
} else if ( $status == 5 ) {
$img = ImageCreateFromPng("images/status-bot.png");
} else {
$img = ImageCreateFromPng("images/status-offline.png");
}

if ( $ssl == 1 ) {
$imgssl = ImageCreateFromPng("images/status-ssl.png");
ImageCopyMerge($img, $imgssl, 0, 0, 0, 0, 16, 16, 100);
ImageDestroy($imgssl);
}

if ( $away == 1 ) {
$imgaway = ImageCreateFromPng("images/status-away.png");
ImageCopyMerge($img, $imgaway, 0, 0, 0, 0, 16, 16, 100);
ImageDestroy($imgaway);
}

header ("Content-type: image/png");
ImagePNG($img);

ImageDestroy($img);

mysql_close($conn);
?>