|
From: wasted <wa...@fi...> - 2004-01-18 16:53:46
|
wasted 2004/01/18 10:59:18 CST
Added files:
scripts README chaninfo.php channels.php
functions.php seen.php squits.php
Log:
Add some PHP example scripts and bump up the version for a release.
Revision Changes Path
1.1 +3 -0 wStats/scripts/README (new)
1.1 +62 -0 wStats/scripts/chaninfo.php (new)
1.1 +98 -0 wStats/scripts/channels.php (new)
1.1 +204 -0 wStats/scripts/functions.php (new)
1.1 +42 -0 wStats/scripts/seen.php (new)
1.1 +75 -0 wStats/scripts/squits.php (new)
Index: README
====================================================================
The scripts in this directory are here to help give a webmaster
the idea of whats possible with the wStats database, no support
is given for them.
Index: chaninfo.php
====================================================================
<?
include"functions.php";
// Change the host, user and password.
$dbstats = mysql_connect("wstats.mysql.host", "youruser", "yourpassword");
if(!$dbstats) {
die("Sorry, the connection to the server cannot be made! (".mysql_error().")");
}
else {
// Change the database if needed aswell.
mysql_select_db("wStats", $dbstats) or die("Failed the select database: ".mysql_error());
}
if($_GET['channel'])
{
$channel = "#".mysql_real_escape_string($_GET['channel']);
$sql = mysql_query("SELECT topic, topicby, topicon, modes, climit, users FROM channels WHERE cname = '".$channel."'");
if(!mysql_num_rows($sql))
{
echo"<center>No such channel!</center>";
}
else {
echo"<table align=\"center\">
<tr><td colspan=2 align=\"center\"><b>".$channel."</b></td></tr>";
list($topic, $topicby, $topicon, $modes, $limit, $users) = mysql_fetch_row($sql);
if(!$limit) unset($limit);
if($topic) echo"<tr><td colspan=2>Topic: ".irctext(stripslashes($topic), 15, 15)." set on ".date("H/m/d H:i:s", $topicon)." by ".stripslashes($topicby)."</td></tr>
<tr>
<td colspan=2> </td>
</tr>
<tr>
<td colspan=2>Modes: ".$modes." ".$limit."</td>
</tr>
<tr>
<td colspan=2>Users: ".$users."</td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
<tr>
<td colspan=2 align=\"center\"><b>Users:</b></td>
</tr>";
$sql = mysql_query("SELECT nickname, status FROM userlists WHERE cname = '".$channel."' ORDER BY status DESC");
while($usr = mysql_fetch_row($sql))
{
echo"<tr><td>".get_status($usr[1]).$usr[0]."</td></tr>";
}
echo"</table>";
}
}
else {
echo"<center>Please call this file with ?channel=channel (without a #)</center>";
}
?>
Index: channels.php
====================================================================
<?
include"functions.php";
// Change the host, user and password.
$dbstats = mysql_connect("wstats.mysql.host", "youruser", "yourpassword");
if(!$dbstats) {
die("Sorry, the connection to the server cannot be made! (".mysql_error().")");
}
else {
// Change the database if needed aswell.
mysql_select_db("wStats", $dbstats) or die("Failed the select database: ".mysql_error());
}
?>
<h2>Channel search</h2>
<form method="post">
<table>
<tr>
<td>Channel:</td>
<td><input type="text" name="channel" value="<?=$_POST['channel']?>" class="editbox"></td>
</tr>
<tr>
<td>Sort by:</td>
<td>
<select name="sortby" class="editbox">
<option <? if($_POST['sortby'] == "Users") { echo "selected"; } ?>>Users</option>
<option <? if($_POST['sortby'] == "Name") { echo "selected"; } ?>>Name</option>
<option <? if($_POST['sortby'] == "Topic timestamp") { echo "selected"; } ?>>Topic timestamp</opion>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="checkbox" name="showpub" value="1" <? if($_POST['showpub']) echo"checked";?>>Show topics in +p channels</td>
</tr>
<tr>
<td> </td>
<td><input type="checkbox" name="showsecret" value="1" <? if($_POST['showsecret']) echo"checked";?>>Show +s channels</td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
<tr>
<td colspan=2><input type="submit" value="Search" class="editbox"></td>
</tr>
</table>
</form>
<?
if($_POST['channel']) {
echo"<br><hr>";
if($_POST['showsecret']) $where = "WHERE";
else $where = "WHERE issecret = 0 AND";
$channel = addslashes($_POST['channel']);
if($_POST['sortby'] == "Users") {
$sql = mysql_query("SELECT cname, modes, topic, users, isprivate FROM channels ".$where." cname LIKE '%".$channel."%' ORDER BY users DESC");
}
elseif($_POST['sortby'] == "Name") {
$sql = mysql_query("SELECT cname, modes, topic, users, isprivate FROM channels ".$where." cname LIKE '%".$channel."%' ORDER BY cname ASC");
}
elseif($_POST['sortby'] == "Topic timestamp") {
$sql = mysql_query("SELECT cname, modes, topic, users, isprivate FROM channels ".$where." cname LIKE '%".$channel."%' ORDER BY topicon DESC");
}
if(!mysql_num_rows($sql)) {
echo"No channels found.<br><br>";
}
else {
?>
<table align="center">
<tr bgcolor="#000000">
<td><font color="#ffffff"><b>Channel</b></font></td>
<td><font color="#ffffff"><b>Users</b></font></td>
<td><font color="#ffffff"><b>Modes</b></font></td>
<td><font color="#ffffff"><b>Topic</b></font></td>
</tr>
<?
while($chan = mysql_fetch_row($sql)) {
echo"<tr>
<td>".stripslashes($chan[0])."</td>
<td>".$chan[3]."</td>
<td>".$chan[1]."</td>
<td>";
if($chan[4] != 1 || $_POST['showpub'])
{
echo irctext(stripslashes($chan[2]), 15, 15);
}
else {
echo" ";
}
echo"</td></tr>";
}
?></table><?
}
}
?>
Index: functions.php
====================================================================
<?
function calcElapsedTime($time)
{
$diff = time()-$time;
$daysDiff = floor($diff/60/60/24);
$diff -= $daysDiff*60*60*24;
$hrsDiff = floor($diff/60/60);
$diff -= $hrsDiff*60*60;
$minsDiff = floor($diff/60);
$diff -= $minsDiff*60;
$secsDiff = $diff;
return $daysDiff.'d '.$hrsDiff.'h '.$minsDiff.'m '.$secsDiff.'s ago';
}
function isnumber($x)
{
if (($x == "0") || ($x == "1") || ($x == "2") ||
($x == "3") || ($x == "4") || ($x == "5") ||
($x == "6") || ($x == "7") || ($x == "8") ||
($x == "9"))
{
return 1;
}
return 0;
}
function colourof($x, $fgbg = "fg", $fgx = -1, $bgx = -1)
{
if ($x > 15 && $x < 99) $x = $x % 16;
if ($x == 0) return "white";
if ($x == 1) return "black";
if ($x == 2) return "darkblue";
if ($x == 3) return "darkgreen";
if ($x == 4) return "red";
if ($x == 5) return "maroon";
if ($x == 6) return "purple";
if ($x == 7) return "orange";
if ($x == 8) return "yellow";
if ($x == 9) return "lime";
if ($x == 10) return "teal";
if ($x == 11) return "cyan";
if ($x == 12) return "blue";
if ($x == 13) return "pink";
if ($x == 14) return "darkgray";
if ($x == 15) return "lightgray";
if ($fgx == -1) $fgx = "black";
if ($bgx == -1) $bgx = "white";
if ($fgbg == "fg") return $fgx;
if ($fgbg == "bg") return $bgx;
}
function irctext($x, $fgx = "99", $bgx = "99")
{
$z = "";
$bold = 0;
$underline = 0;
$colour = 0;
$reverse = 0;
$fg = $fgx;
$bg = $bgx;
for ($i = 0; $i < strlen($x); $i++)
{
if (substr($x, $i, 1) == chr(3)) {
if ($colour == 7 && !$reverse) { $z .= "</font>"; }
$colour = 1;
}
elseif ($colour == 1) {
if (isnumber(substr($x, $i, 1))) {
$colour++;
$fg = substr($x, $i, 1);
$comma = 0;
}
else {
$colour = 0;
$fg = $fgx;
$bg = $bgx;
}
}
elseif ($colour == 2) {
if (isnumber(substr($x, $i, 1))) {
$colour++;
$fg .= substr($x, $i, 1);
$comma = 0;
}
elseif (substr($x, $i, 1) == ",") {
$colour++;
$comma = 1;
}
else {
$colour = 7;
if (!$reverse) $z .= "<font color=\"".colourof($fg, "fg", $fgz, $bgx)."\" style=\"background:".colourof($bg, "bg")."\">";
}
}
elseif ($colour == 3) {
if (isnumber(substr($x, $i, 1)) && $comma) {
$colour++;
$bg = substr($x, $i, 1);
$comma = 0;
}
elseif (substr($x, $i, 1) == ",") {
$colour++;
$comma = 1;
}
else {
$colour = 7;
if (!$reverse) $z .= "<font color=\"".colourof($fg, "fg", $fgz, $bgx)."\" style=\"background:".colourof($bg, "bg")."\">";
if ($comma) $z .= ",";
}
}
elseif ($colour == 4) {
if (isnumber(substr($x, $i, 1))) {
$colour++;
$bg .= substr($x, $i, 1);
if ($comma) $bg = substr($x, $i, 1);
}
else {
$colour = 7;
if (!$reverse) $z .= "<font color=\"".colourof($fg, "fg", $fgz, $bgx)."\" style=\"background:".colourof($bg, "bg")."\">";
if ($comma) $z .= ",";
}
}
elseif ($colour == 5) {
if (isnumber(substr($x, $i, 1))) {
$bg .= substr($x, $i, 1);
$colour++;
}
else {
$colour = 7;
if (!$reverse) $z .= "<font color=\"".colourof($fg,"fg",$fgz,$bgx)."\" style=\"background:".colourof($bg,"bg")."\">";
}
}
elseif ($colour == 6) {
$colour++;
if (!$reverse) $z .= "<font color=\"".colourof($fg,"fg",$fgz,$bgx)."\" style=\"background:".colourof($bg,"bg")."\">";
}
if (substr($x, $i, 1) == chr(2)) {
if ($bold) {
$z .= "</b>";
$bold = 0;
}
else {
$z .= "<b>";
$bold = 1;
}
}
elseif (substr($x, $i, 1) == chr(31)) {
if ($underline) {
$z .= "</u>";
$underline = 0;
}
else {
$z .= "<u>";
$underline = 1;
}
}
elseif (substr($x, $i, 1) == chr(22)) {
if ($reverse) {
$z .= "</font>";
if ($colour == 7) $z .= "<font color=\"".colourof($fg, "fg", $fgx, $bgx)."\" style=\"background:".colourof($bg, "bg", $fgx, $bgx)."\">";
$reverse = 0;
}
else {
if ($colour == 7) $z .= "</font>";
$z .= "<font color=\"".colourof(99, "bg")."\" style=\"background:".colourof(99, "fg")."\">";
$reverse = 1;
}
}
elseif (substr($x, $i, 1) == chr(15)) {
if ($bold) $z .= "</b>";
if ($underline) $z .= "</u>";
if ($colour == 7 AND !$reverse) $z .= "</font>";
if ($reverse) $z .= "</font>";
$bold = 0; $colour = 0; $underline = 0;
$reverse = 0; $fg = $fgx; $bg = $bgx;
}
elseif (substr($x, $i, 1) != chr(3) AND ($colour == 0 OR ($colour == 1 AND !isnumber(substr($x, $i, 1))) OR $colour == 7)) {
$z .= htmlentities(substr($x, $i, 1));
}
}
if ($bold) $z .= "</b>";
if ($underline) $z .= "</u>";
if ($colour == 7 AND !$reverse) $z .= "</font>";
if ($reverse) $z .= "</font>";
return $z;
}
function get_status($status)
{
switch($status)
{
case 2:
return "@";
break;
case 1:
return "+";
break;
}
}
?>
Index: seen.php
====================================================================
<?
include"functions.php";
// Change the host, user and password.
$dbstats = mysql_connect("wstats.mysql.host", "youruser", "yourpassword");
if(!$dbstats) {
die("Sorry, the connection to the server cannot be made! (".mysql_error().")");
}
else {
// Change the database if needed aswell.
mysql_select_db("wStats", $dbstats) or die("Failed the select database: ".mysql_error());
}
?>
<center>
See how long ago it was a nickname was used.<br><br>
<form method="post">
<table width="50%" align="center">
<tr>
<td>Nickname:</td>
<td><input type="text" name="seennick" class="editbox"></td>
</tr>
<tr>
<td colspan=2 align="center"><input type="submit" value="Go!" class="editbox"></td>
</tr>
</table>
</form>
<?
if(!empty($_POST['seennick'])) {
echo"<br><hr><br><br>";
$nick = addslashes($_POST['seennick']);
$sql = mysql_query("SELECT nickname, lastused FROM seen WHERE nickname = '".$nick."'");
if(!mysql_num_rows($sql)) {
echo"The nickname <b>".$nick."</b> has not been recorded being used, sorry.";
}
else {
list($nickname, $lastused) = mysql_fetch_row($sql);
echo"The nickname <b>".stripslashes($nickname)."</b> was last used on ".date("Y-m-d", $lastused)." at ".date("H:i:s", $lastused).", ".calcElapsedTime($lastused)."<br><br>";
}
}
?>
</center>
Index: squits.php
====================================================================
<?
include"functions.php";
// Change the host, user and password.
$dbstats = mysql_connect("wstats.mysql.host", "youruser", "yourpassword");
if(!$dbstats) {
die("Sorry, the connection to the server cannot be made! (".mysql_error().")");
}
else {
// Change the database if needed aswell.
mysql_select_db("wStats", $dbstats) or die("Failed the select database: ".mysql_error());
}
?>
<form method="post">Show only:
<select name="order" onchange="this.form.submit();">
<option value="All">All</option>
<?
$sql = mysql_query("SELECT mask FROM servers ORDER BY mask");
while($serv = mysql_fetch_row($sql))
{
$selected = "";
if($_POST['order'] == $serv[0]) $selected = " selected";
echo"<option value=\"".$serv[0]."\"".$selected.">".$serv[0]."</option>";
}
?>
</select>
</form>
<center>
<?
if(isset($_POST['order']) && $_POST['order'] != "All") {
$sql = mysql_query("SELECT ts, split_server, reason, hub FROM splits WHERE split_server = '".$_POST['order']."' ORDER BY id DESC");
}
else {
$sql = mysql_query("SELECT ts, split_server, reason, hub FROM splits ORDER BY id DESC");
}
if(!mysql_num_rows($sql)) {
if(isset($_POST['order'])) {
echo"No *.net *.splits recorded for ".$_POST['order'];
}
else {
echo"No *.net *.splits recorded.";
}
}
else {
?>
<table border=1 bordercolor="#000000" width="90%" align="center">
<tr>
<td width="20%" align="center" bgcolor="#000000"><font color="#ffffff"><B>Date</B></font></td>
<td width="15%" align="center" bgcolor="#000000"><font color="#ffffff"><B>Hub</B></font></td>
<td width="15%" align="center" bgcolor="#000000"><font color="#ffffff"><B>Split</B></font></td>
<td width="50%" align="center" bgcolor="#000000"><font color="#ffffff"><B>Reason</B></font></td>
</tr>
<?
while($split = mysql_fetch_row($sql)) {
$split[0] = date("H:i:s d-m-Y T", $split[0]);
echo"<tr>
<td width=\"20%\" align=\"center\">".$split[0]."</td>
<td width=\"20%\" align=\"center\">".$split[3]."</td>
<td width=\"20%\" align=\"center\">".$split[1]."</td>
<td width=\"60%\" align=\"center\">".$split[2]."</td>
</tr>
";
}
?>
</table>
<br><br>
<?
$rows = mysql_num_rows($sql);
echo "$rows squits logged.";
}
?>
</center>
|