Home Archive Cast Gallery Links Info

SushiBox Code


The SushiBox was created as an alternative to yellbox and other similiar products. The main advantage is that because all shouts save on your server and you do not rely on another site, it does not cause popups and the sushibox can be made to look and act as you wish. It is easy to add emoticons because the system sutomatically adds all gifs in a folder to the emoticon menu. The code has four parts: first, sushibox.php which has the code for the windows and bottons and the javascript to load the emoticon menu; secondly, displayicons.php which has a short bit of code that cycles through all of the gifs in a folder and outputs their icons (with links); third, postmessage.php which filters and submits a message if someone has entered a name and message and outputs the code of the box either way, and finally shouts.htm which is the file where shouts are saved. You should also create a folder to contain emoticons and edit the code so that it will use your folder.

The SushiBox is currently designed to look like the yellbox it was based off, but this can be changed. The alternating colors (marked in red, like most important parts of the code) can be changed easily, but more coding experience would be needed to make it alternate between more than two colors. Changes to the font sizes, types, and colors are also marked in red, and are near the beginning of postmessage.php. Shouts can be deleted by removing lines from the file shouts.htm, but be careful: the shoutbox needs at least one shout or it will not work (because it checks the last shout to decide what color to use).

In order to implement the SushiBox, you will need a line of php code on the page where you will put the box. In order for this php command to work, the page needs to be saved with the .php extension. Note that this extension works just like .html except that it enables php commands. After renaming your page, you may have to fix several links to it, but that shouldn't be a problem (Having access to php commands is very worthwhile). Once the following four parts of the program have been set up, add this line "<?php include("sushibox.php"); ?>" and the program should work! If not, contact me at .

sushibox.php

<script type="text/javascript">
<!--

function openiconswindow() {

newWindow = window.open('', 'icons', 'width=300,height=300,scrollbars=yes,status=no');
newWindow.opener = self;

newWindow.document.open("text/html");
newWindow.document.write("<html><head><title>Select Icon</title>");
newWindow.document.write("<script language='JavaScript'>\n");
newWindow.document.write("function addicon(brackettext) {\n");
newWindow.document.write(" if (window.opener.document.sushiboxform!=window.undef) {\n");
newWindow.document.write(" if (window.opener.document.sushiboxform.mesg_text.value=='Message') window.opener.document.sushiboxform.mesg_text.value='[['+brackettext+']]';\n");
newWindow.document.write(" else window.opener.document.sushiboxform.mesg_text.value+='[['+brackettext+']]';\n");
newWindow.document.write(" window.opener.document.sushiboxform.mesg_text.focus();\n");
newWindow.document.write(" window.close();\n");
newWindow.document.write(" }\n");
newWindow.document.write("};\n");
newWindow.document.write("</script>\n");
newWindow.document.write("</head>\n");

newWindow.document.write("<body><table>\n");
newWindow.document.write("<center><?php include('displayicons.php'); ?></center>\n");
newWindow.document.write("</table></body></html>");

newWindow.document.close();
newWindow.focus();

}

function clear_message2() {
document.sushiboxform.mesg_text.value="";
document.sushiboxform.mesg_name.focus();
}

function clearMessageBox() {
document.sushiboxform.submit();
setTimeout("clear_message2()",200);
return false;
}

//-->
</script>

<table width='80%'><tr><td>
<iframe name="sbframe" style="width: 100%; border: 1px inset;" frameborder="0" height="250" marginwidth="0" marginheight="0" src="postmessage.php"></iframe>
<form method="post" action="postmessage.php" name="sushiboxform" target="sbframe">
<input name='mesg_name' value='Name' maxlength='20' style='width: 100%;' onfocus="if (this.value=='Name') this.value=''; return;">
<br><textarea name='mesg_text' value='Message' maxlength='800' rows='4' cols='1' style='width: 100%;' onfocus="if (this.value=='Message') this.value=''; return;">Message</textarea>
<button onclick="return clearMessageBox();" style="height: 25px; width: 100px;">Submit</button>
<button onclick="openiconswindow(); return false;" style="width: 27px; height: 23px; border: ridge; background-color: white;"><img src="site_images/smiley.gif" alt="Smileys"></button>
</form>
</td></tr></table>



displayicons.php

<?php
$dir="site_images/sushi_box_icons/";
//$rowcounter=0;
if ($dh=opendir($dir)) {
while (($file=readdir($dh))!==false) {
$len=strlen($file);
$pos=strpos($file,".");
$fname=substr($file,0,$pos);
$type=substr($file,$pos+1,$len);
if (strtolower($type)=="gif") {
//$rowcounter++;
//if ($rowcounter>=10) {echo "<br>"; $rowcounter=0;}
echo "<a href=\\\"javascript:addicon('".$fname."');\\\"><img src='".$dir.$file."' border=0></a> ";
}
}
closedir($dh);
}
?>



