PHPBuilder - Chat in RetroStyle (ChatRS)



RSS Twitter
Snippets Bbs Discussion

Chat in RetroStyle (ChatRS)

by: Allen
|
November 7, 2004

Version: 1.5.2

Type: Full Script

Category: BBS/Discussion

License: Artistic License

Description: ChatRS is a highly customizable pull based chat script. Users can post with their own font/colors -- which can be saved in a cookie or URL encoded (either as a bookmark or in the optional sidebar). ChatRS uses an installer for setup, making it a breeze to install. The many options can be managed easily via an administrative interface. To install it, one need only change the two variables in the beginning of the (install) script, upload the installer to the desired directory (which should be chmod 777), and then go to the installer via your web browser.



<?php
/*
  ChatRS Installer
  An "Any Idiot Can Do It" installer

  This chat source is provided exclusively 
  under an open source artistic license
  http://www.opensource.org/licenses/artistic-license.php
*/


###########################################################################
###### INSTALLATION #######################################################
###########################################################################
## The  Following options must                 ############################
## be filled out in order for the installer    ############################
## and control panel to work properly          ############################
###########################################################################
###########################################################################
# When editing the following to values, be certain to put the information #
# between the two single quotes ( $inst_url = 'http://theprawn.com/chat'; #
# If you are updating a previous installation of ChatRS, you do NOT need  #
# to fill these fields.  They are only necessary if you have no settings. #
###########################################################################
$inst_url = '';      // Location of the chat without trailing slash       #
                             // e.g. http://theprawn.com/chat             #
$inst_pss = '';      // Your desired password for logging in to           #
                             // the control panel. May be changed later.  #
###########################################################################
## IMPORTANT: DO NOT EDIT BELOW THIS LINE      ############################
###########################################################################

error_reporting(8);
$score = 0;
function INSTFILE($insfl,$instxt,$insatr) {
	if ( $handle = fopen($insfl,"w+") ) {
		echo "<div>$insfl created successfully. ";
	} else {
		echo "<div>$insfl could not be created. ";
	}
	if ( fwrite($handle,$instxt) ) {
		echo "<strong>Defaults successfully written to $insfl</strong></div>";
	} else {
		echo "$insfl could not be written to successfully.</div>";
	}
	fclose($handle);
	if ( chmod($insfl,$insatr) ) {
		echo "CHMOD $insfl successful. ";
	} else {
		echo "CHMOD $insfl unsuccessful. ";
	}
	echo "Permissions are: <strong>".(substr(sprintf("%o",fileperms($insfl)),3))."</strong>. ";
	unset($handle);
}
@include "settings.php";
if ( !isset($siteurl) || $siteurl === '' || $sitepass === '' ) {
  if ( $inst_url === '' || $inst_pss === '' ) {
    die("Please open install.php in a text editor and edit the two initial settings.  Then, reload this page to continue with the installation.");
  } else {
    $siteurl = $inst_url;
    $sitepass = $inst_pss;
    $tempset = "<?php\r\n";
    $tempset .= '$sitepass = \''.$sitepass.'\';'."\r\n";
    $tempset .= '$siteurl = \''.$siteurl.'\';'."\r\n";
    $tempset .= "?>";
    $handle = fopen('settings.php','w+');
    fwrite($handle,$tempset);
    fclose($handle);
    unset($handle);
  }
}

if ( !isset($_GET['install']) && !is_file('text_parse.php') ) {
	echo "<strong>It appears you are installing this chat for the first time.</strong><br />Please ensure the directory you are installing to has it's attributes changed to 777 so that the installer may create all necessary files.";
	echo '<br /><form method="get" action="install.php"><input type="submit" name="install" value="Install" /></form>';
	return;
} elseif ( !isset($_GET['install']) ) {
	echo "<strong>It appears you have previously installed this chat.</strong><br />Your settings will be preserved through this update, but be sure to run the settings update in the next step as it will ensure your settings file is in good repair.";
	echo '<br /><form method="get" action="install.php"><input type="submit" name="install" value="Install" /></form>';
	return;
}

#INDEX.PHP
$def_index = <<<text
<?php
/*
  Chat-RS "Chat in RetroStyle"
  A SIMPLE CHAT PROGRAM for pull/not push
  http://www.theprawn.com/chat/chatrs-latest.zip
  
  This chat source is provided exclusively 
  under an open source artistic license
  http://www.opensource.org/licenses/artistic-license.php
  
  Five Latest Changes
  - "Rapid Data File" is locked using a lock file to prevent screen clearing
  - Links inverse of poster, rather than system default
  - New time function that accurately accounts for server and user
  - Sidebar now shows user time preferences
  - Data split into two files -- Rapid Data File and History Archive.
    Chat is now much, much faster
*/

define('AUTHORNAME','Allen Day');
define('AUTHORADDR','http://www.theprawn.com/fr/?mail');
require_once "settings.php";
#Error Reporting Handling
error_reporting(\$erep);
require_once "color_gen.php"; 
\$version = "v 1.5.2";  // System version number
\$versiondt = '2004-11-04';  // System version date
\$uversiondt = makeTime(\$u_zone,\$u_dst,filemtime("index.php")); //Last upload/update dtg
#\$uversionoff = date("Z",\$uversiondt);
#\$uversionoffout = \$def_u_zone;
#\$uversiondt = \$uversiondt - \$uversionoff + 3600 * \$def_u_zone;
\$uversiondt = date("d F Y h:ia", \$uversiondt);
ob_start();
# include header/defaults
require_once "imports.php";
require_once "text_parse.php";
require_once "header.php";
if ( isset(\$kill) && \$kill == 1 ) {
  return;
}

