IRC channel quotes
<html>
<head>
<title>IRC channel quotes</title>
<style>
h2 {border-bottom:1px solid #A0A0A0;}
.footer {border-bottom:1px solid #FFBE21;border-top:1px solid #FFBE21;}
</style>
</head>
<body>
<div style="float:right">
<small>
<a href='?q=main'>home</a> |
<a href='?q=random'>random quote</a> |
<a href='?q=list'>list quotes</a> |
<a href='?q=all'>all quotes</a> |
<a href='?q=code'>source code</a>
</small>
</div>
<h2>IRC channel quotes</h2>
<?
if(isset($_GET['q'])){
$quotenum=$_GET['q'];
switch($quotenum){
case 'all':
echo all_quotes();
break;
case 'main':
echo default_page();
break;
case 'list':
echo list_quotes();
break;
case 'random':
echo random_quote();
break;
case 'code':
source_code();
break;
default:
echo quote_by_num($quotenum);
break;
}
} else {
echo default_page();
}
// This function returns a random quote from the quotes.txt file
function random_quote() {
$quotes=explode("\r\n%\r\n", file_get_contents("quotes.txt"));
$qub=count($quotes)-1;
$qub=rand(0, $qub);
$a=$quotes[$qub];
$a=str_replace("&", "&", $a);
$a=str_replace("<", "<",$a);
$a=str_replace(">", ">", $a);
$b=$a;
$a="<pre><tt>";
$a=$a."<b>Quote #<a href='?q=".$qub."'>".$qub."</a></b>";
$a=$a."\r\n".$b."\r\n</tt></pre>";
return $a;
}
// This function returns a quote by its number (first quote is 0, etc)
function quote_by_num($n) {
$quotes=explode("\r\n%\r\n", file_get_contents("quotes.txt"));
$qub=count($quotes)-1;
if ($n<$qub+1&&$n>-1) {
$qub=$n;
$a=$quotes[$qub];
if ($a != '') {
$a=str_replace("&", "&", $a);
$a=str_replace("<", "<",$a);
$a=str_replace(">", ">", $a);
$b=$a;
$a="<pre><tt>";
$a=$a."<b>Quote #<a href='?q=".$qub."'>".$qub."</a></b>\r\n";
$a=$a.$b."\r\n";
$a=$a."</tt></pre>";
} else {
$a="<pre><tt>";
$a=$a."<font color='red'>";
$a=$a."No such quote [quote identifiers must be numerical]";
$a=$a."</font>\r\n</tt></pre>";
}
} else {
$a="<pre><tt>";
$a=$a."<b>Quote #<a href='?q=".$n."'>".$n."</a></b>\r\n";
$a=$a."<font color='red'>";
$a=$a."No such quote [quote out of range]";
$a=$a."</font>\r\n</tt></pre>";
}
return $a;
}
function list_quotes() {
$quotes=explode("\r\n%\r\n", file_get_contents("quotes.txt"));
$qub=count($quotes)-1;
$qub2=$qub+1;
$a="There are currently <b>".$qub2."</b> quotes.\r\n";
$a=$a."<div style='-moz-column-count:5; column-count:5;'>\r\n<UL>";
for($i = 0; $i < $qub+1; $i++) {
$a=$a."\r\n<LI><A href='?q=".$i."'>#".$i."</A></LI>";
}
$a=$a."\r\n</UL>\r\n</div>";
return $a;
}
function count_quotes() {
$quotes=explode("\r\n%\r\n", file_get_contents("quotes.txt"));
return count($quotes);
}
function default_page() {
$a="";
$a=$a."This is a fairly simple PHP based tool to aid in browsing of the ";
$a=$a."<a href='http://meta.wikimedia.org/wiki/IRC_channel_quotes'>";
$a=$a."IRC channel quotes</a>. If you've been here before, then you ";
$a=$a."may use the box below to re-visit a quote you liked. ";
$a=$a."If this is the first time you've seen this tool, then ";
$a=$a."you can use the above links to browse the quotes.";
$a=$a."<center>";
$a=$a."<br />";
$num=count_quotes()-1;
$a=$a."Enter the number of the quote you wish to read (0-".$num."):";
$a=$a."<form>";
$a=$a."<input type='text' name='q'/><input type='submit' value='Go'>";
$a=$a."</form>";
$a=$a."</center>";
return $a;
}
function all_quotes() {
$qub=count_quotes();
for($i = 0; $i < $qub; $i++) {
$temp=quote_by_num($i);
if ($i != $qub-1) { $temp=$temp."<hr />"; }
$a=$a.$temp;
}
return $a;
}
function source_code() {
show_source(__FILE__);
}
?>
<div class="footer">
<small><center><br/>
<div style="float:right">
<a href="http://tools.wikimedia.de">
<img src="http://tools.wikimedia.de/images/wikimedia-toolserver-button.png" border="0"
alt="Powered by the Wikimedia Toolserver"/>
</a>
</div>
This tool was coded by Michael Billington.<br/>
You may contact me either through my
<a href="http://en.wikipedia.org/w/index.php?title=User_talk:MichaelBillington&action=edit§ion=new">
talk page</a> or <a href="mailto:michael.billington@gmail.com">by email</a>.<br/><br/>
</center></small>
</div>
</body>
</html>