postmessage.php

<html>
<head>
<title>SushiBox</title>
</head>

<style type="text/css">
p,td{
font-family: Arial, Helvetica, sans-serif;
font-size: 12;
color: #000000;
}
</style>
<body bgcolor=#FFFFFF>

<?php

$name=$_POST["mesg_name"];
$mesg=$_POST["mesg_text"];

if ($name=="Name"||$name==""||$mesg=="Message"||$mesg=="") {DisplayText(); return;}
$name=strip_tags($name);
$mesg=strip_tags($mesg, "<b><i><u><sup><sub><a>");
$name=str_replace("\'", "&#39;", $name);
$name=str_replace('\"', "&#34;", $name);
$name=str_replace("\\\\", "&#92;", $name);
$mesg=str_replace("\'", "&#39;", $mesg);
$mesg=str_replace('\"', "&#34;", $mesg);
$mesg=str_replace("\\\\", "&#92;", $mesg);

$mesg=" ".$mesg;
$curchar=0;
while ($curchar<strlen($mesg)) {
$curchar=strpos($mesg, "[[", $curchar);
if ($curchar==false) break;
for ($i=$curchar+2; 1==1; $i++) {
if (substr($mesg, $i+1, 2)=="]]") {
$mesg=substr($mesg, 0, $curchar)."<img src='site_images/sushi_box_icons/".substr($mesg, $curchar+2, $i-$curchar-2).".gif'>".substr($mesg, $i+3, strlen($mesg)-$i-3);
break;
} else if ($i>=strlen($mesg)) {
$mesg=substr($mesg, 0, $curchar).substr($mesg, $curchar+2, strlen($mesg)-$curchar-2);
break;
}
}
}
$mesg=substr($mesg, 1, strlen($mesg)-1);
if ($mesg=="") {DisplayText(); return;}

$curchar=strpos($mesg, "<a ");
if ($curchar!=false) $mesg=substr_replace($mesg, "target='_blank' ", $curchar+3, 0);

$shoutfile=fopen("shouts.htm","r");
$lastshout=fgets($shoutfile);
fclose($shoutfile);
$lastshoutcolor=substr($lastshout,16,7);
if ($lastshoutcolor=="#CCCCCC") $linecolor="#FFFFFF"; else $linecolor="#CCCCCC";

$lastshout=strip_tags($lastshout);
$centerpos=strpos($lastshout,':');
$lastname=substr($lastshout,0,$centerpos);
$lastmesg=substr($lastshout,$centerpos+2,strlen($lastshout)-$centerpos-4);
if ($name==$lastname && $mesg==$lastmesg) {DisplayText(); return;}

$shoutarraylength=0;
$shoutfile=fopen("shouts.htm","r");
while(!feof($shoutfile)&&$shoutarraylength<500) {
$shoutarraylength++;
$shoutarray[$shoutarraylength]=fgets($shoutfile);
if (trim(strip_tags($shoutarray[$shoutarraylength]))=="") $shoutarraylength--;
}
fclose($shoutfile);

flock($shoutfile, 1);
$shoutfile=fopen("shouts.htm","w");
fwrite($shoutfile, "<table bgcolor='".$linecolor."' width='100%'><tr><td><b>".$name."</b>: ".$mesg."</td></tr></table>\r\n");
for ($i=1; $i<=$shoutarraylength; $i++) fwrite($shoutfile, $shoutarray[$i]);
fclose($shoutfile);
flock($shoutfile, 3);

DisplayText();
return;

function DisplayText() {
$shoutfile=fopen("shouts.htm","r");
$curline=0;
while(!feof($shoutfile)&&$curline<50) {
echo fgets($shoutfile);
$curline++;
}
fclose($shoutfile);

}

?>

</body></html>



shouts.htm

<table bgcolor='#CCCCCC' width='100%'><tr><td><b>Ian</b>: This sushibox was programmed by Ian Burnet of <a href=http://www.sushidatabase.com>Sushi Database</a>. Keep this shout because your box always needs to have at least one shout to work properly.</td></tr></table>

Sushi Database and The Adventures of Emo Samurai are copyright of Jamie Burnet (2007). Original character designs of Sushi Database by Lynette Bishop. Original sprite of Striker by James Beaver.
The Webcomic List Online Comics Lost in the Fog Productions Top 100 Lost in the Fog Productions Top 100