# Check to see if the chat should be loaded as history or active chat
if ( isset(\$_GET['go']) && \$_GET['go'] == 'history' ) {
# Initiate search, if used // It's slow on large data files.
# All in all, the search feature is very rudimentary . . .
  if ( isset(\$_GET['find']) ) {
    \$find_in = file(\$hstfile);
    \$find = \$_GET['find'];
    \$resnum = 0;
    echo '<body id="history">';
    echo "<p class=\\"hst_navt\\"><a href=\\"?go=history\\">".HstLkTxt."</a></p>";
    foreach ( \$find_in as \$num => \$post ) {
      \$text = preg_split('/\\\\s:\\\\s/', \$post);
      if ( strpos(\$text[5],\$find) ) {
        \$resnum++;
        \$name = stripslashes(\$text[4]);
        \$text = stripslashes(\$text[5]);
        echo "<div class=\\"hist\\"><strong><a href=\\"?go=history&fm=\$num\\">\$resnum</a></strong> -- <strong>\$name:</strong> \$text</div>";
      }
    }
    echo "<p class=\\"hst_navb\\"><a href=\\"?go=history\\">".HstLkTxt."</a></p>";
  } else {

# Establish navigation; num & from may be altered in the URL.
# I probably should provide an idiot proof interface for this.
    \$more_from = \$from - \$num;
    \$less_from = \$from + \$num;
    echo ( '<p class="hst_navt"><a href="?' . \$action_do . '">'.HstLkTxt.'</a> | ' );
    echo ('<a href="?' . \$action_do . '&go=history&nm=' . \$num . '&fm=' . \$more_from . '">'.HstLkBak.'</a>' );
    echo (' | <a href="?' . \$action_do . '&go=history&nm=' . \$num . '&fm=' . \$less_from . '">'.HstLkFor.'</a></p>' );
    echo ( '<div><form style="text-align: center;" action="./?'.\$action_do.'" method="get"><input type="hidden" name="go" value="history" /><input type="text" name="find" /><input type="submit" value="'.HstBnTxt.'" /></form></div>' );
    
# Data and history are stored independently.
# The history file can get huge, this slowed chatting significantly.
# Speed is now improved, but the method for getting and re-writing data is buggy
# A busy chat session, often php can't keep up and the data file gets cleared.
# History remains intact, but it's still annoying.
    \$input = file(\$hstfile);
    \$output = array_slice(\$input,\$from,\$num);
    
### # # # # # # # # # # ###
### Parse and print text ##
### # # # # # # # # # # ###
    
    for ( \$n=0; \$n < count(\$output); \$n++ ) {
      parseText(\$output[\$n]);
    }
# History Footer
    echo ( '<p class="Hst_navb"><a href="?' . \$action_do . '">'.HstLkCht.'</a> | ' );
    echo ('<a href="?' . \$action_do . '&go=history&nm=' . \$num . '&fm=' . \$more_from . '">'.HstLkBak.'</a>' );
    echo (' | <a href="?' . \$action_do . '&go=history&nm=' . \$num . '&fm=' . \$less_from . '">'.HstLkFor.'</a>' );
    echo ( '</p>' );
  }
} else {
  echo '<body id="index" onload="ol()">';
  if ( isset(\$dobeep) && \$dobeep == 1 ) {
    echo '<embed src="'.\$def_lurkvol.'" hidden="true" width="0" height="0" loop="false" autostart="true" />';
  }

# then process cookies  
# Check the data file
# Be sure to chmod the file to 666 before using chat.
# I'll automate that, later.
  if ( !is_file(\$file) ) {
    \$tempsetup = time();
    \$tempsetup.= file_get_contents('http://www.theprawn.com/chat/instxt');
    if ( \$handle = fopen(\$file,"at") ) {
      if ( fwrite(\$handle,\$tempsetup) ) { \$sysout .= "<div>".ErrDatTr."</div>"; } else { \$sysout .= "<div>".ErrDatFa."</div>"; }
      fclose(\$handle);
      chmod(\$file,0666);
    } else {
      \$sysout .= "<div>".ErrDatNw."</div>";
    }
  }
  
# INPUT-TO-FILE PROCESSOR
# Check for user name; Need to fix it so spaces are not a valid option.
# Check also for text; Error messages can be edited here, I may move them to config
  if ( \$strp_meth == 0 ) {
    if ( isset(\$uword) ) { \$uword = htmlentities(\$uword); }
    \$ffamily = htmlentities(\$ffamily);
    \$fsize = htmlentities(\$fsize);
  } elseif ( \$strp_meth == 1 ) {
    //\$uname = strip_tags(\$uname);
    if ( isset(\$uword) ) { \$uword = strip_tags(\$uword); }
    \$ffamily = strip_tags(\$ffamily);
    \$fsize = strip_tags(\$fsize);
  }

# Set output to 1; will be disabled if text not properly formatted
  
# # # # # # # # # # # # # # # # # #
#~~PROCESS FOR INTERNAL COMMANDS~~#
#   SYSTEM MESSAGES ACCORDINGLY   #
# # # # # # # # # # # # # # # # # #
  
# Lurk setup
  if ( isset(\$refresh_do) && is_numeric(\$refresh_do) ) {
    \$dateString = "jS M, Y g:i:s A";
    if ( isset(\$u_dst) && \$u_dst != 0 ) {
      \$do_date = date(\$dateString,makeTime(\$u_zone,1,0));
    } else {
      \$do_date = date(\$dateString,makeTime(\$u_zone,0,0));
    }
    \$sysout .= locals(PanLrkGo,array(\$refresh_do,\$do_date));
    if ( isset(\$_POST['postrefresh']) ) {
      \$sysout .= "<p>".PanLrkOn."</p>";
    }
#    \$do_write = 0;
  }
  if ( isset(\$refresh_do) && is_numeric(\$refresh_do) && ( !isset(\$_POST['uword']) || strlen(\$uword) <= 1 ) ) {
    \$do_write=0;
  } elseif ( isset(\$_GET['sv']) && isset(\$_SERVER['HTTP_REFERER']) ) {
    \$sysout .= "<p>".locals(PanSavDo,array(PanSavNm))."</p>";
    \$do_write = 0;
  } elseif ( !isset(\$_POST['postrefresh']) && ( !isset(\$refresh_do) || !is_numeric(\$refresh_do) ) ) {
    if ( isset(\$bwelcome) && strlen(\$bwelcome) > 0 ) {
      \$sysout .= "<p><strong>".\$bwelcome."</strong></p>";
    }
    if ( isset(\$bannounce) && strlen(\$bannounce) > 0 ) {
      \$sysout .= "<p><em>".\$bannounce."</em></p>";
    }
    \$do_write = 0;
  } elseif ( preg_match('/^([:]+|[\\/])[\\\\s]*\$/im',\$uword ) ) {
    \$sysout .= '<p>'.ErrComCh.'</p>';
    \$do_write = 0;
  } elseif ( preg_match('/^\\//im', \$uword ) ) {
    if ( preg_match('/^[\\\\s]*\\/([^\\\\s]+)/im', \$uword, \$matches) ) {
      if ( \$use_comm == 1 ) {
        foreach ( \$s_commands as \$command => \$action ) {
          if ( strcasecmp(\$command, \$matches[1]) == 0 ) {
            \$sysout .= "\$action";
            \$comout = TRUE;
            \$do_write = 0;
          }
        }
        foreach ( \$s_tcommands as \$command => \$action ) {
          if ( strcasecmp(\$command, \$matches[1]) == 0 ) {
            \$uword = \$action;
            \$comout = TRUE;
          }
        } 
        if ( !array_search(strtolower(\$matches[1]),\$getsyscom) && 0 === preg_match('/^\\/me\\\\s.{2,}/im',\$uword) && \$comout !== TRUE ) {
          if ( preg_match('/^\\/me\\\\s*(?![\\\\w+])/im',\$uword ) ) {
            \$sysout .= '<p>'.ErrComMe.'</p>';
            \$do_write = 0;
          } else {
            \$sysout .= "<p>".locals(ErrComCm,array(\$matches[1]))."</p>";
            \$do_write = 0;
          }
        }
      }
    } elseif ( !isset(\$comout) || \$comout !== TRUE ) {
      \$sysout .= "<p>".ErrComNn."</p>";
      \$do_write = 0;
    }
  }
  if ( isset(\$_POST['postrefresh']) ) {
    if ( !isset(\$uname) || strlen(\$uname) < 1 ) {
      if ( !isset(\$uword) || strlen(\$uword) < 1 ) {
        \$sysout .= ("<p>".ErrInfNt."</p>");
      } else {
        \$sysout .= ("<p>".ErrInfNm."</p>");
      }
      \$do_write = 0;
    } elseif ( isset(\$s_resname[\$uname]) && ( !isset(\$s_blocklist[\$_SERVER['REMOTE_ADDR']]) && \$_SERVER['REMOTE_ADDR'] != \$siteaddr ) ) {
      \$sysout .= "<p>".locals(ErrInfLk,array(\$uname))."</p>";
      \$do_write = 0;
      \$uname = '';
/*    } elseif ( strstr(\$uname,'/') || strstr(\$uname,'\\\\') || strstr(\$uname,'"') || strstr(\$uname,"'") ) {
      \$sysout .= "<p>User names may not contain \\", ', / or \\.</p>";
      \$uname = '';
      \$do_write = 0; */
    } elseif ( (! preg_match('/^(?:#)?[a-z0-9]+\$/im',\$fcolor)) || (! preg_match('/^(?:#)?[a-z0-9]+\$/im',\$bcolor)) ) {
      \$sysout .= "<p>".ErrClrPr." ";
      if ( (! preg_match('/^(?:#)?[a-z0-9]+\$/im',\$fcolor)) ) {
        \$sysout .= PanClrFr."</p>";
      }
      if ( (! preg_match('/^(?:#)?[a-z0-9]+\$/im',\$bcolor)) ) {
        \$sysout .= PanClrBk."</p>";
      }
      \$do_write = 0;
    } elseif ( ! preg_match('/^[a-z -]+\$/im',\$ffamily) ) {
      \$sysout .= "<p>".ErrClrFt."</p>";
      \$do_write = 0;
    } elseif ( ! preg_match('/^([0-9.-]{1,}((cm|mm|in|pt|pc|px|em|ex)|[%]))|(larger|smaller|xx-small|x-small|small|medium|large|x-large|xx-large)/im',\$fsize) ) {
      \$sysout .= '<p>'.ErrSzPre.'<br /><strong>'.ErrSzAbs.':</strong> xx-small, x-small, small, medium, large, x-large, xx-large<br /><strong>'.ErrSzRel.':</strong> smaller, larger<br /><strong>'.ErrSzLen.':</strong><br /><strong>'.ErrSzAun.'</strong>: cm, mm, in, pt, pc, px; <Strong>'.ErrSzRun.'</strong>: em, ex. (10px; 10em)<br /><strong>'.ErrSzPer.': </strong> ( 75% )</p>';
      \$do_write = 0;
    } elseif ( preg_match('/^(([ ])|(&nbsp;))*\$/im', \$uword) ) {
      \$sysout .= ("<p>".MsgWrtRf."</p>");
      \$do_write = 0;
    }
  }
  if ( isset(\$do_write) && \$do_write === 1 && isset(\$_POST['postrefresh']) && strlen(\$uword) > 0 ) {
    \$time = time();
    \$postdat = "\$time : \$fcolor : \$bcolor : \$ffamily : \$uname : \$uword : \$_SERVER[REMOTE_ADDR]\\n";
    # Use lock file to prevent overwriting of data
    # Without the lock, it's possible for rapid chatting to clear the active file.
    # (Though the history  will remain intact
    # The lock system will not work on win32 servers running a php version prior to 5
    # as it does not support the usleep function.
//    if ( ( !stristr(\$_SERVER['SERVER_SOFTWARE'],'windows') && !stristr(\$_SERVER['SERVER_SOFTWARE'],'win32') ) || phpversion() >= 5 ) {
      \$lockfile = "\$file.lock";
      \$lock = fopen(\$lockfile,"x+");
      while ( FALSE === \$lock ) {
        microdelay(.25);
        \$lock = @fopen(\$lockfile,"x+");
      }
//    }
    \$oldfiledat = file("\$file");
    \$oldfiledat = array_reverse(\$oldfiledat);
    \$oldfiledat[] = \$postdat;
    \$oldfiledat = array_slice(array_reverse(\$oldfiledat),0,\$prnt_num);
    \$oldfiledat = implode('',\$oldfiledat);
    // These messages are not localized; they're for installation trouble shooting, users shouldn't see them.
    if ( !\$handle = fopen(\$file,"wt") ) {
      \$sysout.="<p>The data file could not be secured. 255</p>";
    }
    flock(\$handle, LOCK_EX);
    if ( !fwrite(\$handle,\$oldfiledat) ) {
      \$sysout.="<p>There was a problem writing to the data file. 259</p>";
    }
    flock(\$handle, LOCK_UN);
    fclose(\$handle);
    unset(\$handle);
    if ( !\$handle = fopen(\$hstfile,"at") ) {
      \$sysout.="<p>The history file could not be secured. 265</p>";
    }
    if ( !fwrite(\$handle,\$postdat) ) {
      \$sysout.="<p>There was a problem writing to the history file. 268</p>";
    }
    fclose(\$handle);
    unset(\$handle);
    \$sysout .= "<p>".MsgWrtDo."</p>";
    unlink(\$lockfile);
  }
  if ( \$bunews === 1 && isset(\$sysout) ) {
    echo '<div class="report">';
      echo \$sysout;
    echo '</div>';
  }
  require_once "panel.php";
# Read from file to output transcript.
# The whole chat is read, then the array is sliced to ~n.
# Need to pull fewer lines from the text file. Somehow.

  \$input = file(\$file);
  \$output = array_slice(\$input,0,\$num);
  \$output = array_reverse(\$output);
  
  if ( \$print_txt_do === 1 ) {
    for ( \$n=count(\$output)-1; \$n >= 0; \$n-- ) {
      parseText(\$output[\$n]); //require "text_parse.php";
    }
  }
  if ( \$print_r_do > 0 || (isset(\$_GET['debug']) && isset(\$_GET['pass'])) ) {
    echo "<pre>";
    echo "POST\\n";
    print_r(\$_POST);
    echo "GET\\n";
    print_r(\$_GET);
    echo "COOKIE\\n";
    print_r(\$_COOKIE["\$cname"]);
    echo "</pre>";
  }
  if ( \$print_r_do > 1 || (isset(\$_GET['debug']) && isset(\$_GET['past'])) ) {
    echo "<pre>";
    echo "VAR DUMP\\n";
    var_dump(\$GLOBALS);
    echo "<pre>";
  }
}
echo <<<foot
<div id="footer" class="report"><a href="?\$action_do&amp;go=about">\$version</a></div>
</body>
</html>
foot;
ob_end_flush();
?>
text;

#IMPORTS.PHP
$def_imports = <<<text
<?php
# Text Parser (very, very, very important)
include "s_commands.php";
include "s_tcommands.php";
include "s_replacements.php";
include "s_blocklist.php";
include "s_resname.php";
include "local.php";
?>
text;

#HEADER.PHP
$def_header = <<<text
<?php
echo <<<header
<!DOCTYPE html 
  PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="author" content="Allen Day, http://www.theprawn.com" />
<title>\$btitle</title>
header;
# If refresh enabled, output accordingly
if ( \$urefresh == 1 ) {
	if ( isset(\$refresh_do) && \$refresh_do > 0 ) {
	  if ( FALSE != stristr(\$_SERVER['PHP_SELF'],'sidebar') ) {
		  echo ( '<META HTTP-EQUIV="Refresh" CONTENT="' . \$refresh_do . '; URL=./sidebar.php?'. \$action_do .'" />' . "\\r\\n" );
		} else {
		  echo ( '<META HTTP-EQUIV="Refresh" CONTENT="' . \$refresh_do . '; URL=./?'. \$action_do .'" />' . "\\r\\n" );
		}
	}
}
# Determine whether to use user colors or default colors
# If user colors are not set, admin default will be used
# user control may be disabled from within config.php
echo <<<header

<style type="text/css">
body { font-family: "\$ffamily"; color: \$fgcolor; font-size: \$fsize; background: \$bgcolor; margin: 0; padding: 0; }
a { color: \$lkcolor; background: \$lkbcolor; text-decoration: none; border-bottom: dotted 1px \$lkcolor; }
p.post { padding: 4px; margin: 0 0 \${p_marg}px; }
div#control { color: \$cpan_f; background: \$cpan_b; border: solid \$brdrcl; border-width: 1px 0 1px 0; margin-bottom: 10px; padding: .2em; font-family: "\$cpan_t"; font-size: \${cpan_z}px; }
div#control div { text-align: center; padding: 0; margin: .2em 0 .2em 0; }
span.boxes input { vertical-align: middle; }
input,select,option { font-family: "\$ffamily"; color: \$fcolor; background: \$bcolor; border-style: \$brdrst; border-width: \${brdrsz}px; border-color: \$brdrcl; }
input.set { width: 10%; }
input.sm { width: 20px; }
div#footer { text-align: center; border: none; /* border-size: \${brdrsz}px 0 0 0; border: \$brdrcl \$brdrst; */ }
span.uline { text-decoration: underline; }
div.center { text-align: center; }
div.report { margin: .2em 20% .2em 20%; padding: 2px; text-align: center; font-size: 11px !important; font-family: "\$cpan_t"; border-style: \$brdrst; border-width: \${brdrsz}px; border-color: \$brdrcl; }
div.report p { margin: .2em; padding: 2px; }
div.report a { color: #fff; background: none; }
div#syshelp { text-align: justify; }
div#quote { font-style: italic; font-size: .85em; margin: 1em 20% 0 20%; }
span.time { font-size: .5em; font-family: "small fonts",verdana,"sans-serif"; margin-right: 1em; }
body#sidebar { font-size: 11px; }
body#sidebar div#sidebar_head { text-align: center; font-size: .75em; font-family: verdana; border-bottom: solid 1px #ccc; }
body#sidebar div#sidebar_head a { background: none; color: \$lkcolor; background: \$lkbcolor; }body#sidebar p.post { margin-bottom: 2px; }
body#sidebar span.time { font-size: 1em; font-family: verdana; }
p.hst_navt { background: \$cpan_b; border-bottom: \$brdrst \${brdrsz}px \$brdrcl; font-weight: 900; text-align: center; padding: .5em; padding: .2em; }
p.hst_navb { background: \$cpan_b; border-bottom: \$brdrst \${brdrsz}px \$brdrcl; border-top: \$brdrst \${brdrsz}px \$brdrcl; font-weight: 900; text-align: center; padding: .5em; padding: .2em; }
p.hst_nav a { color: \$cpan_f; background: \$cpan_b; font-family: "\$cpan_t"; }
div.hist { border-bottom: \$brdrst \$brdrcl \${brdrsz}px; margin: .2em; padding: .2em; }
</style>
<script type="text/javascript">
function ol() { document.getElementById("uword").focus(); }
</script>
</head>
header;
require "syscomm.php";
if ( \$ublist == 1 && isset(\$s_blocklist[\$_SERVER['REMOTE_ADDR']]) && \$_SERVER['REMOTE_ADDR'] != \$siteaddr ) {
\$uaddr = \$_SERVER['REMOTE_ADDR'];
	echo <<<blocked
\$uaddr<br />
You have been denied access to this chat.<br />
Reason Given: \$s_blocklist[\$uaddr]<br />
If you believe this to be in error, contact <a href="mailto:\$siteeml?subject=blocked&amp;body=\\nMy%20IP:%20\$uaddr">the administrator</a>.
blocked;
	\$kill = 1;
} elseif ( \$ublist == 2 && !isset(\$s_blocklist[\$_SERVER['REMOTE_ADDR']]) && \$_SERVER['REMOTE_ADDR'] != \$siteaddr ) {
\$uaddr = \$_SERVER['REMOTE_ADDR'];
echo <<<blocked
\$uaddr<br />
\$ubreas<br />
If you believe this to be in error, contact <a href="mailto:\$siteeml?subject=blocked&amp;body=\\nMy%20IP:%20\$uaddr">the administrator</a>.
blocked;
	\$kill = 1;
}
?>
text;

#QUOTES.PHP
$def_quotes = <<<text
<html>
	<head>
		<title>Add a Quote</title>
		<style type="text/css">
		td	{ border-bottom: solid 1px #000; padding: .5em; margin-bottom: .5em; }
		</style>
	</head>
<body onload="document.quoting.new_quote.focus()">
<?php
# Print cookie file and allow for deletion
require "settings.php";
error_reporting(\$erep);
echo <<<quote
<a href="index.php">Back to Chat</a><hr />
<h1>Add a Quote</h1>
<p>
<form action="quotes.php" method="post" name="quoting">
	<strong>Quote</strong> <input type="text" name="new_quote" size="50" />
	<strong>Author</strong> <input type="text" name="new_auth" size="20" />
	<input type="submit" name="add_quote" value="Add Quote" />
	</form></p>
quote;
session_start();
if ( isset(\$_POST['edtpass']) && \$_POST['edtpass'] == \$sitepass ) {
	\$_SESSION['edtpass'] = \$_POST['edtpass'];
}
if ( isset(\$_POST['add_quote']) ) {
	if ( str_word_count(\$_POST['new_quote']) > 1 && str_word_count(\$_POST['new_auth']) > 0 ) {
		if ( !file_exists(\$qfile) ) {
			\$handle = fopen(\$qfile,"xt");
			fclose(\$handle);
		}
		\$old_quotes = file(\$qfile);
		\$old_quotes = implode('',\$old_quotes);
		\$new_quotes = \$_POST['new_quote'] . ' -' . \$_POST['new_auth'] . "\\n" . \$old_quotes;
		\$new_quotes = stripslashes(\$new_quotes);
		\$handle = fopen(\$qfile,"r+t");
		fwrite(\$handle,"\$new_quotes");
		fclose(\$handle);
		\$new_quote = stripslashes(\$_POST['new_quote']);
		echo "Added <em>" . \$_POST['new_quote'] . "</em>";
	} else {
		echo "Please fill out <Strong>Quote</strong> and <strong>Author</strong> properly.";
	}
}
if ( isset(\$_SESSION['edtpass']) && \$_SESSION['edtpass'] == \$sitepass ) {
	if ( isset(\$_POST['quote']) && is_numeric(\$_POST['quote']) ) {
		\$quotes = file(\$qfile);
		unset(\$quotes[\$_POST['quote']]);
		\$quotes = implode('', \$quotes);
		if ( \$handle = fopen(\$qfile,'w+t') ) {
			if ( fwrite(\$handle,\$quotes) ) {
				echo "<p>Quotes file updated. Deleted quote \$_POST[quote]</p>";
				fclose(\$handle);
			} else {
				echo "<p>Failed to write to file. Quotes erased or last quote deleted.</p>";
			}
		} else {
			echo "<p>Failed to open quotes file.</p>";
		}
	}

	
	\$quotes = file(\$qfile);
	echo "<table><tr><th>Delete</th><th>Quote</th></tr>";
	function QDEL(\$line,\$words) {
		echo <<<quoted
<tr><td><input type="submit" name="quote" value="\$line" /></td><td>\$words</td></tr>
quoted;
	}
	echo '<form action="quotes.php" method="post">';
	foreach ( \$quotes as \$num => \$quote ) {
		QDEL(\$num,\$quote);
	}
	echo "</table>";
	echo '</form>';
} else {
/*	\$qn = array_rand(\$quotes);
	echo ('<div id="quote">' . \$quotes[\$qn] . "</div>\\r\\n" ); */
	echo <<<pass
<p>
<Strong>Administrative Interface: </strong>
<form action="quotes.php" method="post">
<input type="password" value="" name="edtpass" />
<input type="submit" />
</form>
</p>
pass;
}
# # #
# ADMIN USE ONLY
# # #
\$admin_print = 0;
if ( \$admin_print == 1 ) {
	echo "<pre>";
	print_r(\$quotes);
	echo "</pre>";
}

?>
text;

#SIDEBAR.PHP
$def_sidebar = <<<text
<?php
# http://www.theprawn.com
require_once "settings.php";
error_reporting("\$erep");
require_once "color_gen.php";
require "imports.php";
require_once "text_parse.php";
# For the side bar, set refresh rate for auto-refresh
if ( isset(\$_GET['rf']) && is_numeric(\$_GET['rf']) ) {
  \$refresh_do = \$_GET['rf'];
} else {
  \$refresh_do = \$sideRate;
}
ob_start();
# include header/defaults
require "header.php";
if ( isset(\$kill) && \$kill == 1 ) {
	return;
}

echo '<body id="sidebar">';
# Check the data file
\$dateString = "jS M, Y g:i:s A";
if ( isset(\$u_dst) && \$u_dst != 0 ) {
  \$do_date = date(\$dateString,makeTime(\$u_zone,1,0));
} else {
  \$do_date = date(\$dateString,makeTime(\$u_zone,0,0));
}
if ( strrpos(\$_SERVER['HTTP_USER_AGENT'], "Internet Explorer") != 'FALSE' ) {
  echo '<div id="sidebar_head">'.\$do_date.'<br />'.locals(SbRefMsg,array(\$refresh_do)).'<br />';
  echo '<a href="sidebar.php?'.\$action_do.'" target="_self">'.SbRefTxt.'</a> | <a href="./?'.\$action_do.'" target="_main" accesskey="c">'.SbRefCht.'</a> | <a href="./?go=history&'.\$action_do.'" target="_main">'.SbRefHst.'</a><br /></div>';
} else {
  echo '<div id="sidebar_head">'.\$do_date.'<br />'.locals(SbRefMsg,array(\$refresh_do)).'<br />';
  echo '<a href="sidebar.php?'.\$action_do.'" target="_self">'.SbRefTxt.'</a> | <a href="./?'.\$action_do.'" target="_content" accesskey="c">'.SbRefCht.'</a> | <a href="/?go=history&'.\$action_do.'" target="_main">'.SbRefHst.'</a><br /></div>';
}
\$num = \$num / 2;
# Read from file to output transcript.
# The whole chat is read, then the array is sliced to ~n.
# Need to pull fewer lines from the text file. Somehow.
\$input = file(\$file);
\$output = array_slice(\$input,0,\$num);

### # # # # # # # # # # ###
### Parse and print text ##
### # # # # # # # # # # ###

for ( \$n=0; \$n < count(\$output); \$n++ ) {
	parseText(\$output[\$n]);
}
#END
ob_end_flush();
?>
</body>
</html>
text;

#CONFIG.PHP
$def_config = <<<text
<?php
error_reporting(2048);
if ( isset(\$_POST['save_do']) ) {
  \$do_save_do = 1;
  unset(\$_POST['save_do']);
}
if ( is_file("settings.php") ) {
  require "settings.php";
  if ( isset(\$erep) ) {
    error_reporting(\$erep);
  }
}
if ( is_file('settings.php') ) {
  \$settings = file("settings.php");
}
\$head = array_shift(\$settings);
\$trailer = array_pop(\$settings);
\$fnm = 0;
session_start();
if ( isset(\$_POST['userpass']) && isset(\$sitepass) && \$_POST['userpass'] == \$sitepass ) {
  if ( !isset(\$sitepass) && !isset(\$_SESSION['edtpass']) || isset(\$_POST['userpass']) ) {
    \$_SESSION['edtpass'] = \$_POST['userpass'];
    echo 'You have logged in successfully.';
  }
}

if ( isset(\$_GET['logout']) == 1 ) {
  unset(\$_SESSION['edtpass']);
  echo 'You have logged out successfully.  <a href="index.php">Return to chat</a> or <a href="config.php">Log in</a>';
  return;
}

if ( isset(\$_SESSION['edtpass']) && \$_SESSION['edtpass'] == \$sitepass || !isset(\$sitepass) || \$siteaddr === \$_SERVER['REMOTE_ADDR'] ) {
  for ( \$n=0; \$n < count(\$settings); \$n++ ) {
    preg_match('/^\\$(.*?) = [\\'"]?(.*?)[\\'"]?;/im',\$settings[\$n],\$set_setting);
    if ( isset(\$set_setting[1]) ) { \$setting[\$n]['option'] = \$set_setting[1]; }
    if ( isset(\$set_setting[2]) ) { \$setting[\$n]['value'] = \$set_setting[2]; }
  }

  if ( isset(\$do_save_do) && \$do_save_do == 1 ) {
    if ( isset(\$_GET['save']) ) {
      foreach ( \$_POST as \$name => \$value ) {
        if ( (\$name != 'PHPSESSID') ) {
          if ( is_numeric(\$value) ) {
            \$output[] = '\$' . \$name . " = " . \$value . ";";
          } else {
            \$output[] = '\$' . \$name . " = '" . \$value . "';";
          }
        }
      }
    } else {
      for ( \$n=0; \$n < count(\$_POST); \$n++ ) {
        \$setting[\$n]['value'] = \$_POST[\$n];
      }
      for ( \$n=0; \$n < count(\$setting); \$n++ ) {
        if ( is_numeric(\$setting[\$n]['value']) ) {
          \$output[] = '\$' . \$setting[\$n]['option'] . " = " . \$setting[\$n]['value'] . ";";
        } else {
          \$output[] = '\$' . \$setting[\$n]['option'] . " = '" . \$setting[\$n]['value'] . "';";
        }
      }
    }
    \$output = implode("\\n",\$output);
    \$outputf = "<?php\\n" . \$output . "\\n?>";
    \$handle = fopen('settings.php',"w+t");
    fwrite(\$handle,\$outputf);
    fclose(\$handle);
    echo 'Settings saved. <a href="config.php">Continue</a><br />';
    return;
  }
  function TOPMENU(\$page='Configuration') {
    \$menuopts = array ('Configuration' => 'config.php','Commands' => 'config.php?go=rep&cat=1','Shortcuts' => 'config.php?go=rep&cat=0','Replacements' => 'config.php?go=rep&cat=2','Blocklist' => 'config.php?go=rep&cat=3','Reserved Names' => 'config.php?go=rep&cat=4','Repair' => 'config.php?go=repair', 'Reinstall' => 'install.php', 'Logout' => 'config.php?logout=1');
    echo "| ";
    foreach ( \$menuopts as \$active => \$url ) {
      if (\$page != \$active) {
        echo "<a href=\\"\$url\\">\$active</a> | ";
      } else {
        echo "\$active | ";
      }
    }
    echo "Your IP: ".\$_SERVER['REMOTE_ADDR']."<hr />";
  }

  if ( !isset(\$_GET['go']) ) {
    function STXT(\$fnm,\$formdata) {
      if ( isset(\$formdata[3]) && is_numeric(\$formdata[3])) {
        echo "<p><strong>\$formdata[1]: </strong><input type=\\"text\\" value=\\"".stripslashes(\$formdata[0])."\\" name=\\"\$fnm\\" maxlength=\\"\$formdata[3]\\" size=\\"\$formdata[3]\\" /><br />";
      } else {
        echo "<p><strong>\$formdata[1]: </strong><input type=\\"text\\" value=\\"".stripslashes(\$formdata[0])."\\" name=\\"\$fnm\\" /><br />";
      }
      echo '<em style="font-size: .8em;">' . \$formdata[2] . '</em>';
      echo '</p>';
      \$fnm++;
      return(\$fnm);
    }

    function SSEL(\$fnm,\$formdata,\$opts=array('Yes' => '1','No' => '0')) {
      echo "<p><strong>\$formdata[1]: </strong><select name=\\"\$fnm\\">";
      foreach ( \$opts as \$opt1 => \$opt2 ) {
        if ( \$formdata[0] === \$opt2 ) {
          echo "<option value=\\"\$opt2\\" SELECTED>\$opt1</option>";
        } else {
          echo "<option value=\\"\$opt2\\">\$opt1</option>";
        }
      }
      echo "</select><br />\\n";
      echo '<em style="font-size: .8em;">' . \$formdata[2] . '</em>';
      echo '</p>';
      \$fnm++;
      return(\$fnm);
    }

    if ( isset(\$_GET['go']) && \$_GET['go'] == 'repair' ) {
      echo '<form method="post" action="config.php?go=repair">';
    } else {
      echo '<form method="post" action="config.php">';
    }
    echo '<h1>Site/Administrative Info</h1>';
    TOPMENU();
    \$formdata = array(\$setting[\$fnm]['value'],'Chat Title','The chat title, which will appear in the browser\\'s title bar.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Admin IP Address','If you specify your IP address, you will automatically be logged into the control panel.  Also, your IP address-used to override reserved name limitations and other IP-limited features.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Admin Email','Your e-mail address, allowing your users to contact you.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Admin Password','Password to access this and all other control panels.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Chat URL','Chat URL is important -- cookie management will not work properly without this filled in.  Should be http://domain.com/director/names .  Do not place a final slash at the end.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Data File','File that recent chatter will be stored in.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'History File','File that chat history will be stored in.   May also be used to start a new file; old will not be deleted.');
    \$fnm = STXT(\$fnm,\$formdata);
    

    echo '<hr /><h2>System Text</h2>' . "\\n";
    
    \$formdata = array(\$setting[\$fnm]['value'],'System Chatter','Show news, updates and general information above the control panel','1');
    \$fnm = SSEL(\$fnm,\$formdata);
    
    \$formdata = array(\$setting[\$fnm]['value'],'Welcome Message','Welcome users upon entering the chat','Welcome to \$btitle');
    \$fnm = STXT(\$fnm,\$formdata);
    
    \$formdata = array(\$setting[\$fnm]['value'],'Announcements','Enter your news/announcements here','');
    \$fnm = STXT(\$fnm,\$formdata);

    echo '<hr /><h2>System Options (enable/disable features)</h2>' . "\\n";

    \$formdata = array(\$setting[\$fnm]['value'],'Message Number','Number of messages to be displayed on the page and in history.','3');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'HTML Strip Method','How to handle HTML tags in posts.  They may be stripped from the text or displayed; html tags will not be parsed as html.');
    \$opts = array ( 'Display: Convert to entities' => '0', 'Delete: Strip tag traces from text' => '1' );
    \$fnm = SSEL(\$fnm,\$formdata,\$opts);

    \$formdata = array(\$setting[\$fnm]['value'],'Enable Blacklist','This will allow you to ban users (by IP) or limit the chat only to specific users, blocking all who are not on the list.  To edit the list, click "commands" in the configuration panel then select "s_blocklist".  Warning: Listing an IP may block/allow multiple users if they are on a LAN and are identified as the same address.');
    \$opts = array ( 'Allow All Users' => '0', 'Block Specified Users' => '1', 'Allow Only Specified Users' => '2' );
    \$fnm = SSEL(\$fnm,\$formdata,\$opts);

    \$formdata = array(\$setting[\$fnm]['value'],'Private Chat Reason','If you have "Allow only specified users" selected, this will be provided as the reason for denial.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Use Cookies','Use cookies to store user data between browser sessions; user may enable/disable their personal cookie.');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Cookie Name','The name given to the cookie your users receive.  Changing the cookie name will lose data saved with a previous name.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Days to store cookie','How long the cookie should be retained by the user\\'s browser before automatically deleted.  Cookies are re-set each time a post is made, so users will not lose their data at this interval unless they are away for that time.','3');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Use Quotes','Enable the quote feature on the website; if enabled, a user may toggle display of a random quote on the bottom of the control panel.');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Quote File','File to use for quote function.  If you wish to use your own quotes, the file need only be a plain text file with one quote per line.  If file does not exist, it will be created when a quote is added via ?go=quotes.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Use Time Stamp','Enable display of a time stamp by text. May be toggled on/off by user. Also present in sidebar.');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Use Refresh','Allow user to set the chat to Lurk mode, auto refreshing ever ~n seconds.  To save bandwidth, it automatically shuts off after 30 minutes.');
    \$fnm = SSEL(\$fnm,\$formdata);
    
    \$formdata = array(\$setting[\$fnm]['value'],'Beep on New Message','Place the url of a sound file here to allow users to be notified of new messages while in lurk mode.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Show Save Link','Display a link that may be bookmarked to save settings for easy recall.  Cookie takes priority over save/restore.');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Show History Link','Display a link to the chat history.  Chat history is preserved indefinitely.');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Show Help Link','Show a link to the help text');
    \$fnm = SSEL(\$fnm,\$formdata);
    
    \$formdata = array(\$setting[\$fnm]['value'],'Show sidebar link','Show sidebar link in main control panel, rather than just in help.');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Refresh Rate','Number of seconds between sidebar refreshes');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Use Commands','Use commands in form of /command.  May be configured via the commands/replacements page.');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Use Emphasis','Allows use of *, _ and / for bold, underlined and italic text.');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Make Links Clickable','');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Protect E-mail','With this option you can mangle e-mail addresses (admin@addr.com would become admin @ addr.com), hide them (will be replaced with (e-mail hidden), or do nothing.');
    \$opts = array('Do Nothing' => '0', 'Mangle Address' => '1', 'Hide Address' => '2');
    \$fnm = SSEL(\$fnm,\$formdata,\$opts);
    
    \$formdata = array(\$setting[\$fnm]['value'],'Shorten URL\\'s','You may replace URL\\'s with a shorter standard blob of text.  Using <strong>URL..</strong> will preserve the original URL as the link text.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Use Search Markup','Markup search querries in chat in form of ?word for dictionary and ?[query] for google.');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Enable Word Filter','Enable auto-replacement of words. Filters may be configured via edit commands/replacements interface.');
    \$fnm = SSEL(\$fnm,\$formdata);
    
    \$formdata = array(\$setting[\$fnm]['value'],'Allow Filter Override','May the user override the word filtering by beginning a line with a colon?');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Allow User Fonts','Allow users to post text with their own font family and colors.');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Color method','Whether default color method should be manual (enter hex/color values) or auto (select form a list).');
    \$opts = array('Selectable List' => 'auto','Manual Entry' => 'manual');
    \$fnm = SSEL(\$fnm,\$formdata,\$opts);

    \$formdata = array(\$setting[\$fnm]['value'],'User Toggle Color Method','Choose whether the user must use your default color method or if they may toggle between the two at their convenience.');
    \$fnm = SSEL(\$fnm,\$formdata);

    echo '<hr />';
    echo '<h2>Chat Look & Feel</h2>' . "\\n";

    \$formdata = array(\$setting[\$fnm]['value'],'Default Page Background','Master background color for chat and sidebar.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Default Page Foreground','Master foreground color for chat and sidebar.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Default Link Background','Master background color for links in chat and sidebar.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Default Link Foreground','Master foreground color for links in chat and sidebar.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Control Panel Background','Background color for chat control panel.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Control Panel Foreground','Foreground color for chat control panel.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Control Panel Font Family','Font family for control panel labels and input areas.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Control Panel Font Size','Font size for control panel labels and input areas.','5');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Border Style','Style of border for interface elements.');
    \$opts = array('none' => 'none', 'hidden' => 'hidden', 'dotted' => 'dotted', 'dashed' => 'dashed', 'solid' => 'solid', 'double' => 'double', 'groove' => 'groove', 'ridge' => 'ridge', 'inset' => 'inset', 'outset' => 'outset');
    \$fnm = SSEL(\$fnm,\$formdata,\$opts);

    \$formdata = array(\$setting[\$fnm]['value'],'Border Size','Size of border, in pixels.','2');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Border Color','Color of border for interface elements.  May be color name or hex value.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Pixels between posts','Number of pixels to place as spacer between posts.','2');
    \$fnm = STXT(\$fnm,\$formdata);

    echo '<hr /><h2>Default User Settings</h2>' . "\\n";

    \$formdata = array(\$setting[\$fnm]['value'],'Default User Name','If you wish to specify a default alias for users who haven\\'t entered data, this is it.  Will make it possible to make a list of random aliases at a later date.');
    \$fnm = STXT(\$fnm,\$formdata);
    
    \$formdata = array(\$setting[\$fnm]['value'],'Name Length','Maximum length of user name (30 is default)');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Default Time Zone','Time zone to use as default; applies to chat and sidebar.','3');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Default User Background','Default background color for user font settings');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Default User Foreground','Default foreground color user font settings.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Default User Font Family','Default font family for user font settings.');
    \$fnm = STXT(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Default User Font Size','Default font size; specify number and unit or relative size (small, smaller, etc.) as described in the help file for size settings.','10');
    \$fnm = STXT(\$fnm,\$formdata);

    echo '<hr /><h2>Debug Tools</h2><hr />' . "\\n";

    \$formdata = array(\$setting[\$fnm]['value'],'Display Chat Text','');
    \$fnm = SSEL(\$fnm,\$formdata);

    \$formdata = array(\$setting[\$fnm]['value'],'Print Arrays','');
    \$opts = array('NONE' => '0', 'COMMON' => '1', 'VARDUMP' => '2');
    \$fnm = SSEL(\$fnm,\$formdata,\$opts);

    \$formdata = array(\$setting[\$fnm]['value'],'Error Reporting','');
    \$opts = array('NONE' => '0', 'E_ERROR' => '1', 'E_WARNING' => '2', 'E_PARSE' => '4', 'E_NOTICE' => '8', 'E_CORE_ERROR' => '16', 'E_CORE_WARNING' => '32', 'E_COMPILE_ERROR' => '64', 'E_COMPILE_WARNING' => '128', 'E_USER_ERROR' => '256', 'E_USER_WARNING' => '512', 'E_USER_NOTICE' => '1024', 'E_ALL' => '2047', 'E_STRICT' => '2048');
    \$fnm = SSEL(\$fnm,\$formdata,\$opts);

    echo '<input type="submit" name="save_do" value="Save" />';
    echo '</form>' . "\\n";

  } elseif ( isset(\$_GET['go']) && \$_GET['go'] == 'rep' ) {
    \$repdist = array ('Shortcuts','Commands','Replacements','Blocklist','Reserved Names');
    echo "<h1>" . \$repdist[\$_GET['cat']] . " Configuration Panel</h1>\\n";
    TOPMENU(\$repdist[\$_GET['cat']]);
    \$fnames = array ('s_tcommands','s_commands','s_replacements','s_blocklist','s_resname');
    function proccom(\$fnames, \$fname, \$cat ) {
      require "\$fname";
      if ( isset(\$_GET['save']) ) {
        for ( \$n=0; \$n < (count(\$_POST)-2) ; \$n++ ) {
          if ( isset(\$_POST["\${n}in"]) ) { \$nn = \$_POST["\${n}in"]; }
          if ( isset(\$_POST["\${n}out"]) ) { \$no = \$_POST["\${n}out"]; }
          \$outprep[\$nn] = \$no;
        }
        foreach ( \$outprep as \$key => \$val ) {
          if ( strlen(\$val) > 0 ) {
            \$pdata[] = '"' . \$key . '" => "' . \$val .'",';
          }
        }
        if (isset(\$pdata)) {
          \$pdata = implode("\\n",\$pdata);
        } else {
          \$desc = array ( 
            array ( 'field1' => 'Shortcut', 'field2' => 'Text to be printed to the chat in place of /shortcut'),
            array ( 'field1' => 'Command', 'field2' => 'Command output; will appear as a message/link/image above the control panel. HTML is OK.'),
            array ( 'field1' => 'Word', 'field2' => 'Replacement -- Word will be replaced by word or phrase entered here.'),
            array ( 'field1' => 'IP Address', 'field2' => 'REASON GIVEN -- Must put something here. Clearing this box will delete the item.'),
            array ( 'field1' => 'Name', 'field2' => 'IP Address to auto-allow-- /login to use word.')
          );
          \$pdata = '"' . \$desc[\$_GET['cat']]['field1'] . '" => "' . \$desc[\$_GET['cat']]['field2'] . '",';
        }
        \$pdata = "<?php\\n\$\$fnames = array (\\n\$pdata\\n);\\n?>";
        \$handle = fopen(\$fname,"w+t");
        fwrite (\$handle,\$pdata);
        fclose(\$handle);
        echo 'File saved. <a href="config.php?go=rep&cat=' . \$_GET['cat'] . '>Continue.</a>';
        return;
      }

      echo "<form method=\\"post\\" action=\\"config.php?go=rep&cat=" . \$_GET['cat'] ."&save\\">";
      echo '<input type="hidden" name="cat" value="' . \$cat . '" />';
      \$n = 0;
      foreach ( \$\$fnames as \$in => \$out ) {
        \$_replacement[\$n]['in'] = \$in;
        \$_replacement[\$n]['out'] = \$out;
        echo "<input type=\\"text\\" value=\\"" . stripslashes(htmlentities(\$in,ENT_QUOTES)) . "\\" name=\\"\${n}in\\" />";
        echo "<input type=\\"text\\" value=\\"" . stripslashes(htmlentities(\$out,ENT_QUOTES)) . "\\" name=\\"\${n}out\\" size=\\"100\\" /><br />\\n";
        \$n++;
      }
      echo "<input type=\\"text\\" name=\\"\${n}in\\" />";
      echo "<input type=\\"text\\" name=\\"\${n}out\\" size=\\"100\\" /><br />\\n";
      echo '<input type="submit" name="Save" value="Save" /><br />' . "\\n";
      echo '</form>';
      if ( isset(\$_GET['cat']) && \$_GET['cat'] == 3 ) {
        require 'settings.php';
        echo "<h3>Most Recent Chatter</h3>";
        \$num = 10;
        \$input = file(\$file);
#        \$input = array_reverse(\$input);
        \$output = array_slice(\$input,0,\$num);
#  Output User data
        for ( \$n=0; \$n < count(\$output); \$n++ ) {
          \$pass_txt = preg_split('/\\\\s:\\\\s/', \$output[\$n]);
          \$pass_fcol = \$pass_txt[1];
          \$pass_bcol = \$pass_txt[2];
          \$pass_ffam = \$pass_txt[3];
          \$pass_name = \$pass_txt[4];
          \$pass_text = \$pass_txt[5];
          if ( count(\$pass_txt) > 6 ) {
            for (\$nn=6; \$nn < count(\$pass_txt); \$nn++) {
              if ( preg_match('/[\\\\d]{1,3}\\\\.[\\\\d]{1,3}\\\\.[\\\\d]{1,3}\\\\.[\\\\d]{1,3}/m',\$pass_txt[\$nn]) ) {
                \$pass_addr = trim(\$pass_txt[\$nn]);
              } else {
                \$pass_text = ( \$pass_text . \$pass_txt[\$nn] );
              }
            }
          }
          if ( isset(\$pass_addr) ) {
            echo "<div><strong>\$pass_name</strong> <a href=\\"http://ws.arin.net/cgi-bin/whois.pl?queryinput=".stripslashes(\$pass_addr)."\\">\$pass_addr</a> \$pass_text</div>\\n";
            unset(\$pass_addr);
          } else {
            echo "<div><strong>\$pass_name</strong> &lt;no address available&gt;\\t\\t".stripslashes(\$pass_text)."</div>\\n";
          }
        }
      }
    }

    if ( \$_SESSION['edtpass'] == \$sitepass ) {
      if ( isset(\$_GET['cat']) && \$_GET['cat'] >= 0 ) {
        \$ufnm = \$fnames[\$_GET['cat']];
        \$uarr = \$fnames[\$_GET['cat']];
      }

      if ( isset(\$ufnm) ) {
        proccom(\$uarr,"\$ufnm.php",\$_GET['cat']);
      } else {
        return;
      }
    } else {
      echo '<form action="config.php?go=rep&cat=' . \$_GET['cat'] . '" method="post">' . "\\n";
      echo '<input type="password" name="userpass" />' . "<br />\\n";
      echo '<input type="submit" name="passsmt" value="Login" />' . "<br />\\n";
      echo '</form>';
    }
  } else {
# CONFIG FILE REPAIR SYSTEM; SHOULD FIX ERRORS.
    \$rep_def = array(
      'btitle' => 'Chat in RetroStyle',
      'siteaddr' => '0.0.0.0',
      'siteeml' => 'address@domain.com',
      'sitepass' => '',
      'siteurl' => '',
      'file' => 'print.txt',
      'hstfile' => 'history.txt',
      'bunews' => '1',
      'bwelcome' => 'Welcome to the Chat!',
      'bannounce' => '',
      'prnt_num' => '30',
      'strp_meth' => '1',
      'ublist' => '0',
      'ubreas' => 'This is a private chat.',
      'ucookies' => '1',
      'cname' => 'chatter',
      'c_days' => '7',
      'use_quote' => '1',
      'qfile' => 'cookie.txt',
      'use_time' => '1',
      'urefresh' => '1',
      'def_lurkvol' => '',
      'use_save' => '1',
      'use_hist' => '1',
      'use_help' => '1',
      'use_side' => '1',
      'sideRate' => '45',
      'use_comm' => '0',
      'use_styl' => '1',
      'use_link' => '1',
      'use_peml' => '1',
      'use_lshr' => 'URL..',
      'use_srch' => '1',
      'replace_do' => '0',
      'uover' => '1',
      'uctrl' => '1',
      'colst' => 'auto',
      'ucol_toggle' => '1',
      'def_bgcolor' => '#000',
      'def_fgcolor' => '#ccc',
      'def_lkbcolor' => 'none',
      'def_lkcolor' => '#fff',
      'cpan_b' => '#ccc',
      'cpan_f' => '#000',
      'cpan_t' => 'Verdana',
      'cpan_z' => '11',
      'brdrst' => 'groove',
      'brdrsz' => '2',
      'brdrcl' => 'Orange',
      'p_marg' => '1',
      'def_uname' => '',
      'unlen' => '15',
      'def_u_zone' => '-5',
      'def_bcolor' => 'White',
      'def_fcolor' => 'Black',
      'def_ffamily' => 'Verdana',
      'def_fsize' => '1em',
      'print_txt_do' => '1',
      'print_r_do' => '0',
      'erep' => '0',
    );
    if ( is_file ("settings.php") ) {
      include "settings.php";
      echo '<hr /><div>Changes to your configuration file are outlined below.<br />This process ensures your old configuratino file is brought up to date with the system requirements.<br />After saving changes, you will be taken to the configuration interface where you can update the settings.<em><strong>Note:</strong> if you have just installed or reinstalled the chat, you are strongly urged to save the changes.<br />An old configuration file may cause serious problems.</em></div><hr />';
      echo '<form method="post" action="config.php?go=repair&save=1">';
      foreach ( \$rep_def as \$name => \$setting ) {
        echo '<div style="font-size: 10px;">';
        if ( isset(\$\$name) ) {
          echo "<input type=\\"hidden\\" name=\\"\$name\\" value=\\"\${\$name}\\" />\$name <em>ok</em>, ";
          \$rep_def[\$name] = \$\$name;
        } else {
          \$\$name = \$setting;
          echo "<input type=\\"hidden\\" name=\\"\$name\\" value=\\"\${\$name}\\" /><strong>\$name set to <em>\$setting</em></strong>";
        }
        echo '</div>';
      }
      echo '<div><input type="submit" name="save_do" value="Save changes to disk" /></div></form>';
    } else {
      echo 'There is no settings file to update. Please re-run the <a href="install.php">installer</a>.';
    }
  }
} else {
  if ( isset(\$_GET['go']) && \$_GET['go'] == 'repair' ) {
    echo '<form action="config.php?go=repair" method="post">';
  } else {
    echo '<form action="config.php" method="post">';
  }
  echo '<input type="password" name="userpass" />' . "<br />\\n";
  echo '<input type="submit" name="passsmt" value="Login" />' . "<br />\\n";
  echo '</form>';
}
if ( \$print_r_do > 0 ) {
  echo "<pre>";
  echo "POST\\n";
  print_r(\$_POST);
  echo "GET\\n";
  print_r(\$_GET);
  echo "COOKIE\\n";
  print_r(\$_COOKIE["\$cname"]);
  echo "</pre>";
}
if ( \$print_r_do > 1 ) {
  echo "<pre>";
  echo "VAR DUMP\\n";
  var_dump(\$GLOBALS);
  echo "<pre>";
}
?>
text;

#NEWS.PHP
$def_news = <<<text
<?php
\$authoraddr = AUTHORADDR;
\$sys_news = <<<news
<p style="text-align: center;">Chat in RetroStyle<br /><a href="http://www.theprawn.com/chat/chatrs-latest.zip">Download</a> | <a href="\$authoraddr">Contact</a></p><hr />
<ul>
<li>1.00<ul><li>Initial release</li></ul></li>
<li>1.01<ul><li>Added: Support for bold/italics/asterix *text* = bold, /text/ = italic, _text_ = underline whitespace must preceed the */_ </li>character<li>Added: Url's beginning with http: and not containing white-space are converted to clickable links</li><li>Added: Added create file feature in case there is no data file. It sets permissions for data file to 666 automatically. This makes installation a breeze. -- Just chmod the parent directory to 777.</li></ul></li>
<li>1.02<ul><li>Added: Cookie quote feature; will randomly print a line from cookie.txt below the control panel.  This may be enabled/disabled via the config file.</li><li>Updated: Changed "Refresh" to "Lurk" reflecting the purpose of it. It now displays whether it is on or off.</li></ul></li>
<li>1.03<ul><li>Display changes for quotes and error messages.</li></ul></li>
<li>1.04<ul><li>Rewrote the parsing engine, should be much faster</li><li>Two html tag options; hidden or shown</li><li>Minor updates to b/i/u markup regex</li></ul></li>
<li>1.05<ul><li>Quotes, if enabled by the chat owner, may be turned on and off at will.  Remembered, as all else, by the cookie</li></ul></li>
<li>1.06<ul><li>Body background may now be randomized by default by admin</li><li>User may randomize font color with "rand" color value.</li></ul></li>
<li>1.08<ul><li>Color defaults made more intuitive using the randlite and randdark commands; should make readable defaults.</li><li>New time stamp feature, allowing user to view the time as offset by their own time zone.  We'll see what DST does to the system, eh? Beh.</li></ul></li>
<li>1.09<ul><li>Colors can now be set to automatically randomize with with each post.</li></ul></li>
<li>1.10<ul><li>Navigatable history implemented</li></ul></li>
<li>1.11<ul><li>Bug fixes, some config file options removed name/text</li><li>Few more options in config file</li><li>Installation instructions</li><li>Random color generator moved to color_gen.php for portability</li></ul></li>
<li>1.12<ul><li>Fixed bug? in handling of lurk cookie.  Maybe.</li><li>Made DST offset option on a per-user basis.</li></ul></li>
<li>1.13<ul><li>Disabled form autocomplete</li></ul></li>
<li>1.14<ul><li>Fixed hunter phenomenon -- exploiting data format, " : " would destroy message layout.  Text containing that string is now not accepted.  Error message is returned.</li></ul></li>
<li>1.15<ul><li>With help from hunter, found and stopped most 'holes' in the write pars

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Allen

Comment:



Comment:

(Maximum characters: 1200). You have characters left.